// JavaScript Document

var xhr=null;
function load() {
	if (GBrowserIsCompatible()) {
		

	    var map = new GMap2(document.getElementById("map"));
		var directionsPanel = document.getElementById("my_textual_div");
	    map.setCenter(new GLatLng(48.827351,-3.479576), 8);
		
	    var le_ranolien= new GMarker(new GLatLng(48.827351,-3.479576));
		var mapControl = new GMapTypeControl();
		map.enableScrollWheelZoom();
		map.addControl(new GScaleControl()); 
		map.enableContinuousZoom(); 
		map.addControl(mapControl);
		map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(130,20)));
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,60));
		var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
		map.addControl(new GOverviewMapControl(),new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10)));
		map.addControl(new GLargeMapControl());
		map.addOverlay(le_ranolien);
	}
}
GSearch.setOnLoadCallback(load);
function setDirections(fromAddress, toAddress, locale) {
      directions.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     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)
	     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.");
	   
	}

	function onGDirectionsLoad(){ 
      // Use this function to access information about the latest load()
      // results.

      // e.g.
      // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	}

function getXhr()
 {
  if(window.XMLHttpRequest) xhr = new XMLHttpRequest();
  else if(window.ActiveXObject)
   {
    try
     {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch (e)
     {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
     }
   }
  else
   {
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour");
    xhr = false;
   }
 }

 function affiche(choix){
  GUnload();
  getXhr();
  xhr.onreadystatechange = function(){
  if(xhr.readyState == 4 &&  xhr.status== 200){
     document.getElementById("map").innerHTML=xhr.responseText;
    }
  }
  xhr.open("POST",'localisation/ajaxaffiche.php',true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  if (choix=="selection"){
	if(document.getElementById("selection").value!=" "){
      xhr.send("choix="+document.getElementById("selection").value); 
	}
  }else{
    xhr.send("choix="+choix);
  }
 }
load();


