﻿        
////////        function validar(object){ 
////////            for(i=0;i<object.length;i++){ 
////////                if(object.elements(i).type == 'text' || object.elements(i).type == 'password'){ 
////////                    if(object.elements(i).value == ''){ 
////////                        alert("Debe rellenar el campo para continuar"); 
////////                        object.elements(i).focus(); 
////////                        return false; 
////////                    } 
////////                } 
////////            }
////////        }

// Esta función permitirá validar la fecha
// caja representa el textBox
//function validaFecha(caja)
function validaFecha(ctrlTexto)
{ 
   caja = ctrlTexto.value;
   
   if (caja)
   {  
      borrar = caja;
      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))
      {      
         for (i=0; i<10; i++)
	     {	
            if (((caja.substr(i,1)<"0") || (caja.substr(i,1)>"9")) && (i != 2) && (i != 5))
			{
               borrar = '';
               break;  
			}  
         }
	     if (borrar)
	     { 
	        a = caja.substr(6,4);
		    m = caja.substr(3,2);
		    d = caja.substr(0,2);
		    if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
		       borrar = '';
		    else
		    {
		       if((a%4 != 0) && (m == 2) && (d > 28))	   
		          borrar = ''; // Año no bisiesto y es febrero y el dia es mayor a 28
			   else	
			   {
		          if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
			         borrar = '';	      				  	 
			   }  // else
		    } // fin else
         } // if (error)
      } // if ((caja.substr(2,1) == \"/\") && (caja.substr(5,1) == \"/\"))			    			
	  else
	     borrar = '';
	  if (borrar == ''){
	     //alert('Fecha err\u00F3nea');
	     ctrlTexto.value = borrar;
	     ctrlTexto.focus();
	     fijarError('El formato de fecha debe ser dd/mm/aaaa');
	     return false;
	  }
   } // if (caja)   
}

// Esta función permitirá validar solo letras minusculas y mayusculas y el espacio
function validaSoloLetras(){ 
    var key=window.event.keyCode;
    if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && (event.keyCode != 209) && (event.keyCode != 241) && (event.keyCode != 39) && (event.keyCode != 32)){
        window.event.keyCode=0;
    }
} 

function validaOnBlur(ctrlTexto, opcion) {
    //var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
    
    var checkOK = '';
    var message = 'Escriba sólo letras en el campo';
    if (opcion=='L'){
        checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz ";
    }
    if (opcion=='N'){
        checkOK = "0123456789";
        message = 'Escriba sólo numerales en el campo';
    }
    if (opcion=='LN'){
        checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz0123456789 ";
        message = 'Escriba sólo letras o numerales en el campo';
    }
    
    var checkStr = ctrlTexto.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) {
        alert(message);
        ctrlTexto.value = '';
        ctrlTexto.focus();
        return (false);
    }
    return true;
}

function validaSoloLetrasyNumero(){ 
    var key=window.event.keyCode;
    if ((event.keyCode < 65 || event.keyCode > 90) && (event.keyCode < 97 || event.keyCode > 122) && (event.keyCode != 209) && (event.keyCode != 241) && (event.keyCode != 39) && (event.keyCode != 32) && (event.keyCode < 48 || event.keyCode > 57)){
        window.event.keyCode=0;
    }
} 

function validaSoloNumeroEntero(){ 
    var key=window.event.keyCode;
    if (event.keyCode < 48 || event.keyCode > 57){
        window.event.keyCode=0;
    }
} 

//Esta funcion solo valida los campos apppat y appmat para qe no sean vacios del wfrmConsultaPadron.aspx
//////function validaCamposNombres(){

