function ModeAffichage(IdMode)
{
	var ModeAffichageRequest = null;

	// Définition du connecteur en fonction du navigateur :
	if(window.XMLHttpRequest)
	 {///////////////////////////////////// Firefox et autres
          ModeAffichageRequest = new XMLHttpRequest();
     }else if(window.ActiveXObject){
	  /////////////////////////////////// Internet Explorer
          ModeAffichageRequest = new ActiveXObject("Microsoft.XMLHTTP");
	 }else{
	 /////////////////////////////////// XMLHttpRequest non supporté par le navigateur
     	  return(false)
	 }

	var data = "IdMode="+escape(IdMode)+"&OldSearchValue="+escape(document.getElementById("OldSearchValue").value) ;

	ModeAffichageRequest.onreadystatechange = function()
	{
		if(ModeAffichageRequest.readyState == 4 )
		{
			// Ici le code 200 signifie que la requête a renvoyé une valeur valide. On pourrait aussi gérer les erreurs 500, 404 ...
			if( ModeAffichageRequest.status == 200 )
			{
				ModeAffichageResponse = ModeAffichageRequest.responseText.split('[#]');

				if(IdMode == 1 && ModeAffichageResponse[2] == "0")
				{
					document.getElementById("map").style.visibility = "visible";
					document.getElementById("map").style.height = "650px";
				}
				else if(IdMode == 1 && ModeAffichageResponse[2] != "0")
				{
					document.getElementById("map").style.background = 'url(images/commun/divers/loader.gif)';
					document.getElementById("map").style.visibility = "visible";
					document.getElementById("map").style.height = "650px";

					var MAP = new google.maps.Map2(document.getElementById('map'));
					MAP.setCenter(new GLatLng(47.294134,2.922363),5);
					MAP.addControl(new GSmallMapControl());
					MAP.addControl(new GMapTypeControl());
		        	MAP.addMapType(G_PHYSICAL_MAP);
		        	MAP.addMapType(G_SATELLITE_MAP);
					MAP.setMapType(G_PHYSICAL_MAP);
					MAP.enableContinuousZoom();
					window.unload = GUnload;

					////////////////////////////////////////////////////////////////////////////
					RafraichirGoogleMapResponse = ModeAffichageResponse[2].split('[GOOGLEMAP]');

					if(document.getElementById("OldSearchValue").value != "" && parseInt(RafraichirGoogleMapResponse[0]) != 0)
					{

						//On recupere les coord geloc
						var zoom_encompass = true;
						CoordGeoloc = RafraichirGoogleMapResponse[0].split('||');
						var Latitude = parseFloat(CoordGeoloc[0]);
						var Longitude = parseFloat(CoordGeoloc[1]);
						var Zoom = parseFloat(CoordGeoloc[2]);

						//on ajoute
						function createMarker(point,html,Lien)
						{
						   	var icon = new GIcon();
							icon.image = "http://www.zevisit.com/VirgulePub/GoogleEarth/defaut.png";
							icon.iconSize = new GSize(24, 20);
							icon.iconAnchor = new GPoint(6, 20);
							icon.infoWindowAnchor = new GPoint(15, 1);
							var marker = new GMarker(point,icon);
						    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(Lien);});
						    return marker;
						}

						var bounds = new GLatLngBounds;

						for (i=1;i<RafraichirGoogleMapResponse.length;i++)
						{
							CoordGeoloc = RafraichirGoogleMapResponse[i].split('||');
							var Id = parseInt(CoordGeoloc[0]);
							var LatitudeCircuit = parseFloat(CoordGeoloc[1]);
							var LongitudeCircuit = parseFloat(CoordGeoloc[2]);
							var Lien = CoordGeoloc[3];
							var NomCircuit = CoordGeoloc[4];
							bounds.extend(new GLatLng(LatitudeCircuit,LongitudeCircuit));
							var point = new GLatLng(LatitudeCircuit, LongitudeCircuit);
							var marker = createMarker(point,NomCircuit,Lien);
						    MAP.addOverlay(marker);
						}
						MAP.setZoom(MAP.getBoundsZoomLevel(bounds));
						MAP.setCenter(bounds.getCenter());
					}
					////////////////////////////////////////////////////////////////////////////
				}
				else
				{
					document.getElementById("map").style.visibility = "hidden";
					document.getElementById("map").style.height = "0px";
				}

				//document.getElementById("ModeAffichage").innerHTML = ModeAffichageResponse[0];
				document.getElementById("LesDestinations").innerHTML = ModeAffichageResponse[1];
			}
		}
	};

	// le secret d'AJAX réside également dans l'envoi de la requête en background ( sans recharger la page ) :
	ModeAffichageRequest.open("POST", "ModeAffichageHomepage.php", true);
	ModeAffichageRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ModeAffichageRequest.send(data);

}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
function sndReq(action) {
    http.open('get', action);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

var httpSearchSubmit = createRequestObject();
function sndReqSearchSubmit(action) {
    httpSearchSubmit.open('get', action);
    httpSearchSubmit.onreadystatechange = handleResponseSearchSubmit;
    httpSearchSubmit.send(null);
}

var httpSearchHomePage = createRequestObject();
function sndReqSearchHomePage(action) {
    httpSearchHomePage.open('get', action);
    httpSearchHomePage.onreadystatechange = handleResponseSearchHomePage;
    httpSearchHomePage.send(null);
}

var httpSearchHomePageTexte = createRequestObject();
function sndReqSearchHomePageTexte(action) {
    httpSearchHomePageTexte.open('get', action);
    httpSearchHomePageTexte.onreadystatechange = handleResponseSearchHomePageTexte;
    httpSearchHomePageTexte.send(null);
}


function handleResponse() {
    if(http.readyState == 4){
		document.getElementById("SearchResultsDiv").innerHTML = http.responseText;
    }
}

function handleResponseSearchSubmit() {
    if(httpSearchSubmit.readyState == 4){
		document.getElementById("SearchResultsDiv").innerHTML = "";
		document.getElementById("AudioGuideDisponible").innerHTML = httpSearchSubmit.responseText;
		document.getElementById("SearchValue").value = "";
		document.getElementById("SearchResultsDiv").innerHTML = "";
    }
}

function handleResponseSearchHomePage()
{
	if(httpSearchHomePage.readyState == 4)
    {		
		SearchHomePageResponse = httpSearchHomePage.responseText.split('[#]');
		document.getElementById("AudioGuideDisponible").innerHTML = SearchHomePageResponse[0];

		var MAP = new google.maps.Map2(document.getElementById('map'));
		MAP.setCenter(new GLatLng(47.294134,2.922363),5);
		MAP.addControl(new GSmallMapControl());
        MAP.addControl(new GMapTypeControl());
	    MAP.addMapType(G_PHYSICAL_MAP);
	    MAP.addMapType(G_SATELLITE_MAP);
		MAP.setMapType(G_PHYSICAL_MAP);
		MAP.enableContinuousZoom();
		window.unload = GUnload;

		function createMarker(point,html,Lien)
		{
		   	var icon = new GIcon();
			icon.image = "http://www.zevisit.com/VirgulePub/GoogleEarth/defaut.png";
			icon.iconSize = new GSize(24, 20);
			icon.iconAnchor = new GPoint(6, 20);
			icon.infoWindowAnchor = new GPoint(15, 1);
			var marker = new GMarker(point,icon);
		    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(Lien);});
		    return marker;
		}

		if(parseInt(SearchHomePageResponse[1]) != 0)
		{
			var zoom_encompass = true;
			var bounds = new GLatLngBounds;

			for (i=1;i<SearchHomePageResponse.length;i++)
			{
				CoordGeoloc = SearchHomePageResponse[i].split('||');
				var Id = parseInt(CoordGeoloc[0]);

				if(Id != "Undefined")
				{
					var LatitudeCircuit = parseFloat(CoordGeoloc[1]);
					var LongitudeCircuit = parseFloat(CoordGeoloc[2]);
					var Lien = CoordGeoloc[3];
					var Nom = CoordGeoloc[4];

					if(LatitudeCircuit!= '0.0' && LongitudeCircuit!='0.0')
					{
					    bounds.extend(new GLatLng(LatitudeCircuit,LongitudeCircuit));
						var point = new GLatLng(LatitudeCircuit, LongitudeCircuit);
						var marker = createMarker(point,Nom,Lien);
					 	MAP.addOverlay(marker);
				   	}
			   	}
			}

			MAP.setZoom(MAP.getBoundsZoomLevel(bounds));
			MAP.setCenter(bounds.getCenter());
		}
	}

	document.getElementById("SearchResultsDiv").innerHTML = "";
	document.getElementById("OldSearchValue").value = document.getElementById("SearchValue").value;
	document.getElementById("map").onclick = '';
}

