function fcDraw(){
	var chartObj = new FusionCharts("/flash/"+arguments[0]+"?XMLLoadingText=Cargando Datos...&InvalidXMLText=Sin Datos para mostrar.", "fcGraph", arguments[1], arguments[2], "0", "1");
	chartObj.setDataURL(escape(arguments[3]));
	chartObj.render(arguments[4]);
}
function irA(elemID) {
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
		offsetLeft += parseInt(document.body.leftMargin);
		offsetTop += parseInt(document.body.topMargin);
	}
window.scrollTo(offsetLeft,offsetTop)
}
function muestra(cuadro_n) {
	var mousetop=0, mouseleft=0;
	mousetop=window.event.y+document.body.scrollTop+10;
	mouseleft=window.event.x+document.body.scrollLeft+10;
	eval("document.all."+cuadro_n+".style.top="+mousetop);
	eval("document.all."+cuadro_n+".style.left="+mouseleft);
	eval("document.all."+cuadro_n+".style.visibility='visible'");
}
function oculta(cuadro_n){eval("document.all."+cuadro_n+".style.visibility='hidden'")}
function MGM_openWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function printPage() {
	if (window.print){
		if(_stack.length!=0)
			ttss = setTimeout("printPage()", 20);
		else{
			agree = confirm('¿Desea imprimir ahora?');
			if (agree)
				window.print();
			clearTimeout(ttss);
		}
   	}
   	else
  		alert ("Su navegador no acepta el comando de impresion directa. Utilice la opcion Imprimir del Menu de Archivo para imprimir.");  
}

function ltrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function rtrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}
function trim(str){
	return rtrim(ltrim(str))
}

function left(str, n){
	return (n<=0?'':(n>String(str).length?str:String(str).substring(0,n)))
}

function right(str, n){
	return (n<=0?'':(n>String(str).length?str:String(str).substring(String(str).length,String(str).length - n)))
}

function formatnumber(expr, decplaces){
	return Math.floor(expr * Math.pow(10,decplaces))/Math.pow(10,decplaces)
} 

function isvaliddate(day,month,year){
	var dteDate;
	dteDate=new Date(year,month,day);
	return((day==dteDate.getDate())&&(month==dteDate.getMonth())&&(year==dteDate.getFullYear()))
}

function show_div(nom_div,nom_img){
	if(trim(nom_img)!=''){
		fle = new Image(6,6);
	}
	if(typeof(eval("document.all."+nom_div)) == 'object'){
		if(eval("document.all."+nom_div+".style.display")==''){
			eval("document.all."+nom_div+".style.display='none'");
			if(trim(nom_img)!=''){
				fle.src="/Graficos/Botones/abajo.gif";
				document[nom_img].src= fle.src;
			}
		}
		else{
			eval("document.all."+nom_div+".style.display=''");
			if(trim(nom_img)!=''){
				fle.src="/Graficos/Botones/arriba.gif";
				document[nom_img].src= fle.src;
			}
		}
	}
}

function format(val, dec, miles){
	var _str = false;
	if(typeof(val)=='string'){
		val = val.replace('.','').replace(',','.');
		_str = true;
	}
	var num = val, signo=3, expr;
	var cad = ""+val;
	var ceros = "", pos, pdec, i;
	for (i=0; i < dec; i++)
	ceros += '0';
	pos = cad.indexOf('.')
	if (pos < 0)
		cad = cad+"."+ceros;
	else
		{
		pdec = cad.length - pos -1;
		if (pdec <= dec)
			{
			for (i=0; i< (dec-pdec); i++)
				cad += '0';
			}
		else
			{
			num = num*Math.pow(10, dec);
			num = Math.round(num);
			num = num/Math.pow(10, dec);
			cad = new String(num);
			}
		}
	pos = cad.indexOf('.')
	if (pos < 0) pos = cad.lentgh
	if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+')
		   signo = 4;
	if (miles && pos > signo)
		do{
			expr = /([+-]?\d)(\d{3}[\.\,]\d*)/
			cad.match(expr)
			cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)
			}
	while (cad.indexOf(',') > signo)
		if (dec<0) cad = cad.replace(/\./,'')
	if (right(cad,1)=='.'&&dec==0) cad=cad.substring(0,cad.length-1)
	return cad;
	//return (_str?cad.replace(',','#').replace('.',',').replace('#','.'):cad);
}

function show_table(){
	enProceso = true;
	var fle = document.getElementById(arguments[0]+'_show');
	var show = (fle.src.toLowerCase().search(/abajo/)!=-1?false:true);
	var tabla = document.getElementById(arguments[0]);
	var tbo = tabla.tBodies[0];
	var tbh = tabla.tHead;
	var tbf = tabla.tFoot;
	if(window.ActiveXObject){
		_b = (!arguments[1]?(!show?0:100):parseInt(arguments[1]));
		if(_b>=0&&_b<=100){
			_b = _b + (10 *(show?-1:1));
			tabla.style.filter= 'alpha (opacity='+_b.toString()+');';
			ttss = setTimeout("show_table('"+arguments[0]+"','"+_b.toString()+"')", 60);
			if(_b<=0){
				tbh.style.display='none';
				tbo.style.display='none';
				tbf.style.display='none';
				tabla.style.filter= 'alpha (opacity=100);';
			}
			else{ //(_b<=0)
				tbh.style.display='';
				tbo.style.display='';
				tbf.style.display='';
			}
		}
		else{ //(_b>=0&&_b<=100)
			clearTimeout(ttss);
			enProceso = false;
			(fle.src.toLowerCase().search(/abajo/)!=-1?fle.src="/Graficos/Botones/arriba.gif":fle.src="/Graficos/Botones/abajo.gif");
		}
	}
	else{ // (window.ActiveXObject)
		_b = (!arguments[1]?(!show?0.0:1.0):parseFloat(arguments[1]));
		if(_b>=0&&_b<=1){
			_b = _b + (0.1 *(show?-1:1));
			tbh.style.opacity=_b;
			tbo.style.opacity=_b;
			tbf.style.opacity=_b;
			ttss = setTimeout("show_table('"+arguments[0]+"','"+_b.toString()+"')", 60);
			if(_b<=0){
				tbh.style.display='none';
				tbo.style.display='none';
				tbf.style.display='none';
			}
			else{ //(_b<=0)
				tbh.style.display='';
				tbo.style.display='';
				tbf.style.display='';
			}
		}
		else{ //(_b>=0&&_b<=1)
			clearTimeout(ttss);
			enProceso = false;
			(fle.src.toLowerCase().search(/abajo/)!=-1?fle.src="/Graficos/Botones/arriba.gif":fle.src="/Graficos/Botones/abajo.gif");
		}
	} // (window.ActiveXObject)
}

function desPag(tabla){
	var tbo = document.getElementById(tabla);
	if(tbo.getAttribute('filter')!='') return;
	var _aux = document.getElementById(tabla+'_closeimg');
	if(_aux==null) return;
	if(_aux.src.toLowerCase().search(/close/)!=-1){
		_aux.src="/Graficos/imagenes/nota2.gif";
		tbo.setAttribute('xpaginaaux',tbo.getAttribute('xpagina'));
		tbo.setAttribute('xpagina',tbo.tBodies[0].childNodes.length);
		tbo.setAttribute('act',1);
		paging(tabla);
		_aux = document.getElementById(tabla+'_pag')
		_aux.style.display='none';
		_aux = document.getElementById(tabla+'_close');
		_aux.title="Activar Paginacion";
		_aux = document.getElementById(tabla+'_closeimg');
	}
	else{
		_aux.src="/Graficos/imagenes/close.gif";
		tbo.setAttribute('xpagina',tbo.getAttribute('xpaginaaux'));
		tbo.setAttribute('xpaginaaux',0);
		tbo.setAttribute('act',1);
		paging(tabla);
		_aux = document.getElementById(tabla+'_pag')
		_aux.style.display='';
		_aux = document.getElementById(tabla+'_close');
		_aux.title="Desactivar Paginacion";
	}
}

