var sAlpha     = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var sAlphaExt  = "ÁÉÍÓÚÑÄËÏÖÜÂÊÎÔÛ áéíóúñäëïöüâêîôû '"
var sAlphaTE   = "() -";
var sAlphaMail = "@.-_";
var sSpace     = " ";
var sAt        = "@";
var sDot       = ".";
var sDash      = "/";
var sNumeral   = "#";
var sUnderscore  = "_";
var sNumeric     = "1234567890.";
var sNumericExt  = ".+-/*";
var sEsimo       ="º";    
var sMsg         = "";
var sHyphen		 = "-";
var sComa	= ",";
var sUnder	= "_";

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);
  }
}

function ValidateEmail(theField)
{
  var checkOK = sAlpha + sNumeric + sAlphaExt;
  var checkStr = theField.value;
  var allValid = true;
  var ExisteAt = false;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    if (ch == "@") ExisteAt = true;
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  
  if ((!allValid) || (!ExisteAt))
  {
	sMsg = "es inválido";
    return (false);
  }
  else
  {
    return (true);
  }
}

function ValidateRequired(theField)
{
  if (theField.value == "")
  {
	sMsg = "es obligatorio";
    return (false);
  }
  else
  {
    return (true);
  }
}

function ValidateMayor(theField, mayor)
{
  if (theField.value > mayor)
  {
	sMsg = "debe ser Menor a "+mayor;
    return (false);
  }
  else
  {
    return (true);
  }
}

function ValidateMenor(theField, mayor)
{
  if (theField.value < mayor)
  {
	sMsg = "debe ser Mayor que "+mayor;
    return (false);
  }
  else
  {
    return (true);
  }
}

function ValidateLen(theField, nMinLen, nMaxLen)
{
  var checkStr = theField.value;

  if (checkStr.length < nMinLen)
  {
	sMsg = "debe poseer al menos " + nMinLen + " caracteres";
    return (false);
  }
  else
  {
	  if (checkStr.length > nMaxLen)
	  {
		sMsg = "debe poseer menos de " + nMaxLen + " caracteres";
		return (false);
	  }
	  else
	  {
		return (true);
	  }
  }
}

function IsNumber(theField)
{
  var checkOK = "0123456789";
  var checkStr = theField;
  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)
  {
    return (false);
  }
  else
  {
    return (true);
  }
}

function Comparar_Fecha(Obj1,Obj2) 
{
	String1 = Obj1;
	String2 = Obj2;
	// Si los dias y los meses llegan con un valor menor que 10 
	// Se concatena un 0 a cada valor dentro del string 
		if (String1.substring(1,2)=="/") {
		String1="0"+String1
		}
		if (String1.substring(4,5)=="/"){
		String1=String1.substring(0,3)+"0"+String1.substring(3,9)
		}

		if (String2.substring(1,2)=="/") {
		String2="0"+String2
		}
		if (String2.substring(4,5)=="/"){
		String2=String2.substring(0,3)+"0"+String2.substring(3,9)
		}

	dia1=String1.substring(0,2);
	mes1=String1.substring(3,5);
	anyo1=String1.substring(6,10);
	dia2=String2.substring(0,2);
	mes2=String2.substring(3,5);
	anyo2=String2.substring(6,10);

		if (dia1 == "08") // parseInt("08") == 10 base octogonal
		dia1 = "8";
		if (dia1 == '09') // parseInt("09") == 11 base octogonal
		dia1 = "9";
		if (mes1 == "08") // parseInt("08") == 10 base octogonal
		mes1 = "8";
		if (mes1 == "09") // parseInt("09") == 11 base octogonal
		mes1 = "9";
		if (dia2 == "08") // parseInt("08") == 10 base octogonal
		dia2 = "8";
		if (dia2 == '09') // parseInt("09") == 11 base octogonal
		dia2 = "9";
		if (mes2 == "08") // parseInt("08") == 10 base octogonal
		mes2 = "8";
		if (mes2 == "09") // parseInt("09") == 11 base octogonal
		mes2 = "9";

	dia1=parseInt(dia1);
	dia2=parseInt(dia2);
	mes1=parseInt(mes1);
	mes2=parseInt(mes2);
	anyo1=parseInt(anyo1);
	anyo2=parseInt(anyo2);

		if (anyo1>anyo2)
		{
		return false;
		}

		if ((anyo1==anyo2) && (mes1>mes2))
		{
		return false;
		}
		if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
		{
		return false;
		} 

	return true;
	}