function SearchHomePage(SearchValue, Identifiant ) {
	var val = 'RechercheThemeSearchSubmit.php?SearchValue='+escape(SearchValue)+'&Identifiant='+Identifiant;
	sndReqSearchHomePage(val);
	return false;
}


function SearchSubmit() {
	var val = 'RechercheThemeSearchSubmit.php?SearchValue='+ document.getElementById("SearchValue").value+'&Identifiant='+document.getElementById("Identifiant").value;
	sndReqSearchSubmit(val);
	return false;
}

function doSearch() {
	var val = 'RechercheTheme.php?SearchValue='+escape(document.getElementById("SearchValue").value)+'&Identifiant='+document.getElementById("Identifiant").value;
	sndReq(val);
	return false;
}

//Fonction permettant de rafraichir la gg map
function RafraichirGoogleMap(IdTheme,Identifiant)
{
	var RafraichirGoogleMapRequest = null;

	// Définition du connecteur en fonction du navigateur :
	if(window.XMLHttpRequest)
	 {///////////////////////////////////// Firefox et autres
          RafraichirGoogleMapRequest = new XMLHttpRequest();
     }else if(window.ActiveXObject){
	  /////////////////////////////////// Internet Explorer
          RafraichirGoogleMapRequest = new ActiveXObject("Microsoft.XMLHTTP");
	 }else{
	 /////////////////////////////////// XMLHttpRequest non supporté par le navigateur
     	  return(false)
	 }

	var data = "IdTheme="+escape(IdTheme)+"&Identifiant="+escape(Identifiant);

	RafraichirGoogleMapRequest.onreadystatechange = function()
	{

		if( RafraichirGoogleMapRequest.readyState == 4 )
		{
			// Ici le code 200 signifie que la requête a renvoyé une valeur valide. On pourrait aussi gérer les erreurs 500, 404 ...
			if( RafraichirGoogleMapRequest.status == 200 )
			{
				RafraichirGoogleMapResponse = RafraichirGoogleMapRequest.responseText.split('[#]');

				//On recupere les coord geloc
				CoordGeoloc = RafraichirGoogleMapResponse[0].split('||');
				var Latitude = parseFloat(CoordGeoloc[0]);
				var Longitude = parseFloat(CoordGeoloc[1]);
				var Zoom = parseFloat(CoordGeoloc[2]);
				var zoom_encompass = true;

				var MAP = new google.maps.Map2(document.getElementById('map'+IdTheme));
				MAP.setCenter(new GLatLng(47.294134,2.922363),5);
				MAP.addControl(new GSmallMapControl());
        		MAP.addControl(new GMapTypeControl());
        		MAP.addMapType(G_PHYSICAL_MAP);
        		MAP.addMapType(G_SATELLITE_MAP);
				MAP.setMapType(G_PHYSICAL_MAP);
				MAP.enableContinuousZoom();
				window.unload = GUnload;

				//on ajoute
				function createMarker(point,html,Lien)
				{
			    	var icon = new GIcon();
					icon.image = "http://www.zevisit.com/VirgulePub/GoogleEarth/defaut.png";
					icon.iconSize = new GSize(24, 20);
					icon.iconAnchor = new GPoint(6, 20);
					icon.infoWindowAnchor = new GPoint(15, 1);
					var marker = new GMarker(point,icon);
					GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html);});
			        //GEvent.addListener(marker, "click", function() {  window.location=Lien;});
			        //GEvent.addListener(marker,"mouseover", function() {marker.openInfoWindowHtml(html);});
					//GEvent.addListener(marker,"mouseout", function() {marker.closeInfoWindow()});
			        return marker;
			    }

				var bounds = new GLatLngBounds;
				for (i=1;i<RafraichirGoogleMapResponse.length;i++)
				{
					CoordGeoloc = RafraichirGoogleMapResponse[i].split('||');
					var Id = parseInt(CoordGeoloc[0]);
					var LatitudeCircuit = parseFloat(CoordGeoloc[1]);
					var LongitudeCircuit = parseFloat(CoordGeoloc[2]);
					var Lien = CoordGeoloc[3];
					var NomCircuit = CoordGeoloc[4];

					bounds.extend(new GLatLng(LatitudeCircuit,LongitudeCircuit));
					var point = new GLatLng(LatitudeCircuit, LongitudeCircuit);
					var marker = createMarker(point,NomCircuit,Lien);
					MAP.addOverlay(marker);
				}

				MAP.setZoom(MAP.getBoundsZoomLevel(bounds));
				MAP.setCenter(bounds.getCenter());

				document.getElementById("SearchResultsDiv").innerHTML = "";
				document.getElementById("OldSearchValue").value = 	document.getElementById("SearchValue").value;
				document.getElementById("SearchValue").value = "";
			}
		}
	};

	// le secret d'AJAX réside également dans l'envoi de la requête en background ( sans recharger la page ) :
	RafraichirGoogleMapRequest.open("POST", "RechercheRafraichirGoogleMap.php", true);
	RafraichirGoogleMapRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	RafraichirGoogleMapRequest.send(data);
}

