var tipoventana=0;
var auxdonde="";
var bclose=false;
var noseguir=0;
var valoroperacion=0;
var valoremail ="";
var valortipo=0;
var valorprecio=0;
var valorciudad=0;
var altocuadro=0;
var derechacuadro=0;
var valoragencia=0;
var valorcodigo=0;
var posicionasistente=0;
var timermensaje="";
var timerasistente="";
var valorhtml="";
var objobj ="";
var arrciudad ;
var auxprevio="";
var altobanner=0;
var derechabanner=0;
var botonatras=0;




function abreresultados(cadena)
{
var cadorden='';
cadruta=document.getElementById("barrahori").src;
if (document.getElementById("ordenqryb")!=null) cadorden="&orden=" +document.getElementById("ordenqryb").value
if (document.getElementById("ordenqrya")!=null) cadorden="&orden=" +document.getElementById("ordenqrya").value
if (cadena.indexOf('.html')>10) cadorden='';

i=cadruta.indexOf("localhost/");
if (i>1)
    winopen ("http://localhost/"  + cadena,"_top");
else
    winopen ("http://www.haypisos.com/"  + cadena + cadorden,"_top");


}
function cambiaorden(texto,tipo)
{
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (i>1)
    winopen ("http://localhost/propiedades/listados.php"  + texto + "&orden=" +document.getElementById("ordenqry" + tipo).value,"_top");
else
    winopen ("http://www.haypisos.com/propiedades/listados.php"  + texto + "&orden=" +document.getElementById("ordenqry" + tipo).value,"_top");

}
window.onscroll=scrollmovido;
function cambiaordenba(texto)
{

cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (i>1)
    winopen ("http://localhost/propiedades/listados.php"  + texto + "&orden=" +document.getElementById("ordenqry" ).value,"_top");
else
    winopen ("http://www.haypisos.com/propiedades/listados.php"  + texto + "&orden=" +document.getElementById("ordenqry" ).value,"_top");

}
function inicio()
{
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (i>1)
    winopen ("http://localhost/portal","_top");
else
    winopen ("http://www.haypisos.com","_top");

}

function publicar()
{
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (i>1)
    winopen ("http://localhost/publicarpisosgratis.php","_top");
else
    winopen ("http://www.haypisos.com/publicarpisosgratis.php","_top");

}


function getleft(ele)
{
//calcular la posicion de un elemento
    if (ele.offsetParent)
        return ele.offsetLeft + getleft(ele.offsetParent);
    else
        return ele.offsetLeft;
}


function gettop(ele)
{ //calcular la posicion de un elemento
    if (ele.offsetParent)
        return (ele.offsetTop + gettop(ele.offsetParent));
    else
        return (ele.offsetTop);
}


function verventana()
{                            //el tipoventana se le asignara a la llamada del location para saber que ventana cargar con el mismo iframe
valorhtml="";

valorhtml = window.fraprevio.document.body.innerHTML.replace("/\[^\>]+\>/gm", "");

if (valorhtml.length>0)
    {

//para no ponerlo en la hoja de estilo
     if (document.getElementById("previo")!=null)       document.getElementById("previo").style.position="absolute";


    if (valorhtml.indexOf('http://')==0)
        winopen (valorhtml,"_blank");
    else
        {
         if (tipoventana=='fichalocalidades')
             mostrarlocalidades("",1); //solo para la pagina principal carga las localidades
         else
              if (tipoventana=='fichaprevia') verprevio("","","",1);  // esto es para el previo de los resultados
                  else
                       subventanaprevio (1,0,0,0);
         }
    }
}


function verprevio(codigo,agencia,objeto,ventana)
{
var pantalla ="";
var firefox="";

if (ventana==0)    //ventana, se utiliza para saber si lanzas el php o cargas ya el div con los resultados obtenidos
{

if ((tipoventana=='fichaprevia') && (auxprevio==codigo + agencia)) return 0;
//if (document.getElementById("previo").style.display!="block")
//{
if (screen.width<1000) pantalla="&pantalla=1";
objobj=objeto;  //objeto , es el nombre del objeto , para que posteriormente poder calcular la altura y posicion en la ventana de esa propiedad para poner el previo
tipoventana='fichaprevia';
auxprevio=codigo + agencia;
//   fraprevio.location="verprevio.php?codigo=" + codigo + "&agencia=" +agencia ;
 if (navigator.appName == "Netscape") firefox="&firefox=1";
   fraprevio.location= rutapath()+ "propiedadprevia.php?codigo=" + codigo + "&agencia=" +agencia + pantalla + firefox;

// }
    document.getElementById("subprevio").style.display='none';
    document.getElementById("ventanamodal").style.display='none';
    document.getElementById("capaFondo").style.visibility="hidden";

}
else
    {

    //esto es cuando no muesra la paginacion
     if (document.getElementById("ordenqrya")!=null)
         {
            document.getElementById("ordenqrya").style.visibility= "visible";
                 if (document.getElementById("ordenqryb")!=null) document.getElementById("ordenqryb").style.visibility= "visible";
         }

    document.getElementById("previo").innerHTML = valorhtml;

document.getElementById("previo").style.visibility="visible";

   document.getElementById("previo").position = "absolute";
   document.getElementById("previo").style.display="block";
    var derecha=0;

   derecha=getleft(document.getElementById(objobj));
   derecha=derecha-10;
//   derecha=derecha +document.getElementById(objobj).width;
    var alto=0;
//    alto=(document.getElementById(objobj).height/2);

    alto=alto+gettop(document.getElementById(objobj));
    alto=alto-26;

    document.getElementById("previo").style.left=derecha +"px";
//    alert (window.innerHeight); firefox

    if (alto<document.documentElement.scrollTop) window.scrollTo(0,alto);
    diferencia=((alto+document.getElementById(objobj).height+26)-(document.documentElement.clientHeight+ document.documentElement.scrollTop))


    if (((alto+document.getElementById(objobj).height+26)>(document.documentElement.clientHeight+ document.documentElement.scrollTop)) && ((document.documentElement.scrollTop+diferencia+25)>document.documentElement.scrollTop )) window.scrollTo(0,document.documentElement.scrollTop+diferencia+25);
    document.getElementById("previo").style.top=alto +"px";
//MUEVE EL SCROLL A ESA POSICION
//    window.scrollTo(0,alto);
//

//  if (tipoventana=="fichaprevia") cargafotosprevio(0);
      tipoventana='';
    auxprevio='';

    }

}


function mostrarlocalidades(valorprovincia,ventana)
{
var pantalla="";
if (ventana==0)    //ventana, se utiliza para saber si lanzas el php o cargas ya el div con los resultados obtenidos
    {
    if (screen.width<1000) pantalla="&pantalla=1";
    tipoventana='fichalocalidades';
   fraprevio.location="configweb/listalocalidades.php?codigoprovincia=" + valorprovincia  + pantalla;
   }
   else
       {
        document.getElementById("previo").innerHTML = valorhtml;
        document.getElementById("previo").style.display="block";
        var derecha=0;
        derecha=getleft(document.getElementById("poblaciones"));
        document.getElementById("previo").style.left=derecha +"px";
        document.getElementById("previo").style.top="0px";
        var alto=0;

        alto=gettop(document.getElementById("opcionbuscar"));
        document.getElementById("previo").style.height=alto +"px";
        document.getElementById("ventanalocalidades").style.height=(alto-4) +"px";
        document.getElementById("previo").style.width=document.getElementById("poblaciones").offsetWidth + "px";
        document.getElementById("previo").style.overflow="auto"
       }
}

function mostrarfiltroavanzado()
{
if (document.getElementById("filtroavanzado").style.display=="none")
    document.getElementById("filtroavanzado").style.display="block";
else
    {
    document.getElementById("filtroavanzado").style.display="none";
    document.getElementById("lstprecio").value="";

    }


}
function mostrarmapa(tipo)
{
    document.getElementById("previo").style.display="none";
if (tipo==0)
{

derecha=getleft(document.getElementById("lstprovincia"));

alto=gettop(document.getElementById("lstprovincia"));

document.getElementById("lstprovincia").style.display= "none";
document.getElementById("mapaprovincia").innerHTML = '<img src="/imagenes/portal-gratuito-mapa.gif" name="map" usemap="#map" border="0">';

document.getElementById("mapaprovincia").style.display="block";
document.getElementById("mapaprovincia").style.position="absolute";



document.getElementById("mapaprovincia").style.left=derecha +"px";
document.getElementById("mapaprovincia").style.top=alto +"px";
}
 else {
     document.getElementById("lstprovincia").style.display= "block";
    document.getElementById("mapaprovincia").style.display= "none";
    document.getElementById("mapaprovincia").style.onmousemove="";
    document.getElementById("mapaprovincia").style.left="-500px";

 }

}






