var undefined;

String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function salirSesion(){
	var nombre = "";
	var pars = "";
    var destino = "/Interfaces/salirSesion.aspx";
    alert(closing);
    if (closing || (window.event.clientX < 0) && (window.event.clientY < 0)){
	   nombre = "salirSesion";
	   pars = "menubar=0,toolbar=0,scrollbars=0,resizable=0," +
			 "width=250,height=200,left=20,top=20,status=0,location=0";
	   alert("abrirInforme " + destino);
	   window.open(destino, nombre, pars);
    }
	return true;
}

function cadenaArreglo(cadena)
// *******************************************************************************************************************
// * Descripcion: Crea un arreglo a partir de una cadena con separador "|"
// * Autor		: Froilan Cortes Ladino
// *******************************************************************************************************************
{
	var arreglo = new Array();
	arreglo= cadena.split("|");
	return arreglo;
}

function arregloCadena(arreglo)
// *******************************************************************************************************************
// * Descripcion: Crea una cadena a partir de un arreglo con separador "|"
// * Autor		: Froilan Cortes Ladino
// *******************************************************************************************************************
{
	var cadena = "";
	var i=0;
	while (arreglo[i]!=undefined && arreglo[i]!=null)
		cadena+=arreglo[i] + "|";
	return arreglo;
}

function formatearNumero(num)
// *********************************************************************
// * Descripcion: formatea nmeros con separadores de mil y dos decimales
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	var texto = new String();
	texto = "";
	if (isNaN(num) || num == null || !isFinite(num))
		return "&nbsp;";
	texto = "" + (Math.round (num*100)/100);
	return texto;
}

function formatearNumero0(num)
// *********************************************************************
// * Descripcion: formatea nmeros con separadores de mil y sin decimales
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	var texto = new String();
	var texto2 = new String();
	var longitud = 0;
	texto = "";
	if (isNaN(num) || num == null || !isFinite(num))
		return "&nbsp;";
	texto2 = "" + (Math.round (num));
	longitud = texto2.length;
	if (longitud > 6)
	{
		texto = "," + texto2.substr(longitud-6, 3);
		texto = texto + "," + texto2.substr(longitud-3, 3);
		texto = texto2.substr(0,longitud-6) + texto;
	}
	else if (longitud > 3)
	{
		texto = texto + "," + texto2.substring(longitud, longitud-3);
		texto = texto2.substr(0,longitud-3) + texto;
	}
	else
		texto = texto2;
	return texto;
}

function formatearNumero0(num, separador)
// *********************************************************************
// * Descripcion: formatea nmeros con separadores de mil y sin decimales
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	var texto = new String();
	var texto2 = new String();
	var longitud = 0;
	texto = "";
	if (isNaN(num) || num == null || !isFinite(num))
		return "&nbsp;";
	texto2 = "" + (Math.round (num));
	longitud = texto2.length;
	if (longitud > 9)
	{
		texto = separador + texto2.substr(longitud-9, 3);
		texto = texto + separador + texto2.substr(longitud-6, 3);
		texto = texto + separador + texto2.substr(longitud-3, 3);
		texto = texto2.substr(0,longitud-9) + texto;
	}
	else if (longitud > 6)
	{
		texto = separador + texto2.substr(longitud-6, 3);
		texto = texto + separador + texto2.substr(longitud-3, 3);
		texto = texto2.substr(0,longitud-6) + texto;
	}
	else if (longitud > 3)
	{
		texto = texto + separador + texto2.substring(longitud, longitud-3);
		texto = texto2.substr(0,longitud-3) + texto;
	}
	else
		texto = texto2;
	return texto;
}

