function ofTrim(as_value)
{
    var len, st, off;
    if (null==as_value || ""==as_value) {
        return as_value;
    }
    len=as_value.length;
    off=0;
    st=0;
    while ((st < len) && ( as_value.charAt(off+st) <=' ') ) st++;
    while ((st < len) && ( as_value.charAt(off+len-1) <=' ') ) len--;
    return ((st > 0) || (len < as_value.length)) ? as_value.substring(st, len) : as_value;
}

function email(name, domain, suffix, text)
{
   var address = name + "\u0040" + domain + "." + suffix;
   var url = "mailto:" + address;
   if( ! text )
   {
      text = address;
   }
   document.write("<a class=creditos href=\"" + url + "\">" + text + "</a>");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) { document.forms[0].elements[i].focus();
break;
         }
      }
   }
}


function reemplazar(s, t, u) {

  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += reemplazar(s.substring(i + t.length, s.length), t, u);
  return r;
}

function validaform(form){
	//form.tokensH.value=form.tokens.value;
	/*form.tokensH.value=form.tokensH.value.replace('á','&#225;');
	form.tokensH.value=form.tokensH.value.replace('é','&#233;');
	form.tokensH.value=form.tokensH.value.replace('í','&#237;');
	form.tokensH.value=form.tokensH.value.replace('ó','&#243;');
	form.tokensH.value=form.tokensH.value.replace('ú','&#250;');
	form.tokensH.value=form.tokensH.value.replace('Á','&#193;');
	form.tokensH.value=form.tokensH.value.replace('É','&#201;');
	form.tokensH.value=form.tokensH.value.replace('Í','&#205;');
	form.tokensH.value=form.tokensH.value.replace('Ó','&#211;');
	form.tokensH.value=form.tokensH.value.replace('Ú','&#218;');
	form.tokensH.value=form.tokensH.value.replace('ñ','&#241;');
	form.tokensH.value=form.tokensH.value.replace('Ñ','&#209;');
	form.tokensH.value=form.tokensH.value.replace('ü','&#252;');
	form.tokensH.value=form.tokensH.value.replace('Ü','&#220;');
*/

	/*form.tokensH.value=form.tokensH.value.replace('á','&aacute;');
	form.tokensH.value=form.tokensH.value.replace('é','&eacute;');
	form.tokensH.value=form.tokensH.value.replace('í','&iacute;');
	form.tokensH.value=form.tokensH.value.replace('ó','&oacute;');
	form.tokensH.value=form.tokensH.value.replace('ú','&uacute;');
	form.tokensH.value=form.tokensH.value.replace('Á','&Aacute;');
	form.tokensH.value=form.tokensH.value.replace('É','&Eacute;');
	form.tokensH.value=form.tokensH.value.replace('Í','&Iacute;');
	form.tokensH.value=form.tokensH.value.replace('Ó','&Oacute;');
	form.tokensH.value=form.tokensH.value.replace('Ú','&Uacute;');
	form.tokensH.value=form.tokensH.value.replace('ñ','&ntilde;');
	form.tokensH.value=form.tokensH.value.replace('Ñ','&Ntilde;');*/
	
/*	form.tokensH.value=form.tokensH.value.replace('ü','&#252;');
	form.tokensH.value=form.tokensH.value.replace('Ü','&#220;');*/

	
	if(form.q.value==""){
	alert("La busqueda no puede ser vacia");
	}
	else{
	//form.textfield.value=form.tokensH.value;		
	//alert(form.textfield.value);
	form.submit();
	}
}


/*-----------------------------------------------------------*/


/*------------------------------------------------------------------------
---------------- *Libreria de Funciones JavaScript*-----------------------
------------------------------------------------------------------------*/

