/**********************************
* Desarrollado por De Facto S.A.  *
**********************************/

//
//Define variables que determinan la versión del browser
//
// 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.
var is_major = parseInt(navigator.appVersion);
var is_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.
var is_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));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
					  (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);


var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

/* Delimitador usado en inet_dflt(), fb_inet_chequea_dect() */
var KS_DELIMITADOR     = "|";

/* Separador de decimales */
var KS_SEP_DEC = ',';

/* Constantes con objetos disponibles en un <form></form>, usadas en inet_dflt()*/
/*
 Estas contantes usadas en inet_dflt han sido descartadas ya que no pueden utilizarse 
 variables en la sentencia case del switch en Netscape 4.6
*/
/*
var KS_OBJ_TEXT        = "text";
var KS_OBJ_RADIO       = "radio";
var KS_OBJ_CHECKBOX    = "checkbox";
var KS_OBJ_SELECT_ONE  = "select-one";
var KS_OBJ_SELECT_MULT = "select-multiple";
var KS_OBJ_HIDDEN      = "hidden";
var KS_OBJ_TEXTAREA    = "textarea";
*/

var _XPOST = "POST";
var _XGET = "GET";

/* Delitador de fechas */
var KS_DELIMITADOR_FECHA1     = "/";
/*
Nombre: f_inet_reload
Descripción: Vuelve a carga la página actual (Tecla F5 en Internet Explorer y Netscape 7)
Parametros: ninguno
Retorno: ninguno
*/
function f_inet_reload()
{
        location.reload();
}

/*
Nombre: f_inet_programar_ejec_funcion
Descripción: Ejecuta la función pasada por parámetro después de cierta cantidad de minutos.
Parametros: 
        ps_funcion: String que contiene el nombre de la función
        pn_minutos: Cantidad de minutos que deben pasar antes de que se llame a la función.
Retorno: ninguno        
*/
function f_inet_programar_ejec_funcion(ps_funcion,pn_minutos)
{
        window.setTimeout(ps_funcion,pn_minutos * 60 * 1000);
}

/*
Nombre: inet_muestra_elementos
Descripción: Muestra en pantalla los elemento u objetos que contiene un formulario(<form>). Además
             se muestra la posición del objeto dentro del formulario.
Parametros:
        form: Objeto formulario.
Retorno: ninguno
*/
function inet_muestra_elementos(form)
{
	str = "Elementos del form(" + form.name + "): \n "
	for (i = 0; i < form.length; i++)
	str += "[" + i + "] " + form.elements[i].name + "\n"
	alert(str)
}

/*
Nombre: inet_dflt
Descripción: Asigna los valores por omisión(ps_val_df) a los objetos(ps_val_df) 
        pasado por parámetro.
Parametros:
        form: Objeto formulario.

        ps_nb_objs: String que contiene los nombres o id (un numérico que representa el orden de
        		aparición o definición dentro del form) de los distintos objetos, separados por
                KS_DELIMITADOR, a los cuales se le asignara un valor por omisión.

                Si no se puede pasar el nombre de los objetos se puede pasar la posición (numérico de 0 a n)
                dentro del formulario de los objetos que se necesite

        ps_val_df: String que contiene los valores por omisión, separados por KS_DELIMITADOR,
                para cada uno de los objetos contenidos en ps_nb_objs.
Retorno: ninguno
*/
function inet_dflt(/*form, ps_nb_objs, ps_val_df [,ps_delim]*/)
{
	form = arguments[0];
	ps_nb_objs = arguments[1];
	ps_val_df = arguments[2];
	if (arguments.length == 4)
		ps_delim = arguments[3];
	else
		ps_delim = KS_DELIMITADOR;
        la_objetos         = ps_nb_objs.split(ps_delim);
        la_val_df = ps_val_df.split(ps_delim);

	// Para depuración
	//inet_muestra_elementos(form);

        for (i = 0; i < la_objetos.length; i++)
        {

                lo_tmp = eval(form.elements[la_objetos[i]]);

                if (lo_tmp != undefined)
                {
                        switch (lo_tmp.type)
			{
                                case "text" :
                                        lo_textfield = lo_tmp;
                                        lo_textfield.value = la_val_df[i];
                                break;
                                case "textarea" :
                                        lo_textareafield = lo_tmp;
                                        lo_textareafield.value = la_val_df[i];
                                break;
				case "hidden" :
                                        lo_hiddenfield = lo_tmp;
                                        lo_hiddenfield.value = la_val_df[i];
                                break;
                                case "radio" :
                                        lo_radiobutton = lo_tmp;
                                        if (eval(form.name+"."+la_objetos[i]+".value") == la_val_df[i]) //???
                                                lo_radiobutton.checked = true;
                                        else
                                                lo_radiobutton.checked = false;
                                break;
                                case "checkbox" :
                                        lo_checkbox = lo_tmp;
                                        if (la_val_df[i] == "on")
                                                lo_checkbox.checked = true;
                                        else
                                                lo_checkbox.checked = false;
                                break;
                                case "select-one" :
                                        la_opciones_combo_box = lo_tmp;
                                        for (j=0; j < la_opciones_combo_box.length; j++)
                                        {
                                                if (la_opciones_combo_box[j].value == la_val_df[i])
                                                {
                                                        la_opciones_combo_box[j].selected = true;
                                                        break;
                                                }
                                        }
                                break;

                                default :
                                        ;
                        }
                }
        }
}