function frst(tabla){
	var tbo = document.getElementById(tabla);
	var act = parseInt(tbo.getAttribute('act'));
	if(act!=1){
		act=1;
		tbo.setAttribute('act',act.toString());
		paging(tabla);
	}
}
function previous(tabla){
	var tbo = document.getElementById(tabla);
	var act = parseInt(tbo.getAttribute('act'));
	if(act>1){
		act=act-1;
		tbo.setAttribute('act',act.toString());
		paging(tabla);
	}
}
function next(tabla){
	var tbo = document.getElementById(tabla);
	var act = parseInt(tbo.getAttribute('act'));
	var xpag = parseInt(tbo.getAttribute('xpagina'));
	var bod = tbo.tBodies[0];
	var j=0;
	for(var i=0;i<bod.childNodes.length;i++)
		if(bod.childNodes[i].getAttribute('type')=='D') j++;
	if(act<=parseInt(j/xpag)){
		act++;
		tbo.setAttribute('act',act.toString());
		paging(tabla);
	}
}
function last(tabla){
	var tbo = document.getElementById(tabla);
	var act = parseInt(tbo.getAttribute('act'));
	var xpag = parseInt(tbo.getAttribute('xpagina'));
	var bod = tbo.tBodies[0];
	var j=0;
	for(var i=0;i<bod.childNodes.length;i++)
		if(bod.childNodes[i].getAttribute('type')=='D') j++;
	if(act!=parseInt(j/xpag)+1){
		act=parseInt(j/xpag)+1;
		tbo.setAttribute('act',act.toString());
		paging(tabla);
	}

}
function paging(tabla){
	var tbo = document.getElementById(tabla);
	if(tbo.getAttribute('filter')!='')return;
	var xpag = tbo.getAttribute('xpagina');
	if(xpag){
		xpag = parseInt(xpag);
		if(tbo.tBodies[0].childNodes.length >= xpag){
			var act = parseInt(tbo.getAttribute('act'));
			var nod, i, j=-1;
			var _ini = (act*xpag)-xpag;
			var _fin = (act*xpag)-1;
			nod = tbo.tBodies[0];
			for(i=0;i<nod.childNodes.length;i++){
				if(nod.childNodes[i].getAttribute('type')=='D') j++;
				if(j>=_ini&&j<=_fin)
					nod.childNodes[i].style.display='';
				else
					nod.childNodes[i].style.display='none';
			}
			document.getElementById(tabla+'_txtpage').innerHTML=act;
			if(tbo.getAttribute('detail')!=''&&tbo.getAttribute('detail')!=null){
				nod=document.getElementById(tbo.getAttribute('detail'));
				if(nod.getAttribute('expand')=='F')
					showAllDetails(tabla,true);			
				else
					showAllDetails(tabla,false);
			}
		}
	}
}
function addfoot(){
	var tbf, _td, _text, arr, fft, _val;
	arr=arguments[1];
	fft=arguments[2];
	tbf = arguments[0].tFoot;
	_tr = document.createElement ("tr");
	_tr.setAttribute((window.ActiveXObject?'className':'class'),'tabdatostit');
	if(arguments[3]){
		_td = document.createElement ("td");
		_td.appendChild(document.createTextNode(''));
		_tr.appendChild(_td);
	}
	for(var j=0;j<arr.length;j++)
		if(!isNaN(arr[j]))
			break;
	_td = document.createElement ("td");
	_td.colSpan=j-1;
	_td.appendChild(document.createTextNode(arr[0]));
	_tr.appendChild(_td);
	for(var i=j;i<=arguments[0].tHead.childNodes[0].cells.length-(arguments[3]?1:0);i++){
		if(!isNaN(arr[i])){
			_td = document.createElement ("td");
			_td.setAttribute('align','right');
			_val = (arr[i]?(fft[i]?format(arr[i]/Math.pow(10,fft[i]),fft[i],true):format(arr[i],0,true)):'');
			if(right(_val,1)=='.') _val=left(_val,_val.length-1);
			_td.appendChild(document.createTextNode(_val));
			_tr.appendChild(_td);
		}
		else{
			_td = document.createElement ("td");
			_td.appendChild(document.createTextNode(''));
			_tr.appendChild(_td);
			}
	}
	if(arguments[0].getAttribute('tbldel')=='true'){
		_td = document.createElement ("td");
		_tr.appendChild(_td);
	}
	tbf.appendChild(_tr);
}
function get_page() {
	var http = arguments[0];
	if (http) {
		var tabla = document.getElementById(arguments[2]);
		tabla.setAttribute('className','sortable');

		// Si no tiene un thead se lo creo
		if(tabla.tHead==null){
			var tbh = document.createElement('thead');
			tbh.setAttribute('className','tabdatostit')
			tbh.setAttribute('id','tbh')
			tabla.appendChild(tbh);
		}

		if(tabla.tFoot==null){
			tbf = document.createElement('tfoot');
			tbf.setAttribute('id','tbf')
			tabla.appendChild(tbf);
		}

		// Si no tiene tbodie se lo creo		
		if(tabla.tBodies.length==0){
			var tbl = document.createElement('tbody');
			tbl.setAttribute('id','tbb')
			tabla.appendChild(tbl);
			
		}
		else
			var tbl = tabla.tBodies[0];
			
		//Limpio la tabla			
		while (tbl.childNodes.length > 0)
			tbl.removeChild(tbl.firstChild); 

		//Agrego el texto "Buscando" para q no piense q se colgo la busqueda			
		var _tr = document.createElement ("tr");
		var _td = document.createElement ("td");
		_td.setAttribute('className','tabdatostit2')
		var _text = document.createTextNode ('Buscando');
		var _img = new Image(18,18);
		_img.src = '/Graficos/Imagenes/load.gif'
		_td.setAttribute('colspan', '4');
		_td.appendChild (_img);
		_td.appendChild (_text);
		_tr.appendChild(_td);		
		tbl.appendChild (_tr);

		var url = arguments[1]
		url+='&xml=1&pwd='+Math.round(Math.random()*1000000);
		http.open("GET", url, true);
		_tbl = tabla.id;
		http.onreadystatechange = function(){
//			procesaXML(http,_tbl)
//			var http = arguments[0];
			if (http.readyState == 4 && http.status == 200 && http.responseXML) {
				var _tr, _td, _text, _a, _val, _visc = 0, _xpag = 0, _show=true, _link, _detail='', _detailfoot=false;
				var dat = http.responseXML.documentElement.getElementsByTagName('dato');
				var _fmax = new Array();
				var _fmin = new Array();
				var _ftot = new Array();
				var _ftotp = new Array();
				var _fprom = new Array();
				var _fcont = new Array();
				var _fformat = new Array();
				var _arred = new Array();
				
				_cls = (window.ActiveXObject?'className':'class');

				if(tabla.caption) tabla.removeChild(tabla.caption);
				while(tabla.tFoot.rows.length > 0) tabla.tFoot.deleteRow(0);

				//armo el thead con los nombres de las tags de XML
				var tbh = tabla.tHead;
				if(tbh.rows.length > 0) tbh.deleteRow(0);
				tbh.insertRow(0);
				for(var i = 0; i < dat[0].childNodes.length; i++ ){
					_val = (window.ActiveXObject?dat[0].childNodes[i].text:(dat[0].childNodes[i].firstChild?dat[0].childNodes[i].firstChild.nodeValue:''));
					if(dat[0].childNodes[i].tagName.toUpperCase()=='CAPTION'){
						if(dat[0].childNodes[i].getAttribute('forceview')=='false')
							tabla.style.display='none';
						else
							tabla.style.display='';
						var _cap = document.createElement('caption');
						if(dat[0].childNodes[i].getAttribute('menuadd')=='true'){
							tabla.setAttribute('menuadd','true');
							tabla.setAttribute('menuaddpg',(dat[0].childNodes[i].getAttribute('menuaddpg')?dat[0].childNodes[i].getAttribute('menuaddpg'):''));
						}
						if(dat[0].childNodes[i].getAttribute('scroll')=='true'){
							if(window.ActiveXObject){
//								tabla.setAttribute("height", "400px");
								tabla.tBodies[0].style.cssText=("display: block; overflow-y : scroll;");
							}
							else{
								tabla.tBodies[0].style.cssText="height: 400px; overflow : -moz-scrollbars-vertical;";
							}
						}
						if(dat[0].childNodes[i].getAttribute('menu')=='true'){
							tabla.setAttribute('menu','true');
							var _menu='<td onclick=javascript:menu_table("'+tabla.id+'");  style="cursor:hand; cursor:pointer;" valign="middle" width="8"><img id="'+tabla.id+'_imgmenu" src="/Graficos/Imagenes/menu.gif" title="Menu de Opciones" ></td>';							
						}
						else
							var _menu='';
						tabla.setAttribute('tbldel',(dat[0].childNodes[i].getAttribute('tbldel')?dat[0].childNodes[i].getAttribute('tbldel'):''));
						tabla.setAttribute('deltrigger',(dat[0].childNodes[i].getAttribute('deltrigger')?dat[0].childNodes[i].getAttribute('deltrigger'):''));
						tabla.setAttribute('tbldelpg',(dat[0].childNodes[i].getAttribute('tbldelpg')?dat[0].childNodes[i].getAttribute('tbldelpg'):''));
						tabla.setAttribute('tbledt',(dat[0].childNodes[i].getAttribute('tbledt')?dat[0].childNodes[i].getAttribute('tbledt'):''));
						tabla.setAttribute('addblank',(dat[0].childNodes[i].getAttribute('addblank')?dat[0].childNodes[i].getAttribute('addblank'):''));
						tabla.setAttribute('rfafteredt',(dat[0].childNodes[i].getAttribute('rfafteredt')?dat[0].childNodes[i].getAttribute('rfafteredt'):''));
						_text= tabla.parentNode.className.search(/subtabla/i)!=-1?'tabdatoscuer2':'tabdatostit2';
						_cap.innerHTML = '<table width="100%" align="center" class="tabla" style="border: 1px solid #000000;" cellspacing="0" cellpadding="0"><tr valign="middle" class="'+(dat[0].childNodes[i].getAttribute('class')?dat[0].childNodes[i].getAttribute('class'):_text)+'" align="'+(dat[0].childNodes[i].getAttribute('align')?dat[0].childNodes[i].getAttribute('align'):'center')+'">'+_menu+'<td id="'+tabla.id+'Caption"  nowrap>'+_val+'</td><td onclick=javascript:if(!enProceso){show_table("'+tabla.id+'")};  style="cursor:hand; cursor:pointer;" valign="middle" width="8"><img id="'+tabla.id+'_show" src="/Graficos/Botones/arriba.gif" width="8" heigth="8"></td></tr></table>';
						tabla.appendChild(_cap);
					}
					if(dat[0].childNodes[i].tagName.toUpperCase()=='XPAGINA'){
						_xpag=parseInt(_val);			
					}
					if(dat[0].childNodes[i].tagName.toUpperCase()=='SHOW'){
						_show=eval(_val);			
					}
					if(dat[0].childNodes[i].tagName.toUpperCase()=='DETAIL'){
						_td = tbh.rows[0].insertCell(0);
						_td.setAttribute(_cls, 'tabdatostit');
						_td.setAttribute('order', 'nosort');
						_td.setAttribute('width', '10');
						_td.setAttribute('align', 'center');
						_text = document.createElement('img');
						_text.src='/Graficos/Imagenes/masC.gif';
						_text.title='Mostrar Todos Los Detalles';
						_text.border=0;
						_text.setAttribute('id', tabla.id+'AllDetail');
						_text.setAttribute('expand','F');
						_link = document.createElement('a');
						_link.setAttribute('href', "javascript:showAllDetails('"+tabla.id+"')");
						_link.appendChild(_text);
						_td.appendChild(_link);
						_detailfoot=true;
						tabla.setAttribute('detail',_text.id);
					}
					// Solo muestro las columnas q no tengan visible=false
					if(dat[0].childNodes[i].getAttribute('visible')=='true' || dat[0].childNodes[i].getAttribute('visible')==null){
						_td = document.createElement ('th');			
						
						if(dat[0].childNodes[i].getAttribute('colname')==null)
							//Por si tengo campos unidos con guion bajo
							_text = dat[0].childNodes[i].tagName;
						else
							_text = dat[0].childNodes[i].getAttribute('colname');
							
						_text = document.createTextNode(_text.replace(/_/g,' '));
						
						_td.setAttribute(_cls, 'tabdatostit');
						_td.setAttribute('field', dat[0].childNodes[i].getAttribute('field'));
						_td.setAttribute('fsize', (dat[0].childNodes[i].getAttribute('fsize')!=null||dat[0].childNodes[i].getAttribute('fsize')!=''?dat[0].childNodes[i].getAttribute('fsize'):10));
						_td.setAttribute('fdefault', (dat[0].childNodes[i].getAttribute('fdefault')!=null?dat[0].childNodes[i].getAttribute('fdefault'):''));
						_td.setAttribute('inputtype', (dat[0].childNodes[i].getAttribute('inputtype')!=null||dat[0].childNodes[i].getAttribute('inputtype')!=''?dat[0].childNodes[i].getAttribute('inputtype'):''));
						_td.setAttribute('inputsrc', dat[0].childNodes[i].getAttribute('inputsrc'));
						_td.setAttribute('order', dat[0].childNodes[i].getAttribute('order'));
						_td.setAttribute('subtotal', dat[0].childNodes[i].getAttribute('subtotal'));
						_td.setAttribute('dec', dat[0].childNodes[i].getAttribute('dec'));
						
						_td.appendChild(_text);
						
						_visc++;
						if(dat[0].childNodes[i].getAttribute('max')=='true'){_td.setAttribute('max','true');_fformat[_visc]=dat[0].childNodes[i].getAttribute('dec');_fmax[_visc] = parseFloat(dat[0].childNodes[i].getAttribute('order'))};
						if(dat[0].childNodes[i].getAttribute('min')=='true'){_td.setAttribute('min','true');_fformat[_visc]=dat[0].childNodes[i].getAttribute('dec');_fmin[_visc] = 99999999};
						if(dat[0].childNodes[i].getAttribute('tot')=='true'){_td.setAttribute('tot','true');_fformat[_visc]=dat[0].childNodes[i].getAttribute('dec');_ftot[_visc] = 0};
						if(dat[0].childNodes[i].getAttribute('prom')=='true'){_td.setAttribute('prom','true');_fformat[_visc]=dat[0].childNodes[i].getAttribute('dec');_ftotp[_visc] = 0;_fprom[_visc] = 0};
						if(dat[0].childNodes[i].getAttribute('cont')=='true'){_td.setAttribute('cont','true');_fformat[_visc]=dat[0].childNodes[i].getAttribute('dec');_fcont[_visc] = 0};
						
						tbh.rows[0].appendChild(_td);
					}
				}
				if(tabla.getAttribute('tbldel')=='true'){
					_td = tbh.rows[0].insertCell(-1);
					_td.setAttribute('order','nosort');
					_td.setAttribute(_cls, 'tabdatostit');
					_td.width='13px';
					_visc++;
				}
				
				if(Math.abs(_xpag)>0&&Math.abs(_xpag)<dat.length){
					var tbf = tabla.tFoot;
					tabla.setAttribute('xpagina',Math.abs(_xpag));
					tabla.setAttribute('xpaginaaux',0);
					tabla.setAttribute('act',1);
					_tr = document.createElement ("tr");
					_td = document.createElement ("td");
					_td.colSpan = _visc+(_detailfoot?1:0);
					_td.setAttribute(_cls, 'tabdatostit3');
					_td.setAttribute('align', 'center');
					var _navbar = '<table class="tabla" align="center" celpadding=0 cellspacing=0 width="100%"><tr class="tabdatostit3"><td><table class="tabla" align="center" celpadding=0 cellspacing=0 id="'+tabla.id+'_pag"><tr class="tabdatostit3" align="center">';
					_navbar +='<td id="'+tabla.id+'_first" style="cursor:hand; cursor:pointer;" title="Primera Pagina"> <img src="/graficos/imagenes/first.gif"> </td><td id="'+tabla.id+'_prev" title="Pagina Anterior" style="cursor:hand; cursor:pointer;"> <img src="/graficos/imagenes/prev.gif"> </td>';
					_navbar +='<td id="'+tabla.id+'_txtpage">1</td>';
					_navbar +='<td id="'+tabla.id+'_next" title="Pagina Siguiente" style="cursor:hand; cursor:pointer;"> <img src="/graficos/imagenes/next.gif"> </td><td id="'+tabla.id+'_last" title="Ultima Pagina" style="cursor:hand; cursor:pointer;"> <img src="/graficos/imagenes/last.gif"> </td></tr></table></td>';
					_navbar +='<td width="8" id="'+tabla.id+'_close" style="cursor:hand; cursor:pointer;" title="Desactivar Paginacion" align="rigth"><img align="rigth" id="'+tabla.id+'_closeimg" src="/graficos/imagenes/close.gif"></td></tr></table>';
					_td.innerHTML=_navbar;
					_tr.appendChild(_td);
					tbf.appendChild(_tr);
					_navbar = document.getElementById(tabla.id+'_prev');
					addEvent(_navbar, 'click', function(){previous(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_next');
					addEvent(_navbar, 'click', function(){next(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_last');
					addEvent(_navbar, 'click', function(){last(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_first');
					addEvent(_navbar, 'click', function(){frst(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_close');
					addEvent(_navbar, 'click', function(){desPag(tabla.id)});
				}
				tabla.setAttribute('filter','');
				tabla.setAttribute('adding','false');
				tbh =  tabla.tBodies[0];
				//borro la primer fila de tbodie ("buscando")
				tbh.removeChild(tbh.firstChild);
				_a=0;
				//armo el tbodie
				for(i = 0; i < dat.length; i++ ) {
					_visc=0;
					_tr = document.createElement ("tr");
					_tr.setAttribute('type','D');
					_wid=0;
					for(var j = 0; j < dat[i].childNodes.length; j++ ){
						_val = (window.ActiveXObject?dat[i].childNodes[j].text:(dat[i].childNodes[j].firstChild?dat[i].childNodes[j].firstChild.nodeValue:''));
						if(dat[i].childNodes[j].getAttribute('dec')){
							_val = format(_val, dat[i].childNodes[j].getAttribute('dec'),true);
							if(_fformat[j]=='undefined'){_fformat[j]='0'};
							if(parseInt(_fformat[j]) < parseInt(dat[i].childNodes[j].getAttribute('dec'))){_fformat[j]=dat[i].childNodes[j].getAttribute('dec')};
						};
						if(dat[i].childNodes[j].tagName.toUpperCase()=='ID'){_tr.setAttribute('id', _val)};
						if(dat[i].childNodes[j].tagName.toUpperCase()=='DETAIL'){_detail = _val==""?'SINDET':_val}
						// Solo muestro las columnas q no tengan visible=false
						if(dat[i].childNodes[j].getAttribute('visible')=='true' || dat[i].childNodes[j].getAttribute('visible')==null){
							_td = document.createElement ("td");
							
							if(dat[i].childNodes[j].getAttribute('preimg')){
								_text = document.createElement('img');
								_text.src=dat[i].childNodes[j].getAttribute('preimg');
								_text.border=0;
								_text.setAttribute('id', tabla.id + 'PreImg' + i.toString() + j.toString());
								if(dat[i].childNodes[j].getAttribute('preimgw'))
									_text.setAttribute('width',dat[i].childNodes[j].getAttribute('preimgw'));
								if(dat[i].childNodes[j].getAttribute('preimgh'))
									_text.setAttribute('height',dat[i].childNodes[j].getAttribute('preimgh'));
								if(dat[i].childNodes[j].getAttribute('preimgt'))
									_text.setAttribute('title',dat[i].childNodes[j].getAttribute('preimgt'));
								if(dat[i].childNodes[j].getAttribute('preimgl')){
									_link = document.createElement('a');
									_link.setAttribute('href', dat[i].childNodes[j].getAttribute('preimgl'));
									_link.appendChild(_text);
									_td.appendChild(_link);
								}
								else
									_td.appendChild(_text);
							}
							// Si no me define una class le aplico la class x defecto
							_td.style.cssText=(dat[i].childNodes[j].getAttribute('style')?dat[i].childNodes[j].getAttribute('style'):'');
							_td.setAttribute(_cls, (dat[i].childNodes[j].getAttribute('class')?dat[i].childNodes[j].getAttribute('class'):'tabdatoscuer'));
							//Si tiene el atributo "link", armo una tag <a href>, sino es texto normal o editable
							if(dat[i].childNodes[j].getAttribute('link')==null || dat[i].childNodes[j].getAttribute('link')=='')
								if(dat[i].childNodes[j].getAttribute('edit')==null || dat[i].childNodes[j].getAttribute('edit')=='false')
									// Si el valor es cero no lo muestro				
									switch(dat[i].childNodes[j].getAttribute('type')){
										case 'T':									
											_text=document.createTextNode(_val);
											break
										case 'M':
											_text = document.createElement('p');
											_text.style.width = '100%';
											_text.innerHTML=_val;
											break
										case 'L':
											_text=document.createTextNode((_val=='1'?'Si':'No'));
											break
										default:
											_text=(parseFloat(_val.replace('.','').replace(',','.'))==0?document.createTextNode(''):document.createTextNode (_val));
									}
								else{
									//Si no me especifica q campo actuelizar, no lo muestro como editable
									if(dat[i].childNodes[j].getAttribute('field')==null || dat[i].childNodes[j].getAttribute('field')=='')
										// Si el valor es cero no lo muestro				
										_text = (parseFloat(_val.replace('.','').replace(',','.'))==0?document.createTextNode(''):document.createTextNode(_val));
									else{
										_text = document.createElement('p');
										_text.style.width = '100%';
										_text.setAttribute('id', tabla.id + 'Td' + i.toString() + j.toString());
										_text.setAttribute('field', dat[i].childNodes[j].getAttribute('field'));
										_text.setAttribute('fdefault', (dat[i].childNodes[j].getAttribute('fdefault')!=null?dat[i].childNodes[j].getAttribute('fdefault'):''));
										_text.setAttribute('trigger', (dat[i].childNodes[j].getAttribute('trigger')!=null?dat[i].childNodes[j].getAttribute('trigger'):''));
										_text.setAttribute('fsize', (dat[i].childNodes[j].getAttribute('fsize')!=null||dat[i].childNodes[j].getAttribute('fsize')!=''?dat[i].childNodes[j].getAttribute('fsize'):10));
										_text.setAttribute('inputtype', (dat[i].childNodes[j].getAttribute('inputtype')!=null||dat[i].childNodes[j].getAttribute('inputtype')!=''?dat[i].childNodes[j].getAttribute('inputtype'):''));
										_text.setAttribute('editpg', (dat[i].childNodes[j].getAttribute('editpg')!=null||dat[i].childNodes[j].getAttribute('editpg')!=''?dat[i].childNodes[j].getAttribute('editpg'):''));
										_text.setAttribute('inputsrc', dat[i].childNodes[j].getAttribute('inputsrc'));
										if(dat[i].childNodes[j].getAttribute('inputtype')=='L')
											_text.appendChild(document.createTextNode((parseInt(_val)==1?'Si':'No')));
										else{
											if(trim(_val)=='')
												_text.innerHTML='&nbsp;';
											else
												_text.appendChild(document.createTextNode(_val));
										}
										_arred.push(tabla.id + 'Td' + i.toString() + j.toString());
									}
								}
							else{
								_text = document.createElement('a');
								_text.setAttribute('href', dat[i].childNodes[j].getAttribute('link'));
								_text.appendChild(document.createTextNode(_val));
							}
							_visc++;
							if(dat[i].childNodes[j].getAttribute('max')=='true'){_fmax[_visc]=Math.max(_fmax[_visc],parseFloat(dat[i].childNodes[j].getAttribute('order')))};
							if(dat[i].childNodes[j].getAttribute('min')=='true'){if(parseFloat(dat[i].childNodes[j].getAttribute('order'))!=0){_fmin[_visc]=Math.min(_fmin[_visc],parseFloat(dat[i].childNodes[j].getAttribute('order')))}};
							if(dat[i].childNodes[j].getAttribute('tot')=='true'){_ftot[_visc]=_ftot[_visc]+parseFloat(dat[i].childNodes[j].getAttribute('order'))}							
							if(dat[i].childNodes[j].getAttribute('prom')=='true'&&parseFloat(dat[i].childNodes[j].getAttribute('order'))!=0.00){_ftotp[_visc]=_ftotp[_visc]+parseFloat(dat[i].childNodes[j].getAttribute('order'));_fprom[_visc]++}				
							if(dat[i].childNodes[j].getAttribute('cont')=='true'){_fcont[_visc]=_fcont[_visc]+1*Math.pow(10,_fformat[_visc])}				
							_td.appendChild(_text);
							_td.setAttribute('align',(dat[i].childNodes[j].getAttribute('align')!=null?dat[i].childNodes[j].getAttribute('align'):'right'));
							_td.setAttribute('width',(dat[i].childNodes[j].getAttribute('width')?dat[i].childNodes[j].getAttribute('width'):''));
							if(!isNaN(dat[i].childNodes[j].getAttribute('width'))){_wid=_wid+parseInt(dat[i].childNodes[j].getAttribute('width'))};
							if(dat[i].childNodes[j].getAttribute('order')&&dat[i].childNodes[j].getAttribute('order')!='nosort')
								_td.setAttribute('sorttable_customkey',dat[i].childNodes[j].getAttribute('order'));
							if(dat[i].childNodes[j].getAttribute('title')) _td.setAttribute('title',dat[i].childNodes[j].getAttribute('title'));
							_td.noWrap = true;
							if(dat[i].childNodes[j].getAttribute('posimg')){
								_text = document.createElement('img');
								_text.src=dat[i].childNodes[j].getAttribute('posimg');
								_text.border=0;
								_text.setAttribute('id', tabla.id + 'PosImg' + i.toString() + j.toString());
								if(dat[i].childNodes[j].getAttribute('posimgw'))
									_text.setAttribute('width',dat[i].childNodes[j].getAttribute('posimgw'));
								if(dat[i].childNodes[j].getAttribute('posimgh'))
									_text.setAttribute('height',dat[i].childNodes[j].getAttribute('posimgh'));
								if(dat[i].childNodes[j].getAttribute('posimgt'))
									_text.setAttribute('title',dat[i].childNodes[j].getAttribute('posimgt'));
								if(dat[i].childNodes[j].getAttribute('posimgl')){
									_link = document.createElement('a');
									_link.setAttribute('href', dat[i].childNodes[j].getAttribute('posimgl'));
									_link.appendChild(_text);
									_td.appendChild(_link);
								}
								else
									_td.appendChild(_text);
							}
							_tr.appendChild(_td);
						}
					}
					if(tabla.getAttribute('tbldel')=='true'){
						_td = document.createElement ("th");
						_td.setAttribute(_cls,'tabdatoscuer');
						_text = document.createElement('img');
						_text.src='/Graficos/Botones/factura4.gif';
						_text.title='Borrar Registro';
						_text.border=0;
						_link = document.createElement('a');
						_link.setAttribute('href', "javascript:delrecord("+_tr.id+",'"+tabla.id+"')");
						_link.appendChild(_text);
						_td.appendChild(_link);
						_tr.appendChild(_td);
					}

					// Si pagina, d entrada siempre muestro la primer pagina
					if(_xpag>0)
						if(tbh.childNodes.length>=_xpag)
							_tr.style.display='none';
					tbh.appendChild(_tr);
					if(rtrim(_detail)!=''){
						_td = tbh.rows[i].insertCell(0);
						_td.setAttribute('align', 'center');
						if(rtrim(_detail)!='SINDET'){
							_text = document.createElement('img');
							_text.src='/Graficos/Imagenes/mas.gif';
							_text.title='Mostrar Detalle';
							_text.border=0;
							_text.setAttribute('id', tabla.id+'Detail'+  i.toString());
							_text.setAttribute('expand','F');
							_text.setAttribute('detail',_detail);
							_link = document.createElement('a');
							_link.setAttribute('href', "javascript:showDetails('"+_text.id+"')");
							_link.appendChild(_text);
							_td.appendChild(_link);
						}
					}
				}
				if(_xpag<0){
					desPag(tabla.id)
				}
				for(i=0;i<_arred.length;i++){
					maked(_arred[i]);
				}
				if(_fmin.length>0){
					for(i=0; i<_fmin.length;i++ ){  
						if(_fmin[i]==99999999)
						  _fmin.splice(i,1,0);          
					  }        					
					_fmin[0]='Mínimo:';
					addfoot(tabla,_fmin, _fformat, _detailfoot)
				}
				if(_fmax.length>0){
					_fmax[0]='Máximo:';
					addfoot(tabla,_fmax, _fformat, _detailfoot)
				}
				if(_fprom.length>0){
					_fprom[0]='Promedio:';
					for(i=1;i<_fprom.length;i++)
						if(_fprom[i])
							_fprom[i]=_ftotp[i]/_fprom[i]
					addfoot(tabla,_fprom, _fformat, _detailfoot)
				}
				if(_ftot.length>0){
					_ftot[0]='Total:';
					addfoot(tabla,_ftot, _fformat, _detailfoot)
				}
				if(_fcont.length>0){
					_fcont[0]='Cantidad:';
					addfoot(tabla,_fcont, _fformat, _detailfoot)
				}
				if(tabla.getAttribute("sorttable")!="false")
					try{sorttable.makeSortable(tabla)}
						catch(e){}
				if(tabla.getAttribute('width')==''||tabla.getAttribute('width')==null){
					tabla.setAttribute('width',_wid);
				}
				for(i=0;i<_fformat.length;i++){
					if(tabla.tHead.rows[0].cells[i+(_detailfoot?1:0)]){tabla.tHead.rows[0].cells[i+(_detailfoot?1:0)].setAttribute('dec',_fformat[i+1])};
				};
				if(!_show){show_table(tabla.id)};
				i=_stack.pop();
			}
// --------------------------------------------------------------------------------------------------------------------------
		};
		http.send(null);
	}
}

function get_value() {
	var httpx = arguments[0];
	if (httpx) {
	var obj = arguments[2];
	if(typeof(obj.value)!='undefined'){
			obj.value='';
			obj.style.background='url(/Graficos/Imagenes/load.gif)';
			obj.style.backgroundColor='#FFFFFF';
			obj.style.backgroundRepeat="no-repeat";
		}
		var url = arguments[1];
		var def;
		if(arguments[3]){def=arguments[3]};
		url+='&xml=1&pwd='+Math.round(Math.random()*1000000);
		httpx.open("GET", url, true);
		httpx.onreadystatechange = function(){
			if (httpx.readyState == 4 && httpx.status == 200 && httpx.responseXML) {
				var dat = httpx.responseXML.documentElement.getElementsByTagName('dato');
				if(typeof(obj.value)!='undefined'){
					obj.value = (typeof(def)!='undefined'?def:(dat.length==1?(window.ActiveXObject?dat[0].childNodes[0].text:dat[0].childNodes[0].firstChild.nodeValue):''));
					obj.style.background='';
					obj.style.backgroundColor='#FFFFFF';
				}
				else
					obj.innerHTML = (typeof(def)!='undefined'?def:(dat.length==1?(window.ActiveXObject?dat[0].childNodes[0].text:(dat[0].childNodes[0].firstChild?dat[0].childNodes[0].firstChild.nodeValue:'&nbsp')):'&nbsp'));
				var i=_stack.pop();
			}
		};
		httpx.send(null);
	}
}

function get_cbo() {
	var httpx = arguments[0];
	if (httpx) {
		var url = arguments[1];
		url+='&xml=1&pwd='+Math.round(Math.random()*1000000);
		httpx.open("GET", url, true);
		var cbo = arguments[2];
		var val = arguments[3];
		var id = arguments[4];
		httpx.onreadystatechange = function(){
			if (httpx.readyState == 4 && httpx.status == 200 && httpx.responseXML) {
				var dat = httpx.responseXML.documentElement.getElementsByTagName('dato');
				var optionObj, _sel;
				cbo.length=0;
				var searc= isNaN(id)?new RegExp('^'+val+'$',"i"):id;
				if(window.ActiveXObject)
					for(var i = 0; i < dat.length; i++ ) {
						_sel = isNaN(id)?(dat[i].childNodes[1].text.search(searc)!=-1?true:false):(parseInt(dat[i].childNodes[0].text)==id?true:false);
						optionObj = new Option(dat[i].childNodes[1].text,dat[i].childNodes[0].text,_sel, _sel);
						optionObj.style.cssText=(dat[i].childNodes.length>2?dat[i].childNodes[2].text:'');
						cbo.options[i] = optionObj
					}
				else
					for(var i = 0; i < dat.length; i++ ) {
						_sel = isNaN(id)?(dat[i].childNodes[1].firstChild.nodeValue.search(searc)!=-1?true:false):(parseInt(dat[i].childNodes[0].firstChild.nodeValue)==id?true:false);
						optionObj = new Option(dat[i].childNodes[1].firstChild.nodeValue,dat[i].childNodes[0].firstChild.nodeValue,_sel, _sel);
						optionObj.style.cssText=(dat[i].childNodes.length>2?dat[i].childNodes[2].firstChild.nodeValue:'')
						cbo.options[i] =optionObj
					}
				var _img = document.getElementById("imgespvue");
				if(_img){
					var _par = cbo.parentNode;
					_par.removeChild(_img);
				}
				var i=_stack.pop();
			}
		};
		httpx.send(null);
	}
}

function getHTTPObject() {
    var xmlhttp;
    if(window.XMLHttpRequest) {
    	try {
			xmlhttp = new XMLHttpRequest();
			if (xmlhttp.overrideMimeType)
				xmlhttp.overrideMimeType('text/xml')
        } catch(e) {
			xmlhttp = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		xmlhttp = false;
        	}
		}
    }
	_stack.push(true);
	return xmlhttp;
}

function addEvent(obj,evType,fn){
 var r = false;
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    r = true
  } else if (obj.attachEvent) {
    var id = obj.sourceIndex || -1;

    if (!fn[evType + id]) {
      var f = fn[evType + id] = function(e) {
        var o = document.all[id] || document;
        o._f = fn;
        var s = o._f(e);
        o._f = null;
        return s
      };

      r = obj.attachEvent("on" + evType, f);
      obj = null;
    }
  }
  return r;
}

function removeEvent(obj, evType, fn){
  var r = false
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, false);
    r = true
  } else if (obj.detachEvent) {
    r = obj.detachEvent("on" + evType, fn)
  }
  return r
}

function delrecord(){
	if(!confirm('¿Seguro que desea eliminar el registro?')) return;
	var _tag = document.getElementById(arguments[1]);
	var _trigger =_tag.getAttribute('deltrigger')
	_obj=document.getElementById(arguments[0]);
	if(_obj.getAttribute('expand')=='T') _obj.parentNode.deleteRow(_obj.rowIndex);		
	var _o = _tag.getAttribute('tbledt');
	var _i = _obj.id;
	var _pg = _tag.getAttribute('tbldelpg')==''?'/bin/consulta.asp?opc=777&o='+_o+'&i='+_i:_obj.getAttribute('delpg')+'&i='+_i;
	get_value(getHTTPObject(), _pg, _obj);
	_o = _tag.tBodies[0];
	_o.removeChild(_obj)
	try{eval(_trigger);}
	catch(e){}

}
function adding_table(){
	var _tbl, _tbo, _row, _cell, i, _input, _flag=true;
	_tbl = typeof(arguments[0])=='object'?arguments[0]:document.getElementById(arguments[0]);
	if(_tbl.getAttribute('addblank')=='true'){
		_tbo = '';
		get_value(getHTTPObject(), _tbl.getAttribute('menuaddpg')+'&blk=1', _tbo,'');
		if(_tbl.getAttribute('rfsh')!=''||_tbl.getAttribute('rfsh')!=null){
			ttss=setTimeout(_tbl.getAttribute('rfsh'),75);
		}
		return;
	}
	_tbo=_tbl.tBodies[0];
	if(_tbl.getAttribute('adding')=='false'){
		_tbl.setAttribute('adding','true');
		_row=_tbo.insertRow(0);
		for(i=0;i<_tbl.tHead.rows[0].cells.length;i++){
			_cell=_row.insertCell(i);
			if(_tbl.tHead.rows[0].cells[i].getAttribute('field')&&_tbl.tHead.rows[0].cells[i].getAttribute('field')!=''){
				_flag=false;
				switch(_tbl.tHead.rows[0].cells[i].getAttribute('inputtype')){
					case 'R':
						_cell.innerHTML = '<select class=ftexto id="'+_tbl.id+'_new'+i+'"></select>';
						_input = document.getElementById(_tbl.id+'_new'+i);
						get_cbo(getHTTPObject(),_tbl.tHead.rows[0].cells[i].getAttribute('inputsrc'),_input, '');						
					break
					case 'L':
						_cell.innerHTML = '<input type="checkbox" class=ftexto id="'+_tbl.id+'_new'+i+'">';
					break
					default:
						_cell.innerHTML = '<input type="text" id="'+_tbl.id+'_new'+i+'" size="'+_tbl.tHead.rows[0].cells[i].getAttribute('fsize')+'" value="'+_tbl.tHead.rows[0].cells[i].getAttribute('fdefault')+'" class="ftexto">';
				}
			}
		}
		if(_flag){
			_tbl.setAttribute('adding','false');
			_tbo.deleteRow(0);
			return;
		}
		_row=_tbo.insertRow(1);
		_cell=_row.insertCell(0);
		_cell.colSpan=_tbl.tHead.rows[0].cells.length;
		_cell.innerHTML='<div style="border-bottom: 1px solid #000000;" align="center"><font class="ftexto" style="cursor:hand; cursor:pointer; white-space:nowrap;" onClick="javascript:saveNew('+_tbl.id+');"><img src="/Graficos/Imagenes/flechas_nup.gif">Guardar</font>&nbsp;&nbsp;&nbsp;&nbsp;<font class="ftexto" style=" cursor:hand; cursor:pointer;" onClick="javascript:adding_table('+_tbl.id+');" white-space:nowrap;"><img src="/Graficos/Imagenes/flechas_ndw.gif">Cancelar</font></div>';
	}
	else{
		_tbl.setAttribute('adding','false');
		_tbo.deleteRow(0);
		_tbo.deleteRow(0);
	}
}
function saveNew(){
	var _tbl, i, _atr='',  _val='', _obj, _url, _tbedit;
	_tbl = typeof(arguments[0])=='object'?arguments[0]:document.getElementById(arguments[0]);
	_tbedit = _tbl.getAttribute('tbledt');
	if(_tbl.getAttribute('adding')=='false') return;
	for(i=0;i<_tbl.tHead.rows[0].cells.length;i++)
		if(_tbl.tHead.rows[0].cells[i].getAttribute('field')&&_tbl.tHead.rows[0].cells[i].getAttribute('field')!=''){
			_obj=document.getElementById(_tbl.id+'_new'+i);
			_atr=_atr+_tbl.tHead.rows[0].cells[i].getAttribute('field')+'|';
			_val=_val+_obj.value+"|"
		}
	if(_tbl.getAttribute('menuaddpg')==''||_tbl.getAttribute('menuaddpg')=='null'||_tbl.getAttribute('menuaddpg')==null)
		get_value(getHTTPObject(), '/bin/consulta.asp?opc=999&o='+_tbedit+'&f='+_atr+'&v='+_val, _obj,'');
	else
		get_value(getHTTPObject(), _tbl.getAttribute('menuaddpg')+'&o='+_tbedit+'&f='+_atr+'&v='+_val, _obj,'');
	adding_table(_tbl.id);
	if(_tbl.getAttribute('rfsh')!=''||_tbl.getAttribute('rfsh')!=null){
		ttss=setTimeout(_tbl.getAttribute('rfsh'),75);
	}
}

function chngzs(){
	if(arguments[2]<=arguments[3]) return;
	var _obj = document.getElementById(arguments[1]);
	if(arguments[0]=='w')
		_obj.style.width=arguments[3];
	else
		_obj.style.height=arguments[3];
	ttss=setTimeout("chngzs('"+arguments[0]+"','"+arguments[1]+"',"+arguments[2]+","+(parseInt(arguments[3])+10)+");",0);
}
function filter(){
	var _celtxt, _img, _tbo, _txt, _tbl;
	_tbl = document.getElementById(arguments[0]);
	if(_tbl.getAttribute('xpaginaaux')==0)desPag(_tbl.id);
	if(_tbl.getAttribute('detail')){
			_img=document.getElementById(_tbl.getAttribute('detail'));
			if(_img.getAttribute('expand')=='T') showAllDetails(_tbl.id,false);
	}
	if(typeof arguments[1]=='string')
		_txt=arguments[1];
	else
		_txt=trim(document.getElementById(arguments[0]+'_divmenu_txtfilter')?document.getElementById(arguments[0]+'_divmenu_txtfilter').value:_tbl.getAttribute('filter'));
	_tbl.setAttribute('filter',_txt);
	_celtxt=document.getElementById(_tbl.id+'Caption');
	if(_txt==''){
		_img=document.getElementById(_tbl.id+'_filterC');
		if(_img)_celtxt.removeChild(_img);
	}
	else{
		_img=document.getElementById(_tbl.id+'_filterC');
		if(!_img){
			_img=document.createElement('img');
			_img.src='/Graficos/Botones/filter.gif';
			_img.setAttribute('id',_tbl.id+'_filterC');
			_img.border=0;
			_img.style.cursor=window.ActiveXObject?'hand':'pointer';
			addEvent(_img, 'click', function(){filter(_tbl.id,'')});
		}
		_img.setAttribute('title','Filtro Activado. Filas que contengan: "'+_txt+'"');
		_celtxt.appendChild(_img);
	}
	_tbo = _tbl.tBodies[0];
	for(var i=0;i<_tbo.rows.length;i++){
		_tbo.rows[i].style.display='none';
		for(var j=0;j<_tbo.rows[i].cells.length;j++){
			_celtxt = window.ActiveXObject?_tbo.rows[i].cells[j].innerText:_tbo.rows[i].cells[j].textContent
			if(_celtxt.search(new RegExp( _txt, "i" ))!=-1){
				_tbo.rows[i].style.display='';
				break;
			}
		}
		
	}
}
function filterkey(){
	if(arguments[0].keyCode==13){
		filter(arguments[1]);
		menu_table_close(arguments[1]);
	}
	if(arguments[0].keyCode==27) menu_table_close(arguments[1]);
}

function pagingkey(){
	if(arguments[0].keyCode==13){
		var _tbl, _xpag;
		_tbl = document.getElementById(arguments[1]);
		_xpag = document.getElementById(_tbl.id+'_divmenu_txtxpagina');
		if(_tbl.tBodies[0].childNodes.length==parseInt(_tbl.getAttribute('xpagina'))){
			_tbl.setAttribute('xpaginaaux',_xpag.value);
			desPag(_tbl.id);
		}
		else{
			_tbl.setAttribute('xpagina',_xpag.value);
			paging(_tbl.id);
		}
		menu_table_close(_tbl.id);
	}
	if(arguments[0].keyCode==27) menu_table_close(arguments[1]);
}
function menu_table(){
	if(arguments.length==0) return;
	var _tbl, _img, y = 5, x = 12, _div, _p, _cls, _tblm, _hei;
	_tbl = document.getElementById(arguments[0]);
	if(_tbl.getAttribute('menu')==1) return;
	if(_tbl.getAttribute('adding')=='true') return;
	_cls = (window.ActiveXObject?'className':'class');
	_tbl.setAttribute('menu',1);
	_img = document.getElementById(_tbl.id+'_imgmenu');
    if(window.ActiveXObject){
		while (_img.offsetParent != null){
		  y += _img.offsetTop;
		  x += _img.offsetLeft;
		  _img = _img.offsetParent;
		}
		y += _img.offsetTop;
		x += _img.offsetLeft;
	}
	else{
		y += _img.y;
		x += _img.x;
	}
	_div =  document.createElement('div');
	_div.setAttribute('id',_tbl.id+'_divmenu');
	_div.style.left=x;
	_div.style.top=y;
	_div.setAttribute(_cls,'tabdatostit');
	 if(window.ActiveXObject)
		_div.style.filter= 'alpha (opacity=90);';
	else
		_div.style.opacity=0.9;
	_div.style.border = "1px solid #ffffff";
	_div.style.position = "absolute";
	document.body.appendChild(_div);
	chngzs('w',_div.id,213,0);
	
	_p=document.createElement('li');
	_p.innerHTML=("<span>Buscar:&nbsp;<input id='"+_div.id+"_txtfilter' type'text' size='20' class='ftexto' value='"+_tbl.getAttribute('filter')+"'>&nbsp;<img valing='center' id='"+_div.id+"_imgfilter' style='cursor:hand;cursor:pointer;' src='/graficos/botones/filter.gif'></span>");
	_p.setAttribute(_cls,'tabdatostit');
	_div.appendChild(_p);
	_p=document.getElementById(_div.id+"_txtfilter");
	addEvent(_p,'keypress',function(event){filterkey(event,_tbl.id)});
	_p=document.getElementById(_div.id+"_imgfilter");
	addEvent(_p,'click',function(){filter(_tbl.id);menu_table_close(_tbl.id)});
	_p=document.createElement('hr');
	_div.appendChild(_p);
	if(_tbl.getAttribute('menuadd')=='true'){
		_p=document.createElement('li');
		_p.innerHTML= 'Agregar Registros';
		_p.setAttribute(_cls,'tabdatostit');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent(_p,'click',function(){adding_table(_tbl.id);menu_table_close(_tbl.id)});
	}
	if(_tbl.getAttribute('rfsh')!=''||_tbl.getAttribute('rfsh')!=null){
		_p=document.createElement('li');
		_p.innerHTML= 'Refrescar Registros';
		_p.setAttribute(_cls,'tabdatostit');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent(_p,'click',function(){eval(_tbl.getAttribute('rfsh'));menu_table_close(_tbl.id)});
	}
	_p=document.createElement('hr');
	_div.appendChild(_p);
	if(_tbl.getAttribute('xpagina')&&_tbl.getAttribute('filter')==''){
		_p=document.createElement('li');
		_p.innerHTML=(_tbl.getAttribute('xpaginaaux')==0?'Desactivar Paginacion&nbsp;&nbsp;':'Activar Paginacion&nbsp;&nbsp;');
		_p.setAttribute(_cls,'tabdatostit');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent(_p,'click',function(){desPag(_tbl.id);menu_table_close(_tbl.id)});
		_p=document.createElement('li');
		_p.innerHTML=("<span>Registros por Pag:&nbsp;<input id='"+_div.id+"_txtxpagina' type'text' size='3' maxlength='3' class='ftexto' value='"+_tbl.getAttribute('xpagina')+"'></span>");
		_p.setAttribute(_cls,'tabdatostit');
		_div.appendChild(_p);
		_p=document.getElementById(_div.id+"_txtxpagina");
		addEvent(_p,'keypress',function(event){pagingkey(event,_tbl.id);});
		_p=document.createElement('hr');
		_div.appendChild(_p);
	}
	if(_tbl.getAttribute('detail')){
		_img=document.getElementById(_tbl.id+'AllDetail');
		_p=document.createElement('li');
		_p.innerHTML= _img.getAttribute('expand')=='F'?'Expandir Detalles':'Contraer Detalles';
		_p.setAttribute(_cls,'tabdatostit');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent(_p,'click',function(){showAllDetails(_tbl.id);menu_table_close(_tbl.id)});
	}
	_img=document.getElementById(_tbl.id+'_show');
	_p=document.createElement('li');
	_p.innerHTML= _img.src.toLowerCase().search(/abajo/)!=-1?'Mostrar Tabla':'Ocultar Tabla';
	_p.setAttribute(_cls,'tabdatostit');
	_p.style.cursor='pointer';
	_div.appendChild(_p);
	addEvent(_p,'click',function(){show_table(_tbl.id);menu_table_close(_tbl.id)});
	_p=document.createElement('hr');
	_div.appendChild(_p);
	_p=document.createElement('li');
	_p.innerHTML='Cerrar';
	_p.setAttribute(_cls,'tabdatostit');
	_p.style.cursor='pointer';
	_div.appendChild(_p);
	addEvent(_p,'mouseover',function(){menu_table_close(_tbl.id)});
}

function menu_table_close(){
	var _tbl = document.getElementById(arguments[0]);
	if(_tbl.getAttribute('menu')==0) return;
	_tbl.setAttribute('menu',0);
	var _div = document.getElementById(arguments[0]+'_divmenu');
	try{document.body.removeChild(_div)}
	catch(e){};
}

function edit(obj){
	obj = document.getElementById(obj);
	var _img = "<img src='/Graficos/Imagenes/load.gif' width='20' height='20' id='imgespvue'>";
	var _obj = trim(obj.id);
	var _val = trim(obj.innerHTML);
	var _input;
	switch(obj.getAttribute('inputtype')){
		case 'R':
			_input = '<select class=ftexto id="'+_obj+'_edit" onChange="javascript:this.style.backgroundColor=this.options[this.selectedIndex].style.backgroundColor;"></select>';
		break
		case 'L':
			_input = '<input type="checkbox" class=ftexto id="'+_obj+'_edit" '+(parseInt(_val)==1||_val.toUpperCase()=='SI'?'checked':'')+'>';
		break
		default:
			_input = '<input type="text" value="'+_val+'" id="'+_obj+'_edit" name="'+_obj+'" class="ftexto" onFocus="this.select();" >';
	}
	var _div = '<div id="'+_obj+'_dived" align="center">'+_input+_img+'<br><div align="center"><font id="'+_obj+'_save" class="ftexto" style="cursor:hand; cursor:pointer; white-space:nowrap;" ><img src="/Graficos/Imagenes/flechas_nup.gif">Guardar</font>&nbsp;&nbsp;&nbsp;&nbsp;<font id="'+_obj+'_cancel" class="ftexto" style=" cursor:hand; cursor:pointer; white-space:nowrap;"><img src="/Graficos/Imagenes/flechas_ndw.gif">Cancelar</font></div></div>';
	obj.style.display='none';
	obj.parentNode.innerHTML = obj.parentNode.innerHTML + _div;
	var _cancel = document.getElementById(_obj+'_cancel');
	var _guard = document.getElementById(_obj+'_save');
	var _edt = document.getElementById(_obj+'_edit');
	addEvent(_cancel, 'click', function(){cancelEdit(_obj)});
	addEvent(_guard, 'click', function(){saveChange(_obj)});
	addEvent(_edt, 'keypress', function(event){keyp(event,_obj)});
	switch(obj.getAttribute('inputtype')){
		case 'R':
			get_cbo(getHTTPObject(),obj.getAttribute('inputsrc'),_edt, _val);
		break
		case 'L':
			var _div = document.getElementById(_obj+'_dived');
			_div.removeChild(document.getElementById('imgespvue'))
		break
		default:
			_edt.maxLength=parseInt(obj.getAttribute('fsize'));
			_edt.size=(parseInt(obj.getAttribute('fsize'))<10?10:parseInt(obj.getAttribute('fsize'))+2);
			var _div = document.getElementById(_obj+'_dived');
			_div.removeChild(document.getElementById('imgespvue'))
	}
	_edt.focus()
}

function saveChange(obj){
	showAsEditable(obj, true);
	var _obj = document.getElementById(obj);
	var _val = document.getElementById(_obj.id+"_edit");
	var _tag = _obj
	var _f = _tag.getAttribute('field');
	var _trigger = _tag.getAttribute('trigger');
	while(_tag.tagName!='TR'){_tag = _tag.parentNode};
	var _i = _tag.id;
	while(_tag.tagName!='TABLE'){_tag = _tag.parentNode};
	var _o = _tag.getAttribute('tbledt');
	var _pg = (_obj.getAttribute('editpg')==''||_obj.getAttribute('editpg')=='null'||_obj.getAttribute('editpg')==null)?'/bin/consulta.asp?opc=666&o='+_o+'&i='+_i+'&f='+_f:_obj.getAttribute('editpg')+'&i='+_i;
	switch(_obj.getAttribute('inputtype')){
		case 'R':
			_obj.style.backgroundColor=_val.options[_val.selectedIndex].style.backgroundColor; // etiqueta <p>
			_obj.parentNode.style.backgroundColor=_obj.style.backgroundColor  // etiqueta <td>			
			get_value(getHTTPObject(), _pg+'&v='+escape(_val.value), _obj, _val.options[_val.selectedIndex].text);
			break
		case 'L':
			get_value(getHTTPObject(), _pg+'&v='+(_val.checked?'1':'0'), _obj, (_val.checked?'Si':'No'));
			break
		default:
			get_value(getHTTPObject(), _pg+'&v='+_val.value, _obj)
	}
	if(_trigger){
		try{setTimeout("eval('"+_trigger+"')",1500)}
		catch(e){}
		};
	cancelEdit(obj);	
	if(_tag.getAttribute('rfafteredt')=='true'){
		try{setTimeout('eval("'+_tag.getAttribute('rfsh')+'")',1000)}
		catch(e){}
	}
}

function cancelEdit(obj){
	showAsEditable(obj,true);
	obj = document.getElementById(obj);
	var _cancel = document.getElementById(obj.id+'_cancel');
	var _guard = document.getElementById(obj.id+'_save');	
	removeEvent(_cancel, 'click', function(){cancelEdit(obj.id)});
	removeEvent(_guard, 'click', function(){saveChange(obj.id)});
	var _div = document.getElementById(obj.id+'_dived');
	obj.parentNode.removeChild(_div);
	obj.style.display='';
	maked(obj.id);
}

function maked(obj){
	id = document.getElementById(obj);
	addEvent(id, 'click', function(){edit(obj)});
	addEvent(id, 'mouseover',  function(){showAsEditable(obj)});
	addEvent(id, 'mouseout',  function(){showAsEditable(obj,true)})
}
function showAsEditable(obj, clear){!clear?addClassName(obj,'editable'):removeClassName(obj,'editable')}
function keyp(e,obj){e.keyCode==13?saveChange(obj):e.keyCode==27?cancelEdit(obj):true}
function addClassName(element, className){
element = document.getElementById(element);
removeClassName(element, className);
element.className += ' ' + className}
function removeClassName(element, className) {
element = document.getElementById(element);
if (!element) return;
var newClassName = '';
var a = element.className.split(' ');
for(var i=0;i<a.length;i++){
	if(a[i]!=className){
		if(i>0) newClassName += ' ';
		newClassName += a[i];
	}
}
element.className = newClassName}
function showDetails(){
	var _obj, _tr, _td, _cols, _tbldet, _cls, _img;
	_obj=document.getElementById(arguments[0]);
	if(_obj.getAttribute('detail')=='') return;
	_tr=_obj;
	while(_tr.tagName!='TR'){_tr = _tr.parentNode};
	if(_obj.getAttribute('expand')=='F'){
		_tr.setAttribute('expand','T');
		_cls=window.ActiveXObject?'className':'class';
		_cols=_tr.cells.length;
		_tr=_tr.parentNode.insertRow(_tr.rowIndex);
		_tr.setAttribute('type','X');
		_td=document.createElement('td');
		_img=document.createElement('img');
		_img.src='/Graficos/Imagenes/sub.gif';
		_img.border=0;
		_td.appendChild(_img);
		_td.setAttribute(_cls,'tabdatoscuer');
		_td.vAlign = 'top';
		_td.setAttribute('width','10');
		_tr.appendChild(_td);
		_td = document.createElement('td');
		_td.colSpan = _cols;
		_td.setAttribute(_cls,'subtabla');
		_tbldet = document.createElement('table');
		_tbldet.setAttribute('cellpadding','0');
		_tbldet.setAttribute('cellspacing','1');
		_tbldet.setAttribute('id','tb_'+_obj.id);
		_tbldet.setAttribute(_cls,'tabla');
		//_tbldet.setAttribute('width','100%');
		_tbldet.setAttribute('align','left');
		_tbldet.setAttribute('subtable','true');
		_tbldet.setAttribute('rfsh',"showDetails('"+_obj.id+"');showDetails('"+_obj.id+"');");
		_tbldet.style.border='1px solid #333333';
		_td.appendChild(_tbldet);
		_tr.appendChild(_td);
		get_page(getHTTPObject(),_obj.getAttribute('detail'),_tbldet.id)
		_obj.src="/Graficos/Imagenes/menos.gif";
		_obj.setAttribute('expand','T');
	}
	else{
		_tr.parentNode.deleteRow(_tr.rowIndex);
		_obj.src="/Graficos/Imagenes/mas.gif";
		_obj.setAttribute('expand','F');
		_tr.setAttribute('expand','F');
		
	}
}

function showAllDetails(){
	var _tbl, _img, _tbo, i, _row, _fil, _tr;
	if(arguments[0]=='') return;
	_tbl=document.getElementById(arguments[0]);
	if(_tbl.getAttribute('detail')==''||_tbl.getAttribute('detail')==null) return;
	if(_tbl.getAttribute('adding')=='true') return;
	_tbo=_tbl.tBodies[0];
	_img=document.getElementById(_tbl.getAttribute('detail'));
	if(arguments[1]==true)_img.setAttribute('expand','T');
	if(arguments[1]==false)_img.setAttribute('expand','F');
	if(_img.getAttribute('expand')=='F'){
		for(i=0;i<_tbo.rows.length;i++){
				_row=document.getElementById(_tbl.id+'Detail'+  i.toString());
				if(_row)
					if(_row.getAttribute('expand')=='F'){
						_tr=_row;
						while(_tr.tagName!='TR'){_tr=_tr.parentNode};
						if (_tr.style.display==''){showDetails(_row.id)};
					}
		}
		_img.src="/Graficos/Imagenes/menosC.gif";
		_img.setAttribute('expand','T');
	}
	else{
		for(i=0;i<_tbo.rows.length;i++){
			_row=document.getElementById(_tbl.id+'Detail'+i.toString());
			if(_row) if(_row.getAttribute('expand')=='T') showDetails(_row.id);
		}
		_img.src="/Graficos/Imagenes/masC.gif";
		_img.setAttribute('expand','F');
	}
}

function hideSubtotals(){
	if(arguments[0]=='') return;
	var _tbl=document.getElementById(arguments[0]);
	if(_tbl.getAttribute('subtotals')=='T'){
		_tbl.setAttribute('subtotals','F');
		var _tBo=_tbl.tBodies[0];
		for(var i=0;i<_tBo.rows.length;i++)
			if(_tBo.rows[i].getAttribute('type')=='ST')
				_tBo.deleteRow(i);
	}
}

function showSubtotals(){
	if(arguments[0]=='') return;
	var _cel, _corte, corte1, j, i, tr, _con, _tit;
	var _tbl=document.getElementById(arguments[0]);
	if(_tbl.tHead.rows[0].cells[arguments[1]].getAttribute('subtotal')=='true'){
		_tbl.setAttribute('subtotals','T');
		var _subT = new Array(), _subTF = new Array();
		for(i=0;i<_tbl.tHead.rows[0].cells.length;i++){
			_subT[i]=_tbl.tHead.rows[0].cells[i].getAttribute('tot')=='true'?0:null;
			_subTF[i]=_tbl.tHead.rows[0].cells[i].getAttribute('tot')=='true'?0:null;
		}
		_corte=true;
		for(i=0;i<_subT.length;i++)
			if(_subT[i]==0)
				_corte=false;
		if(_corte) return;
		var _tbo=_tbl.tBodies[0];
		_corte=(window.ActiveXObject?_tbo.rows[0].cells[arguments[1]].innerText:_tbo.rows[0].cells[arguments[1]].textContent);
		_corte=(trim(_corte)==''?_tbo.rows[0].cells[arguments[1]].getAttribute('title'):_corte)
		_con=0;
		while(_subT[_con]==null){_con++};
		for(i=0;i<_tbo.rows.length;i++){
			_corte1=(window.ActiveXObject?_tbo.rows[i].cells[arguments[1]].innerText:_tbo.rows[i].cells[arguments[1]].textContent);
			_corte1=(trim(_corte1)==''?_tbo.rows[i].cells[arguments[1]].getAttribute('title'):_corte1)
			if(_corte==_corte1){
				for(j=0;j<_subT.length;j++) 
					if(_subT[j]!=null){
						_subTF[j]=parseInt(_tbl.tHead.rows[0].cells[j].getAttribute('dec')||0);
						_subT[j]=_subT[j]+parseInt(_tbo.rows[i].cells[j].getAttribute('sorttable_customkey'));
					}
			}
			else{
				_tit = 'Subtotal '+(_tbo.rows[i-1].cells[arguments[1]].getAttribute('title')!=''&&_tbo.rows[i-1].cells[arguments[1]].getAttribute('title')?_tbo.rows[i-1].cells[arguments[1]].getAttribute('title'):_corte);
				_corte=(window.ActiveXObject?_tbo.rows[i].cells[arguments[1]].innerText:_tbo.rows[i].cells[arguments[1]].textContent);
				_corte=(trim(_corte)==''?_tbo.rows[i].cells[arguments[1]].getAttribute('title'):_corte)
				_tr = _tbo.insertRow(i);
				_tr.setAttribute('type','ST');
				_cel = _tr.insertCell(0);
				_cel.colSpan =_con;
				_cel.className = 'tabdatossubtot';
				_cel.appendChild(document.createTextNode(_tit));
				for(j=_con;j<_subT.length;j++){ 
					_cel=_tr.insertCell(-1);
					_cel.className = 'tabdatossubtot';
					if(_subT[j]!=null){ 
						_cel.setAttribute('align','right');
						_subT[j]=_subT[j]/Math.pow(10,_subTF[j]);
						_cel.appendChild(document.createTextNode(_subT[j]==0?'':format(_subT[j],_subTF[j],true)));
						_subT[j]=0;
					}
				}
			}
			
		}
		_tr = _tbo.insertRow(-1);
		
		_tr.setAttribute('type','ST');
		_cel = _tr.insertCell(0);
		_cel.colSpan =_con;
		_cel.className = 'tabdatossubtot';
		_tit = 'Subtotal '+(_tbo.rows[i-1].cells[arguments[1]].getAttribute('title')!=''&&_tbo.rows[i-1].cells[arguments[1]].getAttribute('title')?_tbo.rows[i-1].cells[arguments[1]].getAttribute('title'):_corte);
		_cel.appendChild(document.createTextNode(_tit));
		for(j=_con;j<_subT.length;j++){ 
			_cel=_tr.insertCell(-1);
			_cel.className = 'tabdatossubtot';
			if(_subT[j]!=null){ 
				_cel.setAttribute('align','right');
				_subT[j]=_subT[j]/Math.pow(10,_subTF[j]);
				_cel.appendChild(document.createTextNode(_subT[j]==0?'':format(_subT[j],_subTF[j],true)));
				_subT[j]=0;
			}
		}
		
	}
}
var ttss, t_print;
var _stack = new Array();
var enProceso = false; // lo usamos para ver si hay un proceso activo