/*************************Version 1.2 ***********************************************
- Descripcion: Funcion que revisa si un string contiene un float o un integer valido.
Revisando ademas que se encuentre dentro de los rangos definidos para este campo.
En el caso de que se intente validar un float, la definicion de la longitud de los
enteros y decimales que debe contener el numero se obtiene del numero maximo.

Restricciones:
- Considera como numeros  validos  solo aquellos que continen numeros y un punto.
No aceptando numeros con coma, ni con notacion decimal,ni negativos.

-parametros:
	* @rangoMax: String que contiene el Valor maximo permitido.
	* @rangoMin: Numero que contiene el Valor minimo permitido.
	* @str: String que contiene un posible numero.
- Retorna: un String
	- VACIO: indica que el string a validar es vacio.
 	- NUMERO_FLOAT: Indica que el string a validar es un float. Esto se arroja cuando 
			 se esta validando si el string es un entero permitido.
 	- NO_ES_NUMERO: Indica que no es numero valido.
 	- FUERA_DE_RANGO_ENTERO: La parte entera del numero no cumpe con los rangos dados.
 	- FUERA_DE_RANGO_DECIMAL: La parte decimal no cumple con los rangos dados.
 	- NUMERO_VALIDO: Cumple el string con las condiciones requeridas.
	- NUMERO_NEGATIVO: Indica que el string a validar es un numero negativo.

 	
# funciones Requeridas:				|  Archivo en que se encuentra
- isEmpty(str) 							- Validadores.js	
- esDigito(string)						- Validadores.js
- parteEntera(cadena)					- EfectosFuncionales.js
- Trim(inString) 						- EfectosFuncionales.js
*/
function ValidarNumero(rangoMax,rangoMin,objeto){
	if(objeto.value == "undefined"){
		str =objeto;
	}else
		str = objeto.value;

	
	if(isEmpty(str))
		return "VACIO";
	//Se eliminan los espacios demas (adornos).		
	str = Trim(str);
	if(objeto.value)
		objeto.value = str;
	
	if (isNaN(Number(str)) || (!esDigito(str) ) ) 
		return "NO_ES_NUMERO";

	if(str.indexOf('-',0) != -1)
		return "NUMERO_NEGATIVO";

	var parteEnteraPermitida = parteEntera(rangoMax);
	var parteEnteraStr = parteEntera(str);
//si la longitud de la parte entera de la definicion del dato es mayor a  15 validar los largos.

	if( ((parteEnteraPermitida.length > 15)? (parteEnteraStr.length > parteEnteraPermitida.length):(parseFloat(parteEnteraStr) > parseFloat(parteEnteraPermitida) ) )|| (parteEnteraStr < rangoMin))
	      return "FUERA_DE_RANGO_ENTERO";
	var parteEnteraPermitidaEsMayor = (parteEnteraPermitida.length > 15)? (parteEnteraStr.length < parteEnteraPermitida.length):(new Number(parteEnteraStr) < new Number(parteEnteraPermitida) );
	 //Si la definicion del dato es un decimal (Float)
	 if(rangoMax.indexOf(".",0) != -1 ) {
		var	numDecPermitido = rangoMax.length -(rangoMax.indexOf(".",0) + 1);
	 	if(str.indexOf(".",0) != -1){
			var decimalesStr = str.length - (str.indexOf(".",0) + 1);
			var punteroStr = str.length - 1; 
			while(str.indexOf(".",0)  < punteroStr){
				if(str.charAt(punteroStr)== '0'){
					decimalesStr--;
					punteroStr--;
					continue;
				}
			break
			}
			if( (parteEnteraPermitidaEsMayor)?(decimalesStr >  numDecPermitido):(parseFloat(str.substring(str.indexOf(".",0),str.length ) ) > parseFloat(rangoMax.substring(rangoMax.indexOf(".",0),rangoMax.length) )))
				return "FUERA_DE_RANGO_DECIMAL";
		}

	 }else{
	 	if(str.indexOf(".",0) != -1)
		  return "NUMERO_FLOAT";
	 
	 }
return "NUMERO_VALIDO";
}


/*************************Version 1.1 ***********************************************
- Descripcion: Valida que el String contiene solo numeros,negativo  y puntos.
* @<autor>: Hugo Martinez
- parametros:
* @str: cadena a validar
- Retorna un booleano:
		true: si el str es considerado digito.
		false: Si el str no es considerado como digito.
*/

function esDigito(str)
{
	 var ch
	 if (str.length == 0)
		 return false;
	 for (var i = 0 ; i < str.length ; i++) {
		 ch = str.charAt(i);
		 if ( (ch < '0' || ch > '9' ) && ch !='.' && ch != '-' )
				return false;
	 }
	 return true;    
}



/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que revisa si un string esta vacio o nulo.

* @<autor>: ASP
- parametros:
	* @str: String validar .
- Retorna: un boolean
	- true: si el string  es vacio o nulo:
	- false: si el string  no es vacio ni nulo.
 	
*/
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que valida que el campo valor corresponda con el 
rango de valores definidos por el usuario a traves de la caja se seleccion.
* @<autor>: Hugo Martinez
- parametros:
	* @campo: String a  validar .
	* @objSelected: Objeto selected.
- Retorna: un String
	- FUERA_RANGO_PORCENTAJE : si el string no cumple con el rango de porcentaje.
	- FUERA_RANGO_POR_MIL :  si el string no cumple con el rango de mil.
	- FUERA_RANGO_MONTO	: si el string no cumple con el rango de monto.