/**
 * Para usar la función SetPointer ubicar este código en el tag <TR onmous....>
 *
 * onmousedown="setPointer(this, 0, 'click', '#DDDDDD', '#CCFFCC', '#FFCC99');"
 * onmouseover="setPointer(this, 0, 'over', '#DDDDDD', '#CCFFCC', '#FFCC99');"
 * onmouseout="setPointer(this, 0, 'out', '#DDDDDD', '#CCFFCC', '#FFCC99');">
 */
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{

    var theCells = null;

    if (typeof(theRow) == 'undefined')
        return false;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/*
Nombre: f_trim
Descripción: Quita espacios a la izquierda y derecha de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function f_trim(TRIM_VALUE)
{
        if(TRIM_VALUE.length < 1){
        return"";
        }
        TRIM_VALUE = f_rtrim(TRIM_VALUE);
        TRIM_VALUE = f_ltrim(TRIM_VALUE);
        if(TRIM_VALUE=="")
        {
                return "";
        }
        else
        {
                return TRIM_VALUE;
        }
} //End Function

/*
Nombre: f_rtrim
Descripción: Quita espacios a la derecha de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function f_rtrim(VALUE)
{
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
        if(v_length < 0)
        {
                return"";
        }
        var iTemp = v_length -1;

        while(iTemp > -1)
        {
                if(VALUE.charAt(iTemp) == w_space)
                {
                }
                else
                {
                        strTemp = VALUE.substring(0,iTemp +1);
                        break;
                }
                iTemp = iTemp-1;
        } //End While
        return strTemp;
} //End Function

/*
Nombre: f_ltrim
Descripción: Quita espacios a la izquierda de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function f_ltrim(VALUE)
{
        var w_space = String.fromCharCode(32);

        if(v_length < 1)
        {
                return"";
        }
        var v_length = VALUE.length;
        var strTemp = "";
        var iTemp = 0;

        while(iTemp < v_length)
        {
                if(VALUE.charAt(iTemp) == w_space)
                {
                }
                else
                {
                        strTemp = VALUE.substring(iTemp,v_length);
                        break;
                }
                iTemp = iTemp + 1;
        } //End While
        return strTemp;
} //End Function

/*
Nombre: f_enviar
Descripción: SUBMITe formulario
Parametros: Objeto Form
Retorno: ninguno
*/
function f_enviar(f)
{
	f.submit();
}

function fb_es_entero (string)
{
   var val = parseInt (string);
   return (val > 0);
}

function fb_inet_ejecuta_chequea_fecha(objName) 
{
//	var strDatestyle = "US"; //United States date style
//	var strDatestyle = "EU";  //European date style

	var datefield = objName;
	strDate = f_trim(datefield.value);

	var strDatestyle = "CL";
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Ene";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Abr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Ago";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	
	if (strDate.length < 8 || strDate.length > 10) // dd-mm-yyyy, 10 caracteres
	{
		return false;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else
			{
				strDay   = strDateArray[0];
				strMonth = strDateArray[1];
				strYear  = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) 
	{
		if (strDate.length == 8) // ddmmyyyy
//		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
		else
			return false;
	}
	if (strYear.length < 4) 
	{
		return(false);
		//strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)  || !fb_inet_esentero(f_trim(strDay))) 
	{
		err = 2;
		return false;
	}
	
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)  || !fb_inet_esentero(f_trim(strMonth))) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	
	if (isNaN(intYear) || !fb_inet_esentero(strYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (f_anno_bisiesto(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;	
				return false;
			}
		}
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}
	if (strDatestyle == "US") 
	{
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else if (strDatestyle == "EU")
	{
		datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
	}
	else 
	{
		intday ="0" + intday;
		intMonth = "0" + intMonth;
		if (intday.length >= 3) intday     = intday.substr(intday.length-2, 2);
		if (intMonth.length >= 3) intMonth = intMonth.substr(intMonth.length-2, 2);
		datefield.value = intday + "/" + intMonth + "/" + strYear;
	}

	return true;
}


function f_anno_bisiesto(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else
	{
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

/*
Nombre: fn_inet_chequea_decimales
Descripción: Chequea si el valor numerico decimal es correcto (Si es numerico y trae la cantidad
			apropiada decimales (pn_nro_decimales))
Parametros: po_nombre_campo: objeto text
			po_valor_campo: valor del objeto text
Retorno: 1: Exitoso
		-1: Cantidad de decimales es superior al permitido
		-2: Valor numerico no ingresado
*/
function fn_inet_chequea_decimales(po_nombre_campo, po_valor_campo, pn_nro_decimales)
{
	if (isNaN(po_valor_campo) || po_valor_campo == "")
	{
		return -2;
	}
	else
	{
		if (po_valor_campo.indexOf(',') == -1)
			po_valor_campo += ",";

		ls_texto_decimal = po_valor_campo.substring(po_valor_campo.indexOf(',')+1, po_valor_campo.length);

		if (ls_texto_decimal.length > pn_nro_decimales)
		{
			return -1;
		}
		else
		{
			return 1;
		}
   }
}

/*
Nombre: fb_inet_chequea_dec
Descripción: Chequea si el valor numerico tiene decimales. Si tiene decimales comprueba que trae la cantidad
			apropiada decimales (pn_nro_decimales))
			Solo acepta números postivos.
			Si el numero no tiene decimales, osea es entero, retorna 1
Parametros: ps_numero: string con numero
			pn_nro_decimales: cantidad de decimales
Retorno: true: Exitoso
		 false: Cantidad de decimales es superior al permitido o no es un número con decimales válido
*/
function fb_inet_chequea_dec(ps_numero, pn_nro_decimales)
{
	ls_numero = f_trim(ps_numero);

	if (ls_numero == "")
		return true;
	else
	if (!fb_inet_valcaracteres(ls_numero, "01234567890" + KS_SEP_DEC))
		return false;	
	else
	{
		ln_pos_coma = ls_numero.indexOf(KS_SEP_DEC);
		
		if (ln_pos_coma == -1) // No tiene decimales
			return true;

		if (ln_pos_coma < 1)  // Si es algo como ",2" o ","
			return false;

		if (ln_pos_coma == (ls_numero.length - 1))  // Si es algo como "2," 
			return false;

		ls_texto_decimal = ls_numero.substring(ln_pos_coma + 1, ls_numero.length);
		
		if (!fb_inet_esentero(ls_texto_decimal) || ls_texto_decimal.length > pn_nro_decimales)
			return false;
		else
			return true;
   }
}

function fb_inet_chequea_dec2(ps_numero, pn_nro_decimales) 
{
	ls_nro = ps_numero.replace(',','.');

	if (isNaN(ls_nro)) 
	{
		return(false);
	}
	else 
	{
		if (ls_nro.indexOf('.') == -1) 
			ls_nro += ".";
		dectext = ls_nro.substring(ls_nro.indexOf('.')+1, ls_nro.length);
	
		if (dectext.length > pn_nro_decimales)
		{
			return(false);
		}
		else
		{
			return(true);
		}
	}
}

/*
Nombre: fb_inet_chequea_decespec
Descripción: Chequea si el objeto po_num tiene decimales. Los valores permitidos para los decimales se encuentran en 
			 ps_dec_ok
Parametros: po_num: objeto text con el número
			ps_dec_ok: números que serán permitidos como decimales separados por KS_DELIMITADOR (Ej. '|0|5' osea
			           permite valores como: 1 - 1,5 ó 2,0);
Retorno: true: Si es un número con decimales válidos
		 false: Si no es un número con decimales válidos
*/
function fb_inet_chequea_decespec(po_num, ps_dec_ok)
{
	var ln_nro_decimales = 1;

	if (f_trim(po_num.value) == "")
		return(true);
		
	switch(fb_inet_chequea_dec(po_num.value, ln_nro_decimales))
	{
		case false:
			return(false);
		case true:
			ln_pos_coma = po_num.value.indexOf(KS_SEP_DEC);
			if (ln_pos_coma == -1) //Sin decimales
				return(true);
			ls_texto_decimal = po_num.value.substring(ln_pos_coma + 1, po_num.length);
			pa_dec_ok = ps_dec_ok.split(KS_DELIMITADOR);
			for (i=0; i < pa_dec_ok.length; i++)
			{
				if (f_trim(pa_dec_ok[i]) == f_trim(ls_texto_decimal))
					return(true);
			}
			break;
	}
	return(false);
}

/* true si 00:00 -> 23:59. false en caso contrario */
/*function f_chequehr(po_valor)
{

	if (po_valor == "")
		return false;
	else
	{
		if (po_valor.indexOf(':') != 2)
			return false;
		ls_hh = po_valor.substring(0, 2);
		ls_mm = po_valor.substring(3, 5);
		if (isNaN(ls_hh) || isNaN(ls_mm))
			return false;
		else
			if ((ls_hh < 0 ) || (ls_hh > 23) ||(ls_mm < 0) || (ls_mm > 59))
				return false;
			else
 				return true;
	}
}*/

/*
Nombre: f_inet_sum_dia_obj_text
Descripción: Incrementa "pn_incremento_dias" un fecha contenida en un objeto text, con formato dd/mm/aaaa
Parametros: po_texto: objeto text
			pn_incremento_dias: días a incrementar
Retorno: Ninguno
*/
function f_inet_sum_dia_obj_text(po_texto,pn_incremento_dias)
{
	if (f_trim(po_texto.value) == '' || !fb_inet_ejecuta_chequea_fecha(po_texto))
		return;

	po_texto.value = fs_inet_sum_dia_a_fecha_str(po_texto.value, pn_incremento_dias);
}

/*
Nombre: fs_inet_sum_dia_a_fecha_str
Descripción: Incrementa "pn_incremento_dias" un fecha
Parametros: ps_texto: string con fecha formato dd/mm/aaaa
			pn_incremento_dias: días a incrementar
Retorno: String con fecha en formato dd/mm/aaaa
*/
function fs_inet_sum_dia_a_fecha_str(ps_texto,pn_incremento_dias)
{
	var ln_milisegundos_en_un_dia = 24 * 3600000;
	var la_fecha = ps_texto.split(KS_DELIMITADOR_FECHA1);
	var ld_fecha = new Date(parseInt(la_fecha[2]),eval(la_fecha[1]) - 1,eval(la_fecha[0]));

	ld_fecha.setTime(ld_fecha.getTime() + pn_incremento_dias * ln_milisegundos_en_un_dia);
	ln_mes = ld_fecha.getMonth() + 1;
	return( fs_inet_agrega_cero(ld_fecha.getDate().toString())
		+ KS_DELIMITADOR_FECHA1
		+ fs_inet_agrega_cero(ln_mes.toString())
		+ KS_DELIMITADOR_FECHA1
		+ ld_fecha.getFullYear().toString());
}

/*
Nombre: fs_inet_compara_fechas_str
Descripción: Compara fechas
Parametros: ps_fecha_1: string con fecha1 formato dd/mm/aaaa
			ps_fecha_2: string con fecha2 formato dd/mm/aaaa
			pn_incremento_dias: días a incrementar
Retorno: -1 si fecha1 < fecha2
		  0 si fecha1 = fecha2
		  1 si fecha1 > fecha2
*/
function fs_inet_compara_fechas_str(ps_fecha1,ps_fecha2)
{
	var ln_milisegundos_en_un_dia = 24 * 3600000;

	var la_fecha1 = ps_fecha1.split(KS_DELIMITADOR_FECHA1);
	var ld_fecha1 = new Date(parseInt(la_fecha1[2]),eval(la_fecha1[1]) - 1,eval(la_fecha1[0]));

	var la_fecha2 = ps_fecha2.split(KS_DELIMITADOR_FECHA1);
	var ld_fecha2 = new Date(parseInt(la_fecha2[2]),eval(la_fecha2[1]) - 1,eval(la_fecha2[0]));

//	var x = ld_fecha2.getTime() - ld_fecha1.getTime();
//	alert("2");
//	alert(x.toString());
	if ((ld_fecha2.getTime() - ld_fecha1.getTime()) < 0)
		return -1;
	if ((ld_fecha2.getTime() - ld_fecha1.getTime()) == 0)
		return 0;
	if ((ld_fecha2.getTime() - ld_fecha1.getTime()) > 0)
		return 1;
}


/*
Nombre: fs_inet_agrega_cero
Descripción: concatena un cero al comiento a los números (positivos) de un digito que van desde 0 a 9
Parametros: ps_numero: string con valor numerico
Retorno: pn_numero con cero concatenado a la izquierda
*/
function fs_inet_agrega_cero(ps_numero)
{
	if (eval(f_trim(ps_numero)) >= 0 && eval(f_trim(ps_numero)) < 10)
		return "0" + ps_numero;
	return ps_numero;
}

/*
Nombre: fb_inet_entre
Descripción: valida que un número este en un cierto rango
Parametros: ps_numero: string con valor numerico
			ps_num_1: string con rango inicial
			ps_num_2: string con rango final
Retorno: TRUE si pn_numero esta entre ps_num_1 y ps_num_2
*/
function fb_inet_entre(ps_numero, ps_num_1, ps_num_2)
{
	return (
		   parseFloat(f_trim(ps_numero)) >= ps_num_1
		&& parseFloat(f_trim(ps_numero)) <= ps_num_2
		);
}

function f_val_hhmm(os_hhmm,oi_mindia)
{
   return(false);
}

/*
Nombre: f_chequehr
Descripción: Valida y formatea hora
Parametros: po_hora: hora 
			ps_formato: Formatos posibles hhmm, hhmmss, hh:mm, hh:mm:ss
Retorno: Retorna TRUE si la hora es correcta
*/
function f_chequehr(po_hora, ps_formato)
{
	var hh_min = 0;
	var hh_max = 23;
	var mm_min = 0;
	var mm_max = 59;
	var ss_min = 0;
	var ss_max = 59;
	var delim  = ':';
	var formato_default = "hh:mm";

	var ls_hora = f_trim(po_hora.value);
	if (ps_formato != undefined && f_trim(ps_formato) != "")
		switch (ps_formato)
		{
			case 'hhmm'    : break
			case 'hhmmss'  : break
			case 'hh:mm'   : break;
			case 'hh:mm:ss': break;
			default        : return(false);
		}
	else
		ps_formato = formato_default;
	if (ls_hora.length < 4 || ls_hora.length > 8)
		return(false);
	
	ls_ss = "00";
	switch (ls_hora.length)
	{
		case 4: // hhmm

			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			ls_mm = ls_hora.substr(2, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);
			break;
		case 6: // hhmmss
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			ls_mm = ls_hora.substr(2, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);	
			ls_mm = ls_hora.substr(4, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_ss, ss_min, ss_max))
				return(false);
			break;
		case 5: // hh:mm
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			if (ls_hora.substr(2, 1) != ":")
				return(false);
			ls_mm = ls_hora.substr(3, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);	
			break;
		case 8: // hh:mm:ss
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			if (ls_hora.substr(2, 1) != ":")
				return(false);
			ls_mm = ls_hora.substr(3, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);
			if (ls_hora.substr(5, 1) != ":")
				return(false);
			ls_ss = ls_hora.substr(6, 2);	
			if (!fb_inet_esentero(ls_ss) || !fb_inet_entre(ls_ss, ss_min, ss_max))
				return(false);
			break;
		default:
			return(false);
	}
	
	switch (ps_formato)
	{
		case 'hhmm'    : 
			po_hora.value = (ls_hh) + (ls_mm);
			break;	
		case 'hhmmss'  :
			po_hora.value = (ls_hh) + (ls_mm) + (ls_ss);
			break;	
		case 'hh:mm'   :
			po_hora.value = (ls_hh) + delim + (ls_mm);
			break;	
		case 'hh:mm:ss':
			po_hora.value = (ls_hh) + delim + (ls_mm) + delim + (ls_ss);
			break;	
		default        : 
			return(false);
	}
	return(true);
}

/*
Nombre: fb_inet_valcaracteres
Descripción: Valida si ps_texto contiene solo los carateres contenidos en ps_caracteres_validos
Parametros: ps_texto: Texto a validar
			ps_caracteres_validos: Cadena con caracteres permitidos
Retorno: Retorna TRUE si ps_texto solo tiene caracteres validos
*/
function fb_inet_valcaracteres(ps_texto, ps_caracteres_validos) 
{
 	for (k=0;k < ps_texto.length; k++) 
		if (ps_caracteres_validos.indexOf(ps_texto.substr(k,1)) == -1 ) 
			return(false);
	return(true);
}

/*
Nombre: fb_inet_esentero
Descripción: Valida si ps_texto coniene un numero entero
Parametros: ps_texto: Texto a validar
			
Retorno: Retorna TRUE si ps_texto tiene un número entero
*/
function fb_inet_esentero(ps_texto)
{
	return(fb_inet_valcaracteres(ps_texto, "0123456789"));
}

/*
Nombre: f_focoerr
Descripción: Coloca el foco en  po si pb_sin_error es false
Parametros: po: Objeto al cual se le da el foco
            ps_msg: Mensaje de alerta para el error
            pb_sin_error: Undefined y False indica que hay error y se pone el foco en objeto po. True que no se coloca foco
			
Retorno: Ninguno
*/
function f_focoerr(po,ps_msg,pb_sin_error)
{
	if (pb_sin_error == undefined || !pb_sin_error)
	{
		alert(ps_msg);
		lo_tmp = po;
		setTimeout("lo_tmp.focus(); lo_tmp.select()", 0); 
//		po.focus();
//		po.select();
		return;
	}
}

/*
Nombre: f_inet_vtna
Descripción: Abre una ventana que contendra la información de cierta URL(Ej. con documento a bajar)
Parametros: ps_url: URL con el contenido de la ventana
            ps_nomventana: Nombre de la ventana
            ps_atributos: atributos extras para la ventana
			
Retorno: Ninguno
*/
function f_inet_vtna(ps_url,ps_nomventana,ps_atributos) 
{
	ps_atributos = 'scrollbars=yes,menubar=no,status=no,resizable=no,screenX=400,screenY=10,top=10,left=10,' + ps_atributos;
	window.open(ps_url,ps_nomventana,ps_atributos);
}

/*
Nombre: f_inet_vtna
Descripción: Abre una ventana que contendra la información de cierta URL(Ej. con documento a bajar)
Parametros: ps_url: URL con el contenido de la ventana
            ps_nomventana: Nombre de la ventana
            ps_atributos: atributos extras para la ventana
			
Retorno: Ninguno
*/
function f_inet_vtna(ps_url,ps_nomventana,ps_atributos) 
{
	ps_atributos = 'scrollbars=yes,menubar=no,status=no,resizable=no,screenX=400,screenY=10,top=10,left=10,' + ps_atributos;
	window.open(ps_url,ps_nomventana,ps_atributos);
}

function f_inet_vtnap(ps_url,ps_nomventana,pn_top, pn_left, pn_width, pn_height, pb_scrollbar, pb_menu, pb_redimensionar, pb_bestado) 
{
	ps_atributos = "top="+pn_top+",left="+pn_left+",width="+pn_width+",height="+pn_height+",";

	if (pb_scrollbar)
		ps_atributos += "scrollbars=yes,";
	else
		ps_atributos += "scrollbars=no,";

	if (pb_menu)
		ps_atributos += "menubar=yes,";
	else
		ps_atributos += "menubar=no,";
	if (pb_redimensionar)
		ps_atributos += "resizable=yes,";
	else
		ps_atributos += "resizable=no,";
	if (pb_bestado)
		ps_atributos += "status=yes";
	else
		ps_atributos += "status=no";
	window.open(ps_url,ps_nomventana,ps_atributos);
}

var KS_MSJ_NOBD = '';

/*
Nombre: f_inet_nobdereve
Descripción: Declara función para atrapar evento del mouse, especificamente botón derecho
Parametros: 
	e:handle del evento
Retorno: Ninguno
*/

function f_inet_nobdereve(e) 
{
	if (parseInt(navigator.appVersion)>3) 
	{

		var ln_tipoclick=1;
		if (navigator.appName == "Netscape") 
			ln_tipoclick=e.which;
		else 
			ln_tipoclick=event.button;
		if (ln_tipoclick!=1) 
		{
			if (KS_MSJ_NOBD != "")
				alert (KS_MSJ_NOBD);
			return false;
		}
	}
 	return true;
}

function f_inet_nobder(ps_mensaje)
{
	if (ps_mensaje != "")
		KS_MSJ_NOBD = ps_mensaje;
	if (parseInt(navigator.appVersion)>3) 
	{
	
		document.onmousedown = f_inet_nobdereve;
		if (navigator.appName == "Netscape") 
			document.captureEvents(Event.MOUSEDOWN);
	}
}

function f_lyoculta(ps_id) 
{
	if (document.getElementById) // DOM3 = IE5, NS6
	{ 
		document.getElementById(ps_id).style.visibility = 'hidden';
	}
	else 
	{
		if (document.layers) // Netscape 4
		{ 
/*			lo_dv = eval('document.'+ps_id);
			lo_dv.visibility = 'hidden';*/
			document.layers[ps_id].visibility = 'hide';
		}
		else  // IE 4
		{
			lo_dv = eval('document.all.'+ps_id);
			lo_dv.style.visibility = 'hidden';
		}
	}
}

function f_lymuestra(ps_id) 
{
	if (document.getElementById)  // DOM3 = IE5, NS6
	{
		document.getElementById(ps_id).style.visibility = 'visible';
	}
	else
	{
		if (document.layers) // Netscape 4
		{ 
/*			lo_dv = eval('document.'+ps_id);
			lo_dv.visibility = 'visible';*/
			document.layers[ps_id].visibility = 'show';
		}
		else // IE 4
		{ 
			lo_dv = eval('document.all.'+ps_id);
			lo_dv.style.visibility = 'visible';
		}
	}
}

function f_lyimprimir(ps_id)
{
	f_lyoculta(ps_id);
	print();
	setTimeout("f_lymuestra('"+ps_id+"')", 2000);
}

/*
Nombre: f_chequeaemail
Descripción: Chequea si el parámetro entregado (ps_valor) tiene el formato correcto de un mail
Parametros: 
	ps_valor: Dirección de correo
Retorno: 
	True: dirección de correo con formato válido
	False: dirección de correo con formato inválido
*/
function f_chequeaemail(ps_valor) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(ps_valor))
		return (true)
	else
		return (false);
}

function f_selselect(p_frm, po_select, pb_chequear)
{
    var selectObject = document.forms[p_frm].elements[po_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) {
        selectObject.options[i].selected = pb_chequear;
    } // end for

    return true;
} // end of the 'setSelectOptions()' function

function f_selcheckbox(p_frm, po_checkbox)
{
    for (var i=0;i < p_frm.elements.length;i++)
    {
    	po_e = p_frm.elements[i];
    	if (po_e.name == po_checkbox.name)
    	    po_e.checked = po_checkbox.checked;
    }
}

function f_haychequeados(p_frm, ps_nbobj)
{
    for (var i=0;i < p_frm.elements.length;i++)
    {
    	po_e = p_frm.elements[i];
    	if (po_e.name == ps_nbobj)
    	    if (po_e.checked)
    	    	return(true);
    }
    return(false);
}

function f_valrut2(rut)
{
	var tmpstr = "";

/*	if (rut.indexOf('.') != -1)
		return(false);
	if (rut.indexOf('-') == -1)
		return(false);*/
	for ( i=0; i < rut.length ; i++ )
		if ( /*rut.charAt(i) != ' ' && rut.charAt(i) != '.' &&*/ rut.charAt(i) != '-' )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM+]
	tmpstr = "";
	for ( i=0; rut.charAt(i) == '0' ; i++ );
		for (; i < rut.length ; i++ )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM-]
	if ( largo < 2 )
	{
		alert("Debe ingresar el RUT completo.");
//		document.frm.rut_aux.focus();
//		document.frm.rut_aux.select();
		return false;
	}
	for (i=0; i < largo ; i++ )
	{
		if ( rut.charAt(i) != "0" && rut.charAt(i) != "1" && rut.charAt(i) !="2" && rut.charAt(i) != "3" && rut.charAt(i) != "4" && rut.charAt(i) !="5" && rut.charAt(i) != "6" && rut.charAt(i) != "7" && rut.charAt(i) !="8" && rut.charAt(i) != "9" && rut.charAt(i) !="k" && rut.charAt(i) != "K" )
		{
			alert("El formato del RUT es incorrecto");
//			document.frm.rut_aux.focus();
//			document.frm.rut_aux.select();
			return false;
		}
	}
	var invertido = "";
	for ( i=(largo-1),j=0; i>=0; i--,j++ )
		invertido = invertido + rut.charAt(i);
	var drut = "";
	drut = drut + invertido.charAt(0);
	drut = drut + '-';
	cnt = 0;
	for ( i=1,j=2; i<largo; i++,j++ )
	{
		if ( cnt == 3 )
		{
			drut = drut + '.';
			j++;
			drut = drut + invertido.charAt(i);
			cnt = 1;
		}
		else
		{
			drut = drut + invertido.charAt(i);
			cnt++;
		}
	}
	invertido = "";
	for ( i=(drut.length-1),j=0; i>=0; i--,j++ )
		invertido = invertido + drut.charAt(i);
	//document.frm.rut_aux.value = invertido;
	if ( checkDV(rut) )
		return true;
	else
		alert('RUT no es válido');
	return false;
}

