// JavaScript Document
var lang;
var map;
var mapsBounds;
var startZoom;
var zoomcourant;
var code_sep = ',';
var nb_ann_list = 30;
var type_trans = 90;
var tb_markers;
var icon;
var icon1;
var iconV;
var iconL;
var iconLV;

// Mots en francais
var annonce_fr = 'annonce';
var region_parisienne_fr = "Région Parisienne";
var piece_fr = "pièce";
var mois_fr = "mois";
var detail_fr = "détail";
var maj_fr = "Mise à jour";
var ref_fr = "Réf";
var vente_fr = "Vente";
var location_fr = "Location";
var vacances_fr = "Vacances";
var terrain_fr = "terrain";
var terrasse_fr = "terrasse";
var chambres_fr = "chambres";
var supp_selection_fr = 'Supprimez de "Ma S&eacute;lection"';
var add_selection_fr = 'Ajouter &agrave; "Ma S&eacute;lection"';

// Mots en anglais
var annonce_en = 'ad';
var region_parisienne_en = "Paris Region"; 
var piece_en = "room";
var mois_en = "month";
var detail_en = "detail";
var maj_en = "Update";
var ref_en = "Ref";
var vente_en = "Sale";
var location_en = "Rent";
var vacances_en = "Holidays";
var terrain_en = "field";
var terrasse_en = "terrasse";
var chambres_en = "bedrooms";
var supp_selection_en = 'Delete My selection ';
var add_selection_en = "Add to 'My selection'";

// Mots en espagnol
var annonce_es = 'anuncio';
var region_parisienne_es = "Región de París";
var piece_es = "habitacion";
var mois_es = "meses";
var detail_es = "detalle";
var maj_es = "Actualizado";
var ref_es = "Ref";
var vente_es = "Venta";
var location_es = "Llegadas";
var vacances_es = "Vacaciones";
var terrain_es = "terreno";
var terrasse_es = "terrasse";
var chambres_es = "dormitorio";
var supp_selection_es = 'Ma Quitar selección';
var add_selection_es = 'Añadir a mi selección';