function fechaDias(sfecha)
// *********************************************************************
// * Descripcion: devuelve la cantidad de das de una fecha, en formato aaaa/mm/dd, a partir de 1970/1/1
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	sfecha = "" + sfecha;
	var cadena= "";
	var dias=0;
	//alert ("in4:" + sfecha.indexOf("/",4) + " in5:" + sfecha.indexOf("/",6))
	if (sfecha.indexOf("/",5)==7)
		cadena = sfecha.substr(5,2) + "/" + sfecha.substr(8,2) + "/" + sfecha.substr(0,4);
	else
		cadena = sfecha.substr(5,1) + "/" + aNumeros(sfecha.substr(7,2)) + "/" + sfecha.substr(0,4);
	var fecha = new Date(cadena);
	dias = fecha.getTime()/1000; //en segundos
	dias /=60; //en minutos
	dias /=60; //en horas
	dias /=24; //en dias
	//alert("fecha: " + fecha + "dias: " + dias);
	return dias;
}

function aNumeros(txtNum)
// *********************************************************************
// * Descripcion: convierte una cadena de texto txtNum en una cadena numrica, eliminando caracteres que no son numricos
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	var txtNumi = new String ();
	var txtRes = new String (), txtNumeros = "0123456789.";
	var numi = new Number ();
	var i=0;
	if (txtNum == null || txtNum == "")
		return 0;
	txtRes.concat("");
	for(i=0; i<txtNum.length; i++)
	{
		txtNumi = txtNum.charAt(i);
		if (txtNumeros.indexOf(txtNumi) >= 0)
		{
			txtRes = txtRes.concat(""+txtNumi+"");
		}
	}
	if (txtRes == null || txtRes == "")
		return 0;
	return txtRes;
}

function aNumeros0(txtNum)
// *********************************************************************
// * Descripcion: convierte una cadena de texto txtNum en una cadena numrica, eliminando caracteres que no son numricos
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
{
	var txtNumi = new String ();
	var txtRes = new String (), txtNumeros = "0123456789";
	var numi = new Number ();
	var i=0;
	if (txtNum == null || txtNum == "")
		return 0;
	txtRes.concat("");
	for(i=0; i<txtNum.length; i++){
		txtNumi = txtNum.charAt(i);
		if (txtNumi.indexOf(".") >= 0)
		    break;
		if (txtNumeros.indexOf(txtNumi) >= 0){
			txtRes = txtRes.concat(""+txtNumi+"");
		}
	}
	if (txtRes == null || txtRes == "")
		return 0;
	return txtRes;
}

// *********************************************************************
// * Descripcion: convierte una cadena de texto txtNum en una cadena numrica, eliminando caracteres que no son numricos
// * Autor		: Froilan Cortes Ladino
// **********************************************************************
function limitarTexto(campo, maxlimit)
{
	if (campo.value.length > maxlimit) // cortarlo, si es muy largo!
		campo.value = campo.value.substring(0, maxlimit);
}

function imprimirPagina(){
  try{
    //window.print;
    if (window.print) {
      //top.frames[].focus();
      top.frames[1].print();
    }
    parent.framePrincipal.print();
    if (window.print) {
        if (confirm("Imprimir?")) {
            window.print();
        }
    }

  }
  catch (e){
    print("error: " + e);
  }
  alert("enviado a imprimir");
}