//---------------------------------------------------------------
// Mise à jour du message destiné à l'utilisateur sans recharger la page
// Traitement du résultats de la recherche (guide audio et a proximité)
function ResultatsTraiterDestination(IdTheme,Identifiant)
{
	var ResultatsTraiterDestinationRequest = null;

	// Définition du connecteur en fonction du navigateur :
	if(window.XMLHttpRequest)
	 {///////////////////////////////////// Firefox et autres
          ResultatsTraiterDestinationRequest = new XMLHttpRequest();
     }else if(window.ActiveXObject){
	  /////////////////////////////////// Internet Explorer
          ResultatsTraiterDestinationRequest = new ActiveXObject("Microsoft.XMLHTTP");
	 }else{
	 /////////////////////////////////// XMLHttpRequest non supporté par le navigateur
     	  return(false)
	 }

	var data = "Identifiant="+escape(Identifiant);

	ResultatsTraiterDestinationRequest.onreadystatechange = function()
	{

		if( ResultatsTraiterDestinationRequest.readyState == 4 )
		{
			// Ici le code 200 signifie que la requête a renvoyé une valeur valide. On pourrait aussi gérer les erreurs 500, 404 ...
			if( ResultatsTraiterDestinationRequest.status == 200 )
			{
				ResultatsTraiterDestinationResponse = ResultatsTraiterDestinationRequest.responseText.split('<!-- [SEPARATION] -->');
				//Mise a jour
				document.getElementById("AudioGuideDisponible").innerHTML = ResultatsTraiterDestinationResponse[0];
				document.getElementById("AProximite").innerHTML = ResultatsTraiterDestinationResponse[1];
				document.getElementById("SearchValue").value = "";
				document.getElementById("SearchResultsDiv").innerHTML = "";
			}
		}
	};

	// le secret d'AJAX réside également dans l'envoi de la requête en background ( sans recharger la page ) :
	ResultatsTraiterDestinationRequest.open("POST", "RechercheTraiterDestination.php", true);
	ResultatsTraiterDestinationRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ResultatsTraiterDestinationRequest.send(data);
}