var supp_selection;
var add_selection;

	function init(lg) {
		lang = lg;
		switch (lang) {
			case 'en' :
				supp_selection = supp_selection_en;
				add_selection = add_selection_en;
				break;
			case 'es' :
				supp_selection = supp_selection_es;
				add_selection = add_selection_es;
				break;
			default :
				supp_selection = supp_selection_fr;
				add_selection = add_selection_fr;
				break;
    	}
	}
	
	function marker_tab () {
		var marker = new GMarker(coord);
		var window = function() {
		    var tabs = [
		            new GInfoWindowTab('Infos',
		                    '<strong>Place Bellecour</strong>' +
		                    '<br /><img src="images/place-bellecour-miniature.jpg" alt="" />' +
		                    '<br /><a href="http://fr.wikipedia.org/wiki/Place_Bellecour">Voir l\'article sur Wikipedia (fr)</a>'
		               ),
		            new GInfoWindowTab('Metro', 
		                    '<span id="metroA">Metro A</span>' +
		                    '<br /><span id="metroD">Metro D</span>'
		               )
		        ];
		 
		    marker.openInfoWindowTabsHtml(tabs);
		};
		GEvent.addListener(marker, "click", window);
		map.addOverlay(marker);
	}
	
	function marker_simple() {
		var marker = new GMarker(coord);
 
		var window = function() {
		    marker.openInfoWindowHtml(
		            '<strong>Place Bellecour</strong>' +
		            '<br /><img src="images/place-bellecour-miniature.jpg" alt="" />' +
		            '<br /><a href="http://fr.wikipedia.org/wiki/Place_Bellecour">Voir l\'article sur Wikipedia (fr)</a>'
		      );
		};
		 
		GEvent.addListener(marker, "click", window);
		map.addOverlay(marker);
	}
 

    function addMarkersToMap(latitude, longitude, description) {
    	var marker = new GMarker(new GLatLng(latitude,longitude),icon);
    	tb_markers.push(marker);
    	var options = {maxWidth:208};
    	/*GEvent.addListener(marker, 'click',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);*/
    	GEvent.addListener(marker, 'mouseover',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);
    	map.addOverlay(marker);    	
    }
    
    
    
	function addMarkersToMapMonde(latitude, longitude, description,icon) {
	    //var marker = new GMarker(posn, {title: title, icon: icon, draggable:true });
		var title = "essai ";
    	var marker = new GMarker(new GLatLng(latitude,longitude),{icon:icon, draggable:true} );
    	tb_markers.push(marker);
    	var options = {maxWidth :100};
    	/*GEvent.addListener(marker, 'click',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);*/
    	GEvent.addListener(marker, 'mouseover',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);
    	map.addOverlay(marker);    	
    }
    function addMarkersToMap1(latitude, longitude, description) {
	    //var marker = new GMarker(posn, {title: title, icon: icon, draggable:true });
		var title = "essai ";
    	var marker = new GMarker(new GLatLng(latitude,longitude),{title:title, icon:icon1, draggable:true} );
    	tb_markers.push(marker);
    	var options = {maxWidth :50};
    	/*GEvent.addListener(marker, 'click',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);*/
    	GEvent.addListener(marker, 'mouseover',
    		function () {
    			marker.openInfoWindowHtml(description,options);
    			
    		}
    	);
    	map.addOverlay(marker);    	
    }
     function addAddressToMap(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
		map.setCenter(point, 13);
      }
    }
      
    function showLocation(address) {
	  // alert("showLocation " + address)
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
      icon.image = "icones/bleu.png";
      icon.shadow = "icones/mm_20_shadow.png";
      icon.iconSize = new GSize(12, 20);
      icon.iconAnchor = new GPoint(7, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
	  map = new GMap2(document.getElementById("map"));
	 
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  var controlPosition2 = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(30, 30));
	  map.addControl(new GOverviewMapControl());
	  var options = {
	  	resultList : document.getElementById("results"),
		suppressZoomToBounds : true
	  };
	  lsc = new google.maps.LocalSearch(options);
	  var controlPosition = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(0, -30));
	  map.addControl(lsc,controlPosition);
	  geocoder = new GClientGeocoder();
      geocoder.getLocations(address, addAddressToMap);     
    }
    
    function showListePays(latitude,longitude,recInfos) {
    	//alert ("showListePays " + recInfos);
		icon = new GIcon();// mm_20_blue.png,mm_20_red.png
		icon.image = "icones/vermillon.png";
	    icon.shadow = "icones/mm_20_shadow.png";

	    icon.iconSize = new GSize(13, 23);
	    //icon.shadowSize = new GSize(22, 20);
	    icon.iconAnchor = new GPoint(7, 20);
	    icon.infoWindowAnchor = new GPoint(5, 1);
	      
		map = new GMap2(document.getElementById("acMap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(latitude, longitude),5);
		 var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_liste_pays(xhr); };
	    map.clearOverlays();
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
		var url =  "reponse_etranger.php?recherche_infos[loc_pays]="+recInfos.substr(2,2);
		var url =  "reponse_etranger.php";
		alert (url);
	    xhr.open("GET", url, true);
	    xhr.send(null);
    }
    
    function alert_ajax_liste_pays(xhr) {
    	if (xhr.readyState==4) {
			var docXML= xhr.responseXML;
			var items = docXML.getElementsByTagName("code_postal")
			//on fait juste une boucle sur chaque element "donnee" trouvé
			document.getElementById("messageAccueil").className="tumevoispas";
			var items = docXML.getElementsByTagName("code_postal");    
			//on fait juste une boucle sur chaque element "code_postal" trouvé
			var nbItemsCP = items.length;
			for (i=0;i<nbItemsCP;i++)
			{
				var nombre = items.item(i).getAttribute("nb");
				var latitude = items.item(i).getAttribute("latitude");
				var longitude = items.item(i).getAttribute("longitude");
				var nom = items.item(i).getAttribute("nom");
				if (items.item(i).firstChild.data != null ) {
					var code_postal = items.item(i).firstChild.data;
				} else {
					var code_postal = "00000";

				}
	    		var url =  'index.php?module=afficherAnnonces&code_trans=90&recherche_infos[localisation]=';
	    		url += code_postal;
	    		
	    		var description = "<div align='center'>";
	    		var ann;
	    		switch (lang) {
	    			case 'en' :
	    				ann = annonce_en;
	    				break;
					case 'es' :
	    				ann = annonce_es;
	    				break;
	    			default :
	    				ann = annonce_fr;
	    				break;
	    		}
	    		description +=  "<br>  " + nom;
	    		description += '<br> <a href=" ' + url + '"> ' + nombre + ' ' + ann ;
	    		if (nombre > 1 ) description += 's';
	    		description += ' </a></div>';
	    		//alert ("description" + description);
	    		
	    		if (nombre > 0 ) {
		    		addMarkersToMap(latitude , longitude,
				      	description);
				}
	    	}
		}
	}

    function showListeMondeTT(latitude,longitude) {
	  iconV = new GIcon();// mm_20_blue.png,mm_20_red.png
	  iconV.image = "icones/bleu.png";
      iconV.shadow = "icones/mm_20_shadow.png";
      iconV.iconSize = new GSize(11, 20);
      iconV.iconAnchor = new GPoint(7, 20);
      iconV.infoWindowAnchor = new GPoint(5, 1);
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),1);
      // recuperation des données
       var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_mondeTT(xhr); };
	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
		
	    //on appelle le fichier reponse.txt
		var url = "reponse_monde.php";
		//alert (url);
	    xhr.open("GET", url, true);
	    xhr.send(null);
    }
    // 
    function alert_ajax_mondeTT(xhr) {
    	 if (xhr.readyState==4) 
	    {
	    	var docXML= xhr.responseXML;
	    	var items = docXML.getElementsByTagName("donnee")
	    	//on fait juste une boucle sur chaque element "donnee" trouvé
	    	document.getElementById("messageAccueil").className="tumevoispas";
	    	for (i=0;i<items.length;i++)
	    	{
	    		var itemNom = docXML.getElementsByTagName("nom")
	    		var nom = itemNom.item(i).firstChild.data;
	    		var itemDpt = docXML.getElementsByTagName("dpt")
	    		var dpt = itemDpt.item(i).firstChild.data;
	    		var itemLat = docXML.getElementsByTagName("latitude")
	    		var latitude = itemLat.item(i).firstChild.data;
	    		var itemLong = docXML.getElementsByTagName("longitude")
	    		var longitude = itemLong.item(i).firstChild.data;
	    		var itemNb = docXML.getElementsByTagName("nbannonces")
	    		var nombre = itemNb.item(i).firstChild.data;
	    		var itemNbV = docXML.getElementsByTagName("nb_vente")
	    		var nombre_vente = itemNbV.item(i).firstChild.data;
	    		var itemNbL = docXML.getElementsByTagName("nb_location")
	    		var nombre_location = itemNbL.item(i).firstChild.data;
	    		var itemNbVL = docXML.getElementsByTagName("nb_vacances")
	    		var nombre_vacances = itemNbVL.item(i).firstChild.data;
	    		var itemInfos = docXML.getElementsByTagName("recinfos")
	    		var recInfos = itemInfos.item(i).firstChild.data;
	    		var url =  'index.php?module=afficherAnnonces&code_trans=90&recherche_infos[localisation]=';
	    		url += recInfos;
	    		var url_vente =  'index.php?module=afficherAnnonces&code_trans=10&recherche_infos[localisation]=';
	    		url_vente += recInfos;
	    		var url_location =  'index.php?module=afficherAnnonces&code_trans=20&recherche_infos[localisation]=';
	    		url_location += recInfos;
	    		var url_vacances =  'index.php?module=afficherAnnonces&code_trans=30&recherche_infos[localisation]=';
	    		url_vacances += recInfos;
	    		var description = "<div align='center'>";
	    		var ann;
	    		switch (lang) {
	    			case 'en' :
	    				ann = annonce_en;
	    				break;
					case 'es' :
	    				ann = annonce_es;
	    				break;
	    			default :
	    				ann = annonce_fr;
	    				break;
	    		}
	    		
	    		//alert ("description" + description);
	    		
	    		if (nombre > 0 ) {
					//alert ("compteur " + compteur + " " + latitude + " " + longitude)
					fct_pays = 'showListePays('+latitude+','+longitude+',\''+recInfos+'\')';
					
			 		description += '<button type="button" style=" cursor:hand; border:solid 0px black;;background-color: #C5C8B5;"';
					description += 'onclick="JavaScript:'+fct_pays+'" >';
					description += nom + '</button>';
			 		description +=  ' <span  style="cursor:hand;" onclick="JavaScript:'+fct_pays+'" >' + nom ;
		    		description +=  nombre + ' ' + ann ;
		    		if (nombre > 1 ) description += 's';
		    		description += '</span>';
		    		if (nombre_vente > 0) {
			    		description += '<br> <a href=" ' + url_vente + '"> Vente : ' + nombre_vente + ' ' + ann ;
			    		if (nombre > 1 ) description += 's';
			    		description += ' </a>';
		    		}
		    		if (nombre_location > 0) {
			    		description += '<br> <a href=" ' + url_location + '"> Location : ' + nombre_location + ' ' + ann ;
			    		if (nombre > 1 ) description += 's';
			    		description += ' </a>';
		    		}
		    		if (nombre_vacances > 0) {
			    		description += '<br> <a href=" ' + url_vacances + '"> Vacances : ' + nombre_vacances + ' ' + ann ;
			    		if (nombre > 1 ) description += 's';
			    		description += ' </a>';
		    		}
		    		description += ' </div>';
		    		addMarkersToMapMonde(latitude , longitude,
				      	description,icon);
				}
	    	}
	    }
    }
    
    var compteur = 0;
    
    function showListeMonde(latitude,longitude) {
	  iconV = new GIcon();// mm_20_blue.png,mm_20_red.png
	  iconV.image = "icones/bleu.png";
      iconV.shadow = "icones/mm_20_shadow.png";
      iconV.iconSize = new GSize(11, 20);
      iconV.iconAnchor = new GPoint(7, 20);
      iconV.infoWindowAnchor = new GPoint(5, 1);
      iconL = new GIcon();// mm_20_blue.png,mm_20_red.png
	  iconL.image = "icones/vermillon.png";
      iconL.shadow = "icones/mm_20_shadow.png";
      iconL.iconSize = new GSize(11, 20);
      iconL.iconAnchor = new GPoint(7, 20);
      iconL.infoWindowAnchor = new GPoint(5, 1);
	  iconLV = new GIcon();// mm_20_blue.png,mm_20_red.png
	  iconLV.image = "icones/vert.png";
      iconLV.shadow = "icones/mm_20_shadow.png";
      iconLV.iconSize = new GSize(11, 20);
      iconLV.iconAnchor = new GPoint(7, 20);
      iconLV.infoWindowAnchor = new GPoint(5, 1);
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),1);
      // recuperation des données
	  compteur = 0;
      ajaxMonde(10);
    }

    function ajaxMonde(code_trans)
	{
	    var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_monde(xhr); };
	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
		
	    //on appelle le fichier reponse.txt
		type_trans = code_trans;
		var url = "reponse_monde.php?code_trans="+code_trans;
		//alert (url);
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}
   
	function alert_ajax_monde(xhr)
	{
	   if (xhr.readyState==4) 
	    {
	    	var docXML= xhr.responseXML;
	    	var items = docXML.getElementsByTagName("donnee")
	    	//on fait juste une boucle sur chaque element "donnee" trouvé
	    	document.getElementById("messageAccueil").className="tumevoispas";
	    	for (i=0;i<items.length;i++)
	    	{
	    		var itemNom = docXML.getElementsByTagName("nom")
	    		var nom = itemNom.item(i).firstChild.data;
	    		var itemDpt = docXML.getElementsByTagName("dpt")
	    		var dpt = itemDpt.item(i).firstChild.data;
	    		var itemLat = docXML.getElementsByTagName("latitude")
	    		var latitude = itemLat.item(i).firstChild.data;
	    		var itemLong = docXML.getElementsByTagName("longitude")
	    		var longitude = itemLong.item(i).firstChild.data;
	    		var itemNb = docXML.getElementsByTagName("nbannonces")
	    		var nombre = itemNb.item(i).firstChild.data;
	    		var itemInfos = docXML.getElementsByTagName("recinfos")
	    		var recInfos = itemInfos.item(i).firstChild.data;
	    		
	    		var url =  'index.php?module=afficherAnnonces&code_trans=' + type_trans +'&recherche_infos[localisation]=';
	    		url += recInfos;
	    		var description = "<div align='center'>";
	    		var ann;
	    		switch (lang) {
	    			case 'en' :
	    				ann = annonce_en;
	    				break;
					case 'es' :
	    				ann = annonce_es;
	    				break;
	    			default :
	    				ann = annonce_fr;
	    				break;
	    		}
	    		
	    		//alert ("description" + description);
	    		
	    		if (nombre > 0 ) {
					switch (compteur) {
						case 0 :
							var icon = iconV;
							trans = "Vente";
							break;
						case 1 :
							var icon = iconL;
							longitude = longitude-2.5;
							latitude = latitude-2.5;
							trans = "Location";
							break;
						case 2 :
							var icon = iconLV;
							longitude = 1*(longitude)+2.5*1;
							latitude = 1*(latitude)-2.5*1;
							trans = "Vacances";
							break;
					}
					//alert ("compteur " + compteur + " " + latitude + " " + longitude)
					description +=  "<br>  " + nom + " " + trans;
		    		description += '<br> <a href=" ' + url + '"> ' + nombre + ' ' + ann ;
		    		if (nombre > 1 ) description += 's';
		    		description += ' </a></div>';
		    		addMarkersToMapMonde(latitude , longitude,
				      	description,icon);
				}
	    	}
	    	
	    	if (compteur < 2) {
	    		// type_trans type de transaction
	    		if (compteur == 0) code_trans = 20
	    		if (compteur == 1) code_trans = 30
	    		compteur++;
		    	ajaxMonde(code_trans);
	    	}
	    }
	}
	
    function showListeVac(latitude,longitude) {
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
	  icon.image = "icones/vert.png";
      icon.shadow = "icones/mm_20_shadow.png";
      icon.iconSize = new GSize(13, 22);
      icon.iconAnchor = new GPoint(7, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),5);
	  type_trans = 30;
	  GEvent.addListener(map, "zoomend", function() { 
	    zoomcourant = map.getZoom();
	    //alert ('zoom Vac ' + zoomcourant);
	    if (zoomcourant < 6)
	    	ajaxVac();
	    else ajaxZoomVac();
		});
      // recuperation des données
      zoomcourant = map.getZoom();
      // recuperation des données
      ajaxVac();
    }
    
    function ajaxVac()
	{
	    var xhr=null;
	    
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    tb_markers = new Array;
	     map.clearOverlays();
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax(xhr); };
	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
		
	    //on appelle le fichier reponse.txt
	    xhr.open("GET", "reponse_ville.php?code_trans=30&loc_pays=FR" , true);
	    xhr.send(null);
	}
	
	function ajaxZoomVac()
	{
	    var xhr=null;
	    
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_zooom(xhr); };
	    map.clearOverlays();
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
		
	    //on appelle le fichier reponse.txt
	    var url =  "reponse_critere.php?code_trans=30&recherche_infos[loc_pays]=FR";
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}
    
    function showListeLocation(latitude,longitude) {
	  // alert("showPoint " + latitude + " " + longitude );
	  // Create our "tiny" marker icon
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
	  icon.image = "icones/vermillon.png";
      icon.shadow = "icones/mm_20_shadow.png";

      icon.iconSize = new GSize(13, 23);
      //icon.shadowSize = new GSize(22, 20);
      icon.iconAnchor = new GPoint(7, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
      
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),5);
	  type_trans = 20;
      // recuperation des données
      GEvent.addListener(map, "zoomend", function() { 
	    zoomcourant = map.getZoom();
	    //alert ('zoom ' + zoomcourant);
	    if (zoomcourant < 6)
	    	ajaxLoc();
	    else ajaxZoomLoc();
		});
      // recuperation des données
      zoomcourant = map.getZoom();
      ajaxLoc();
    }
    
    function ajaxLoc()
	{
	    var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    tb_markers = new Array;
	     map.clearOverlays();
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax(xhr); };
	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    xhr.open("GET", "reponse_ville.php?code_trans=20&loc_pays=FR" , true);
	    xhr.send(null);
	}
	function ajaxZoomLoc()
	{
	    var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_zooom(xhr); };
	    map.clearOverlays();
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    var url =  "reponse_critere.php?code_trans=20&recherche_infos[loc_pays]=FR";
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}
	
     function showListeVente(latitude,longitude) {
	  // alert("showPoint " + latitude + " " + longitude );
	  // Create our "tiny" marker icon
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
      icon.image = "icones/bleu.png";
      icon.shadow = "icones/mm_20_shadow.png";
      //icon.iconSize = new GSize(12, 20);
      icon.iconSize = new GSize(13, 22);
      //icon.shadowSize = new GSize(22, 20);
      icon.iconAnchor = new GPoint(6, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
      
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),5);
	  type_trans = 10;
	  GEvent.addListener(map, "zoomend", function() { 
	    zoomcourant = map.getZoom();
	    //alert ('zoom ' + zoomcourant);
	    if (zoomcourant < 6)
	    	ajaxVente();
	    else ajaxZoomVente();
		});
      // recuperation des données
      zoomcourant = map.getZoom();
      ajaxVente();
    }
    
	
    function ajaxVente()
	{
	    var xhr=null;
	   
		try {
		   xhr = new ActiveXObject("Microsoft.XMLHTTP");    // Essayer Internet Explorer 
		}
		catch(e)   // Echec
		{
		  xhr = new XMLHttpRequest();  // Autres navigateurs
		}
	    map.clearOverlays();
	    tb_markers = new Array;
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax(xhr); };	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    xhr.open("GET", "reponse_ville.php?code_trans=10&loc_pays=FR" , true);
	    xhr.send(null);
	}
	
	function ajaxZoomVente()
	{
	    var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    map.clearOverlays();
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_zooom(xhr); };	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    var url =  "reponse_critere.php?code_trans=10&recherche_infos[loc_pays]=FR";
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}
	
    function showListe(latitude,longitude) {
	  // alert("showPoint " + latitude + " " + longitude );
	  // Create our "tiny" marker icon
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
	  icon.image = "icones/mm_20_blue.png";
      icon.shadow = "icones/mm_20_shadow.png";
      icon.iconSize = new GSize(12, 20);
      icon.shadowSize = new GSize(22, 20);
      icon.iconAnchor = new GPoint(6, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);      
	  map = new GMap2(document.getElementById("acMap"));
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.setCenter(new GLatLng(latitude, longitude),5);
      // recuperation des données
      ajax();
    }