// ******************************************************************************
// * Descripcion: Imprime con objeto ScriptX, escondiendo boton de Imprimir
// *				además de no mostrar encabezados y pies del navegador
// * Autor      : Froilan Cortes Ladino
// * Parámetros : regreso: pagina donde debe regresar
// * Devuelve   : imprime la pagina
// ******************************************************************************
function doprint(regreso) {
    if (!factory.object) {
        return
    } else {
        var h = factory.printing.header;
        var f = factory.printing.footer;
        var l = factory.printing.leftMargin;
        var r = factory.printing.rightMargin;
        var t = factory.printing.topMargin;
        var b = factory.printing.bottomMargin;
        //hide the button
        document.all("btnImprimir").style.visibility = 'hidden';
        //document.all("btnVolver").style.visibility = 'hidden';
        //document.all("btnComponente").style.visibility = 'hidden';
        //set header and footer to blank
        factory.printing.header = "";
        factory.printing.footer = "";
        factory.printing.portrait = true;
        //factory.printing.paperSize = "Letter";
        //factory.printing.SetMarginMeasure(1);
        factory.printing.leftMargin = 10;
        factory.printing.rightMargin = 10;
        factory.printing.topMargin = 10;
        factory.printing.bottomMargin = 10;
        //factory.printing.disableUI = true; // disable IE native printing UI

        // enable control buttons
        /*var templateSupported = factory.printing.IsTemplateSupported();
        var controls = imprimir.all.tags("input");
        for (i = 0; i < controls.length; i++) {
            controls[i].disabled = false;
            if (templateSupported && controls[i].className == "ie55") {
                controls[i].style.display = "inline";
            }
        }*/

        factory.printing.Print(true);
        /*
        if (factory.printing.Print(true)){
        //SpoolStatus(true);
        //factory.printing.WaitForSpoolingComplete();
        //SpoolStatus(false);
        }
        */

        //restore user's info
        factory.printing.header = h;
        factory.printing.footer = f;
        factory.printing.leftMargin = l;
        factory.printing.rightMargin = r;
        factory.printing.topMargin = t;
        factory.printing.bottomMargin = b;
        //show the print button
        document.all("btnImprimir").style.visibility = 'visible';
        //document.all("btnVolver").style.visibility = 'visible';
        //document.all("btnComponente").style.visibility = 'visible';
        //salir de la impresion y saltar a otra pagina o regresar
        if (!(regreso == "" || regreso == null)) {
            window.location = regreso;
        }else
            history.go(-1);
    }
    return true;
}

function actualizarElementos(forma) {
  with (forma){
  	actualizarLista(hidCategoria, cmbcategoria);
  }
}

function actualizarOrden(forma){
with(forma){
  actualizarLista(hidproveedor,cmbproveedor);
  }
}
function actualizarModelo(forma)
  {

    with (forma)
      {
  	  actualizarLista(hidmodelo, cmbmodelo);
  	  actualizarLista(hidarticulo, cmbarticulo);
      }
  }

function actualizarOrdenArt(forma)
{
  with(forma){
  actualizarLista(hidia,cmbdia);
  actualizarLista(hidmes,cmbmes);
  }
}
function actualizarPedido(forma){
with(forma){
  actualizarLista(hidpedido,cmbpedido);
  }
}
function actualizarLista(hidValor, lista)
{
for (i=0;i<lista.length;i++)
    {
		if (lista[i].value==hidValor.value){
	  		lista.selectedIndex = i;
		}
	}
}
function actualizartipoSat(hidValor,lista)
{

for (i=0;i<lista.length;i++)
    { //alert(lista[i].value + "-" + hidValor);
		if (lista[i].value==hidValor){
	  		lista.selectedIndex = i;
		}
	}
}

function confirmarDatos(pregunta)
{
	var confirma = new Boolean();
	return confirma = confirm(pregunta);
}

function validarEmail(strEmail)
// ******************************************************************************
// * Descripcion: Valida que una direccin de email sea correcta
// * Autor      : Elkin Leandro Torres Vargas
// * Parmetros : strEmail, direccin de emial a evaluar. Ej: 'elkin@torre.nu'
// * Devuelve   : Valor de verdad sobre si la direccin de email es vlida o no
// ******************************************************************************
{
    var posicionPrimerEspacio = 0;
    var posicionPrimeraArroba = 0;
    var posicionSegundaArroba = 0;
    var posicionUltimaArroba = 0;
    var posicionPrimerPunto = 0;
    var posicionUltimoPunto = 0;
    var longitudEmail = 0;
    var strAntesArr = "";
    var longitudAntesArr = 0;
    var posUPuntoAntesArr = 0;
    var distArrPunto = 0;
    var distPuntoArr = 0;

    longitudEmail = strEmail.length;
    posicionPrimerEspacio = strEmail.indexOf(" ");
    //Tiene espacios
    if (posicionPrimerEspacio != -1)
		return false;
	//No tiene espacios
	else
	{
		posicionPrimeraArroba = strEmail.indexOf("@");
		//No tiene el caracter '@'
		if (posicionPrimeraArroba == -1)
			return false;
		//Tiene por lo menos un caracter '@'
		else
		{
			posicionUltimaArroba = strEmail.lastIndexOf("@");
			//No empieze ni termine con '@'
			if ((posicionPrimeraArroba == 0) || (posicionUltimaArroba == longitudEmail-1))
				return false;
			posicionSegundaArroba = strEmail.indexOf("@",posicionPrimeraArroba+1);
			//Tiene 2 o ms caracteres '@'
			if (posicionSegundaArroba != -1)
				return false;
			posicionPrimerPunto = strEmail.indexOf(".");
			//No tiene el caracter '.'
			if (posicionPrimerPunto == -1)
				return false;
			else
			{
				posicionUltimoPunto = strEmail.lastIndexOf(".");
				//No empieze ni termine con '.'
				if ((posicionPrimerPunto == 0) || (posicionUltimoPunto == longitudEmail-1))
					return false;
				//Con mnimo 2 espacios despus del ltimo '.'
				if (posicionUltimoPunto >= longitudEmail-2)
					return false;
				strAntesArr = strEmail.substr(0,posicionPrimeraArroba);
				longitudAntesArr = strAntesArr.length;
				posUPuntoAntesArr = strAntesArr.lastIndexOf(".");
				distArrPunto = 	longitudAntesArr - posUPuntoAntesArr;
				distPuntoArr = strEmail.indexOf(".",posicionPrimeraArroba+1) - posicionPrimeraArroba;
				//Con mnimo 2 espacios entre '@' y '.'
				if (distPuntoArr <= 1)
					return false;
				if (distArrPunto <= 1)
					return false;
			}
		}
	}
	return true;
}

