   
   
  
  
   if ( ('function' == typeof(GBrowserIsCompatible)) && GBrowserIsCompatible()) { 
   
  
   

    var map;
    var geo;
    var reasons=[];
	
	
/*TC* Fonction permettant la création d'un marqueur **/
function CreationDuMarqueur(point,icon) {
/** Création d'un nouveau marqueur nommé "marker" **/
var marker = new GMarker(point,icon);
/** ... Un observateur d'&eacute;v&eacute;nement est ajout&eacute; au marqueur appel&eacute; "marker". L'&eacute;venement d&eacute;tect&eacute; est "click" (D&eacute;tecte si un click est effectu&eacute; sur le marqueur appel&eacute; "marker"). Si un click a &eacute;t&eacute; effectu&eacute; sur le marqueur appel&eacute; "marker", la fonction situ&eacute;e entre les {} sera alors execut&eacute;e ... **/
GEvent.addListener(marker, 'click', function() {


 var nom_salle = document.getElementById("nom_salle").value;
  var tel_salle = document.getElementById("tel_salle").value;
   var adresse_salle = document.getElementById("adresse_salle").value;
    var cp_salle = document.getElementById("cp_salle").value;
	 var ville_salle = document.getElementById("ville_salle").value;
	  var web_salle = document.getElementById("web_salle").value;



/** Création du formulaire au format HTML contenu dans l'info-bulle **/
if (web_salle!='') var largeT=110; else var largeT=100;
var formulaire_itineraire ='<div style="padding-top:10px;width:350px; height:'+largeT+'px; border: 1px solid #DE0E65; background:#ffffff; font-size: 8pt;">' +
'<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">' +
'<table width="350" border="0" cellspacing="0" cellpadding="0" class="table_google">' +
'  <tr>' +
'    <td width="99" align="right">Nom : </td>' +
'    <td width="10">&nbsp;</td>' +
'    <td width="243">'+nom_salle+'</td>' +
'  </tr>' +
' <tr>' +
'    <td align="right">T&eacute;l : </td>' +
'    <td>&nbsp;</td>' +
'    <td>'+tel_salle+'</td>' +
'  </tr>' +
'  <tr>' +
'    <td align="right">Adresse : </td>' +
 '   <td>&nbsp;</td>' +
 '   <td>'+adresse_salle+'</td>' +
 ' </tr>' +
'  <tr>' +
 '   <td align="right">Code postal : </td>' +
'    <td>&nbsp;</td>' +
 '   <td>'+cp_salle+'</td>' +
 ' </tr>' +
'  <tr>' +
 '   <td align="right">Ville : </td>' +
'    <td>&nbsp;</td>' +
 '   <td>'+ville_salle+'</td>' +
'  </tr>';
if (web_salle!='') {
formulaire_itineraire +='<tr>' +
 '   <td align="right">Site Web : </td>' +
 '   <td>&nbsp;</td>' +
 '   <td>'+web_salle+'</td>' +
'  </tr>';
}

formulaire_itineraire +='</table>' +
'</div>';
marker.openInfoWindowHtml(formulaire_itineraire);
});
return marker;
}



function sendDataX(data, page, method)
{
    if(document.all)
    {
        //Internet Explorer
        var XhrObj = new ActiveXObject("Microsoft.XMLHTTP") ;
    }//fin if
    else
    {
        //Mozilla
        var XhrObj = new XMLHttpRequest();
    }//fin else
    
    //définition de l'endroit d'affichage:
    //var content = document.getElementById("google");
    
    //si on envoie par la méthode GET:
    if(method == "GET")
    {
        if(data == 'null')
        {
            //Ouverture du fichier sélectionné:
            XhrObj.open("GET", page);
        }//fin if
        else
        {
            //Ouverture du fichier en methode GET
            XhrObj.open("GET", page+"?"+data);
        }//fin else
    }//fin if
    else if(method == "POST")
    {
        //Ouverture du fichier en methode POST
        XhrObj.open("POST", page);
    }//fin elseif
    //Ok pour la page cible
    XhrObj.onreadystatechange = function()
    {
      // if (XhrObj.readyState == 4 && XhrObj.status == 200)
          // content.innerHTML = XhrObj.responseText ;
    }    
    if(method == "GET")
    {
        XhrObj.send(null);
    }//fin if
    else if(method == "POST")
    {
        XhrObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        XhrObj.send(data);
    }//fin elseif
}//fin fonction SendData




    function loadgoogle_map() {
	
		 var search = document.getElementById("search").value;
		 
		 if (search!="") {     
	  map = new GMap(document.getElementById("map"));  
	  
	  //on cache la map 
	  //document.getElementById("map").style.visibility='hidden';
      //document.getElementById("map").style.display='none';
	  //document.getElementById("google").style.visibility='hidden';
      //document.getElementById("google").style.display='none';	  
	  
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      //map.setCenter(new GLatLng(50,0),5);	 
	  
      // ====== Create a Client Geocoder ======
      geo = new GClientGeocoder(); 
	  showAddress();
	  
      // ====== 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,id_etab) {
		  
	
        var point = new GLatLng(lat,lng);
		//alert(lat);
		//alert(lng);
		// si id_etab n est pas null signifie que l'on pas en base on enregistre
		//if (id_etab!="") sendDataX('null', 'enregistre.php?id_etab='+id_etab+'&lat='+lat+'&lng='+lng, 'GET');
		
		    var icon = new GIcon();
           icon.image = "http://www.printempsdurire.org/img/pdrL.png";
           icon.iconSize = new GSize(60, 89);
           icon.iconAnchor = new GPoint(18, 3);
           icon.infoWindowAnchor = new GPoint(60, 1);	
		   
		   		
		
		
        map.setCenter(point,14); 
        //map.addOverlay(new GMarker(point,icon));
		var marker=CreationDuMarqueur(point,icon);
		map.addOverlay(marker);		
		GEvent.trigger(marker,"click"); 
		
		
    	//document.getElementById("message").innerHTML = "";
		//on affiche
	  //document.getElementById("map").style.visibility='visible';
      //document.getElementById("map").style.display='block';
	  document.getElementById("google").style.visibility='visible';
      document.getElementById("google").style.display='block';
      }

      // ====== Geocoding ======
      function showAddress() {
        var search = document.getElementById("search").value;
		var id_etab = document.getElementById("id_etab").value;
		var lx = document.getElementById("lx").value;
		var ly = document.getElementById("ly").value;
		
		
		//lx="";
	     //Pour placer si on a les coordonnees dans l hidden
		 if (lx!="")  place(lx,ly,"");		
		if ( (id_etab!="") && (search!="") && (lx=="") ) {
			
		//alert ('on cherche: '+search);
		
        // ====== 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) { 
               // document.getElementById("message").innerHTML = "Did you mean:";
                // 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;
				//alert ("on place etab");
                place(p[1],p[0],id_etab);
              }
            }
            // ====== 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 "'+encodeURI(search)+ '" ' + reason);
			  	 document.getElementById("google").style.visibility='hidden';
                 document.getElementById("google").style.display='none';
				 
				//sendDataX('null', 'enregistrepb.php?id_etab='+id_etab+'&adresse='+encodeURI(search), 'GET');
            }
          }
		  
	
		  
		  
        );
		}
      }
    }
    
	


function tester_google () {
	

	 if (document.getElementById("search")) {	
		 loadgoogle_map();		 
		 }
	
}
	
	
