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("xhr error"); } } params = params.concat("&lang=fr"); xhr.send(params); } function onChangePays(){ document.getElementById("selectRegion").innerHTML = ""; document.getElementById("selectDepartement").innerHTML = ""; document.getElementById("selectCommune").innerHTML = ""; if( document.formdepot.destination.value == "" ) return; document.getElementById("errPays").style.display = "none"; loading(document.getElementById("selectRegion")); var params = "&action=getregions&destination=".concat(document.formdepot.destination.value); sendRequest(params,onRegionsLoaded); } function onChangeRegion(){ document.getElementById("selectDepartement").innerHTML = ""; document.getElementById("selectCommune").innerHTML = ""; if( document.formdepot.region.value == "" ) return; document.getElementById("errRegion").style.display = "none"; loading(document.getElementById("selectDepartement")); var params = "&action=getdepartements&destination=".concat(document.formdepot.destination.value,"®ion=",document.formdepot.region.value); sendRequest(params,onDepartementsLoaded); } function onChangeDepartement(){ document.getElementById("selectCommune").innerHTML = ""; if( document.formdepot.departement.value == "" ) return; document.getElementById("errDept").style.display = "none"; loading(document.getElementById("selectCommune")); var params = "&action=getcommunes&destination=".concat(document.formdepot.destination.value,"®ion=",document.formdepot.region.value,"&departement=",document.formdepot.departement.value); sendRequest(params,onCommunesLoaded); } function onChangeVille(){ if( document.formdepot.ville.value == "" ) return; document.getElementById("errComm").style.display = "none"; } function onRegionsLoaded(html){ var node = document.getElementById("selectRegion"); node.className = ""; node.innerHTML = html; document.formdepot.region.focus(); } function onCommunesLoaded(html){ var node = document.getElementById("selectCommune"); node.className = ""; node.innerHTML = html; document.formdepot.ville.focus(); } function onDepartementsLoaded(html){ var node = document.getElementById("selectDepartement"); node.className = ""; node.innerHTML = html; document.formdepot.departement.focus(); }