
function getValue(otherElement) {

  alert(otherElement.form.elements[0].value);
//  alert(Encripta1(otherElement.form.elements[0].value));
  alert(otherElement.form.elements[1].value);
  alert(Encripta1(otherElement.form.elements[1].value));

  alert(otherElement.form.elements[2].value);
  alert(Encripta2(otherElement.form.elements[2].value));

}

function KeyIsNRut(evt)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1);
var isIE = (navigator.appName.indexOf("Microsoft") != -1);
if (isNav)
	{
	if (evt.which == 13 || evt.which == 8 || (evt.which >= 48 && evt.which <= 57) )			
	return true;
	return false;
	}
	else
	if (isIE)
	{
	evt = window.event;
	if (evt.keyCode == 13 || evt.keyCode == 8 || (evt.keyCode >= 48 && evt.keyCode <= 57) )				
	return true;
	return false;
	}
	else
	{
	alert("Esta aplicación no funciona en su Navegador.");			
	return false;
	}
}




function KeyIsDVRut(evt)
{
var isNav = (navigator.appName.indexOf("Netscape") != -1);
var isIE = (navigator.appName.indexOf("Microsoft") != -1);
if (isNav)
	{
	if (evt.which == 13 || evt.which == 75 || evt.which == 107 || evt.which == 8 || (evt.which >= 48 && evt.which <= 57) )
	return true;
	return false;
	}
	else
	if (isIE)
	{
	evt = window.event;
	if (evt.keyCode == 13 || evt.keyCode == 75 || evt.keyCode == 107 || evt.keyCode == 8 || (evt.keyCode >= 48 && evt.keyCode <= 57) )
	return true;			
	return false;		
	}		
else		
	{
	alert("Esta aplicación no funciona en su Navegador.");
	return false;
	}
}
function checkFilledFields()
{
	//saca el focus para estabilizar los datos.
    document.frm.rut.blur();
    document.frm.drut.blur();
    document.frm.clave.blur();
    if ( (document.frm.drut.value == "") || (document.frm.rut.value == "") )
	{
	return false;
	}
    else
	{
    	return true;
    }
}
//Limpia los campos
function LimpiaCampos()
{
   	document.frm.rut.value="";
   	document.frm.drut.value="";
	document.frm.clave.value="";
   	document.frm.rut.focus();
}
 //Valida largo de un string.
function testlargo(texto,largomin,largomax)
{	
if ((texto.length < largomin) || (texto.length > largomax))
	{
      return false;
	}   
 else   
	{
    	return true;    }
}
//Chequea que los campos contengan datos válidos.
function checkDataFields()
{
	if ( testlargo(document.frm.rut.value,3,9) )
	  {
	return true;	
	}
  	else
  	{
	return false
  	}
}
//Chequea el dígito verificador.
function checkDV()
{
rut = document.frm.rut.value;
drut = document.frm.drut.value;
var dvr = '0'
suma = 0
mul  = 2
for (i= rut.length -1 ; i >= 0; i--)
    {
	suma = suma + rut.charAt(i) * mul
        if (mul == 7)
       	mul = 2
        else
       	mul++
    }
res = suma % 11
if (res==1) dvr = 'k'
else
if (res==0) dvr = '0'
else
	{
	dvi = 11-res
	dvr = dvi + ""
    	}
  	if ( dvr != drut.toLowerCase() )
	{
    	return false;
	}
  	else
   	{
	return true;
	}
}

//Chequea todo.
function checkAll()
{
if ( !checkFilledFields() )
	{
    	alert("Complete todos los datos por favor");
    	return false;
        }

if ( !checkDataFields() )
  	{
    	alert("Los datos ingresados no son correctos");    	
	document.frm.clave.value="";
    	document.frm.rut.value="";
    	document.frm.drut.value="";
    	return false;
        }
	if ( document.frm.clave.value.length < 7 )
	{
    	alert("La clave debe poseer 7 caracteres como minimo.");    	
	document.frm.clave.focus()
    	document.frm.clave.select()
    	return false;
	}
  	if ( !checkDV() )
  	{
    	alert("El Rut es incorrecto")
    	document.frm.clave.value="";
    	document.frm.rut.value="";
    	document.frm.drut.value="";
   	return false;
        }
  	return true;
}
function ChequeaDatos()
{
	var verif=checkAll();
	if (verif==false)return false;
	var numrut=document.frm.rut.value;
	Codigo=Encripta2(numrut)
	var cClave=document.frm.clave.value;
	if (cClave == Codigo)
		{
		var doc=Encripta1(numrut)
		document.frm.infnotas.value = doc
//		alert(document.frm.infnotas.value)
		document.frm.submit()
//		Session("yaestube") = True
//		Session("rut") = "Chao Pezcao"
//		var location="notas1.asp?infnotas="+doc
//		window.location.href = location;

		}
	else
		{
		alert("Clave Incorrecta..!")
		}
}