function generaciudades()
{
var j=0;
var sel=0;
arrciudad = new Array() ;
i=1;

if (document.getElementById("ciudad[1]"))
{
    var valor=0;

    while (i>0)
    {
        if (document.getElementById("ciudad[" + i +"]")==null)
             i=-1;
        else
            {
             if ((document.getElementById("ciudad[" + i +"]").checked==true) || (document.getElementById("ciudad[0]").checked==true))
                 {
                   arrciudad[j]=document.getElementById("ciudad[" + i +"]").value;
                 j=j+1;
                 }
            }
        i=i+1;
    }

}
else
    {

    sel = document.getElementById("lstprovincia").selectedIndex;
    if (sel<0)
       alert ('Debes de seleccionar una Provincia del 3º Paso');
    else
        {
        mostrarlocalidades(document.getElementById("lstprovincia").options[sel].value,"");
        }
    valor=1;
    }

//si todos=1 significa que estan todos seleccionados y que no pase ninguna cadena o si?
//if (todos==0) arrciudad = new Array() ;
//for  (i=0;i<arrciudad.length;i++)
  //    {
    //  alert (arrciudad[i]);
    //  }
return valor;
}


function frmcontactofaltanciudades()
{
var numciudad="";
var pantalla="";
if (screen.width<1000) pantalla="&pantalla=1";
numciudad=document.getElementById("lstprovincia").value;

tipoventana='faltanlocalidades';
//subventanaprevio (0,7,numciudad,0);
fraprevio.location=rutapath() +"formularios/faltalocalidad.php?numprovincia=" + numciudad + pantalla;

}


function realizarbusqueda()
{
var operacion;
operacion=document.getElementById("lstoperacion").value;
if (operacion.length==0)
{
alert ('Debes de seleccionar el tipo de operación (Venta, Alquiler o Promociones) \n\n Situado en el cuadro del "2º PASO"');
return 0;
}
valor=generaciudades();
//no hay provincias seleccionadas
if (valor==1) return 0;
var operacion="";
operacion="&numoperacion=" + document.getElementById("lstoperacion").value;
//operacion=operacion.substring(1); // equivale a mid(1,cadena)
//significa que estan todos seleccionados

var tipogrupo="";
tipogrupo="&tipogrupo=" + document.getElementById("lstgrupo").value;

//grupo=grupo.substring(1); // equivale a mid(1,cadena)
//significa que estan todos seleccionados


if (arrciudad.length==0)
    {
    alert ('Debes de seleccionar al menos una localidad');
    return 0;
    }
    else
        {

        var cadena="";
        for (i=0;i<arrciudad.length;i++)
             {

             cadena=cadena +"," +arrciudad[i];
             }
             cadena=cadena.substring(1);

        }
   var avanzado="";
if (document.getElementById("filtroavanzado").style.display=="block")
    {

    if (document.getElementById("lstprecio").value!="") avanzado= avanzado + "&precio=" + document.getElementById("lstprecio").value;
    if (document.getElementById("lstmetros").value!="") avanzado= avanzado + "&metros=" + document.getElementById("lstmetros").value ;
   if (document.getElementById("lsthabitaciones").value!="") avanzado= avanzado + "&habitacion=" + document.getElementById("lsthabitaciones").value;
    if (document.getElementById("chkascensor").checked==true) avanzado= avanzado + "&ascensor=1";
    if (document.getElementById("chkurbanizacion").checked==true) avanzado= avanzado + "&urbanizacion=1" ;
    if (document.getElementById("chkpiscina").checked==true) avanzado= avanzado + "&piscina=1" ;
    }


winopen (rutapath() + "listados.php?numciudad=" +  cadena + avanzado + tipogrupo + operacion,"_top");
}

function posicionar()
{
var altura=0;
altura=gettop(document.getElementById("menubotones"))+8;
if (document.getElementById("propiedadseleccionada")!=null)
    {

    altura=gettop(document.getElementById("propiedadseleccionada"));
    altu= (document.getElementById("propiedadseleccionada").offsetHeight);
    altu=(document.documentElement.clientHeight+altu);
    altu=altu/2;
    altura=altura-altu;
    }

if (altura>document.documentElement.scrollTop)
{
if (screen.width>850) {
    window.scrollTo(0,altura); }
else {
    window.scrollTo(0,altura); }
}

}

function swap(id,newsrc){
   var image=locateImage(id);
   if(image){
      image.src=newsrc;
   }
}
function locateImage(name){
   var image=false;
   if(document.images){
      image=document.images[name];
   }
   if(image){
      return image;
   }
   return false;
}

function rutapath ()
{
var cadruta="";
var i=0;
cadruta=document.getElementById("barrahori").src;
//if (navigator.appName == "Netscape") return "propiedades/";
i=cadruta.indexOf("localhost/");
if (i>1)
    {
    cadruta=cadruta.replace("http://localhost/","");
    cadruta="http://localhost/propiedades/";
    }
    else
        cadruta="/propiedades/";


return cadruta;
}

function cambiafoto(rutafoto)
{
var objeto;

if (rutafoto.indexOf('peq.jpg')>0)
          objeto=document.getElementById("imageid");
else
    objeto=document.getElementById("imagefichaid");


if (objeto.src!=rutafoto)
    {
    if (navigator.appName == "Netscape")
        objeto.src = rutafoto;
    else
        {
        objeto.style.filter="blendTrans(duration=1,Transition=16)";
        objeto.filters.blendTrans.Apply();
        objeto.src = rutafoto;
        objeto.filters.blendTrans.Play()
        }
    }
}

function subventanaprevio(ventana,tipo,agencia,codigo)
{
//tipoventana por aqui se utilizaran el 2,3,4,5
//esta funcion es llamada desde el previo que me llamen-2, recibir emails-1, y ficha completa -3,4 - es enviar propiedad

var nombreventana="";
var pantalla="";


if (screen.width<1000) pantalla="&pantalla=1";
    //esto es cuando no muesra la paginacion
     if (document.getElementById("ordenqrya")!=null)
         {
            document.getElementById("ordenqrya").style.visibility= "hidden";
                             if (document.getElementById("ordenqryb")!=null) document.getElementById("ordenqryb").style.visibility= "hidden";
         }


if (ventana==0)
    {
    botonatras=botonatras+1;

    tipoventana=tipo;

    if ((tipo=='mailficha') || (tipo=='mailpag') || (tipo=='llamarficha') || (tipo=='llamarpag'))
         {

         fraprevio.location=rutapath() + "formularios/quemellamen.php?tipo=" + tipo + "&codigo=" + codigo + "&agencia=" +agencia + pantalla;
         }

//    if (tipo=='verficha') fraprevio.location=rutapath() + "fichapiso.php?codpiso=" + codigo + "&codagencia=" +agencia  + pantalla;
    if (tipo=='verficha')
        {
//        fraprevio.location= rutapath()+ "parametros/actestadistica.php?codigo=" + codigo + "&agencia=" +agencia + "&tipo=3";
          if (document.getElementById("pubbanner")!=null) document.getElementById("pubbanner").style.visibility="hidden";
          cadruta=document.getElementById("barrahori").src;
          i=cadruta.indexOf("localhost/");
          if (i>0)
                  fraprevio.location=rutapath() + "manualfichapiso.php?" + codigo + "&codagencia=" +agencia  + pantalla;
          else
                  fraprevio.location=rutapath() + "ficha/fichapiso.php?codpiso=" + codigo + "&codagencia=" +agencia  + pantalla;
        }
    if (tipo=='enviaficha')
        {
         alert ('Actualmente en desarrollo');
//          fraprevio.location="quemellamen.php?tipo=" + tipo + "&codigo=" + codigo + "&agencia=" +agencia + pantalla;
        }
    if (tipo=='filtrazonas') fraprevio.location=rutapath() + "formularios/filtrarzonas.php?ciudades=" + agencia + pantalla;
    if (tipo=='filtraprecios') fraprevio.location=rutapath() + "formularios/filtraprecios.php?tipoprecio=" + agencia + "&operacion=" + codigo  + pantalla;

    if (tipo=='nohaypisos') fraprevio.location=rutapath() + "formularios/nohaypisos.php?numtipo=" + agencia + "&numciudad=" + codigo  + pantalla;
    if (tipo=='agenciabanner') fraprevio.location=rutapath() + "listados/agenciabanner.php?agencia=" + agencia   + pantalla;

    }
    else
        {

        if (tipoventana=='verficha')
            {
            document.getElementById("capaFondo").style.visibility="visible";
            document.getElementById("capaFondo").style.top=document.documentElement.scrollTop +"px";
            document.getElementById("previo").style.display= "none";
            document.getElementById("ventanamodal").style.display='none';
                nombreventana="subprevio";
            }
            else
                nombreventana="ventanamodal";

        if ((tipoventana=='faltanlocalidades') || (tipoventana=='nohaypisos') || (tipoventana=='consultahaypisos')) nombreventana="previo";
        if (document.getElementById(nombreventana)==null) nombreventana="previo";
//        if (document.getElementById(nombreventana)==null) alert (nombreventana);
      document.getElementById(nombreventana).innerHTML = valorhtml;
      document.getElementById(nombreventana).style.visibility="visible";

//   document.getElementById("previo").position = "absolute";

        document.getElementById(nombreventana).style.display="block";
        alto=document.getElementById(nombreventana).offsetHeight;
        ancho=document.getElementById(nombreventana).offsetWidht;

        //fichapiso
        if (tipoventana=='verficha')
            {
            alto=document.getElementById(nombreventana).offsetHeight;
            alto=((document.documentElement.clientHeight-alto)/2);
            ancho=document.getElementById(nombreventana).offsetWidth;
            ancho=(anchoarea()-ancho)/2;

            if (alto<0)  alto=-7;
            document.getElementById(nombreventana).style.top=(alto+ document.documentElement.scrollTop) +"px";

            document.getElementById(nombreventana).style.left=ancho +"px";
            return 0;
           }
         if (tipoventana=='faltanlocalidades')
             {
            document.getElementById(nombreventana).style.top="0px";

            document.getElementById(nombreventana).style.left=getleft(document.getElementById("poblaciones")) +"px";
             return 0;
             }
             //sino recojes los datos de alto y ancho cambia el absolute por el por el auto
            alto=document.getElementById(nombreventana).offsetHeight;
            ancho=document.getElementById(nombreventana).offsetWidth;
            document.getElementById(nombreventana).style.top=(((document.documentElement.clientHeight-alto)/2)+ document.documentElement.scrollTop) +"px";
            document.getElementById(nombreventana).style.left=(document.documentElement.scrollLeft + ((document.documentElement.clientWidth-ancho)/2)) + "px";
        }
}