function f_valrut(rut)
{
	var tmpstr = "";

	if (rut.indexOf('.') != -1)
		return(false);
	if (rut.indexOf('-') == -1)
		return(false);
	for ( i=0; i < rut.length ; i++ )
		if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM+]
	tmpstr = "";
	for ( i=0; rut.charAt(i) == '0' ; i++ );
		for (; i < rut.length ; i++ )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM-]
	if ( largo < 2 )
	{
//		alert("Debe ingresar el rut completo.");
//		document.frm.rut_aux.focus();
//		document.frm.rut_aux.select();
		return false;
	}
	for (i=0; i < largo ; i++ )
	{
		if ( rut.charAt(i) != "0" && rut.charAt(i) != "1" && rut.charAt(i) !="2" && rut.charAt(i) != "3" && rut.charAt(i) != "4" && rut.charAt(i) !="5" && rut.charAt(i) != "6" && rut.charAt(i) != "7" && rut.charAt(i) !="8" && rut.charAt(i) != "9" && rut.charAt(i) !="k" && rut.charAt(i) != "K" )
		{
//			alert("El valor ingresado no corresponde a un R.U.T valido.");
//			document.frm.rut_aux.focus();
//			document.frm.rut_aux.select();
			return false;
		}
	}
	var invertido = "";
	for ( i=(largo-1),j=0; i>=0; i--,j++ )
		invertido = invertido + rut.charAt(i);
	var drut = "";
	drut = drut + invertido.charAt(0);
	drut = drut + '-';
	cnt = 0;
	for ( i=1,j=2; i<largo; i++,j++ )
	{
		if ( cnt == 3 )
		{
			drut = drut + '.';
			j++;
			drut = drut + invertido.charAt(i);
			cnt = 1;
		}
		else
		{
			drut = drut + invertido.charAt(i);
			cnt++;
		}
	}
	invertido = "";
	for ( i=(drut.length-1),j=0; i>=0; i--,j++ )
		invertido = invertido + drut.charAt(i);
	//document.frm.rut_aux.value = invertido;
	if ( checkDV(rut) )
		return true;
	return false;
}

