
function Replace(Expression, Find, Replace)
{ 
    if (Expression==null || String(Expression) == 'undefined')
        return Expression;
	var temp = Expression;
	var a = 0;
	
	for (var i = 0; i < Expression.length; i++)
	{
	a = temp.indexOf(Find);
	if (a == -1)
		break
	else
		temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
		Expression.value=temp;
	}
	return temp;
}

/*======================================================================================
Entrega la Posición de un determinado caracter dentro de un string
InString: String a evaluar.
Char : Caracter a encontrar.
*/
function PosChar(InString, Char)
{
	Char = Char.toLowerCase();
	for ( pos=0; pos < InString.length ; pos++){
		if ( InString.charAt(pos).toLowerCase() == Char ) {
			return pos++;
		}
	}
	return 0;		
}
/*======================================================================================
Entrega la cantidad de caracteres de la izquierda de un string
InString: String a evaluar.
cantidad: Numero de caracteres desde la izquierda
*/
function left(InString, cantidad)
{
	if (cantidad > InString.length){
		return InString
	}
	InString = InString.substring(0, cantidad);
	return InString
}
/*======================================================================================
Entrega la cantidad de caracteres de la derecha de un string
InString: String a evaluar.
cantidad: Numero de caracteres desde la derecha
*/
function right(InString, cantidad)
{
	if (cantidad > InString.length){
		return InString
	}
	InString = InString.substring(InString.length - cantidad, InString.length);
	return InString
}


/*======================================================================================
*/
function TodasMayusculas(Obj){
	Obj = trim(Obj);
	if (Obj.value != ''){
		Obj.value = Obj.value.toUpperCase();
	}
	return Obj;
}

function TodasMinusculas(Obj){
	Obj = trim(Obj);
	if (Obj.value != ''){
		Obj.value = Obj.value.toLowerCase();
	}
	return Obj;
}

function PrimeraMayuscula(Obj){
	Obj = trim(Obj);
	InString = Obj.value;
	if (InString != ''){
		Primera = InString.charAt(0);
		Primera = Primera.toUpperCase();
		if (InString.length > 1){
			InString = Primera + InString.substring(1,InString.length);
		}
		else {
			InString = Primera;
		}
	}
	Obj.value = InString;
	return 
}



function InicialesMayusculas(Obj){
	Obj = trim(Obj);
	InString = Obj.value;
	if (InString != ''){
		Amay = InString.charAt(0);
		Amay = Amay.toUpperCase();
		InString = Amay + InString.substring(1,InString.length);
		for (i=1; i < InString.length;i++){
			if (InString.charAt(i) == ' '){
				Amay = InString.charAt(i+1);
				Amay = Amay.toUpperCase();
				InString = InString.substring(0,i+1) + Amay + InString.substring(i+2,InString.length);
			}	
		}
	}
	Obj.value = InString;
	return 
}


/*======================================================================================
Funcion que elimina los blancos a la izquierda de un string.
Obj: Objeto que contiene Strin a eliminar blancos de la izquierda.
Retorna :Un Objeto
*/
function ltrim(obj) {
	if( typeof(obj) == 'object')
	{
        if( (obj.value==null) || (obj.value+''=='undefined') )
             var InString = '' 
        else
             var InString = obj.value; 
    }
    else
       var InString = obj;
             
	var n = i = 0;
	while (i < InString.length) {
		if (InString.charAt(i) != " ") {
			n = i
			break
		}
		i++
	}
	if (n == 0 && i == InString.length)
		obj.value = ''
	else
		obj.value = InString.substring(n, InString.length)
	return obj;
}

/*======================================================================================
Elimina los blancos a la derecha de un string.
obj:	objeto que contiene string a eliminar blancos de la derecha
Retorna: Un Objeto	
*/
function rtrim(obj) {
	if( typeof(obj) == 'object')
	{
        if( (obj.value==null) || (obj.value+''=='undefined') )
             var InString = '' 
        else
             var InString = obj.value; 
    }
    else
       var InString = obj;
	
	var n = i = InString.length
	while (i > 0) {
		if (InString.charAt(i - 1) != " ") {
			n = i
			break
		}
		i--
	}
	if (n == InString.length && i == 0)
		obj.value = ''
	else
		obj.value = InString.substring(0, n);
	return obj;
}

/*======================================================================================
Elimina los blancos de los extremos de un string.
Obj:	objeto que contiene string a eliminar blancos de los extremos
Retorna: Un Objeto	
*/

function trim(Obj) {
	return rtrim(ltrim(Obj));
}



// Suma la columna de una tabla
function XS_SumColumn(Tabla, nCol, lTotalizer)
{
	var nSuma = 0;
	if (lTotalizer == true)
		 var nFilas = Tabla.rows.length-1
  else
		 var nFilas = Tabla.rows.length;
  	
  	
	for(var r=1;r<nFilas;r++)
	{
			aFila = Tabla.rows[r].cells;
			nValor = aFila[nCol-1].innerText;
			if (nValor != '')
			{
					nValor = Replace(nValor,'.','');
				  nSuma = nSuma + parseInt(nValor)
		  }
	}	 				 	
	return nSuma
}



function ValidaInputTexto(sText)
{
var IsOk;
var Char;
IsOk=true;
//if (sText.length==0)
	//IsOk=false;
for (i = 0; i < sText.length && IsOk == true; i++)
	{
	Char = sText.charAt(i);
	if (esCaracterInvalido(Char))
		{
		IsOk = false;
		}
	}
return IsOk;	
}

function ValidaCaracter(sText, sCaracteresAdicionales)
{

var Char;
var nPos = -1;

for (i = 0; i < sText.length && nPos == -1; i++)
{
	Char = sText.charAt(i);
	if (esCaracterInvalido(Char))
	{
	    if ( sCaracteresAdicionales != null)
	    {
	       var sAux = sCaracteresAdicionales.toString();
           if (sAux.indexOf (Char, 0) == -1) 
              nPos = i;  
	    }
	    else
		    nPos = i;
	}
}
return nPos;	
}


function ValidaRutDigito(strObjRut, strObjDig) {

	var dvr = '0'
	suma = 0
	mult = 2

	for ( i = strObjRut.length - 1 ; i >= 0 ; i -- ) {
		suma = suma + strObjRut.charAt(i) * mult;
		if ( mult == 7 )
			mult = 2;
		else
			mult ++;
	}
	res = suma % 11;
	if ( res == 1 )
		dvr = 'k';
	else {
		if ( res == 0 )
			dvr = '0';
		else {
			dvi = 11 - res;
			dvr = dvi + "";
		}
	}
	if ( dvr != strObjDig.toLowerCase() )
		return false;
	return true;
}

 
function validaRut(objRut)
{	var strdig
	var str
	var rut
	

	if(objRut.value){
		
		objRut.value = Replace(objRut.value, ".","")
		rut = new String(objRut.value)
		
		strdig = new String(right(rut,1))
		str = new String(left(rut, rut.length-2))
	
		
		if (!ValidaRutDigito(str,strdig))
		 {
		 objRut.value = "";
		 objRut.focus();
		 alert("El Rut ingresado no es valido");
		 return(false);
		 }

		 return(true);
	}
	else
	{
		alert("Debe ingresar un rut válido")
	    objRut.focus();
		return(false)
	}

}


