// JavaScript Document


contenido_textarea = ""
num_caracteres_permitidos = 600

function valida_longitud(){
   num_caracteres = document.forms[0].txt_noticia_es.value.length

   if (num_caracteres > num_caracteres_permitidos){
      document.forms[0].txt_noticia_es.value = contenido_textarea
   }else{
      contenido_textarea = document.forms[0].txt_noticia_es.value
   }

   if (num_caracteres >= num_caracteres_permitidos){
      document.forms[0].caracteres_es.style.color="#ff0000";
   }else{
      document.forms[0].caracteres_es.style.color="#000000";
   }

   cuenta()
}
function cuenta(){
   document.forms[0].caracteres_es.value=document.forms[0].txt_noticia_es.value.length
}

 
function validar_form_reservas(){
  
  with(document.form_reservas) {
                 
        if (txt_club.value == ''){
          
              alert("Debes introducir el nombre del Club");
              txt_club.focus();
              txt_club.style.background="#d5f5fc";
              return false;            
        
        }
        
        if (txt_contacto.value == ''){
          
              alert("Debes introducir el nombre de una persona de contacto");
              txt_contacto.focus();
              txt_contacto.style.background="#d5f5fc";
              return false;            
        
        }
        
        if (txt_direccion.value == ''){
                                                
              alert("Debes introducir la direccion");
              txt_direccion.focus();
              txt_direccion.style.background="#d5f5fc";
              return false;            
        
        }
        
        if (txt_ciudad.value == ''){
          
              alert("Debes introducir la ciudad");
              txt_ciudad.focus();
              txt_ciudad.style.background="#d5f5fc";
              return false;            
        
        }
        
        if (txt_pais.value == ''){
          
              alert("Debes introducir el pais");
              txt_pais.focus();
              txt_pais.style.background="#d5f5fc";
              return false;            
        
        }
        
        if (txt_tel.value == ''){
          
              alert("Debes introducir un numero de telefono");
              txt_tel.focus();
              txt_tel.style.background="#d5f5fc";
              return false;            
        
        } 
        
         if (txt_mail.value == ''){
      
          //mensaje de error
          alert("Debes introducir un e-mail");           
          txt_mail.focus();           
          txt_mail.style.background="#d5f5fc";
          
          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_mail.value)==false){
                alert("El e-mail introducido no es correcto");
                txt_mail.focus();
                txt_mail.style.background="#d5f5fc";
                return false;
            }
            
        }
         
  } // fin de with     
  
  return true;
  
}

//**************************************************************

function validar_form_libro(){
  
  with(document.form_libro) {
    
        if (txt_nombre.value == ''){
          
              alert("Debes introducir tu nombre");
              txt_nombre.focus();
              txt_nombre.style.background="#d5f5fc";
              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="#d5f5fc";
                return false;
            }
        }
        
         if (txt_email.value == ''){
      
          //mensaje de error
          alert("Debes introducir tu e-mail");           
          txt_email.focus();           
          txt_email.style.background="#d5f5fc";
          
          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="#d5f5fc";
                return false;
            }
            
        }
         
        if (txt_comentarios.value == ''){
          
          alert("Debes introducir un mensaje");
          txt_comentarios.focus();
          txt_comentarios.style.background="#d5f5fc";
          return false;
          
        }   
        
        if (txt_captcha.value == ''){
                    
            alert("Escriba el codigo de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#d5f5fc";
            return false;
            
        }      
        
        
      
  } // fin de with     
  
  return true;
  
}


//**************************************************************

function validar_form_noticias(){
  
  with(document.frmNoticias) {
    
        if (txt_titulo_es.value == ''){
          
              alert("Debes introducir el titulo de la noticia en castellano");
              txt_titulo_es.focus();
              txt_titulo_es.style.background="#d5f5fc";
              return false;                            
        }
        if (txt_titulo_ca.value == ''){
          
              alert("Debes introducir el titulo de la noticia en catalan");
              txt_titulo_ca.focus();
              txt_titulo_ca.style.background="#d5f5fc";
              return false;                            
        }
        if (txt_titulo_en.value == ''){
          
              alert("Debes introducir el titulo de la noticia en ingles");
              txt_titulo_en.focus();
              txt_titulo_en.style.background="#d5f5fc";
              return false;                            
        }
        
        if (txt_titulo_nl.value == ''){
          
              alert("Debes introducir el titulo de la noticia en holandes");
              txt_titulo_nl.focus();
              txt_titulo_nl.style.background="#d5f5fc";
              return false;                            
        }
        
         if (txt_noticia_es.value == ''){
      
          //mensaje de error
          alert("Debes introducir el cuerpo de la noticia en castellano");           
          txt_noticia_es.focus();           
          txt_noticia_es.style.background="#d5f5fc";
          
          return false;         
        }
        if (txt_noticia_ca.value == ''){
      
          //mensaje de error
          alert("Debes introducir el cuerpo de la noticia en catalan");           
          txt_noticia_ca.focus();           
          txt_noticia_ca.style.background="#d5f5fc";
          
          return false;         
        }
        if (txt_noticia_en.value == ''){
      
          //mensaje de error
          alert("Debes introducir el cuerpo de la noticia en ingles");           
          txt_noticia_en.focus();           
          txt_noticia_en.style.background="#d5f5fc";
          
          return false;         
        }
        
        if (txt_noticia_nl.value == ''){
      
          //mensaje de error
          alert("Debes introducir el cuerpo de la noticia en holandes");           
          txt_noticia_nl.focus();           
          txt_noticia_nl.style.background="#d5f5fc";
          
          return false;         
        }
        
        if (txt_captcha.value == ''){
                    
            alert("Escriba el codigo de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#d5f5fc";
            return false;
            
        }   
        
  } // fin de with     
  
  return true;
  
}
   
function cambiarIdioma()
{     
    str = agent.call('','agent__cambiarIdioma', '', document.getElementById('comboIdioma').value);    
    window.open("./index.php", "_self"); 
}

//VALIDACION DEL LOGIN
function login()
{
    with(document.frm_login){
        
        //si la caja del usuario esta en blanco..
        if (txt_login.value == ''){
      
          //mensaje de error
          alert("Debes introducir un nombre de usuario");
          
          //ponemos el cursor en la caja de 
          
          txt_login.focus();
          
          //coloreamos de un color la caja en la que está el error
          txt_login.style.background="#d5f5fc";
          
          //devolvemos "false" para que no haga submit hasta que se solucione el error
          return false;
          
        }
                
        if (txt_password.value == ''){
          
          alert("S'ha d'introduir un password");
          txt_password.focus();
          txt_password.style.background="#d5f5fc";
          return false;
          
        }
        
        //pasa por validación.php
         action="./validacion.php";
         
        //una vez validado ya puede seguir hacia adelante con el submit 
        submit();
    }
    
}