function checkDV( crut )
{
	largo = crut.length;
	if ( largo < 2 )
	{
//		alert("Debe ingresar el rut completo.");
//		document.frm.rut_aux.focus();
//		document.frm.rut_aux.select();
		return false;
	}
	if ( largo > 2 )
		rut = crut.substring(0, largo - 1);
	else
		rut = crut.charAt(0);
	dv = crut.charAt(largo-1);
	checkCDV( dv );
	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 es incorrecto.");
//		document.frm.rut_aux.focus();
//		document.frm.rut_aux.value = "";
		return false;
	}
	return true;
}

function checkCDV( dvr )
{
	dv = dvr + "";
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')
	{
//		alert("Debe ingresar un digito verificador valido.");
//		document.frm.rut_aux.focus();
//		document.frm.rut_aux.select();
		return false;
	}
	return true;
}

function f_check_entdec(ps_numero, pn_enteros, pn_nro_decimales)
{
	ls_numero = f_trim(ps_numero);

	if (ls_numero == "")
		return true;
	else
	if (!fb_inet_valcaracteres(ls_numero, "01234567890" + KS_SEP_DEC))
		return false;	
	else
	{
		ln_pos_coma = ls_numero.indexOf(KS_SEP_DEC);
		
		if (ln_pos_coma == -1 && fb_inet_esentero(ls_numero) && ls_numero.length <= pn_enteros) // Si No tiene decimales
			return true;

		if (ln_pos_coma < 1)  // Si es algo como ",2" o ","
			return false;

		if (ln_pos_coma == (ls_numero.length - 1))  // Si es algo como "2," 
			return false;

		ls_texto_decimal = ls_numero.substring(ln_pos_coma + 1, ls_numero.length);
		
		if (!fb_inet_esentero(ls_texto_decimal) || ls_texto_decimal.length > pn_nro_decimales)
			return false;
		
		ls_texto_entero = ls_numero.substring(0, ln_pos_coma);
		
		if (!fb_inet_esentero(ls_texto_entero) || ls_texto_entero.length > pn_enteros)
			return false;
		
		return true;
   }
}

