	var CabinetID = 0;
	var geocoder = null;
    var addressMarker;

    function initialize(ID) {
      if (GBrowserIsCompatible()) { 
       	eval("map_"+ID+" = new GMap2(document.getElementById('carte_"+ID+"'))");
        eval("gdir_"+ID+" = new GDirections(map_"+ID+", document.getElementById('directions_"+ID+"'))");
        GEvent.addListener(eval("gdir_"+ID), "load", onGDirectionsLoad);
        GEvent.addListener(eval("gdir_"+ID), "error", handleErrors);
		
		//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        eval("map_"+ID+".addControl(new GSmallMapControl())");
        eval("map_"+ID+".addControl(new GMapTypeControl())");
		
		if(eval("CP_"+ID) != 0 && eval("From_"+ID) != 0){
			setDirections(eval("From_"+ID), eval("CP_"+ID), "fr_CA");
		}else{
			if(eval("Lat_"+ID) && eval("Lng_"+ID)){
				eval("map_"+ID+".setCenter(new GLatLng(Lat_"+ID+", Lng_"+ID+"), 13)");
				// ajout marker
				eval("map_"+ID+".addOverlay(new GMarker(new GLatLng(Lat_"+ID+", Lng_"+ID+")))");
			}else{
				eval("map_"+ID+".setCenter(new GLatLng(45.633726, -73.435364), 7)");
			}
		}
      }
    }
    
    function setDirections(ID, fromAddress, toAddress, locale) {
      //$("#directions").slideUp("slow");
	  CabinetID = ID;
	  eval("gdir_"+CabinetID+".load('from: ' + fromAddress + ' to: ' + toAddress, { 'locale': locale })");
	  //gdir.loadFromWaypoints("from: " + fromAddress + " to: " + toAddress, { "locale": locale })
    }

    function handleErrors(){
		alert("Une erreur est survenue. Veuillez vérifier l'adresse entrée et réessayer de nouveau.")
	}

	function onGDirectionsLoad(){
      // Use this function to access information about the latest load()
      // results.

	  	var hauteurDirection = $("#directions_"+CabinetID).height();
		if( hauteurDirection < 15 ){
			//alert("ouvre les directions");
			$("#directions_"+CabinetID).slideDown("slow");
			document.getElementById("toggleDirec_"+CabinetID).style.display = "block";
			$("#toggleDirec_"+CabinetID).html("Cacher les directions");
		}else{
			$("#toggleDirec_"+CabinetID).html("Afficher les directions");
		}
		// e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}
	
	
	
	
	
  
	function getDistance(monDiv, start, end){
		var Gdist = new GDirections();
		
		GEvent.addListener(Gdist,"error", function() {
			//GLog.write("Failed: "+Gdist.getStatus().code);
			//alert("Failed: "+Gdist.getStatus().code);
			$("#"+monDiv).html("Distance non trouv&eacute;");
		});
		
		GEvent.addListener(Gdist,"load", function() {
			//GLog.write("The distance is "+Gdist.getDistance().meters+" metres");
			//GLog.writeHtml("The distance is "+Gdist.getDistance().html);
			//alert("The distance is "+Gdist.getDistance().html);
			$("#"+monDiv).html(Gdist.getDistance().html);
		});
		
		//var start = "H1W 3N5";
		//var end = "H2T 1S9";
		
		Gdist.loadFromWaypoints([start,end],{getSteps:true});
	}
	
	
	
	
	function toggleDirection(ID){
		$("#directions_"+ID).slideToggle("slow");
		var hauteurDirection = $("#directions_"+ID).height();
		if( hauteurDirection > 5 ){
			$("#toggleDirec_"+ID).html("Afficher les directions");
		}else{
			$("#toggleDirec_"+ID).html("Cacher les directions");
		}
		
		/*
		si on veut utiliser une fonction lorsque fini faire comme le suivant
		$("p").slideUp("fast",function(){
		   alert("Animation Done.");
		 });
		*/
	}