// Función para validar que le el valor introducido en teléfono sea numérico
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}

function validarinfo(){	
// document.<nombreDelFormulario>.<campoDelFormulario>.value == ...
// DATOS PERSONALES
// NOMBRE
	if (document.infoform.nombre.value == "")
	{alert("Debe escribir su nombre y apellidos")
	   document.infoform.nombre.focus() //pone el cursor del ratón sobre el campo a rellenar
       return 0;}
// tfno.comprueba si se ha introducido algo en el campo tfno y ese valor introducido no es un numero 
	else if(document.infoform.tfno.value == "")
		{alert ("El campo telefono es un campo obligatorio y debe ser rellenado")
		document.infoform.tfno.focus()
       return 0;} 
		
    else if(document.infoform.tfno.value != "" && !IsNumeric(document.infoform.tfno.value))
		{alert ("Debe rellenar el campo telefono correctamente")
		document.infoform.tfno.focus()
       return 0;}  
// EMAIL
    else if(document.infoform.email.value == "")
		{alert ("Debe rellenar el campo email")
		document.infoform.email.focus()
       return 0;}
// SOLICITUD
    else if(document.infoform.solicitud.value == "")
		{alert ("Debe rellenar el campo solicitud")
		document.infoform.solicitud.focus()
       return 0;}

return emailCheck (document.infoform.email.value); //es la última funcion del script, si todo va bien pasará a chequear que la dirección de correo sea válida y enviará por fin el formulario. 
} 

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
/* Finally, let's start trying to figure out if the supplied address is
   valid. */
/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)

if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("El formato de e-mail es incorrecto.");
	document.infoform.email.select();
	return false;
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("El formato de e-mail es incorrecto.");
	document.infoform.email.select();
    return false;
}

if ((domain.indexOf(".com")<1)&&(domain.indexOf(".org")<1)
  &&(domain.indexOf(".biz")<1)&&(domain.indexOf(".net")<1)&&(domain.indexOf(".es")<1)&&(domain.indexOf(".uk")<1)&&(domain.indexOf(".it")<1)
  &&(domain.indexOf(".fr")<1)&&(domain.indexOf(".de")<1)&&(domain.indexOf(".pt")<1)&&(domain.indexOf(".nl")<1)&&(domain.indexOf(".us")<1)&&(domain.indexOf(".ie")<1)
  &&(domain.indexOf(".gi")<1)&&(domain.indexOf(".au")<1)&&(domain.indexOf(".ad")<1)&&(domain.indexOf(".ar")<1)&&(domain.indexOf(".be")<1)&&(domain.indexOf(".mx")<1)
  &&(domain.indexOf(".br")<1)&&(domain.indexOf(".ch")<1)&&(domain.indexOf(".cu")<1)&&(domain.indexOf(".gr")<1)&&(domain.indexOf(".jp")<1)&&(domain.indexOf(".lu")<1)
  &&(domain.indexOf(".ma")<1)&&(domain.indexOf(".ni")<1)&&(domain.indexOf(".pe")<1)&&(domain.indexOf(".ve")<1)&&(domain.indexOf(".yo")<1)){
   alert("La dirección e-mail no es válida."
   +" La dirección e-mail debe contener un sufijo del tipo "
   +".com,.net,.org,.biz o un sufijo de un país.");
   document.infoform.email.select();
   return false;
}

// en caso de que el mail esté correcto SE ENVIAN TODOS LOS DATOS DEL FORMULARIO
    else {
       document.infoform.submit();      
    }
}