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;
	$(cuadro_n).setStyles({opacity:100,display:''});
}
function oculta(cuadro_n){
	$(cuadro_n).setStyles({opacity:0,display:'none'});
	}

function MGM_openWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function printPage() {
	if (window.print){
		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($(nom_div).style.display==''){
		$(nom_div).style.display='none';
		if(trim(nom_img)!=''){
			fle.src='/images/abajo.jpg';
			$(nom_img).src= fle.src;
		}
	}
	else{
		$(nom_div).style.display='';
		if(trim(nom_img)!=''){
			fle.src="/images/arriba.jpg";
			$(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="/images/arriba.jpg":fle.src="/images/abajo.jpg");
		}
	}
	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="/images/arriba.jpg":fle.src="/images/abajo.jpg");
		}
	} // (window.ActiveXObject)
}

function desPag(tabla){
	var tbo = document.getElementById(tabla);
	if(tbo.getAttribute('filter')!=''){
		alert('Esta opcion no esta disponible porque tiene activado un FILTRO');
		return;
	}
	var _aux = document.getElementById(tabla+'_closeimg');
	if(_aux==null) return;
	if(_aux.src.toLowerCase().search(/close/)!=-1){
		_aux.src="/images/open.jpg";
		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="/images/close.jpg";
		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, _img;
	arr=arguments[1];
	fft=arguments[2];
	tbf = arguments[0].tFoot;
	_tr = document.createElement ("tr");
	_tr.setAttribute((window.ActiveXObject?'className':'class'),'sub_tit_2');
	_tr.style.cssText="width: 17px; text-align: left;";
	if(arguments[3]){
		_td = document.createElement ("td");
		_td.appendChild(document.createTextNode('\u00a0'));
		_tr.appendChild(_td);
	}
	for(var j=0;j<arr.length;j++)
		if(!isNaN(arr[j]))
			break;
	_img = new Image(12,6);
	_img.src = '/images/punto.png'
	_td = document.createElement ("td");
	_td.colSpan=j-1;
	_td.appendChild(_img);
	_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');
			_td.setAttribute((window.ActiveXObject?'className':'class'),'sub_tit_3');
			_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));
			if(arr[i]<0) _td.style.cssText="color:#ff0000;";
			_td.noWrap = true;
			_tr.appendChild(_td);
		}
		else{
			_td = document.createElement ("td");
			_td.setAttribute((window.ActiveXObject?'className':'class'),'sub_tit_3');
			_td.appendChild(document.createTextNode('\u00a0'));
			_tr.appendChild(_td);
			}
	}
	if(arguments[0].getAttribute('tbldel')=='true'){
		_td = document.createElement ("td");
		_td.setAttribute((window.ActiveXObject?'className':'class'),'sub_tit_3');
		_tr.appendChild(_td);
	}
	tbf.appendChild(_tr);
}
function get_page() {
	var http = arguments[0];
//	var _call = get_page.caller;
//	var _arr = _call.arguments[];
//	alert("caller is " + _call.name + '. Args: ' +	_arr.join());
	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','sub_tit_1')
			tbh.setAttribute('id','tbh')
			tabla.appendChild(tbh);
		}
		else{
			tbh=tabla.tHead;
			while (tbh.childNodes.length > 0)
				tbh.removeChild(tbh.firstChild);			
		}

		if(tabla.tFoot==null){
			tbf = document.createElement('tfoot');
			tbf.setAttribute('id','tbf')
			tabla.appendChild(tbf);
		}
		else{
			tbf = tabla.tFoot;
			while (tbf.childNodes.length > 0)
				tbf.removeChild(tbf.firstChild); 
		}
		// 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");
		var _text = document.createTextNode ('Buscando');
		var _img = new Image(100,18);
		_img.src = '/images/loading.gif'