*/
function ValidarValor(valor,objSelected)
{

       if (objSelected.options[objSelected.selectedIndex].value == "P"){                               
                               if (valor < 0 || valor > 100){
                                       return "FUERA_RANGO_PORCENTAJE";
                                }
         }
//alert("pasa 2 ");
       if (objSelected.options[objSelected.selectedIndex].value == "L"){
                        
//                      alert("valor "+valor);
                                if ((valor < 0) || (valor > 1000)){
                                        return "FUERA_RANGO_POR_MIL";
                                }
           }
                        
           if (objSelected.options[objSelected.selectedIndex].value == "M"){
                               
                                if ((valor < 0) || (valor > 9999.999)){
                                        return "FUERA_RANGO_MONTO" ;                                    
                                }

           }       
        return "RANGO_PERMITIDO"
}

/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que compara dos string que contiene numeros validos.
* @<autor>: Hugo Martinez
- parametros:
	* @ numeroUno: String uno a comparar.
	* @ numeroDos: String dos a comparar.
- Retorna: un numero.
	- 0 : Si el numeroUno es igual al numeroDos.
	- positivo: Si el numeroDos es mayor que el numeroUno.
	- negativo: Si el numeroDos es menor que el numeroUno 	
*/
function comparaNumeros(numeroUno,numeroDos){
	return parseFloat(numeroDos) - parseFloat(numeroUno); 
	
	}


/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que compara dos string que contiene numeros validos.
* @<autor>: Hugo Martinez
- parametros:
	* @ fecha : objeto o String que contiene una fecha.
	* @ anioMax : es el año maximo valido.
	* @ aniMin : es el año minimo valido.
- Retorna: un String.
	- VACIO : Si la fecha validada es un string vacio .
	- ERROR_FORMATO_FECHA: Si la fecha validada no posee el formato dd/mm/aaaa
	- FECHA_VALIDA:Si la fecha validada es correcta. 
# Retorna los errores de:
	|Nombre de la funcion                               |Archivo en que se encuentra
	- ValidaDiaMesAnio(dia, mes, anio,anioMax,anioMin)	      - Validadores.js
# funciones Requeridas:								|  Archivo en que se encuentra
	- ValidaDiaMesAnio(dia, mes, anio,anioMax,anioMin)	      - Validadores.js	
	- isEmpty(str)											  - EfectosFuncionales.js
*/
function ValidarFecha( campoFecha, anioMax,anioMin){
	var fecha = campoFecha.value;

	if(isEmpty(campoFecha.value))
	return "VACIO";
	
	var expregFecha = /\d\d?(\/|-)\d\d?(\/|-)\d\d\d\d/;
//	alert(fecha.search(expregFecha));
	if( fecha.length > 10
	||fecha.search(expregFecha) == -1 )
	return "ERROR_FORMATO_FECHA";

	var diaMesanio;
	if(fecha.indexOf('/')!=-1 )
	 diaMesanio =  fecha.split('/');
			else
	 diaMesanio =  fecha.split('-');
	if(ValidarFecha.arguments.length == 1){	 
	//Se colocan por defecto los rangos anios.
	var anioMax = 3000;
	var anioMin = 1900;
	}
	var resultado = ValidaDiaMesAnio(new Number(diaMesanio[0]), new Number(diaMesanio[1]), new Number(diaMesanio[2]),anioMax,anioMin);
        if (resultado != "DIA_MES_ANO_VALIDO" ) 
	  	   return resultado;


	       return "FECHA_VALIDA";

}


function formateaFecha(campoFecha){
	var fecha = campoFecha.value;

	if(isEmpty(campoFecha.value) || campoFecha!=10)
	return "VACIO";
	
	var expregFecha = /\d\d?(\/|-)\d\d?(\/|-)\d\d\d\d/;

	var diaMesanio;
	if(fecha.indexOf('/')!=-1 )
	 diaMesanio =  fecha.split('/');
			else
	 diaMesanio =  fecha.split('-');

	if(diaMesanio[0].length==1)
		diaMesanio[0]="0"+diaMesanio[0];
	if(diaMesanio[1].length==1)
		diaMesanio[1]="0"+diaMesanio[1];
				
	campoFecha.value=diaMesanio[0]+"/"+diaMesanio[1]+"/"+diaMesanio[2]
}

