var gdir;
var MaCarte;
var geocoder = null;
var Adresse;
var Ville;
var DescriptionCentre;
var marker;
var pointMag;
var Latitude;
var Longitude;
function load(div) {
	switch(div){
		case "Layer_marseille":
		ChargeInfoMarseille();
		divAffichage='div_marseille';
		break;
		case "Layer_lyon":
		ChargeInfoLyon();
		divAffichage='div_lyon';
		break;
		case "Layer_nancy":
		ChargeInfoNancy();
		divAffichage='div_nancy';
		break;
	}
 	if (GBrowserIsCompatible()) {
		// Initialisation d'un nouveau géocodeur nommé "geocoder"	
 		geocoder = new GClientGeocoder();
		pointMag=geocoder.getLatLng(Adresse, function(point) {
			// Création d'une nouvelle carte nommée "MaCarte" s'affichant en lieu et place de la <div> ayant pour identifiant id="EmplacementDeMacarte"	
			MaCarte = new GMap2(document.getElementById(divAffichage),    { size: new GSize(425,350) } );
			// Affichage des contrôles sur la carte nommée "MaCarte" : Déplacement/Zoom - Type de carte - Mini-carte en bas à droite - Echelle
			MaCarte.setUIToDefault();
			// La carte nommée "MaCarte" est centrée sur le point
			//point = new GLatLng(lat, lng);
			
			MaCarte.setCenter(point, 14);
				
			var tinyIcon = new GIcon();
			tinyIcon.image = "http://test.attrait.com/charte/picto_magasin.png";
			tinyIcon.iconSize = new GSize(25, 35);
			tinyIcon.iconAnchor = new GPoint(12, 35);
			tinyIcon.infoWindowAnchor = new GPoint(25, 1);
			
			// Set up our GMarkerOptions object literal
			markerOptions = { icon:tinyIcon };
			marker = new GMarker(point, markerOptions);
			MaCarte.addOverlay(marker);
			marker.openInfoWindowHtml(DescriptionCentre);
			GEvent.addListener(marker,"click", function() {
				MaCarte.openInfoWindowHtml(point, DescriptionCentre);
			});
			}
		);
 	}else{
 		alert("Désolé, mais votre navigateur n\'est pas compatible avec Google Maps");
 	}
}

 function setDirections(fromAddress) {
	 MaCarte.removeOverlay(marker);
      gdir.load("from: " + fromAddress + " to: "+Adresse,
                { "locale": 'fr' });
    }
	
 function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Votre adresse ne correspond pas à une position géographique. Cela peut être du au fait que l'adresse soit relativement récente ou incorrecte.\nCode Erreur: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\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("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

