var zoom_map;
if (GBrowserIsCompatible()) {
  var googleMapLay = document.all ? document.all["googleMap"] : document.getElementById("googleMap");
  var map = new GMap(googleMapLay);
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(42.179688,13.337402),6);

	
  // ====== Create a Client Geocoder ======
  var geo = new GClientGeocoder(); 

  // ====== Array for decoding the failure codes ======
  var reasons=[];
  reasons[G_GEO_SUCCESS]            = "Successo";
  reasons[G_GEO_MISSING_ADDRESS]    = "Indirizzo mancante: Indirizzo nullo o inesistente.";
  reasons[G_GEO_UNKNOWN_ADDRESS]    = "Indirizzo sconosciuto:  L'indirizzo inserito non è stato trovato, prova a controllare che sia stato scritto correttamente.";
  reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Indirizzo non disponibile: L'indirizzo non può essere riportato per limitazioni contrattuali di Google Maps";
  reasons[G_GEO_BAD_KEY]            = "Bad Key";
  reasons[G_GEO_TOO_MANY_QUERIES]   = "Troppe Queries: Sono state effettuate troppe queries da questo sito.";
  reasons[G_GEO_SERVER_ERROR]       = "Errore lato server.";
  
  // ====== Plot a marker after positive reponse to "did you mean" ======
  function place(lat,lng) {
	var point = new GLatLng(lat,lng);
	map.setCenter(point,zoom_map); 
	//*********
	//SETTO MARKER PERSONALIZZATO
	//*********

	if(document.location.href.indexOf("casaveloce.eu")>-1){
		var markerCV = new GIcon(G_DEFAULT_ICON);
		markerCV.image = "/_htdocs/images/google_marker.png";
		//markerCV.shadow = "";
		markerCV.iconSize = new GSize(71,58);
		/*
		markerCV.shadowSize = new GSize(37, 34);
		markerCV.iconAnchor = new GPoint(9, 34);
		markerCV.infoWindowAnchor = new GPoint(9, 2);
		markerCV.infoShadowAnchor = new GPoint(18, 25);
		markerCV.transparent = "http://www.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
		markerCV.printImage = "coldmarkerie.gif";
		markerCV.mozPrintImage = "coldmarkerff.gif";
		*/
		map.addOverlay(new GMarker(point,markerCV));
	}else{
		var marker = new GMarker(point);
		map.addOverlay(marker);
	}
	
	
	/* document.getElementById("message").innerHTML = ""; */
  }

  // ====== Geocoding ======
  function showAddress(search,zoom) {
	zoom_map = zoom ? 16 : 12;
	// ====== Perform the Geocoding ======        
	geo.getLocations(search, function (result)
	  {
		map.clearOverlays(); 
		if (result.Status.code == G_GEO_SUCCESS) {
		  // ===== If there was more than one result, "ask did you mean" on them all =====
		  if (result.Placemark.length >= 1) { 
			var p = result.Placemark[0].Point.coordinates;
			var marker = new GMarker(new GLatLng(p[1],p[0]));
			place(p[1],p[0]);
			/*
			document.getElementById("message").innerHTML = "Volevi dire:";
			// Loop through the results
			for (var i=0; i<result.Placemark.length; i++) {
			  var p = result.Placemark[i].Point.coordinates;
			  var marker = new GMarker(new GLatLng(p[1],p[0]));
			  document.getElementById("message").innerHTML += "<br/>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"</a>";
			map.addOverlay(marker);
			}
			document.getElementById("message").innerHTML += "<br/>Se il risultato non è quello che desideravi, prova ad aggiungere informazioni";*/
		  }
	  
		}
		// ====== Decode the error status ======
		else {
		  var reason="Code "+result.Status.code;
		  if (reasons[result.Status.code]) {
			reason = reasons[result.Status.code]
		  } 
		  googleMapLay.style.display = "none";
		  //alert('Non trovato: "'+search+ '" ' + reason);
		}
	  }
	);
  
  }
}

// display a warning if the browser was not compatible
else {
	$('msgGoogleMap').innerHTML = 'Questo browser non supporta Google Map';
 // alert("Sorry, the Google Maps API is not compatible with this browser");
}