function fechaesmayorque( fechamayor,fechamenor){  /*da igual si viene con / o con - pero que venga dd?mm?yyyy */

var dia1;
var dia2;
var mes1;
var mes2;
var anio1;
var anio2;

dia1=Number(fechamayor.substring(0,2));
dia2=Number(fechamenor.substring(0,2));
mes1=Number(fechamayor.substring(3,5));
mes2=Number(fechamenor.substring(3,5));
anio1=Number(fechamayor.substring(6,10));
anio2=Number(fechamenor.substring(6,10));

if (anio1>anio2)
	return true;
else if (anio1==anio2)
	if (mes1>mes2)
		return true;	
	else if (mes1==mes2)
			if (dia1>dia2)
				return true;
			else if (dia1==dia2)
				return false;
			else
				return false;
	else
		return false;
else
	return false;

}

/******************************************
* Descripcion:  Valida dias, meses y años.
- parametros:
	* @ dia : dia a validar.
	* @ mes : mes a validar.
	* @ anio : año a validar.		
	* @ anioMax : es el año maximo valido.
	* @ aniMin : es el año minimo valido.	
- Retorna: un String.
	- NO_ES_DIA: Indica que el parametro dia no contiene un numero de dia valido. 
	- NO_ES_MES: Indica que el parametro mes no contiene un numero de mes valido. 
	- DIA_INVALIDO : Indica que el parametro dia no contiene un numero de dia valido para el numero del mes dado.  
	- ANO_NO_BISIESTO : Indica que el año no es bisiesto.
	- DIA_MES_ANO_VALIDO : indica que el dia,el mes y el año son validos.
# Retorna los errores de:
	|Nombre de la funcion                   |Archivo en que se encuentra
	- ValidaAnio(anio,anioMax,anioMin)	      - Validadores.js
*/

function ValidaDiaMesAnio(dia, mes, anio,anioMax,anioMin)
{
	// Valida cantidad maxima de dias
	if (dia > 31||dia < 1) 
		return "NO_ES_DIA";
	// Valida cantidad maxima de meses
	if (mes > 12||mes < 1)
		return "NO_ES_MES";
	// Valida los meses de 30 dias
	if ((mes==4||mes==6||mes==9||mes==11)&&(dia>30))
		return "DIA_INVALIDO";

	// Valida febrero
	if (mes==2 && dia>28 && anio%4!=0) 
		return "ANO_NO_BISIESTO";
	if(mes ==2 && dia > 29)
		return "NO_ES_DIA";
var resultado = ValidaAnio(anio,anioMax,anioMin);
	if(resultado != "ANIO_VALIDO" )
		return	resultado;
	return "DIA_MES_ANO_VALIDO";
}
/*************************Version 1.0 ***********************************************
* Descripcion:  Valida si un año es valido. 
* @<autor>: Hugo Martinez
- parametros:
	* @ anio : número que contiene el año a validar.		
	* @ anioMax : número que contiene el año maximo valido.
	* @ aniMin : número que contiene el año minimo valido.	
- Retorna: un String.
	- ANIO_VACIO: Indica que el parametro año es vacio. 
	- ANIO_MAYOR:  Indica que el parametro año es mayor que el permitido. 
	- ANIO_MENOR : Indica que el parametro año es menor que el permitido. 
	- ANIO_VALIDO : Indica que el parametro año es valido .
# Funciones Utilizadas:
	|Nombre de la funcion                   |Archivo en que se encuentra
	- isEmpty(str)						      - EfectosFuncionales.js
# Funciones Requeridas: 				    |Archivo en que se encuentra	
	- isEmpty(str)						      - EfectosFuncionales.js	-
*/
function ValidaAnio(anio,anioMax,anioMin){
if(isEmpty(anio))
	return "ANIO_VACIO"
else if(anio > anioMax)
	return "ANIO_MAYOR";
else if(anio < anioMin)
	return "ANIO_MENOR";
return"ANIO_VALIDO"
}
/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que valida un rut de acuerdo al algoritmo del digito verificador.
* @<autor>: Hugo Martinez
- parametros:
	* @rut: String o cadena que contine el rut a validar.
	* @dv: String que contiene el digito verificador del rut.
- Retorna: un booleano .
	* true: si es un rut valido.
	* false : no es un rut valido.
