/***************************************************
Formatea fecha dd/mm/aaaa

esta es la forma para ejecutar la funcion de formateo de fecha
<input name="fecha" type="text" size="10" maxlength="10" onKeyUp = "this.value=formateafecha(this.value);"> 

*/
function IsNumeric(valor) 
{ 
var log=valor.length; var sw="S"; 
for (x=0; x<log; x++) 
{ v1=valor.substr(x,1); 
v2 = parseInt(v1); 
//Compruebo si es un valor numerico 
if (isNaN(v2)) { sw= "N";} 
} 
if (sw=="S") {return true;} else {return false; } 
} 

var primerslap=false; 
var segundoslap=false; 

function formateafecha(fecha) 
{ 
var long = fecha.length; 
var dia; 
var mes; 
var ano; 

if ((long>=2) && (primerslap==false)) { dia=fecha.substr(0,2); 
if ((IsNumeric(dia)==true) && (dia<=31) && (dia!="00")) { fecha=fecha.substr(0,2)+"/"+fecha.substr(3,7); primerslap=true; } 
else { fecha=""; primerslap=false;} 
} 
else 
{ dia=fecha.substr(0,1); 
if (IsNumeric(dia)==false) 
{fecha="";} 
if ((long<=2) && (primerslap=true)) {fecha=fecha.substr(0,1); primerslap=false; } 
} 
if ((long>=5) && (segundoslap==false)) 
{ mes=fecha.substr(3,2); 
if ((IsNumeric(mes)==true) &&(mes<=12) && (mes!="00")) { fecha=fecha.substr(0,5)+"/"+fecha.substr(6,4); segundoslap=true; } 
else { fecha=fecha.substr(0,3);; segundoslap=false;} 
} 
else { if ((long<=5) && (segundoslap=true)) { fecha=fecha.substr(0,4); segundoslap=false; } } 
if (long>=7) 
{ ano=fecha.substr(6,4); 
if (IsNumeric(ano)==false) { fecha=fecha.substr(0,6); } 
else { if (long==10){ if ((ano==0) || (ano<1900) || (ano>2100)) { fecha=fecha.substr(0,6); } } } 
} 

if (long>=10) 
{ 
fecha=fecha.substr(0,10); 
dia=fecha.substr(0,2); 
mes=fecha.substr(3,2); 
ano=fecha.substr(6,4); 
// A�o no viciesto y es febrero y el dia es mayor a 28 
if ( (ano%4 != 0) && (mes ==02) && (dia > 28) ) { fecha=fecha.substr(0,2)+"/"; } 
} 
return (fecha); 
} 
/*******************************************************************/


function varchar(objeto)
{
    digito=(objeto.value).substr((objeto.value).length -1,(objeto.value).length)
    var vDigitosNulos = " abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ,:.;-_!$%&/()=?纪0123456789#"
    if(parseInt(vDigitosNulos.lastIndexOf(digito),10)==-1){
        objeto.value=(objeto.value).substr(0,(objeto.value).length -1)
    }
}
function validanumero(field){
    // onblur="javascript:validanumero(this)"
    if (field.value==""){
        return false;
    }
    var valid = "0123456789."
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
        temp = "" + field.value.substring(i, i+1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no") {
        alert("Solo se Aceptan numeros !!!" )
        field.value="";
        field.focus();
        field.select();
    }else{
        if (field.value=="")field.value=""
    }
}
function validastring(field){
    if (field.value==""){
        return false;
    }
    //var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?=()/\&%$#@|{}[]*;:.-_^,' "
    //cambiado por ariosr 04/02/2009
    var valid = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?=()/\%$#@{}[]*;:.-_^,' "
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
        temp = "" + field.value.substring(i, i+1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no") {
        alert("Entrada de dato no valida! Ha escrito caracteres no validos en esta entrada de datos!\n\nNo se permiten los caracteres especiales | (Pipe) ni & (Ampersan)");
        //field.value="";
        field.focus();
        field.select();
    }else{
        if (field.value=="")field.value=""
    }
}






