var URL = window.location.href; var index = URL.indexOf("/",8); if ( index != -1 ) URL = URL.substring(0,index).concat("/location_vacances/xhr.php"); else URL = URL.concat("/location_vacances/xhr.php"); var XHR_IDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; function getXHR(){ var xhr = null; // FF, safari, opera try{ xhr = new XMLHttpRequest(); }catch(e){} // IE if( !xhr ){ for( var i = 0; i < 3; i++ ){ var id = XHR_IDS[i]; try{ xhr = new ActiveXObject(id); }catch(e){} if( xhr ){ XHR_IDS = [id];// so faster next time break; } } } if( !xhr ){ alert("XMLHTTP not available"); } return xhr; } function sendRequest(params,callback){ var xhr = getXHR(); if( !xhr ) return; xhr.open("POST",URL,true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function(){ if( xhr.readyState == 4 ){ if( xhr.status == 200 ){ var html = xhr.responseText; callback(html); } else alert("Service unavailable"); } } params = params.concat("&lang=en"); xhr.send(params); } function onChangePays(){ getRegions(); searchAnnonce(); getDepartements(); } function onChangeRegion(){ getDepartements(); searchAnnonce(); getCommunes(); } function onChangeDepartement(){ getCommunes(); searchAnnonce(); } function onChangeVille(){ searchAnnonce(); } function getRegions(){ if( !document.recherche.destination || document.recherche.destination.value == "" ) return; clearRegion(); clearDepartement(); clearCommune(); loading(document.getElementById("selectRegion")); var params = "&action=getregions&destination=".concat(document.recherche.destination.value); sendRequest(params,onRegionsLoaded); } function getCommunes(){ if( !document.recherche.departement || document.recherche.departement.value == "" ) return; clearCommune(); loading(document.getElementById("selectCommune")); var params = "&action=getcommuneswithannonce&destination=".concat(document.recherche.destination.value,"®ion=",document.recherche.region.value,"&departement=",document.recherche.departement.value); sendRequest(params,onCommunesLoaded); } function getDepartements(){ //if( document.recherche.region.value == "" ) return; clearDepartement(); clearCommune(); loading(document.getElementById("selectDepartement")); var params = "&action=getdepartements&destination=".concat(document.recherche.destination.value,"®ion=",document.recherche.region.value); sendRequest(params,onDepartementsLoaded); } function onRegionsLoaded(html){ var node = document.getElementById("selectRegion"); node.innerHTML = html; document.recherche.region.focus(); } function onCommunesLoaded(html){ var node = document.getElementById("selectCommune"); node.innerHTML = html; document.recherche.ville.focus(); } function onDepartementsLoaded(html){ var node = document.getElementById("selectDepartement"); node.innerHTML = html; document.recherche.departement.focus(); } function clearRegion(){ document.recherche.region.selectedIndex = 0; for ( var i = document.recherche.region.options.length - 1; i > 0; i-- ){ document.recherche.region.remove(i); } } function clearDepartement(){ document.recherche.departement.selectedIndex = 0; for ( var i = document.recherche.departement.options.length - 1; i > 0; i-- ){ document.recherche.departement.remove(i); } } function clearCommune(){ document.recherche.ville.selectedIndex = 0; for ( var i = document.recherche.ville.options.length - 1; i > 0; i-- ){ document.recherche.ville.remove(i); } } function initSearch(){ document.getElementById("accueil").style.display = "none"; document.getElementById("searchresult").innerHTML = "" document.getElementById("searchloading").style.display = "block"; document.getElementById("search").style.display = "block"; } function searchAnnonce(page){ initSearch(); if ( !page ) page = 0; var params = "&action=search&lang=".concat(document.recherche.lang.value,"&pge=",page,"&destination=",document.recherche.destination.value,"&hebergement=",document.recherche.hebergement.value,"&situation=",document.recherche.situation.value,"&nbp=",document.recherche.nbp.value,"&trier=",document.recherche.trier.value); if ( document.recherche.region ){ params = params.concat("®ion=",document.recherche.region.value); } if ( document.recherche.departement ){ params = params.concat("&departement=",document.recherche.departement.value); } if ( document.recherche.ville ){ params = params.concat("&ville=",document.recherche.ville.value); } if ( document.recherche.hcp.checked ){ params = params.concat("&hcp=",document.recherche.hcp.value); } if ( document.recherche.animalOUI.checked ){ params = params.concat("&animalOUI=",document.recherche.animalOUI.value); } if ( document.recherche.piscine.checked ){ params = params.concat("&piscine=",document.recherche.piscine.value); } if ( document.recherche.trier ){ params = params.concat("&trier=",document.recherche.trier.value); } sendRequest(params,onResultLoaded); } function searchMer(){ initSearch(); var params = "&action=search&lang=".concat(document.recherche.lang.value,"&destination=france&situation=Mer"); sendRequest(params,onResultLoaded); } function searchVille(){ initSearch(); var params = "&action=search&lang=".concat(document.recherche.lang.value,"&destination=france&situation=Ville"); sendRequest(params,onResultLoaded); } function searchMontagne(){ initSearch(); var params = "&action=search&lang=".concat(document.recherche.lang.value,"&destination=france&situation=Montagne"); sendRequest(params,onResultLoaded); } function searchCampagne(){ initSearch(); var params = "&action=search&lang=".concat(document.recherche.lang.value,"&destination=france&situation=Campagne"); sendRequest(params,onResultLoaded); } function onResultLoaded(html){ document.getElementById("searchloading").style.display = "none"; document.getElementById("searchresult").innerHTML = html; }