// JavaScript Document



//**************************************************************

//VALIDAR NEWS_LETTER

function validar_news_letter(){
  
  with(document.frm_news_letter) {
    
        if (txt_news_letter.value == ''){
          
              alert("Debes introducir un e-mail");
              txt_news_letter.focus();
              txt_news_letter.style.background="#FFF2F2";
              return false;
          
        }else{
                patron = /^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
                if (patron.test(txt_news_letter.value)==false){
                    alert("El e-mail introducido no es correcto");
                    txt_news_letter.focus();
                    txt_news_letter.style.background="#FFF2F2";
                    return false;
                }
            
        }         
      
  } // fin de with     
  
  return true;
  
}

//**************************************************************
 

 //VALIDAR form libro

function validar_form_libro(){
  
  with(document.form_libro) {
    
        if (txt_nombre.value == ''){
          
              alert("Debes introducir tu nombre");
              txt_nombre.focus();
              txt_nombre.style.background="#FFF2F2";
              return false;            
        
        }else{              
            patron_nombre = /[A-Za-z]/;
            if (patron_nombre.test(txt_nombre.value)==false){
                alert("El formato del nombre es incorrecto");
                txt_nombre.focus();
                txt_nombre.style.background="#FFF2F2";
                return false;
            }
        }
        
         if (txt_email.value == ''){
      
          //mensaje de error
          alert("Debes introducir tu e-mail");           
          txt_email.focus();           
          txt_email.style.background="#FFF2F2";
          
          return false;
          
        }else{
            patron = /^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
            if (patron.test(txt_email.value)==false){
                alert("El e-mail introducido no es correcto");
                txt_email.focus();
                txt_email.style.background="#FFF2F2";
                return false;
            }
            
        }
                
        if (lst_valoracion.value == '0'){
          
          alert("Debes seleccionar una puntuación");
          lst_valoracion.focus();
          lst_valoracion.style.background="#FFF2F2";
          return false;
          
        }
        
        if (txt_comentarios.value == ''){
          
          alert("Debes introducir algún comentario");
          txt_comentarios.focus();
          txt_comentarios.style.background="#FFF2F2";
          return false;
          
        }   
        
        if (txt_captcha.value == ''){
                    
            alert("Escriba el código de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#92ADDA";
            return false;
            
        }      
        
        
      
  } // fin de with     
  
  return true;
  
}

//**************************************************************



function validar_recogida_aeropuerto(){
    
    with(document.frm_recogida_aeropuerto) {
        
        if (txt_nombre.value == ''){
            
            alert("Debes ingresar el nombre");
            txt_nombre.focus();
            txt_nombre.style.background="#FFF2F2";
            return false;
            
        }
        
        if (txt_apellido.value == ''){
            
            alert("Debes ingresar el apellido");
            txt_apellido.focus();
            txt_apellido.style.background="#FFF2F2";
            return false;
            
        }
        
        if (txt_email.value == ''){
            
            alert("Debes ingresar el e-mail");
            txt_email.focus();
            txt_email.style.background="#FFF2F2";
            return false;
            
        }else{
            patron = /^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
            if (patron.test(txt_email.value)==false){
                alert("El e-mail introducido es incorrecto");
                txt_email.focus();
                txt_email.style.background="#FFF2F2";
                return false;
            }
            
        }/**/
        
    
        if (lst_aeropuerto.value == '0'){
            alert("Debes seleccionar un aeropuerto");
            lst_aeropuerto.focus();
            lst_aeropuerto.style.background="#FFF2F2";
            return false;
            
        }
            
        if (txt_vuelo.value == ''){
            
            alert("Debes ingresar el vuelo");
            txt_vuelo.focus();
            txt_vuelo.style.background="#FFF2F2";
            return false;
            
        }
        
        //validacion de la fecha
        if (txt_dia.value == ''){
            
            alert("Debes ingresar un dia correcto");
            txt_dia.focus();
            txt_dia.style.background="#FFF2F2";
            return false;
            
        }else{
            patron = /^(0?[1-9]|1[0-9]|2|2[0-9]|3[0-1])$/;
            if (patron.test(txt_dia.value)==false){
                alert("El dia introducido es incorrecto");
                txt_dia.focus();
                txt_dia.style.background="#FFF2F2";
                return false;
            }
            
        }
        
        if (txt_mes.value == ''){
            
            alert("Debes ingresar un mes correcto");
            txt_mes.focus();
            txt_mes.style.background="#FFF2F2";
            return false;
            
        }else{
            patron = /^(0?[1-9]|1[0-2])$/;
            if (patron.test(txt_mes.value)==false){
                alert("El mes introducido es incorrecto");
                txt_mes.focus();
                txt_mes.style.background="#FFF2F2";
                return false;
            }
            
        }
        
        if (txt_anyo.value == ''){
            
            alert("Debes ingresar un año correcto");
            txt_anyo.focus();
            txt_anyo.style.background="#FFF2F2";
            return false;
            
        }else{
            patron = /^(20[0-9][0-9])$/;
            if (patron.test(txt_anyo.value)==false){
                alert("El año introducido es incorrecto");
                txt_anyo.focus();
                txt_anyo.style.background="#FFF2F2";
                return false;
            }
            
        }
        
        //fin de validación de la fecha
        
        if (txt_hora_llegada.value == ''){
            
            alert("Debes ingresar una hora de llegada");
            txt_hora_llegada.focus();
            txt_hora_llegada.style.background="#FFF2F2";
            return false;
            
        }else{
        //    patron2=/^(0[1-9]|1\d|2[0-3]):([0-5]\d):([0-5]\d)$/; <<-- patron con segundos incluidos
            patron=/^(0[1-9]|1\d|2[0-3]):([0-5]\d)$/;
            if (patron.test(txt_hora_llegada.value)==false){
                alert("La hora introducida es incorrecta");
                txt_hora_llegada.focus();
                txt_hora_llegada.style.background="#FFF2F2";
                return false;
            }
        }
        
        if (txt_adultos.value == ''){
            
            alert("Debes ingresar un número de adultos");
            txt_adultos.focus();
            txt_adultos.style.background="#FFF2F2";
            return false;
            
        }
        
        if (txt_ninyos.value == ''){
            
            alert("Debes ingresar un número de niños");
            txt_ninyos.focus();
            txt_ninyos.style.background="#FFF2F2";
            return false;
            
        }
        
        if (chk_transporte_privado.checked==false && chk_transporte_colectivo.checked==false){
            alert("Debes seleccionar una opción");
            chk_transporte_privado.focus();
            chk_transporte_colectivo.focus();
            chk_transporte_privado.style.background="#FFF2F2";
            chk_transporte_colectivo.style.background="#FFF2F2";
            return false;
        }
        
        
//        action="formulario2_enviar.php";
//        submit();

    
    } // fin de with
    return true;
    
} //fin de validación d recogida de aeropuerto


function cambia_idioma()
{
    with (document.frm_idioma)
    {
        submit();
    }
}