//    var RelojID12 = null;
//    var RelojEjecutandose12 = false;

//    var FormActual = document.forms['aspnetForm'];
//    if (!FormActual) {
//       FormActual = document.aspnetForm;
//    }
                
    var celda_ant; 
    celda_ant=""; 
    
    var color_tabant; 
    color_tabant=""; 
    
    var cuenta=0;
    
    //setInterval("MsgAlert()",1000);
    //setInterval("MostrarReloj24()",1000);

   function RedireccionarPagina(pagina) 
    {
        location.href=pagina;
    } 
    
    function CerrarVentanaActiva(){
        /*window.close("_parent")*/
        var ventana = window.self;
        ventana.opener = window.self;
        ventana.close();
    }
    
    function HandleOnClose() {
        if (event.clientY < 0) {
           event.returnValue = '¿Desea cerrar el sistema? Debe hacerlo a través del Menú “Módulos – Salir”';
        }
    }
    
    function ConvertirTextoAMayuscula(object){
	    object.value = object.value.toUpperCase();
    }

    function ConvertirTextoAMinuscula(object){
	    object.value = object.value.toLowerCase();
    }

    function EsLetraMayuscula(){
	    var tepuesok = true;
	    if ((window.event.keyCode < 65) || (window.event.keyCode > 90))
	    {
		    if (!(window.event.keyCode == 209 || window.event.keyCode == 32 || window.event.keyCode == 13))
		    {
			    tepuesok = false;
		    }
	    }
	    return(tepuesok)
    }

    function EsLetraMinuscula(){
	    var tepuesok = true;
	    if ((window.event.keyCode < 97) || (window.event.keyCode > 122))
	    {
		    if (!(window.event.keyCode == 241 || window.event.keyCode == 32 || window.event.keyCode == 13))
		    {
			    tepuesok = false;
		    }
	    }
	    return(tepuesok)
    }

    function EsNumero(){
	    var tepuesok = true;
	    if ((window.event.keyCode < 48) || (window.event.keyCode > 57))
	    {
	        /*tepuesok = false;*/
	        if (!(window.event.keyCode == 241 || window.event.keyCode == 32 || window.event.keyCode == 13))
		    {
			    tepuesok = false;
		    }
	    }
	    return(tepuesok)
    }

    function EsOperadorNumerico(){
	    var tepuesok = true;
	    if ((window.event.keyCode < 42) || (window.event.keyCode > 47))
	    {
		    /*tepuesok = false;*/
		    if (!(window.event.keyCode == 241 || window.event.keyCode == 32 || window.event.keyCode == 13))
		    {
			    tepuesok = false;
		    }
	    }
	    return(tepuesok)
    }

    function PermitirSoloDatosNumericos(){
	    if (!(EsNumero() || EsOperadorNumerico()))
	    {
		    window.event.returnValue = '';
	    }
    }

    function PermitirSoloNumerosEnteros(){
	    if (!EsNumero())
	    {
		    window.event.returnValue = '';
	    }
    }

    function PermitirSoloLetras(){
	    if (!(EsLetraMayuscula() || EsLetraMinuscula()))
	    {
		    window.event.returnValue = '';
	    }
    }

    function PermitirSoloLetrasMayusculas(object){
	    if (!(EsLetraMayuscula()))
	    {
		    if (EsLetraMinuscula())
		    {
			    ConvertirTextoAMayuscula(object);
		    }
		    else
		    {
			    window.event.returnValue = '';
		    }
	    }
    }

    function PermitirSoloLetrasMinusculas(object){
	    if (!(EsLetraMinuscula()))
	    {
		    if (EsLetraMayuscula())
		    {
			    ConvertirTextoAMinuscula(object);
		    }
		    else
		    {
			    window.event.returnValue = '';
		    }
	    }
    }
     
    function PermitirSoloNumerosYLetras(){
	    if (!(EsLetraMinuscula()))
	    {
		    if (!(EsLetraMayuscula()))
		    {
			    if (!EsNumero())
			    {
				    window.event.returnValue = '';
			    }
		    }
	    }
    }

    function PermitirSoloNumerosYLetrasMayusculas(object){
	    if (!(EsNumero()))
	    {
		    if (!(EsLetraMayuscula()))
		    {
			    if (EsLetraMinuscula())
			    {
				    ConvertirTextoAMayuscula(object);
			    }
			    else
			    {
				    window.event.returnValue = '';
			    }
		    }
	    }
    }

    function PermitirSoloNumerosYLetrasMinusculas(object){
	    if (!(EsNumero()))
	    {
		    if (!(EsLetraMinuscula()))
		    {
			    if (EsLetraMayuscula())
			    {
				    ConvertirTextoAMinuscula(object);
			    }
			    else
			    {
				    window.event.returnValue = '';
			    }
		    }
	    }
    }

    function PermitirSoloLetrasYCaracteresEspeciales(){
	    if (EsNumero())
	    {
		    window.event.returnValue = '';
	    }
    }

    function PermitirSoloNumerosYCaracteresEspeciales(){
	    if (EsLetraMayuscula() || EsLetraMinuscula())
	    {
		    window.event.returnValue = '';
	    }
    }
    

    function PermitirSoloFormatoHora(obj){
	     if (!EsNumero() && (window.event.keyCode != 58) )
	     {
		    window.event.returnValue = '';
	    }
    }


    function ValidarHora(obj)
    {
        if ( obj.value.indexOf("0") )
        {
            pasodato = obj.value
           if ( pasodato.substr(2, 1) == ":"  &&  pasodato.substr(5, 1) == ":" )
            {
    	        if ( pasodato.substr(0, 2) > 23 )
    	        {
		            alert("La hora no puede ser mayor a 23")
		            obj.focus()
		            return
	            }
    	        if ( pasodato.substr(3, 2) > 59  )
	            {
		            alert("Los minutos no pueden ser mayor a 59")
		            obj.focus()
		            return
	            }
    	        if ( pasodato.substr(6, 2) > 59  )
	            {
		            alert("Los segundos no pueden ser mayor a 59")
		            obj.focus()
		            return
	            }
            } else {
		        alert("La hora no tiene un formato valido en los dos puntos posición 3 y 5 (00:00:00) ")
		        obj.focus()
            }
        } else {
            if ( obj.value.length > 0 )
            {
                alert("La hora no tiene un formato valido (00:00:00) ")
	            obj.focus()
	        }
        }
    }



    function NumberFormat(num, numDec, decSep, thousandSep){ 
        var arg; 
        var Dec; 
        Dec = Math.pow(10, numDec);  
        if (typeof(num) == 'undefined') return;  
        if (typeof(decSep) == 'undefined') decSep = ','; 
        if (typeof(thousandSep) == 'undefined') thousandSep = '.'; 
        if (thousandSep == '.') 
            arg=/./g; 
        else 
        if (thousandSep == ',') arg=/,/g; 
        if (typeof(arg) != 'undefined') num = num.toString().replace(arg,''); 
            num = num.toString().replace(/,/g, '.');  
        if (isNaN(num)) num = "0"; 
            sign = (num == (num = Math.abs(num))); 
            num = Math.floor(num * Dec + 0.50000000001); 
            cents = num % Dec; 
            num = Math.floor(num/Dec).toString();  
        if (cents < (Dec / 10)) cents = "0" + cents;  
            for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) 
            num = num.substring(0, num.length - (4 * i + 3)) + thousandSep + num.substring(num.length - (4 * i + 3)); 
        if (Dec == 1) 
            return (((sign)? '': '-') + num); 
        else 
            return (((sign)? '': '-') + num + decSep + cents); 
    }
   
    function isMail(object) {
        if (!(object.value == ""))
        {
            var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=&gt;0-9\.]+\.[a-z]{2,3}$/i
            if (!(emailReg.test(object.value)))
	        {
		        alert("Por favor ingrese una dirección de e-mail válida")
		        object.focus();
	        }
	    }
    }
    
    function ValidarRFCoCURP(obj,escurp)
    {
	    primpart = obj.value.substr(0,4)
	    segupart = obj.value.substr(4,6)
	    tercpart = obj.value.substr(10,3)
	    if (primpart.indexOf("0")>-1 || primpart.indexOf("1")>-1 || primpart.indexOf("2")>-1 || primpart.indexOf("3")>-1 || primpart.indexOf("4")>-1 || primpart.indexOf("5")>-1 || primpart.indexOf("6")>-1 || primpart.indexOf("7")>-1 || primpart.indexOf("8")>-1 || primpart.indexOf("9")>-1)
	    {
		    if (escurp!="S")
		    {
			    alert("El RFC no tiene un formato valido.\nAlguno de los 4 primeros digitos no es correcto.")
			    obj.focus()
		    }
		    else
		    {
			    alert("El CURP no tiene un formato valido.\nAlguno de los 4 primeros digitos no es correcto.")
			    obj.focus()
		    }
	    }
	    else
	    {
		    if (isNaN(segupart))
		    {
			    if (escurp!="S")
			    {
				    alert("El RFC no tiene un formato valido.\nAlguno de digitos que forman la fecha de nacimiento no son correctos.")
				    obj.focus()
			    }
			    else
			    {
				    alert("El CURP no tiene un formato valido.\nAlguno de digitos que forman la fecha de nacimiento no son correctos.")
				    obj.focus()
			    }
		    }
		    else
		    {
		    }
	    }
	    obj.value=obj.value.toUpperCase()
    }
    function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
    }

    function finMes(oTxt,formato){
	    var mes = damemes(oTxt,formato);
	    var nMes = parseInt(mes, 10);
	    var nRes = 0;
	    switch (nMes){
	    case 1: nRes = 31; break;
	    case 2: nRes = 29; break;
	    case 3: nRes = 31; break;
	    case 4: nRes = 30; break;
	    case 5: nRes = 31; break;
	    case 6: nRes = 30; break;
	    case 7: nRes = 31; break;
	    case 8: nRes = 31; break;
	    case 9: nRes = 30; break;
	    case 10: nRes = 31; break;
	    case 11: nRes = 30; break;
	    case 12: nRes = 31; break;
	    }
	    return nRes;
    }

    function valSep(oTxt,formato){
	    var bOk = false;
	    var pos1 = 0;
	    var pos2 = 0;
	    if (formato == "DD/MM/AAAA")
	    {
		    pos1 = 2;
		    pos2 = 5;
	    }
	    else
	    {
		    if (formato == "AAAA/MM/DD")
		    {
			    pos1 = 4;
			    pos2 = 7;
		    }
		    else
		    {
			    if (formato == "MM/DD/AAAA")
			    {
				    pos1 = 2;
				    pos2 = 5;
			    }
		    }
	    }
	    bOk = bOk || ((oTxt.value.charAt(pos1) == "-") && (oTxt.value.charAt(pos2) == "-"));
	    bOk = bOk || ((oTxt.value.charAt(pos1) == "/") && (oTxt.value.charAt(pos2) == "/"));
	    return bOk;
    }

    function valDia(oTxt,formato){
	    var bOk = false;
	    var dia = damedia(oTxt,formato);
	    var nDia = parseInt(dia, 10);
	    bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt,formato)));
	    return bOk;
    }

    function valMes(oTxt,formato){
	    var bOk = false;
	    var mes = damemes(oTxt,formato);
	    var nMes = parseInt(mes, 10);
	    bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	    return bOk;
    }

    function valAno(oTxt,formato){
	    var bOk = true;
	    var nAno = dameano(oTxt,formato)
	    bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
	    if (bOk){
		    for (var i = 0; i < nAno.length; i++){
			    bOk = bOk && esDigito(nAno.charAt(i));
		    }
	    }
	    return bOk;
    }

    function damedia(oTxt,formato){
	    var dia = "";
	    if (formato == "DD/MM/AAAA")
	    {
		    dia = oTxt.value.substr(0, 2);
	    }
	    else
	    {
		    if (formato == "AAAA/MM/DD")
		    {
			    dia = oTxt.value.substr(8);
		    }
		    else
		    {
			    if (formato == "MM/DD/AAAA")
			    {
				    dia = oTxt.value.substr(3, 2);
			    }
		    }
	    }
	    return dia
    }

    function damemes(oTxt,formato){
	    var mes = "";
	    if (formato == "DD/MM/AAAA")
	    {
		    mes = oTxt.value.substr(3, 2);
	    }
	    else
	    {
		    if (formato == "AAAA/MM/DD")
		    {
			    mes = oTxt.value.substr(5, 2);
		    }
		    else
		    {
			    if (formato == "MM/DD/AAAA")
			    {
				    mes = oTxt.value.substr(0, 2);
			    }
		    }
	    }
	    return mes
    }

    function dameano(oTxt,formato){
	    var nAno = ""
	    if (formato == "DD/MM/AAAA")
	    {
		    nAno = oTxt.value.substr(6);
	    }
	    else
	    {
		    if (formato == "AAAA/MM/DD")
		    {
			    nAno = oTxt.value.substr(0, 4);
		    }
		    else
		    {
			    if (formato == "MM/DD/AAAA")
			    {
				    nAno = oTxt.value.substr(6);
			    }
		    }
	    }
	    return nAno
    }

    function ValidarFecha(oTxt,formato){
	    var bOk = true;
	    if (oTxt.value != ""){
		    bOk = bOk && (valAno(oTxt,formato));
		    bOk = bOk && (valMes(oTxt,formato));
		    bOk = bOk && (valDia(oTxt,formato));
		    bOk = bOk && (valSep(oTxt,formato));
		    if (!bOk){
			    alert("Fecha inválida debe ser: " + formato);
			    oTxt.focus();
		    }
	    }
    }
    
    function MsgAlert(){
	    Nobjeto = BuscaObjeto("MsgAlerta")
	    if (Nobjeto != null){
		    objeto = document.getElementById(Nobjeto);
		    var texto = objeto.value
		    var msg = ""
		    var letra = ""
		    if (texto.length > 0){
			    for (var i = 0; i < texto.length; i++){
				    letra = texto.charAt(i)
				    if (letra == "*"){
				        if (msg.length > 0 && msg != " "){
					        alert(msg);
					    }
					    msg = "";
				        letra = "";
				    }
				    msg = msg + letra;
			    }
			    if (msg.length > 0){
				    alert(msg);
			    }
			    document.getElementById(Nobjeto).value = ""
		    }
		    document.getElementById(Nobjeto).style.visibility = 'hidden'
	    }
    }
       
    function BuscaObjeto(nombobjeto)
    {
        habielem=document.all.length
        nombcamp = null
	    for (selex=0; selex<habielem; selex++){
		    if (document.all[selex].type=="text"){
			    nombcate = document.all[selex].name
			    if (nombcate.search(nombobjeto) != -1){
			        if (document.getElementById(nombcate).style.visibility != 'hidden'){
				        nombcamp = nombcate;
				        selex=habielem;
				    }
			    }
		    }
	    }
	    return nombcamp
    }

    function enviado() {                       
       if (cuenta == 0)
          {
          cuenta++;
          return true;
          }
       else 
          {
          alert("El formulario ya ha sido enviado, muchas gracias.");
          return false;
          }
       }

    function DameFecha() {
        miFechaActual = new Date() 
        //extraemos el día mes y año 
        dia = miFechaActual.getDate() 
        mes = parseInt(miFechaActual.getMonth()) + 1 
        ano = miFechaActual.getFullYear() 
        fecharegresa = (dia + "/" + mes + "/" + ano)
        return fecharegresa
    }
    
    function ilumina(celda){ 
          desilumina(celda);
            /*celda.style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#ff3366CC',EndColorStr='#ff3366CC')"; /*StartColorStr='#ff112233',EndColorStr='#ffFFFFFF'*/
            celda.style.color = "white"
            celda.style.backgroundColor = "#3399FF"
            /*celda.style.backgroundColor = "black"
            /*celda.style.border = "1px inset"*/
            celda_ant = celda; 
        }
        
    function desilumina(celda){ 
          if (celda_ant=="") 
            { 
                celda_ant = celda; 
            } 
            celda.style.filter = "";
            celda.style.color = "blue"
            celda.style.backgroundColor = "white"
            /*
            celda.style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=1,StartColorStr='silver',EndColorStr='gray')";
            celda_ant.style.color = "black"
            celda_ant.style.backgroundColor = "white"
            celda.style.border = "1px outset"
            */
        }
      
    function goLiteTab(FRM,BTN)
    {
       color_tabant = window.document.forms[FRM].elements[BTN].style.color;
       window.document.forms[FRM].elements[BTN].style.color = "#CC5533";
       window.document.forms[FRM].elements[BTN].style.borderTopColor = "#666666";
       window.document.forms[FRM].elements[BTN].style.borderBottomColor = "#666666";
    }

    function goDimTab(FRM,BTN)
    {
       window.document.forms[FRM].elements[BTN].style.color = color_tabant;
       window.document.forms[FRM].elements[BTN].style.borderTopColor = "#AAAAAA";
       window.document.forms[FRM].elements[BTN].style.borderBottomColor = "#AAAAAA";
    }
    

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      
