var ajax = new sack();

function whenLoading(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Enviando petición...</p>";
}

function whenLoaded(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Petición realizada...</p>";
}

function whenInteractive(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Obteniendo datos...</p>";
}

function whenCompleted(){
	var e = document.getElementById('inter'); 
	e.innerHTML ="<p></p>";
}
function envia_pet() {
	ajax.requestFile = "buscador_home/postajax.php";
	ajax.method = 'post';
	ajax.element = 'inter';
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}
function validar() {
	var check =document.buscador.alo;
	selected = false
	x=0;
   	while (!selected && (x <check.length)) {
 		if (check[x].checked) {   
     		selected = true;  
    	}
    	x++;
	}
	if (document.buscador.tipo_bus.selectedIndex==0) {
		return false;
	}else if (!selected) {
		return false;
	}else if (document.buscador.tipo_bus.selectedIndex==2 && document.buscador.comunidades.selectedIndex==0) {
		return false;
	}else if (document.buscador.tipo_bus.selectedIndex==3 && document.buscador.provincias.length==0) {
		return false;
	}else {
		return true;
	}
}
function envia_pet() {
	var check=document.buscador.alo;
	var valor="";
	selected = false
	x=0;
   	while (!selected && (x <check.length)) {
 		if (check[x].checked) {   
     		selected = true;
    	}
    	x++;
	}
	
	if (document.buscador.tipo_bus.selectedIndex==0) {
		alert("Por favor, elige un tipo de búsqueda");
	}else if (!selected) {
		alert("Por favor, elige un tipo de alojamiento");
	}else if (document.buscador.tipo_bus.selectedIndex==2 && document.buscador.comunidades.selectedIndex==0) {
		alert("Por favor, elige una provincia");
	}else if (document.buscador.tipo_bus.selectedIndex==3 && document.buscador.provincias.length==0) {
		alert("Por favor, elige al menos una provincia");
	}else {
		ocultar('resto',1);
		ajax.requestFile = "buscador_home/postajax.php";
		ajax.method = 'post';
		ajax.element = 'datos';
		ajax.setVar("busqueda",document.buscador.tipo_bus.value);
		ajax.setVar("precio",document.buscador.precio.value);
		ajax.setVar("provincias",document.buscador.mprovincias.value);
		ajax.setVar("plazas",document.buscador.plazas.value);
		ajax.setVar("comunidad",document.buscador.comunidades.value);
		ajax.setVar("alojamientos",document.buscador.alojamiento.value);
		ajax.setVar("orden","");
		ajax.setVar("pag",0);
		ajax.onLoading = whenLoading;
		ajax.onLoaded = whenLoaded; 
		ajax.onInteractive = whenInteractive;
		ajax.onCompletion = whenCompleted;
		ajax.runAJAX();
	}
}
function pagina(num) {
	ajax.requestFile = "buscador_home/postajax.php";
	ajax.method = 'post';
	ajax.element = 'datos';
	ajax.setVar("pag",num);
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}
function ordenar() {
	ajax.requestFile = "buscador_home/postajax.php";
	ajax.method = 'post';
	ajax.element = 'datos';
	ajax.setVar("orden",document.ordenador.orden.value);
	ajax.setVar("forma",document.ordenador.forma.value);
	ajax.setVar("pag",0);
	ajax.onLoading = whenLoading;
	ajax.onLoaded = whenLoaded; 
	ajax.onInteractive = whenInteractive;
	ajax.onCompletion = whenCompleted;
	ajax.runAJAX();
}