function clicaimg(){
 var link=document.getElementById('infoid').value;
 var preu=document.getElementById('descid').value;
document.getElementById('fotoid').onClick=miraenlace(link,preu);


}


function miraenlace(link,preu){

var divenlace=document.getElementById('principal');
var enlaceinmo=document.createElement('div');
enlaceinmo.id = 'enlaceinmo';

divenlace.appendChild(enlaceinmo);
var elemento=document.createElement('a');
enlaceinmo.appendChild(elemento);
var nodotexto=document.createTextNode(preu);
elemento.appendChild(nodotexto);
elemento.id=link;
elemento.value=link;
elemento.setAttribute('href',"javascript:tajax("+link+")");
elemento.onclick= function() {clearinfo();};


}

function miralocal(){
ajaxlocal();
}





//funciones ajax busca local

function ajaxlocal() {    // native XMLHttpRequest object  

 if (window.XMLHttpRequest) {    
   req2 = new XMLHttpRequest();       
   req2.onreadystatechange = function() {ajaxlocalDone();};     
   req2.open("POST", 'funcionlocal.php', true);     
   req2.send(null);   // IE/Windows ActiveX version 
  } else if (window.ActiveXObject) {    
     req2 = new ActiveXObject("Microsoft.XMLHTTP");     
     if (req2) {   
        req2.onreadystatechange = function() {ajaxlocalDone();}; 
          req2.open("POST", 'funcionlocal.php', true); 
          req2.send();    
   }
 }		  
}
//var j=0;

var localarray=new Array();

function ajaxlocalDone() { 
   // only if req2 is "loaded"  
 if (req2.readyState == 4) {       // only if "OK"       
     if (req2.status == 200 || req.status == 304) { 
                                      var variosi= req2.responseText.split("|");   
                                     //ultimo=vari.pop();
                                      //var variosi=unique(vari);
                                     var di=document.getElementById('buscalocal');

//document.getElementById('1').innerHTML=variosi;
document.getElementById('buscalocal').innerHTML='Elija la poblacion de busqueda en la :';
                                     //while(j<variosi.length) {

for(j=0;j<variosi.length;j++){

var di=document.getElementById('buscalocal');
var enlac=document.createElement('a');
var enlacdiv=document.createElement('div');
di.appendChild(enlacdiv);
//var enlac=document.createElement('input');
enlac.id=variosi[j];
enlac.name=variosi[j];
//enlac.type='button';

enlac.value=variosi[j];
enlacdiv.appendChild(enlac);
enlac.onclick= function() {cleart();clears();};

var nodote=document.createTextNode(variosi[j]);
enlac.appendChild(nodote);


//j++;

        }  
  
for(a=0;a<variosi.length;a++){
eval(localarray.push(variosi[a]));

document.getElementById(variosi[a]).setAttribute('href',"javascript:tipoAjax(localarray["+a+"])");


} 


      }
   }
}

function tipoAjax(valor){
ajaxTipo(valor);
document.getElementById('localidad').value=valor;

buscaprop();
}




function unique(arrayName)
            {
                var newArray=new Array();
                label:for(var i=0; i<arrayName.length;i++ )
                {  
                    for(var j=0; j<newArray.length;j++ )
                    {
                        if(newArray[j]==arrayName[i]) 
                            continue label;
                    }
                    newArray[newArray.length] = arrayName[i];
                }
                return newArray;
            }