function solonumeros(e){
tecla_codigo = (document.all) ? e.keyCode : e.which;
if(tecla_codigo==8)return true;
patron =/[0-9]/;
if (tecla_codigo!=0)
{
tecla_valor = String.fromCharCode(tecla_codigo);

return patron.test(tecla_valor);

}
else
    {
    return 1;
    }

}

function enviarsolicitud(tipo,agencia,codigo)
{

var telefono="";
var email="";
var nombre="";
var notificar="";
var precio="";
var hacer=0;
var descripcion="";

if (document.getElementById("telefono")!=null) telefono=document.getElementById("telefono").value;
if (document.getElementById("telefonoinicio")!=null) telefono=document.getElementById("telefonoinicio").value;
if ((document.getElementById("email")!=null)  && (email.length===0)) email=document.getElementById("email").value;
if ((document.getElementById("nombre")!=null) && (nombre.length===0)) nombre=document.getElementById("nombre").value;
if ((document.getElementById("nombreinicio")!=null) && (nombre.length===0)) nombre=document.getElementById("nombreinicio").value;
if ((document.getElementById("nombredos")!=null) && (nombre.length===0)) nombre=document.getElementById("nombredos").value;
if ((document.getElementById("nombretres")!=null) && (nombre.length===0)) nombre=document.getElementById("nombretres").value;
if (document.getElementById("notificar")!=null)
    {
    if (document.getElementById("notificar").checked==true) notificar=1;
    }
if (document.getElementById("precio")!=null) precio=document.getElementById("precio").value;
if ((document.getElementById("descripcion")!=null)  && (descripcion.length===0)) descripcion=document.getElementById("descripcion").value;
if ((document.getElementById("descripcioninicio")!=null)  && (descripcion.length===0)) descripcion=document.getElementById("descripcioninicio").value;
if ((document.getElementById("descripciondos")!=null)  && (descripcion.length===0))  descripcion=document.getElementById("descripciondos").value;
if ((document.getElementById("telefonodos")!=null)   && (telefono.length===0)) telefono=document.getElementById("telefonodos").value;
if ((document.getElementById("telefonotres")!=null)   && (telefono.length===0)) telefono=document.getElementById("telefonotres").value;
if ((document.getElementById("emaildos")!=null)   && (email.length===0))email=document.getElementById("emaildos").value;
if ((document.getElementById("emailinicio")!=null)   && (email.length===0))email=document.getElementById("emailinicio").value;
if ((document.getElementById("emailtres")!=null)  && (email.length===0)) email=document.getElementById("emailtres").value;
if ((document.getElementById("preciodos")!=null) && (precio.length===0)) precio=document.getElementById("preciodos").value;

if ((tipo=="faltalocalidad") || (tipo=="nohaypisos") || (tipo=="bannerhaypisos") || (tipo=="compro"))
    {
    if (telefono.length>0)
         {
         if (email.length>0) hacer= compruebaemail(email);
         if (comprobartelefono(telefono)==0)
             {
             alert ('Debes de introducir un telefono valido');
             hacer=1
             }
         }
         else
             {
             hacer=1;
             alert ('Debes de introducir un telefono valido');
             }
    }
if (tipo=="enviaficha")
    {
    if (email.length>0)
         {
              hacer= compruebaemail(email);
             if (comprobartelefono(telefono)==0)
                 {
                 alert ('Error en el teléfono');
                 hacer=1
                 }

         }
         else
             {
             hacer=1;
             alert ('Debes de rellenar un E-mail');
             }
    }

if ((tipo=="OBRA") || (tipo=="frmresul") || (tipo=="FICHA") || (tipo=="resulobra"))
    {
    if (email.length>0) hacer= compruebaemail(email);
       if (comprobartelefono(telefono)==0)
                 {
                 alert ('Error en el teléfono');
                 hacer=1
                 }

    if (hacer==0)
        {
             if (comprobartelefono(telefono)==0)
             {
             alert ('Debes de introducir un telefono valido');
             hacer=1;
             }

        }

    }

if (tipo.indexOf('llamar')==0) //que me llanen
{

if (comprobartelefono(telefono)==0)
    {
    hacer=1;
    alert ('Error en el Teléfono')
    }
}
//para recibir emails

if (tipo.indexOf('mail')>-1)  hacer= compruebaemail(email);
var cadena="";
if (hacer==0)
    {
    botonatras=botonatras+1;
    if (tipo=='faltalocalidad')
        fraprevio.location=rutapath() + "formularios/enviarsolicitud.php?tipo=" + tipo + "&telefono=" + telefono + "&agencia=" + agencia  + "&codigo=" + codigo +"&nombre=" + nombre + "&email=" + email + "&notificar=" + notificar + "&precio=" + precio + "&descripcion=" + descripcion ;
     else
        fraprevio.location=rutapath() + "formularios/enviarsolicitud.php?tipo=" + tipo + "&telefono=" + telefono + "&agencia=" + agencia  + "&codigo=" + codigo +"&nombre=" + nombre + "&email=" + email + "&notificar=" + notificar + "&precio=" + precio + "&descripcion=" + descripcion;
    }
if ((tipo=="OBRA") || (tipo=="frmresul") || (tipo=="FICHA"))
    {
     if (hacer==0)
         {
               if (document.getElementById("nombre")!=null) document.getElementById("nombre").value="";
               if (document.getElementById("telefono")!=null) document.getElementById("telefono").value="";
               if (document.getElementById("email")!=null) document.getElementById("email").value="";
               if (document.getElementById("descripcion")!=null) document.getElementById("descripcion").value="";
               if (document.getElementById("nombretres")!=null) document.getElementById("nombretres").value="";
               if (document.getElementById("telefonotres")!=null) document.getElementById("telefonotres").value="";

               if (document.getElementById("nombredos")!=null) document.getElementById("nombredos").value="";
               if (document.getElementById("telefonodos")!=null) document.getElementById("telefonodos").value="";
               if (document.getElementById("emaildos")!=null) document.getElementById("emaildos").value="";
               if (document.getElementById("emailtres")!=null) document.getElementById("emailtres").value="";
               if (document.getElementById("descripcion")!=null) document.getElementById("descripcion").value="";

         }

    }
}

function enviaremail(tipo,agencia,codigo)
{
var mxa;
var nohacer=0;
var precio=0;
mxa=document.getElementById("telefono").value;
precio=document.getElementById("precio").value;
if ((mxa.indexOf('@')<1) && (nohacer==0))      nohacer=1;
if ((mxa.indexOf('.')<1) && (nohacer==0))      nohacer=1;
if ((mxa.indexOf(' ')>0) && (nohacer==0))       nohacer=1;
if ((mxa.length<5) && (nohacer==0))      nohacer=1;

if (nohacer==1)
    {
    alert ('Error en la dirección de E-mail');
    }
    else
        {
        fraprevio.location=rutapath() + "enviaremail.php?tipo=2&email=" + mxa + "&agencia=" + agencia  + "&codigo=" + codigo + "&precio=" + precio;
        }
}

function cerrarventana(texto,tipo)
{


if (document.getElementById(texto)==null)
    {
    if (texto=="previo")
        texto="ventanamodal";
    else
        texto="previo";
    }
document.getElementById(texto).style.display='none';
document.getElementById(texto).style.visibility="hidden";
if (tipo==100)
    {
    winopen ("index.php","_top");
    return 0;
    }
//cuando se cierra la ventana de previo
if ((texto=="previo") && (tipo==0))
    {
    document.getElementById("subprevio").style.display='none';
    document.getElementById("capaFondo").style.visibility="hidden";

    }
//cuando se cierra la ventana de ficha
if ((texto=="subprevio") && (tipo==0))
     {
     document.getElementById("capaFondo").style.visibility="hidden";
            document.getElementById("ordenqrya").style.visibility= "visible";
                             if (document.getElementById("ordenqryb")!=null) document.getElementById("ordenqryb").style.visibility= "visible";

     }
if ((texto=="ventanamodal") && (tipo==10))
     {
     document.getElementById("capaFondo").style.visibility="hidden";
      fraprevio.location= rutapath()+ "parametros/actestadistica.php?tipo=10";

     }
if (document.getElementById("pubbanner")!=null)
        document.getElementById("pubbanner").style.visibility="visible";


}