*/
function ValidarRut(rut, dv) {
    var suma = 0;
    var mul = 2;
    var i = 0;
    for (i = rut.length-1; i >= 0; i--) {
        suma = suma + rut.charAt(i) * mul;
        mul = mul==7 ? 2 : mul+1;
    }
    var dvr = '' + (11 - suma % 11);
    if (dvr == '10')
        dvr = 'K';
    else if (dvr=='11')
        dvr = '0';
    if (dvr != dv.toUpperCase() )
        return false;
    else
        return true;
}
/*************************Version 1.0 ***********************************************
* Descripcion: Funcion que valida un direccion de correo electronico.
* @<autor>: Hugo Martinez
- parametros:
	* @src: String o cadena que el rut a validar.
- Retorna: un booleano .
	* true: si es correo valido.
	* false : no es correo valido.
*/
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is.nav5up and is.ie5up (see below).
// Revised 21 Nov 00 to add is.gecko and is.ie5_5 Also Changed is.nav5 and is.nav5up to is.nav6 and is.nav6up
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4, 
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
//                      add is.aol5, is.aol6
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask ... "Is" is the constructor function for "is" object,
// which has properties indicating:
// (1) browser vendor:
//     is.nav, is.ie, is.opera, is.hotjava, is.webtv, is.TVNavigator, is.AOLTV
// (2) browser version number:
//     is.major (integer indicating major version number: 2, 3, 4 ...)
//     is.minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is.nav2, is.nav3, is.nav4, is.nav4up, is.nav6, is.nav6up, is.gecko, is.ie3, 
//     is.ie4, is.ie4up, is.ie5, is.ie5up, is.ie5_5, is.ie5_5up, is.ie6, is.ie6up, is.hotjava3, is.hotjava3up,
//     is.opera2, is.opera3, is.opera4, is.opera5, is.opera5up, is.aol3, is.aol4, is.aol5, is.aol6
// (4) JavaScript version number:
//     is.js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is.win, is.win16, is.win32, is.win31, is.win95, is.winnt, is.win98, is.winme, is.win2k
//     is.os2
//     is.mac, is.mac68k, is.macppc
//     is.unix
//     is.sun, is.sun4, is.sun5, is.suni86
//     is.irix, is.irix5, is.irix6
//     is.hpux, is.hpux9, is.hpux10
//     is.aix, is.aix1, is.aix2, is.aix3, is.aix4
//     is.linux, is.sco, is.unixware, is.mpras, is.reliant
//     is.dec, is.sinix, is.freebsd, is.bsd
//     is.vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when Nav5 and IE5 (or later) are released, so
// in conditional code forks, use is.nav4up ("Nav4 or greater")
// and is.ie4up ("IE4 or greater") instead of is.nav4 or is.ie4
// to check version in code which you want to work on future
// versions.


function ObtieneInfoCliente()
{   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is.ie5up to detect IE5
    // or is.ie6up to detect IE6.

    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);


    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is.aol, is.aol3, and is.aol4 aren't 100% reliable.
    this.aol   = (agt.indexOf("aol") != -1);
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);
    this.aol5  = (agt.indexOf("aol 5") != -1);
    this.aol6  = (agt.indexOf("aol 6") != -1);

    this.opera = (agt.indexOf("opera") != -1);
    this.opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.opera5up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4);

    this.webtv = (agt.indexOf("webtv") != -1); 

    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    this.AOLTV = this.TVNavigator;

    this.hotjava = (agt.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    if (this.nav2 || this.ie3) this.js = 1.0;
    else if (this.nav3) this.js = 1.1;
    else if (this.opera5up) this.js = 1.3;
    else if (this.opera) this.js = 1.1;
    else if ((this.nav4 && (this.minor <= 4.05)) || this.ie4) this.js = 1.2;
    else if ((this.nav4 && (this.minor > 4.05)) || this.ie5) this.js = 1.3;
    else if (this.hotjava3up) this.js = 1.4;
    else if (this.nav6 || this.gecko) this.js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (this.nav6up) this.js = 1.5;
    // note ie5up on mac is 1.4
    else if (this.ie5up) this.js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else this.js = 0.0;

}

/****************************/
/*DHTML SIMULADOR CUOTAS*/

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.left = newXCoordinate+"px";
	styleObject.top = newYCoordinate+"px";
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject



var xOffset = -200;
var yOffset = 10;

function showPopup (targetObjectId, eventObj) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	//var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
//	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:document.documentElement.scrollLeft);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop);

	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup



var xOffsetEYN = -200;
var yOffsetEYN = 10;

function showPopupEYN (targetObjectId, eventObj) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)
	var newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffsetEYN:eventObj.x + xOffsetEYN + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffsetEYN:eventObj.y + yOffsetEYN + ((document.body.scrollTop)?document.body.scrollTop:0);
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);
	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopupEYN() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} 


// initialize hacks whenever the page loads
window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}