function validarUser(){
if(document.form1.name.value==""){
	alert("Debe informar el usuario");
	document.form1.name.focus();
	}
	else{
		if(document.form1.clave.value==""){
			alert("Debe informar la clave");
			document.form1.clave.focus();
			}
			else
				document.form1.submit()
		}
}

function validarName(){
if(document.form1.name.value==""){
	alert("Debe informar el usuario");
	document.form1.name.focus();
	}
	else
		document.form1.submit()
}
function validarClaves(){
strC=document.form1.clave
strOut=sAlphaExt+sAlphaTE+sAlphaMail+sSpace+sAt+sDot+sNumeral+sUnderscore+sNumericExt+sEsimo+sMsg+sHyphen+sComa+sUnder
if (document.form1.clave.value==""){
	alert("Debe informar su nueva clave");
	document.form1.clave.focus();	
	}	
	else{
		if (document.form1.clave2.value==""){			
			alert("Debe repetir su nueva clave");
			document.form1.clave2.focus();
			}		
			else{
				if(document.form1.clave.value!=document.form1.clave2.value){
					alert("La clave y la confirmación son diferentes")
					}
					else{
						if(ValidateString(strC,strOut)){							
							alert("Ha ingresado caracteres no válidos");
							document.form1.clave.focus();
							}
							else
								document.form1.submit();								
						}
				}
		}
}	
	
function cambiarFoco(f){ 
var f
if (event.keyCode == 13){ 
	switch (f){ 
		case 1: 
			document.form1.clave.focus();
			break; 
		case 2: 
			validarUser(); 
			break; 		
		case 3: 
			document.form1.clave2.focus();
			break; 
		case 4: 
			validarClaves(); 
			break; 

		} 
	} 
} 
function validaPaci(){
switch (document.FrmEditPaci.operacion.value){
	case 'insert':
			if (document.FrmEditPaci.txtNombre.value==""){
				alert("Debe completar el campo nombre");
				document.FrmEditPaci.txtNombre.focus();
				}
				else{
					if (document.FrmEditPaci.txtApellido.value==""){
						alert("Debe completar el campo Apellido");
						document.FrmEditPaci.txtApellido.focus();
						}	
						else{
							if ((document.FrmEditPaci.txtEmail.value.indexOf('@', 0) == -1 || document.FrmEditPaci.txtEmail.value.indexOf('.', 0) == -1)){
								alert("Debe ingresar un e-mail válido");
								document.FrmEditPaci.txtEmail.focus();
								}
								else
									document.FrmEditPaci.submit();
							}
					}
			break;
	case 'update':
			if (document.FrmEditPaci.txtNombre.value==""){
				alert("Debe completar el campo nombre");
				document.FrmEditPaci.txtNombre.focus();
				}
				else{
					if(document.FrmEditPaci.txtUsuario.value==""){
						alert("Debe completar el campo usuario");
						document.FrmEditPaci.txUsuario.focus();
						}
						else{
							if(document.FrmEditPaci.txtPassword.value==""){
								alert("Debe completar el campo password");
								document.FrmEditPaci.txtPassword.focus();
								}
								else{
									if ((document.FrmEditPaci.txtEmail.value.indexOf('@', 0) == -1 || document.FrmEditPaci.txtEmail.value.indexOf('.', 0) == -1)){
										alert("Debe ingresar un e-mail válido");
										document.FrmEditPaci.txtEmail.focus();
										}
										else{
											if (!ValidateDate(document.FrmEditPaci.txtFechaAlta.value)){
												alert("La fecha ingresada no es válida");		
												document.FrmEditPaci.txtFechaAlta.focus();
												}
												else
													document.FrmEditPaci.submit();										
											}								
									}
							}
					}
			break;
		}
		
}
function ValidateDate(f){ 
var f
var dia=(f.substring(0,2));
var mes=(f.substring(3,5));
var anio=(f.substring(6,10));
if (f.length!==10){
	return false;
	}
	else{
		if ((isNaN(dia)) || (isNaN(mes)) || (isNaN(anio))){
			return false;
			}
			else{
				if(dia>31){
					return false;
					}
					else{
						if(mes>12){
							return false;
							}
							else{
								if((anio%4!=0) && (mes==2) && (dia==29)){
									return false;							
									}
									else{
										if((dia==31)&&((mes==2)||(mes==4)||(mes==6)||(mes==9)||(mes==11))){
											return false;
											}									
											else{
												return true;
												}										
										}
								}
						}
				}
		}
}