// JavaScript Document
//<![CDATA[
  var map;
	var loc;
  var gdir;
  var geocoder = null;
  var addressMarker;
  var punto;
  var marker;
  
  function load() {
    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("mappa"));
      map.addControl(new GSmallMapControl());
      map.setCenter(new GLatLng(45.37062947960158, 9.830596446990967), 11, G_NORMAL_MAP);
      punto = new GLatLng(45.37062947960158, 9.830596446990967);
      var mapControl = new GMapTypeControl();
      map.addControl(mapControl);
      marker = new GMarker(punto);
      map.addOverlay(marker);
      GEvent.addListener(marker, "click", function() {
        var html = "<div style='color: #062c5b;' align='center'><strong>LASLO s.r.l.<br>Idropulitrici Super Professionali CASTELLO</strong><br />Via Leonardo da Vinci, 5 - 26020 Ticengo (CR) - ITALY</div>";     
				map.setCenter;
        marker.openInfoWindowHtml(html);
      });
      GEvent.addListener(marker, "mouseover", function() {
        
      });
      
      /* impostazione per direzione*/

      gdir = new GDirections(map, document.getElementById("directions"));
      GEvent.addListener(gdir, "load", onGDirectionsLoad);
      GEvent.addListener(gdir, "error", handleErrors);
      //setDirections("", "KosmoSol s.n.c.", "it_PR");
    }
  }
	
  function setDirections(fromAddress, toAddress, locale) {
		  loc = locale;
      gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale });
  }

  function handleErrors(){
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
      alert("Indirizzo inserito non e' valido.\nCodice Errore: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
      alert("Problemi Tecnici. Siamo spiacenti.\nCodice Errore: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
      alert("Attenzione indirizzo immesso e' vuoto.\n Error code:  " + gdir.getStatus().code);
    
    // else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
    // alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
    
    else if (gdir.getStatus().code == G_GEO_BAD_KEY)
      alert("Chiave non valida.\nCodice Errore: " + gdir.getStatus().code);
    
    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
      alert("Siamo spiacenti. Servizio non disponibile.\nCodice Errore: " + gdir.getStatus().code);
    
    else alert("Errore Sconosciuto. Siamo spiacenti ma non e' possibile calcolare il percorso");   
  }
  
  function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load() results.
      // e.g. 
      //document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  }

	window.onload = load;
	window.onunload = GUnload;

//]]>


