// JavaScript Document

$(document).ready(function(){ $("#navmenu-h li,#navmenu-v li").hover( function() { $(this).addClass("iehover"); }, function() { $(this).removeClass("iehover"); } ); });

//*********************************
function call_actualizaEstado(idMsg)
{    //alert(idMsg)    
    document.getElementById('divLoading').innerHTML = '<font color="#f5faf4">Actualizando...';
    agent.call('', 'actualizaEstado', 'callback_actualizaEstado', idMsg);
}        
function callback_actualizaEstado(str)
{               
    //alert(str);
    document.getElementById('divLoading').innerHTML = '';
    aValores = str.split('|');
    if(aValores[0]==='false')
    {
        alert(aValores[1]);
    }    
} 

//*************************************

function actualizaEstadoPublicar(idHome)
{    //alert(idHome)    
    document.getElementById('divLoading').innerHTML = '<font color="#f5faf4">Actualizando...';
    agent.call('', 'actualizaEstadoPublicar', 'callback_actualizaEstadoPublicar', idHome);
}        
function callback_actualizaEstadoPublicar(str)
{               
    //alert(str);
    document.getElementById('divLoading').innerHTML = '';
    aValores = str.split('|');
    if(aValores[0]==='false')
    {
        alert(aValores[1]);
    }    
}

function cambiarIdioma()
{   
    with (document.frm_idioma)
    {
        submit();
    }
}

function validar_form_libro(){
  
  with(document.form_libro) {
    
        if (txt_nombre.value == ''){
          
              alert("Debes introducir tu nombre");
              txt_nombre.focus();
              txt_nombre.style.background="#dbe8d8";
              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="#dbe8d8";
                return false;
            }
        }
        
         if (txt_email.value == ''){
      
          //mensaje de error
          alert("Debes introducir tu e-mail");           
          txt_email.focus();           
          txt_email.style.background="#dbe8d8";
          
          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="#dbe8d8";
                return false;
            }
            
        }
        
        if (lst_valoracion.value == '0'){
          
          alert("Debes seleccionar tu valoracion");
          lst_valoracion.focus();
          lst_valoracion.style.background="#dbe8d8";
          return false;
          
        }
         
        if (txt_comentarios.value == ''){
          
          alert("Debes introducir un mensaje");
          txt_comentarios.focus();
          txt_comentarios.style.background="#dbe8d8";
          return false;
          
        }   
        
        if (txt_captcha.value == ''){
                    
            alert("Escriba el codigo de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#dbe8d8";
            return false;
            
        }      
        
        
      
  } // fin de with     
  
  return true;
  
}

//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="#dbe8d8";
              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="#dbe8d8";
                    return false;
                }
            
        }         
      
  } // fin de with     
  
  return true;
  
}

function validar_form_contacto(){
  
  with(document.formContacto) {
    
        if (txtNombre.value == ''){
          
              alert("Debes introducir tu nombre");
              txtNombre.focus();
              txtNombre.style.background="#dbe8d8";
              return false;            
        
        }else{              
            patron_nombre = /[A-Za-z]/;
            if (patron_nombre.test(txtNombre.value)==false){
                alert("El formato del nombre es incorrecto");
                txtNombre.focus();
                txtNombre.style.background="#dbe8d8";
                return false;
            }
        }
        
        if (txtApellidos.value == ''){
          
              alert("Debes introducir tus apellidos");
              txtApellidos.focus();
              txtApellidos.style.background="#dbe8d8";
              return false;            
        
        }else{              
            patron_nombre = /[A-Za-z]/;
            if (patron_nombre.test(txtApellidos.value)==false){
                alert("El formato de los apellidos es incorrecto");
                txtApellidos.focus();
                txtApellidos.style.background="#dbe8d8";
                return false;
            }
        }
                
        if (txtTelefono.value == ''){
          
              alert("Debes introducir un telefono de contacto");
              txtTelefono.focus();
              txtTelefono.style.background="#dbe8d8";
              return false;            
        
        }else{              
            patron_tel = /[0-9]/;
            if (patron_tel.test(txtTelefono.value)==false){
                alert("El formato del telefono es incorrecto");
                txtTelefono.focus();
                txtTelefono.style.background="#dbe8d8";
                return false;
            }
        }
        
         if (txtEmail.value == ''){
      
          //mensaje de error
          alert("Debes introducir tu e-mail");           
          txtEmail.focus();           
          txtEmail.style.background="#dbe8d8";
          
          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(txtEmail.value)==false){
                alert("El e-mail introducido no es correcto");
                txtEmail.focus();
                txtEmail.style.background="#dbe8d8";
                return false;
            }
            
        }
        
        if (txt_captcha.value == ''){
                    
            alert("Escriba el codigo de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#dbe8d8";
            return false;
            
        }      
        
        
      
  } // fin de with     
  
  return true;
  
}

//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="#dbe8d8";
          
          //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="#dbe8d8";
          return false;
          
        }
        
        //pasa por validación.php
         action="./validacion.php";
         
        //una vez validado ya puede seguir hacia adelante con el submit 
        submit();
    }
    
}

function validar_form_home(){
  
  with(document.frmHome) {
        
        if (txt_titulo_es.value == ''){
          
              alert("Debes introducir el titulo en castellano");
              txt_titulo_es.focus();
              txt_titulo_es.style.background="#dbe8d8";
              return false;                            
        }
        if (txt_titulo_ca.value == ''){
          
              alert("Debes introducir el titulo en catalan");
              txt_titulo_ca.focus();
              txt_titulo_ca.style.background="#dbe8d8";
              return false;                            
        }
        if (txt_titulo_en.value == ''){
          
              alert("Debes introducir el titulo en ingles");
              txt_titulo_en.focus();
              txt_titulo_en.style.background="#dbe8d8";
              return false;                            
        }
        if (txt_titulo_fr.value == ''){
          
              alert("Debes introducir el titulo en frances");
              txt_titulo_fr.focus();
              txt_titulo_fr.style.background="#dbe8d8";
              return false;                            
        }
        
        if (FCKeditor_es.value == ''){
          
              alert("Debes introducir la descripcion en castellano");
              FCKeditor_es.focus();
              FCKeditor_es.style.background="#dbe8d8";
              return false;                            
        }
        
        if (FCKeditor_ca.value == ''){
          
              alert("Debes introducir la descripcion en catalan");
              FCKeditor_ca.focus();
              FCKeditor_ca.style.background="#dbe8d8";
              return false;                            
        }
        
        if (FCKeditor_en.value == ''){
          
              alert("Debes introducir la descripcion en ingles");
              FCKeditor_en.focus();
              FCKeditor_en.style.background="#dbe8d8";
              return false;                            
        }
        
        if (FCKeditor_fr.value == ''){
          
              alert("Debes introducir la descripcion en frances");
              FCKeditor_fr.focus();
              FCKeditor_fr.style.background="#dbe8d8";
              return false;                            
        } 
        if (txt_captcha.value == ''){
                    
            alert("Escriba el codigo de seguridad");
            txt_captcha.focus();
            txt_captcha.style.background="#dbe8d8";
            return false;
            
        }        
        
  } // fin de with     
  
  return true;
  
}