function validarFechaCorrecta(strDia, strMes, intAnno)
// ************************************************************************************************************************
// * Descripcion: Vlida que una combinacin de dia, mes y ao corresponda a una fecha verdadera
// * Autor      : Elkin Leandro Torres Vargas
// * Modificado : Froilan Cortes Ladino
// * Parmetros : strDia, dia como cadena. Ej: '23'; strMes, mes como cadena. Ej: '9';
// *              intAnno, ao como entero de 4 cifras. Ej: 1979
// * Devuelve   : Valor de verdad sobre si es  no correcta la fecha
// *************************************************************************************************************************
{
	var dia = 0;
	var mes = 0;
	var anno = 0;
	var noBisiesto = 0;
	var esCorrecta = true;

	dia = parseInt(strDia,10);  //Valores 1-31
	mes = parseInt(strMes,10);  //Valores 0-11
	mes -=1;
	anno = intAnno;
	noBisiesto = !(((anno%4==0) && (anno%100!=0))||(anno%400==0));
	//Validar nmero de das segun el mes
	if (dia < 1 || dia > 31) esCorrecta = false;
	if (mes < 0 || mes > 11) esCorrecta = false;
	if(!(noBisiesto) && (mes == 1) && (dia > 29))  //Febrero y Ao bisiesto (29)
		esCorrecta = false;
	else if(noBisiesto && (mes == 1) && (dia > 28))  //Febrero y Ao no bisiesto (28)
		esCorrecta = false;
    	else if(((mes == 3) || (mes == 5) || (mes == 8) || (mes == 10)) && (dia > 30))  //Abril, Junio, Septiembre, Noviembre (30)
		esCorrecta = false;
	if (!(esCorrecta))
	{
		alert("El numero de dias no corresponde con el mes seleccionado.");
		return false;
	}
	if (anno < 1800 || anno > 2010) esCorrecta = false;
	if (!(esCorrecta))
	{
		alert("El año no es correcto.");
		return false;
	}
	return true;
}

