var localidad22 = getQueryVariable('localidad');

getTipos();
getZonasPpo(document.getElementById('islaa').value);


if(!localidad22){
	getResultado(document.forms["sencillo"]);
}



function getQueryVariable(variable) { 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i = 0; i < vars.length; i++) { 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) { 
			return unescape(pair[1]); 
		} 
	} 
	return false; 
}

function getZona(islaId){
	//getTipos();
	var strURL="includes/moviles.php?accion=localidades&id="+islaId;
  var req = getXMLHTTP();
  if (req){

		req.onreadystatechange = function(){
      if (req.readyState == 4){
	 // only if "OK"
				if (req.status == 200){
					document.getElementById('zona').innerHTML=req.responseText;

			 	} else {
					alert("Problema de conexión1 XMLHTTP:\n" + req.statusText);
			 	}
				
      }//if req
     }//function()
   	req.open("GET", strURL, true);
   	req.send(null);
	}//if(req)
}//function



function getZonasPpo(islaId,localidad){
	//getTipos();
	var localidad = getQueryVariable('localidad');
	if(islaId != 0){
	//	alert (var1);
	
		var strURL="includes/moviles.php?accion=localidades&id="+islaId+"&localidadID="+localidad;
		var req = getXMLHTTP();
		if (req){
	
			req.onreadystatechange = function(){
				if (req.readyState == 4){
		 // only if "OK"
					if (req.status == 200){
						document.getElementById('zona').innerHTML=req.responseText;
	
					} else {
						alert("Problema de conexión1 XMLHTTP:\n" + req.statusText);
					}
					
				}//if req
			 }//function()
			req.open("GET", strURL, true);
			req.send(null);
		}//if(req)
		
		
		getResultado(document.forms["sencillo"], localidad);
		
	}
	
	
}//function




function getTipos(){

	var strURL="includes/moviles.php?accion=tipos";
  var req = getXMLHTTP();
  if (req){

		req.onreadystatechange = function(){
      if (req.readyState == 4){
	 // only if "OK"
				if (req.status == 200){
					document.getElementById('tipo').innerHTML=req.responseText;

			 	} else {
					alert("Problema de conexión2 XMLHTTP:\n" + req.statusText);
			 	}
				
      }//if req
     }//function()
   	req.open("GET", strURL, true);
   	req.send(null);
	}//if(req)
}//function








function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
		
		

		
		
		
		
		
		
		
		
		
function buscarS(form){

	var strURL;

	strURL="buscador.php?piscina=false&terraza=false&ascensor=false&amueblado=false&jardin=false&garaje=false&banos=0&dormitorios=0&metros=0&precio=180000&contrato="+form.contrato.value+"&tipo="+form.tipo.value+"&localidad="+form.zona.value+"&municipio=undefined&isla="+form.isla.value+"&buscador=rapido";
	
	
	location.href = strURL;
	return false;
	
	
	
}//function




function buscarRef(form){

	var strURL;

	strURL="buscadorRef.php?ref="+form.referencia.value;
	
	
	location.href = strURL;
	return false;
	
	
	
}//function



function getResultado(form,loc){

//alert ("LOC:"+loc);
	var loca;

	if(loc == undefined){
	//	alert ("es indefinido");
		loca = form.zona.value;
	}else{
		loca = loc;
	}
	
	if(form.isla.value == 0){
	//	alert ("es indefinido");
		loca = 0;
	}
	

	var strURL="buscador.php?piscina=false&terraza=false&ascensor=false&amueblado=false&jardin=false&garaje=false&banos=0&dormitorios=0&metros=0&precio=9999999&contrato="+form.contrato.value+"&tipo="+form.tipo.value+"&localidad="+loca+"&municipio=undefined&isla="+form.isla.value+"&buscador=movil";
	
	//alert("UNO"+strURL);
  var req = getXMLHTTP();
  if (req){

		req.onreadystatechange = function(){
      if (req.readyState == 4){
	 // only if "OK"
				if (req.status == 200){
					document.getElementById('resultado').innerHTML=req.responseText;

			 	} else {
					alert("Problema de conexión3 XMLHTTP:\n" + req.statusText);
			 	}
				
      }//if req
     }//function()
   	req.open("GET", strURL, true);
   	req.send(null);
	}//if(req)
}//function


function getResultado2(form,loc){

	var strURL="buscador.php?piscina=false&terraza=false&ascensor=false&amueblado=false&jardin=false&garaje=false&banos=0&dormitorios=0&metros=0&precio=9999999&contrato="+form.contrato.value+"&tipo="+form.tipo.value+"&localidad="+loc+"&municipio=undefined&isla="+form.isla.value+"&buscador=movil";
	alert("DOS"+strURL);
  var req = getXMLHTTP();
  if (req){

		req.onreadystatechange = function(){
      if (req.readyState == 4){
	 // only if "OK"
				if (req.status == 200){
					document.getElementById('resultado').innerHTML=req.responseText;

			 	} else {
					alert("Problema de conexión3 XMLHTTP:\n" + req.statusText);
			 	}
				
      }//if req
     }//function()
   	req.open("GET", strURL, true);
   	req.send(null);
	}//if(req)
}//function
















