// array associativo di messaggi divisi per lingua
   var msgs = {
    'it' : {
        nameRequired: "Attenzione: nome e cognome sono obbligatori.",
        mailError: "Attenzione: email non valida.",
        msgRequired: "Attenzione: specificare un messaggio.",
        urlError: "Attenzione: non usare \"www\" o \"http\" nel testo del messaggio"
    },
    'en':  {
        nameRequired: "Name and surname are mandatory fields.",
        mailError: "Email address is not valid.",
        msgRequired: "Please specify a message.",
        urlError: "Do not use \"www\" or \"http\" in message body."
    },
    'de':  {
        nameRequired: "Vor - und Zuname sind verbindlich",
        mailError: "Bitte: controllieren Sie das Email Adresse",
        msgRequired: "Nachricht ist verbindlich",
        urlError: "Bitte nicht benutzen entweder \"www\" oder \"http\" im Nachricht."
    }
};
// strumenti per il contatto agli agriturismi
function isValidEmail(str) {
	var filtro = /^([a-z0-9]+)([\.\-_][a-z0-9]*)*\@([a-z0-9]+)([\.\-_][a-z0-9]+)*\.([a-z]{2,4})$/;

	return filtro.test(str.toLowerCase());
}
function checkFormInviaMail(){
	if (document.inviamail.fromName.value == ""){
		alert(msgs[lang].nameRequired);
		return false;
	}
	if (!isValidEmail(document.inviamail.fromEmail.value)){
		alert(msgs[lang].mailError);
		return false;
	}
	if (document.inviamail.body.value == ""){
		alert(msgs[lang].msgRequired);
		return false;
	}
	if (
		( document.inviamail.body.value.indexOf( "www" ) >= 0 ) ||
		( document.inviamail.body.value.indexOf( "http" ) >= 0 )
	){
		alert(msgs[lang].urlError);
		return false;
	}
}

/*
 * creazione mappa google
 */
function loadMappa(lat, lon, centro_lat, centro_lon, zoom, map_type) {
  lat = parseFloat(lat.replace(",","."));
  lon = parseFloat(lon.replace(",","."));
  centro_lat = parseFloat(centro_lat.replace(",","."));
  centro_lon = parseFloat(centro_lon.replace(",","."));
  zoom = parseInt(zoom);
  var icon = new GIcon(G_DEFAULT_ICON);
    icon.image = "/images/marker.gif";
    icon.iconSize = new GSize(43, 58);
    icon.shadow = "/images/marker_shadow.png";
    icon.shadowSize = new GSize(84, 58);
    icon.iconAnchor = new GPoint(22, 58);
    markerOptions = { icon:icon };
  var customUI;
  if (GBrowserIsCompatible()) {
    G_NORMAL_MAP.getMinimumResolution = function() {return 5};
    G_HYBRID_MAP.getMinimumResolution = function() {return 5};
    G_PHYSICAL_MAP.getMinimumResolution = function() {return 5};
    var map = new GMap2(document.getElementById("mappa"));
    if(!centro_lat || centro_lat == '0.0' || centro_lat == ''){
        centro_lat = lat;
        centro_lon = lon;
        zoom = 9;
    }
    map.setCenter(new GLatLng(centro_lat, centro_lon), zoom);//centra la mappa con le coordinate recuperate dall indirizzo
    customUI = map.getDefaultUI();
    customUI.controls.scalecontrol = false;
    customUI.maptypes.satellite = false;
    map.setUI(customUI);
    if(map_type == 1)
      map.setMapType(G_PHYSICAL_MAP);
    else map.setMapType(G_NORMAL_MAP);
    map.addOverlay(new GMarker(new GLatLng(lat, lon), markerOptions));
    GEvent.addListener(map,"zoomend",function(old_zoom, new_zoom) {
                    if(map.getCurrentMapType() == G_PHYSICAL_MAP){
                        if(new_zoom == 15){
                             map.setMapType(G_NORMAL_MAP);
                             c = true;
                        }
                    }else
                        if(c && map.getCurrentMapType() == G_NORMAL_MAP && new_zoom == 14){
                             map.setMapType(G_PHYSICAL_MAP);
                             c = false;
                        }
                });
  }
}
