function pregunta(laid){ 
    if (confirm('Seguro que desea eliminar este inmueble')){ 
       urlToGo= "ajax/eliminainmueble.php?idi="+laid;
				frames['elimina'].location.href= urlToGo;
				setTimeout("window.location.reload()",1000)
				//window.location.reload(); 
    } 
} 

function emailCheck (emailStr) {
/* Verificar si el email tiene el formato user@dominio. */
var emailPat=/^(.+)@(.+)$/; 

/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 

/* Verifica los caracteres que son válidos en una dirección de email */
var validChars="\[^\\s" + specialChars + "\]"; 

var quotedUser="(\"[^\"]*\")"; 

/* Verifica si la dirección de email está representada con una dirección IP Válida */ 


var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;


/* Verificar caracteres inválidos */ 

var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
/*alert("Email address seems incorrect (check @ and .'s)");*/
return false
}
var user=matchArray[1]
var domain=matchArray[2]

// Si el user "user" es valido 
if (user.match(userPat)==null) {
// Si no
/*alert("El nombre de usuario no es válido.");*/
return false
}

/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
/*alert("IP de destino inválida");*/
return false
}
}
return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
/*alert("El dominio parece no ser válido.");*/
return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { 

/*alert("La dicrección debe tener 3 letras si es .'com' o 2 si en de algún pais.");*/
return false
}

if (len<2) {
var errStr="La dirección es erronea"
/*alert(errStr);*/
return false
}

// La dirección de email ingresada es Válida
return true;
}

function validarEntero(codigo){ 
    //intento convertir a entero. 
    //si era un entero no le afecta, si no lo era lo intenta convertir 
    valor = parseInt(codigo) 

    //Compruebo si es un valor numérico 
    if (isNaN(valor)) { 
       //entonces (no es numero) devuelvo el valor cadena vacia 
       return "" 
    }else{ 
       //En caso contrario (Si era un número) devuelvo el valor 
       return valor 
    } 
} 


function obtenerDigito(valor){
  valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
  control = 0;
  for (i=0; i<=9; i++)
    control += parseInt(valor.charAt(i)) * valores[i];
  control = 11 - (control % 11);
  if (control == 11) control = 0;
  else if (control == 10) control = 1;
  return control;
}



function numerico(valor){
  cad = valor.toString();
  for (var i=0; i<cad.length; i++) {
    var caracter = cad.charAt(i);
	if (caracter<"0" || caracter>"9")
	  return false;
  }
  return true;
}


function validar(f) {
  if (f.banco.value == ""  || f.sucursal.value == "" ||
      f.dc.value == "" || f.cuenta.value == "")
    alert("Por favor, introduzca los datos de su cuenta");
  else {
    if (f.banco.value.length != 4 || f.sucursal.value.length != 4 ||
        f.dc.value.length != 2 || f.cuenta.value.length != 10)
      alert("Por favor, introduzca correctamente los datos de su cuenta;"
	    + " no están completos");
    else {
      if (!numerico(f.banco.value) || !numerico(f.sucursal.value) ||
          !numerico(f.dc.value) || !numerico(f.cuenta.value))
        alert("Por favor, introduzca correctamente los datos de su "
         + "cuenta; no son numericos");
      else {
        if (!(obtenerDigito("00" + f.banco.value + f.sucursal.value) ==
              parseInt(f.dc.value.charAt(0))) || 
            !(obtenerDigito(f.cuenta.value) ==
              parseInt(f.dc.value.charAt(1))))
          alert("Los dígitos de control no se corresponden con los demás"
            + " números de la cuenta");
	    else
          alert ("CCC correcto");
      }
    }
  }
}