function f_selbscav(p_s, ps_valor)
{
	for (i = 0; i < p_s.options.length; i++)
		if (p_s.options[i].value == ps_valor)
		{
			p_s.selectedIndex = i;
			//p_s.options[i].selected = true;
			return;
		}
	p_s.selectedIndex = 0;
}

function f_seliniv(p_s, ps_valor, ps_desc)
{
	p_s.options.length = 0;
	p_s.options.length = 1;
	p_s.options[0].value = ps_valor;
	p_s.options[0].text = ps_desc;
	p_s.selectedIndex = 0;
}

function f_crea_ajax()
{
	var lo_xmlhttp=false;
	try 
	{
		lo_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			lo_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (e) 
		{
			lo_xmlhttp = false;
		}
	}

	if (!lo_xmlhttp && typeof XMLHttpRequest!='undefined') 
	{
		lo_xmlhttp = new XMLHttpRequest();
		}
	return(lo_xmlhttp);
}

function f_dvOK( dvr )
{	
	dv = dvr + ""	
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')	
	{		
		return false;	
	}	
	return true;
}

function f_rutOK( crut )
{	
	largo = crut.length;	
	if ( largo < 2 )	
	{		
		return false;	
	}	
	if ( largo > 2 )		
		rut = crut.substring(0, largo - 1);	
	else		
		rut = crut.charAt(0);	
	dv = crut.charAt(largo-1);	
	f_dvOK( dv );	

	if ( rut == null || dv == null )
		return false	

	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() )	
	{		
		return false	
	}

	return true
}