function validarFechaMenorOIgual(strDiaMenor, strMesMenor, intAnnoMenor, strDiaMayor, strMesMayor, intAnnoMayor)
// ***************************************************************************************************************************
// * Descripcion: Valida que una fecha sea menor o igual que otra
// * Autor      : Elkin Leandro Torres Vargas
// * Parmetros : strDiaMenor, dia de la fecha menor; strMesMenor, mes de la fecha menor; intAnnoMenor, ao de la fecha menor;
// *			  strDiaMayor, dia de la fecha mayor; strMesMayor, mes de la fecha mayor; intAnnoMayor, ao de la fecha mayor;
// * Devuelve   : Valor de verdad sobre si la fecha menor EN VERDAD es menor o igual que la mayor
// ***************************************************************************************************************************
{
	var diaI, mesI, annoI, diaF, mesF, annoF;
	diaI = parseInt(strDiaMenor,10);
	mesI = parseInt(strMesMenor,10);
	annoI = parseInt(intAnnoMenor,10);
	diaF = parseInt(strDiaMayor,10);
	mesF = parseInt(strMesMayor,10);
	annoF = parseInt(intAnnoMayor,10);
	//alert("diaI: " + diaI + " mesI: " + mesI + " annoI: " + annoI + "\ndiaF: " + diaF + " mesF: " + mesF + " annoF: " + annoF);
	if (annoF > annoI) return true;
	else if (annoF == annoI && mesF > mesI) return true;
	else if (annoF == annoI && mesF == mesI && diaF >= diaI) return true;
	else return false;
}

function valEntero(q){
// *******************************************************************************************************************
//  Descripcion: Verifica que una cadena contenga nicamente caracteres numricos.
//               Ninguno de los caracteres que componen la cadena debe ser diferente de los
//	             caracteres de la lista "0123456789"
//  Autor		  :  Margarita Ballesteros
//  Parametros:  q : Cadena que se quiere evaluar
//  Retorna   :  "true"  "false" segn sea el caso
// *******************************************************************************************************************
	var test = true;
	cadena = q.toString();
	for (var i = 0; i < cadena.length; i++)
		{
			var caracter = cadena.charAt(i)
			if (caracter < "0" || caracter > "9")
		     {
				test = false;
			   }
		}
	return test;
 }

function depurarTexto(texto)
// *******************************************************************************************************************
// * Descripcion: Elimina caracteres especiales y otros enviados en un textarea
// * Autor		: Froilan Cortes Ladino
// * Parmetros : texto es un objeto que representa un input de tipo Text o TextArea
//                en una forma html
// * Modificado : Margarita Ballesteros
// *******************************************************************************************************************
  {
	//Verificar valores
	var descripcion = "";
	if (texto.value == null || texto.value == "")
	{
		texto.value = "";
		return;
	}
	descripcion = texto.value;
	while (descripcion.indexOf(String.fromCharCode(13)) >=0 ||
			descripcion.indexOf(String.fromCharCode(10)) >=0 ||
			descripcion.indexOf("\"") >=0 ||
			descripcion.indexOf("'") >=0
			)
	{
		descripcion = descripcion.replace(String.fromCharCode(13),"<br>");
		descripcion = descripcion.replace(String.fromCharCode(10),"");
		descripcion = descripcion.replace("\"","");
		descripcion = descripcion.replace("'","");
	}
	texto.value = descripcion;
}

function abrirExcel(forma){
	//alert("abrirExcel");
	forma.validaExcel.value = "1";
	return true;
}

function abrirInforme(forma, destino){
	var nombre = "";
	var pars = "";
	nombre = "informe" + destino.substring(0,destino.indexOf(".")-1);
	pars = "menubar=1,toolbar=0,scrollbars=1,resizable=1," +
			"width=750,height=550,left=20,top=20,status=1,location=0";
	//alert("abrirInforme " + destino + "?tipoConsulta=" + forma.ddlConsulta.value);
	if (destino.indexOf("?") > 0)
	    window.open(destino + "&tipoConsulta=" + forma.ddlConsulta.value, nombre, pars);
	else
	    window.open(destino + "?tipoConsulta=" + forma.ddlConsulta.value, nombre, pars);
	return false;
}

function abrirRedInforme(forma, destino){
	var nombre = "";
	var pars = "";
	nombre = "rinforme" + destino.substring(0,destino.indexOf(".")-1);
	pars = "menubar=1,toolbar=0,scrollbars=1,resizable=1," +
			"width=750,height=550,left=20,top=20,status=1,location=0";
	//alert("abrirInforme " + destino + "?codigoConsulta=" + forma.codigo.value);
	if (destino.indexOf("?") > 0)
	    window.open(destino + "&codigoConsulta=" + forma.codigo.value, nombre, pars);
	else
	    window.open(destino + "?codigoConsulta=" + forma.codigo.value, nombre, pars);
	return false;
}

