if (GBrowserIsCompatible()) 
    { 

    var map;
    var geo;
    var reasons=[];




    function load() {
    	//document.getElementById("map").style.visibility="hidden";	
      map = new GMap(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
    	 map.setCenter(new GLatLng(46.227638,2.213749),5);
       

      
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 
	
      // ====== Array for decoding the failure codes ======
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
      
    }

      // ====== Plot a marker after positive reponse to "did you mean" ======
      function place(lat,lng) {
    
        var point = new GLatLng(lat,lng);
        map.setCenter(point,10); 
              
        affichInfosMag(lat,lng);
        
        document.getElementById("map").style.visibility="visible";
        

      }
      function createMarkers(point,title, desc, img_src,h,w )
    	{
    		//create an icon instance
    		var icon = new GIcon();
    		//add the img src for the icon
    		icon.image = img_src;
    		//setting the size of the image
    		icon.iconSize = new GSize(h, w);
    		//seting an anchor
    		icon.iconAnchor = new GPoint(h, w);
    		//setting the info windo anchor
    		icon.infoWindowAnchor = new GPoint(h, w);
			//setting the option => in this case, no draggable option (ie fixed)
    		var options = { icon: icon, draggable: false};

			//setting the content of the bubble
    		var bulle = desc;
    		//instanciation of the marker
    		var marker = new GMarker(point,options);
    		//setti?ng the event listener
    		GEvent.addListener(
	    		marker, "click", function()
	    		{
	    			marker.openInfoWindowHtml(bulle);
	    		}
    		);
    		//returning our instanciated marker to feed our map.addOverlay instance.
    		return marker;
    	}

      // ====== Geocoding ======
      function showAddress() {
        var search = document.getElementById("codepostalmagasinInput").value + " france";
         if(document.getElementById("codepostalmagasinInput").value=="75000")
		     {
		            	search="75001 france";
		            	
		      }
		      if(document.getElementById("codepostalmagasinInput").value == "13000")
		      {
		            	search="13001 france";
		            	
		      }
		      if(document.getElementById("codepostalmagasinInput").value == "69000")
		      {
		            	search="69001 france";
		            	
		       }   
       
        // ====== Perform the Geocoding ======        
        geo.getLocations(search, function (result)
          {
            map.clearOverlays(); 
            if (result.Status.code == G_GEO_SUCCESS) {
              // ===== If there was more than one result, "ask did you mean" on them all =====
              if (result.Placemark.length > 1) { 
                
                // Loop through the results
                for (var i=0; i<result.Placemark.length; i++) {
                  var p = result.Placemark[i].Point.coordinates;
                 // document.getElementById("message").innerHTML += "<br>"+(i+1)+": <a href='javascript:place(" +p[1]+","+p[0]+")'>"+ result.Placemark[i].address+"</a>";
                }
              }
              // ===== If there was a single marker =====
              else {
                //document.getElementById("message").innerHTML = "";
                var p = result.Placemark[0].Point.coordinates;
                place(p[1],p[0]);

              }
            }
            // ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              } 
              //alert('Could not find "'+search+ '" ' + reason);
              alert("Veullez saisir un autre code postal !")
              document.getElementById("magasinResult").style.display="none";
              load();
            }
          }
        );
        
      }
      
    }
    
    // display a warning if the browser was not compatible
    else {
      alert("Veullez saisir un code postal !");

          document.getElementById("magasinResult").style.display="none";
          load();
    }

    // This Javascript is based on code provided by the
    // Blackpool Community Church Javascript Team
    // http://www.commchurch.freeserve.co.uk/   
    // http://econym.googlepages.com/index.htm
    
    