function colocafiltros()
{
var alto=0;
     if (document.getElementById("ventanafiltro")==null) return 0;
    document.getElementById("ventanafiltro").style.visibility= "visible";

alto=gettop(document.getElementById("bannero"));
alto=alto +    document.getElementById("bannero").offsetHeight;
alto=alto +    (document.getElementById("bannero").offsetHeight/3*2);
    document.getElementById("ventanafiltro").style.top=alto;
derecha=getleft(document.getElementById("bannero"));
derecha=derecha+ document.getElementById("bannero").offsetWidth;
derecha=derecha-document.getElementById("ventanafiltro").offsetWidth;
//    alert (document.getElementById("listadopropiedades").width);
    document.getElementById("ventanafiltro").style.left=derecha

}

function cargarprecios()
{
var valor=0;
var total=0;

total=document.getElementById("lstprecio").length;
for (valor=0;valor<total;valor++)
     document.getElementById("lstprecio").remove(0);

document.getElementById("lstprecio").options[0]=new Option('Cualquiera');
document.getElementById("lstprecio").options[0].value='';

valor=document.getElementById("lstoperacion").value;
if (valor==1)
    {
    document.getElementById("lstprecio").options[1]=new Option('Menos de 70.000 €');
    document.getElementById("lstprecio").options[1].value=7;

    document.getElementById("lstprecio").options[2]=new Option('Entre 70.000 y 100.000 €');
    document.getElementById("lstprecio").options[2].value=8;

    document.getElementById("lstprecio").options[3]=new Option('Entre 100.000 y 150.000 €');
    document.getElementById("lstprecio").options[3].value=9;

    document.getElementById("lstprecio").options[4]=new Option('Entre 150.000 y 200.000 €');
    document.getElementById("lstprecio").options[4].value=10;

    document.getElementById("lstprecio").options[5]=new Option('Entre 200.000 y 250.000 €');
    document.getElementById("lstprecio").options[5].value=11;

    document.getElementById("lstprecio").options[5]=new Option('Entre 250.000 y 350.000 €');
    document.getElementById("lstprecio").options[5].value=12;

    document.getElementById("lstprecio").options[6]=new Option('Entre 350.000 y 500.000 €');
    document.getElementById("lstprecio").options[6].value=13;

    document.getElementById("lstprecio").options[7]=new Option('Más de 500.000 €');
    document.getElementById("lstprecio").options[7].value=14;

    }

if (valor==2)
    {

    document.getElementById("lstprecio").options[1]=new Option('Menos de 400 €');
    document.getElementById("lstprecio").options[1].value=1;

    document.getElementById("lstprecio").options[2]=new Option('Entre 400 y 700 €');
    document.getElementById("lstprecio").options[2].value=2;

    document.getElementById("lstprecio").options[3]=new Option('Entre 700 y 1.000 €');
    document.getElementById("lstprecio").options[3].value=3;

    document.getElementById("lstprecio").options[4]=new Option('Entre 1.000 y 1.500 €');
    document.getElementById("lstprecio").options[4].value=4;

    document.getElementById("lstprecio").options[5]=new Option('Entre 1.500 y 3.000 €');
    document.getElementById("lstprecio").options[5].value=5;

    document.getElementById("lstprecio").options[6]=new Option('Mas de 3.000 €');
    document.getElementById("lstprecio").options[6].value=6;

    }


if (valor==3)
    {
    document.getElementById("lstprecio").options[1]=new Option('Menos de 100.000 €');
    document.getElementById("lstprecio").options[1].value=14;

    document.getElementById("lstprecio").options[2]=new Option('Entre 100.000 y 150.000 €');
    document.getElementById("lstprecio").options[2].value=15;

    document.getElementById("lstprecio").options[2]=new Option('Entre 150.000 y 200.000 €');
    document.getElementById("lstprecio").options[2].value=16;

    document.getElementById("lstprecio").options[3]=new Option('Entre 250.000 y 350.000 €');
    document.getElementById("lstprecio").options[3].value=17;

    document.getElementById("lstprecio").options[4]=new Option('Entre 350.000 y 500.000 €');
    document.getElementById("lstprecio").options[4].value=18;

    document.getElementById("lstprecio").options[5]=new Option('Más de 500.000 €');
    document.getElementById("lstprecio").options[5].value=19;

    }

document.getElementById("lstprecio").value="";

}



function eventoscroll()
{
//alert ('scroll');
//dObj =document.getElementById("ventanafiltro");
//if (document.body.scrollTop> dObj.style.posTop) dObj.style.posTop = document.body.scrollTop+20
}

function abrirresultados(cadena)
{

winopen (rutapath() + "listados.php?precio=" + document.getElementById("auxlstprecio").value + cadena,"_top");
}

function abrirresultadoszonas(argumentos)
{

var valor=0;
var cadena="";
var i=0;
var j=0;
var todos=0;
var texto="";
while (i>-1)
{
//sirve para saber si existe un objeto
if (document.getElementById("zona[" + i +"]")==null)
   i=-2;
else
    {
     if (document.getElementById("zona[" + i +"]").checked==true)
         {
             if (texto.length>0) texto=texto + ',';
           texto=texto + document.getElementById("zona[" + i +"]").value;
         j=j+1;
         }
    }
i=i+1;
}

if (texto.length>0) cadena="&numzona=" + texto;
texto="";
 i=0;

while (i>-1)
{
//sirve para saber si existe un objeto
if (document.getElementById("tipo[" + i +"]")==null)
   i=-2;
else
    {

     if (document.getElementById("tipo[" + i +"]").checked==true)
         {

             if (texto.length>0) texto=texto + ',';
           texto=texto + document.getElementById("tipo[" + i +"]").value;


         }
    }
i=i+1;
}

cadena=cadena + "&numtipo=" + texto;


winopen (rutapath() + "listados.php" + argumentos + cadena ,"_top");
}

valortiempo=setInterval(revisar,500);
 //para saber que tiene que mostrar ejecutando los scripts sin estar en el html
function revisar()
{
                             //el botim es porque ha detectado a googlef

clearInterval(valortiempo);
 if (document.getElementById("botimg")==null)
 {

 if (document.getElementById("bannero")!=null)  posicionar() ;
// if (document.getElementById("listadopropiedades")!=null) colocafiltros();



 if (document.getElementById("imgnopisos")!=null)
     {
     texto=document.getElementById("imgnopisos").name
     if (texto.indexOf('-')>1)
         {
         subventanaprevio(0,'nohaypisos',texto.substr(0,texto.indexOf('-')),texto.substr(texto.indexOf('-')+1))
         }
     }
//     else
  //       {
//          if (document.getElementById("compro")!=null)     cargarselecajax("compro") ;
    //     }
  }

}


function compruebaemail(mxa)
{
var cade
var nohacer
nohacer=0;


if ((mxa.indexOf('@')<1) && (nohacer==0))      nohacer=1;
if ((mxa.indexOf('.')<1) && (nohacer==0))      nohacer=1;
if ((mxa.indexOf(' ')>0) && (nohacer==0))       nohacer=1;
if ((mxa.length<5) && (nohacer==0))      nohacer=1;

if (nohacer==1)
    {
    alert ("Error en el E-mail");
        return 1;
    }
else
    return 0;

}

function abrircliente(agencia,web)
{

if (web.length>0)
   {
    web=web.replace(' ','.');
    winopen ("http://www." + web,"_blank");
    }
 subventanaprevio(0,'agenciabanner',agencia,0)
}

function consultahaypisos()
{

telefono=document.getElementById("telefono").value;
email=document.getElementById("email").value;
web=document.getElementById("web").value;
descripcion=document.getElementById("descripcion").value;
nombre=document.getElementById("nombre").value;
tipoventana="consultahaypisos";
if (comprobartelefono(telefono)==1)
     fraprevio.location="configweb/enviaconsulta.php?telefono=" + telefono + "&email=" + email + "&web=" + web + "&nombre=" + nombre + "&descripcion=" + descripcion;
else
    alert ('Debes de introducir los datos');
}

function anchoarea()
{
//el area disponible del ancho
var ancho=0;
if (navigator.appName == "Netscape")
    ancho= window.innerWidth;
else
    ancho= document.documentElement.offsetWidth ;
//document.documentElement.clientWidth
return ancho;
}

function revisartodas(posicion)
{
var i=1;
var valor=0;
if (document.getElementById("ciudad[" + posicion +"]").checked==true)
    document.getElementById("ciudad[0]").checked=false;
else
    {
    while (i>0)
        {
        if (document.getElementById("ciudad[" + i +"]")==null)
            i=-1;
        else
            {
            if (document.getElementById("ciudad[" + i +"]").checked==true) valor=1;
             }
        i=i+1;
        }
    if (valor==0)     document.getElementById("ciudad[0]").checked=true;
    }
}