function ajax()
{
    var xhr=null;    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    tb_markers = new Array();
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { alert_ajax(xhr); };   
    //on affiche le message d'accueil
    document.getElementById("messageAccueil").className="tumevois";
    xhr.open("GET", "reponse_ville.php" , true);
    xhr.send(null);
}


function alert_ajax(xhr)
{
   if (xhr.readyState==4) 
    {
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("donnee")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	document.getElementById("messageAccueil").className="tumevoispas";
    	for (i=0;i<items.length;i++)
    	{
    		// alert (items.item(i).firstChild.data);
    		var itemNom = docXML.getElementsByTagName("nom")
    		var nom = itemNom.item(i).firstChild.data;
    		var itemDpt = docXML.getElementsByTagName("dpt")
    		var dpt = itemDpt.item(i).firstChild.data;
    		var itemLat = docXML.getElementsByTagName("latitude")
    		var latitude = itemLat.item(i).firstChild.data;
    		var itemLong = docXML.getElementsByTagName("longitude")
    		var longitude = itemLong.item(i).firstChild.data;
    		var itemNb = docXML.getElementsByTagName("nbannonces")
    		var nombre = itemNb.item(i).firstChild.data;
    		var itemInfos = docXML.getElementsByTagName("recinfos")
    		var recInfos = itemInfos.item(i).firstChild.data;
    		
    		var url =  'index.php?module=afficherAnnonces&code_trans=' + type_trans +'&recherche_infos[localisation]=';
    		url += recInfos;
    		var description = "<html><head>";
    		description2 = '<style type="text/css">';
    		description2 += '#main {width:40px;color: #00a650;font-style: italic;}';
			description2 += "</style>";
    		description += "</head><body align='center' >";
    		description += "<div id='main' align='center' style='font-style: italic;'>";
    		var ann;
    		var paris;
    		switch (lang) {
    			case 'en' :
    				ann = annonce_en;
    				paris = region_parisienne_en;
    				break;
				case 'es' :
    				ann = annonce_es;
    				paris = region_parisienne_es;
    				break;
    			default :
    				ann = annonce_fr;
    				paris = region_parisienne_fr;
    				break;
    		}
    		if (nom == "Paris") {
    			description +=  "<br> " + paris;
    		} else {
    			description +=  "<br>  " + nom;
    		}
    		
    		description += '<br> <a href=" ' + url + '"> ' + nombre + ' ' + ann ;
    		if (nombre > 1 ) description += 's';
    		description += '</a>';
    		description += '</div>';
    		description += "</body></html>";
    		//alert ("description" + description);
    		
    		if (nombre > 0 ) {
	    		addMarkersToMap(latitude , longitude,
			      	description);
			}
    	}
    	// type_trans type de transaction
    	var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_etranger(xhr); };	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    var url =  "rep_etranger_acc.php?code_trans="+type_trans;
	    xhr.open("GET", url, true);
	    xhr.send(null);
    }
}