function ofCheckData(theForm)
{
	var lsEmail=theForm.elements["email"].value;
	var lsName=theForm.elements["nombre"].value;
	var lsTextQ=theForm.elements["texto_consulta"].value;
	var TypeQ=theForm.elements["tipo_consulta"].value;
	lsEmail=ofTrim(lsEmail);
	lsName=ofTrim(lsName);
	lsTextQ=ofTrim(lsTextQ);
	if (lsName==null || lsName=='') {
			alert('El nombre ha sido mal especificado');
			theForm.elements["nombre"].focus();
			return false;
	}
	if (lsEmail!=null && lsEmail!='') {
		if (ofEMailCheck(lsEmail)==false) {
			alert('El e-mail ha sido mal especificado');
			theForm.elements["email"].focus();
			return false;
		}
	} else {
		alert('No ha especificado un e-mail al cual notificar');
		theForm.elements["email"].focus();
		return false;
	}
	
	//theForm.elements["texto_consulta"].value=theForm.elements["texto_consulta"].value+" La consulta es: " +theForm.elements["texto_consulta1"].value;
	
	if (lsTextQ==null || lsTextQ=='') {
			alert('El texto de la consulta ha sido mal especificado');
			theForm.elements["texto_consulta"].focus();
			return false;
	}
	if (TypeQ=="01") {
			alert('El tipo de consulta ha sido mal especificado');
			theForm.elements["tipo_consulta"].focus();
			return false;
	}
	
	
	return true;
}





function revisa(formu){
	formu.meses.value=formu.mesestemp.value;
var marcados="";
for(i = 0; i < formu.banco.length; i++){
 	if(formu.banco[i].checked)  marcados=marcados+formu.banco[i].value+";";
 }   
formu.marcados.value=marcados;
err=0;
errortext="Errores:\n";

if(!IsNumeric2(parseInt(formu.meses.value)) || formu.meses.value==""){ 
	errortext=errortext+"Los meses son incorrectos\n";
 formu.mesestemp.focus();
 err=1;
 } else if(parseInt(formu.meses.value)<6 || parseInt(formu.meses.value)>72 ){ 
 	errortext=errortext+"Los meses deben ser entre 6 y 72\n";
 formu.mesestemp.focus();
 err=1;
 } 
if(!IsNumeric2(formu.monto.value) || formu.monto.value==""){ 	
	errortext=errortext+"El monto es incorrecto\n";
 formu.montotemp.focus();
 err=1;
 } else if(parseInt(formu.monto.value)<100000 || parseInt(formu.monto.value)>50000000 ){  
 	errortext=errortext+"El monto debe estar entre 100.000 y 50.000.000\n";
  formu.montotemp.focus();
 err=1;
 }
if(err==0)
formu.submit();
 else 
 	alert(errortext);
 }


function revisa2(formu){
	
var marcados="";
for(i = 0; i < formu.banco.length; i++){
 	if(formu.banco[i].checked)  
 		marcados=marcados+formu.banco[i].value+";";
 }   

if(marcados!="")
formu.marcados.value=marcados;
else
	formu.marcados.value=formu.banco.value+";";
err=0;
errortext="Errores:\n";

if(parseInt(formu.plazo.value)==0){ 
 errortext=errortext+"El plazo es incorrecto\n";
 formu.plazo.focus();
 err=1;
 } 
 
if(!IsNumeric2(formu.monto.value) || formu.monto.value==""){ 	
	errortext=errortext+"El monto es incorrecto\n";
 formu.montotemp.focus();
 err=1;
 }else if(parseInt(formu.tipomoneda.value)==2 && (parseInt(formu.monto.value)<parseInt(formu.minpeso.value) || parseInt(formu.monto.value)>parseInt(formu.maxpeso.value))){  
 	errortext=errortext+"El monto en pesos debe estar entre "+ parseInt(formu.minpeso.value) +" y "+parseInt(formu.maxpeso.value)+"\n";
  formu.montotemp.focus();
 err=1;
 }else if(parseInt(formu.tipomoneda.value)==1 && (parseInt(formu.monto.value)<parseInt(formu.minuf.value) || parseInt(formu.monto.value)>parseInt(formu.maxuf.value))){  
 	errortext=errortext+"El monto en UF debe estar entre "+parseInt(formu.minuf.value)+" y "+parseInt(formu.maxuf.value)+"\n";
  formu.montotemp.focus();
 err=1;
 }

if(err==0)
	formu.submit();
 else 
 	alert(errortext);
}

function IsNumeric2(sText){ 
	var ValidChars = '0123456789';
  var IsNumber=true;
  var Char;
  for (i = 0;
 i < sText.length && IsNumber == true; i++)   {     
 	Char = sText.charAt(i);
  if (ValidChars.indexOf(Char) == -1)   {  
  	IsNumber = false;
   }  
   }   return IsNumber;
  }

