﻿
    //--> Función que valida un correo electrónico.
    function isEmailAddress(theElement, nombre_del_elemento, msg)
    {
        var s = theElement.value;
        var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
        if (s.length == 0 ) return true;
        if (filter.test(s)) {
            if(confirm(msg) ) return true;
            return false;
        }
        else
            alert("Ingrese su C. Electrónico válido, verifique    ");
        theElement.focus();
        return false;
    }
    
    function confirmar(msg)
    {
        if(confirm(msg) ) return true;
        return false;
    } 
    
          
////////////////////////////   GENERAL  //////////////////////////////////////////
function ValidarTextBox(TextBox,Campo)
    {
		    if(TextBox.value == '')
		    {
			    alert(Campo);
			    TextBox.focus();
			    return false;
		    }
    }
function ValidarEntero(TextBox,Campo)
{  var valid = "0123456789- ()";
   var ok = "si"
   for(var i=0; i<TextBox.value.length; i++)
     {val = TextBox.value.substring(i, i+1)
      if (valid.indexOf(val) == -1)ok = "no"
     }
      if(ok == "no")
       { alert(Campo); 
         TextBox.focus(); 
         return false;
       }
}
function ValidarLongitud(TextBox,Campo)
{       if(TextBox.value.length < 7 || TextBox.value.length > 11)
		   {
		    if (TextBox.value != '')
		      {
			    alert(Campo);
			    TextBox.focus();
			    return false;
			  }
		   } 
}
	
//////////////////////////////   LOGIN.ASPX    //////////////////////////////////			

   function ValidaIdentificacion()
    {
      if(ValidarTextBox(document.form1.txtNroDoc,"Ingrese el Número del Documento        ")==false)return false;
     if (document.form1.cboTipoLic != null)
      {
      if(document.form1.cboTipoLic.options[document.form1.cboTipoLic.selectedIndex].value=="0"){alert("Escoga el tipo de licencia     ");return false;}
      }
     return true;
    }

    
     
    /*function ValidaCorreo()
    {   
       var filter=/^[A-Za-z][A-Za-z0-9_.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/ ; 
       var emailid=document.form1.txtEmail2Alt.value;
        if (document.form1.txtEmail2Alt != null)
        {
            if(ValidarTextBox(document.form1.txtEmail2Alt,"Ingrese su dirección de email alternativo") == false)
                return false;
            if(filter.test(emailid) == false)
            {
                alert("Ingrese su dirección de email válido, verifique");
                document.form1.txtEmail2Alt.focus(); 
                return false;
            }
         }
         return true;             
     }*/
     
    function  ValidaTelefono()
    {//if(ValidarTextBox(document.form1.txttelf,"Ingrese su número telefonico     ")==false)return false;
        if (document.form1.txttelf !=null)
        {
        if(ValidarEntero(document.form1.txttelf,"Ingrese correctamente su número telefonico     ")==false)return false;
        if(ValidarLongitud(document.form1.txttelf,"Ingrese correctamente su número telefonico     ")==false)return false; 
        }
        return true; 
    }
      
function EnterDinac(pressevent,obj)
{
        var charCode = (pressevent.which)? pressevent.which : (event.keyCode);
        if (charCode ==13 )
        {
		     var btn = document.getElementById(obj);
			 if (btn != null)
				{ //If we find the button click it
						btn.click();
						event.keyCode = 0
			   }
         }
}
   
///////////////////////////////////////////////////////////////////////////////////			

//function Regresartramite1()
//{
//   /*alert("hola");*/
//   window.location.href="frmLogueo.aspx";
//} 

function Agregar() {
	var nMes, estado;

	estado = 0
    for (i = 0; i < document.form1.length; i++)
		if (document.form1.elements[i].type == "text") {
			if (document.form1.elements[i].value != "") {
				estado = 1
			}
		}
		
	if (estado == 0) {
		alert("Debe de ingresar su número de Voucher.")
		return
	}	
	if (document.form1.secuencia.value.length <5) {
		alert("Ingrese correctamente el N° de secuencia.")
		return
	}		
	if (document.form1.dia.value.length <2) {
		alert("Ingrese correctamente el dia de Pago.")
		return
	}		
	if (document.form1.mes.value.length <3) {
		alert("Ingrese correctamente el mes de Pago.")
		return
	}		
	if (document.form1.anio.value.length <4) {
		alert("Ingrese correctamente el año de Pago.")
		return
	}

	estado = 1
	dia = document.form1.dia.value
	mes = document.form1.mes.value
	anio = document.form1.anio.value
	switch (mes){
		case "ENE": nMes = 1; break;
		case "FEB": nMes = 2; break;
		case "MAR": nMes = 3; break;
		case "ABR": nMes = 4; break;
		case "MAY": nMes = 5; break;
		case "JUN": nMes = 6; break;
		case "JUL": nMes = 7; break;
		case "AGO": nMes = 8; break;
		case "SET": nMes = 9; break;
		case "OCT": nMes = 10; break;
		case "NOV": nMes = 11; break;
		case "DIC": nMes = 12; break;
	}		
	if (nMes < 1 || nMes > 12) { 
		estado = 0
	}
	if (dia < 1 || dia > 31) {
		estado = 0	
	}
	if ((nMes==4 || nMes==6 || nMes==9 || nMes==11) && dia==31) {
		estado = 0
	}

	if (nMes == 2) { 
		var isleap = (anio % 4 == 0 && (anio % 100 != 0 || anio % 400 == 0));
		if (dia > 29 || (dia==29 && !isleap)) {
			estado = 0
		}
	}
	
	if (estado == 0) {
		alert("Debe de ingresar una Fecha Válida.")
		return
	}	
	
	if (document.form1.agencia.value.length <4) {
		alert("Ingrese correctamente el Codigo de Agencia.")
		return
	}			
	
    document.form1.action = "verificar_voucher.aspx"
    document.form1.method = "post";
	document.form1.submit()
	
}