function cargafotosprevio(tipo)
{

//fue imposible implantar esto
//parece que hasta que no termina de cargar el div y se muestra
//las funciones de javascript del js no estan visibles
//esta funcion es llamada por el onresize
//alert ('1');
if (tipo==0)
    {
    valortiempo=setInterval("cargafotosprevio(1)",200);
    }
else
    {
var i=0;

 clearInterval(valortiempo);
// alert ('2');
     if (document.getElementById("botoncerrar").src=="/imagenes/botoncerrar.gif") return 0;
 document.getElementById("botoncerrar").src="/imagenes/botoncerrar.gif";
 if (screen.width<900)
 {
     if (document.getElementById("botonpts")!=null)      document.getElementById("botonpts").src="/imagenes/ptsseleccion1.gif";
     document.getElementById("barraizq1").background="/imagenes/barraizq1.jpg";
     document.getElementById("barraizq2").background="/imagenes/barraizq1.jpg";
     document.getElementById("barraizq3").background="/imagenes/barraizq1.jpg";
     document.getElementById("barrader1").background="/imagenes/barrader1.jpg";
     document.getElementById("barrader2").background="/imagenes/barrader1.jpg";
     document.getElementById("barrader3").background="/imagenes/barrader1.jpg";
     document.getElementById("barracen1").background="/imagenes/barracen1.jpg";
     document.getElementById("barracen2").background="/imagenes/barracen1.jpg";
     document.getElementById("barracen3").background="/imagenes/barracen1.jpg";

}
else
    {
 //   alert ('3');
     if (document.getElementById("botonpts")!=null) document.getElementById("botonpts").src="/imagenes/ptsseleccion.gif";
     document.getElementById("barraizq1").background="/imagenes/barraizq.jpg";
     document.getElementById("barraizq2").background="/imagenes/barraizq.jpg";
     document.getElementById("barraizq3").background="/imagenes/barraizq.jpg";
     document.getElementById("barrader1").background="/imagenes/barrader.jpg";
     document.getElementById("barrader2").background="/imagenes/barrader.jpg";
     document.getElementById("barrader3").background="/imagenes/barrader.jpg";
     document.getElementById("barracen1").background="/imagenes/barracen.jpg";
     document.getElementById("barracen2").background="/imagenes/barracen.jpg";

     document.getElementById("barracen3").background="/imagenes/barracen.jpg";
     }
    if (document.getElementById("imageid").alt.length>0)
        {
        document.getElementById("imageid").src= document.getElementById("imageid").alt;
         document.getElementById("imageid").alt="";
         }
    for (i=1;i<7;i++)
         {
         if (document.getElementById("fotoaux" +i)!=null)
             {
                document.getElementById("fotoaux" +i).src= document.getElementById("fotoaux" +i).alt;
                 document.getElementById("fotoaux" +i).alt="";

             }

         }
     document.getElementById("barracen3").style.color="white";
     document.getElementById("barracen2").style.color="white";
     document.getElementById("barracen1").style.color="white";
    }

}

function scrollmovido()
{
var altura=0;
moverasistente();
movermensaje();
if (document.getElementById("bannero")!=null)
             {
                auxderechabanner=getleft(document.getElementById("bannero"));
                auxderechabanner=auxderechabanner+ document.getElementById("bannero").offsetWidth;
                    if (document.getElementById("ventanafiltro")!=null) auxderechabanner=auxderechabanner-document.getElementById("ventanafiltro").offsetWidth;
                if (auxderechabanner>derechabanner) derechabanner=auxderechabanner;
                  }

if (altobanner==0)
    {

    if (document.getElementById("ventanafiltro")!=null)
        {
        altobanner =gettop(document.getElementById("ventanafiltro"));
        derechabanner=getleft(document.getElementById("ventanafiltro"));
        }
    if (document.getElementById("bannero")!=null)
                 {
                  altobanner =gettop(document.getElementById("bannero"));
                    derechabanner=getleft(document.getElementById("bannero"));
                    derechabanner=derechabanner+ document.getElementById("bannero").offsetWidth;
                        if (document.getElementById("ventanafiltro")!=null) derechabanner=derechabanner-document.getElementById("ventanafiltro").offsetWidth;
                      }
    }
    if (altobanner==0) return "";
if (altobanner>document.documentElement.scrollTop)
{
     if (document.getElementById("bannero")!=null) {
    document.getElementById("bannero").style.position="";
    document.getElementById("bannero").style.top= "0px";
    }
    if (document.getElementById("ventanafiltro")!=null) document.getElementById("ventanafiltro").style.position="";
}
else
    {

        if (document.getElementById("bannero")!=null) {
        document.getElementById("bannero").position="absolute";
        document.getElementById("bannero").style.display="block";
        document.getElementById("bannero").style.top=(document.documentElement.scrollTop-altobanner-5) + "px";
        altura=document.getElementById("bannero").offsetHeight;
        }
        if (document.getElementById("ventanafiltro")!=null)
        {
            document.getElementById("ventanafiltro").style.position="absolute";
            document.getElementById("ventanafiltro").style.display="block";
            if (screen.width<900)
                document.getElementById("ventanafiltro").style.top=(document.documentElement.scrollTop+altura + 10) +"px";
            else
                document.getElementById("ventanafiltro").style.top=(document.documentElement.scrollTop+altura + 25) +"px";
            var derecha=0;
            //derecha=(getleft(document.getElementById("bannero"))+document.getElementById("bannero").offsetWidth-document.getElementById("ventanafiltro").offsetWidth+5);
            document.getElementById("ventanafiltro").style.left=derechabanner + "px" ;
        }
     }

}


function cargaelprevio(agencia,codigo,foto1,foto2,foto3,foto4,foto5,foto6,posfoto)
{
var imageid="height=117";
var imageaux="height=56";
var pantallamedida=" width=22 height=35";
var pantalla="";
if (screen.width<900)
    {
    pantalla=1;
    pantallamedida=" width=15 height=25";
    imageid="height=90";
    imageaux="height=42";
    }


var cadena='';
cadena='<div id="propiedadprevio" >';
cadena =cadena + '<div id="cabeceraprevio">';
cadena =cadena + '<img src="/imagenes/botoncerrar.gif" id="botoncerrar" align=right style="cursor:pointer" onclick="cerrarventana(\'previo\',0)">';
cadena =cadena + '<center>PREVIO FOTOS (Situe el ratón encima de la foto a visualizar)</center>';
cadena =cadena + '</div>';
cadena =cadena + '<div id="cuerpoprevio">';
cadena =cadena + '<table width=100% cellspacing=1 cellpadding=2 border=0>';
cadena =cadena + '<TD width=1 >';
cadena =cadena + '<img  name="imageid" id="imageid" src="/fotos/' + agencia + '/' + agencia + '_' + foto1 +'-1.jpgpeq.jpg" ' + imageid + ' border=1  >';
cadena =cadena + '</td>';
cadena =cadena + '<td width=1>';
if (foto1>0) cadena =cadena + '<img id=fotoaux1 vspace=2 src="/fotos/' + agencia + '/' + agencia + '_' + foto1 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'/fotos/' + agencia + '/' + agencia + '_' + foto1 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
if (foto2>0) cadena =cadena + '<img id=fotoaux2 src="/fotos/' + agencia + '/' + agencia + '_' + foto2 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'/fotos/' + agencia + '/' + agencia + '_' + foto2 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
cadena =cadena + '</td>';

cadena =cadena + '<td width=1>';
if (foto3>0) cadena =cadena + '<img id=fotoaux3 vspace=2 src="/fotos/' + agencia + '/' + agencia + '_' + foto3 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'/fotos/' + agencia + '/' + agencia + '_' + foto3 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
if (foto4>0) cadena =cadena + '<img id=fotoaux4 src="/fotos/' + agencia + '/' + agencia + '_' + foto4 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'/fotos/' + agencia + '/' + agencia + '_' + foto4 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
cadena =cadena + '</td>';
//cadena =cadena + '<td width=1>';
//if (foto5>0) cadena =cadena + '<img id=fotoaux5 vspace=2 src="fotos/' + agencia + '/' + agencia + '_' + foto5 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'fotos/' + agencia + '/' + agencia + '_' + foto5 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
//if (foto6>0) cadena =cadena + '<img id=fotoaux6 src="fotos/' + agencia + '/' + agencia + '_' + foto6 +'-1.jpgpeq2.jpg"  border=1     onMouseOver="cambiafoto(\'fotos/' + agencia + '/' + agencia + '_' + foto6 +'-1.jpgpeq.jpg\');" ' + imageaux + ' >';
//cadena =cadena + '</td>';

cadena =cadena + '<td width=100% valign=top align=center>';
cadena =cadena + '<table cellspacing=0 cellpadding=0>';
cadena =cadena + '<tr>';

cadena =cadena + '<td background="/imagenes/barraizq'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '<td background="/imagenes/barracen'  + pantalla + '.jpg" style="cursor:pointer" class=textobotonprevio valign=top  onclick="subventanaprevio(0,\'llamarficha\',' + agencia + ',' + codigo + ');" >Deseo que me llamen de esta propiedad</td>';
cadena =cadena + '<td background="/imagenes/barrader'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '</tr>';
cadena =cadena + '<tr><td colspan=3 height=8></td></tr>';
cadena =cadena + '</table>';

cadena =cadena + '<table cellspacing=0 cellpadding=0>';
cadena =cadena + '<tr>';
cadena =cadena + '<td background="/imagenes/barraizq'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '<td background="/imagenes/barracen'  + pantalla + '.jpg" style="cursor:pointer" class=textobotonprevio valign=top  onclick="subventanaprevio(0,\'mailficha\',' + agencia + ',' + codigo + ')" >Recibir propiedades similares en mi e-mail</td>';
cadena =cadena + '<td background="/imagenes/barrader'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '</tr>';
cadena =cadena + '<tr><td colspan=3 height=8></td></tr>';
cadena =cadena + '</table>';
cadena =cadena + '<table cellspacing=0 cellpadding=0 border=0>';
cadena =cadena + '<tr>';
cadena =cadena + '<td background="/imagenes/barraizq'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '<td background="/imagenes/barracen'  + pantalla + '.jpg" style="cursor:pointer" class=textobotonprevio onclick="subventanaprevio(0,\'verficha\',' + agencia + ',' + codigo + ')" valign=top>Ver Ficha Completa</td>';
cadena =cadena + '<td background="/imagenes/barrader'  + pantalla + '.jpg" ' + pantallamedida + '></td>';
cadena =cadena + '</tr>';
cadena =cadena + '</table>';

cadena =cadena + '        </td>';
cadena =cadena + '        </table>';
cadena =cadena + '        </div>';
cadena =cadena + '    </div>';
objobj="foto" + posfoto;

valorhtml=cadena;
tipoventana='fichaprevia';
    document.getElementById("subprevio").style.display='none';
    document.getElementById("ventanamodal").style.display='none';
    document.getElementById("capaFondo").style.visibility="hidden";
tipoventana="fichaprevia";
document.getElementById("previo").style.position="absolute";

verprevio("","","",1);

fraprevio.location= rutapath()+ "parametros/actestadistica.php?codigo=" + codigo + "&agencia=" +agencia + "&tipo=1";
}

