
function ValidaMes() {
  
  var d, m, a, md;
  
  d = Registro2.Dia.selectedIndex + 1;
  m = Registro2.Mes.selectedIndex + 1;
  a = Registro2.Ano.selectedIndex + 1;
  
  md = ChkDiaMes(d, m, a);
  
  if (md > 0 && a != 1) {
    alert("Fecha incorrecta !");
    Registro2.Dia.selectedIndex = md - 1;
    Registro2.Dia.focus;
    return false;
  	
  }
  else
    return true;
    
}

function ChkDiaMes(dia, mes, ano) {
  
  var am4 = false, am100 = false, am1k = false;
  
  ano += 1929;
  
  if ((ano/4) == parseInt(ano/4))
    am4 = true;
    
  if ((ano / 100) == parseInt(ano / 100))
    am100 = true;
  
  if ((ano / 1000) == parseInt(ano / 1000))
    am1k = true;
  
  switch (mes) {
    case 4:
    case 6:
    case 9:
    case 11:
      if (dia > 30)
        return 30;
      
      break;
    
    case 2:
      if ((am4 && !am100) || am1k) {
        if (dia > 29) 
          return 29;
      }
      else
        if (dia > 28)
          return 28;
      
      break;
  }
  
  return 0;
  
}

function IsValidNumber(astrNumero) {
  
  var lfstrCheckOK = "0123456789";
  var lfstrValueCheck;
  var i;
  var lfstrChar;
  
  lfstrValueCheck = astrNumero.value;
  
  for (i = 0; i < lfstrValueCheck.length; i++) {
    lfstrChar = lfstrValueCheck.charAt(i);
    if (lfstrCheckOK.indexOf(lfstrChar,0) == -1)
      return false;
  
  }
  
  return true;
  
}

function IsValidText(astrText) {
  
  var lfstrCheckOK = "@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-. !?¿¡_,";
  var lfstrValueCheck;
  var i;
  var lfstrChar;
  
  lfstrValueCheck = astrText.value;
  for (i = 0; i < lfstrValueCheck.length; i++) {
    lfstrChar = lfstrValueCheck.charAt(i);
    if (lfstrCheckOK.indexOf(lfstrChar,0) == -1)
      return false;
  }
  
  return true;
  
}

function IsValidTextArea(astrText) {
  
  var lfstrCheckOK = "@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789-. !?¿¡\n\r_";
  var lfstrValueCheck;
  var i;
  var lfstrChar;
  
  lfstrValueCheck = astrText.value;
  for (i = 0;  i < lfstrValueCheck.length;  i++) {
    lfstrChar = lfstrValueCheck.charAt(i);
    if (lfstrCheckOK.indexOf(lfstrChar,0) == -1)
      return false;
  
  }
  
  return true;
  
}