/*-------------------------------------------------------------------
Funcion que verifica si un Email es valido
Obj: Objeto que contiene el Email a evaluar
Retorna : Nulo
*/

function esEmail(Obj) {
	
	Obj = trim(Obj);
	band = true;
	InString = Obj.value;
	RefString = 'abcdefghijklmnopqrstuvwxyz-_.@';
	cont=puntos=0;
	for (i=0;i < InString.length; i++){
		car = InString.charAt(i);
		car = car.toLowerCase();
		if (RefString.indexOf(car, 0) == -1) 
    		band=false;
    	if ( car == '@'){
			cont++;
		}
		if (cont > 0){
			puntos++;
		}
	}
	if (InString.charAt(InString.length - 1) == '.' || cont > 1 || puntos < 1 || InString.indexOf('@.') != -1 || InString.indexOf('.@') != -1 || band == false){
		alert("Error: \""+InString+"\" no es una dirección valida de mail.")
		InString='';
		Obj.focus();
		band=false;
	}
	Obj.value = InString;	
	return band;
	
}

function esReal(InString, Signo){
		i=0;
		
		c=InString.charAt(i);   // Saca el signo 
		if (c == '-') {			
			if (Signo == '+') return false;
			InString=InString.substring(i+1, InString.length)
		}
		else if (c == '+'){
			if (Signo == '-') return false;
			InString=InString.substring(i+1, InString.length)
		}
		else if (c >= '0' && c <= '9') {   // Si no trae asume que es positivo
				if (Signo == '-') return false
		}
		puntos=posicion=0;
		for (cont=0; cont < InString.length; cont++) { 
			if (InString.charAt(cont) == ',')
			{
				puntos = puntos + 1;
				posicion = cont;
			}
		}
		if (puntos > 1) return false;
		if (puntos == 1 && InString.length == 1) return false;
		if (InString.length > 1){ 
			if (posicion+1 == InString.length) return false;
		}
		InString = Replace(InString,',','');  //Saca el punto 
		if (!SoloTipo(InString,'9'))  //valida que sean solo numeros
			return false;
		return true;
}

function esCaracterInvalido(Char) {
    	if(Char.length!=1) 
    		return false;
    	Char=Char.toLowerCase();
    
   	RefString='1234567890abcdefghijklmnñopqrstuvwxyz áéíóúü()*+,-./:;=?[\]_{}|';
   	
    	if (RefString.indexOf (Char, 0) == -1) 
    		return true;
    	return false;
}	


/*======================================================================================
Funcion que verifica si un numero es entero.
InString	: String a evaluar.
Signo		: '+' Solo Positivos
			  '-' Solo Negativos
			  ' ' Acepta positivos y negativos 
Retorna : Un Booleano
*/
function esEntero(InString, Signo){
		i=0;
		
		if (InString==0){return true;} //Si el numero es cero el resultado de la funcion es verdadero
		
		c=InString.charAt(i);   // Saca el signo 
		if (c == '-') {			
			if (Signo == '+') return false;
			InString=InString.substring(i+1, InString.length)
		} 
		else if (c == '+'){
			if (Signo == '-') return false;
			InString=InString.substring(i+1, InString.length)
		}
		else if (c >= '0' && c <= '9') {   // Si no trae asume que es positivo
				if (Signo == '-') return false
		}
		if (!SoloTipo(InString,'9'))  //valida que sean solo numeros
			return false;
		return true;
}


/*======================================================================================    
Funcion que verifica si una fecha es valida
InString: String a evaluar
Formato:	dma (dia mes ano)
			mda (mes dia ano)
			amd (ano mes dia)
Observación: es utilizada por la funcion Ver_Fecha(Obj) (Siguiente)
Retorna : Un Booleano
*/
function EsFecha(InString,formato) {
		//Agrega ceros a la fecha		
		if (InString.substring(1,2)=="/") {
		  InString="0"+InString
		}
		if (InString.substring(4,5)=="/"){
		  InString=InString.substring(0,3)+"0"+InString.substring(3,9)
		}
	
		
		if (formato == "dma"){
			dia=InString.substring(0,2);
			mes=InString.substring(3,5);
			anyo=InString.substring(6,10);
		}
		if (formato == "mda"){
			mes=InString.substring(0,2);
			dia=InString.substring(3,5);
			anyo=InString.substring(6,10);
		}
		if (formato == "amd"){
			anyo=InString.substring(0,4);
			mes=InString.substring(5,7);
			dia=InString.substring(8,10);
		}
		if (dia == '08') dia = '8';	// parseInt("08") == 10		base octogonal
		if (dia == '09') dia = '9';	// parseInt("09") == 11		base octogonal
		if (mes == '08') mes = '8';	// parseInt("08") == 10		base octogonal
		if (mes == '09') mes = '9'; // parseInt("09") == 11		base octogonal
		dia=parseInt(dia);
		mes=parseInt(mes);
		anyo=parseInt(anyo);
		if (anyo < 1900) return false;    // Anyo mayor a 1900 (por la Base de Datos)
		mes = mes - 1;  // El mes se representa del 0 al 11 (solo para la validación)
		esfecha = new Date(anyo,mes,dia);
		if (dia == esfecha.getDate()){
			if(mes == esfecha.getMonth()){
				if(anyo == esfecha.getFullYear()){
					return true;
				}
			}
		}
		return false;
}

/***************************************************************************************
Funcion que valida la fecha separada en Dia, Mes y Año.
Se debe pasar el objeto del campo.

***************************************************************************************/
function ValidaFecha(Dia, Mes, Ano)
{
if (Dia.value == "")
	{
	alert("Debe ingresar el día")
	Dia.focus()
	return false
	}
if (Mes.value == "")
	{
	alert("Debe ingresar el mes")
	Mes.focus()
	return false
	}
if (Ano.value == "")
	{
	alert("Debe ingresar el año")
	Ano.focus()
	return false
	}
if (Dia.value != "")
	{
	if (!SoloNumeros(Dia))
		{
		return false
		}
	}
if (Mes.value != "")
	{
	if (!SoloNumeros(Mes))
		{
		return false
		}
	}
if (Ano.value != "")
	{
	if (!SoloNumeros(Ano))
		{
		return false
		}
	}
if ((Dia.value != "") && (Mes.value != "") && (Ano.value != ""))
	{
	fecha = Dia.value + '/' + Mes.value + '/' + Ano.value 
	if (!EsFecha(fecha,'dma'))
		{
		alert("La fecha es incorrecta")
		Dia.focus()
		return false
		}
	}
return true
}



/*======================================================================================
Función que verifica que la entrada sea de un determinado tipo de dato
InStrin :	String a evaluar
tipo	:	9 - Numerico 
			A - Alfabetico
			X - AlfaNumerico
			D - Decimal
Retorna : Un Booleano
*/
function SoloTipo(InString, tipo){
		for (Cont=0; Cont < InString.length; Cont++) {
    		Char = InString.charAt(Cont);
    		if (tipo == '9') {
    			if(!esNumerico(Char))
    				return false;
    		}
    		else if (tipo == 'A') {
    			if(!esAlfabetico(Char))
    				return false;
    		}
    		else if (tipo == 'X') {
    			if(!esAlfaNumerico(Char))
    				return false;
    		}
    		else if (tipo == 'H') {
    			if(!esHexa(Char))
    				return false;
    		}
    		else if (tipo == 'D') {
                return !isNaN(InString);
    		}
		}
    	return true;
 }