function IsNumeric(sText){ 
	var ValidChars = '0123456789.';
  var IsNumber=true;
  var Char;
  for (i = 0;
 i < sText.length && IsNumber == true; i++)   {     
 	Char = sText.charAt(i);
  if (ValidChars.indexOf(Char) == -1)   {  
  	IsNumber = false;
   }  
   }   return IsNumber;
  }


function marcatodos(formObj)
{ for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if (fldObj.type == 'checkbox')
      { 
         if(todosm){
            fldObj.checked = (fldObj.checked) ? false : true;
         }
         else{
           fldObj.checked = true;
         }
       }
   }
   todosm=!todosm;
   formObj.todos.checked=todosm;
}

function revisamonto(formu){
 formu.montotemp.value=replaceChars(formu.montotemp.value);
 formu.monto.value=formu.montotemp.value;
 formu.montotemp.value=addseps(formu.montotemp.value);
 montobak=formu.montotemp.value;
}

function revisamonto2(formu){
	var err=0;
	var errortext="";
 		formu.montotemp.value=replaceChars(formu.montotemp.value);
 		formu.monto.value=formu.montotemp.value;
 		formu.montotemp.value=addseps(formu.montotemp.value);
 		
		montobak=formu.montotemp.value;
 		
		if(!IsNumeric2(formu.monto.value)){ 	
			errortext=errortext+"El monto es incorrecto\n";
			formu.monto.value="";
			formu.montotemp.value="";
		 	formu.montotemp.focus();
		 	err=1;
		 }else if(parseInt(formu.tipomoneda.value)==2 && (parseInt(formu.monto.value)<parseInt(formu.minpeso.value) || parseInt(formu.monto.value)>parseInt(formu.maxpeso.value))){  
		 	errortext=errortext+"El monto en pesos debe estar entre "+ addseps(parseInt(formu.minpeso.value)) +" y "+addseps(parseInt(formu.maxpeso.value))+"\n";
		 	formu.monto.value="";
		 	formu.montotemp.value="";
		 	writetoLyr('lay1','');
		  formu.montotemp.focus();
		 	err=1;
		 }else if(parseInt(formu.tipomoneda.value)==1 && (parseInt(formu.monto.value)<parseInt(formu.minuf.value) || parseInt(formu.monto.value)>parseInt(formu.maxuf.value))){  
		 	errortext=errortext+"El monto en UF debe estar entre "+addseps(parseInt(formu.minuf.value))+" y "+addseps(parseInt(formu.maxuf.value))+"\n";
		 	formu.monto.value="";
		 	formu.montotemp.value="";
		 	writetoLyr('lay1','');
		  formu.montotemp.focus();
		 	err=1;
		 } 		

		if(err==1){
			alert(errortext);
			return false;
		}else{
	 		if(parseInt(formu.tipomoneda.value)==2){
				formu.montouf.value=(Math.round((parseFloat(formu.monto.value)/parseFloat(formu.uf.value))*100))/100;
			}else{
				formu.montopeso.value=Math.round(parseFloat(formu.monto.value)*parseFloat(formu.uf.value));
			}
			return true;
		}
		
}


	function revisacombos(formu){
		if (parseInt(formu.tipocredito.value)==1 || parseInt(formu.tipocredito.value)==2)
			if(parseInt(formu.tipotasa.value)!=1 && parseInt(formu.tipotasa.value)!=0){
				formu.tipotasa.value=1;
				alert("Para el tipo de cr"+decodeURI('%C3%A9')+"dito seleccionado el "+ decodeURI('%C3%BA') +"nico tipo de tasa posible es fija")
			}else if (parseInt(formu.tipotasa.value)==0){
				formu.tipotasa.value=1;
			}
	}

function addseps(x) {
var x=x;x+="";iLen=x.length;
pos=x.indexOf(",");
if (pos>-1)
{
iLen=pos;
}
temp="";
temp=x.substring(iLen,x.length);
for (var i=iLen-1;i>=0;i--)
if ((iLen-i-1)%3==0&&i!=iLen-1)
temp=x.charAt(i)+"."+temp;
else
temp=x.charAt(i)+temp;
return temp;
}

function replaceChars(entry) {
out = ".";
add = "";
temp = "" + entry;
while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
} 
return temp;
}

/*saca los puntos y luego reemplaza comas por puntos */
function replaceChars2(entry) {
	entry=replaceChars(entry);
out = ",";
add = ".";
temp = "" + entry;
while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
} 
return temp;
}