function MyMapRemoveMarker(marker) {
      map.removeOverlay(marker);
    }

function alert_ajax_etranger(xhr)
{
   if (xhr.readyState==4) 
    {
    	var docXML= xhr.responseXML;
    	var taille = tb_markers.length;
    	var items = docXML.getElementsByTagName("code_postal")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	document.getElementById("messageAccueil").className="tumevoispas";
    	var items = docXML.getElementsByTagName("code_postal");    
    	//on fait juste une boucle sur chaque element "code_postal" trouvé
    	var nbItemsCP = items.length;
    	for (i=0;i<nbItemsCP;i++)
    	{
    		var nombre = items.item(i).getAttribute("nb");
    		var latitude = items.item(i).getAttribute("latitude");
    		var longitude = items.item(i).getAttribute("longitude");
    		var nom = items.item(i).getAttribute("nom");
    		if (items.item(i).firstChild.data != null ) {
    			var code_postal = items.item(i).firstChild.data;
    		} else {
    			var code_postal = "00000";

    		}
    		var url =  'index.php?module=afficherAnnonces&code_trans=' + type_trans +'&recherche_infos[localisation]=';
    		url += code_postal;
    		
    		var description = "<div align='center'>";
    		var ann;
    		switch (lang) {
    			case 'en' :
    				ann = annonce_en;
    				break;
				case 'es' :
    				ann = annonce_es;
    				break;
    			default :
    				ann = annonce_fr;
    				break;
    		}
    		description +=  "<br>  " + nom;
    		description += '<br> <a href=" ' + url + '"> ' + nombre + ' ' + ann ;
    		if (nombre > 1 ) description += 's';
    		description += ' </a></div>';
    		//alert ("description" + description);
    		
    		if (nombre > 0 ) {
	    		addMarkersToMap(latitude , longitude,
			      	description);
			}
    	}
    }
}
    
function alert_ajax_zooom(xhr)
{
   if (xhr.readyState==4) 
    {
    	var docXML= xhr.responseXML;
    	var taille = tb_markers.length;
    	var items = docXML.getElementsByTagName("code_postal")
    	//on fait juste une boucle sur chaque element "donnee" trouvé
    	document.getElementById("messageAccueil").className="tumevoispas";
    	var items = docXML.getElementsByTagName("code_postal");    
    	//on fait juste une boucle sur chaque element "code_postal" trouvé
    	var nbItemsCP = items.length;
    	for (i=0;i<nbItemsCP;i++)
    	{
    		var nombre = items.item(i).getAttribute("nb");
    		var latitude = items.item(i).getAttribute("latitude");
    		var longitude = items.item(i).getAttribute("longitude");
    		var nom = items.item(i).getAttribute("nom");
    		if (items.item(i).firstChild.data != null ) {
    			var code_postal = items.item(i).firstChild.data;
    		} else {
    			var code_postal = "00000";

    		}
    		var url =  'index.php?module=afficherAnnonces&code_trans=' + type_trans +'&recherche_infos[localisation]=';
    		url += code_postal;
    		
    		var description = "<div style='width :auto; height:auto;' align='center' >";
    		var ann;
    		switch (lang) {
    			case 'en' :
    				ann = annonce_en;
    				break;
				case 'es' :
    				ann = annonce_es;
    				break;
    			default :
    				ann = annonce_fr;
    				break;
    		}
    		description +=  "<br>  " + nom;
    		description += '<br> <a href=" ' + url + '"> ' + nombre + ' ' + ann ;
    		if (nombre > 1 ) description += 's';
    		description += ' </a></div>';
    		//alert ("description" + description);
    		
    		if (nombre > 0 ) {
	    		addMarkersToMap(latitude , longitude,
			      	description);
			}
    	}
    	var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_etranger(xhr); };	    
	    //on affiche le message d'accueil
	    document.getElementById("messageAccueil").className="tumevois";
	    //on appelle le fichier reponse.txt
	    var url =  "reponse_etranger.php?code_trans="+type_trans+"&recherche_infos[etranger]=1";
	    xhr.open("GET", url, true);
	    xhr.send(null);
    }
}

function addMarkersToMapDet (latitude, longitude, description) {
	var marker = new GMarker(new GLatLng(latitude,longitude),icon);
	var options = {maxWidth :100};
	var inputDescr = document.createElement("div");
	inputDescr.innerHTML = description;
	GEvent.addListener(marker, 'mouseover',
		function () {
			marker.openInfoWindow(inputDescr);
		}
	);
	map.addOverlay(marker);
		
}

