// JavaScript Document
 function Letras(campo, nombre)
 {
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Sólo se aceptan letras en el campo "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);
 }

function Letras_Espacios(campo, nombre)
 {
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Sólo se aceptan letras y espacios en blanco en el campo "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);
 }


function Letras_Numeros(campo, nombre)
 {
    var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Sólo se aceptan letras y números sin espacios "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);
 }

function Letras_Numeros_Espacios(campo, nombre)
 {
    var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Sólo se aceptan letras, espacios en blanco y números en el campo "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);
 }
function Numeros(campo, nombre)
 {
    var checkOK = "0123456789";
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("Sólo se aceptan NÚMEROS para "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);
 }

function Long_Min(campo, nombre, cantidad)
 {
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	  if (checkStr.length < cantidad)
	  {
	    alert("Debes escribir al menos "+cantidad+" letras en "+nombre.toUpperCase()+".");
	    return (false);
	  }
	return(true);
 }

function Long_Max(campo, nombre, cantidad)
 {
    var checkStr = campo;	
    var allValid = true;
    var validGroups = true;
  	  if (checkStr.length > cantidad)
	  {
	    alert("No puedes escribir mas de "+cantidad+" caracteres en "+nombre.toUpperCase()+".");
	    return (false);
	  }
	  return(true);

 }

function requerido(campo, nombre)
 {
      if (campo == "")
	 {
	  alert("El campo " + nombre.toUpperCase()+ " es OBLIGATORIO!.");
	  return (false);
	}
	return(true);
 }
 
 
//////////////////contacto 
 function validacion_comentario(theForm){
  
  if (!requerido(theForm.Nombre.value, "Nombre")) {
    theForm.Nombre.focus();
    return (false);
  }   
  if (!Letras_Espacios(theForm.Nombre.value, "Nombre")){
    theForm.Nombre.focus();
    return (false);
  }
     if (!requerido(theForm.empresa.value, "empresa"))  {
    theForm.empresa.focus();
    return (false);
  }
     if (!requerido(theForm.telefono.value, "telefono"))  {
    theForm.telefono.focus();
    return (false);
  }
       if (!Numeros (theForm.telefono.value, "telefono"))  {
    theForm.telefono.focus();
    return (false);
  }
      if (!Long_Min (theForm.telefono.value, "telefono",6))  {
    theForm.telefono.focus();
    return (false);
  }
  
  
    if (!requerido(theForm.email.value, "email"))  {
    theForm.email.focus();
    return (false);
  }
    if (theForm.email.value.indexOf('@', 0) == -1 || theForm.email.value.indexOf('.', 0) == -1){
  alert("Dirección de e-mail inválida"); theForm.email.focus(); 
  return (false); 
  } 
  if (!requerido(theForm.comentario.value, "Comentario"))  {
     theForm.comentario.focus();
    return (false);
  } 
//   if (!Numeros(theForm.email.value, "telefono"))  {
//    theForm.email.focus();
//    return (false);
//  }
	return(true);
 }
 
 ////////////////////// registro
 function validacion(theForm){
  
  if (!requerido(theForm.Nombre1.value, "Nombre")) {
    theForm.Nombre1.focus();
    return (false);
  }   
  if (!Letras_Espacios(theForm.Nombre1.value, "Nombre")){
    theForm.Nombre1.focus();
    return (false);
  }
    if (!requerido(theForm.Apellido1.value, "Apellido")) {
    theForm.Apellido1.focus();
    return (false);
  }   
  if (!Letras_Espacios(theForm.Apellido1.value, "Apellido")){
    theForm.Apellido1.focus();
    return (false);
  }
    if (!requerido(theForm.email.value, "email"))  {
    theForm.email.focus();
    return (false);
  }

    if (!Long_Min(theForm.email.value, "email", 10))  {
    theForm.email.focus();
    return (false);
  }
      if (theForm.email.value.indexOf('@', 0) == -1 || theForm.email.value.indexOf('.', 0) == -1){
  alert("Dirección de e-mail inválida"); theForm.email.focus(); 
  return (false); 
  } 
  if (!requerido(theForm.nick.value, "Nickname"))  {
    theForm.nick.focus();
    return (false);
  }

  if (!requerido(theForm.pass.value, "Password"))  {
    theForm.pass.focus();
    return (false);
  }
   if (!Letras_Numeros(theForm.pass.value, "Password")){
   alert("No puedes poner espacios en la contraseña");
    theForm.pass.focus();
    return (false);
  }	
    if(theForm.ido.checked != true){
    
    alert("Debes ACEPTAR nuestros TÉRMINOS y CONDICIONES!");
    theForm.ido.focus();
    return (false);
    }

return(true);
 }