function addLoadEvent(func){
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
    {
        window.onload = func;
    }else{
        window.onload = function(){
            if (oldonload)
            {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(function(){
    if (document.getElementById( 'enviadoai' )==null) { } else {
	document.getElementById( 'enviadoai' ).onclick = function (){
	var mail=emailCheck(document.getElementById( 'email' ).value);
	if (document.getElementById( 'Nombre' ).value == "")
	{ alert("Debe proporcionarnos el Nombre comercial"); document.getElementById( 'Nombre' ).focus(); return 0; }
	if (document.getElementById( 'pcont' ).value == "")
	{ alert("Debe proporcionarnos el Nombre de la persona de contacto"); document.getElementById( 'pcont' ).focus(); return 0; }
	if (document.getElementById( 'dir' ).value == "")
	{ alert("Debe proporcionarnos su direccion"); document.getElementById( 'dir' ).focus(); return 0; }
	if (document.getElementById( 'Localidad' ).value == "")
	{ alert("Debe proporcionarnos su localidad"); document.getElementById( 'Localidad' ).focus(); return 0; }
	//var cpv = validarEntero(document.getElementById('cp').value)
	if (document.getElementById('cp').value=="")
	{ alert("Debe proporcionarnos su CP"); document.getElementById('cp').focus(); return 0; }
	var tlfv = validarEntero(document.getElementById( 'Telefono' ).value)
	if (document.getElementById( 'Telefono' ).value == "")
	{ alert("Debe proporcionarnos su telefono"); document.getElementById( 'Telefono' ).focus(); return 0; }
	if (mail == false)
	{ alert("Debe proporcionarnos un e-mail valido"); document.getElementById( 'email' ).focus(); return 0; }
	if (document.getElementById( 'pass' ).value == "")
	{ alert("Debe especificar una contrase\u00F1a"); document.getElementById( 'pass' ).focus(); return 0; }
	if (document.getElementById( 'rpass' ).value == "")
	{ alert("Debe escribir de nuevo la contrase\u00F1a"); document.getElementById( 'rpass' ).focus(); return 0; }
	if (document.getElementById( 'pass' ).value == document.getElementById( 'rpass' ).value)
	{} else
	{ alert("Debe escribir la misma contrase\u00F1a"); document.getElementById( 'rpass' ).focus(); return 0; }
	if (document.getElementById( 'plan' ).value == "0")
	{ alert("Debe seleccionar el plan que desea"); document.getElementById( 'plan' ).focus(); return 0; }
	/*if (document.getElementById( 'ccbanco' ).value == ""  || document.getElementById( 'ccbancob' ).value == "" || document.getElementById( 'ccbancoc' ).value == "" || document.getElementById( 'ccbancod' ).value == "")
    { alert("Por favor, introduzca los datos de su cuenta"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (document.getElementById( 'ccbanco' ).value.length != 4  || document.getElementById( 'ccbancob' ).value.length != 4 || document.getElementById( 'ccbancoc' ).value.length != 2 || document.getElementById( 'ccbancod' ).value.length != 10)
    { alert("Por favor, introduzca correctamente los datos de su cuenta; no estan completos"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (!numerico(document.getElementById( 'ccbanco' ).value) || !numerico(document.getElementById( 'ccbancob' ).value) || !numerico(document.getElementById( 'ccbancoc' ).value) || !numerico(document.getElementById( 'ccbancod' ).value))
    { alert("Por favor, introduzca correctamente los datos de su cuenta; no son numericos"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (!(obtenerDigito("00" + document.getElementById( 'ccbanco' ).value + document.getElementById( 'ccbancob' ).value) == parseInt(document.getElementById( 'ccbancoc' ).value.charAt(0))) || !(obtenerDigito(document.getElementById( 'ccbancod' ).value) == parseInt(document.getElementById( 'ccbancoc' ).value.charAt(1))))	
    { alert("Los digitos de control no se corresponden con los demas numeros de la cuenta"); document.getElementById( 'ccbanco' ).focus(); return 0; }
	*/
	if (document.getElementById( 'Privacidad' ).checked == false)
	{ alert("Debe aceptar la politica de privacidad"); document.getElementById( 'Privacidad' ).focus(); return 0; }
	
	document.getElementById( 'fcontacto' ).submit();
	}
	}
});
addLoadEvent(function(){
    if (document.getElementById('enviadofa')==null) { } else {
	document.getElementById('enviadofa').onclick = function (){
	var mail=emailCheck(document.getElementById( 'email' ).value);
	if (mail == false)
	{ alert("Debe proporcionarnos un e-mail valido"); document.getElementById( 'email' ).focus(); return 0; }
	if (document.getElementById( 'pass' ).value == "")
	{ alert("Debe escribir su contrase\u00F1a"); document.getElementById( 'pass' ).focus(); return 0; }	
	document.getElementById( 'facceso' ).submit();
	}
	}
});

addLoadEvent(function(){
    if (document.getElementById('enviadopub')==null) { } else {
	document.getElementById( 'enviadopub' ).onclick = function (){
	if (document.getElementById( 'ref' ).value == "")
	{ alert("Debe escribir una referencia del inmueble"); document.getElementById( 'ref' ).focus(); return 0; }	
	if (document.getElementById( 'Localidad' ).value == "")
	{ alert("Debe escribir la localidad donde esta ubicado el inmueble"); document.getElementById( 'Localidad' ).focus(); return 0; }	
	if (document.getElementById( 'dirr' ).value == "")
	{ alert("Debe escribir la direccion del inmuble pinchando en el boton ubicacion del inmueble"); document.getElementById( 'dirr' ).focus(); return 0; }
	if (document.getElementById( 'lat' ).value == "" || document.getElementById( 'lng' ).value == "" )
	{ alert("Debe ubicar el inmueble en el mapa pinchando sobre el boton ubicacion exacta"); document.getElementById( 'dirr' ).focus(); return 0; }

	var precio = validarEntero(document.getElementById( 'precio' ).value);
	var precioa = validarEntero(document.getElementById( 'precioa' ).value);
	var moda=document.fcontacto.modalidad;
	if (document.getElementById( 'destacadob' ).value=="1") {} else {
	if (moda.value=="0")
	{ if (precio == "" || precioa == "") { alert("Debe escribir el precio de venta y alquiler solo con numeros"); document.getElementById( 'precio' ).focus(); return 0;} }	
	if (moda.value=="1" && precio == "")
	{ alert("Debe escribir el precio de venta solo con numeros"); document.getElementById( 'precio' ).focus(); return 0; }	
	if (moda.value=="2" && precioa == "")
	{ alert("Debe escribir el precio de alquiler solo con numeros"); document.getElementById( 'precioa' ).focus(); return 0; }	
	}
	
	if (document.getElementById( 'supe' ).value!=="")
	{ 
	//var super = validarEntero(document.getElementById( 'supe' ).value);
	if (validarEntero(document.getElementById( 'supe' ).value)=="") {
	alert("Debe escribir la superficie solo con numeros"); document.getElementById( 'supe' ).focus(); return 0; } }	
	
	if (!document.getElementById( 'parcela' ).value=="")
	{ 
	var parcela = validarEntero(document.getElementById( 'parcela' ).value);
	if (parcela=="")
	{ alert("Debe escribir la parcela solo con numeros"); document.getElementById( 'parcela' ).focus(); return 0; } }	
	
	if (!document.getElementById( 'hab' ).value=="")
	{
	var hab = validarEntero(document.getElementById( 'hab' ).value);
	if (hab=="")
	{ alert("Debe escribir las habitaciones solo con numeros"); document.getElementById( 'hab' ).focus(); return 0; } }	
	
	if (!document.getElementById( 'ban' ).value=="")
	{
	var ban = validarEntero(document.getElementById( 'ban' ).value);
	if (ban=="")
	{ alert("Debe escribir los ba\u00F1os solo con numeros"); document.getElementById( 'ban' ).focus(); return 0; } }	
	
	if (!document.getElementById( 'aseos' ).value=="")
	{
	var aseos = validarEntero(document.getElementById( 'aseos' ).value);
	if (aseos=="")
	{ alert("Debe escribir los aseos solo con numeros"); document.getElementById( 'aseos' ).focus(); return 0; } }	
	

	document.getElementById( 'fcontacto' ).submit();
	}
	}
});
addLoadEvent(function(){
    if (document.getElementById('enviadobsqvi')==null) { } else {
	document.getElementById('enviadobsqvi').onclick = function (){
	if (document.getElementById( 'Nombre' ).value == "")
	{ alert("Debe escribir su nombre"); document.getElementById( 'Nombre' ).focus(); return 0; }
	if (document.getElementById( 'Telefono' ).value == "")
	{ alert("Debe escribir su telefono de contacto"); document.getElementById( 'Telefono' ).focus(); return 0; }	
	if (document.getElementById( 'Privacidad' ).checked == false)
	{ alert("Debe aceptar la politica de privacidad"); document.getElementById( 'Privacidad' ).focus(); return 0; }
	document.getElementById( 'fcontacto' ).submit();
	}
	}
});
addLoadEvent(function(){
    if (document.getElementById('enviadoct')==null) { } else {
	document.getElementById('enviadoct').onclick = function (){
	if (document.getElementById( 'Nombre' ).value == "")
	{ alert("Debe escribir su nombre"); document.getElementById( 'Nombre' ).focus(); return 0; }
	if (document.getElementById( 'Localidad' ).value == "")
	{ alert("Debe escribir su localidad"); document.getElementById( 'Localidad' ).focus(); return 0; }	
	if (document.getElementById( 'Telefono' ).value == "")
	{ alert("Debe escribir su telefono de contacto"); document.getElementById( 'Telefono' ).focus(); return 0; }
	if (document.getElementById( 'Consulta' ).value == "")
	{ alert("Escriba su consulta o motivo de contacto"); document.getElementById( 'Consulta' ).focus(); return 0; }
	if (document.getElementById( 'Privacidad' ).checked == false)
	{ alert("Debe aceptar la politica de privacidad"); document.getElementById( 'Privacidad' ).focus(); return 0; }
	document.getElementById( 'fcontacto' ).submit();
	}
	}
});
addLoadEvent(function(){
    if (document.getElementById( 'enviadoaip' )==null) { } else {
	document.getElementById( 'enviadoaip' ).onclick = function (){
	var mail=emailCheck(document.getElementById( 'email' ).value);
	if (document.getElementById( 'Nombre' ).value == "")
	{ alert("Debe proporcionarnos su Nombre y apellidos"); document.getElementById( 'Nombre' ).focus(); return 0; }
	var tlfv = validarEntero(document.getElementById( 'Telefono' ).value)
	if (tlfv == "")
	{ alert("Debe proporcionarnos su telefono solo numeros sin guiones ni ningun tipo de texto o separacion"); document.getElementById( 'Telefono' ).focus(); return 0; }
	if (mail == false)
	{ alert("Debe proporcionarnos un e-mail valido"); document.getElementById( 'email' ).focus(); return 0; }
	if (document.getElementById( 'pass' ).value == "")
	{ alert("Debe especificar una contrase\u00F1a"); document.getElementById( 'pass' ).focus(); return 0; }
	if (document.getElementById( 'rpass' ).value == "")
	{ alert("Debe escribir de nuevo la contrase\u00F1a"); document.getElementById( 'rpass' ).focus(); return 0; }
	if (document.getElementById( 'pass' ).value == document.getElementById( 'rpass' ).value)
	{} else
	{ alert("Debe escribir la misma contrase\u00F1a"); document.getElementById( 'rpass' ).focus(); return 0; }
		
	if (document.getElementById( 'Privacidad' ).checked == false)
	{ alert("Debe aceptar la politica de privacidad"); document.getElementById( 'Privacidad' ).focus(); return 0; }
	
	document.getElementById( 'fcontacto' ).submit();
	}
	}
});
addLoadEvent(function(){
    if (document.getElementById( 'enviadoact' )==null) { } else {
	document.getElementById( 'enviadoact' ).onclick = function (){
	var mail=emailCheck(document.getElementById( 'email' ).value);
	if (document.getElementById( 'Nombre' ).value == "")
	{ alert("Debe proporcionarnos el Nombre comercial"); document.getElementById( 'Nombre' ).focus(); return 0; }
	if (document.getElementById( 'dir' ).value == "")
	{ alert("Debe proporcionarnos su direccion"); document.getElementById( 'dir' ).focus(); return 0; }
	if (document.getElementById( 'Localidad' ).value == "")
	{ alert("Debe proporcionarnos su localidad"); document.getElementById( 'Localidad' ).focus(); return 0; }
	//var cpv = validarEntero(document.getElementById('cp').value)
	if (validarEntero(document.getElementById('cp').value)=="")
	{ alert("Debe proporcionarnos su CP de forma numerica"); document.getElementById('cp').focus(); return 0; }
	var tlfv = validarEntero(document.getElementById( 'Telefono' ).value)
	if (tlfv == "")
	{ alert("Debe proporcionarnos su telefono solo numeros sin guiones ni ningun tipo de texto o separacion"); document.getElementById( 'Telefono' ).focus(); return 0; }
	if (mail == false)
	{ alert("Debe proporcionarnos un e-mail valido"); document.getElementById( 'email' ).focus(); return 0; }
	
	if (document.getElementById( 'ccbanco' ).value == ""  || document.getElementById( 'ccbancob' ).value == "" || document.getElementById( 'ccbancoc' ).value == "" || document.getElementById( 'ccbancod' ).value == "")
    { alert("Por favor, introduzca los datos de su cuenta"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (document.getElementById( 'ccbanco' ).value.length != 4  || document.getElementById( 'ccbancob' ).value.length != 4 || document.getElementById( 'ccbancoc' ).value.length != 2 || document.getElementById( 'ccbancod' ).value.length != 10)
    { alert("Por favor, introduzca correctamente los datos de su cuenta; no estan completos"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (!numerico(document.getElementById( 'ccbanco' ).value) || !numerico(document.getElementById( 'ccbancob' ).value) || !numerico(document.getElementById( 'ccbancoc' ).value) || !numerico(document.getElementById( 'ccbancod' ).value))
    { alert("Por favor, introduzca correctamente los datos de su cuenta; no son numericos"); document.getElementById( 'ccbanco' ).focus(); return 0; }

	if (!(obtenerDigito("00" + document.getElementById( 'ccbanco' ).value + document.getElementById( 'ccbancob' ).value) == parseInt(document.getElementById( 'ccbancoc' ).value.charAt(0))) || !(obtenerDigito(document.getElementById( 'ccbancod' ).value) == parseInt(document.getElementById( 'ccbancoc' ).value.charAt(1))))	
    { alert("Los digitos de control no se corresponden con los demas numeros de la cuenta"); document.getElementById( 'ccbanco' ).focus(); return 0; }
		
	document.getElementById( 'fcontacto' ).submit();
	}
	}
});


function toggle_prov() {

if(document.getElementById( 'prov' ).value==28) {
   document.getElementById("zonasi").style.display = "inline";
} else {
   document.getElementById("zonasi").style.display = "none";
}

}