/*======================================================================================
Funcion que solo permite el ingreso de datos en un determinado formato
InString	:	String a evaluar.
Mask		:	Formato que debe poseer el String a evaluar
				Ej: '99/99/9999' marcara para una fecha
				'9' - Numero
				'A' - Alfabetico
				'X' - AlfaNumerico
Retorna : Un Booleano
*/

function Mascara(InString, Mask) {
    	LenStr = InString.length;
    	LenMsk = Mask.length;
    	if ((LenStr==0) || (LenMsk==0))
    		return false;
    	if (LenStr != LenMsk)
    		return false;
    	TempString=""
    	for (Cont=0; Cont < InString.length; Cont++) {
    		StrChar = InString.charAt(Cont);
    		MskChar = Mask.charAt(Cont);
    		if (MskChar == '9') {
    			if(!esNumerico(StrChar))
    				return false;
    		}
    		else if (MskChar == 'A') {
    			if(!esAlfabetico(StrChar))
    				return false;
    		}
    		else if (MskChar == 'X') {
    			if(!esAlfaNumerico(StrChar))
    				return false;
    		}
    		else {
    			if (MskChar != StrChar) // compara otros caracteres
    				return false;		// ej: los / de la fecha
    		}
    	}
    	return true;
}
    
/*======================================================================================
Funcion que verifica si un caracter es Alfabetico (Acepta blancos)
Char	:	Caracter a evaluar.
Oservación: Si se necesita que esta funcion acepte otro caracter 
agregarlo al String de Referencia (RefString)
Retorna : Un Booleano
*/
    
function esAlfabetico(Char) {
    	if(Char.length!=1) 
    		return false;
    	Char=Char.toLowerCase();
    	RefString='abcdefghijklmnñopqrstuvwxyz áéíóúü';
    	if (RefString.indexOf (Char.toLowerCase(), 0) == -1) 
    		return false;
    	return true;
}
/*======================================================================================    
Funcion que verifica si un caracter es AlfaNumerico (Acepta Blancos)
Char	:	Caracter a evaluar.
Retorna : Un Booleano
*/
function esAlfaNumerico(Char) {
    	if(Char.length != 1) 
    		return false;
    	Char=Char.toLowerCase();
    	RefString='1234567890abcdefghijklmnñopqrstuvwxyz áéíóúü';
    	if (RefString.indexOf(Char,0) == -1) 
    		return false;
    	return true;
}

/*======================================================================================    
Funcion que verifica si un caracter es Numerico
Char	:	Caracter a evaluar.
Retorna : Un Booleano
*/
function esNumerico(Char) {		
    	if(Char.length!=1) 
    		return false;
    	RefString="1234567890";
    	if (RefString.indexOf(Char, 0) == -1) 
    		return false;
    	return true;
}

/*======================================================================================    
Funcion que verifica si un caracter pertenece al rango de Hexadecimal
Char	:	Caracter a evaluar.
Retorna : Un Booleano
*/
function esHexa(Char) {
    	if(Char.length!=1) 
    		return false;
    	Char=Char.toLowerCase();
    	RefString="1234567890abcdef";
    	if (RefString.indexOf(Char, 0) == -1) 
    		return false;
    	return true;
}



	
	


function ValidaCampo(objCampo, sTipo, sLargo, sMensaje, sCaracteresAdicionales)
{
	sCampo = trim(objCampo).value;
	var nLar = sCampo.length;
	var sLar = sLargo.toString()
	var aRango = sLar.split(',')
	if (aRango.length == 1)	
	{
	    var nMin = parseInt(sLargo)
	    var nMax = -1
	} 	
	else
	{
	    var nMin = aRango[0]
	    var nMax = aRango[1]	
	}
	
	if (nLar == 0) 
	{
		  if (nMin > 0)
		  {
				alert(sMensaje + ": Debe ingresar un dato")
				objCampo.style.border = "1px solid #FF0000";
			    objCampo.focus();
				return false;			
		  }
	} 
    else
	{		
		  if (nMax > 0 && nLar > nMax)
		  {
				alert(sMensaje + ": Largo máximo permitido " + nMax)
				objCampo.style.border = "1px solid #FF0000";
			    objCampo.focus();
				return false;			
		  }		
	}
		
		
		if (sTipo == 'T')
		{
		    var nPos = ValidaCaracter(sCampo, sCaracteresAdicionales)
			if (nPos != -1)
			{
				alert(sMensaje + ": Ha ingresado un caracter inválido [ " + sCampo.charAt(nPos) + " ]");
			    objCampo.style.border = "1px solid #FF0000";
				objCampo.focus();
				return;
			}
			if ( nMin> 0)
			{
					if (nLar < nMin)
					{
							alert(sMensaje + ": Debe tener mínimo " + nMin + " caracteres")
				            objCampo.style.border = "1px solid #FF0000";
						    objCampo.focus();
							return false;
					}
			}
		}
		else
		if (sTipo == 'N')
		{
			if (!SoloTipo(sCampo, "9"))
			{
				objCampo.focus()
				objCampo.style.border = "1px solid #FF0000";
				alert(sMensaje + ": Número Inválido")
				return false
			}	
		}
		else
		if (sTipo == 'D')
		{
			sCampo = Replace(sCampo,",","")
			if (!SoloTipo(sCampo, "9"))
			{
				objCampo.style.border = "1px solid #FF0000";
				objCampo.focus()
				alert(sMensaje + ": Número Inválido")
				return false
			}	
		}
		else			
		if (sTipo == 'F')
		{
			sCampo = Replace(sCampo,"-","/")
			if (!EsFecha(sCampo, "dma"))
			{
				objCampo.focus()
				objCampo.style.border = "1px solid #FF0000";
				alert(sMensaje + ": Fecha Inválida")
				return false
			}	
		}
		else
		if (sTipo == 'R')
		{
			if (!validaRut(objCampo))
			{
				objCampo.style.border = "1px solid #FF0000";
				return false
			}	
		}
		else
		if (sTipo == 'C')
		{

			if (!esEmail(objCampo))
			{
				objCampo.style.border = "1px solid #FF0000";
				objCampo.focus()
		        if (sMensaje != null)
				   alert(sMensaje + ": Correo Inválido")
				return false
			}	
		}			
	objCampo.style.border = "1px solid #cccccc";
	return true;
}

// Formatea un número
function FormatNumber(numero) 
{
	var textFormato = "";
	var t = 0;
	var str = "";
	var strDec = "";
	var numeroAux = numero;

	str = numero.toString();
	if (str.indexOf(",") != -1) {
		strDec = str.substr(str.indexOf(",") + 1);
		str = str.substr(0, str.indexOf(","));
		numeroAux = str;
	}
	if ( str.length != 0 && (str.length)>3 ) 
	{
		for ( var k = str.length-1; k >= 0 ; k-- ) 
		{
			t++
			if ( t % 3 == 0 ) 
				textFormato = "." + str.substr(k, 1) + textFormato 
			else 
				textFormato = str.substr(k, 1) + textFormato; 
	    }
		
		if ( textFormato.substr(0, 1) == "," || textFormato.substr(0, 1) == ".") 
			numeroAux = textFormato.substr(1, textFormato.length - 1) 
		else
		{	
			numeroAux = textFormato 
	  }
	}
	if (strDec.length > 0)
		numeroAux = numeroAux + "," + strDec;
	return numeroAux;
}

