function validarCupon(){   
    
    var errores="";
    if( document.getElementById("nombre")!=null && (document.getElementById("nombre").value=="" || document.getElementById("nombre").value=="Nombre * :") ){
        errores="- No has introducido tu nombre.\n"
    }
    /*
    if(document.getElementById("domicilio")!=null&&document.getElementById("domicilio").value==""){
        errores+="- No has introducido el domicilio. \n"
    }*/
    var telefono=document.getElementById("telefono").value;
    if(document.getElementById("telefono")!=null && (document.getElementById("telefono").value=="" || document.getElementById("telefono").value=="Teléfono * :") ){
        errores+="- No has introducido el telefono o no es válido.\n"
    }else if(!parseFloat(document.getElementById("telefono").value)||document.getElementById("telefono").value.length!=9){
        errores+="- El teléfono debe estar formado por 9 números sin separaciones. \n"
    }else if(telefono.charAt(0)!="6"&&telefono.charAt(0)!="8"&&telefono.charAt(0)!="9"){
        errores+="- El número de telefono no es válido. \n"
    }
    if(document.getElementById("provinciaid")!=null&&document.getElementById("provinciaid").value <= 0){
        errores+="- No has seleccionado tu provincia. \n"
    }
    if(document.getElementById("poblacionid")!=null&&document.getElementById("poblacionid").value <= 0){
        errores+="- No has seleccionado tu población. \n"
    }
    if( document.getElementById("codigopostal")!=null&& ( document.getElementById("codigopostal").value <= 0 || document.getElementById("codigopostal").value == "" ) ){
        errores+="- No has seleccionado tu Código postal. \n"
    }
    if(document.getElementById("edad")!=null&&document.getElementById("edad").value <= 0){
        errores+="- No has introducido la edad. \n"
    }
    if(document.getElementById("estudiosid")!=null&&document.getElementById("estudiosid").value <= 0){
        errores+="- No has seleccionado los estudios. \n"
    }
    if(document.getElementById("checkcondicioneslegales")!=null&&document.getElementById("checkcondicioneslegales").checked==false){
        errores+="- Debes aceptar las condiciones de la politica de privacidad y aviso legal del servicio. \n"
    }
    if(errores.length>0){
        alert("Errores: \n\n"+errores);
        return false;
    } else {
        return true;
    }
}

var context ="/unoauno";
function listarProvincias() {
}



/* Fin de carga automÃ¡tica de combos de la pÃ¡gina de cupÃ³n*/
/** Listar poblaciones */
function listarPoblaciones(provinciaId) {
    $('#comboPoblacionesDiv').html('<select class="campo_fijo_cupon_2"><option value="-1"></option></select>');
    $("#poblacionesDiv").slideDown("slow");  
    $.ajax({
        url: context+"/poblaciones-ajax.action?id="+ provinciaId,
        cache: true,
        success: function(html){
            $('#comboPoblacionesDiv').html(html);
            $("select").uniform({selectClass: 'campo_fijo_cupon_2'});
        }
    });
    /* listarCP(-1); */
}
/** Listar cÃ³digos postales */
function listarCP(poblacionId) {
    $('#comboCPDiv').html('<select class="campo_fijo_cupon_2"><option value="-1"></option></select>');
    $("#cpDiv").slideDown("slow");
    $.ajax({
        url: context+"/cp-ajax.action?id="+ poblacionId,
        cache: true,
        success: function(html){
            $('#comboCPDiv').html(html);
            $("select").uniform({selectClass: 'campo_fijo_cupon_2'});
        }
    });
}

/** Enviar formulario */
function enviarForm(id) {
    var form = document.getElementById(id);
    form.submit();
}

/** Cargar el resultado de una llamada en un div*/
function loadAjax(funcion, divId) {
    $.ajax({
        url: funcion,
        cache: true,
        success: function(html){
            $('#'+divId).html(html);
        }
    });    
}

/** Cargar el resultado de una llamada en un div*/
function submitAjax(formId, divId) {
    var action = $('#'+formId).attr('action');
    var data = $('#'+formId).serialize();
    alert(action + '?' + data);
    $.ajax({
        url: action + '?' + data,
        cache: true,
        success: function(html){
            $('#'+divId).html(html);
        }
    });
}

function validarEmail(valor) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
        return (true)
    } else {
        alert("Email no valido.\nPor favor, revisa este dato para poder recibir nuestro boletÃ­n de noticias.");
        return (false);
    }
}

function validarNacionalidad(){
    var nacionalidadId = document.getElementById("cupon_comboNacionalidadId").value;
    if(nacionalidadId != 90){
        $("#divDni").slideDown(500);
    }else{
        $("#divDni").slideUp(500);
    }
}



