/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function validacionDatosReserva(idioma){
    var panel_errores="ErrorMsg", errores = "";
    var validacion = new Validation('datosreserva',{onSubmit:false}); // OR new Validation(document.forms[0]);
    var result = validacion.validate();
    if (result){
        
        //Comprobar rango de fechas
        var fechaLlegada = document.datosreserva.fechallegada.value;
        var fechaSalida = document.datosreserva.fechasalida.value;
        var j_manana = new Date();
        j_manana.setDate(j_manana.getDate()+1);
        j_manana.setHours(0, 0, 0, 0);
        var j_fechaLlegada = new Date(fechaLlegada.substr(6,4, length),parseInt(fechaLlegada.substr(3,2, length),10)-1,fechaLlegada.substr(0,2, length));
        var j_fechaSalida = new Date(fechaSalida.substr(6,4, length),parseInt(fechaSalida.substr(3,2, length),10)-1,fechaSalida.substr(0,2, length));
        if(j_fechaLlegada<j_manana){
            errores = addError(errores,texto1.replace("[*1*]", formateaFechaPantalla(j_manana)));
        }
        if (j_fechaLlegada>j_fechaSalida)
            errores = addError(errores,texto2);
        
        var adultos = document.datosreserva.adultos.value;
        var suma_ninos = parseInt(document.datosreserva.ninos1.value,10) + parseInt(document.datosreserva.ninos2.value,10) + parseInt(document.datosreserva.bebes.value,10);

        if ((adultos > 2 && suma_ninos>0) || (adultos==2 && suma_ninos>2))
            errores = addError(errores,texto3);
        
        mostrarErrores(errores,panel_errores);
        if(errores!=""){    
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }
}
function validacionDatosPersonales(){
    var panel_errores="ErrorMsg", errores = "";
    var validacion = new Validation('datospersonales',{onSubmit:false}); // OR new Validation(document.forms[0]);
    var result = validacion.validate();
    if (result){
        if(document.datospersonales.nombre.value.length>50)
            errores = addError(errores,texto4);
        if(document.datospersonales.apellidos.value.length>100)
            errores = addError(errores,texto5);
        if(document.datospersonales.email.value.length>100)
            errores = addError(errores,texto6);
        if(document.datospersonales.telefono.value.length>15)
            errores = addError(errores,texto7);
        if(document.datospersonales.direccion.value.length>200)
            errores = addError(errores,texto8);
        if(document.datospersonales.ciudad.value.length>50)
            errores = addError(errores,texto9);
        if(document.datospersonales.pais.value.length>50)
            errores = addError(errores,texto10);
        if(document.datospersonales.codigopostal.value.length>5)
            errores = addError(errores,texto11);
        mostrarErrores(errores,panel_errores);
        if(errores!=""){
            return false;
        }else{
            return true;
        }
    }else{
        return false;
    }
}
function mostrarErrores(errores,id_panel){
    panelError = document.getElementById(id_panel);
    panelError.innerHTML = errores;
}
function addError(errores,mensaje){
    if (errores!=""){
        errores+="<br>";
    }
    errores+=mensaje;
    return errores;
}
function formateaFechaPantalla(fecha){
    var dia = fecha.getDate();
    var mes = fecha.getMonth()+1;
    var anyo = fecha.getFullYear();
    var vfecha = "";
    if(dia<10)
        vfecha+="0"
    vfecha+=dia+"-";
    if(mes<10)
        vfecha+="0"
    vfecha+=mes+"-"+anyo;
    return vfecha;
}