function FormatNumberByMask(n, option)
{
	//Opciones
	var decimals 			= 0;
	var currency 			= false;	
	var formatWhole 		= false;
	
	//Constantes
	var wholeDelimiter 		= ".";
	var decimalDelimiter 	= ",";
	var currencySymbol 		= "$";
	
	if (option.split(decimalDelimiter).length > 1){ //Significa que existe decimal en el formato.	
		decimals = option.split(decimalDelimiter)[1].split("#").length - 1;
	}
	
	if (option.split(currencySymbol).length > 1){
		currency = true;
	}
	
	if (option.split(wholeDelimiter).length > 1){
		formatWhole = true;
	}

	var nArr = new Array();
	nArr = String(n).split(decimalDelimiter);
		
	var whole = (typeof nArr[0]!='undefined')?nArr[0]:'0';
	if(formatWhole){
		var exp = /(\d+)(\d{3})/;
		while (exp.test(whole)) {
			whole = whole.replace(exp, '$1' + wholeDelimiter + '$2');
		}
	}
	
	if(typeof nArr[1]!='undefined'){
		var remainder = nArr[1];
	}else{
		var remainder = '';
		for(var i=0;i<decimals;i++){remainder += '0'}
	}
	
	var pfix = currency?currencySymbol:'';

	if(decimals<=0) return pfix + whole;

	var a = new Array();
	for(var i = 0; i < decimals; i++){
		if(remainder.charAt(i) != '') a[i] = remainder.charAt(i);
		else a[i] = '0';
	}
	
	return pfix + whole + decimalDelimiter + a.join("");
}



function XS_ListOption(Obj, sParam)
{
    if (sParam == null)
        sCode = Obj.value     
    else
        sCode = sParam;
	var sRet = '';
	if (Obj.nodeName == 'SELECT')
	{
		aOptions = Obj.childNodes;
		for(var r=0;r<aOptions.length;r++)
		{
			if (aOptions[r].nodeName == 'OPTION')
			{
				if (aOptions[r].getAttribute('value') == sCode)
				{
				 		sRet = aOptions[r].innerHTML;
						break;
				}	
		  }
		}
	}	 
	return sRet;			
}	

function XS_SetOption(Obj, sCode)
{
	if (Obj.nodeName == 'SELECT')
	{
		aOptions = Obj.childNodes;
		for(var r=0;r<aOptions.length;r++)
		{
			if (aOptions[r].nodeName.toUpperCase() == 'OPTION')
			{
				if (aOptions[r].getAttribute('value') == sCode)
				{
				 		aOptions[r].setAttribute('selected', 'true');
						break;
				}	
		  }
		}
	}	 
	return 
}
//***************************************************************************************
function Comparar_Fecha(Obj1, Obj2, Formato) {
 // Obj1: objeto que contiene la primera fecha 
 // Obj2: objeto que contiene la segunda fecha 

   String1 = Obj1.value
   String2 = Obj2.value
   // Si los dia y los meses llegan con un valor menor que 10 
	// Se concatena un 0 a cada valor dentro del string  
	if (String1.substring(1,2)=="/") {
	  String1="0"+String1
	}
	if (String1.substring(4,5)=="/"){
	  String1=String1.substring(0,3)+"0"+String1.substring(3,9)
	}
	
	if (String2.substring(1,2)=="/") {
	  String2="0"+String2
	}
	if (String2.substring(4,5)=="/"){
	  String2=String2.substring(0,3)+"0"+String2.substring(3,9)
	 
	}
	
   if (Formato == "dma"){
		dia1=String1.substring(0,2);
		mes1=String1.substring(3,5);
		anyo1=String1.substring(6,10);
		dia2=String2.substring(0,2);
		mes2=String2.substring(3,5);
		anyo2=String2.substring(6,10);
   }

   if (Formato=="amd"){
   		dia1=String1.substring(8,10);
		mes1=String1.substring(5,7);
		anyo1=String1.substring(0,4);
		dia2=String2.substring(8,10);
		mes2=String2.substring(5,7);
		anyo2=String2.substring(0,4);
   }
   if (Formato == "mda"){
   		mes1=String1.substring(0,2);
		dia1=String1.substring(3,5);
		anyo1=String1.substring(6,10);
		mes2=String2.substring(0,2);
		dia2=String2.substring(3,5);
		anyo2=String2.substring(6,10);
   }
   
   if (dia1 == "08")	// parseInt("08") == 10		base octogonal
		dia1 = "8";
	if (dia1 == '09')	// parseInt("09") == 11		base octogonal
		dia1 = "9";
	if (mes1 == "08")	// parseInt("08") == 10		base octogonal
		mes1 = "8";
	if (mes1 == "09")	// parseInt("09") == 11		base octogonal
		mes1 = "9";
	if (dia2 == "08")	// parseInt("08") == 10		base octogonal
		dia2 = "8";
	if (dia2 == '09')	// parseInt("09") == 11		base octogonal
		dia2 = "9";
	if (mes2 == "08")	// parseInt("08") == 10		base octogonal
		mes2 = "8";
	if (mes2 == "09")	// parseInt("09") == 11		base octogonal
		mes2 = "9";
   dia1=parseInt(dia1);
   dia2=parseInt(dia2);
   mes1=parseInt(mes1);
   mes2=parseInt(mes2);
   anyo1=parseInt(anyo1);
   anyo2=parseInt(anyo2);
   
   
   if (anyo1>anyo2)
		{
		return false;
		}
	if ((anyo1==anyo2) && (mes1>mes2))
		{
		return false;
		}
	if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
		{
		return false;
		}	  
					  
	 return true;

}


	/*
	These cookie functions are downloaded from 
	http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
	*/	
	function Get_Cookie(name) { 
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	   if (start == -1) return null; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   return unescape(document.cookie.substring(len,end)); 
	} 

	// This function has been slightly modified
	function Set_Cookie(name,value,expires,path,domain,secure) { 
		expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
	} 

function XS_FormatCrLf(sHtml)
{
    var sCrLf = String.fromCharCode(10,13);
    sRet = sHtml.replace(sCrLf, '<br/>');
    return sRet;
}



//Normaliza Fecha
function XS_FormatDate(obj)
{
	var sFecha = trim(obj).value
	if (sFecha != '')
	{    
	      sFecha = Replace(sFecha, '-', '/')
			if (sFecha.substring(1,2) == "/") 
			  sFecha="0"+sFecha;
			  
			if (sFecha.substring(4,5) == "/")
			  sFecha=sFecha.substring(0,3)+"0"+sFecha.substring(3,9);
			        
         if (ValidaCampo(obj, "F", 0, "Formato de Fecha (dd/mm/aaaa)") )
			   obj.value = sFecha;
	}   
}


//Agrega a oParentNode un hijo de nombre sTag 
function XS_CreateChild(oParentNode,sTag)
{
	var oNode = document.createElement(sTag);
	oParentNode.appendChild(oNode);
	return oNode;
}