function ExisteArchivo(nomarch)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
fileBool = fso.FileExists(nomarch);
alert( fileBool);
return fileBool;
}

function printPage() {
  if (window.print)
    window.print()
  else
   alert("¡Su explorador no soporta esta característica!");
}

function addBookmark() {
  if (window.external)
    external.AddFavorite(location.href)
  else
    alert("¡Su explorador no soporta esta característica!");
}

function handlePress(e) {
  var shiftPressed = (window.Event) ? e.modifiers & Event.SHIFT_MASK : e.shiftKey;
  if (shiftPressed) {
    alert("El uso de la Tecla Shift no está permitida en este sitio");
	return false;
  }
  else return true;
}


function escribe(codigo)
{
	document.write(codigo)
}


function click() {
if (event.button==2)
	{
	alert('¡ El botón derecho del ratón está deshabilitado !');
	}
}
document.onmousedown=click

function VeriRut(a)
   {
	var DIGITO =" ";		
	a=a.toUpperCase();
	var i=a.substring(0,a.length-2);

	var dv=a.substring(a.length-1,a.length);

	var j=i*1;
	var N = i*1;
	var K = 2;
	var D = 10;
	var SU = 0;
 for ( ind=i.length-1; ind >= 0 ; ind-- )
	{
		if (K == 8)
		{
			K=2;
		}
		var S = parseInt((N-parseInt(N/D)*D)/(D/10));
		D = D * 10;
		SU = SU+S*K;
		K = K + 1;
	}
		var vDIGITO = parseInt(11-(SU/11-(parseInt(SU/11)))*11+.05)
	if (vDIGITO == 11)
		 DIGITO = "0";
	else if (vDIGITO == 10)
		 DIGITO = "K";
	else if (vDIGITO < 10)
		 DIGITO = vDIGITO;
	else
		 DIGITO =0
if (dv == DIGITO)
	{
	var x = 1;
	return x;
	}
else
	{
	var x = 0;
	return x;
	}
}

function Encripta1(cNumero)
{
var Codigo = new String;
var p = new Array();
    p[0]=10
    p[1]= -5
    p[2]= -2
    p[3]= 8
    p[4]= -1
    p[5]= 7
    p[6]= -3
    p[7]= 4

Codigo = ""
TextSize = cNumero.length;

for (i = 0; i < TextSize; i++)
	{
	Ascii=cNumero.charCodeAt(i)+p[i]+54
	Letra=String.fromCharCode(Ascii);
	Codigo += Letra
	}

return Codigo;
}

function Encripta2(cNumero)
{

codigo = new String;
p = new Array();
    p[0]=10
    p[1]= -5
    p[2]= -2
    p[3]= 8
    p[4]= -1
    p[5]= 7
    p[6]= -3
    p[7]= 4

Codigo = ""
TextSize = cNumero.length;
for (i = 0; i < TextSize; i++) {
Ascii=cNumero.charCodeAt(i)+p[i]+54
Letra=String.fromCharCode(Ascii);
Codigo += Letra
}

var Codigo1 =""
var L1=parseInt(TextSize/2);

for ( i=L1; i >= 1 ; i-- )
	{
	Codigo1=Codigo1 + Codigo.substring(i-1,i);
	}

var Codigo2=""

var L2=parseInt(TextSize/2);

for ( i=TextSize; i >= L1+1 ; i-- )
	{
	Codigo2= Codigo2 + Codigo.substring(i-1,i);
    }
Codigo= Codigo1 + Codigo2;

return Codigo;
}
