var xmlhttp = null;
var isSafari = null;
var isMoz = null;
var isIE = null;


if (navigator.userAgent.indexOf("Safari") > 0){
    isSafari = true;
    isMoz = false;
    isIE = false;
}
else if (navigator.product == "Gecko"){
    isSafari = false;
    isMoz = true;
    isIE = false;
}
else{
    isSafari = false;
    isMoz = false;
    isIE = true;
}

function getHTTPObject(){

    if (window.XMLHttpRequest) {
        this.xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    return this.xmlhttp;
}

function doGET(url, queryString, handle){

    this.xmlhttp.open("GET", url + queryString, true);
    this.xmlhttp.onreadystatechange = handle;
    this.xmlhttp.send(null);
}


// Establecemos la variable para el httprequest
var http = getHTTPObject();
function handleHttpResponse(nom) {
	if (http.readyState == 4) {  // Si recibe respuesta
		if (http.status == 200) {  // Si la respuesta es correcta
			var xml = http.responseXML;
		
			var action = xml.firstChild.nodeName;
			if (action != null) {
				switch(action)
				{
					case "list_zone":
						getList_Zone_Action(xml);
					break;
					case "list_station":
						getList_Stations_Action(xml);
					break;
					case "list_heberg":
						getList_Heberg_Action(xml);
					break;
					case "moteur1":
						getOnglet1(xml);
					break;
				}
			}
		}
	}
}               
        
        
        
function getList_Zone(desc, langue) {
	if (desc != '') {
		url = "../../../librairie/js/moteur_recherche_v3/ajax/requete_destinations.php";
		queryString = "?code_pays="+desc+"&langue="+langue;
		doGET(url, queryString, handleHttpResponse);
		if(document.getElementById("sel_destinations")){
			document.getElementById("sel_destinations").value = '';
			document.getElementById("sel_destinations").focus();
		}
	}else{
		if(document.getElementById("sel_destinations")){
			document.getElementById("sel_destinations").value = '';
		}
	}
}  


function getList_Stations(desti, langue) {
	if(desti!=''){
		url = "../../../librairie/js/moteur_recherche_v3/ajax/requete_stations.php";
		queryString = "?situgeo="+desti+"&langue="+langue;
		doGET(url, queryString, handleHttpResponse);
		document.getElementById("site_geo_4d").value=desti;
	}else{
		document.getElementById("station").value = '';
	}
}  

function getList_Heberg(type, param) {
	url = "../../../librairie/js/moteur_recherche_v3/ajax/requete_heberg.php";
	queryString = "?zone="+param+"&type="+type;	
	doGET(url, queryString, handleHttpResponse);
	document.getElementById("code_station_4d").value=param;	
}  

      
function getList_Zone_Action(xml) 
{
	if(document.getElementById("sel_destinations")){
		var responseElement = xml.getElementsByTagName("list_zone")[0];
		var zone = responseElement.getElementsByTagName("zone");
		cleanZoneList("sel_destinations");
		cleanZoneList("station");
		
		for (var i = 0; i < zone.length; i++) {
			document.getElementById("sel_destinations").options[i+1] = new Option(zone[i].getElementsByTagName("name")[0].firstChild.data,zone[i].getElementsByTagName("code")[0].firstChild.data);
			document.getElementById("sel_destinations").options[i+1].className=zone[i].getElementsByTagName("style")[0].firstChild.data; 
		}
	}
}

function getList_Stations_Action(xml) 
{
	var responseElement = xml.getElementsByTagName("list_station")[0];
	var station = responseElement.getElementsByTagName("station");
	cleanZoneList("station");
	cleanZoneList("sel_heberg");
	
	for (var i = 0; i < station.length; i++) {
		document.getElementById("station").options[i+1] = new Option(station[i].getElementsByTagName("name")[0].firstChild.data,station[i].getElementsByTagName("code")[0].firstChild.data);
	}
	
}

function getList_Heberg_Action(xml) 
{
	var responseElement = xml.getElementsByTagName("list_heberg")[0];
	var heberg = responseElement.getElementsByTagName("heberg");
	cleanZoneList("sel_heberg");
	
	for (var i = 0; i < heberg.length; i++) {
		document.getElementById("sel_heberg").options[i+1] = new Option(heberg[i].getElementsByTagName("name")[0].firstChild.data,heberg[i].getElementsByTagName("code")[0].firstChild.data);
	}
}	

     
// Limpia combo destinos
function cleanZoneList(name) 
{
	document.getElementById(name).options.length = 0;
	
	//if(name!="sel_destinations"){
		document.getElementById(name).options[0] = new Option(traduc_indifferent,"null");
		document.getElementById(name).options[0].className = 'rec-destcountry';
	//}
}