//Agrega a oParentNode un hijo de nombre sTag que tiene los atributos definidos en el arrego aAttrs
//XS_CreateChildWithAttrs(oDiv, 'img', [['src','/files/icons/icon_rotor.gif'], ['borde','0']]);
function XS_CreateChildWithAttrs(oParentNode, sTag, aAttrs)
{
	if (FireFoxDetect() || OperaDetect() )
	{
		var oNode = document.createElement(sTag);
		for (var i = 0; i < aAttrs.length; i++)
		{
			var t = aAttrs[i];
			var key = t[0];
			var val = t[1];
			oNode.setAttribute(key,val);
		}
	} else {
		var sAdd = '';
		for (var i = 0; i < aAttrs.length; i++)
		{
			var t = aAttrs[i];
			sAdd += ' ' + t[0] + '="'+ t[1] + '"';
		}
		sTag = '<' + sTag + sAdd + '>';
		var oNode = document.createElement(sTag);
	}
	oParentNode.appendChild(oNode);
	return oNode;
}

//Recupera una lista con los hijos de un elemento oParentNode que tiene la clase className
function XS_getChildElementsByClassName(oParentNode, className)
{
	var i, childElements, pattern, result;
	result = new Array();
	pattern = new RegExp("\\b"+className+"\\b");

	childElements = oParentNode.getElementsByTagName('*');
	for(i = 0; i < childElements.length; i++)
	{
		if(childElements[i].className.search(pattern) != -1)
		{
			result[result.length] = childElements[i];
		}
	}
	return result;
}


function _F_IsRut(strObjRut) 
{
	strRut = new String(strObjRut.value)			
	
	strDig = strRut.substring(strRut.length - 1, strRut.length);
	strObjDig = new String(strDig)
	
	strCuerpo = strRut.substring(0, strRut.length-2);
	strObjRut = new String(strCuerpo)

	var dvr = '0'
	suma = 0
	mult = 2

	for ( i = strObjRut.length - 1 ; i >= 0 ; i -- ) {
		suma = suma + strObjRut.charAt(i) * mult;
		if ( mult == 7 )
			mult = 2;
		else
			mult ++;
	}
	res = suma % 11;
	if ( res == 1 )
		dvr = 'k';
	else {
		if ( res == 0 )
			dvr = '0';
		else {
			dvi = 11 - res;
			dvr = dvi + "";
		}
	}
	if ( dvr != strObjDig.toLowerCase() )
		return false;

	return true;
}


function _F_IsDate(ObjDate,formato) 
{
		
		var InString = ObjDate.value;
		var dia = null, mes = null, anyo = null; 
		
		//Agrega ceros a la fecha		
		if (InString.substring(1,2)=="/") {
		  InString="0"+InString
		}
		if (InString.substring(4,5)=="/"){
		  InString=InString.substring(0,3)+"0"+InString.substring(3,9)
		}
		if (InString.substring(2,3)!="/")
			{
			return false;
			}
		if (InString.substring(5,6)!="/")
			{
			return false;
			}	
		if ( (formato == "dma") || (formato == "dmy") ){
			dia  = InString.substring(0,2);
			mes  = InString.substring(3,5);
			anyo = InString.substring(6,10);
		}
		if ( (formato == "mda") || (formato == "mdy") ){
			mes=InString.substring(0,2);
			dia=InString.substring(3,5);
			anyo=InString.substring(6,10);
		}
		if ( (formato == "amd") || (formato == "ymd") ){
			anyo=InString.substring(0,4);
			mes=InString.substring(5,7);
			dia=InString.substring(8,10);
		}
		
		if(dia == null)
		{
		    alert('_F_IsDate: Formato ' + formato + ' no reconocido');
		    return false;
		}
		
		strDate = dia + '/' + mes + '/' + anyo;

		if (dia == '08') dia = '8';	// parseInt("08") == 10		base octogonal
		if (dia == '09') dia = '9';	// parseInt("09") == 11		base octogonal
		if (mes == '08') mes = '8';	// parseInt("08") == 10		base octogonal
		if (mes == '09') mes = '9'; // parseInt("09") == 11		base octogonal

		dia=parseInt(dia);
		mes=parseInt(mes);
		anyo=parseInt(anyo);
		if (anyo < 1900) return false;    // Anyo mayor a 1900 (por la Base de Datos)
		mes = mes - 1;  // El mes se representa del 0 al 11 (solo para la validación)
		esfecha = new Date(anyo,mes,dia);
		if (dia == esfecha.getDate()){
			if(mes == esfecha.getMonth()){
				if(anyo == esfecha.getFullYear())
				{
					ObjDate.value = strDate;
					return true;
				}
			}
		}
		
		return false;
}

function _F_captureEnter(e)
{
    var keynum;
    if(window.event) // IE
        {
        keynum = e.keyCode;
        }
    else if(e.which) // Netscape/Firefox/Opera
        {
        keynum = e.which;
        }
    return (keynum==13);
}

function _F_onlyNumbers(e)
{
    var keynum;
    var keychar;
    var numcheck;
	//e = e || window.event;
	//keynum = e.keyCode || e.which;
	
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
		if (keynum == Event.KEY_BACKSPACE)
			return true;
	}
	else
	{
		keynum = e.keyCode;
		if (keynum == Event.KEY_TAB || keynum == Event.KEY_HOME || keynum == Event.KEY_END || keynum == Event.KEY_LEFT || keynum == Event.KEY_UP || keynum == Event.KEY_RIGHT || keynum == Event.KEY_DOWN)
			return true;
	}
	
	//Habilita los botones: 44 punto; 46 coma; 36 $
	//if (keynum == 44 || keynum == 46 || keynum == 36)
	if (keynum == 44)
		return true;

	keychar = String.fromCharCode(keynum);
	numcheck = /\d/;
    return numcheck.test(keychar);
}

function XS_requireNumber(sObj, sMsg, sType)
{
    var sRet = ''
    if ( typeof(sObj) == 'string' )
        var sNumber = sObj
    else
        var sNumber = sObj.value;
    
    if (sNumber.length == '')
        sRet = sMsg + ': ' + 'Dato requerido';

    
    if (sRet == '')
    {
            if (sType == null || sType == 'int')
            {
             if ( !SoloTipo(sNumber, "9") )    
                sRet = sMsg + ': ' + 'Entrada inválida'
            }                 
            else
            if (sType == 'real')
            {
             if (!esReal(sNumber, '+'))
                sRet = sMsg + ': ' + 'Entrada inválida';
            }        
    }            
    if (sRet == '')
    {
        if (parseFloat(sNumber) == 0)                                 
                sRet = sMsg + ': ' + 'Debe ser mayor que cero';
    }

    if (sRet == '')
        return ''
    else
    {
        if ( typeof(sObj) == 'object' )
            sObj.focus();
        return sRet
    }

}

function XS_ToggleButton(sId_Boton, sNombre)
{
    var obj = $(sId_Boton);
    
    if (obj == null)
    {
        alert('No se encontró botón ' + sId_Boton)
    }    
    if (obj.disabled == true)
        obj.disabled = false
    else
        obj.disabled = true;
        
    if (sNombre != null)
        obj.value = sNombre;       
}

