function ValidaBusqueda()
{
    if(document.frmbuscador.localidad.value == "Seleccione una localidad" && document.frmbuscador.zona.value == "Seleccione una zona" && document.frmbuscador.tipo.value == "Seleccione un tipo de inmueble" && document.frmbuscador.modalidad.value == "Seleccione una modalidad" && document.frmbuscador.preciomin.value == "Precio mínimo" && document.frmbuscador.preciomax.value == "Precio máximo" && document.frmbuscador.referencia.value == "Referencia"){
        alert("ADVERTENCIA!! No ha indicado ningún parámetro de búsqueda.\n Debe indicar al menos uno.");
        return;
    }
    
    if(document.frmbuscador.preciomin.value.indexOf(".") != -1 || document.frmbuscador.preciomin.value.indexOf(",") != -1 || (!IsNumeric(document.frmbuscador.preciomin.value) && document.frmbuscador.preciomin.value != "Precio mínimo")){
        alert("ADVERTENCIA!! No incluya el . o la , en las cantidades, ni otro tipo de caracteres, sólo número.\nEscriba por ejemplo: 180000");
        return;        
    }
    
    if(document.frmbuscador.preciomax.value.indexOf(".") != -1 || document.frmbuscador.preciomax.value.indexOf(",") != -1 || (!IsNumeric(document.frmbuscador.preciomax.value) && document.frmbuscador.preciomax.value != "Precio máximo")){
        alert("ADVERTENCIA!! No incluya el . o la , en las cantidades, ni otro tipo de caracteres, sólo número.\nEscriba por ejemplo: 180000");
        return;        
    }
    
    document.frmbuscador.submit();
}

