// JavaScript Document
var cargada=0;

var vecesatras=0
vecesatras=history.length;
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 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("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="7">Menos de 70.000 €</option>';
	cadena = cadena + '<option value="8">70.000 - 100.000 €</option>';
	cadena = cadena + '<option value="9">100.000 - 150.000 €</option>';
	cadena = cadena + '<option value="10">150.000 - 200.000 €</option>';
	cadena = cadena + '<option value="11">200.000 - 250.000 €</option>';
	cadena = cadena + '<option value="12">250.000 - 300.000 €</option>';
	cadena = cadena + '<option value="13">300.000 - 350.000 €</option>';
	cadena = cadena + '<option value="14">350.000 - 500.000 €</option>';
	cadena = cadena + '<option value="15">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="16">Menos de 100.000 €</option>';
	cadena = cadena + '<option value="17">100.000 - 150.000 €</option>';
	cadena = cadena + '<option value="18">150.000 - 200.000 €</option>';
	cadena = cadena + '<option value="19">200.000 - 250.000 €</option>';
	cadena = cadena + '<option value="20">250.000 - 300.000 €</option>';
	cadena = cadena + '<option value="21">300.000 - 350.000 €</option>';
	cadena = cadena + '<option value="22">350.000 - 500.000 €</option>';
	cadena = cadena + '<option value="23">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;

	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";

	tipo = document.getElementById("numtipo").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 = "&tipohab=" + habitacion;

	// window.open (rutapath() + "listados.php?numciudad=" + numciudad + precio
	// + habitacion + tipo ,"_top");
	window.open("?numciudad=" + numciudad + precio + habitacion + tipo, "_top");
}

function revisaprecio(valor) {
	if (valor == "v")
		cambiaventa();
	if (valor == "a")
		cambiaalquiler();
	if (valor == "p")
		cambiapromocion();
}

function buscaralquiler() {
	gdom.$("formbuscar").submit();
}

function limpiarConsulta() {
	gdom.$("formconsulta").reset();
}
function enviarConsulta() {
	gdom.$("formconsulta").submit();
}




function enviarnewconsulta(ciudad)
{

var telefono="";
var email="";
var nombre="";
var notificar="";
var precio="";
var hacer=0;
var descripcion="";
var masinfo="";

if (document.getElementById("telefono")!=null) telefono=document.getElementById("telefono" ).value;

if (document.getElementById("nombre" )!=null)  nombre=document.getElementById("nombre").value;
if (document.getElementById("descripcion" )!=null)   descripcion=document.getElementById("descripcion").value;
if (document.getElementById("zonaform" )!=null)   descripcion=document.getElementById("zonaform").value;
if (document.getElementById("phonoform")!=null) telefono=document.getElementById("phonoform" ).value;
if (document.getElementById("nombreform" )!=null)  nombre=document.getElementById("nombreform").value;
if (document.getElementById("emailform")!=null)  email=document.getElementById("emailform").value;
if (document.getElementById("email")!=null)  email=document.getElementById("email").value;


if (email.length>0) hacer= compruebaemail(email);
if (comprobartelefono(telefono)==0)
             {
         alert ('Debes de introducir un telefono valido');
         hacer=1;
         }
if (hacer==0)
    {

        cargarventanaajax ("frmportal","includes/enviarsolicitud.php?tipo=frmresul&telefono=" + telefono + "&agencia=" + ciudad +"&nombre=" + nombre + "&email=" + email + "&notificar=" + notificar + "&precio=" + precio + "&descripcion=" + descripcion +"&masinfo=" + masinfo) ;
    if (document.getElementById("telefono")!=null) document.getElementById("telefono").value="";
    if (document.getElementById("nombre")!=null)  document.getElementById("nombre" ).value="";
    if (document.getElementById("descripcion")!=null)   document.getElementById("descripcion").value="";
    if (document.getElementById("email")!=null)  document.getElementById("email").value="";
if (document.getElementById("zonaform" )!=null)   document.getElementById("zonaform").value="";
if (document.getElementById("phonoform")!=null) document.getElementById("phonoform" ).value="";
if (document.getElementById("nombreform" )!=null)  document.getElementById("nombreform").value="";
if (document.getElementById("emailform")!=null)  document.getElementById("emailform").value="";
    }
}


function cargarventanaajax (id,parametro)
{

cargada=1;
    url= 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";

		document.getElementById(id).style.visibility="visible";
            centrarventana(id);
        }
    }
    ajax.send(null)
}



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 cerrarventana(texto,tipo)
{

document.getElementById(texto).style.display='none';
document.getElementById(texto).style.visibility="hidden";
}


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 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;
}

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 deseomellamen(codigo, agencia)
{
var url='';
url= "quemellamen.php?tipo=llamarficha&codigo=" + codigo + "&agencia=" +agencia + "&portal=" + window.location.host;

cargarventanaajax ("frmportal", url );
}