function f_chequeaformatrut(ps_rut)
{	
	var tmpstr = "";
	texto = ps_rut.value;
	for ( i=0; i < texto.length ; i++ )		
		if ( texto.charAt(i) != ' ' && texto.charAt(i) != '.' && texto.charAt(i) != '-' )
			tmpstr = tmpstr + texto.charAt(i);	
	texto = tmpstr;	
	largo = texto.length;	

	if ( largo < 2 )	
	{		
		return false;	
	}	

	for (i=0; i < largo ; i++ )	
	{			
		if ( texto.charAt(i) !="0" && texto.charAt(i) != "1" && texto.charAt(i) !="2" && texto.charAt(i) != "3" && texto.charAt(i) != "4" && texto.charAt(i) !="5" && texto.charAt(i) != "6" && texto.charAt(i) != "7" && texto.charAt(i) !="8" && texto.charAt(i) != "9" && texto.charAt(i) !="k" && texto.charAt(i) != "K" )
 		{			
			return false;		
		}	
	}	

	var invertido = "";	
	for ( i=(largo-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + texto.charAt(i);	
	var dtexto = "";	
	dtexto = dtexto + invertido.charAt(0);	
	dtexto = dtexto + '-';	
	cnt = 0;	

	for ( i=1,j=2; i<largo; i++,j++ )	
	{		
		//alert("i=[" + i + "] j=[" + j +"]" );		
	/*	if ( cnt == 3 )		
		{			
			dtexto = dtexto + '.';			
			j++;			
			dtexto = dtexto + invertido.charAt(i);			
			cnt = 1;		
		}		
		else		*/
		{				
			dtexto = dtexto + invertido.charAt(i);			
			cnt++;		
		}	
	}	

	invertido = "";	
	for ( i=(dtexto.length-1),j=0; i>=0; i--,j++ )		
		invertido = invertido + dtexto.charAt(i);	

	ps_rut.value = invertido.toUpperCase()		
	if ( f_rutOK(texto) )		
		return true;	

	return false;
}

function f_spinselect(p_s, pn_inc, pb_circular)
{
	if (p_s.options.length <= 0)
		return(false);
	li_indice = p_s.selectedIndex + pn_inc;
	
	if (li_indice >= p_s.options.length && pb_circular)
	{
		p_s.selectedIndex = 0;
		p_s.form.submit();
		return(true);
	}
	if (li_indice < 0 && pb_circular)
	{
		p_s.selectedIndex = p_s.options.length - 1;
		p_s.form.submit();
		return(true);
	}
	if (li_indice >= p_s.options.length || li_indice < 0)
		return(false);
	p_s.selectedIndex = li_indice;
	p_s.form.submit();
	return(true);
}

/*
Nombre: f_chequehr
Descripción: Valida y formatea hora
Parametros: po_hora: hora 
			ps_formato: Formatos posibles hhmm, hhmmss, hh:mm, hh:mm:ss
Retorno: Retorna TRUE si la hora es correcta
*/
function f_chequeahr(po_hora, ps_formato)
{
	var hh_min = 0;
	var hh_max = 23;
	var mm_min = 0;
	var mm_max = 59;
	var ss_min = 0;
	var ss_max = 59;
	var delim  = ':';
	var formato_default = "hh:mm";

	var ls_hora = f_trim(po_hora.value);

	if (ps_formato != undefined && f_trim(ps_formato) != "")
		switch (ps_formato)
		{
			case 'hhmm'    : break
			case 'hhmmss'  : break
			case 'hh:mm'   : break;
			case 'hh:mm:ss': break;
			default        : return(false);
		}
	else
		ps_formato = formato_default;
	if (ls_hora.length < 4 || ls_hora.length > 8)
		return(false);
	
	ls_ss = "00";
	switch (ls_hora.length)
	{
		case 4: // hhmm

			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			ls_mm = ls_hora.substr(2, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);
			break;
		case 6: // hhmmss
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			ls_mm = ls_hora.substr(2, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);	
			ls_mm = ls_hora.substr(4, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_ss, ss_min, ss_max))
				return(false);
			break;
		case 5: // hh:mm
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			if (ls_hora.substr(2, 1) != ":")
				return(false);
			ls_mm = ls_hora.substr(3, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);	
			break;
		case 8: // hh:mm:ss
			ls_hh = ls_hora.substr(0, 2);
			if (!fb_inet_esentero(ls_hh) || !fb_inet_entre(ls_hh, hh_min, hh_max))
				return(false);
			if (ls_hora.substr(2, 1) != ":")
				return(false);
			ls_mm = ls_hora.substr(3, 2);	
			if (!fb_inet_esentero(ls_mm) || !fb_inet_entre(ls_mm, mm_min, mm_max))
				return(false);
			if (ls_hora.substr(5, 1) != ":")
				return(false);
			ls_ss = ls_hora.substr(6, 2);	
			if (!fb_inet_esentero(ls_ss) || !fb_inet_entre(ls_ss, ss_min, ss_max))
				return(false);
			break;
		default:
			return(false);
	}
	
	switch (ps_formato)
	{
		case 'hhmm'    : 
			po_hora.value = (ls_hh) + (ls_mm);
			break;	
		case 'hhmmss'  :
			po_hora.value = (ls_hh) + (ls_mm) + (ls_ss);
			break;	
		case 'hh:mm'   :
			po_hora.value = (ls_hh) + delim + (ls_mm);
			break;	
		case 'hh:mm:ss':
			po_hora.value = (ls_hh) + delim + (ls_mm) + delim + (ls_ss);
			break;	
		default        : 
			return(false);
	}
	return(true);
}

function f_ir(po_s,ps_valor_ignorar)
{
	ls_destino = po_s.options[po_s.selectedIndex].value;
	if (ls_destino != ps_valor_ignorar) location.href = ls_destino;
}

/*
Nombre: fs_inet_trim
Descripción: Quita espacios a la izquierda y derecha de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function fs_inet_trim(TRIM_VALUE)
{
        if(TRIM_VALUE.length < 1){
        return"";
        }
        TRIM_VALUE = fs_inet_rtrim(TRIM_VALUE);
        TRIM_VALUE = fs_inet_ltrim(TRIM_VALUE);
        if(TRIM_VALUE=="")
        {
                return "";
        }
        else
        {
                return TRIM_VALUE;
        }
} //End Function

/*
Nombre: fs_inet_rtrim
Descripción: Quita espacios a la derecha de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function fs_inet_rtrim(VALUE)
{
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
        if(v_length < 0)
        {
                return"";
        }
        var iTemp = v_length -1;

        while(iTemp > -1)
        {
                if(VALUE.charAt(iTemp) == w_space)
                {
                }
                else
                {
                        strTemp = VALUE.substring(0,iTemp +1);
                        break;
                }
                iTemp = iTemp-1;
        } //End While
        return strTemp;
} //End Function

/*
Nombre: fs_inet_ltrim
Descripción: Quita espacios a la izquierda de un string
Parametros: String al que se le quitarán los espacios
Retorno: String
*/
function fs_inet_ltrim(VALUE)
{
        var w_space = String.fromCharCode(32);

        if(v_length < 1)
        {
                return"";
        }
        var v_length = VALUE.length;
        var strTemp = "";
        var iTemp = 0;

        while(iTemp < v_length)
        {
                if(VALUE.charAt(iTemp) == w_space)
                {
                }
                else
                {
                        strTemp = VALUE.substring(iTemp,v_length);
                        break;
                }
                iTemp = iTemp + 1;
        } //End While
        return strTemp;
} //End Function

/*
Nombre: f_inet_focoerr
Descripción: Coloca el foco en  po si pb_sin_error es false
Parametros: po: Objeto al cual se le da el foco
            ps_msg: Mensaje de alerta para el error
            pb_sin_error: Undefined y False indica que hay error yse pone el foco en objeto po. True que no se coloca foco
			
Retorno: Ninguno
*/
function f_inet_focoerr(po,ps_msg,pb_sin_error)
{
	if (pb_sin_error == undefined || !pb_sin_error)
	{
		alert(ps_msg);
		lo_tmp = po;
		setTimeout("lo_tmp.focus(); lo_tmp.select()", 0); 
//		po.focus();
//		po.select();
		return;
	}
}

function f_verocultar(id1, id2)
{
        if (id1 != '') f_toggleview(id1);
        if (id2 != '') f_toggleview(id2);
}

function f_toggleview(id)
{
        if ( ! id ) return;
        
        if ( itm = f_getbyid(id) )
        {
                if (itm.style.display == "none")
                {
                        f_ver_div(itm);
                }
                else
                {
                        f_ocultar_div(itm);
                }
        }
}

function f_getbyid(id)
{
        itm = null;
        
        if (document.getElementById)
        {
                itm = document.getElementById(id);
        }
        else if (document.all)
        {
                itm = document.all[id];
        }
        else if (document.layers)
        {
                itm = document.layers[id];
        }
        
        return itm;
}

function f_ocultar_div(itm)
{
        if ( ! itm ) return;
        
        itm.style.display = "none";
}

function f_ver_div(itm)
{
        if ( ! itm ) return;
        
        itm.style.display = "";
}
