function valLogin( rut, pass )
{
  //NUEVO

	var tmpstr = "";

	for ( i=0; i < rut.length ; i++ )
		if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;

  //NUEVO

	if ( rut == "" )
	{
		alert( "Complete todos los datos, por favor.");
		window.document.form.txtRut.focus();
		window.document.form.txtRut.select();
		return false;
	}
	if ( pass == "" )
	{
		alert( "Complete todos los datos, por favor.");
		window.document.form.pass.focus();
		window.document.form.pass.select();
		return false;
	}

	if ( !checkRutField(rut) )
		return false;
	if ( !checkDV( rut ) )
		return false;
  
    //NUEVO
	window.document.form.hrut.value = rut; 
	//alert("rut [" + rut + "]" );
	//NUEVO

    return true
	//window.document.form.submit()
}

//////////////////////////////////////////////////

function checkCDV( dvr, objRut )
{
	dv = dvr + ""
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')
	{
		alert("Debe ingresar un digito verificador valido");
		objRut.focus();
		objRut.select();
		return false;
	}
	return true;
}

//////////////////////////////////////////////////

function checkDV( objCrut )
{
	crut = objCrut.value;
	largo = crut.length;
	if ( largo < 2 )
	{
		alert("Debe ingresar el RUT completo")
		objCrut.focus();
		objCrut.select();
		return false;
	}

	if ( largo > 2 )
		rut = crut.substring(0, largo - 1);
	else
		rut = crut.charAt(0);
		
	dv = crut.charAt(largo-1);
	checkCDV( dv, objCrut );

	if ( rut == null || dv == null )
		return 0

	var dvr = '0'

	suma = 0
	mul  = 2
	
	rut = rut.replace(".", "");
	rut = rut.replace(".", "");
	rut = rut.replace("-", "");
	//rutB = parseInt(rut);
	//rut = rutB.toString;
	for (i= rut.length - 1 ; i >= 0; i--)
	{
		
		suma = suma + (parseInt(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 != dv.toLowerCase() )
	{
		alert("EL rut es incorrecto")
		objCrut.focus();
		objCrut.select();
		return false
	}

    return true
}

///////////////////////////////////////////////////////

function checkRutField(objText)
{
  //NUEVO
  var texto = objText.value;
  var tmpstr = "";

  for ( i=0; i < texto.length ; i++ )
    if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
      tmpstr = tmpstr + texto.charAt(i);
  texto = tmpstr;
  largo = texto.length;

  //NUEVO

  if ( largo < 2 )
  {
    alert("Debe ingresar el RUT completo")
    objText.focus();
    objText.select();
    return false;
  }

  for (i=0; i < largo ; i++ )
  { 
    if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" ) 
    {
      alert("El valor ingresado no corresponde a un R.U.T valido");
      objText.focus();
      objText.select();
      return false;
    }
  }

  //NUEVO

  var invertido = "";

  for ( i=(largo-1),j=0; i>=0; i--,j++ )
    invertido = invertido + texto.charAt(i);

  var dtexto = "";

  dtexto = dtexto + invertido.charAt(0);
  dtexto = dtexto + '-';
  cnt = 0;

  for ( i=1,j=2; i<largo; i++,j++ )
  {
    //alert("i=[" + i + "] j=[" + j +"]" );
    if ( cnt == 3 )
    {
      dtexto = dtexto + '.';
      j++;
      dtexto = dtexto + invertido.charAt(i);
      cnt = 1;
    }
    else
    { 
      dtexto = dtexto + invertido.charAt(i);
      cnt++;
    }
  }

  invertido = "";

  for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )
    invertido = invertido + dtexto.charAt(i);

  objText.value = invertido;  

  //NUEVO

  if ( checkDV(objText) )
    return true;
  return false;
}

function check_date(field){
	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "-";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	DateValue = DateField.value;
	/* Delete all chars except 0..9 */
	for (i = 0; i < DateValue.length; i++) {
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}	
	DateValue = DateTemp;

	/* Always change date to 8 digits - string*/
	/* if year is entered as 2-digit / always assume 20xx */
	if (DateValue.length == 0) {
		err = 69;
		return false;}
	if (DateValue.length == 6) {
		DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
	if (DateValue.length != 8) {
		err = 19;}
	   /* year is wrong if year = 0000 */
	   year = DateValue.substr(4,4);
	   if (year == 0) {
	      err = 20;
	   }
	   /* Validation of month*/
	   month = DateValue.substr(2,2);
	   if ((month < 1) || (month > 12)) {
	      err = 21;
	   }
	   /* Validation of day*/
	   day = DateValue.substr(0,2);
	   if (day < 1) {
	     err = 22;
	   }
	   /* Validation leap-year / february / day */
	   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
	      leap = 1;
	   }
	   if ((month == 2) && (leap == 1) && (day > 29)) {
	      err = 23;
	   }
	   if ((month == 2) && (leap != 1) && (day > 28)) {
	      err = 24;
	   }
	   /* Validation of other months */
	   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
	      err = 25;
	   }
	   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
	      err = 26;
	   }
	   /* if 00 ist entered, no error, deleting the entry */
	   if ((day == 0) && (month == 0) && (year == 00)) {
	      err = 0; day = ""; month = ""; year = ""; seperator = "";
	   }
	   
	   cadenota = year + month + day;
	   
	   hoy = new Date();
	   
	   hoy_dia = hoy.getDate();
	   hoy_dia = hoy_dia.toString();
	   if (hoy_dia.length = 1 )
		{
			hoy_dia = "0" + hoy_dia
		}
	   
	   //window.alert (hoy_dia);
	   
	   hoy_mes = hoy.getMonth() + 1;
	   hoy_mes = hoy_mes.toString();
	   if (hoy_mes.length = 1 )
		{
			hoy_mes = "0" + hoy_mes
		}

	//	window.alert (hoy_mes);
		
	   hoy_yr = hoy.getYear();
	   hoy_yr = hoy_yr.toString();
	   
	   //window.alert (hoy_yr);
	   
	   cadenota2 = hoy_yr + hoy_mes + hoy_dia
	   cadenota2 = cadenota2.toString();
	   
	   hoy_entero = parseInt(cadenota2);
	   fecha_entero = parseInt(cadenota);
	   
	   if (hoy_entero > fecha_entero )
		{
		err = 69;
		}
	   
	   
	   
	   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
	   if (err == 0) {
	      DateField.value = day + seperator + month + seperator + year;
	      return true;
	   }
	   /* Error-message if err != 0 */
	   else {
			alert("Fecha errónea. Debe estar en formato dd-mm-aaaa y no ser anterior a hoy.");
			DateField.focus();
			return false;
	   }
	}
//  End -->


<!-- Begin
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("La Direccion Email ingresada no es correcta.");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("La Direccion Email ingresada no es correcta.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("La Direccion Email ingresada no es correcta.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("La Direccion Email ingresada no es correcta.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("La Direccion Email ingresada no es correcta.");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("La Direccion Email ingresada no es correcta.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("La Direccion Email ingresada no es correcta.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("La Direccion Email ingresada no es correcta.");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->