
 //<![CDATA[

 	 var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	
	function creer_icone()
	{
		icon=new GIcon();
        icon.image = "./images/logomap.png";
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(13,1);
		return icon
	}
	
	function latitude_garage(num_garage)
	{
		num_garage=parseInt(num_garage);
		var lat;
		switch(num_garage)
		{ 
			case 1: 
				lat=49.6994761;
				break;
			case 2: 
				lat=50.0019363;
				break;
			case 3: 
				lat=49.9919532;
				break;
			case 4: 
				lat=49.8951804;
				break;
			case 5: 
				lat=50.2144915;
				break;
			case 3: 
				lat=50.4247609;
				break;
			default: lat=49.6994761; 
		}
		return lat;
	}
	
	function longitude_garage(num_garage)
	{
		num_garage=parseInt(num_garage);
		var long;
		switch(num_garage)
		{ 
			case 1: 
				long=5.8068752;
				break;
			case 2: 
				long=5.7012445;
				break;
			case 3: 
				long=5.7202721;
				break;
			case 4: 
				long=5.0759625;
				break;
			case 5: 
				long=5.3589892;
				break;
			case 6: 
				long=4.9305761;
				break;
			default: long=5.8068752; 
		}
		return long;
	}
	
	
    function initialize(num_garage) 
	{
		
      if (GBrowserIsCompatible()) 
	  { 
	  
			$("map_go1").innerHTML="";
			$("directions").innerHTML="";
			//$("fromAddress").value="";
			$("map_avertissement").innerHTML="";
			
			//if($("fromAddress").value!="")
			//setDirections(0);
			
	  		
			var map = new GMap2($("map"));
			
			latitude=latitude_garage(num_garage);
			longitude=longitude_garage(num_garage);
			map.setCenter(new GLatLng(latitude, longitude), 16);
			
			icon=creer_icone();

			latitude=latitude_garage(1);
			longitude=longitude_garage(1);
			var point = new GLatLng(latitude, longitude);
			var marker_1 = new GMarker(point,icon);
			GEvent.addListener(marker_1, "click", function(){marker_1.openInfoWindowHtml("<p>Votre concession à <span class='gras'>Arlon</span><br /><br />Route de Bastogne, 342<br />6700 Arlon<br /><br /></p>");});
		
			latitude=latitude_garage(2);
			longitude=longitude_garage(2);
			var point = new GLatLng(latitude, longitude);
			var marker_2 = new GMarker(point,icon);
			GEvent.addListener(marker_2, "click", function(){marker_2.openInfoWindowHtml("<p>Votre concession à <span class='gras'>Bastogne</span><br />Fiat - Alfa - Suzuki<br /><br />Route de Marche, 139<br />6600 Bastogne<br /><br /></p>");});
			
			latitude=latitude_garage(3);
			longitude=longitude_garage(3);
			var point = new GLatLng(latitude, longitude);
			var marker_3 = new GMarker(point,icon);
			GEvent.addListener(marker_3, "click", function(){marker_3.openInfoWindowHtml("<p>Votre concession à <span class='gras'>Bastogne</span><br />Citroën<br /><br />Chaussée d'Arlon<br />6600 Bastogne<br /><br /></p>");});
			
			latitude=latitude_garage(4);
			longitude=longitude_garage(4);
			var point = new GLatLng(latitude, longitude);
			var marker_4 = new GMarker(point,icon);
			GEvent.addListener(marker_4, "click", function(){marker_4.openInfoWindowHtml("<p>Votre concession à <span class='gras'>Carlsbourg</span><br /><br />Route de Bièvre, 3<br />6850 Carlsbourg<br /><br /></p>");});
			
			latitude=latitude_garage(5);
			longitude=longitude_garage(5);
			var point = new GLatLng(latitude, longitude);
			var marker_5 = new GMarker(point,icon);
			GEvent.addListener(marker_5, "click", function(){marker_5.openInfoWindowHtml("<p><p>Votre concession à <span class='gras'>Marche</span><br /><br />Route de Bastogne, 67<br />6900 Marche<br /><br /></p>");});
			
			latitude=latitude_garage(6);
			longitude=longitude_garage(6);
			var point = new GLatLng(latitude, longitude);
			var marker_6 = new GMarker(point,icon);
			GEvent.addListener(marker_6, "click", function(){marker_6.openInfoWindowHtml("<p>Votre concession à <span class='gras'>Namur</span><br /><br />Chaussée de Marche, 814<br />5100 Namur<br /><br /></p>");});
			
    		map.addOverlay(marker_1);
			map.addOverlay(marker_2);
			map.addOverlay(marker_3);
			map.addOverlay(marker_4);
			map.addOverlay(marker_5);
			map.addOverlay(marker_6);

			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(liste) 
	{
		address=$("fromAddress").value;
		
		if(address=="")
		{
			initialize($("liste_garage_plan").value);
			if(liste!=1)
			$("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": "fr" });
			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 postal 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)
	 	num_garage=$("liste_garage_plan").value;
		$("map_avertissement").innerHTML="";
		$("map_go1").innerHTML="<a href='#' onclick='$(\"fromAddress\").value=\"\";initialize("+num_garage+");'>&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;
	}
       //]]>