function showCritereEtranger(latitude,longitude,code_trans,recherche_infos) {
	// alert("showCritereEtranger " + code_trans + " " + recherche_infos );
	// Create our "tiny" marker icon
	icon = new GIcon();// mm_20_blue.png,mm_20_red.png
	icon.image = "icones/mm_20_blue.png";
	icon.shadow = "icones/mm_20_shadow.png";
	icon.iconSize = new GSize(12, 20);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(6, 20);
	icon.infoWindowAnchor = new GPoint(5, 1);
	map  = new GMap2(document.getElementById("listeMap"));
	//startZoom = 11;
	startZoom = 10;
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	map.setCenter(new GLatLng(latitude, longitude),startZoom);
	// recuperation des données
	var xhr=null;
	if (window.XMLHttpRequest) { 
	    xhr = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
	    xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//on définit l'appel de la fonction au retour serveur
	xhr.onreadystatechange = function() { alert_ajax_detail(xhr,code_trans,recherche_infos); };
	//on affiche le message d'accueil
	document.getElementById("message").className="tumevois";
	var tabInfos = recherche_infos.split("-");
	var res = "";
	for (i = 0 ; i < tabInfos.length ; i++) {
		var item = tabInfos[i];
		var tabElt = item.split("=");
		res += 'recherche_infos[' + tabElt[0] +'] =' + tabElt[1];
		if (i < tabInfos.length -1) res += "&";
	}
	var url =  "reponse_etranger.php?code_trans="+code_trans+"&"+res;
	xhr.open("GET", url, true);
	xhr.send(null);
}

//====================================================================
//
//       function showCritere
//       point de départ pour afficher sur carte
//       les annonces avec les critères de recherche dans recherche_infos
//       et avec le code_trans (vante , location etc...)
//====================================================================

function showCritere(latitude,longitude,code_trans,recherche_infos) {
	  // alert("showCritere " + code_trans + " " + recherche_infos );
	  // Create our "tiny" marker icon
	  icon = new GIcon();// mm_20_blue.png,mm_20_red.png
	  icon.image = "icones/mm_20_blue.png";
      icon.shadow = "icones/mm_20_shadow.png";
      icon.iconSize = new GSize(12, 20);
      icon.shadowSize = new GSize(22, 20);
      icon.iconAnchor = new GPoint(6, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);
	  map  = new GMap2(document.getElementById("listeMap"));
	  //startZoom = 11;
	  startZoom = 15;
	  map.addControl(new GSmallMapControl());
	  map.addControl(new GMapTypeControl());
	  map.addControl(new GOverviewMapControl());
	  map.setCenter(new GLatLng(latitude, longitude),startZoom);
      // recuperation des données
      ajaxDetail(code_trans,recherche_infos);
    }


    function ajaxDetail(code_trans,recherche_infos)
	{
//		alert ("ajaxDetail");
	    var xhr=null;
	    try {
		   xhr = new ActiveXObject("Microsoft.XMLHTTP");    // Essayer Internet Explorer 
		}
		catch(e)   // Echec
		{
		  xhr = new XMLHttpRequest();  // Autres navigateurs
		}
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_detail(xhr,code_trans,recherche_infos); };
	    
	    //on affiche le message d'accueil
	    document.getElementById("message").className="tumevois";
	    var tabInfos = recherche_infos.split("-");
	    var res = "";
	    for (i = 0 ; i < tabInfos.length ; i++) {
	    	var item = tabInfos[i];
	    	var tabElt = item.split("=");
	    	res += 'recherche_infos[' + tabElt[0] +'] =' + tabElt[1];
	    	if (i < tabInfos.length -1) res += "&";
	    }
	    var url =  "reponse_critere.php?code_trans="+code_trans+"&"+res;
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}


function alert_ajax_detail(xhr,code_trans,recherche_infos)
{
   var	latlng;
   if (xhr.readyState==4) 
    {
    	document.getElementById("message").className="tumevoispas";
     	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("code_postal");    
    	//on fait juste une boucle sur chaque element "code_postal" trouvé
    	var nbItemsCP = items.length;
//    	if (nbItemsCP == 0) {
//    		document.getElementById("aucuneAnnonce").innerHTML = 'Aucune annonce pour vos critères de choix'; 
//    	} 	
    	for (i=0;i<nbItemsCP;i++)
    	{
    		var nombre = items.item(i).getAttribute("nb");
    		var latitude = items.item(i).getAttribute("latitude");
    		var longitude = items.item(i).getAttribute("longitude");
    		var nom = items.item(i).getAttribute("nom");
    		if (items.item(i).firstChild.data != null ) {
    			var code_postal = items.item(i).firstChild.data;
    		} else {
    			var code_postal = "00000";

    		}
			var res = "";
			var tabInfos = recherche_infos.split("-");
			    for (k = 0 ; k < tabInfos.length ; k++) {
			    	var elt = tabInfos[k];
			    	var tabElt = elt.split("=");
			    	if (tabElt[0] == 'localisation') {
			    		if (code_postal != "00000") {
			    		 	res += 'recherche_infos[' + tabElt[0] +'] =' + code_postal;
			    		}
			    	} else {
			    		res += 'recherche_infos[' + tabElt[0] +'] =' + tabElt[1];
			    	}
			    	if (k  < tabInfos.length -1) res += "&";
			    }
	    	var url =  'index.php?module=afficherAnnonces&code_trans='+code_trans+'&'+res;
    		var cpAnnonces = items.item(i).getElementsByTagName("annonce");
    		// récuperation de la liste des tags annonce à l'intérieur du tag code_postal
    		var tbAnnonces = new Array();
    		if (nombre < nb_ann_list ) {
	    		for (j=0;j<cpAnnonces.length;j++) {
	    			// pour chaque tag ds annonce récuperer la valeur
	    			var itemId = cpAnnonces.item(j).getElementsByTagName("ann_id");
	    			var valAnn = itemId.item(0).firstChild.data;
	    			itemId = cpAnnonces.item(j).getElementsByTagName("type_bien");
	    			if (itemId.item(0).firstChild != null ) {
	    				var valBien = itemId.item(0).firstChild.nodeValue;
	    			} else var valBien = "";
	    			itemId = cpAnnonces.item(j).getElementsByTagName("code_trans");
	    			if (itemId.item(0).firstChild != null ) {
	    				var valTrans = itemId.item(0).firstChild.nodeValue;
	    			} else var valTrans = "";
	    			itemId = cpAnnonces.item(j).getElementsByTagName("prix");

	    			if (itemId.item(0).firstChild != null ) {
	    				var valPrix = itemId.item(0).firstChild.nodeValue;
	    			} else var valPrix = 0;
	    			itemId = cpAnnonces.item(j).getElementsByTagName("surface");
	    			if (itemId.item(0).firstChild != null ) {
	    				var valSurface = itemId.item(0).firstChild.nodeValue;
	    			} else var valSurface = 0;
	    			itemId = cpAnnonces.item(j).getElementsByTagName("descriptif");
	    			if (itemId.item(0).firstChild != null ) {
		    			var valDescriptif = itemId.item(0).firstChild.nodeValue;
		    			valDescriptif = valDescriptif.substring(0,55) + "... ";
	    			} else var valDescriptif = "";
	    			itemId = cpAnnonces.item(j).getElementsByTagName("nb_pieces");
	    			if (itemId.item(0).firstChild != null ) {
		    			var valPieces = itemId.item(0).firstChild.nodeValue;
	    			} else var valPieces = "";
	    			var ann;
	    			var piece;
	    			var ann;
		    		switch (lang) {
		    			case 'en' :
		    				piece = piece_en;
		    				mois = mois_en;
		    				ann = annonce_en;
		    				detail = detail_en;
		    				break;
						case 'es' :
		    				piece = piece_es;
		    				mois = mois_es;
		    				ann = annonce_es;
		    				detail = detail_es;
		    				break;
		    			default :
		    				piece = piece_fr;
		    				mois = mois_fr;
							ann = annonce_fr;
		    				detail = detail_fr;
		    				break;
		    		}
	    			var urlDet =  'annonce-' + valAnn + '.html';
	    			var urlD = 'index.php?module=produit&trans='+valTrans;
					urlD += '&ville=' + nom + '&dept=' + code_postal.substring(0,2) + '&ann_id=' + valAnn;
	    			var refer = '<a href=" ' + urlDet + '"> '+detail + '</a>';
	    			var refJs = '<a href="javascript: rechercheDetail(' + valAnn + ');">'+ detail + '</a>';
	    			tbAnnonces[j] = '<table width="90%" style ="font-size:11px;"><tr>';
	    			tbAnnonces[j] += '<td > <strong> ';
	    			switch (lang) {
							case 'en' :
								lvente = vente_en;
								llocation = location_en;
								lvacances = vacances_en;
								break;
							case 'es' :
								lvente = vente_es;
								llocation = location_es;
								lvacances = vacances_es;
								break;
							default :
								lvente = vente_fr;
								llocation = location_fr;
								lvacances = vacances_fr;
								break;
							}
	    			switch (valTrans.substring(0,2)) {
	    				case '10' :
	    					tbAnnonces[j] += lvente + " ";
	    				case '20' :
	    					tbAnnonces[j] += llocation + " ";
	    				case '30' :
	    					tbAnnonces[j] += lvacances + " ";
	    			}
	    			//alert ("alert_ajax_detail code trans -" + valTrans + "-");
	    			switch (valTrans) {
	    				case 'Achat Vente' :
	    					tbAnnonces[j] += lvente + " ";
	    					break;
	    				case 'Location' :
	    					tbAnnonces[j] += llocation + " ";
	    					break;
	    				case 'Vacances' :
	    					tbAnnonces[j] += lvacances + " ";
	    					break;
	    				case 'Location Vacances' :
	    				case 'Etranger' :
	    				case ' Etranger' :
	    				case 'Mer' :
	    				case 'Campagne' :
	    				case 'Montagne' :
	    				case 'Ville' :
	    					tbAnnonces[j] += lvacances + " ";
	    					break;
	    			}
	    			//alert ("alert_ajax_detail tbannonces " + tbAnnonces[j]);
	    			tbAnnonces[j] += " " + valBien + " ";
	    			if (valPieces > 0 ) {
	    				tbAnnonces[j] +=  valPieces + " " + piece;
	    			}
	    			if (valPieces > 1 ) tbAnnonces[j] += "s ";
	    			else  tbAnnonces[j] += " ";
	    			// tbAnnonces[j] +=  " " + "</td></tr>" ; 
	    			if (valPrix > 0) {
	    			tbAnnonces[j] += valPrix;
		    			if (code_trans == '10') {
		    				tbAnnonces[j] +=  " &#8364;  </strong> ";
		    			} else {
		    				tbAnnonces[j] +=  " &#8364;/" + mois + " </strong>";
		    			}
	    			}
	    			if (valSurface > 0 && valSurface != '' ) {
	    				tbAnnonces[j] += valSurface + ' m² ';
	    			}
	    			
	    			tbAnnonces[j] += "</td>";
	    			tbAnnonces[j] += "<td align='right'>  " + refJs + "</td></tr>";
	    			tbAnnonces[j] += '<tr><td >' + valDescriptif + "</td></tr>" ;
	    			tbAnnonces[j] += '<tr><td colspan="2"><hr></td></tr>';
	    			tbAnnonces[j] += "</table>";
	    			// alert (valBien + " " + tbAnnonces[j]);  			
	    		}
    		}
			var description ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"';
			description += '<html><head>';
			description += '</head><body >';
			description +=  '<div margin:10px>';
    		description += " <b> " + nom +" </b> ("+ code_postal +") <br>";
   			description += ' <a href=" ' + url + '"> ' + nombre + ' ' + ann;
   			if (nombre > 1) description += 's </a>';
   			else  description += ' </a>';
   			description += "<br>";
   			description += '</div>';
			
    		description +=  '<div  style ="width:300px; height:150px; overflow:auto; border: thin solid #F7F7F7;';
			description +=  ' margin: 10px;" >';
   			if (nombre < 20 ) {
   				// faire une liste avec les principaux critères des annonces
   				description += "<hr>";
				for (k=0; k < cpAnnonces.length;k++) {
					description += tbAnnonces[k];
				}
				description += '<br>';
   			}
   			description += '</div>';
     	    latlng = new GLatLng(latitude, longitude);
     		if (i==0) {
     			// alert ("i " + i+ "lat " + latitude + "long " + longitude + "Zoom" + startZoom);
     		    var latlgnzero = new GLatLng(latitude, longitude);
     			map.setCenter(latlgnzero,startZoom);
				// alert ("après map.SetCenter");
     		}
     		mapBounds = map.getBounds();
     		
     		if (!mapBounds.contains(latlng)) {
     			//alert ("latitude " +latitude +  "long " + longitude +"non ds map");
     			while (startZoom > 5 && !mapBounds.contains(latlng)) {
	     			startZoom--;
	     			map.setCenter(latlgnzero,startZoom);
	     			// alert ("starZoom " + startZoom);
	     			mapBounds = map.getBounds();
	     			latlng = new GLatLng(latitude, longitude);
     			}
     		}
	    	addMarkersToMapDet(latitude , longitude,
			      	description);
    	}
	}
}