function abrirExtracto(forma, destino,anno, mes){
	var nombre = "";
	var pars = "";
	nombre = "extracto" + destino.substring(0,destino.indexOf(".")-1);
	pars = "menubar=1,toolbar=0,scrollbars=1,resizable=1," +
			"width=750,height=550,left=20,top=20,status=1,location=0";
	//alert("abrirInforme " + destino + "?tipoConsulta=" + forma.ddlConsulta.value);
	window.open(destino + "?anno=" + anno + "&mes=" + mes, nombre, pars);
	return false;
}

function abrirProducto(idProducto){
	var pars = "";
	var destino = "";
	destino = "../Respuestas/verProducto.aspx";
	nombre = "producto" + idProducto;
	pars = "menubar=0,toolbar=0,scrollbars=1,resizable=1," +
			"width=620,height=550,left=20,top=20,status=0,location=0";
	//alert("abrirInforme " + destino + "?tipoConsulta=" + forma.ddlConsulta.value);
	window.open(destino + "?idProducto=" + idProducto, nombre, pars);
	return false;
}

function abrirEventos(fecha){
	var pars = "";
	var destino = "";
	//alert(fecha);
	fecha = fecha.replace("/","");
	fecha = fecha.replace("/","");
	destino = "/Respuestas/verEventos.aspx";
	nombre = "eventos" + fecha;
	pars = "menubar=0,toolbar=0,scrollbars=1,resizable=1," +
			"width=720,height=550,left=20,top=20,status=1,location=0";
	//alert("abrirEventos " + destino + "?fecha=" + fecha);
	window.open(destino + "?fecha=" + fecha, nombre, pars);
	return true;
}

// ************************************************************************************************************************
// * Descripcion: en una pgina .Net hace Submit a otra desde un botn de servidor Button.
// * Autor      : Froilan Corts Ladino
// * Parmetros : forma, la forma (como objeto) donde se encontrar el foco
// * Devuelve   : Ubica el foco del cursor en el campo nombrado en el elemento forma.foco
// *************************************************************************************************************************
function submitPagina(objeto, pagina){
	var f
	if (objeto != null)
		f = objeto.form;
	else
		f = this.form;
	f.action = pagina;
	if (f.__VIEWSTATE != null){
		f.__VIEWSTATE.value = "";
		f.__VIEWSTATE.name = 'NOVIEWSTATE';
	}
	if (objeto == null || objeto.type != "submit")
		f.submit();
	return true;
}

function irMall(){
	;
}

function x () {
return;
}

function storeCaret (textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	} // end if
} // end storeCaret

function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		// MSIE
		var caretPos = textEl.caretPos;
		caretPos.text =
			caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			text + ' ' : text;
	} else if(textEl.selectionStart && textEl.setSelectionRange) {
		// Mozilla 1.3+
		var val = textEl.value;
		var cpos = textEl.selectionStart;
		var fpos = cpos + text.length;

		var before = val.substr(0,cpos);
		var after = val.substr(cpos, val.length);
		var aspace = after.charAt(0) == ' ' ? "" : " ";
		var bspace = before.charAt(before.length) == ' ' ? "" : " ";

		textEl.value = before + bspace + text + aspace + after;
		textEl.setSelectionRange(fpos,fpos); // set cursor pos to end of text
		textEl.focus();
	} else {
		textEl.value  = textEl.value + text; // otherwise just append
	}

	return true;
} // end insertAtCaret




function DoSmilie(addSmilie) {
	var revisedMessage;
	var currentMessage = document.replier.message.value;
	revisedMessage = currentMessage+addSmilie;
	document.replier.message.value=revisedMessage;
	document.replier.message.focus();
	return;
}