/*
Autor: Marco Z. Alvarez
Fecha Modificación: 15/04/2011
Descripción: Se implementara, la validación por expresión regular.
EXPR: ^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$
*/
function ValidaCorreo(vCorreo)
{

    var reCorreo = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    return reCorreo.test(vCorreo);
  
}

// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact

//num: numero a formatear
//dec: cantidad de decimales, si hay mas se redondea, si se pone -1 deja los decimales de origen
//thou: separador de miles 
//pnt : separador decimal
//curr1: simbolo de moneda
//curr2: simbolo de moneda si va despues del monto
//n1	:simbolo adelante del numero cuando el valor es negativo
//n2	:simbolo despues del numero cuando el valor es negativo 

function XS_FormatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {

if (dec == null) dec=0;if (thou == null) thou='.';if (pnt == null) pnt=',';
if (curr1 == null)	curr1=''; if (curr2 == null) curr2=''; 
if (n1 == null) n1='-';if (n2 == null) n2='';
if(dec==0)  pnt='';
num=Replace(num,',','.')
num=parseFloat(num);
if (dec==-1)
{
	var tdec=(''+ num).split('.');
	if(tdec.length==2)
		dec=tdec[1].length;
	else
	{
		dec=0;	
		pnt='';
	}
}

var x = Math.round(num * Math.pow(10,dec));
if (x >= 0) 
	n1=n2='';
var y = (''+Math.abs(x)).split('');
var z = y.length - dec; 
if (z<0) z--; 
for(var i = z; i < 0; i++) 
	y.unshift('0'); 
if (z<0) 
	z = 1; 
y.splice(z, 0, pnt); 
if(y[0] == pnt) 
	y.unshift('0'); 
while (z > 3) {
	z-=3; 
	y.splice(z,0,thou);
}

var r = curr1+n1+y.join('')+n2+curr2;

return r;
}

// Des Formatea un número
function XS_unFormatNumber(str) 
{
    if (str != null && str != '')
    {
        sMonto = Replace(str,'.','')
        sMonto = Replace(sMonto,'$','')
        sMonto = Replace(sMonto,' ','')
        sMonto = Replace(sMonto,',','.')
		if (str.indexOf(",") != -1)
			return parseFloat(sMonto)
		else
			return parseInt(sMonto)
    }    
    else
        return 0
    
}	

function TruncaDecimales(pnumero, decimales) 
{
	var snumero = new String( pnumero )
	var porcion = snumero.split( '.' )
	var entero = parseInt( porcion[0] )

	if ( porcion.length == 1 ) {
		resultado = entero
	}
	else {
		snumero = ''
		var decimal = new String( porcion[1] + '0000000000' )
		var t = -1
		for ( var k = decimales-1; k >= 0; k--) {
			t++
			snumero = snumero + decimal.substr(t, 1)
		}
		decimal = snumero
		if (decimal=='')
			resultado = entero;
		else	
			resultado = entero + '.' + decimal;
	}

	return resultado
}


//Levanta una ventana de pop-up
function XS_EjecutarPopUp(sTitulo, sUrl, jDimentions, jOptions, sTarget)
{
    if( sTarget == null)
        sTarget = "_new";
	if(jDimentions == null)
	{
		  var iWidth  = screen.width * 0.80
		  var iHeight = screen.height * 0.50
	}
	else
	{
		  var iWidth  = jDimentions.width;
		  var iHeight = jDimentions.height;
	}
	
    var iLeft   = (screen.width - iWidth) / 2
    var iTop    = (screen.height - iHeight) / 2

	if(jOptions == null)
	{
		var sOptions = "toolbar=NO, menubar=NO, directories=NO, location=NO, titlebar=NO, status=yes, resizable=yes, scrollbars=yes ";
	}
	else
	{
		var sOptions = "toolbar=" + jOptions.toolbar + ", menubar=" + jOptions.menubar + ", directories=" + jOptions.directories + ", location=" + jOptions.location + ", titlebar=" + jOptions.titlebar + ", status=" + jOptions.status + ", resizable=" + jOptions.resizable + ", scrollbars=" + jOptions.scrollbars ;
	}
	
	var sOptions = "left=" + iLeft + ",top=" + iTop + ",width=" + iWidth + ",height=" + iHeight	+ ',' + sOptions;	  	
	
    var openWin = window.open(""+sUrl, sTarget, sOptions )
      
    if (navigator.appName != "Microsoft Internet Explorer")  
      {
	    if ( window.focus )  openWin.focus()
      }  
}    

Date.fromUKFormat = function(sUK) 
{ 
  var A = sUK.split(/[\\\/]/); 
      A = [A[1],A[0],A[2]]; 
  return new Date(Date.parse(A.join('/'))); 
} 