function affichInfosMag(iLatitude,iLongitude)
{
	var objHtpp;
	var strHml ="";
	var sUrlWeb = "";
	var sNomMag="";
	var sAddress = "";
	var sZip = "";
	var sCity = "";
	var listItem = ""
	var dtDate = new Date();
	var ms = dtDate.getMilliseconds();
	//alert("lat : " + iLatitude + "-- Long : " + iLongitude);
	
	var sUrl ="/c2k/portail/storelocator/recupListeMagCoordGps.asp?latitude=" + iLatitude + "&longitude="+ iLongitude;
	


	var sMethod ="GET";
	var sMode = false;
	var sReponse = "XML";
	sXml=initHTTPRequest(objHtpp,sMethod,sUrl, sMode,sReponse);	
	var listeWeb=sXml.getElementsByTagName('u_web');
	var listeLabel=sXml.getElementsByTagName('u_label');
	var listeLong=sXml.getElementsByTagName('gps_longitude');
	var listeLat=sXml.getElementsByTagName('gps_latitude');
	var listeZip=sXml.getElementsByTagName('u_zip');
	var listeCity=sXml.getElementsByTagName('u_city');
	var listePfax=sXml.getElementsByTagName('u_pfax');
	var listeDistance = sXml.getElementsByTagName('distance');
	var len=listeWeb.length;
	var lastDistance = "";
	var iEchelle = 0;
	var k = 1;
	if(len>0)
	{
		strHml="";
		//recup lla dernirere distance pour fixer l'echelle de l map
		for (var t=0; t<len; t++)
		{
			
			lastDistance = listeDistance[t].firstChild.data;
		}

		if(lastDistance < 20)
		{
			iEchelle = 10;
		}
		else if((lastDistance > 20) && (lastDistance < 30))
		{
			iEchelle = 9;
		}
		else
		{
			iEchelle = 8;
		}
		document.Form1.code_PFInput.options.length=0;
		for (var i=0; i<len; i++)
		{
			
			sUrlWeb = "/"+listeWeb[i].firstChild.data+"/default.asp";
			sNomMag=listeLabel[i].firstChild.data;
			sNomMag=sNomMag.replace("#","'");
			sNomMag=sNomMag.replace("&'201;","\311");
			sPfax = listePfax[i].firstChild.data;
			
			sZip = listeZip[i].firstChild.data;
			sCity = listeCity[i].firstChild.data;
			//strHml +='<br><input name="u_mag_id" type="radio" value="'+ sPfax +'¤' + sNomMag.replace("#","'") +'" onClick="afficherNomMag(\''+sNomMag.replace('#','\'')+'\',\''+sPfax+'\')" /> ' + sNomMag.replace("#","'") +'<br>';

			strHmlBulle ="<font class='contenu10'><a href='"+sUrlWeb+"'><b>Centre E.Leclerc "+sNomMag.replace("&'194;","A")+"</b></a></font> <br><font class='contenu10'>"+sZip+ " " + sCity.replace("#","'") +"</font>";
			
				var o = new Option ();
				o.text = sNomMag;
				o.value = sPfax;

				document.Form1.code_PFInput.options[i] = o;
			
		 if(i==0)
			{
				var point = new GLatLng(listeLat[i].firstChild.data,listeLong[i].firstChild.data);
        			map.setCenter(point,iEchelle);
        			marker = new GMarker(point);
        			map.addOverlay(createMarker(point, i + 1,strHmlBulle));

      				
 
			}
			else
			{
					
				var point = new GLatLng(listeLat[i].firstChild.data,listeLong[i].firstChild.data);
				marker = new GMarker(point);
     				map.addOverlay(createMarker(point, i + 1,strHmlBulle));
			}

		}
		
		strHmlNavDroite ="<ul>" + strHml + "</ul>";	
		//document.getElementById("divu_label").innerHTML=strHml;
		
		document.getElementById("magasinResult").style.display="block";
		document.getElementById("divu_label").style.visibility="visible";

			
		
		return false;
			
	}
	else
	{		
		alert("Aucun magasin pour ce code postal");
		document.getElementById("magasinResult").style.display="none";
		load();
		return false;
			
	}


}
function createMarker(latlng, number, sHtml) {
      var marker = new GMarker(latlng);
      marker.value = number;
      GEvent.addListener(marker,"click", function() {
        var myHtml = sHtml;
        map.openInfoWindowHtml(latlng, myHtml);
      });
      return marker;
	}
	
function verifChoixMag()
{
			var sResult = "";
			if(document.Form1.u_mag_id.length > 0)
			{

				for(i=0;i < document.Form1.u_mag_id.length;i++)
				{
					if (document.Form1.u_mag_id[i].checked==true)
					{
						//document.Form1.u_label.options.length = 0;
						var sMagId = document.Form1.u_mag_id[i].value;
						var arrMagId = sMagId.split('¤');
						//var objOp = new Option ();
						//objOp.text = arrMagId[1];
						//objOp.value = arrMagId[0];
						document.Form1.code_PFInput.value = arrMagId[0];
						
						document.Form1.nom_mag.value =arrMagId[1];
						//alert(document.Form1.u_label.value);
						//alert(document.Form1.nom_mag.value);
						sResult = arrMagId[1];
					}
				}
			}

				
		return sResult;

}
function afficherNomMag(sNomMag,sPfax)
{
	document.Form1.code_PFInput.value =sPfax;
						
						
	document.Form1.u_name_magInput.value =sNomMag;

	
}