function writetoLyr(name, message) {
    if (document.layers) {
        document.layers[name].document.close();
        document.layers[name].document.write(message);
        document.layers[name].document.close();
    }else {
        if (document.all) {
            eval("document.all." + name + ".innerHTML='" + message + "'");
        }else {
            document.getElementById(name).innerHTML = message;
        }
    }
}

function CheckBusq(theForm){
	var lsTexto=theForm.elements["q"].value;
	lsTexto=ofTrim(lsTexto);
if (lsTexto==null || lsTexto=='') {
			alert('Debe ingresar los párametros de búsqueda');
			theForm.elements["q"].focus();
			return false;
}
return true;
}


// Funciones validadoras de Simuladores

		function revisatipocredito(formulario){
		if ((obtenerValorSeleccionado(formulario.tipocredito)=='1' || obtenerValorSeleccionado(formulario.tipocredito)=='2') && (obtenerValorSeleccionado(formulario.tipotasa) !='1' && obtenerValorSeleccionado(formulario.tipotasa)!='0')){
		alert("Para el tipo de cr"+decodeURI('%C3%A9')+"dito seleccionado el "+ decodeURI('%C3%BA') +"nico tipo de tasa posible es fija");
		return false;
		}else {	return true; }
		}
		
        	function validaboton(formObj){
		ver = false;
		for(var i=0; i < formObj.marcados.length; i++){
			if(formObj.marcados[i].checked)
			ver = true;
		}
		//if (document.getElementById)
			// this is the way the standards work
			var style2 = document.getElementById("boton").style;
		//else if (document.all)
			// this is the way old msie versions work
		//	var style2 = document.all["boton"].style;
		
		if (ver  || formObj.marcados.checked) {
		 style2.display = "block";
		}
		else {
		 style2.display = "";
		}
		}
		
		function revmonto(formu){
		var err=0;
		var errortext="";
 		
		if(!IsNumeric2(formu.monto.value)){ 	
			errortext=errortext+"El monto es incorrecto\n";
			formu.monto.value="";
		 	err=1;
		 }else if(obtenerValorSeleccionado(formu.tipomoneda)=='2' && (parseInt(formu.monto.value)<parseInt(formu.minpeso.value) || parseInt(formu.monto.value)>parseInt(formu.maxpeso.value))){  
		 	errortext=errortext+"El monto en pesos debe estar entre "+ addseps(parseInt(formu.minpeso.value)) +" y "+addseps(parseInt(formu.maxpeso.value))+"\n";
		 	formu.monto.value="";
		 	err=1;
		 }else if(obtenerValorSeleccionado(formu.tipomoneda)=='1' && (parseInt(formu.monto.value)<parseInt(formu.minuf.value) || parseInt(formu.monto.value)>parseInt(formu.maxuf.value))){  
		 	errortext=errortext+"El monto en UF debe estar entre "+addseps(parseInt(formu.minuf.value))+" y "+addseps(parseInt(formu.maxuf.value))+"\n";
		 	formu.monto.value="";
		  	err=1;
		 } 		

		if(err==1){
			alert(errortext);
			return false;
		}else{
	 	
			return true;
		}
		}
	
		function obtenerValorSeleccionado(radio){
		for(i=0;i< radio.length;i++){
		//alert("Largo "+radio.length+"->> "+radio[i].checked );
			if(radio[i].checked == true ){
			//alert("Radio "+radio[i].name+" "+radio[i].value);
			return radio[i].value;
			}
		}
		return "";
		}

function Valida_Rut( Objeto )
	{
	var tmpstr = "";
	var intlargo = Objeto.value
	if (intlargo.length> 0)
	{
		crut = Objeto.value
		largo = crut.length;
		if ( largo <2 )
		{
			alert('rut inválido')
			Objeto.focus()
			return false;
		}
		for ( i=0; i <crut.length ; i++ )
		if ( crut.charAt(i) != ' ' && crut.charAt(i) != '.' && crut.charAt(i) != '-' )
		{
			tmpstr = tmpstr + crut.charAt(i);
		}
		rut = tmpstr;
		crut=tmpstr;
		largo = crut.length;
	
		if ( largo> 2 )
			rut = crut.substring(0, largo - 1);
		else
			rut = crut.charAt(0);
	
		dv = crut.charAt(largo-1);
	
		if ( rut == null || dv == null )
		return 0;
	
		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 != dv.toLowerCase() )
		{
			alert('El Rut Ingresado es Invalido')
			Objeto.focus()
			return false;
		}
		//alert('El Rut Ingresado es Correcto!')
		Objeto.focus()
		return true;
	}
	}		