function 	ajaxTipo(dataToSend){

              ajaxTipoP('buscatipo.php',dataToSend);

}
function ajaxTipoP(url,dataToSend){

	var pageRequestP = false
	if (window.XMLHttpRequest) {
		pageRequestP = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ 
		try {
			pageRequestP = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e) {
			try{
				pageRequestP = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else return false
	pageRequestP.onreadystatechange=function() {	
		ajaxTipoPDone(pageRequestP)
}
	if (dataToSend) {		
		var sendDataP = 'sendDataP=' + dataToSend;
		pageRequestP.open('POST',url,true);
    pageRequestP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   	pageRequestP.send(sendDataP);
	}
	else {
		pageRequestP.open('GET',url,true)
		pageRequestP.send(null)	
	}


}

tipoarray=new Array();
//var f=0;
function ajaxTipoPDone(pageRequestP) { 

 if (pageRequestP.readyState == 4 && (pageRequestP.status==200 || window.location.href.indexOf("http")==-1)) {
		if(pageRequestP.responseText != '') {
                                      var restipo = pageRequestP.responseText.split(",");   
                                      ultimo=restipo.pop();
                                        var resti=unique(restipo);
document.getElementById('buscatipo').innerHTML='Elija el tipo de propiedad de busqueda';
                                     var diti=document.getElementById('buscatipo');

for(f=0;f<resti.length;f++){



var diti=document.getElementById('buscatipo'); 

enlacdivti=document.createElement('div');
diti.appendChild(enlacdivti);

var enlacti=document.createElement('a');



enlacti.id=resti[f];
enlacti.name=resti[f];


enlacti.value=resti[f];
enlacdivti.appendChild(enlacti);
enlacti.onclick= function() {clears();};
var nodoteti=document.createTextNode(resti[f]);
enlacti.appendChild(nodoteti);
eval(tipoarray.push(resti[f]));



document.getElementById(resti[f]).setAttribute('href',"javascript:preuAja(tipoarray["+f+"])");
} 
      } 
   }
}



function preuAja(valor){

document.getElementById('tipopropiedad').value=valor;

fajax();
buscaprop();
}


function cleart()
{

t=0;


 var diti=document.getElementById("buscatipo");

while (diti.hasChildNodes()) {
diti.removeChild(diti.childNodes[t]);

}t++;
tipoarray.length = 0;

document.getElementById('tipopropiedad').value="";
}


function clears()
{

w=0;

var ditip=document.getElementById('buscapreu'); 
while (ditip.hasChildNodes()) {
ditip.removeChild(ditip.childNodes[w]);

}w++;
preuarray.length = 0;
clearTimeout(buscatime);
document.getElementById("precio").value="";
}

function cleard()
{
v=0;
var divenlapy=document.getElementById('producto'); 
while (divenlapy.hasChildNodes()) {
divenlapy.removeChild(divenlapy.childNodes[v]);

}v++;
}




function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    return xmlHttp;
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      return xmlHttp;
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        return xmlHttp;
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
  }

var preuarray=new Array();

function fajax()    
{ 
    var tipopropiedad;
    var localidad;
    tipopropiedad = document.getElementById('tipopropiedad').value;
    localidad = document.getElementById('localidad').value;


    ajax=ajaxFunction();
    ajax.open("POST","elpreu.php",true);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    ajax.onreadystatechange=function() 
    {
		if (ajax.readyState==4) 
		{
		    if (ajax.status==200)
		     {



          respreu = ajax.responseText.split(','); 

                                       ultimo=respreu.pop();
                                    var resp=unique(respreu);

                                     var ditip=document.getElementById('buscapreu');
document.getElementById('buscapreu').innerHTML='Elija el precio de busqueda';


 for(a=0;a<resp.length;a++){



var ditip=document.getElementById('buscapreu'); 

enlacdivtip=document.createElement('div');
ditip.appendChild(enlacdivtip);

var enlactip=document.createElement('a');



enlactip.id=resp[a];
enlactip.name=resp[a];


enlactip.value=resp[a];
enlacdivtip.appendChild(enlactip);

var nodotetip=document.createTextNode(resp[a]);
enlactip.appendChild(nodotetip);
//enlactip.onclick= function() {clearTimeout(buscatime);};

eval(preuarray.push(resp[a]));

document.getElementById(resp[a]).setAttribute('href',"javascript:preuAjax(preuarray["+a+"])");
}



		     }
		}
    }

    ajax.send("localidad="+localidad+"&tipopropiedad="+tipopropiedad);
} 

function preuAjax(valor){
clearTimeout(buscatime);
document.getElementById('precio').value =valor;
buscaprop();
}







function buscaprop(){

buscatot();
buscatime=setTimeout("buscaprop()", 5000);
}


function buscatot()    
{ 
    var tipopropiedad;
    var localidad;
    var precio;
    tipopropiedad = document.getElementById('tipopropiedad').value;
    localidad = document.getElementById('localidad').value;
    precio = document.getElementById('precio').value;


    ajaxt=ajaxFunction();
    ajaxt.open("POST","buscatot.php",true);
    ajaxt.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    ajaxt.onreadystatechange=function() 
    {
		if (ajaxt.readyState==4) 
		{
		    if (ajaxt.status==200)
		     {


                                      var variosin = ajaxt.responseText.split("|");   
                                      document.getElementById('enlace').value=variosin[3];
                                      filenam="http://www.redcostablanca.es/imagefot/fotosinmob/med/";
                                      archiv=filenam+variosin[0];
                                      document.getElementById('fotoid').src=archiv;
                                      document.getElementById('descid').innerHTML=variosin[1];
                                      document.getElementById('descid').value=variosin[1];
                                       document.getElementById('infoid').value=variosin[3];
                                      document.getElementById('infoid').innerHTML=variosin[2]// '<a href ="mas_info.php?ID='+enlace+'" target="_blank">'+enlace+'</a>';



		     }
		}
    }

    ajaxt.send("localidad="+localidad+"&tipopropiedad="+tipopropiedad+"&precio="+precio);
} 




function tajax(dataToSendt) {

	var page= false
	if (window.XMLHttpRequest) {
		page = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ 
		try {
			page = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e) {
			try{
				page= new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else return false
	page.onreadystatechange=function() {	
		ajaxDonet(page);
}
	if (dataToSendt) {		
		var sendDataPt = 'sendDataPt=' + dataToSendt;
		page.open('POST','rand.php',true);
    page.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   	page.send(sendDataPt);
	}
	else {
		page.open('GET','rand.php',true)
		page.send(null)	
	}	  
}
var concepto=['o','localidad:','localizacion:','precio:','mconstr:','mparc:','antiguedad aņos:','terrazas:','piscina:','jardin:','garage:','plantas:','habitaciones:','aseos:',
'cocina:','salones:','telefono:'];

var idarray=new Array();
function ajaxDonet(page) { 
   // only if req is "loaded" 

 if (page.readyState == 4) {       // only if "OK"       
     if (page.status == 200 || page.status == 304) { 
                                      var variosinp = page.responseText.split("|");  
                                     ultimo=variosinp.pop();
                                        var long=variosinp.length; 
                                       var desc=variosinp.slice(long-40,long);
                                     variosinp.splice(long-40,long);
                                      filenamp="http://www.redcostablanca.es/imagefot/fotosinmob/min/";

                                     var divenlap=document.getElementById('producto');



for(h=0;h<variosinp.length/3;h++) {
                              var n=3*h;
                               filap=filenamp+variosinp[n];
eval(idarray.push(variosinp[n+2]));

var enlacein=document.createElement('div');
enlacein.id = 'enlacein';
enlacein.value = 'enlacein';
divenlap.appendChild(enlacein);
var elementds=document.createElement('a');
elementds.id='vars'+h;

enlacein.appendChild(elementds);
var elementg=document.createElement('IMG');
elementg.setAttribute("src",filap);
elementds.appendChild(elementg);
var nodotep=document.createTextNode(variosinp[n+1]);
enlacein.appendChild(nodotep);
document.getElementById('vars'+h).setAttribute('href',"javascript:popUp(idarray["+h+"])");
elementg.onmouseout= function() {popHide();};


}
if(idarray.length<5){
for(v=idarray.length;v<5;v++) {
var enlacein=document.createElement('div');
enlacein.id = 'enlacein';
enlacein.value = 'enlacein';
divenlap.appendChild(enlacein);
}
}




var divendata=document.createElement('div');
divendata.id = 'divendata';
divendata.value = 'divendata';
divenlap.appendChild(divendata);

 for(s=1;s<concepto.length;s++){
if(desc[s]){
var enlaces=document.createElement('div');
enlaces.className = 'enlaces';
enlaces.value = 'enlaces';
divendata.appendChild(enlaces);
var nodotepy=document.createTextNode(concepto[s]+desc[s]);
enlaces.appendChild(nodotepy);
}
}
var enlaces=document.createElement('div');
enlaces.className = 'enlaces';
enlaces.value = 'enlaces';
divendata.appendChild(enlaces);
var eledesc=document.createElement('a');
enlaces.appendChild(eledesc);
var nododesc=document.createTextNode('email contacto');
eledesc.appendChild(nododesc);
eledesc.onclick= function() {popUpM(desc[19],desc[18]);};
eledesc.style.cursor="pointer";

var enlaces=document.createElement('div');
enlaces.className = 'enlaces';
enlaces.value = 'enlaces';
divendata.appendChild(enlaces);
var eleweb=document.createElement('a');
enlaces.appendChild(eleweb);
var nodoweb=document.createTextNode('web contacto');
eleweb.appendChild(nodoweb);
eleweb.setAttribute('href',"http://"+desc[17]);
eleweb.setAttribute('target',"_blank");
eleweb.style.cursor="pointer";

var descrip=document.createElement('div');
descrip.id = 'enladesc';
divendata.appendChild(descrip);
var nododesc=document.createTextNode(desc[0]);
descrip.appendChild(nododesc);
      } 
   }

}

function UpMail(id,email){

 var divformu=document.getElementById('popUpMail');
var nodop=document.createElement("p");
nodop.id='labe';
var nodoformu=document.createTextNode('Usted va a solicitar informacion sobre la propiedad de referencia : '+id+' introduza su e-mail y su telefono y nos pondremos en contacto con usted en breve.');
nodop.appendChild(nodoformu);
divformu.appendChild(nodop);

formu = document.createElement("form");
formu.name ="sendf";
//formu.action ="pc_sendmail.php";
//formu.method ="POST";
//formu.target=;
control = document.createElement("input");
control.setAttribute("type","text");
control.setAttribute("name","email");
control.setAttribute("value",email);
control.setAttribute("id","email");
control.setAttribute("class","campo");
control.readOnly=true;
formu.appendChild(control);

formu.appendChild(document.createElement("br"));
control1 = document.createElement("input");
control1.setAttribute("type","text");
control1.setAttribute("name","id");
control1.setAttribute("value","solicitar informacion numero de referencia :"+id);
control1.setAttribute("id","id");
control1.setAttribute("class","campo");
control1.readOnly=true;
formu.appendChild(control1);


formu.appendChild(document.createElement("br"));
control2 = document.createElement("input");
control2.setAttribute("type","text");
control2.setAttribute("value","entre su email");
control2.setAttribute("name","suemail");
control2.setAttribute("id","suemail");
control2.setAttribute("class","campo");
formu.appendChild(control2);


formu.appendChild(document.createElement("br"));
control3 = document.createElement("input");
control3.setAttribute("type","text");
control3.setAttribute("value","entre su consulta");
control3.setAttribute("name","telefono");
control3.setAttribute("id","telefono");
control3.setAttribute("class","campo");
formu.appendChild(control3);


formu.appendChild(document.createElement("br"));
control4 = document.createElement("input");
control4.setAttribute("type","button");
control4.setAttribute("value","enviar");
control4.setAttribute("id","botoenviar");
control4.onclick= function() 
{trataEmail(document.getElementById('suemail').value,document.getElementById('email').value,document.getElementById('id').value,document.getElementById('telefono').value);};
formu.appendChild(control4);

var enlaform=document.createElement('div');
enlaform.id = 'enlaform';
formu.appendChild(enlaform);


divformu.appendChild(formu);


}
function trataEmail(suemaildoc,emaildoc,iddoc,telefonodoc)   
{ 

    ajaxm=ajaxFunction();
    ajaxm.open("POST","pc_sendmail.php",true);
    ajaxm.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    ajaxm.onreadystatechange=function() 
    {
		if (ajaxm.readyState==4) 
		{
		    if (ajaxm.status==200)
		     {


                                      var variotar = ajaxm.responseText;   
                                      document.getElementById('enlaform').innerHTML=variotar;

control5 = document.createElement("input");
control5.setAttribute("type","button");
control5.setAttribute("value","cerrar");
control5.setAttribute("id","botoenviar");
control5.onclick= function() {popHideM();};
formu.appendChild(control5);

		     }
		}
    }

    ajaxm.send("suemail="+suemaildoc+"&email="+emaildoc+"&id="+iddoc+"&telefono="+telefonodoc);
} 

var objPopUpMail = null;

function popUpM(id,email) {

	UpMail(id,email);
	objPopUpMail = document.getElementById('popUpMail');
	objPopUpMail.style.visibility = 'visible';
}

function popHideM() {
	objPopUpMail.style.visibility = 'hidden';
	objPopUpMail = null;
             clearm();


}

function clearm()
{

b=0;
var divem=document.getElementById('popUpMail'); 
while (divem.hasChildNodes()) {
divem.removeChild(divem.childNodes[b]);

}b++;

}




function clearinfo()
{
cleard();
idarray.length = 0;
i=0;


 var ditifo=document.getElementById("producto");

while (ditifo.hasChildNodes()) {
ditifo.removeChild(ditifo.childNodes[i]);

}i++;

}


function dajax(dataToSendd) {

	var paged= false
	if (window.XMLHttpRequest) {
		paged = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ 
		try {
			paged = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e) {
			try{
				paged= new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else return false
	paged.onreadystatechange=function() {	
		ajaxD(paged);
}
	if (dataToSendd) {		
		var sendDataPd = 'sendDataPd=' + dataToSendd;
		paged.open('POST','desc.php',true);
    paged.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   	paged.send(sendDataPd);
	}
	else {
		paged.open('GET','desc.php',true)
		paged.send(null)	
	}	  
}



function ajaxD(paged) { 
   // only if req is "loaded" 

 if (paged.readyState == 4) {       // only if "OK"       
     if (paged.status == 200 || paged.status == 304) { 
                                      var variod = paged.responseText.split("|");   
                                       ultimo=variod.pop();
                                      filenamp="http://www.redcostablanca.es/imagefot/fotosinmob/med/";
                                      filap=filenamp+variod[0];

                                    var divend=document.getElementById('popUp');

var enlad=document.createElement('div');
enlad.id = 'enlad';
enlad.value = 'enlad';
divend.appendChild(enlad);

var elementimg=document.createElement('IMG');
elementimg.setAttribute("src",filap);
enlad.appendChild(elementimg);

var nodod=document.createTextNode(variod[1]+':'+variod[2]);
enlad.appendChild(nodod);


}
}
}


var objPopUp = null;

function popUp(whichLink) {

	dajax(whichLink);
	objPopUp = document.getElementById('popUp');
	objPopUp.style.visibility = 'visible';
}

function popHide() {
	objPopUp.style.visibility = 'hidden';
	objPopUp = null;
             clearh();

}

function clearh()
{

z=0;
var divez=document.getElementById('popUp'); 
while (divez.hasChildNodes()) {
divez.removeChild(divez.childNodes[z]);

}z++;

}


