var gihttprequestjson;
function sendajax(s_url, s_onresponse, s_data){

	gihttprequestjson = new Request({

		url: s_url,

		data: s_data,

		onRequest: function(){
			//alert("Sending");
		},

		onComplete: function(response){
			//alert('Response is done');
		},

		onSuccess: function(jsonObj){
			s_onresponse(eval( "(" + jsonObj + ")" ), jsonObj);
		},

		onFailure: function(){
			alert('The request failed.');
		}
	});

	gihttprequestjson.send();
}

/**/
function getprovinces(lang){
	$("waitprovince").style.display="inline";
	idpays = document.grpaidbooking_form.country.value;
	s_data = "idpays="+idpays+"&lang="+lang;
	s_file = "http://"+window.location.hostname+"/siteincludes/getprovinces.php";
	sendajax(s_file, setprovinces, s_data);
}
function setprovinces(jsonObj, text){
	//alert(text);
	//remove provinces
	liste = document.getElementById("province");
	while(liste.options.length > 0){
		liste.removeChild(liste.options[0]);
	}

	var provinces = jsonObj.provinces;
	if(provinces.length > 0){
		provinces.each(function(province) {
			//add news
			option = document.createElement("option");
			option.value = province.reservitid; //id			 
			option.text = province.nom;
			liste.options[liste.options.length] = option;
		});
	}
	$("waitprovince").style.display="none";	
	document.grpaidbooking_form.province.onchange();
}
function getregions(lang){
	$("waitregion").style.display="inline";
	idprovince = document.grpaidbooking_form.province.value;
	idpays = document.grpaidbooking_form.country.value;
	s_data = "idprovince="+idprovince+"&idpays="+idpays+"&lang="+lang;
	s_file = "http://"+window.location.hostname+"/siteincludes/getregions.php";
	sendajax(s_file, setregions, s_data);
}
function setregions(jsonObj, text){
	//alert(text);
	//remove regions
	liste = document.getElementById("region");
	while(liste.options.length > 0){
		liste.removeChild(liste.options[0]);
	}

	//id = 0;

	var regions = jsonObj.regions;
	if(regions.length > 0){
		regions.each(function(region) {
			//add news
			option = document.createElement("option");
			option.value = region.reservitid; //id			 
			option.text = region.nom;
			liste.options[liste.options.length] = option;

			if(!ReservITID_Thematique_isset && region.reservitid == ReservITID_Thematique){
				ReservITID_Thematique_isset = true;
				option.selected = true;
			}
		});
	}
	$("waitregion").style.display="none";	
	document.grpaidbooking_form.region.onchange();
}
function getvilles(lang){
	$("waitville").style.display="inline";
	idregion = document.grpaidbooking_form.region.value;
	idprovince = document.grpaidbooking_form.province.value;
	idpays = document.grpaidbooking_form.country.value;
	s_data = "idregion="+idregion+"&idprovince="+idprovince+"&idpays="+idpays+"&lang="+lang;
	s_file = "http://"+window.location.hostname+"/siteincludes/getvilles.php";
	sendajax(s_file, setvilles, s_data);
}
function setvilles(jsonObj, text){
	//alert(text);
	//remove villes
	liste = document.getElementById("namecity");
	while(liste.options.length > 0){
		liste.removeChild(liste.options[0]);
	}

	var villes = jsonObj.villes;
	if(villes.length > 0){
		villes.each(function(ville) {
			//add news
			option = document.createElement("option");
			option.value = ville.nom; //ville.reservitid; //id			 
			option.text = ville.nom;
			liste.options[liste.options.length] = option;
		});
	}
	$("waitville").style.display="none";
}
/**/

