// JavaScript Document.
/*document.write('<' + 'script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA" type="text/javascript"></script>');*/
  //KEY DU PDB
document.write('<' + 'scriptsrc="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAALECn_De1uvV_6py6n0rG3xQsvuqmVgfutFAXPV9RGZvqOJPTHBRehI_j_YDrYkbt06fYrtO3SGiW-g" type="text/javascript"></script>');

var http = createRequestObject();		// Instanciation de l'objet XMLHttpRequest
var action; // globale permettant d'utiliser la méthode handleResponse
var map;  //Object pour google Map
var gdir; //Sert pour l'itinéraire de Google Map
var trafficInfo; //Affiche le traffic info

function Son1() {
	eval("document.son1.play();");
}
function Son2() {
	eval("document.son2.play();");
}
function Son3() {
	eval("document.son3.play();");
}
function Son4() {
	eval("document.son4.play();");
}
function Son5() {
	eval("document.son5.play();");
}
function Son6() {
	eval("document.son6.play();");
}
function Son7() {
	eval("document.son7.play();");
}
function Son8() {
	eval("document.son8.play();");
}
function Son9() {
	eval("document.son9.play();");
}
function Son10() {
	eval("document.son10.play();");
}

// fontion appelé par la variable http permettant de créer l'objet ajax en fonction du navigateur et du système d'exploitation
function createRequestObject() {
        var req=false;
        if(window.XMLHttpRequest){	// Firefox, Safari, Opera...
		req = new XMLHttpRequest();
		if (req.overrideMimeType) req.overrideMimeType('text/xml');
        } else if(window.ActiveXObject) { // Internet Explorer 5+
        	try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}	
        } else {
            // Affichage erreur lorsque explorateur internet obsolete
            alert("Votre navigateur n'est pas compatible avec la technologie Ajax.");
        }
    return req;
} 

// appel de la fonction maj_conteneur via un fichier index.php par ex
function maj_conteneur(url,div){
	

	//alert('Je Passe dans la Fonction :' + url + div)
	action=div;
	
	http.open('GET', url, true);
	http.onreadystatechange = handleResponse;
	http.send(null);
}

function handleResponse() {

	if(http.readyState == 4 && http.status == 200){
		if(http.responseText){
			
			switch (action){
				case 1:
				// nomdetadiv sera par exemple la div de ton conteneur
					//alert(http.responseText);
					document.getElementById('Centre').innerHTML = http.responseText;
				break;
				
				case 2:
				// nomdetadiv sera par exemple la div de ton conteneur
					//alert(http.responseText);
					document.getElementById('Attrac_Contener').innerHTML = http.responseText;
				break;
				
			}
		}
	}
}


function alter()
{
	alert();
}

function nav()
{
	var NavName = navigator.appName;
	var NavVers = navigator.appVersion;
		
	if (NavVers.indexOf('MSIE 8') > 0)
	{
		ie8 = true;
	}else{
		ie8 = false;
	}
	
	if (ie8==true) {
		//alert('IE8 : ' + NavVers);
		document.getElementById("lienCSS").href="parcIE8.css"; 
	}else{
		//alert('Autre : ' + NavName + ' ' + NavVers);
		document.getElementById("lienCSS").href="parc.css"; 
	}
	
}


function initializeMap() {
        if (GBrowserIsCompatible()) {
	    var point = new GLatLng(49.602391,1.079103);
        map = new GMap2(document.getElementById("map_canvas"));
		gdir = new GDirections(map, document.getElementById("map_direction"));
        map.setCenter(new GLatLng(49.608708,1.080437), 13);
    	map.addOverlay(new GMarker(point));
		var trafficOptions = {incidents:true};
        trafficInfo = new GTrafficOverlay(trafficOptions);
        map.addOverlay(trafficInfo);
        map.setUIToDefault();
      }
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load("from: " + fromAddress + " to: " + toAddress,
  { "locale": locale , "getSteps":true});
}

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_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.");
}
  
///////////////////////////////////////////////////////////////////////

/**
* The add-on code for draggable markers
* @author Esa 2008
*/
var newMarkers = [];
var latLngs = [];
var icons = [];

// Note the 'addoverlay' GEvent listener inside initialize() function of the original code (above).
// 'load' event cannot be used

function onGDirectionsAddOverlay(){ 
  // Remove the draggable markers from previous function call.
  for (var i=0; i<newMarkers.length; i++){
    map.removeOverlay(newMarkers[i]);
  }

  // Loop through the markers and create draggable copies
  for (var i=0; i<=gdir.getNumRoutes(); i++){
    var originalMarker = gdir.getMarker(i);
    latLngs[i] = originalMarker.getLatLng();
    icons[i] = originalMarker.getIcon();
    newMarkers[i] = new GMarker(latLngs[i],{icon:icons[i], draggable:true, title:'Draggable'});
    map.addOverlay(newMarkers[i]);

    // Get the new waypoints from the newMarkers array and call loadFromWaypoints by dragend
    GEvent.addListener(newMarkers[i], "dragend", function(){
      var points = [];
      for (var i=0; i<newMarkers.length; i++){
        points[i]= newMarkers[i].getLatLng();
      }
      gdir.loadFromWaypoints(points);
    });

    //Bind 'click' event to original markers 'click' event
    copyClick(newMarkers[i],originalMarker);

    // Now we can remove the original marker safely
    map.removeOverlay(originalMarker);
  }

  function copyClick(newMarker,oldMarker){
    GEvent.addListener(newMarker, 'click', function(){
      GEvent.trigger(oldMarker,'click');
    });
  }
}