function rechercheDetail(ann_id) {
//		alert ("ajaxDetail");
	    var xhr=null;
	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alert_ajax_annonce(xhr); };
	    //on affiche le message d'accueil
	    var url = "reponse_annonce.php?ann_id=" + ann_id;
	    xhr.open("GET", url, true);
	    xhr.send(null);
	}
	
function alert_ajax_annonce(xhr,code_trans,recherche_infos) {
  
   // div id='animeFlash' style="display=block">, 
   // et tu fais un bouton qui permet de faire un document.getElementById('animeFlash').style.display='none';
   var ann_id;
   var code_trans;
   var type_bien;
   var date_entree;
   var nb_pieces;
   var date_dispo;
   var surface;
   var prix;
   var charges;
   var chargesC;
   var meuble;
   var descriptif;
   var loc_adresse1;
   var loc_proximite;
   var loc_cp;
   var loc_dpt;
   var loc_ville;
   var nb_chambres;
   var nb_sdb;
   var etage;
   var surface_terrain;
   var unite_terrain;
   var exposition;
   var type_chauffage;
   var access;
   var nom_emetteur;
   var prenom_emetteur;
   var adresse_emetteur;
   var ville_emetteur;
   var email_emetteur;
   var tel_fixe;
   var tel_mobile;
   var libTrans;
    
   if (xhr.readyState==4) {
    	document.getElementById("cart_detail").style.display='block';
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("ann_id");
    	if (items.item(0).firstChild != null ) {
    		ann_id = items.item(0).firstChild.data;
    	} else ann_id = "";
    	var items = docXML.getElementsByTagName("type_bien");
    	if (items.item(0).firstChild != null ) {
    		type_bien = items.item(0).firstChild.data;
    	} else type_bien = "";
    	items = docXML.getElementsByTagName("date_entree");
    	if (items.item(0).firstChild != null ) {
    		date_entree = items.item(0).firstChild.data;

    	} else date_entree = "";
    	items = docXML.getElementsByTagName("nb_pieces");
    	var texte = "";
    	if (items.item(0).firstChild != null ) {
    		 nb_pieces = items.item(0).firstChild.data;
    		 if (nb_pieces > 1) {
    		 	texte = items.item(0).getAttribute("texte");
    		 }
    	} else nb_pieces = "";
    	items = docXML.getElementsByTagName("date_dispo");
    	if (items.item(0).firstChild != null ) {
    		 date_dispo = items.item(0).firstChild.data;
    	} else date_dispo = "";
    	items = docXML.getElementsByTagName("surface");
    	if (items.item(0).firstChild != null ) {
    		 surface = items.item(0).firstChild.data;
    	} else surface = 0;
    	items = docXML.getElementsByTagName("prix");
    	if (items.item(0).firstChild != null ) {
    		 prix = items.item(0).firstChild.data;
    	} else prix = 0;
    	items = docXML.getElementsByTagName("charges");
    	if (items.item(0).firstChild != null ) {
    		 charges = items.item(0).firstChild.data;
    	} else charges = 0;
    	items = docXML.getElementsByTagName("chargesC");
    	if (items.item(0).firstChild != null ) {
    		 chargesC = items.item(0).firstChild.data;
    	} else surface = "";
    	items = docXML.getElementsByTagName("meuble");
    	if (items.item(0).firstChild != null ) {
    		 meuble = items.item(0).firstChild.data;
    	} else meuble = "";
    	items = docXML.getElementsByTagName("descriptif");
    	if (items.item(0).firstChild != null ) {
    		 descriptif = items.item(0).firstChild.data;
    	} else descriptif = "";
    	items = docXML.getElementsByTagName("loc_cp");
    	if (items.item(0).firstChild != null ) {
    		 loc_cp = items.item(0).firstChild.data;
    	} else loc_cp = "";
    	items = docXML.getElementsByTagName("loc_dpt");
    	if (items.item(0).firstChild != null ) {
    		 loc_dpt = items.item(0).firstChild.data;
    	} else loc_dpt = "";
    	items = docXML.getElementsByTagName("loc_ville");
    	if (items.item(0).firstChild != null ) {
    		 loc_ville = items.item(0).firstChild.data;
    	} else loc_ville = "";
    	// ecriture de l'entete gauche
    	items = docXML.getElementsByTagName("code_trans");
    	if (items.item(0).firstChild != null ) {
    		 code_trans = items.item(0).firstChild.data;
    	} else code_trans = "90";
    	libTrans = ' ';
    	var ann;
		var mois;
		var maj;
		var lref;
		var lvente;
		var llocation;
		var lvacances;
		var terrain;
		var chambres;
		switch (lang) {
			case 'en' :
				mois = mois_en;
				maj = maj_en;
				lref = ref_en;
				lvente = vente_en;
				llocation = location_en;
				lvacances = vacances_en;
				terrain = terrain_en;
				terrasse = terrasse_en;
				chambres = chambres_en;
				break;
			case 'es' :
				mois = mois_es;
				maj = maj_es;
				lref = ref_es;
				lvente = vente_es;
				llocation = location_es;
				lvacances = vacances_es;
				terrain = terrain_es;
				terrasse = terrasse_es;
				chambres = chambres_es;
				break;
			default :
				mois = mois_fr;
				maj = maj_fr;
				lref = ref_fr;
				lvente = vente_fr;
				llocation = location_fr;
				lvacances = vacances_fr;
				terrain = terrain_fr;
				terrasse = terrasse_fr;
				chambres = chambres_fr;
				break;
		}
    	
    	if (code_trans == '10') libTrans = lvente;
    	if (code_trans == '20') libTrans = llocation;
    	if (code_trans == '30') libTrans = lvacances;
    	if (code_trans.substring(0,2) == '30') libTrans = lvacances;
    	var html = libTrans + " ";
    	if (nb_pieces > 0 && (type_bien == "maison " || type_bien == "appartement")) {
    		html += nb_pieces + " " + texte;
    		if (nb_pieces > 1) html += 's';
    	}
    	html += ' ' + type_bien ;
    	if (surface > 0) 
    		html += "<br>" +  surface + " m²";
    	if (loc_cp != "") html += "<br>" +  loc_cp;
		else  html += "<br>" +  loc_dpt;   
		if (loc_ville != "") html += " " + loc_ville;
		document.getElementById("cart_entleft").innerHTML = html;
		html = '';
		if (prix > 0) {
	    	if (code_trans == '10') {
	    		html += prix + " &euro;";
	    	} else html += prix + " &euro;/"+mois;
		}
    	document.getElementById("cart_entright").innerHTML = html;
    	// mettre en forme la date
    	html = maj + " " + date_entree;
    	// Reference
    	var ref = "T_";
    	if (code_trans == '10') ref = 'V_';
    	if (code_trans == '20') ref = 'L_';
    	if (code_trans == '30') ref = 'Va_';
    	ref += type_bien.substring(0,1) + ann_id;
    	html += '<br> ' + lref + ' : ' + ref;
    	//alert ("html " + html);
    	document.getElementById("cart_maj").innerHTML = html;
    	document.getElementById("cart_description").innerHTML = descriptif.substring(0,2000);
    	items = docXML.getElementsByTagName("photo");
    	html = "";
    	var image = "";
    	document.getElementById("cart_photo").innerHTML = "";
    	for (i=0;i<items.length;i++){
    		var photo = items.item(i).firstChild.data;
    		var url = 'photos/' + photo;
    		txt_width = '60';
    		txt_height = '60';
    	    image = '<li><a href="' + url + '"  title="' +  photo + '">';
			image += '<img src="photos/' + photo + '" width="'+txt_width+'" height="'+txt_height + '"></a></li>';
			//alert ("image " + image);
			html += image;
			if ( i== 0) {
				image = '<a href="' + url + '"  title="' +  photo + '">';
				image += '<img src="photos/' + photo + '" class="image" width="'+txt_width+'" height="'+txt_height + '"></a>';
				image = '<dd><img id="cart_big_pict" src="photos/' + photo + ' " alt="Photo 1 en taille normale"  width="300" height="200" /></dd>';
				document.getElementById("cart_photo").innerHTML = image;
			}
    	}
    	//alert ("html" + html);
    	document.getElementById("cart_galerie_mini").innerHTML = html;
    	// Infos complémentaires
    	html = "";
    	items = docXML.getElementsByTagName("surface_terrain");
    	if (items.item(0).firstChild != null ) {
    		 surface_terrain = items.item(0).firstChild.data;
    		 if (surface_terrain > 0 ) {
    		 	items = docXML.getElementsByTagName("unite_terrain");
    		 	unite_terrain = "m2";
		    	if (items.item(0).firstChild != null ) {
		    		 unite_terrain = items.item(0).firstChild.data;
		    	}
		    	if (type_bien == 'Appartement') {
		    		html =  surface_terrain + " " + unite_terrain + " (" + terrasse + ") <br>";
		    	} else {
    		 		html =  surface_terrain + " " + unite_terrain + " (" + terrain+ ") <br>";
		    	}
    		 }
    	}
    	items = docXML.getElementsByTagName("nb_chambres");
    	if (items.item(0).firstChild != null ) {
    		 nb_chambres = items.item(0).firstChild.data;
    		 if (nb_chambres > 1)
    		  html +=  nb_chambres + " " + chambres;
    	} 
    	document.getElementById("cart_comp").innerHTML = html;
    	displayImgs();
	}
}