function XS_DateDiff( start, end, interval, wholedays ) 
{
    if( wholedays == null)
        wholedays = true;
    
    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Revise las fechas,\n"
        startMsg += "deben tener un fromato válido('mm/dd/aaaa').\n\n"
        startMsg += "inténtelo nuevamente." ;
		
    var intervalMsg = "La función solo acepta\n"
        intervalMsg += "d, h, m ó s .\n\n"
        intervalMsg += "inténtelo nuevamente." ;

    var bufferA = Date.fromUKFormat( start ) ;
    var bufferB = Date.fromUKFormat( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( startMsg ) ;
        return null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
// what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(wholedays) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(wholedays) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(wholedays) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(wholedays) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}

function XS_padNumber(nStr, nLen, sChr)
{ 
    var sRes = String(nStr); 
    for (var i = 0; i < nLen - String(nStr).length; i++) 
     sRes = sChr + sRes; 
    return sRes; 
} 

/*======================================================================================
Autor: Carlos Acevedo
Fecha: 04/06/2010
Reemplaza los caracteres especiales por su equivalente numerico HTML/XML dentro de un string. 
sTexto: String Con Texto HTML que contiene caracteres especiales a ser reemplazados.
*/
function ReplaceXmlSpecChars( sTexto )
{
    var sRetorno = trim( sTexto );

/*      //Caracteres Excluidos por ser parte de los caracteres reservados de HTML, XML, CSS y JAVASCRIPT...
	sRetorno = Replace( sRetorno , ''' , '&#34;');	 //--comillas dobles
	sRetorno = Replace( sRetorno , ''' , '&#39;');	 //--- comilla / apóstrofe
	sRetorno = Replace( sRetorno , '\' , '&#92;');	 //--barra inversa
	sRetorno = Replace( sRetorno , ':' , '&#58;');	 //--- dos puntos
	sRetorno = Replace( sRetorno , ';' , '&#59;');	 //--- punto y coma
	sRetorno = Replace( sRetorno , '!' , '&#33;');	 //--- signo de cierre de exclamación / admiración
	sRetorno = Replace( sRetorno , '<' , '&#60;');	 //--- signo de menor que
	sRetorno = Replace( sRetorno , '=' , '&#61;');	 //--- signo de igual
	sRetorno = Replace( sRetorno , '>' , '&#62;');	 //--- signo de mayor que
	sRetorno = Replace( sRetorno , '?' , '&#63;');	 //--- signo de interrogación - cierre
	sRetorno = Replace( sRetorno , '[' , '&#91;');	 //--- corchete izquierdo
	sRetorno = Replace( sRetorno , ']' , '&#93;');	 //--- corchete derecho
	sRetorno = Replace( sRetorno , '^' , '&#94;');	 //--- signo de intercalación - acento circunflejo
	sRetorno = Replace( sRetorno , '_' , '&#95;');	 //--- signo de subrayado
	sRetorno = Replace( sRetorno , '`' , '&#96;');	 //--- acento grave
	sRetorno = Replace( sRetorno , '{' , '&#123;');	 //--- llave de apertura - izquierda
	sRetorno = Replace( sRetorno , '|' , '&#124;');	 //--- barra vertical
	sRetorno = Replace( sRetorno , '}' , '&#125;');	 //--- llave de cierre - derecho
	sRetorno = Replace( sRetorno , '~' , '&#126;');	 //--- signo de equivalencia / tilde	
	sRetorno = Replace( sRetorno , '#' , '&#35;');	 //--- signo de número	
	sRetorno = Replace( sRetorno , '%' , '&#37;');	 //--- signo de porcentaje
	sRetorno = Replace( sRetorno , '&' , '&#38;');	 //--- signo '&' / ampersand
	sRetorno = Replace( sRetorno , '(' , '&#40;');	 //--- paréntesis izquierdo
	sRetorno = Replace( sRetorno , ')' , '&#41;');	 //--- paréntesis derecho
	sRetorno = Replace( sRetorno , '*' , '&#42;');	 //--- asterisco
	sRetorno = Replace( sRetorno , '+' , '&#43;');	 //--- signo de más / adición
	sRetorno = Replace( sRetorno , ',' , '&#44;');	 //--- coma
	sRetorno = Replace( sRetorno , '-' , '&#45;');	 //--- signo de menos / sustracción / guíon / raya
	sRetorno = Replace( sRetorno , '.' , '&#46;');	 //--- punto
	sRetorno = Replace( sRetorno , '/' , '&#47;');	 //--- barra oblicua - barra de división
*/
	sRetorno = Replace( sRetorno , ' ' , '&#32;');	 //--- espacio
	sRetorno = Replace( sRetorno , '$' , '&#36;');	 //--- signo de dólar
	sRetorno = Replace( sRetorno , '@' , '&#64;');	 //--- símbolo arroba
	sRetorno = Replace( sRetorno , ' ' , '&#160;');	 //--- espacio sin separación
	sRetorno = Replace( sRetorno , '¡' , '&#161;');	 //--- signo de apertura de exclamación / admiración
	sRetorno = Replace( sRetorno , '¢' , '&#162;');	 //--- signo de centavo
	sRetorno = Replace( sRetorno , '£' , '&#163;');	 //--- signo de Libra Esterlina
	sRetorno = Replace( sRetorno , '¤' , '&#164;');	 //--- signo de divisa general
	sRetorno = Replace( sRetorno , '¥' , '&#165;');	 //--- signo de yen
	sRetorno = Replace( sRetorno , '¦' , '&#166;');	 //--- barra vertical partida
	sRetorno = Replace( sRetorno , '§' , '&#167;');	 //--- signo de sección
	sRetorno = Replace( sRetorno , '¨' , '&#168;');	 //--- diéresis - umlaut
	sRetorno = Replace( sRetorno , '©' , '&#169;');	 //--- signo de derechos de autor - copyright
	sRetorno = Replace( sRetorno , 'ª' , '&#170;');	 //--- género feminino - indicador ordinal feminino
	sRetorno = Replace( sRetorno , '«' , '&#171;');	 //--- comillas anguladas de apertura
	sRetorno = Replace( sRetorno , '¬' , '&#172;');	 //--- signo de no - símbolo lógico
	sRetorno = Replace( sRetorno , '­' , '&#173;');	 //--- guión débil
	sRetorno = Replace( sRetorno , '®' , '&#174;');	 //--- signo de marca registrada
	sRetorno = Replace( sRetorno , '¯' , '&#175;');	 //--- macrón - raya alta
	sRetorno = Replace( sRetorno , '°' , '&#176;');	 //--- signo de grado
	sRetorno = Replace( sRetorno , '±' , '&#177;');	 //--- signo de más o menos
	sRetorno = Replace( sRetorno , '²' , '&#178;');	 //--- superíndice dos - cuadrado
	sRetorno = Replace( sRetorno , '³' , '&#179;');	 //--- superíndice tres - cúbico
	sRetorno = Replace( sRetorno , '´' , '&#180;');	 //--- acento agudo - agudo espaciado
	sRetorno = Replace( sRetorno , 'µ' , '&#181;');	 //--- signo de micro
	sRetorno = Replace( sRetorno , '¶' , '&#182;');	 //--- signo de fin de párrafo
	sRetorno = Replace( sRetorno , '·' , '&#183;');	 //--- punto medio - coma Georgiana
	sRetorno = Replace( sRetorno , '¸' , '&#184;');	 //--- cedilla
	sRetorno = Replace( sRetorno , '¹' , '&#185;');	 //--- superíndice uno
	sRetorno = Replace( sRetorno , 'º' , '&#186;');	 //--- género masculino - indicador ordinal masculino
	sRetorno = Replace( sRetorno , '»' , '&#187;');	 //--- comillas anguladas de cierre
	sRetorno = Replace( sRetorno , '¼' , '&#188;');	 //--- fracción un cuarto
	sRetorno = Replace( sRetorno , '½' , '&#189;');	 //--- fracción medio - mitad
	sRetorno = Replace( sRetorno , '¾' , '&#190;');	 //--- fracción tres cuartos
	sRetorno = Replace( sRetorno , '¿' , '&#191;');	 //--- signo de interrogación - apertura
	sRetorno = Replace( sRetorno , 'À' , '&#192;');	 //--- A mayúscula con acento grave
	sRetorno = Replace( sRetorno , 'Á' , '&#193;');	 //--- A mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Â' , '&#194;');	 //--- A mayúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'Ã' , '&#195;');	 //--- A mayúscula con tilde
	sRetorno = Replace( sRetorno , 'Ä' , '&#196;');	 //--- A mayúscula con diéresis
	sRetorno = Replace( sRetorno , 'Å' , '&#197;');	 //--- A mayúscula con anillo
	sRetorno = Replace( sRetorno , 'Æ' , '&#198;');	 //--- diptongo AE mayúscula (ligadura)
	sRetorno = Replace( sRetorno , 'Ç' , '&#199;');	 //--- C cedilla mayúscula
	sRetorno = Replace( sRetorno , 'È' , '&#200;');	 //--- E mayúscula con acento grave
	sRetorno = Replace( sRetorno , 'É' , '&#201;');	 //--- E mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Ê' , '&#202;');	 //--- E mayúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'Ë' , '&#203;');	 //--- E mayúscula con diéresis
	sRetorno = Replace( sRetorno , 'Ì' , '&#204;');	 //--- I mayúscula con acento grave
	sRetorno = Replace( sRetorno , 'Í' , '&#205;');	 //--- I mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Î' , '&#206;');	 //--- I mayúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'Ï' , '&#207;');	 //--- I mayúscula con diéresis
	sRetorno = Replace( sRetorno , 'Ð' , '&#208;');	 //--- ETH islandesa mayúscula
	sRetorno = Replace( sRetorno , 'Ñ' , '&#209;');	 //--- N mayúscula con tilde - eñe mayúscula
	sRetorno = Replace( sRetorno , 'Ò' , '&#210;');	 //--- O mayúscula con acento grave
	sRetorno = Replace( sRetorno , 'Ó' , '&#211;');	 //--- O mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Ô' , '&#212;');	 //--- O mayúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'Õ' , '&#213;');	 //--- O mayúscula con tilde
	sRetorno = Replace( sRetorno , 'Ö' , '&#214;');	 //--- O mayúscula con diéresis
	sRetorno = Replace( sRetorno , '×' , '&#215;');	 //--- signo de multiplicación
	sRetorno = Replace( sRetorno , 'Ø' , '&#216;');	 //--- O mayúscula with slash
	sRetorno = Replace( sRetorno , 'Ù' , '&#217;');	 //--- U mayúscula con acento grave
	sRetorno = Replace( sRetorno , 'Ú' , '&#218;');	 //--- U mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Û' , '&#219;');	 //--- U mayúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'Ü' , '&#220;');	 //--- U mayúscula con diéresis
	sRetorno = Replace( sRetorno , 'Ý' , '&#221;');	 //--- Y mayúscula con acento agudo
	sRetorno = Replace( sRetorno , 'Þ' , '&#222;');	 //--- THORN islandesa mayúscula
	sRetorno = Replace( sRetorno , 'ß' , '&#223;');	 //--- s minúscula (alemán) - Beta minúscula
	sRetorno = Replace( sRetorno , 'à' , '&#224;');	 //--- a minúscula con acento grave
	sRetorno = Replace( sRetorno , 'á' , '&#225;');	 //--- a minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'â' , '&#226;');	 //--- a minúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'ã' , '&#227;');	 //--- a minúscula con tilde
	sRetorno = Replace( sRetorno , 'ä' , '&#228;');	 //--- a minúscula con diéresis
	sRetorno = Replace( sRetorno , 'å' , '&#229;');	 //--- a minúscula con anillo
	sRetorno = Replace( sRetorno , 'æ' , '&#230;');	 //--- diptongo ae minúscula (ligadura)
	sRetorno = Replace( sRetorno , 'ç' , '&#231;');	 //--- c cedilla minúscula
	sRetorno = Replace( sRetorno , 'è' , '&#232;');	 //--- e minúscula con acento grave
	sRetorno = Replace( sRetorno , 'é' , '&#233;');	 //--- e minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'ê' , '&#234;');	 //--- e minúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'ë' , '&#235;');	 //--- e minúscula con diéresis
	sRetorno = Replace( sRetorno , 'ì' , '&#236;');	 //--- i minúscula con acento grave
	sRetorno = Replace( sRetorno , 'í' , '&#237;');	 //--- i minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'î' , '&#238;');	 //--- i minúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'ï' , '&#239;');	 //--- i minúscula con diéresis
	sRetorno = Replace( sRetorno , 'ð' , '&#240;');	 //--- eth islandesa minúscula
	sRetorno = Replace( sRetorno , 'ñ' , '&#241;');	 //--- eñe minúscula - n minúscula con tilde
	sRetorno = Replace( sRetorno , 'ò' , '&#242;');	 //--- o minúscula con acento grave
	sRetorno = Replace( sRetorno , 'ó' , '&#243;');	 //--- o minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'ô' , '&#244;');	 //--- o minúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'õ' , '&#245;');	 //--- o minúscula con tilde
	sRetorno = Replace( sRetorno , 'ö' , '&#246;');	 //--- o minúscula con diéresis
	sRetorno = Replace( sRetorno , '÷' , '&#247;');	 //--- signo de división
	sRetorno = Replace( sRetorno , 'ø' , '&#248;');	 //--- o barrada minúscula
	sRetorno = Replace( sRetorno , 'ù' , '&#249;');	 //--- u minúscula con acento grave
	sRetorno = Replace( sRetorno , 'ú' , '&#250;');	 //--- u minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'û' , '&#251;');	 //--- u minúscula con acento circunflejo
	sRetorno = Replace( sRetorno , 'ü' , '&#252;');	 //--- u minúscula con diéresis
	sRetorno = Replace( sRetorno , 'ý' , '&#253;');	 //--- y minúscula con acento agudo
	sRetorno = Replace( sRetorno , 'þ' , '&#254;');	 //--- thorn islandesa minúscula
	sRetorno = Replace( sRetorno , 'ÿ' , '&#255;');	 //--- y minúscula con diéresis

    return( sRetorno );
}


/*======================================================================================
Autor: Carlos Acevedo
Fecha: 04/06/2010
Genera una Nueva Tabla HTML a partir de los datos de una Grilla.
oGrilla: Objeto Grilla
nIgnoredColumns: Número de Columnas a  ignorar al lado derecho de la Grilla. Por defecto 1
*/
function GridExportationDataPrepare( oGrilla , nIgnoredColumns )
{
    if ((nIgnoredColumns.length == 0) || (nIgnoredColumns == null) )
	   nIgnoredColumns = 1;

    var PosRut = -1;
    var oTable = oGrilla.getTable();
    var sHtml = '';
	  sHtml += '<table class="XS_Table">'
    for(var r=0;r<oTable.rows.length;r++)
    {
        sHtml += '<tr>';
        var aCols = oTable.rows[r].cells;
        for(var c=0;c<aCols.length-nIgnoredColumns ;c++)
        {
            if(r==0)
            {
                var sNombreCampo = aCols[c].innerHTML.toUpperCase();
                if( sNombreCampo.indexOf('RUT') > -1 )
                {
                    PosRut = c;
                }
            }
            
            if(r==0)
                sHtml += '<th>' + aCols[c].innerHTML + '</th>';
            else
            {
                if( (PosRut == c) && (aCols[c].innerHTML.length < 5) )
                    sHtml += '<td>' + '\'' + aCols[c].innerHTML + '</td>';
                else
                    sHtml += '<td>' + aCols[c].innerHTML + '</td>';
            }
        }   
        sHtml += '</tr>';
    }
    sHtml += '</table>';
	sHtml = ReplaceXmlSpecChars( sHtml );
    return( sHtml );
}

function XS_getScreenSizeAvailable() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

function XS_SetDimentions( obj, width, height) {
	if (width != null && width != 'undefined' && width != '')
		$(obj).setStyle({width: width});
	if (height != null && height != 'undefined' && height != '')
		$(obj).setStyle({height: height});
}

function _F_Phone(e)
{
    var keynum;
    var keychar;
    var numcheck;
	//e = e || window.event;
	//keynum = e.keyCode || e.which;
	
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
		if (keynum == Event.KEY_BACKSPACE)
			return true;
	}
	else
	{
		keynum = e.keyCode;
		if (keynum == Event.KEY_TAB || keynum == Event.KEY_HOME || keynum == Event.KEY_END || keynum == Event.KEY_LEFT || keynum == Event.KEY_UP || keynum == Event.KEY_RIGHT || keynum == Event.KEY_DOWN)
			return true;
	}
	
	//Habilita los botones: 44 punto; 46 coma; 36 $
	//if (keynum == 44 || keynum == 46 || keynum == 36)
	if (keynum == 44)
		return true;

	keychar = String.fromCharCode(keynum);
	numcheck = /\d|\(|\)|\+|\-|\s|\/|\;/;
    return numcheck.test(keychar);
}