function abrircontactar()
{
var i=0;
i=5;
if (i==5)     winopen ("/contactar.php","_top");
}
function publicapromociones()
{
var i=0;
i=5;
if (i==5)     winopen ("http://www.haypisos.com/publicarpromociones.php","_top");
}

// Array de provincas
var Provincias = new Array();
    Provincias[00] = "Ninguna";
    Provincias[01] = "A CORUNA";
    Provincias[02] = "ALAVA";
    Provincias[03] = "ALBACETE";
    Provincias[04] = "ALICANTE";
    Provincias[05] = "ALMERIA";
    Provincias[06] = "ASTURIAS";
    Provincias[07] = "AVILA";
    Provincias[08] = "BADAJOZ";
    Provincias[09] = "BALEARES";
    Provincias[10] = "BARCELONA";
    Provincias[11] = "BURGOS";
    Provincias[12] = "CACERES";
    Provincias[13] = "CADIZ";
    Provincias[14] = "CANTABRIA";
    Provincias[15] = "CASTELLON";
    Provincias[16] = "CEUTA";
    Provincias[17] = "CIUDAD REAL";
    Provincias[18] = "CORDOBA";
    Provincias[19] = "CUENCA";
    Provincias[20] = "GERONA";
    Provincias[21] = "GRANADA";
    Provincias[22] = "GUADALAJARA";
    Provincias[23] = "GUIPUZCUA";
    Provincias[24] = "HUELVA";
    Provincias[25] = "HUESCA";
    Provincias[26] = "LA RIOJA";
    Provincias[27] = "LAS PALMAS";
    Provincias[28] = "LEON";
    Provincias[29] = "LUGO";
    Provincias[30] = "MALAGA";
    Provincias[31] = "MELILLA";
    Provincias[32] = "MURCIA";
    Provincias[33] = "NAVARRA";
    Provincias[34] = "ORENSE";
    Provincias[35] = "PALENCIA";
    Provincias[36] = "PONTEVEDRA";
    Provincias[37] = "SALAMANCA";
    Provincias[38] = "TENERIFE";
    Provincias[39] = "SEGOVIA";
    Provincias[40] = "SEVILLA";
    Provincias[41] = "SORIA";
    Provincias[42] = "TARRAGONA";
    Provincias[43] = "TERUEL";
    Provincias[44] = "TOLEDO";
    Provincias[45] = "VALENCIA";
    Provincias[46] = "VALLADOLID";
    Provincias[47] = "VIZCAYA";
    Provincias[48] = "ZAMORA";
    Provincias[49] = "ZARAGOZA";
    Provincias[50] = "JAEN";
    Provincias[51] = "MADRID";
    Provincias[52] = "LERIDA";


/**
 * Recibe el codigo de provincia que se corresponde con el array definido al
 * inicio del fichero.
 */
function queProvincia(num)
{
    var el;  // Elemento del DOM (un span)
    var cnt; // Contenido a cambiar
    var bld; // Esta en negrita ??
    var col; // Color para el contenido

    if (num < 0 || num > 52 ) {
        cnt = "";
        col = "Black";
        bld = "normal";
    }
    else {
        cnt = " " + Provincias[num] + " ";
        col = "SteelBlue";
        bld = "bold";
    }
/*
    el = document.getElementById('queprovincia');
    el.innerHTML = cnt;
    el.style.color = col;
    el.style.fontWeight = bld;
    */
//    si lo pones en el pie el div te aparecera el texto
}

// Al pulsar sobre una provincia del mapa, seleecionada automáticamente
// la misma provincia en la lista SELECT, que estará oculta
function cambiarOpcionSelect(provincia)
{
    var sel = document.getElementById('lstprovincia');
    var opt = document.getElementById('lstprovincia').options;
    var index;
    index=-1;
    for (i = 0; i < sel.length ; i++ ) {
        if ( opt[i].value == provincia )
            index = opt[i].index;
    }
    if (index<0)
         alert ('Provincia sin Inmuebles');
    else
        {
        sel.selectedIndex = index;
        mostrarmapa(1);
        mostrarlocalidades(sel.value, 0 );
        }
}
function abrirfichero (fichero)
{
    winopen ("http://www.haypisos.com/fotospromo/"  + fichero ,"_blank");
}
function abrirpromo(idpromo,idmodelo,obra)
{
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (idpromo>0)
{
if (i>1)
    winopen ("http://localhost/propiedades/fichapromocion.php?estoydentro=1&idpromo="  + idpromo + "&obra=" + obra ,"_top");
else
    winopen ("http://www.haypisos.com/propiedades/fichapromocion.php?estoydentro=1&idpromo="  + idpromo + "&obra=" + obra ,"_top");
}
else
    {
    if (i>1)
        winopen ("http://localhost/propiedades/fichapromocion.php?estoydentro=1&idmodelo="  + idmodelo ,"_top");
    else
        winopen ("http://www.haypisos.com/propiedades/fichapromocion.php?estoydentro=1&idmodelo="  + idmodelo ,"_top");

    }
}

function abrirsitioweb(web)
{
        winopen (web  ,"_blank");
}

function cerrarficha()
{
//es para el evento on beforeunload
auxdonde="sss";
if (botonatras==0) botonatras=1;
//botonatras=1;
        history.go(botonatras*-1)


//document.location=document.referrer;
}


function objetoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
          }
    }

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}
/*
function mostrarmensaje(id,ciudad,codigo,agencia)
{
var parametro=""

parametro="&ciudad=" + ciudad +"&codigo=" + codigo +"&agencia=" +agencia;

cargarventanaajax(id,parametro);
cambiaasistente(0);
altocuadro=0;
derechacuadro=0;
nbventanamovible=id;
clearInterval(tinmover);
 tinmover=setInterval("moverlaventanaizq()",30);

}
*/
function lanzaestadistica (tipo,parametros)
{
 	url=rutapath() + "parametros/actestadistica.php?tipo=" + tipo + parametros;
    ajax = objetoAjax();

    ajax.open("GET", url );
    ajax.onreadystatechange = function() {

    }
    ajax.send(null)
}

function cargarventanaajax (id,parametro)
{
var url="";
var pantalla="";

if (screen.width<1000) pantalla="1";
    if (id=="ventanamensaje") url=rutapath() + "formularios/mensaje.php?pantalla=" + pantalla + parametro;
    if (id=="ventanaasistente") url=rutapath() + "formularios/asistente.php?pantalla=" + pantalla + parametro;

    selectResultado = document.getElementById( id );
    ajax = objetoAjax();

    ajax.open("GET", url );
    ajax.onreadystatechange = function() {

        if ( ajax.readyState == 4 ) {

            document.getElementById(id).innerHTML = ajax.responseText;
            document.getElementById(id).style.position="absolute";
            document.getElementById(id).style.display="block";
        }
    }
    ajax.send(null)
}