function effacer () {
	document.getElementById("cart_detail").style.display='none';
	// document.getElementById("cart_croix").style.display='none';
}

function displayImgs()
{
	var photos = document.getElementById('cart_galerie_mini') ;
	// On récupère l'élément ayant pour id galerie_mini
	var liens = photos.getElementsByTagName('a') ;
	// On récupère dans une variable tous les liens contenu dans galerie_mini
	var big_photo = document.getElementById('cart_big_pict') ;
	// Ici c'est l'élément ayant pour id cart_big_pict qui est récupéré, c'est notre photo en taille normale
	// Une boucle parcourant l'ensemble des liens contenu dans galerie_mini
	for (var i = 0 ; i < liens.length ; ++i) {
		// Au clique sur ces liens 
		liens[i].onmouseover = function() {
			big_photo.src = this.href; // On change l'attribut src de l'image en le remplaçant par la valeur du lien
			big_photo.alt = this.title; // On change son titre


			return false; // Et pour finir on inhibe l'action réelle du lien
		};
	}
}

function selection(idAnn) {
	var el = document.getElementById("sel_"+idAnn);
	if (el.className == "txtVert") {
		var ope = "ajout";
	} else var ope = "sup";
	var xhr=null;
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { alert_ajax_select(xhr,ope); };
    
    var url = "reponse_selection.php?ann_id=" + idAnn + '&ope=' + ope;
    // alert (url);
    //on appelle le fichier reponse.txt
    xhr.open("GET", url, true);
    xhr.send(null);
}
	
