var TamanoLetra= 1;
var TamanoTitulo= 3;

function ValidateString(theField, checkOK)
{
  var checkStr = theField.value;
  var allValid = 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)
  {
	sMsg = "debe poseer caracteres válidos";
    return (false);
  }
  else
  {
    return (true);
  }
}


// valida cadenas vacias 
String.prototype.trim = _String_trim;

function _String_trim(){
 var tstr = this.toString();

 while(tstr.charAt(0) == " ")
 tstr = tstr.substring(1);

 while(tstr.charAt(tstr.length - 1) == " ")
 tstr = tstr.substring(0,tstr.length-2);
 
 return tstr;
}

// valida mail
var sMsg       = ""
var sAlpha     = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- ";
var sAlphaExt  = "ÁÉÍÓÚÑÄËÏÖÜÂÊÎÔÛ áéíóúñäëïöüâêîôû";
var sAlphaMail = "@.-_";
var sNumeric   = "1234567890";
var sDot       = ".";
var sHyphen	   = "-";
var sAlphaOk = "@.-_,:;$!()|?°";

function ValidateEmail(theField){
var checkOK = sAlpha + sNumeric + sAlphaMail;
var checkStr = theField.value;
var allValid = 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)
{
 sMsg = " contiene caracteres inválidos.";
  return (false);
}
else
{
  return (true);
}
}

function popup(url,epi,barra,scroll,w,h) {
	if (url == '/recomendar.asp') {
		url = '/recomendar.asp?nota=' + window.location;
	}
		vent=window.open(url,'Recomendar','screenx=0,screeny=0,toolbar=' + barra + ',width=' + w + ',height='+ h + ',directories=no,status=no,scrollbars=' + scroll + ',resize=no,menubar=no');vent.focus();
}

function valida(datos)
    {
	if(datos.nombre.value=="")
		{
		alert("Ingrese su nombre");
		datos.nombre.focus();
		return false;
		}
	if (datos.apellido.value=="")
		{
		alert("Ingrese su apellido")
		datos.apellido.focus();
		return false;
		}

	if (datos.email.value != "")
	{
		if ((datos.email.value.indexOf(".") == -1) || (datos.email.value.indexOf("@") == -1) )
		{
		alert ("Su dirección de correo es incorrecta");
		datos.email.focus();
		return false
		}
	} else {
		alert ("Su dirección de correo es incorrecta");
		datos.email.focus();
		return false
	}
	return true;

}

function validaRegistro(datos)
    {
    
	if(datos.matricula.value=="")
		{
		alert("Ingrese su número de matricula");
		datos.matricula.focus();
		return false;
		}
	if (ValidateString(datos.matricula, sNumeric)== false) {
        datos.matricula.focus();
        alert("Su número de matrícula contiene caracteres no válidos. Unicamente números.");
        return false;
    } 

	if (datos.dni.value=="")
		{
		alert("Ingrese su número de documento")
		datos.dni.focus();
		return false;
		}

	if (datos.email.value != "")
	{
		if ((datos.email.value.indexOf(".") == -1) || (datos.email.value.indexOf("@") == -1) )
		{
		alert ("Su dirección de correo es incorrecta");
		datos.email.focus();
		return false
		}
	}
    if (datos.npasswd.value.trim() == "") {
         datos.npasswd.focus();
         alert("Por favor ingrese su Clave.");
         return false;
    } 
	  if (ValidateString(datos.npasswd, sAlphaExt+sAlpha+sNumeric)== false) {
           datos.npasswd.focus();
           alert("La Clave ingresada contiene caracteres no válidos.");
           return false;
      } 
    if (datos.rpasswd.value.trim() == "") {
         datos.rpasswd.focus();
         alert("Por favor Reingrese ingrese su Clave.");
         return false;
    } 
	  if (ValidateString(datos.rpasswd, sAlphaExt+sAlpha+sNumeric)== false) {
           datos.rpasswd.focus();
           alert("La Clave ingresada contiene caracteres no válidos.");
           return false;
      } 
    if (datos.rpasswd.value.trim() != datos.npasswd.value.trim()) {
         datos.rpasswd.focus();
         alert("Las Claves ingresadas son distintas.");
         return false;
    } 
	
    if(datos.terminos.checked==false) {
         alert("Debe leer y aceptar lo términos y condiciones.");
         return false;
    }
	

	return true;

}

function validaRegistro2(datos)
    {
    
	if (datos.email.value != "")
	{
		if ((datos.email.value.indexOf(".") == -1) || (datos.email.value.indexOf("@") == -1) )
		{
		alert ("Su dirección de correo es incorrecta");
		datos.email.focus();
		return false
		}
	}

	return true;

}

function validaLogin(datos)
    {
    
	if (datos.usuario.value != "")
	{
		alert ("Ingrese su Número de matrícula.");
		datos.usuario.focus();
		return false
	}
	  if (ValidateString(datos.usuario, sNumeric)== false) {
           datos.usuario.focus();
           alert("La Matrícula ingresada contiene caracteres no válidos, únicamente valores numéricos.");
           return false;
      } 

	if (datos.pass.value != "")
	{
		alert ("Ingrese su Clave.");
		datos.pass.focus();
		return false
	}
	  if (ValidateString(datos.pass, sAlphaExt+sAlpha+sNumeric+sAlphaOk)== false) {
           datos.pass.focus();
           alert("La Clave ingresada contiene caracteres no válidos.");
           return false;
      } 

	return true;

}

function validaRegistroClave(datos)
    {
    
    if (datos.apasswd.value.trim() == "") {
         datos.apasswd.focus();
         alert("Por favor ingrese su Clave Anterior.");
         return false;
    } 
    if (datos.npasswd.value.trim() == "") {
         datos.npasswd.focus();
         alert("Por favor ingrese su Clave.");
         return false;
    } 
	  if (ValidateString(datos.npasswd, sAlphaExt+sAlpha+sNumeric)== false) {
           datos.npasswd.focus();
           alert("La Clave ingresada contiene caracteres no válidos.");
           return false;
      } 
    if (datos.rpasswd.value.trim() == "") {
         datos.rpasswd.focus();
         alert("Por favor Reingrese ingrese su Clave.");
         return false;
    } 
	  if (ValidateString(datos.rpasswd, sAlphaExt+sAlpha+sNumeric)== false) {
           datos.rpasswd.focus();
           alert("La Clave ingresada contiene caracteres no válidos.");
           return false;
      } 
    if (datos.rpasswd.value.trim() != datos.npasswd.value.trim()) {
         datos.rpasswd.focus();
         alert("Las Claves ingresadas son distintas.");
         return false;
    } 
	

	return true;

}

function TamanoTexto(texto){
	aux= TamanoLetra + texto;
	if (aux > 0) {
		if (aux < 5) {
			TamanoTitulo= TamanoTitulo + texto;
			TamanoLetra = TamanoLetra + texto;
			document.getElementById("TextoDesarrollo").size= TamanoLetra;					
			document.getElementById("TextoBajada").size= TamanoLetra;					
			document.getElementById("TextoTitulo").size= TamanoTitulo;					
		}
	}
	
}