function emailsimilares(codigo, agencia)
{
var url='';
url= "quemellamen.php?tipo=mailficha&codigo=" + codigo + "&agencia=" +agencia + "&portal=" + window.location.host;

cargarventanaajax ("frmportal", url );
}


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("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 (email.length>0) hacer= compruebaemail(email);
    if (comprobartelefono(telefono)==0)
                 {
             alert ('Debes de introducir un telefono valido');
             hacer=1;
             }


if (hacer==0)
    {

        cargarventanaajax ("frmportal","includes/enviarsolicitud.php?tipo=" + tipo + "&telefono=" + telefono + "&agencia=" + agencia  + "&codigo=" + codigo +"&nombre=" + nombre + "&email=" + email + "&notificar=" + notificar + "&precio=" + precio + "&descripcion=" + descripcion);
if (document.getElementById("telefono")!=null) document.getElementById("telefono").value="";
if (document.getElementById("telefonoinicio")!=null) document.getElementById("telefonoinicio").value="";
if ((document.getElementById("email")!=null)  ) document.getElementById("email").value="";
if ((document.getElementById("nombre")!=null) ) document.getElementById("nombre").value="";
if ((document.getElementById("nombreinicio")!=null) ) document.getElementById("nombreinicio").value="";
if ((document.getElementById("nombredos")!=null) ) document.getElementById("nombredos").value="";
if ((document.getElementById("nombretres")!=null) ) document.getElementById("nombretres").value="";
if (document.getElementById("precio")!=null) document.getElementById("precio").value="";
if ((document.getElementById("descripcion")!=null)  ) document.getElementById("descripcion").value="";
if ((document.getElementById("descripcioninicio")!=null) ) document.getElementById("descripcioninicio").value="";
if ((document.getElementById("descripciondos")!=null)  )  ddocument.getElementById("descripciondos").value="";
if ((document.getElementById("telefonodos")!=null)   ) document.getElementById("telefonodos").value="";
if ((document.getElementById("telefonotres")!=null)  ) document.getElementById("telefonotres").value="";
if ((document.getElementById("emaildos")!=null)   ) document.getElementById("emaildos").value="";
if ((document.getElementById("emailinicio")!=null)  ) document.getElementById("emailinicio").value="";
if ((document.getElementById("emailtres")!=null)  ) document.getElementById("emailtres").value="";
if ((document.getElementById("preciodos")!=null) ) document.getElementById("preciodos").value="";

    }
}

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 abrirficha(idpromo,agencia)
{
//if (i>1)
//    window.open ("http://localhost/promocionesen/nuevo/fichapromocion.php?estoydentro=1&idpromo="  + idpromo  ,"_self");
//else

  window.open ("ficha.php?codpiso=" +idpromo + "&codagencia=" + agencia  ,"_top");
}

function abreweb(valor)
{
//if (i>1)
//    window.open ("http://localhost/promocionesen/nuevo/fichapromocion.php?estoydentro=1&idpromo="  + idpromo  ,"_self");
//else

  window.open (valor ,"_top");
}

function buscaralquiler()
{
cadena="?numtipo=" + document.getElementById("numtipo").value +"&ordenalo=1";
if (document.getElementById("tipoprecio").value!="") cadena=cadena +"&precio=" + document.getElementById("tipoprecio").value;
if (document.getElementById("tipohab").value!="") cadena=cadena +"&tipohab=" + document.getElementById("tipohab").value;
if (document.getElementById("terraza").checked==true) cadena=cadena + '&terraza=1';
if (document.getElementById("piscina").checked==true) cadena=cadena + '&piscina=1';
if (document.getElementById("opcioncompra").checked==true) cadena=cadena + '&opcioncompra=1';
if (document.getElementById("garaje").checked==true) cadena=cadena + '&garaje=1';
if (document.getElementById("muebles").checked==true) cadena=cadena + '&muebles=1';
if (document.getElementById("ascensor").checked==true) cadena=cadena + '&ascensor=1';
if (document.getElementById("urbanizacion").checked==true) cadena=cadena + '&urbanizacion=1';

window.open ("listados.php" +cadena,"_top");

}

function vuelvehome(web)
{
window.open (web, "_top");
}
function vuelvelistado(web)
{
//alert (history.length);
//alert(vecesatras);
//if (cargada==0)
    history.back(-1);
//else
  //  window.open (web, "_top");
}