function alert_ajax_select(xhr) {
   if (xhr.readyState==4) {
   		var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("nombre_selection");
    	if (items.item(0).firstChild != null ) {
    		var nb_selection = items.item(0).firstChild.data;
    		var el = document.getElementById("nb_selection");
    		el.innerHTML = nb_selection;
    	}
    	var items = docXML.getElementsByTagName("ann_id");
    	if (items.item(0).firstChild != null ) {
    		var idAnn = items.item(0).firstChild.data;
    		var el = document.getElementById("sel_"+idAnn);
    		if (el.className == "txtVert") {
    			el.className = "txtRouge"
				el.innerHTML = supp_selection;
    		} else {
    			el.className = "txtVert";
    			el.innerHTML = add_selection;
    		}
    	}
   }	
}


function verifMail(a) {
	// On ouvre la fonction en lui envoyant la contenu du champ
	testm = false ;
	/*
	la on spécifie que l'adresse est false (fausse) dès le début. Cela permet de pouvoir dire que si rien n'est entré dans le champ l'adresse est fausse.
	*/ 
	
	for (var j=1 ; j<(a.length) ; j++) {
	
	/*
	Ici, ouverture d'une boucle for à 1 qui permettra de tester du premier jusqu'au dernier caractère de l'adresse e-mail entrée.
	*/ 
	 for (var j=1 ; j<(a.length) ; j++) {
	
	/*
	Ici, ouverture d'une boucle for à 1 qui permettra de tester du premier jusqu'au dernier caractère de l'adresse e-mail entrée.
	*/ 
	
	  if (a.charAt(j)=='@') {
	// La on commence les conditions de tests. Ici on cherche l'@
	   if (j<(a.length-4)){
	// Ici on regarde si il y a bien 4 caractère après le @
	    for (var k=j ; k<(a.length-2) ; k++) {
	// On ouvre une seconde boucle pour 
	     if (a.charAt(k)=='.') testm = true;
		/*
		on vérifie qu'il y ai bien un point et on met la variable testm à true (implicitement 
		si toutes les conditions sont remplies) puis on ferme les conditions et boucles
		*/
	    }
	   }
	  }
	 }
	}


	
	if (testm==false) alert('Votre adresse e-mail est incorrecte.');
	// si testm est évalué à false, on ouvre une boite d'alerte pour prévenir. 
	
	// else alert('Votre adresse e-mail semble correcte.'); 
	/*
	Cette boite d'alerte est facultative hein, ici c'est pour le besoin de la démonstration. Chez vous vous pouvez complètement enlever cette condition else car si c'est true le traitement du formulaire peu avoir lieu.
	*/ 
	
	return testm ;
}




function creer_alerte(code_trans,recherche_infos) {
	   //alert("creerAlerte " + code_trans + " " + recherche_infos );
	  // verification de l'email
	    var email = document.getElementById("email").value;
	  	if (!verifMail(email)) {
	  		return false;
	  	}
     	var xhr=null;

	    if (window.XMLHttpRequest) { 
	        xhr = new XMLHttpRequest();
	    }
	    else if (window.ActiveXObject) 
	    {
	        xhr = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    //on définit l'appel de la fonction au retour serveur
	    xhr.onreadystatechange = function() { alerte_mail_creer(xhr); };
	    
//	    alert("recherche_infos" + recherche_infos);
	    var tabInfos = recherche_infos.split("-");
	    var res = "";
	    for (i = 0 ; i < tabInfos.length ; i++) {
	    	var item = tabInfos[i];
	    	var tabElt = item.split("=");
	    	res += 'recherche_infos[' + tabElt[0] +'] =' + tabElt[1];
	    	if (i < tabInfos.length -1) res += "&";
	    }
	    res += '&' + 'recherche_infos[email] =' + email;
	    var url =  "reponse_creer_alerte.php?code_trans="+code_trans+"&"+res;
        //alert ("url : " + url)
	    //on appelle le fichier reponse.txt
	    xhr.open("GET", url, true);
	    xhr.send(null);
	    return false;
 
    }
    
function alerte_mail_creer(xhr) {
	 if (xhr.readyState==4) {
	 	//ecrire que l'alerte a ou non bien été créer
	 	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName("resultat");
    	if (items.item(0).firstChild != null ) {
    		var message = items.item(0).firstChild.data;
    		// alert ("message" + message);
    		document.getElementById("form_alerte").innerHTML = '&nbsp;&nbsp;' + message;
    	}
	 	return false;
	 }
}


function liste(f,q,t) {
	var l1    = f.elements["list"+(q-1)]; 
	var l2    = f.elements["list"+q]; 
	var index = l1.selectedIndex; 
	
	for (i=q;i<=t;i++) f.elements["list"+i].options.length = 0;
	if(index > 0 )  { 
	   var xhr_object = null; 
	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   } 
	 
	   xhr_object.open("POST", "reponse_depart.php?q="+q, true); 
	     
	   xhr_object.onreadystatechange = function() { 
	      if(xhr_object.readyState == 4) 
	         eval(xhr_object.responseText); 
	   } 
	 

	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   var data = "champ="+escape(l1.options[index].value)+"&form="+f.name+"&select=list"+q;
	   alert ("data " + data);
	   xhr_object.send(data); 
	} 
}


function rec_cp (f,q) {
	var l1    = f.elements["list"+(q-1)]; 
	var index = l1.selectedIndex; 
	if(index > 0 )  { 
	   var xhr_object = null; 
	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   } 
	 
	   xhr_object.open("POST", "reponse_depart.php?q=3", true); 
	     
	   xhr_object.onreadystatechange = function() { 
	      if(xhr_object.readyState == 4) 
	         eval(xhr_object.responseText); 
	   } 
	 
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   var data = "champ="+escape(l1.options[index].value)+"&form="+f.name+"&select=list"+q;
	   // alert ("data " + data);
	   xhr_object.send(data); 
	} 
}


function fermePopUp(codePostal,libVille) {
	  opener.document.ajouter['annonce_infos[loc_cp]'].value = codePostal;
	  opener.document.ajouter['annonce_infos[loc_ville]'].value = libVille;
	  opener.document.ajouter['annonce_infos[loc_cp]'].focus();
	  window.close();
	}


function maj_codePostal_region(f,type) {
	var ville = document.getElementById("loc_ville").value;
	if (ville != "") {
		 var xhr_object = null; 
	     
	   if(window.XMLHttpRequest) // Firefox 
	      xhr_object = new XMLHttpRequest(); 
	   else if(window.ActiveXObject) // Internet Explorer 
	      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
	      alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	      return; 
	   }
	   xhr_object.open("POST", "reponse_CP_region.php?type="+type, true); 
	     
	   xhr_object.onreadystatechange = function() { 
	      if(xhr_object.readyState == 4) 
	         eval(xhr_object.responseText); 
	   }
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   var data = "champ="+escape(ville)+"&form="+f.name;
	   // alert ("data " + data);
	   xhr_object.send(data); 
	}
}

function exec_recherche(mot_fr,mot_en,mot_es) {
		 var mot;
		 var r = false;
		 if(document.getElementsByName) {
		 	var d = document.getElementsByName('rech_lg');
            for(var i=0; i<d.length; i++) {
              if(d[i].type=='radio' && d[i].checked) {
                r = d[i].value;
                break;
              }
			}
		 }else {
           var d = document.forms;
           for(var i=0; i<d.length; i++) {
             for(var k=0; k<d[i].length; k++) {
               if(d[i][k].type=='radio' && d[i][k].name=='rech_lg') {
                 for(var j=0; j<d[i][Nom].length; j++)
                 if(d[i][Nom][j].checked)
                   r = d[i][Nom][j].value;
               }
             }
           }
         }
		 switch (r) {
			case 'en' :
				mot = mot_en;
				break;
			case 'es' :
				mot = mot_es;
				break;
			default :
				mot = mot_fr;
				break;
		}
		lsc.execute(mot);
}