//***************************************************************************************
//Funciones nuevas aplicativo
//***************************************************************************************


  
  
  
  function comprueba_valores(field){
      document.getElementById('tiempo').style.visibility="visible";
	variable="";
	//alert(field);
	//if(field.ncorrelativo.value==""){ variable="Falta Numero Interno Correlativo\n";}
	if(field.tipodoc.value=="#"){ variable=variable+"Seleccione Tipo Documento\n";}
	if(field.grtemadoc.value=="#"){ variable=variable+"Seleccione Tema Documento\n";}else{
	     if(field.temadoc.value=="#"){ variable=variable+"Seleccione Detalle Tema \n";}	
	}
	if(field.division.value=="#"){ variable=variable+"Seleccione División de Destino\n";}
	if(field.materia.value==""){ variable=variable+"Falta Materia Documento\n";}
	if(field.resoficio.value==""){ variable=variable+"Falta Campo Responde Oficio \n";}
	if(field.anoresoficio.value==""){ variable=variable+"Falta Campo Año\n";}
	
	//if(field.archivos[0].value==""){ variable=variable+"Falta Archivo a Transmitir\n";}
	 if(variable==""){
				op=confirm('Atencion, Confirma la Operacion ?');
				if(op){
					
					document.getElementById('tiempo').style.visibility="visible";
                                        return true;
				}else{
                                        return false;
				}
	}else{
		alert("Por favor verifique lo siguiente :\n\n"+variable);
		return false;
	}	
}


function comprueba_valores_rechazo(field){
        document.getElementById('tiempo').style.visibility="visible";
	variable="";
	//if(field.ncorrelativo.value==""){ variable="Falta Numero Interno Correlativo\n";}
	if(field.tipodoc.value=="#"){ variable=variable+"Seleccione Tipo Documento\n";}
	if(field.grtemadoc.value=="#"){ variable=variable+"Seleccione Tema Documento\n";}else{
	     if(field.temadoc.value=="#"){ variable=variable+"Seleccione Detalle Tema \n";}	
	}
	if(field.division.value=="#"){ variable=variable+"Seleccione División de Destino\n";}
	if(field.materia.value==""){ variable=variable+"Falta Materia Documento\n";}
	if(field.resoficio.value==""){ variable=variable+"Falta Campo Responde Oficio \n";}
	if(field.anoresoficio.value==""){ variable=variable+"Falta Campo Año\n";}
	
	//if(field.archivos[0].value==""){ variable=variable+"Falta Archivo a Transmitir\n";}
	 if(variable==""){
				op=confirm('Atencion, Confirma la Operacion ?');
				if(op){
					document.getElementById('tiempo').style.visibility="visible";
                                        return true
				}else{
					return false;
				}
	}else{
		alert("Por favor verifique lo siguiente :\n\n"+variable);
		return false;
	}	
}

  
function ActivaDesactiva(){
    if(document.getElementById('bopTodos').checked==true){
        document.getElementById('bopFecha').style.visibility="hidden";
        document.getElementById('bopNumero').style.visibility="hidden";
        document.getElementById('bopMateria').style.visibility="hidden";
        document.getElementById('bopRechazados').style.visibility="hidden";
        
    }
    
    if(document.getElementById('bopFecha').checked==true){
        document.getElementById('bopTodos').style.visibility="hidden";
        document.getElementById('bopNumero').style.visibility="hidden";
        document.getElementById('bopMateria').style.visibility="hidden";
        document.getElementById('bopRechazados').style.visibility="hidden";
        document.getElementById('Bboton').style.visibility="hidden";
        
    }


    if(document.getElementById('bopNumero').checked==true){
        document.getElementById('bopFecha').style.visibility="hidden";
        document.getElementById('bopTodos').style.visibility="hidden";
        document.getElementById('bopMateria').style.visibility="hidden";
        document.getElementById('bopRechazados').style.visibility="hidden";
        document.getElementById('Bboton').style.visibility="hidden";
    }

    
    if(document.getElementById('bopMateria').checked==true){
        document.getElementById('bopFecha').style.visibility="hidden";
        document.getElementById('bopNumero').style.visibility="hidden";
        document.getElementById('bopTodos').style.visibility="hidden";
        document.getElementById('bopRechazados').style.visibility="hidden";
        document.getElementById('Bboton').style.visibility="hidden";
    }
    
    if(document.getElementById('bopRechazados').checked==true){
        document.getElementById('bopFecha').style.visibility="hidden";
        document.getElementById('bopNumero').style.visibility="hidden";
        document.getElementById('bopMateria').style.visibility="hidden";
        document.getElementById('bopTodos').style.visibility="hidden";
        
    }
    
    
    if(document.getElementById('bopTodos').checked==false && 
        document.getElementById('bopFecha').checked==false && 
        document.getElementById('bopNumero').checked==false && 
        document.getElementById('bopMateria').checked==false && 
        document.getElementById('bopRechazados').checked==false){
        
        document.getElementById('bopTodos').style.visibility="visible";
        document.getElementById('bopFecha').style.visibility="visible";
        document.getElementById('bopNumero').style.visibility="visible";
        document.getElementById('bopMateria').style.visibility="visible";
        document.getElementById('bopRechazados').style.visibility="visible";
        document.getElementById('Bboton').style.visibility="visible";
        
    }
}  