function cerrarcapafondo()
{
     if (document.getElementById("previo")!=null)
     {
    document.getElementById("capaFondo").style.visibility="hidden";
    }
}



function movermensaje()
{
var auxaltura=0;
var limitealtura=0;

if (document.getElementById("ventanamensaje")==null)
    {
    clearInterval(timermensaje);
    return "";
    }
if (document.getElementById("ventanamensaje").style.visibility=="hidden")
    {
    clearInterval(timermensaje);
    return "";
    }

auxaltura=document.documentElement.scrollTop;
limitealtura=document.documentElement.clientHeight+auxaltura-document.getElementById("ventanamensaje").offsetHeight;
valornuevo=document.documentElement.clientHeight+auxaltura-altocuadro;
altocuadro=altocuadro+1;
document.getElementById("ventanamensaje").style.left=document.documentElement.clientWidth-document.getElementById("ventanamensaje").offsetWidth-10 +"px";
if (limitealtura<valornuevo)
            document.getElementById("ventanamensaje").style.top=valornuevo +"px";
else
    {
    if (document.getElementById("ventanamensaje").style.top!=limitealtura) document.getElementById("ventanamensaje").style.top=limitealtura  +"px";
//    clearInterval(timermensaje);
    }


}


function posicionarpropiedad(codigo,agencia,directo)
{
if (noseguir==1) return "";
noseguir=1;
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");


if (i>1)
    winopen ("http://localhost/propiedades/listados.php?valoragencia="  + agencia + "&valorcodigo=" + codigo +"&valorestadistica=" + directo,"_top");
else
    winopen ("http://www.haypisos.com/propiedades/listados.php?valoragencia="  + agencia + "&valorcodigo=" + codigo +"&valorestadistica=" + directo ,"_top");



}
function posicionarzonapropiedad(codigo,agencia,zona,directo)
{
if (noseguir==1) return "";
noseguir=1;
cadruta=document.getElementById("barrahori").src;
i=cadruta.indexOf("localhost/");
if (directo==100) zona="";
if (directo==100) directo="";

if (i>1)
    winopen ("http://localhost/propiedades/listados.php?valoragencia="  + agencia + "&valorcodigo=" + codigo +"&valorzona=" + zona + "&valorestadistica=" + directo,"_top");
else
    winopen ("http://www.haypisos.com/propiedades/listados.php?valoragencia="  + agencia + "&valorcodigo=" + codigo  +"&valorzona=" + zona + "&valorestadistica=" + directo ,"_top");



}

function cambiaasistente(tipo,valor)
{
var email="";
    var sel=0;
    if (valor>=0) centrarventana("ventanaasistente");
if (tipo==0)   valorhtml='Que propiedades desea, en <a href="javascript:cambiaasistente(1,1)" >venta</a> o en <a href="javascript:cambiaasistente(1,2)" >alquiler</a>';

if (tipo==1)
    {
    if ((valoroperacion==0) && (valor>=0)) valoroperacion=valor;

    valorhtml='Selecciona el tipo de propiedad que te interese<br>';
    if (valoroperacion==2) valorhtml='Seleccione la propiedad que le gustaria alquilar<br>';
    valorhtml=valorhtml + '<select id=stipo size=8 name=stipo  onChange="cambiaasistente(2,0)">'
    valorhtml=valorhtml + '<option value=-1>Viviendas</option>';
    valorhtml=valorhtml + '<option value=-2>Chalets,Villas</option>';
    valorhtml=valorhtml + '<option value=-3>Locales</option>';
    valorhtml=valorhtml + '<option value=3099>Estudios</option>';
    valorhtml=valorhtml + '<option value=199>Adosadas</option>';
    valorhtml=valorhtml + '<option value=52899>Aticos</option>';
    valorhtml=valorhtml + '<option value=299>Bungalows</option>';
    valorhtml=valorhtml + '<option value=4899>Entresuelos</option>';
    valorhtml=valorhtml + '</select>';
    }
if (tipo==2)
    {
     if (valor>=0)
         {
            sel=document.getElementById("stipo").selectedIndex;
            valortipo=document.getElementById("stipo").options[sel].value;
         }
    if (valoroperacion==2)
        {
        valorhtml='Seleccione hasta que precio<br>';
        valorhtml=valorhtml + '<SELECT SIZE="5" id="listaprecio" NAME="listaprecio"  onChange="cambiaasistente(3,0)">';
        valorhtml=valorhtml + '<OPTION value="0"  >Cualquiera</option>';
        valorhtml=valorhtml + '<OPTION value="1" >Menos de 400 €</option>';
        valorhtml=valorhtml + '<OPTION value="2" >Entre 400 y 700 €</option>';
        valorhtml=valorhtml + '<OPTION value="3" >Entre 700 y 1.000 €</option>';
        valorhtml=valorhtml + '<OPTION value="4" >Entre 1.000 y 1.500 €</option>';
        valorhtml=valorhtml + '<OPTION value="5" >Mas de 1.500 €</option>';
        valorhtml=valorhtml + '</select>';
        }
        else
            {
            valorhtml='<SELECT SIZE="8" id="listaprecio" NAME="listaprecio"   onChange="cambiaasistente(3,0)">';
            valorhtml=valorhtml + '<OPTION value="0"  >Cualquiera</option>';
            valorhtml=valorhtml + '<OPTION value="14"  >Menos de 100.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="8"   >Entre 100.000 y 150.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="9"   >Entre 150.000 y 200.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="10"   >Entre 200.000 y 250.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="11"   >Entre 250.000 y 350.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="12"   >Entre 350.000 y 500.000 €</option>';
            valorhtml=valorhtml + '<OPTION value="13"   >Más de 500.000 €</option>';
            valorhtml=valorhtml + '</selected>';
            }
    }
if (tipo==3)
    {
     if (valor>=0)
         {
        sel=document.getElementById("listaprecio").selectedIndex;
        valorprecio=document.getElementById("listaprecio").options[sel].value;
        }
    valorhtml='Escriba su email, para recibir las propiedades <br><input type=text id=xmail ><br><input id=botrecibir onclick="cambiaasistente(4,0)" type=button value="Recibir Propiedades" />';
    }
if (tipo==4)
    {

    var valorm="";
    email=document.getElementById("xmail").value;

    if (email.length>0)
        hacer= compruebaemail(email);
    else
        hacer=1;

    if (hacer==1)
        {
        alert ('Debe de introducir un email Valido');
        return "";
        }
            valoremail=email;
    //almacene el email         document.getElementById("emailtres").value
      valorhtml='Introduzca sus datos <br>Nombre: <input type=text id=nombredos ><br>Telefono: <input type=text id=telefonodos onKeyPress="return solonumeros(event)" ><br><input id=botrecibir onclick="cambiaasistente(5,0)" type=button value="Aceptar" />';

    }
if (tipo==5)
    {
    telefono=document.getElementById("telefonodos");
    nombre=document.getElementById("nombredos");
    if (comprobartelefono(telefono)==0)
        {
        alert ('Debes de introducir un telefono valido');
        return "";
        }
        lanzaestadistica (13,"&email=" + valoremail +"&valortipo=" + valortipo + "&valorciudad=" +valorciudad + "&valoroperacion=" + valoroperacion + "&valorprecio=" + valorprecio + "&nombre=" + nombre + "&telefono=" + telefono) ;
        cerrarasistente();
    }
document.getElementById("asistente").innerHTML = valorhtml;
posicionasistente=tipo;
if (tipo>0)
    {
    lanzaestadistica (11,"&agencia=" + tipo);

     if (tipo==4)     lanzaestadistica (12,"&email=" + email +"&valortipo=" + valortipo + "&valorciudad=" +valorciudad + "&valoroperacion=" + valoroperacion + "&valorprecio=" + valorprecio) ;
    }
}


function centrarventana(id)
{
//document.getElementById(id).style.visibility='hidden';
document.getElementById(id).style.position="absolute";
document.getElementById(id).style.display="block";

auxaltura=document.documentElement.scrollTop;
limitealtura=(document.documentElement.clientHeight-document.getElementById(id).offsetHeight)/2;
document.getElementById(id).style.top=limitealtura+ auxaltura +"px";
auxaltura=(document.documentElement.clientWidth-document.getElementById(id).offsetWidth)/2;
document.getElementById(id).style.left=auxaltura +"px";

}


function abrirasistente (tipo,operacion,tipovivienda,tipoprecio)
{
valoroperacion=operacion;
valortipo=tipovivienda;
valorprecio=tipoprecio;
//mostrarasistente
 cambiaasistente (tipo,-1);
}


function moverasistente()
{
var auxaltura=0;
var limitealtura=0;

if (document.getElementById("ventanaasistente")==null)
    {
    clearInterval(timerasistente);
    return "";
    }
if (document.getElementById("ventanaasistente").style.visibility=="hidden")
    {
    clearInterval(timerasistente);
    return "";
    }
derechacuadro=derechacuadro+1;
auxaltura=document.documentElement.scrollTop;
limitealtura=(document.documentElement.clientHeight-document.getElementById("ventanaasistente").offsetHeight)/2;
document.getElementById("ventanaasistente").style.top=limitealtura+ auxaltura +"px";


limitealtura=(document.getElementById("ventanaasistente").offsetWidth*-1);
if (limitealtura+derechacuadro<=0)
            document.getElementById("ventanaasistente").style.left=limitealtura+derechacuadro +"px";
else
    clearInterval(timerasistente);


}

