function ing_numeros(a) 
{	
	if ((window.event.keyCode < 48) || (window.event.keyCode > 59))
	{
		window.event.keyCode = 0
		a.focus()
	}
} 
function numeros_letra() { 
  if ((window.event.keyCode < 48) || (window.event.keyCode > 59) &&(event.keyCode != 75 && event.keyCode != 107))
  {
  	window.event.keyCode = 0
  }
}  

function ChangeColorA(Obj){
Obj.style.background = "#ffefd5"
}

function ChangeColorB(Obj){
	Obj.style.background = "#ffffff"
}

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 numérico 
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<2008) || (ano>2010)) { fecha=fecha.substr(0,6); } } } 
} 

if (long>=10) 
{ 
	mm = "00-31-28-31-30-31-30-31-31-30-31-30-31"
	meses =  mm.split("-")
	fecha=fecha.substr(0,10); 
	dia=fecha.substr(0,2); 
	mes=fecha.substr(3,2); 
	ano=fecha.substr(6,4); 
	if (mes == '08')
	  mes = 8;	
	if (mes == '09')
	  mes = 9;	
	if ( parseInt(dia) > meses[parseInt(mes)] )
		{ fecha=fecha.substr(0,2)+"/"; } 
// 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 ingdatos()
{
	document.envdat.action ='Act_Credencial.asp';
	document.envdat.submit();
} 
function ir()
{
	document.envdat.action ="Act_Credencial_grb.asp";
	document.envdat.submit();
}
function salir()
{
	document.envdat.action = "../index.asp";
	window.envdat.submit();
}


function valida_rut(rt,d) 
{ 
	if (rt.value.length > 6)
	{
		var str1, total=0, multi=2, resto=0, dv="";
		var r;
		k = rt.value;
		r = rt;
		r.value = r.value + d.value; 
		str1=r.value, dv = str1.substr(--str1.length,1)
		dv= dv.toUpperCase() ;
		rt.value=k;
		str1=str1.substr(0,--str1.length)
		for (var i = --str1.length; i > -1; i--){
		    total = total += (parseInt(str1.substr(i,1)) * multi);
		    multi = ++multi;
		    if (multi == 8) multi = 2;
		}
		resto = 11 - (total % 11);
		if (resto == 10) resto = "K";
		if (resto == 11) resto = "0";
		if (resto != dv) {
			rt.value = "";
			rt.focus();
			return false;
		}
		else
			return true;
	}
	else
		return false;
}

function validar()
{
	if (valida_rut(document.envdat.rut, document.envdat.dv))
	{
		document.envdat.action ="Act_Credencial_grb.asp";
		document.envdat.submit();
	}
	else
		alert("Rut no valido. Verifiquelo por favor.")
		
}

function validartacoton()
{
	if (valida_rut(document.envdat.rut, document.envdat.dv))
	{
		document.envdat.action ="tacoton_grb.asp";
		document.envdat.submit();
	}
	else
		alert("Rut no valido. Verifiquelo por favor.")
		
}

function mayuscula(obj)
{
	obj.value = obj.value.toUpperCase()
}

function largoMax(obj, lrg)
{
	if(obj.value.length > lrg)
	{
		obj.value = obj.value.substr(0,lrg-1)
	}
}