//<![CDATA[

var map = null;
var geocoder = null;

// ====== Array per i messaggi di errore ======
var reasons=[];
reasons[G_GEO_SUCCESS]            = "OK!";
reasons[G_GEO_MISSING_ADDRESS]    = "Indirizzo non trovato: l'indirizzo inserito potrebbe non esistere o essere incompleto.";
reasons[G_GEO_UNKNOWN_ADDRESS]    = "Indirizzo inesistente: non ci sono regioni geografiche corrispondenti";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Indirizzo non disponibile per motivi legali o contrattuali.";
reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES]   = "Troppe richieste: Google Maps ha bloccato le richieste per oggi.";
reasons[G_GEO_SERVER_ERROR]       = "Errore nel server di Google Maps: l'indirizzo inserito non puņ essere processato.";

function load() {
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(57.044, -4.520), 7);
	geocoder = new GClientGeocoder();
}

// FUNZIONE PER I BOTTONI DELLE ALTRE MAPPE
function cambiaMappa(latitudine, longitudine, valorezoom) {
	var point = new GLatLng(latitudine,longitudine)
	map.setZoom(valorezoom);
	map.setCenter(point);
}

// FUNZIONE PER LA RICERCA DEGLI INDIRIZZI
function showAddress(address) {
  if (geocoder) {
  
	//if (result.Status.code == G_GEO_SUCCESS) {
	
		geocoder.getLatLng(
		  address,
		  function(point) {
			if (!point) {
			  alert(address + " not found");
			} else {
			  map.setCenter(point, 13);
			  var marker = new GMarker(point);
			  map.addOverlay(marker);
			  //marker.openInfoWindowHtml(address);
			}
		  }
		);
	// }
	 
	 //else {
		//  var reason="Code "+result.Status.code;
		//  if (reasons[result.Status.code]) {
			//reason = reasons[result.Status.code]
		//  } 
		//  alert('Indirizzo non trovato: "'+search+ '" ' + reason);
		//}
		
  }
}


//]]>