function cerrarasistente()
{
var cadena="";
document.getElementById('ventanaasistente').style.visibility="hidden";
if (posicionasistente>2)
    {

    if (valorprecio==0)
        posicionarpropiedad(valorcodigo,valoragencia,3)
    else
        {
        cadena="&precio=" + valorprecio;
        cadena=cadena +"&numoperacion=" + valoroperacion;
        if (valortipo>0)
                cadena=cadena + "&numtipo=" + valortipo;
        else
                cadena=cadena + "&tipogrupo=" + (valortipo*-1);

         cadruta=document.getElementById("barrahori").src;
        i=cadruta.indexOf("localhost/");
        if (i>1)
            winopen ("http://localhost/propiedades/listados.php?numciudad=" +valorciudad + cadena ,"_top");
        else
            winopen ("http://www.haypisos.com/propiedades/listados.php?numciudad=" +valorciudad + cadena,"_top");

        }

    }
}


function avisolegal()
{
winopen("avisolegal.php","avisolegal", "height=300,width=500")

}

function politicaprivacidad()
{
winopen("politicaprivacidad.php","politicaprivacidad", "height=300,width=500")

}


function filtrarf5(e) {
tecla_codigo = (document.all) ? e.keyCode : e.which;
if(tecla_codigo==116) bclose=false;
}


function confirmExitx()
{
if (bclose)
        {
        winopen ("http://localhost/portal","_self");
        return "\n\n" + mensaje + "Si desea ver mas propiedades similares a pulse el botón de CANCELAR\n\n";
        }
}

function winopen(cadena,parametro)
{
auxdonde="sss";
    window.open (cadena,parametro);
}

function ponebanner()
{
document.write ('<div id=pubbanner><center>');
document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="950" height="47" title="news" onclick="clickit()">');
document.write ('<param rel=nofolow name="movie" value="/banner.swf">');
document.write ('<param name="quality" value="high">');
document.write ('<embed rel=nofolow src="/banner.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="950" height="47" wmode="green"></embed>');
document.write ('</object>');
document.write ('</center></div>');

}

function abrirminibuscador(numero,ciudad)
{
var url="";
var pantalla="";
var altura=0;
    url=rutapath() + "minibuscador.php?numero=" + numero + "&numciudad=" +ciudad;

    ajax = objetoAjax();

    ajax.open("GET", url );
    ajax.onreadystatechange = function() {

        if ( ajax.readyState == 4 ) {

            document.getElementById("minibuscador").innerHTML = ajax.responseText;
            document.getElementById("minibuscador").style.position="absolute";
            document.getElementById("minibuscador").style.display="block";
            document.getElementById("minibuscador").style.left=(getleft(document.getElementById("listadopropiedades"))+10) +"px";
            document.getElementById("minibuscador").style.top=(gettop(document.getElementById("listadopropiedades"))+20) +"px";
        }
    }
    ajax.send(null)


altura=gettop(document.getElementById("menubotones"))+8;
window.scrollTo(0,altura);
}


function cambiaalquiler()
{
cadena='Elija Precio';
cadena= cadena + '    <br>';
cadena= cadena + '    <select id=tipoprecio size=5>';
cadena= cadena + '    <option value="1">Menos de 400 €</option>';
cadena= cadena + '    <option value="2">Entre 400 y 700 €</option>';
cadena= cadena + '    <option value="3">Entre 700 y 1.000 €</option>';
cadena= cadena + '    <option value="4">Entre 1.000 y 1.500 €</option>';
cadena= cadena + '    <option value="5">Entre 1.500 y 3.000 €</option>';
cadena= cadena + '    <option value="6">Mas de 3.000 €</option>';
cadena= cadena + '    </select>';

document.getElementById("panprecio").innerHTML=cadena;
document.getElementById('obra').checked=false;
document.getElementById('alquiler').checked=true;
document.getElementById('venta').checked=false;

}

function cambiaventa()
{
cadena='Elija Precio';
cadena= cadena + '    <br>';
cadena= cadena + '    <select id=tipoprecio size=5>';
cadena= cadena + '<option value="6">Menos de 70.000 €</option>';
cadena= cadena + '<option value="7">70.000 - 100.000 €</option>';
cadena= cadena + '<option value="8">100.000 - 150.000 €</option>';
cadena= cadena + '<option value="9">150.000 - 200.000 €</option>';
cadena= cadena + '<option value="10">200.000 - 250.000 €</option>';
cadena= cadena + '<option value="11">250.000 - 350.000 €</option>';
cadena= cadena + '<option value="12">350.000 - 500.000 €</option>';
cadena= cadena + '<option value="13">Más de 500.000 €</option>';
cadena= cadena + '    </select>';

document.getElementById("panprecio").innerHTML=cadena;
document.getElementById('obra').checked=false;
document.getElementById('alquiler').checked=false;
document.getElementById('venta').checked=true;
}

function cambiapromocion()
{
cadena='Elija Precio';
cadena= cadena + '    <br>';
cadena= cadena + '    <select id=tipoprecio size=5>';
cadena= cadena + '<option value="14">Menos de 100.000 €</option>';
cadena= cadena + '<option value="16">150.000 - 200.000 €</option>';
cadena= cadena + '<option value="17">250.000 - 350.000 €</option>';
cadena= cadena + '<option value="18">350.000 - 500.000 €</option>';
cadena= cadena + '<option value="19">Más de 500.000 €</option>';
cadena= cadena + '    </select>';
document.getElementById("panprecio").innerHTML=cadena;
document.getElementById('obra').checked=true;
document.getElementById('alquiler').checked=false;
document.getElementById('venta').checked=false;
}



function realizarminibusqueda(numciudad)
{
var tipo;
var precio;
var habitacion;
tipo=document.getElementById("tipogrupo").value;

if (tipo.length==0)
{
alert ('Debes de seleccionar un Tipo de propiedad');
return 0;
}
else
    tipo="&numtipo=" + tipo;


precio=document.getElementById("tipoprecio").value;
if (precio.length==0)
{
alert ('Debes de un Rango de Precios');
return 0;
}
else
    precio="&precio=" + precio;

habitacion=document.getElementById("tipohab").value;
if (habitacion.length>0)  habitacion="&habitacion=" + habitacion;

if (document.getElementById('venta').checked==false)
{
    if (document.getElementById('alquiler').checked==false)
    {
    if (document.getElementById('obra').checked==false)
    {
    alert ('Selecciona el tipo de operacion Venta, Alquiler o Obra Nueva');
    return 0;
    }
    else
        operacion="&numoperacion=3";
    }
    else
        operacion="&numoperacion=2";
}
    else
        operacion="&numoperacion=1";
winopen (rutapath() + "listados.php?numciudad=" +  numciudad + precio + habitacion + tipo  + operacion,"_top");
}

function revisaprecio(valor)
{
if (valor=="v") cambiaventa();
if (valor=="a") cambiaalquiler();
if (valor=="p") cambiapromocion();
}


function comprobartelefono(telefono)
{
var si=0;

if (telefono.length<9) return 0;
if (telefono=="999999999") return 0;
if (telefono=="888888888") return 0;
if (telefono=="666666666") return 0;
if (telefono=="000000000") return 0;
if (telefono.indexOf('00000')>0) return 0;
if (telefono.indexOf('11111')>0) return 0;
if (telefono.indexOf('22222')>0) return 0;
if (telefono.indexOf('33333')>0) return 0;
if (telefono.indexOf('44444')>0) return 0;
if (telefono.indexOf('55555')>0) return 0;
if (telefono.indexOf('66666')>0) return 0;
if (telefono.indexOf('77777')>0) return 0;
if (telefono.indexOf('88888')>0) return 0;
if (telefono.indexOf('99999')>0) return 0;
if (telefono.indexOf('00000')>0) return 0;
if (telefono.indexOf('12345')>0) return 0;
if (telefono.indexOf('23456')>0) return 0;
if (telefono.indexOf('34567')>0) return 0;
if (telefono.indexOf('45678')>0) return 0;
if (telefono.indexOf('56789')>0) return 0;
if (telefono.indexOf('67890')>0) return 0;
if (telefono.indexOf('01234')>0) return 0;
if (telefono.indexOf('09876')>0) return 0;
if (telefono.indexOf('98765')>0) return 0;
if (telefono.indexOf('87654')>0) return 0;
if (telefono.indexOf('76543')>0) return 0;
if (telefono.indexOf('65432')>0) return 0;
if (telefono.indexOf('54321')>0) return 0;


if (telefono.length==9)
{

 if (telefono.substr(0,1)=="9") si=1;

  if (telefono.substr(0,1)=="8") si=1;

   if (telefono.substr(0,1)=="6") si=1;


}

return si;
}