//		_td.setAttribute('colspan', '4');
		_td.setAttribute((window.ActiveXObject?'className':'class'),'sub_tit_3')
		_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?'subtitulo':'titulo';
						_a = tabla.parentNode.className.search(/subtabla/i)!=-1?'/images/int_misc_tit.jpg':'/images/int_misc_tit.jpg';

						_cap.innerHTML = '<table width="100%" align="center" class="titulo" 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')+'"><td style="width:6px" ><img src="'+_a+'" width="6px"/></td>'+_menu+'<td id="'+tabla.id+'Caption"  nowrap>&nbsp;'+_val+'</td><td width="20px" onclick=javascript:if(!enProceso){show_table("'+tabla.id+'")};  style="cursor:hand; cursor:pointer;" valign="middle"><img id="'+tabla.id+'_show" src="/images/arriba.jpg" width="20px" heigth="20px"></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, 'sub_tit_1');
						_td.setAttribute('order', 'nosort');
						_td.setAttribute('width', '10');
						_td.setAttribute('align', 'center');
						_text = document.createElement('img');
						_text.src='/Images/mas.JPG';
						_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, 'sub_tit_1');
						_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] = 9999999999999};
						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, 'sub_tit_1');
					_td.width='13px';
					_visc++;
				}
				

				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')||dat[i].childNodes[j].getAttribute('preimgl2')){
									_link = document.createElement('a');
									_link.setAttribute('href', dat[i].childNodes[j].getAttribute('preimgl2'));
									_link.appendChild(_text);
									_td.appendChild(_link);
									//_td.style.whiteSpace="nowrap";
								}
								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'):((j%2)==1?'celda_1':'celda_0')));
							//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')=='')&&(dat[i].childNodes[j].getAttribute('link2')==null || dat[i].childNodes[j].getAttribute('link2')==''))
								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('div');
										_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(dat[i].childNodes[j].getAttribute('inputtype')=='A'){
												var _arrarea = _val.split(/\n/);
												for(var _xa=0;_xa<_arrarea.length;_xa++){
													_text.appendChild(document.createTextNode(_arrarea[_xa]));
													_text.appendChild(document.createElement('br'));
												}
											}
											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('link2'));
								if(dat[i].childNodes[j].getAttribute('target')!=null && dat[i].childNodes[j].getAttribute('target')!=''){
									_text.setAttribute('target', dat[i].childNodes[j].getAttribute('target'));
								};
								_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')||dat[i].childNodes[j].getAttribute('posimgl2')){
									_link = document.createElement('a');
									_link.setAttribute('href', dat[i].childNodes[j].getAttribute('posimgl2'));
									_link.appendChild(_text);
									_td.appendChild(_link);
									//_td.style.whiteSpace="nowrap";
								}
								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='/Images/mas.jpg';
							_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, 0, _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(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");
					_tr.setAttribute(_cls, 'sub_tit_3'); 
					_td = document.createElement ("td");
					_td.colSpan = _visc+(_detailfoot?1:0);
					_td.setAttribute('align', 'center');
					var _navbar = '<table align="left" celpadding=0 cellspacing=0 width="100%"><tr><td style="background-image:url(/images/fondo_pag.jpg); " ><table align="left" celpadding=0 cellspacing=0 id="'+tabla.id+'_pag"><tr align="center">';
					_navbar +='<td id="'+tabla.id+'_first" style="cursor:hand; cursor:pointer;" title="Primera Pagina"> <img src="/images/first.jpg"> </td><td id="'+tabla.id+'_prev" title="Pagina Anterior" style="cursor:hand; cursor:pointer;"> <img src="/images/prev.jpg"> </td>';
					_navbar +='<td class="sub_tit_2" width="15px" style="width:17px; font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; " id="'+tabla.id+'_txtpage">1</td>';
					_navbar +='<td id="'+tabla.id+'_next" title="Pagina Siguiente" style="cursor:hand; cursor:pointer;"> <img src="/images/next.jpg"> </td><td id="'+tabla.id+'_last" title="Ultima Pagina" style="cursor:hand; cursor:pointer;"> <img src="/images/last.jpg"> </td></tr></table></td>';
					_navbar +='<td width="8" id="'+tabla.id+'_close" style="cursor:hand; cursor:pointer; background-image:url(/images/fondo_pag.jpg); " title="Desactivar Paginacion" align="rigth"><img align="rigth" id="'+tabla.id+'_closeimg" src="/images/close.jpg"></td></tr></table>';
					_td.innerHTML=_navbar;
					_tr.appendChild(_td);
					tbf.appendChild(_tr);
					_navbar = document.getElementById(tabla.id+'_prev');
					addEvent1(_navbar, 'click', function(){previous(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_next');
					addEvent1(_navbar, 'click', function(){next(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_last');
					addEvent1(_navbar, 'click', function(){last(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_first');
					addEvent1(_navbar, 'click', function(){frst(tabla.id)});
					_navbar = document.getElementById(tabla.id+'_close');
					addEvent1(_navbar, 'click', function(){desPag(tabla.id)});
				}

				
				if(!_show){show_table(tabla.id)};
			}
// --------------------------------------------------------------------------------------------------------------------------
		};
		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'));
			}
		};
		httpx.send(null);
	}
}

function post_value() {
	var httpx = arguments[0];
	if (httpx) {
	var obj = arguments[2];
	var _tag = obj;
	while(_tag.tagName!='TABLE'){_tag = _tag.parentNode};
	var _o = _tag.getAttribute('tbledt');
	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]};
		params='&v='+def+'&o='+_o+'&xml=1&pwd='+Math.round(Math.random()*1000000);
//		alert(params);
//		alert(url);
		httpx.open("POST", url, true);
		httpx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//		httpx.setRequestHeader("Content-length", params.length);
//		httpx.setRequestHeader("Connection", "close");		
		httpx.onreadystatechange = function(){
			if (httpx.readyState == 4 && httpx.status == 200 && httpx.responseXML) {
				var dat = httpx.responseXML.documentElement.getElementsByTagName('dato');
//				alert(dat);
				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'));
			}
		};
		httpx.send(params);
	}
}

function get_cbo() {
	var htp = arguments[0];
	if (htp) {
		var url = arguments[1];
		url+='&xml=1&pwd='+Math.round(Math.random()*1000000);
		htp.open("GET", url, true);
		var cbo = arguments[2];
		var val = arguments[3];
		var id = arguments[4];
		htp.onreadystatechange = function(){
			if (htp.readyState == 4 && htp.status == 200 && htp.responseXML) {
//				alert(httpx.responseXML);
		
				var dat = htp.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();
			}
		};
		htp.send(null);
	}
}

function getHTTPObject() {
    var xmlhttp;
    if(window.XMLHttpRequest) {
    	try {
			xmlhttp = new XMLHttpRequest();
        } 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 addEvent1(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 removeEvent1(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 = $(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, _def, _flag=true;
	_tbl = typeof(arguments[0])=='object'?arguments[0]:$(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;
				_def = _tbl.tHead.rows[0].cells[i].getAttribute('fdefault');
				switch(_tbl.tHead.rows[0].cells[i].getAttribute('inputtype')){
					case 'R':
						_cell.innerHTML = '<select class="contenido" id="'+_tbl.id+'_new'+i+'"></select>';
						_input = $(_tbl.id+'_new'+i);
						get_cbo(getHTTPObject(),_tbl.tHead.rows[0].cells[i].getAttribute('inputsrc'),_input, '');						
					break
					case 'L':
						_cell.innerHTML = '<input type="checkbox" '+(_def==1?' checked':'')+' class="contenido" id="'+_tbl.id+'_new'+i+'">';
					break
					case 'A':
						_cell.innerHTML = '<textarea id="'+_tbl.id+'_new'+i+'" cols="'+_tbl.tHead.rows[0].cells[i].getAttribute('fsize')+'" class="contenido" rows="5">'+_tbl.tHead.rows[0].cells[i].getAttribute('fdefault')+'</textarea>';	
						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="contenido">';
				}
			}
		}
		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="sub_tit_3" style="cursor:hand; cursor:pointer; white-space:nowrap;" onClick="javascript:saveNew('+String.fromCharCode(39)+_tbl.id+String.fromCharCode(39)+');"><img src="/Graficos/Imagenes/flechas_nup.gif" />Guardar</font>&nbsp;&nbsp;&nbsp;&nbsp;<font class="sub_tit_3" style=" cursor:hand; cursor:pointer;" onClick="javascript:adding_table('+String.fromCharCode(39)+_tbl.id+String.fromCharCode(39)+');" 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(){
	//alert(arguments[0]);
	var _tbl, i, _atr='',  _val='', _obj, _url, _tbedit;
	_tbl = typeof(arguments[0])=='object'?arguments[0]:$(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=$(_tbl.id+'_new'+i);
			_atr=_atr+_tbl.tHead.rows[0].cells[i].getAttribute('field')+'|';
			if(_tbl.tHead.rows[0].cells[i].getAttribute('inputtype')=='L')
				_val=_val+(_obj.checked?'1':'0')+"|"
			else
				_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){
//		alert(_tbl.getAttribute('rfsh'));
		ttss=setTimeout(_tbl.getAttribute('rfsh'),75);
	}
}

function chngzs(){
	if(arguments[2]<=arguments[3]) return;
	var _obj = $(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 = $(arguments[0]);
	if(_tbl.getAttribute('xpaginaaux')==0)desPag(_tbl.id);
	if(_tbl.getAttribute('detail')){
			_img=$(_tbl.getAttribute('detail'));
			if(_img.getAttribute('expand')=='T') showAllDetails(_tbl.id,false);
	}
	if(typeof arguments[1]=='string')
		_txt=arguments[1];
	else
		_txt=trim($(arguments[0]+'_divmenu_txtfilter')?$(arguments[0]+'_divmenu_txtfilter').value:_tbl.getAttribute('filter'));
	_tbl.setAttribute('filter',_txt);
	_celtxt=$(_tbl.id+'Caption');
	if(_txt==''){
		_img=$(_tbl.id+'_filterC');
		if(_img)_celtxt.removeChild(_img);
	}
	else{
		_img=$(_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';
			addEvent1(_img, 'click', function(){filter(_tbl.id,'')});
		}
		_img.setAttribute('title','Filtro Activado. Filas que contengan: "'+_txt+'"');
		_celtxt.appendChild(_img);
	}
	_tbo = _tbl.tBodies[0];
	_img = true;
	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){
				_img = false;
				_tbo.rows[i].style.display='';
				break;
			}
		}
		
	}
	if(_img)
		alert('No existen datos que concuerden con el criterio de busqueda.');
}
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 = $(arguments[1]);
		_xpag = $(_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 = $(arguments[0]);
	if(_tbl.getAttribute('menu')==1) return;
	if(_tbl.getAttribute('adding')=='true') return;
	_cls = (window.ActiveXObject?'className':'class');
	_tbl.setAttribute('menu',1);
	_img = $(_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.style.position = "absolute";
	_div.style.width = "202px";
	_div.style.border = "1px solid #376CA3";
	_div.style.backgroundImage="url(/images/menu_opbot_fondo.jpg)";
	 if(window.ActiveXObject)
		_div.style.filter= 'alpha (opacity=95);';
	else
		_div.style.opacity=0.95;
	document.body.appendChild(_div);
	chngzs('w',_div.id,202,0);
	
	_p=document.createElement('div');
	//_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.innerHTML = ("<div style='float:left'>BUSCAR</div><div style='float:left; margin-left:3px'><input id='"+_div.id+"_txtfilter' type='text' value='"+_tbl.getAttribute('filter')+"' style=' width:118px; height:16px; border:1px solid #666; overflow:hidden; font-size:10px; color:#999'/></div><div style='float:left; margin-left:3px'><img src='/images/menu_tabla_filtrar.jpg' width='17' id='"+_div.id+"_imgfilter' height='14' /></div>")
	_p.setAttribute(_cls,'op_a');
	_div.appendChild(_p);
	_p=$(_div.id+"_txtfilter");
	addEvent1(_p,'keypress',function(event){filterkey(event,_tbl.id)});
	_p=$(_div.id+"_imgfilter");
	addEvent1(_p,'click',function(){filter(_tbl.id);menu_table_close(_tbl.id)});
	_p=document.createElement('div');
	_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
	_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
	_div.appendChild(_p);
	_p=document.createElement('div');
	_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
	_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
	_div.appendChild(_p);
	if(_tbl.getAttribute('menuadd')=='true'){
		_p=document.createElement('div');
		_p.innerHTML= 'CARGA DE DATOS';
		_p.setAttribute(_cls,'op_b');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent1(_p,'click',function(){adding_table(_tbl.id);menu_table_close(_tbl.id)});
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
	}
	if(_tbl.getAttribute('rfsh')!=''||_tbl.getAttribute('rfsh')!=null){
		_p=document.createElement('div');
		_p.innerHTML= 'REFRESCAR';
		_p.setAttribute(_cls,'op_b');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent1(_p,'click',function(){eval(_tbl.getAttribute('rfsh'));menu_table_close(_tbl.id)});
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
	}
	if(_tbl.getAttribute('xpagina')&&_tbl.getAttribute('filter')==''){
		_p=document.createElement('div');
		_p.innerHTML=(_tbl.getAttribute('xpaginaaux')==0?'DESACTIVAR PAGINACION':'ACTIVAR PAGINACION');
		_p.setAttribute(_cls,'OP_A');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent1(_p,'click',function(){desPag(_tbl.id);menu_table_close(_tbl.id)});
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.innerHTML = "<div style='float:left'>REGISTROS X P&Aacute;GINA</div><div style='float:left; margin-left:3px'><input id='"+_div.id+"_txtxpagina' size='3' maxlength='3' type='text' style='width:45px; height:16px; border:1px solid #666; overflow:hidden; font-size:10px; color:#999' value='"+_tbl.getAttribute('xpagina')+"'/></div>"
		_p.setAttribute(_cls,'op_a');
		_div.appendChild(_p);
		_p=$(_div.id+"_txtxpagina");
		addEvent1(_p,'keypress',function(event){pagingkey(event,_tbl.id);});
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
}
	if(_tbl.getAttribute('detail')){
		_img=$(_tbl.id+'AllDetail');
		_p=document.createElement('div');
		_p.innerHTML= _img.getAttribute('expand')=='F'?'EXPANDIR DETALLES':'CONTRAER DETALLES';
		_p.setAttribute(_cls,'op_b');
		_p.style.cursor='pointer';
		_div.appendChild(_p);
		addEvent1(_p,'click',function(){showAllDetails(_tbl.id);menu_table_close(_tbl.id)});
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
		_p=document.createElement('div');
		_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
		_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
		_div.appendChild(_p);
}
	_img=$(_tbl.id+'_show');
	_p=document.createElement('div');
	_p.innerHTML= _img.src.toLowerCase().search(/abajo/)!=-1?'MOSTRAR TABLA':'OCULTAR TABLA';
	_p.setAttribute(_cls,'op_b');
	_p.style.cursor='pointer';
	_div.appendChild(_p);
	addEvent1(_p,'click',function(){show_table(_tbl.id);menu_table_close(_tbl.id)});
	_p=document.createElement('div');
	_p.style.cssText = "background-color:#9E9E9C; margin-left:2px; height:1px";
	_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
	_div.appendChild(_p);
	
	
	
	_div.appendChild(_p);
	_p=document.createElement('div');
	_p.innerHTML='EXPORTAR A EXCEL';
	_p.setAttribute(_cls,'OP_A');
	_p.style.cursor='pointer';
	_div.appendChild(_p);
	addEvent1(_p,'click',function(){exportToExcel(_tbl.id);menu_table_close(_tbl.id)});

	
	
	
	_p=document.createElement('div');
	_p.style.cssText = "background-color:#ffffff; margin-left:2px; height:1px";
	_p.innerHTML = "<img src='/images/dot.gif' width='1' height='1' />";
	_div.appendChild(_p);
	_p=document.createElement('div');
	_p.style.cssStyle = "margin-left:2px; overflow:hidden; height:20px";
	_p.setAttribute(_cls,'sub_tit_2');
	_p.innerHTML="<div style=' margin-left:6px; margin-top:3px;float:left;font-family:Arial, Helvetica, sans-serif;font-size:11px;font-weight:bold; color:#FFF;'>CERRAR</div><div style='float:right; margin-right:4px; margin-top:4px'><img src='/images/menu_tabla_cerrar.jpg' width='11' height='11' /></div>";
	_p.style.cursor='pointer';
	_div.appendChild(_p);
	addEvent1(_p,'mouseover',function(){menu_table_close(_tbl.id)});

}

function menu_table_close(){
	var _tbl = $(arguments[0]);
	if(_tbl.getAttribute('menu')==0) return;
	_tbl.setAttribute('menu',0);
	var _div = $(arguments[0]+'_divmenu');
	try{document.body.removeChild(_div)}
	catch(e){};
}

function edit(obj){
	obj = $(obj);
	var _img = "<img src='/Graficos/Imagenes/load.gif' width='20' height='20' id='imgespvue'>";
	var _obj = trim(obj.id);
	//alert(obj.id);
	var _val = trim(obj.innerHTML);
	var _input;
	switch(obj.getAttribute('inputtype')){
		case 'R':
			_input = '<select class=contenido id="'+_obj+'_edit" onChange="javascript:this.style.backgroundColor=this.options[this.selectedIndex].style.backgroundColor;"></select>';
		break
		case 'L':
			_input = '<input type="checkbox" class=contenido id="'+_obj+'_edit" '+(parseInt(_val)==1||_val.toUpperCase()=='SI'?'checked':'')+'>';
		break
		case 'A':
			_input = '<textarea id="'+_obj+'_edit" class="contenido" rows="5" >'+_val.replace(/<br>/gi, '\n')+'</textarea>';
		break
		default:
			_input = '<input type="text" rows="10" value="'+_val+'" id="'+_obj+'_edit" class="contenido" 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 = $(_obj+'_cancel');
	var _guard = $(_obj+'_save');
	var _edt = $(_obj+'_edit');
	addEvent1(_cancel, 'click', function(){cancelEdit(_obj)});
	addEvent1(_guard, 'click', function(){saveChange(_obj)});
	if(obj.getAttribute('inputtype')!= 'A') addEvent1(_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 = $(_obj+'_dived');
			_div.removeChild($('imgespvue'))
		break
		case 'A':
			_edt.cols=parseInt(obj.getAttribute('fsize'));
			var _div = $(_obj+'_dived');
			_div.removeChild($('imgespvue'));
		break
		default:
			_edt.maxLength=parseInt(obj.getAttribute('fsize'));
			_edt.size=(parseInt(obj.getAttribute('fsize'))<10?10:parseInt(obj.getAttribute('fsize'))+2);
			var _div = $(_obj+'_dived');
			_div.removeChild($('imgespvue'))
	}
	_edt.focus()
}

function saveChange(obj){
	showAsEditable(obj, true);
	var _obj = $(obj);
	var _val = $(_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
		case 'A':
			post_value(getHTTPObject(), _pg, _obj,escape(_val.value));
			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 = $(obj);
	var _cancel = $(obj.id+'_cancel');
	var _guard = $(obj.id+'_save');	
	removeEvent1(_cancel, 'click', function(){cancelEdit(obj.id)});
	removeEvent1(_guard, 'click', function(){saveChange(obj.id)});
	var _div = $(obj.id+'_dived');
	obj.parentNode.removeChild(_div);
	obj.style.display='';
	maked(obj.id);
}

function maked(obj){
	id = $(obj);
	addEvent1(id, 'click', function(){edit(obj)});
	addEvent1(id, 'mouseover',  function(){showAsEditable(obj)});
	addEvent1(id, 'mouseout',  function(){showAsEditable(obj,true)})
}
function showAsEditable(obj, clear){
//	alert($(obj).parentNode.getAttribute('align'));
	if($(obj).parentNode.getAttribute('align')=='left')
		(!clear?addClassName(obj,'Reditable'):removeClassName(obj,'Reditable'));
	else
		(!clear?addClassName(obj,'Leditable'):removeClassName(obj,'Leditable'));
}
function keyp(e,obj){e.keyCode==13?saveChange(obj):e.keyCode==27?cancelEdit(obj):true}
function addClassName(element, className){
element = $(element);
removeClassName(element, className);
element.className += ' ' + className}
function removeClassName(element, className) {
element = $(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=$(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,'contenido');
		_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="/Images/menos.jpg";
		_obj.setAttribute('expand','T');
	}
	else{
		_tr.parentNode.deleteRow(_tr.rowIndex);
		_obj.src="/Images/mas.jpg";
		_obj.setAttribute('expand','F');
		_tr.setAttribute('expand','F');
		
	}
}

function showAllDetails(){
	var _tbl, _img, _tbo, i, _row, _fil, _tr;
	if(arguments[0]=='') return;
	_tbl=$(arguments[0]);
	if(_tbl.getAttribute('detail')==''||_tbl.getAttribute('detail')==null) return;
	if(_tbl.getAttribute('adding')=='true') return;
	_tbo=_tbl.tBodies[0];
	_img=$(_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=$(_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="/Images/menos.JPG";
		_img.setAttribute('expand','T');
	}
	else{
		for(i=0;i<_tbo.rows.length;i++){
			_row=$(_tbl.id+'Detail'+i.toString());
			if(_row) if(_row.getAttribute('expand')=='T') showDetails(_row.id);
		}
		_img.src="/Images/mas.jpg";
		_img.setAttribute('expand','F');
	}
}

function hideSubtotals(){
	if(arguments[0]=='') return;
	var _tbl=$(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, _img;
	var _tbl=$(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 = 'sub_tit_3';
				_cel.style.textAlign = "left";
				_img = new Image(7,7);
				_img.src = '/images/flecha.jpg'
				_cel.appendChild(_img);
				_cel.appendChild(document.createTextNode(_tit));
				for(j=_con;j<_subT.length;j++){ 
					_cel=_tr.insertCell(-1);
					_cel.className = 'sub_tit_3';
					if(_subT[j]!=null){ 
						_cel.setAttribute('align','right');
						_subT[j]=_subT[j]/Math.pow(10,_subTF[j]);
						_cel.appendChild(document.createTextNode(_subT[j]==0?'\u00a0':format(_subT[j],_subTF[j],true)));
						if(_subT[j]<0) _cel.style.cssText="color:#ff0000;"
						_subT[j]=0;
					}
					else
						_cel.appendChild(document.createTextNode('\u00a0'));
				}
			}
			
		}
		_tr = _tbo.insertRow(-1);
		
		_tr.setAttribute('type','ST');
		_cel = _tr.insertCell(0);
		_cel.colSpan =_con;
		_cel.className = 'sub_tit_3';
		_cel.style.textAlign = "left";
		_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 = 'sub_tit_3';
			if(_subT[j]!=null){ 
				_cel.setAttribute('align','right');
				_subT[j]=_subT[j]/Math.pow(10,_subTF[j]);
				_cel.appendChild(document.createTextNode(_subT[j]==0?'\u00a0':format(_subT[j],_subTF[j],true)));
				if(_subT[j]<0) _cel.style.cssText="color:#ff0000;"
				_subT[j]=0;
			}
			else
				_cel.appendChild(document.createTextNode('\u00a0'));
		}
		
	}
}

function load_sabana(){
//	location.href=location.href+'#q='+parseInt($('hstr').title);
	if(arguments[1]=='') return;
	if(enProceso) return;
	enProceso = true;
	$('dvbusc').style.display='';
	if(menin!='' && menin!=null) 
	try{
		$(menin).setAttribute((window.ActiveXObject?'className':'class'),'lev1');
	}catch(e){};
	if(arguments[0]==0 && arguments[1]!='' && !isNaN(arguments[2]))
		menin=	'x_0_'+arguments[2];
	else
		menin=	'x_0_'+arguments[0];
	try{
		$(menin).setAttribute((window.ActiveXObject?'className':'class'),'lev1_on');
	}catch(e){};
	menurl = arguments[1]; 
	menpr = arguments[2];
	if(isNaN(menpr))
		menpr = 0;
	new Request.HTML({url:"/bin/barrahelp.asp?i="+menpr,update:$( "barra_help" ),evalScripts: true,method:"post"}).send();
	new Request({url: '/bin/lognav.asp?idm='+menpr+'&url='+arguments[1]}).send();
	_jsp='';
	if(arguments[3]!=-1){
		var _point = parseInt($('hstr').title);
		while(_point<$('hstr').getElementsByTagName('li').length)
			$('hstr').removeChild($('hstr').lastChild);
		_li =  document.createElement('li');
		_li.title = arguments[1];
		_li.id = 'hstr'+_point.toString();
		$('hstr').appendChild(_li);
		$('hstr').title=_point+1;
	}
	else{
		_jsp = $('hstr').getElementsByTagName('li')[ parseInt($('hstr').title)-1].getAttribute('jsp');
	}
	var ext = arguments[1].substring(arguments[1].length, arguments[1].length-4);
	if(ext.toUpperCase()=='.PDF'){
		window.open(arguments[1], "Morgan, Garcia Mansilla y Cia. S. A.");
	}
	else{
		rqt = new Request.HTML({url:arguments[1],update:$( "sabana_int" ),evalScripts: true,method:"post", onComplete: function(){onComplete_sabana(arguments[1]);try{eval(_jsp);}catch(e){}}});
		rqt.send();
		$('impbutton').removeEvents();
		$('impbutton').addEvent('click', function(){
					if ($( 'sabana_result')!=null)
						var c = $( 'sabana_result').innerHTML;
					else
						var c = $( 'sabana_int').innerHTML;
					var n = $('dvnomcli').innerHTML;
					var h = $('barra_help').innerHTML;
					var v=window.open("print.asp","prn");
					v.document.open();
					v.document.write('<html>\n<head>\n');
					v.document.write('<title>Morgan Garcia Mansilla y Cia. S.A.</title>\n<link href="/mgm_style_imp.css" rel="stylesheet" type="text/css"/><link href="/inf_style_imp.css" rel="stylesheet" type="text/css"/>\n');
					v.document.write('</head>\n<body >\n');
					v.document.write('<div id="header" style="height:100px "><img src="/images/cabeprint.jpg" width="955px" height="100px" /></div><div style="width:955px; display:block; overflow:hidden; ">');
					v.document.write('<div class="sub_tit_3" style="background-color:#DAD9D3; overflow:hidden; display:block; text-align:left; height:15px">');
					if($('dvnomcli').style.display=='')
						v.document.write('<img src="/images/flecha.jpg"/>Empresa: '+n);
					v.document.write('<div style="float:right; overflow:hidden; margin-top:2px" >'+h+'</div></div>');
					v.document.write(c.replace(/<PARAM NAME="Play" VALUE="0">/gi,''));
					v.document.write('</div><div  class="foot"></div><br><div style="width:955px;font-size:9px;" class="info">NOTA: El presente es un reporte no vinculante confeccionado de acuerdo a un an&aacute;lisis de mercado realizado por MGMSA, que puede no coincidir con otras opiniones existentes en el mercado. Toda decisi&oacute;n acción que los clientes tomen en base al presente reporte  correr&aacute; por su propia cuenta y MGMSA no ser&aacute; bajo ninguna circunstancia responsable por las mismas.</div></body></html>');
					v.document.close();
					v.print();
		});
	} // PDF o ASP
}


function onComplete_sabana(){
	$('dvbusc').style.display='none';
	enProceso = false;
}

function chkbarra(){
	if ($('barra_help').innerHTML == '')
		$('barra_help').innerHTML = arguments[0];
}

function nombarra(){
	if(arguments[2]){
		var _dv = document.createElement('div');
		_dv.setAttribute("id","barracabin");
		$('barracab').innerHTML="";
		$('barracab').appendChild(_dv);
		var flashvars_b = {
	//		status:arguments[0], se usaba para poner el nombre del cliente en la barra superior
			status:'',
			imm: (arguments[1]=='A'?4:3)
		};
		var params = {
		  menu: "false",
		  wmode: "transparent"
		};
		var attributes = {
		  id: "myDynamicContent",
		  name: "myDynamicContent",
		  styleclass: "noOutline"
		};
		
		swfobject.embedSWF("/flash/barra_int11.swf", "barracabin", "955", "21", "9.0.0","expressInstall.swf", flashvars_b, params, attributes);
	}
	if(!$("cbcli"))
		$("dvnomcli").innerHTML = arguments[0];	
}

function buscarinterno(){
	var _arr = arguments[0].split(':')
	var rq = new Request({url:'/bin/auditbuscar.asp?txt='+arguments[0],method:"post"}).send();
	switch(_arr[0].toUpperCase()){
		case "CT":
			load_sabana(0,"/clientes/mercaderia/contrato.asp?bscr=99&sch=1&co="+_arr[1]);
		break;
		case "FC":
			load_sabana(0,"/clientes/contaduria/comprobantes.asp?c="+_arr[1]);
		break;
		case "DE":
			load_sabana(0,"/clientes/mercaderia/entregas.asp?bscr=99&sch=1&co="+_arr[1]);
		break;
		case "CP":
			load_sabana(0,"/clientes/mercaderia/modelocp.asp?bscr=99&co="+_arr[1]);
		break;
		default:
			load_sabana(0,"/bin/buscar.asp?sch="+encodeURI(arguments[0]));
	}
}

function backinterno(){
	var _point = parseInt($('hstr').title);
	if(_point>1){
		$('hstr').title=_point-1;
		_url = $('hstr').getElementsByTagName('li')[_point-2].title;
		load_sabana(0,_url,0,-1);
	}
}

function forwardinterno(){
	var _point = parseInt($('hstr').title);
	if($('hstr').getElementsByTagName('li').length>_point){
		$('hstr').title=_point+1;
		_url = $('hstr').getElementsByTagName('li')[_point].title;
		load_sabana(0,_url,0,-1);
	}
}

function backjsp(){
	var _point = parseInt($('hstr').title)-1;
	$('hstr'+_point.toString()).setAttribute('jsp', arguments[0]);
	//$('hstr'+_point.toString()).innerHTML = arguments[0];
}

function schselect(){
	for(var i=0;i<$(arguments[0]).options.length;i++){
		if($(arguments[0]).options[i].value==arguments[1]){
			$(arguments[0]).selectedIndex = i;
			return;
		}
	}
}
function ayuda(){
	window.open("/general/ayuda.asp","Ayuda","width=500,height=230,scrollbars=NO");
}


function getWindowData(){
    var widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal;
    if (typeof window.innerWidth != 'undefined'){
        widthViewport= window.innerWidth;
        heightViewport= window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0){
        widthViewport=document.documentElement.clientWidth;
        heightViewport=document.documentElement.clientHeight;
    }else{
        widthViewport= document.getElementsByTagName('body')[0].clientWidth;
        heightViewport=document.getElementsByTagName('body')[0].clientHeight;
    }
    xScroll=self.pageXOffset || (document.documentElement.scrollLeft+document.body.scrollLeft);
    yScroll=self.pageYOffset || (document.documentElement.scrollTop+document.body.scrollTop);
    widthTotal=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth,widthViewport);
    heightTotal=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,heightViewport);
    return [widthViewport,heightViewport,xScroll,yScroll,widthTotal,heightTotal];
}
window.onresize=window.onscroll=function(){initdiv();};

function initdiv(){
var data=getWindowData();
if($('_divimgback')){
	$('_divimgback').style.left=data[0]/2+data[2]-parseInt($('_divimgback').style.width)/2+'px';
	$('_divimgback').style.top=data[1]/2+data[3]-parseInt($('_divimgback').style.height)/2+'px';
}
if($('_divimgfront')){
	$('_divimgfront').style.left=data[0]/2+data[2]-parseInt($('_divimgfront').style.width)/2+'px';
	$('_divimgfront').style.top=40+data[1]/2+data[3]-parseInt($('_divimgfront').style.height)/2+'px';
}
}

function showimg(){
	var _div =  document.createElement('div');
	_div.setAttribute('id','_divimgback');
	_div.setAttribute('title','Click para cerrar');
	_div.style.cursor='pointer';
	_div.style.width=window.screen.width-25;
	_div.style.height=window.screen.height;
	if(window.ActiveXObject)
		_div.style.filter= 'alpha (opacity=70);';
	else
		_div.style.opacity=0.7;
	_div.style.backgroundColor='#666666';
	_div.style.position = "absolute";
	addEvent1(_div,'click',function(){closeimg();});
	var _div2 = document.createElement('div');
	_div2.setAttribute('id','_divimgfront');
	_div2.style.width='700px';
	_div2.style.height='500px';
	_div2.style.border = "10px solid #ffffff";
	_div2.style.position = "absolute";
	addEvent1(_div2,'click',function(){closeimg();});
	var _img = document.createElement('img');
	var _src = unescape(arguments[0]);
	_src = _src.replace(/[+]/g, ' ');
	_img.src=_src;
	_img.border=0;
	_img.setAttribute('title','Click para cerrar');
	_img.style.cursor='pointer';
	_img.style.width='700px';
	_img.style.height='500px';
	_div2.appendChild(_img);
	document.body.appendChild(_div);
	document.body.appendChild(_div2);
	initdiv();
}

function closeimg(){
	var _div = $('_divimgback');
	try{document.body.removeChild(_div)}
	catch(e){};
	_div = $('_divimgfront');
	try{document.body.removeChild(_div)}
	catch(e){};
}

function exportToExcel(){
	var oExcel = new ActiveXObject("Excel.Application");
	var oBook = oExcel.Workbooks.Add;
	var oSheet = oBook.Worksheets(1);
	for (var y=0;y<$(arguments[0]).rows.length;y++){
		for (var x=0;x<$(arguments[0]).rows(y).cells.length;x++){
			oSheet.Cells(y+1,x+1) = $(arguments[0]).rows(y).cells(x).innerText;
		}
	}
	oExcel.Visible = true;
	oExcel.UserControl = true;
}

var rqt;
var menin='', menpr, menurl;
var enProceso = false; // lo usamos para ver si hay un proceso activo

