
 //<![CDATA[

 	 var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	var latitude = 	49.5207859;
	var longitude =  6.0129896;
	
	function latitude_garage(num_garage)
	{
		num_garage=parseInt(num_garage);
		var lat;
		switch(num_garage)
		{ 
			case 1: 
				lat=49.5134931;
				break;
			case 2: 
				lat=49.5236901;
				break;
			default: lat=49.5134931; 
		}
		return lat;
	}
	
	function longitude_garage(num_garage)
	{
		num_garage=parseInt(num_garage);
		var long;
		switch(num_garage)
		{ 
			case 1: 
				long=5.9953809;
				break;
			case 2: 
				long=6.0092533;
				break;
			default: long=5.9953809; 
		}
		return long;
	}
	
	function effacer_adresse()
	{
		$("fromAddress").value="";
	}
	
    function initialize() 
	{
      if (GBrowserIsCompatible()) { 
	  
	  	$("map_go1").innerHTML="";
		$("directions").innerHTML="";
		$("map_avertissement").innerHTML="";
	  

        var map = new GMap2($("map"));
        map.setCenter(new GLatLng(49.5185779, 6.0033095), 13);

	 		icon=new GIcon();
            icon.image = "./img/logo_map.png";
            icon.iconAnchor = new GPoint(0, 0);
            icon.infoWindowAnchor = new GPoint(33,1);

			latitude=latitude_garage(1);
			longitude=longitude_garage(1);
			var point = new GLatLng(latitude, longitude);
			var marker = new GMarker(point,icon);
			GEvent.addListener(marker, "click", function() {
        	marker.openInfoWindowHtml("<p><span class='gras'>Autodis s.a. à Esch</span><br /><br />Zone Industrielle \"Um Monkeler\"<br />L-4149 ESCH-SUR-ALZETTE<br /><span class='gras'>Tel :</span> +352.26 55 56-1<br /></p>");
      		});
			
			latitude=latitude_garage(2);
			longitude=longitude_garage(2);
			var point = new GLatLng(latitude, longitude);
			var marker2 = new GMarker(point,icon);
			GEvent.addListener(marker2, "click", function() {
        	marker2.openInfoWindowHtml("<p><span class='gras'>Centre Occasions à Foetz</span><br /><br />4, rue de l'Avenir<br />L-3895 Foetz<br /><span class='gras'>Tel :</span> +352.26 17 42-1<br /></p>");
      		});
			
			

    		map.addOverlay(marker);
			map.addOverlay(marker2);

		map.setUIToDefault();
		     
       // map = new GMap2(document.getElementById("map_canvas"));
        gdir = new GDirections(map, $("directions"));
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        //setDirections("San Francisco", "Mountain View", "fr");
      }
    }

    function setDirections(address) 
	{
		address=$("fromAddress").value;
		
		if(address=="")
		{
			//initialize($("liste_garage_plan").value);
			//if(liste!=1)
			$("directions").innerHTML="";
			$("map_avertissement").innerHTML="<br />Veuillez saisir votre adresse de départ";
		}
		else
		{
			num_garage=$("liste_garage_plan").value;
			latitude=latitude_garage(num_garage);
			longitude=longitude_garage(num_garage);
			
			var geocoder = new google.maps.ClientGeocoder();
			geocoder.getLatLng(address, function (coord) {
			if(coord!=null)
				gdir.loadFromWaypoints([new GLatLng(coord.lat(),coord.lng()),new GLatLng(latitude,longitude)],{ "locale": "l" });
			else
				handleErrors();
			});
		}
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	   		$("map_avertissement").innerHTML="- Itinéraire non trouvé -";
	     //alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     $("map_avertissement").innerHTML="- Itinéraire non trouvé -";
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     $("map_avertissement").innerHTML="- Itinéraire non trouvé -";

	//   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)
	     $("map_avertissement").innerHTML="- Itinéraire non trouvé -";

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	   	$("map_avertissement").innerHTML="- Itinéraire non trouvé -";

	     //alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else 
	   		$("map_avertissement").innerHTML="<br />- Adresse non trouvée -<br />Veuillez indiquer votre adresse, ville, code postale et pays";
	   //alert("Erreur Inconnue");
	   $("directions").innerHTML="";
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.
      // e.g.
     //if(gdir.getStatus().code==200)
		$("map_avertissement").innerHTML="";
		$("map_go1").innerHTML="<a href='#' onclick='$(\"fromAddress\").value=\"\";initialize();'>&bull; Effacer mon itinéraire<\/a>";
	 //document.getElementById("avertissement").innerHTML="Aucun résultat trouvé";
	  // and yada yada yada...
	  //document.getElementById("test2").innerHTML=gdir.getCopyrightsHtml();
	  //gdir.getCopyrightsHtml()=false;
	}
       //]]>