//////    var mensaje = 'Datos insuficientes para generar resultados';
//////    
//////    var appat = trim(document.getElementById("txtApellidoPaterno").value); document.getElementById("txtApellidoPaterno").value = appat;
//////    var apmat = trim(document.getElementById("txtApellidoMaterno").value); document.getElementById("txtApellidoMaterno").value = apmat;
//////    var apesp = trim(document.getElementById("txtApellidoEsposo").value); document.getElementById("txtApellidoEsposo").value = apesp;
//////    var nombre = trim(document.getElementById("txtNombre").value); document.getElementById("txtNombre").value = nombre; 
//////    var numdoc = trim(document.getElementById("txtNumeroDocumento").value); document.getElementById("txtNumeroDocumento").value = numdoc; 
//////    
//////    if ((apmat == '') && (appat == '') && (apesp == '') && (nombre != '')){
//////        fijarError(mensaje);
//////        return false;
//////    }
//////    if ((apmat == '') && (appat == '') && (apesp == '') && (nombre == '')){
//////        if ( numdoc == ''){
//////            fijarError(mensaje);
//////            return false;
//////        }else 
//////            return true;
//////    }
//////    //if (((apmat == '') && (appat != '')) || ((apmat != '') && (appat == '')) )
//////    if  (((appat == '') && (apmat == '') && (apesp != '')) ||
//////        ((appat == '') && (apmat != '') && (apesp == '')) ||
//////        ((appat != '') && (apmat == '') && (apesp == '')))
//////    {
//////        if ((nombre == '') && (numdoc == '')){
//////            fijarError(mensaje);
//////            return false;
//////        }
//////    }
//////    return true;
//////}

function trim(s){
    s = s.replace(/\s+/gi, ' '); //saca espacios en blanco repetidos del medio dejando solo uno
    s = s.replace(/^\s+|\s+$/gi, ''); //saca espacios en blanco del principio y final
    return s;
}

//Esta funcion solo valida Número de Documento que no sean vacios en wfrmHistorialDepuraciones.aspx
function validaCamposHistorial(){
    var numdoc = trim(document.getElementById("txtNumeroDocumento").value); document.getElementById("txtNumeroDocumento").value = numdoc;
    var fechanac = trim(document.getElementById("txtFechaNacimiento").value); document.getElementById("txtFechaNacimiento").value = fechanac;
    if (numdoc != ''){
        if  (fechanac != ''){
            return true;
        }
    }
    fijarError('Datos insuficientes para generar resultados');
    return false;
}

//Esta funcion solo valida Número de Documento que no sean vacios en wfrmListaHabilitadosMesa.aspx
function validaCamposLista(){
    var numdoc = trim(document.getElementById("txtNumeroMesa").value);
    if (numdoc == ''){
        fijarError('Datos insuficientes para generar resultados');
        return false;
    }
    return true;
}


//esto es una aberracion... son funciones provisionales
function limpia_wfrmConsultaPadron(){
    document.getElementById("txtNombre").value = '';
    document.getElementById("txtApellidoPaterno").value = '';
    document.getElementById("txtApellidoMaterno").value = '';
    document.getElementById("txtApellidoEsposo").value = '';
    document.getElementById("DropDownTipoDocumento").value = '';
    document.getElementById("txtNumeroDocumento").value = '';
   
}

function limpia_wfrmHistorialDepuraciones(){
    document.getElementById("DropDownTipoDocumento").value = 'I';
    document.getElementById("txtNumeroDocumento").value = '';
    document.getElementById("txtFechaNacimiento").value = '';
}

function limpia_wfrmListaHabilitadosMesa(){
    document.getElementById("txtNumeroMesa").value = '';
}


function cambiaColor(idTabla) {
    var oTable = document.getElementById(idTabla);
    var oTBody = oTable.tBodies[0];
    var colDataRows = oTBody.rows;
    var aTRs = new Array;
    for (var i=0; i < colDataRows.length; i++) {
        alert(colDataRows[i].text);
        //aTRs.push(colDataRows[i]);
    }

}

/*
function borrarError(){
    if (document.getElementById("divError").style.visibility == "visible"){
        //document.getElementById("lblError").innerText = '';
        document.getElementById("divError").style.visibility = "hidden";
    }
}
*/
function fijarError(mensaje){
    document.getElementById("lblError").innerText = mensaje;
    document.getElementById("divError").style.visibility="visible";
}

function cargaPaginaCNE(){
    //<input type="button" id="btnRegresar" value="Volver a la Página Principal" onclick="cargaPaginaCNE()" tabindex="9"/>
    window.open("http://www.cne.org.bo/", "_self");
}