function IsValidEmail(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function IsValidEmail0(email) { 
  if (email.length == 0) 
    return false; 
  
  var x = email.value;
   
  var filter  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
  
  if (filter.test(x)) 
    return true; 
  else 
    return false; 
} 


function IsValidEmail1(email)
{
	var x = email.value;
	// var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var filter  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
	if (filter.test(x))
	  return true;
	else 
	  return false;
}


function gralKeyPress(eventObject) {
  
  if (eventObject.keyCode == 13) {
    eventObject.returnValue = false;
 
  }
  
  return true;
  
}



function creditcard_validator(theForm)
{
  if (theForm.MEDIODEPAGO.selectedIndex == 0)
  {
    alert("Elija una de las tarjetas de crédito.");
    theForm.MEDIODEPAGO.focus();
    return (false);
  }	  

  if (theForm.cuotas.selectedIndex == 0)
  {
    alert("Elija la cantidad de cuotas.");
    theForm.cuotas.focus();
    return (false);
  }	  
	  
  return (true);  

}




function Login_validator(theForm)
{

  if (theForm.UserID.value == "")
  {  
    alert("El casillero de \"E-Mail\" no puede estar vacío.");
    theForm.UserID.focus();
    return (false);
  }
   
  if (IsValidEmail(theForm.UserID.value)== false) 
  {
    alert("La direccion de mail ingresada no es correcta");
    theForm.UserID.focus();
    return false;
  }

  if (theForm.UserID.value.length < 7)
  {
    alert("Escriba por lo menos 7 caracteres en el campo \"E-mail\".");
    theForm.UserID.focus();
    return (false);
  }

  if (theForm.UserID.value.length > 50)
  {
    alert("Escriba como máximo 50 caracteres en el campo \"E-mail\".");
    theForm.UserID.focus();
    return (false);
  }

  if (theForm.UserPWD.value == "")
  {
    alert("Escriba un valor para el campo \"Contrseña\".");
    theForm.UserPWD.focus();
    return (false);
  }

  if (theForm.UserPWD.value.length < 1)
  {
    alert("Escriba por lo menos 4 caracteres en el campo \"Contraseña\".");
    theForm.UserPWD.focus();
    return (false);
  }

  if (!IsValidText(theForm.UserPWD)) 
  {
    alert("Escriba sólo letras y dígitos en el campo \"Contrseña\".");
    theForm.UserPWD.focus();
    return (false);
  }
  return (true);
}


function SetInit() {
  document.LoginChk.UserID.focus();
  return true;
}


function SignUp_validator(theForm)
{

  if (theForm.UserID2.value == "")
  {  
    alert("El casillero de \"E-Mail\" no puede estar vacío.");
    theForm.UserID2.focus();
    return (false);
  }
   
  if (IsValidEmail(theForm.UserID2.value)== false) 
  {
    alert("La direccion de mail ingresada no es correcta");
    theForm.UserID2.focus();
    return (false);
  }

  if (theForm.UserID2.value.length < 7)
  {
    alert("Escriba por lo menos 7 caracteres en el campo \"E-mail\".");
    theForm.UserID2.focus();
    return (false);
  }

  if (theForm.UserID2.value.length > 50)
  {
    alert("Escriba como máximo 50 caracteres en el campo \"E-mail\".");
    theForm.UserID2.focus();
    return (false);
  }

  if (!IsValidText(theForm.UserID2)) 
  {
    alert("Escriba sólo letras y dígitos en el campo \"E-mail\".");
    theForm.UserID2.focus();
    return (false);
  }

  if (theForm.UserPWD1.value == "")
  {
    alert("Escriba un valor para el campo \"Contraseña\".");
    theForm.UserPWD1.focus();
    return (false);
  }

  if (theForm.UserPWD1.value.length < 4)
  {
    alert("Escriba por lo menos 4 caracteres en el campo \"Contraseña\".");
    theForm.UserPWD1.focus();
    return (false);
  }

  if (theForm.UserPWD1.value.length > 20)
  {
    alert("Escriba como máximo 20 caracteres en el campo \"Contraseña\".");
    theForm.UserPWD1.focus();
    return (false);
  }

  if (!IsValidText(theForm.UserPWD1))
  {
    alert("Escriba sólo letras y dígitos en el campo \"Contraseña\".");
    theForm.UserPWD1.focus();
    return (false);
  }

  if (theForm.UserPWD2.value == "")
  {
    alert("Escriba un valor para el campo \"Confirmación de Contraseña\".");
    theForm.UserPWD2.focus();
    return (false);
  }

  if (theForm.UserPWD2.value.length < 4)
  {
    alert("Escriba por lo menos 4 caracteres en el campo \"Confirmación de Contraseña\".");
    theForm.UserPWD2.focus();
    return (false);
  }

  if (theForm.UserPWD2.value.length > 20)
  {
    alert("Escriba como máximo 20 caracteres en el campo \"Confirmación de Contraseña\".");
    theForm.UserPWD2.focus();
    return (false);
  }

  if (!IsValidText(theForm.UserPWD2)) 
  {
    alert("Escriba sólo letras y dígitos en el campo \"Confirmación de Contraseña\".");
    theForm.UserPWD2.focus();
    return (false);
  }
  
  if (theForm.UserPWD1.value != theForm.UserPWD2.value) {
    alert("Las Claves de acceso que ingresó no coinciden !");
    theForm.UserPWD1.value = "";
    theForm.UserPWD2.value = "";
    theForm.UserPWD1.focus();
    return false;
  }
  else
  {
    if (theForm.UserPWD1.length < 4) {
      alert("La Clave de acceso que ingresó tiene que tener al menos 4 caractéres");
      theForm.UserPWD1.value = "";
      theForm.UserPWD2.value = "";
      theForm.UserPWD1.focus();
      return false;
    }
  }
  return (true);
  
}


function ID_validator(theForm)
{

  if (theForm.UserID.value == "")
  {  
    alert("El casillero de \"E-Mail\" no puede estar vacío.");
    theForm.UserID.focus();
    return (false);
  }
   
  if (IsValidEmail(theForm.UserID.value)== false) 
  {
    alert("La direccion de mail ingresada no es correcta");
    theForm.UserID.focus();
    return (false);
  }

  if (theForm.UserID.value.length < 7)
  {
    alert("Escriba por lo menos 7 caracteres en el campo \"E-mail\".");
    theForm.UserID.focus();
    return (false);
  }

  if (theForm.UserID.value.length > 50)
  {
    alert("Escriba como máximo 50 caracteres en el campo \"E-mail\".");
    theForm.UserID.focus();
    return (false);
  }

  if (!IsValidText(theForm.UserID)) 
  {
    alert("Escriba sólo letras y dígitos en el campo \"E-mail\".");
    theForm.UserID.focus();
    return (false);
  }

  return (true);
  
}