function IsNumeric(sText) {
    if (sText == null) return false;
 
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;
 
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function Contacto(){
    bool = false; 
    if(document.getElementById('nombre').value == '' || document.getElementById('nombre').value == 'Escriba su nombre') {
        bool = false;
        alert('ERROR\nNombre obligatorio');
        document.getElementById('nombre').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('apellidos').value == '' || document.getElementById('apellidos').value == 'Escriba sus apellidos') {
        bool = false;
        alert('ERROR\nApellidos obligatorios');
        document.getElementById('apellidos').focus();
        return;
    }
    else{
        bool = true;
    }
    
/*    if(document.getElementById('direccion').value == '' || document.getElementById('direccion').value == 'Escriba su dirección') {
        bool = false;
        alert('ERROR\nLa dirección es obligatoria');
        document.getElementById('direccion').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('localidad').value == '' || document.getElementById('localidad').value == 'Escriba su localidad') {
        bool = false;
        alert('ERROR\nLa localidad es obligatoria');
        document.getElementById('localidad').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('provincia').value == '' || document.getElementById('provincia').value == 'Escriba su provincia') {
        bool = false;
        alert('ERROR\nEscriba su provincia');
        document.getElementById('provincia').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('telefono').value == '' || document.getElementById('telefono').value == 'Escriba su teléfono') {
        bool = false;
        alert('ERROR\nEscriba su teléfono');
        document.getElementById('telefono').focus();
        return;
    }
    else{
        bool = true;
    }    */
    
    if(bool){
        if(document.getElementById('email').value == '' || document.getElementById('email').value == 'Escriba su e-mail') {
            bool = false;
            alert('ERROR\nE-mail obligatorio');
            document.getElementById('email').focus();
            return;
        }
        else{
            bool = true;
        }
    }
    
 /*   if(document.getElementById('asunto').value == '' || document.getElementById('asunto').value == 'Escriba el asunto') {
        bool = false;
        alert('ERROR\nAsunto obligatorio');
        document.getElementById('asunto').focus();
        return;
    }
    else{
        bool = true;
    } 
    
    if(bool){
        if(document.getElementById('consulta').value == '' || document.getElementById('consulta').value == 'Escriba el motivo de su consulta') {
            bool = false;
            alert('ERROR\nLa consulta es obligatoria');
            document.getElementById('consulta').focus();
            return;
        }
        else{
            bool = true;
        }
    }  */
    
    if(bool){
        if(!document.getElementById('fpolitica').checked) {
            bool = false;
            alert('ERROR\nDebe aceptar la política de privacidad de datos');
            document.getElementById('fpolitica').focus();
            return;
        }
        else{
            bool = true;
        }
    }    
     
    if(bool){
        document.getElementById('frmcontacto').submit();
    }   
}

function Recomendar(){
    bool = false; 
    if(document.getElementById('nombre').value == '' || document.getElementById('nombre').value == 'Escriba su nombre') {
        bool = false;
        alert('ERROR\nNombre obligatorio');
        document.getElementById('nombre').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('email').value == '' || document.getElementById('email').value == 'Escriba su e-mail') {
        bool = false;
        alert('ERROR\nE-mail obligatorios');
        document.getElementById('email').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('email2').value == '' || document.getElementById('email2').value == 'Escriba la dirección de su amigo') {
        bool = false;
        alert('ERROR\nLa dirección de su amigo es obligatoria');
        document.getElementById('email2').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('consulta').value == '' || document.getElementById('consulta').value == 'Escriba su comentario') {
        bool = false;
        alert('ERROR\nEl comentario es obligatorio');
        document.getElementById('consulta').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(bool){
        if(!document.getElementById('fpolitica').checked) {
            bool = false;
            alert('ERROR\nDebe aceptar la política de privacidad de datos');
            document.getElementById('fpolitica').focus();
            return;
        }
        else{
            bool = true;
        }
    }    
     
    if(bool){
        document.getElementById('frmcontacto').submit();
    }   
}

function Vender(){
    bool = false; 
    if(document.getElementById('nombre').value == '' || document.getElementById('nombre').value == 'Su nombre') {
        bool = false;
        alert('ERROR\nNombre obligatorio');
        document.getElementById('nombre').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('email').value == '' || document.getElementById('email').value == 'Su e-mail') {
        bool = false;
        alert('ERROR\nE-mail obligatorio');
        document.getElementById('email').focus();
        return;
    }
    else{
        bool = true;
    }
    
/*    if(document.getElementById('telf').value == '' || document.getElementById('telf').value == 'Su teléfono') {
        bool = false;
        alert('ERROR\nLa dirección de su amigo es obligatoria');
        document.getElementById('telf').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('consulta').value == '' || document.getElementById('consulta').value == 'Escriba una breve descripción de su inmueble') {
        bool = false;
        alert('ERROR\nLa descripción es obligatoria');
        document.getElementById('consulta').focus();
        return;
    }
    else{
        bool = true;
    }   */
     
    if(bool){
        document.getElementById('fventa').submit();
    }   
}

function Vender2(){
    bool = false; 
    if(document.getElementById('nombre2').value == '' || document.getElementById('nombre2').value == 'Su nombre') {
        bool = false;
        alert('ERROR\nNombre obligatorio');
        document.getElementById('nombre2').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('email2').value == '' || document.getElementById('email2').value == 'Su e-mail') {
        bool = false;
        alert('ERROR\nE-mail obligatorio');
        document.getElementById('email2').focus();
        return;
    }
    else{
        bool = true;
    }
    
 /*   if(document.getElementById('telf2').value == '' || document.getElementById('telf2').value == 'Su teléfono') {
        bool = false;
        alert('ERROR\nLa dirección de su amigo es obligatoria');
        document.getElementById('telf2').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('consulta2').value == '' || document.getElementById('consulta2').value == 'Escriba una breve descripción de su inmueble') {
        bool = false;
        alert('ERROR\nLa descripción es obligatoria');
        document.getElementById('consulta2').focus();
        return;
    }
    else{
        bool = true;
    }  */ 
     
    if(bool){
        document.getElementById('fventa2').submit();
    }   
}


function Promocion(){
    bool = false; 
    if(document.getElementById('fnombre').value == '' || document.getElementById('fnombre').value == 'Escriba su nombre') {
        bool = false;
        alert('ERROR\nNombre obligatorio');
        document.getElementById('fnombre').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(bool){
        if(document.getElementById('femail').value == '' || document.getElementById('femail').value == 'Escriba su e-mail') {
            bool = false;
            alert('ERROR\nE-mail obligatorio');
            document.getElementById('femail').focus();
            return;
        }
        else{
            bool = true;
        }
    }
        
 /*   if(document.getElementById('ftelefono').value == '' || document.getElementById('ftelefono').value == 'Escriba su nº de teléfono') {
        bool = false;
        alert('ERROR\nEscriba su nº de teléfono');
        document.getElementById('ftelefono').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('fmovil').value == '' || document.getElementById('fmovil').value == 'Escriba su nº de móvil') {
        bool = false;
        alert('ERROR\nEscriba su nº de móvil');
        document.getElementById('fmovil').focus();
        return;
    }
    else{
        bool = true;
    }
    
    if(document.getElementById('fmensaje').value == '' || document.getElementById('fmensaje').value == 'Escriba su mensaje') {
        bool = false;
        alert('ERROR\nMensaje obligatorio');
        document.getElementById('fmensaje').focus();
        return;
    }
    else{
        bool = true;
    } */
       
    if(bool){
        if(!document.getElementById('fpolitica').checked) {
            bool = false;
            alert('ERROR\nDebe aceptar la política de privacidad de datos');
            document.getElementById('fpolitica').focus();
            return;
        }
        else{
            bool = true;
        }
    }    
     
    if(bool){
        document.getElementById('frmpromo').submit();
    }   
}

//para el calculo de la cuota
function calculocuota(capital,interes,duracion){
    capital=replaceChars(capital,',','.');
    interes=replaceChars(interes,',','.');
    duracion=replaceChars(duracion,',','.');
    
    if((!isNaN(capital)) && (capital!="") && (capital > 0)){
        if((!isNaN(interes)) && (interes!="") && (interes > 0)){
            if((!isNaN(duracion)) && (duracion!="") && (duracion > 0)){     
                inter = interes/(100*12);
                periodos = 12 * duracion;
                cuota  = (capital * inter * Math.pow((1 + inter),periodos)) / (Math.pow((1 + inter),periodos) - 1);
                cuota = Math.round(cuota * 100) / 100;
                
                reembolso = calculocapitalc(capital,interes,duracion);  
                reembolso = Math.round(reembolso*100)/100;  
                
                document.frmcalcular.numcuotas.value=periodos;
                document.frmcalcular.importe.value=cuota;
            }
        }
    }
}

function replaceChars(cadena,val1,val2) {
//function replaceChars(entry) {
    out = val1; // reemplazar la letra a
    add = val2; // por la letra z
    temp = "" + cadena;

    while (temp.indexOf(out)>-1) {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
    }
    return temp;
}

function calculocapitalc(capital,interes,duracion){
//Ct = C (1 + r)t
    inter = interes/(100*12);
    capitalc = capital * Math.pow((1 + inter),duracion);
    // Math.pow((1 + inter),periodos)
    return capitalc; 
}