// ************************************************************************************************************************
// * Descripcion: Valida los campos de una forma y sus tipos de datos
// * Autor      : Froilan Corts Ladino
// * Parmetros : forma, el objeto de la forma
// * Devuelve   : Verdadero si se cumple todo
// * Descripcion: Valida segn el nombre de los campos de la forma y el ttulo de los mismos
// * 			En la propiedad nombre las tres primeras letras indican el tipo entre:
// * 				ent	numrico sin decimales
// * 				num	numrico con decimales y punto separador
// * 				txt	texto alfanumrico
// * 				fec	fecha
// * 				eml	e-mail
// * 			En la propiedad nombre si el cuarto caracter es "1" (numero uno) se toma como requerido
// * 			En la propiedad title debe encontrarse un nombre amigable hacia el usuario
// *************************************************************************************************************************
function validarCamposForma(forma) {
	var esValido = false;
	var nomCampo = "";
	var titulo = "";
	var elementos = "";
	var elemento;
	var requerido = false;
	var numerico = false;
	var obligatotios = "";
	var numericos = "";
	var positivos = "";
	var esNum = false;
	var esPos = false;
	var valor = "";
	with (forma){
		for(i=0;i<elements.length;i++){
			esNum = false;
			esPos = false;
			elemento= forma.elements[i];
			if (elemento.value == null || elemento.type == "hidden")
				continue;
			///alert(elemento.type);
			//alert(elemento.name);
			//alert(elemento.value);
			nomCampo = "" + elemento.name;
			nomCampo= nomCampo.toLowerCase();
			alert(nomCampo);
			if (nomCampo.indexOf("ddl") >= 0)
				continue;
			obligatotios = forma.obligatorio.value;
			obligatotios= obligatotios.toLowerCase();
			numericos = forma.numerico.value;
			numericos= numericos.toLowerCase();
			//alert("numericos: " + numericos)
			positivos = forma.positivo.value;
			positivos= positivos.toLowerCase();
			//alert("positivos: " + positivos)
			titulo = elemento.title;
			if (titulo == "")
				titulo = nomCampo;
			valor = "" + elemento.value;
			requerido = false;
			if (nomCampo.substring(3,4) == "1" || obligatotios.indexOf(","+nomCampo+",")>=0){
				requerido = true;
			}
			if (numericos.indexOf(","+nomCampo+",") >=0){
				elemento.value = aNumeros(elemento.value);
				//elemento.value = aNumerosPesos(elemento.value);
				valor = elemento.value;
				//alert("valor: " + valor);
				esNum = true;
			}
			if (positivos.indexOf(","+nomCampo+",") >=0){
				elemento.value = aNumeros(elemento.value);
				//elemento.value = aNumerosPesos(elemento.value);
				valor = elemento.value;
				//alert("valorPos: " + valor);
				esPos = true;
			}
			if (requerido && (valor == null || valor == ""  || valor == " "  || (esPos && valor == "0"))){
				window.alert("El campo " + titulo + " es requerido");
				elemento.focus ();
				return false;
			}
			if (nomCampo.substring(0,3) == "ent" && !valEntero(valor)){
				alert("El campo " + titulo + " slo acepta datos nmericos enteros, sin decimales");
				elemento.focus();
				return false;
			}
			if ((nomCampo.substring(0,3) == "num" || esNum) && !valNumero(valor)){
				alert("El campo " + titulo + " slo acepta datos nmericos y el punto como separador de decimales");
				elemento.focus();
				return false;
			}
			if (positivos.indexOf(","+nomCampo+",")>=0 && valor <= 0){
				alert("El campo " + titulo + " requiere un valor en rango correcto");
				elemento.focus();
				return false;
			}
			if (nomCampo.substring(0,3) == "txt"){
				valor=depurarTexto(valor);
				elemento.value=valor;
			}
			if (nomCampo.substring(0,3) == "eml" && !validarEmail(valor)){
				alert("El campo " + titulo + " debe ser una direccin de email vlida");
				elemento.focus();
				return false;
			}
			if (nomCampo.substring(0,3) == "fec" && !validarFecha(elemento)){
				alert("El campo " + titulo + " debe ser una fecha vlida");
				elemento.focus();
				return false;
			}
			elementos += elemento.name + ", ";//+ "\n"
		}//end for
		//forma.texto.value=elementos;
	}//end with
	//alert("ok validacion");
	forma.validaOk.value = 1;
	return true;
} //end validarCamposForma


