// Validación del formulario de contacto    
function validaFormContacta (idioma){
            
   //variables necesarias y cogemos los valores
   var nombre = document.getElementById('nombre').value;
   var telefono = document.getElementById('telefono').value;
   var email = document.getElementById('mail').value;
   var apell = document.getElementById('apell').value;
   var comentario = document.getElementById('consulta').value;
   var re = new RegExp (/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/);
   var men1, men2, men3;
   
   //mensajes
   switch(idioma)
   {
     case "1":
        men1 = 'Debes completar los campos: nombre, apellidos, email y consulta para poder ponernos en contacto contigo.';
        men2 = 'El campo no tiene la longitud adecuada';
        men3 = 'El email no parece correcto. Debe tener el siguiente formato: xxx@yyyyy.zzz';
        break;    
      
    case "2":
        men1 = 'All fields marked with an asterisk (*) are required (first name, last name, email and query)';
        men2 = 'Please, check the length of this field';
        men3 = 'Please, check that you have entered a valid email (xxx@yyyyy.zzz)';
        break;
      
    default:
        men1 = 'Debes completar los campos: nombre, apellidos, email y consulta para poder ponernos en contacto contigo.';
        men2 = 'El campo no tiene la longitud adecuada';
        men3 = 'El email no parece correcto. Debe tener el siguiente formato: xxx@yyyyy.zzz';
    }
   
            
   //Obligatorios: nombre, apellidos, comentario; todos
   //Obligatorios: telefono o mail; alguno de los dos por lo menos, para poder ponerse en contacto
			
			
   if ((apell == '') ||(nombre == '') || email=='' || comentario == '' ) {
       alert (men1);
       
       
       if (nombre == '') document.getElementById('nombre').focus();
       else
         if (apell == '') document.getElementById('apell').focus();
         else
            if (email == '') document.getElementById('mail').focus(); 
            else
               if (comentario == '') document.getElementById('consulta').focus();
       
       return false;
   }
   
   else {
			
      if (nombre.length <1 || nombre.length > 150){
         alert(men2)
         document.getElementById('nombre').focus();
         document.getElementById('nombre').select();
         return false;         
      }
				
      else 
         if(apell.length <1 || apell.length > 250){
            alert(men2);
            document.getElementById('apell').focus();
            document.getElementById('apell').select();
            return false;                     
         }
				
         else 
            if(telefono.length > 25){
               alert(men3);
               document.getElementById('telefono').focus();
               document.getElementById('telefono').select();
               return false;                        
            }
				
            else 
               if (email.length <1 || email.length > 150){
                  alert(men2);
                  document.getElementById('mail').focus();
                  document.getElementById('mail').select();
                  return false;                           
               }
				
               else 
                  if (!email.match(re)){
                    alert(men3);
                    document.getElementById('mail').focus();
                    document.getElementById('mail').select();
                    return false;                             
                  }
				
                  else 
                     if(comentario.length <1){
                        alert(men2);
                        document.getElementById('consulta').focus();
                        return false;                                 
                     }
				
   }

   return true;
            
}
        

