<?php
/** 
* o------------------------------------------------------------------------------o
* | FUNCTION: setGridCombinaPrint  						| 02 de Octubre del 2011 |
* |------------------------------------------------------------------------------|
* | Desarrollado por	: Kenett R. Serrano Carranza							 |
* | Email				: ro_ken777sc@hotmail.com								 |
* | Definición			: Grid con columnas Combinadas y Agrupadas por Niveles	 |
* | 					  Para el formato de Impresion	 						 |
* o------------------------------------------------------------------------------o

* o------------------------------------------------------------------------------o
* | CLASE MYSQL, Conexion y Mantenimiento  				  | 01 de Abril del 2009 |
* |------------------------------------------------------------------------------|
* | Desarrollado por	: Kenett R. Serrano Carranza							 |
* | Email				: ro_ken777sc@hotmail.com								 |
* | Definición			: Clase para conectarse a una Base de Datos SQL o MySQL	 |
* o------------------------------------------------------------------------------o
* o------------------------------------------------------------------------------o
* | FUNCTION: setGridCombina  							| 18 de Octubre del 2010 |
* |------------------------------------------------------------------------------|
* | Desarrollado por	: Kenett R. Serrano Carranza							 |
* | Email				: ro_ken777sc@hotmail.com								 |
* | Definición			: Grid con columnas Combinadas y Agrupadas por Niveles	 |
* o------------------------------------------------------------------------------o
* o------------------------------------------------------------------------------o
* | FUNCTION: setTablaFormTabs 						  | 01 de Noviembre del 2010 |
* |------------------------------------------------------------------------------|
* | Desarrollado por	: Kenett R. Serrano Carranza							 |
* | Email				: ro_ken777sc@hotmail.com								 |
* | Definición			: Formulario agrupado en Tabs(Pestañas)					 |
* o------------------------------------------------------------------------------o
**/
class clsConexion {
/*
	var $strServidor;	//Direccion Ip o Nombre del Servidor
	var $strUsuario;	//Nombre del Usuario
	var $strClave;		//Clave
	var $strBD;			//Nombre de la Base de Datos
	var $link;			//Link de Conexion
	var $type;
*/
	protected $strServidor, $strUsuario, $strClave, $strBD, $type, $link;
	var $RutaImage = "../images/";
	var $BotDefault = "b_table.png";

	public function __construct($strServidor,$strUsuario,$strClave,$strBD,$type) {
		$this->strServidor 	= $strServidor;
		$this->strUsuario 	= $strUsuario;
		$this->strClave 	= $strClave;
		$this->strBD 		= $strBD;
		$this->type			= $type;
	 	}
	//function AbrirConexion
  	public function AbrirConexion() {  	
		//Establecemos la Conexion
		if (strtoupper($this->type)=="MYSQL") {
			$this->link = mysql_connect($this->strServidor, 
										$this->strUsuario,
										$this->strClave, false, 65536);	
			if(!mysql_select_db($this->strBD,$this->link))	{
				echo "ERROR SELECCIONANDO LA BASE DE DATOS : ".strtoupper($this->strBD)." EN ".strtoupper($this->strServidor);
				exit();
				}		
			}
		elseif (strtoupper($this->type)=="MYSQLI") {
			$this->link = mysqli_connect($this->strServidor, 
										$this->strUsuario,
										$this->strClave,
										$this->strBD);	
								
			if(!mysqli_select_db($this->strBD,$this->link))	{
				echo "ERROR SELECCIONANDO LA BASE DE DATOS : ".strtoupper($this->strBD)." EN ".strtoupper($this->strServidor);
				exit();
				}		
			
			}
			
		elseif (strtoupper($this->type)=="SQL") {
			$this->link = mssql_connect($this->strServidor, 
										$this->strUsuario, 
										$this->strClave);	
			if(!mssql_select_db($this->strBD,$this->link))	{
				echo "ERROR SELECCIONANDO LA BASE DE DATOS : ".strtoupper($this->strBD). "EN ".strtoupper($this->strServidor);
				exit();
				}
			}
		elseif (strtoupper($this->type)=="SQL2008") {
			$this->link = sqlsrv_connect($this->strServidor, 
										$this->strUsuario, 
										$this->strClave);	
			if(!sqlsrv_select_db($this->strBD,$this->link))	{
				echo "ERROR SELECCIONANDO LA BASE DE DATOS : ".strtoupper($this->strBD)."EN ".strtoupper($this->strServidor);
				exit();
				}
			}
		elseif (strtoupper($this->type)=="ORACLE" || strtoupper($this->type)=="OCI") {	
			if(ocilogon($this->strUsuario, 
									$this->strClave,
									$this->strServidor."/".$this->strBD
									))
				{
				$this->link = ocilogon(	$this->strUsuario, 
										$this->strClave,
										$this->strServidor."/".$this->strBD
										);
				}
//			else echo "ERROR SELECCIONANDO LA BASE DE DATOS :".$this->strBD." EN ".$this->strServidor;
			}
		else {
			echo "No selecciono el Tipo de Conexion: SQL o MySQL";
			exit;
			}	
		if(!($this->link))	{
				echo "ERROR CONECTANDO AL SERVIDOR : ".$this->strServidor;
				exit();
				}		
		return $this->link;	
		}
	//function CerrarConexion
	function CerrarConexion() {
		if(strtoupper($this->type)=="MYSQL") mysql_close($this->link);
		elseif(strtoupper($this->type)=="MYSQLI") mysqli_close($this->link);
		elseif(strtoupper($this->type)=="SQL") mssql_close($this->link);
		}
	function Begin() {
		mysql_query("BEGIN", $this->link);
		}

	function Rollback() {
		mysql_query("ROLLBACK", $this->link);
		}

	function Commit() {
		mysql_query("COMMIT", $this->link);
		}
		
	function Query($sql) {
		if($sql=="") return NULL;
		elseif(strtoupper($this->type)=="MYSQL") {
			if($rs = mysql_query($sql,$this->link)) return $rs;	
			else return mysql_error();
			}
		elseif(strtoupper($this->type)=="MYSQLI") {
			if($rs = mysqli_query($this->link, $sql)) return $rs;	
			else return mysqli_error();
			}
		elseif(strtoupper($this->type)=="SQL") {
			if($rs = mssql_query($sql,$this->link)) return $rs;
			else echo "ERROR AL PROCESAR: ".$sql;
			}
		}
		
	function FetchArray($rs) {
		if(strtoupper($this->type)=="MYSQL") return  mysql_fetch_array($rs);
		elseif(strtoupper($this->type)=="MYSQLI") return mysqli_fetch_array($rs);	
		elseif(strtoupper($this->type)=="SQL") return mssql_fetch_array($rs);
		}
	
	function NumFilas($rs) { 
		if(strtoupper($this->type)=="MYSQL") return mysql_num_rows($rs);	
		elseif(strtoupper($this->type)=="MYSQLI") return mysqli_num_rows($rs);
		elseif(strtoupper($this->type)=="SQL") return mssql_num_rows($rs);
		}
	
	function NumField($rs) { 
		if(strtoupper($this->type)=="MYSQL") return mysql_num_fields($rs);
		elseif(strtoupper($this->type)=="MYSQLI") return mysqli_num_fields($rs);
		elseif(strtoupper($this->type)=="SQL") return mssql_num_fields($rs); 
		}
		
	function FieldType($rs, $i) { 
		if(strtoupper($this->type)=="MYSQL") return mysql_field_type($rs, $i);	
		elseif(strtoupper($this->type)=="SQL") return mssql_field_type($rs, $i);
		}

	function FieldName($rs, $i) { 
		if(strtoupper($this->type)=="MYSQL") return mysql_field_name($rs, $i);	
		elseif(strtoupper($this->type)=="MYSQL") {
			 $finfo = mysqli_fetch_field_direct($rs, $i);
			 return $finfo->name;
			}
		elseif(strtoupper($this->type)=="SQL") return mssql_field_name($rs, $i);
		}
			
	function FieldLength($rs, $i) {
		if(strtoupper($this->type)=="MYSQL") return mysql_field_len($rs, $i);	
		elseif(strtoupper($this->type)=="SQL") return mssql_field_length($rs, $i);			
		}
		
	function LiberaMemoria($rs) { 
		if(strtoupper($this->type)=="MYSQL") return mysql_free_result($rs);
		elseif(strtoupper($this->type)=="MYSQLI") return mysqli_free_result($rs);
		elseif(strtoupper($this->type)=="SQL") return mssql_free_result($rs); 
		}
		
	function ErrorConsulta() {
		$tabla = "<table id=\"TableError\" ";
		$tabla.= "style=\"padding:0; margin-top:0px;border-collapse:collapse;\" "; 
		$tabla.= "width=350 align=center  cellpadding=0 cellspacing=0>";
		$tabla.= "<tr>";
		$tabla.= "<td height=19 colspan=2 align=center valign=middle class=\"FormTitulo\">";
		$tabla.= "ERROR AL REALIZAR CONSULTA...!!!!</th>";
		$tabla.= "</tr>";
		$tabla.= "<tr>";
		$tabla.= "<td height=35 colspan=2 valign=middle align=center class=interiorError>";
		$tabla.= "<b><BR>  LOS PARAMAETROS DE BUSQUEDA QUE INGRESO<BR>";
		$tabla.= "NO DEVOLVIERON DATOS<BR>";
		$tabla.= "SELECCIONE OTROS PARAMETROS Y VUELVA A INTENTARLO";
		$tabla.= "<br>O CONTACTESE CON EL ADMINISTRADOR DEL SISTEMA<BR>";
		$tabla.= "<br></b>";
		$tabla.= "</td>";
		$tabla.= "</tr>";
		$tabla.= "</table>";
		return $tabla;
		}
	
	function SetLista2($Nombre,  	//Nombre del Combo				  
					  $CadSql,		//Cadena de Consulta SQL
					  $Valor,		//Valor Seleccionado
					  $Ancho,		//Ancho del Combo
					  $Reload=NULL,	//Opcion de Recargar el Combo
					  $Titulo=NULL,	//Campo Titulo a Mostrar en el Combo
					  $Todos =NULL,	//Campo Seleccionar Totos
					  $SinCod=NULL,	//Muestra el Codigo en el Combo
					  $Locked=NULL,	//Bloquear el Combo
					  $Clase =NULL	//Stylo
					  ) {
		
		$this->AbrirConexion();
		if(isset($Reload) && $Reload<>"") $Reload=" onChange=\"$Reload\"";
		if(isset($Locked) && $Locked<>"" && $Locked=="SI") $Locked=" disabled";
		$varClass = (isset($Clase) && $Clase<>"")? " class='$Clase' " : " class='input' ";
		
		$combo = "<select name='$Nombre' id='$Nombre' size=\"5\" multiple=\"multiple\" $varClass $Reload ";
		$combo.= "style=\"width:".$Ancho."px; height:80px\" $Locked>";	
		if(isset($CadSql) && $CadSql<>"") {
			$rs = $this->Query($CadSql);
			while($row=$this->FetchArray($rs)) {
				if(isset($SinCod) && $SinCod<>"") $MiValor = strtoupper($row[1]);
				else $MiValor = $row[0]." - ".strtoupper($row[1]);
				$Selected="";
				if($row[0]==$Valor) $Selected="selected";
				$combo.= "<option value='$row[0]' ".$SinCod." - ".$Selected.">$MiValor</option>";
				}
			}
		$combo.= "</select>";
		$this->CerrarConexion();
		return $combo;
		}
	
	function setLista($jcamp) {
		$varCampo = "";
		if(isset($jcamp) && count($jcamp)>0) {
			$varCampo.="<select  ";
			$varCampo.= (isset($jcamp["id"]))?" id=\"".$jcamp["id"]."\" " : NULL;
			$varCampo.= (isset($jcamp["name"]))?" name=\"".$jcamp["name"]."\" " : NULL;
			$varCampo.= (isset($jcamp["filas"]) && $jcamp["filas"]<>"")?" size=\"".$jcamp["filas"]."\" " : " size=\"5\" ";			
			$varCampo.= "multiple=\"multiple\" ";
			$varCampo.= (isset($jcamp["clase"]))?" class=\"".$jcamp["clase"]."\" " : " class=\"input\" ";
			$varCampo.= (isset($jcamp["click"]))?" onclick=\"".$jcamp["click"]."\" " : NULL;
			$varCampo.= (isset($jcamp["dclick"]))?" onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
			$varCampo.= " style=\"";
			$varCampo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px;" : NULL;
			$varCampo.= (isset($jcamp["alto"]))?  " higth:".$jcamp["alto"]."px;" : NULL;
			$varCampo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
			$varCampo.= " \" ";
			$varCampo.= (isset($jcamp["locked"]) && $jcamp["locked"]=="SI")? " disabled " : NULL;
			$varCampo.=">";
			if(isset($jcamp["sql"]) && $jcamp["sql"]<>"") {
				$this->AbrirConexion();
				$rs = $this->Query($jcamp["sql"]);
				$this->CerrarConexion();
				while($row=$this->FetchArray($rs)) {
					if(isset($jcamp["sincod"]) && $jcamp["sincod"]=="SI") $MiValor = strtoupper($row[1]);
					else $MiValor = $row[0]." - ".strtoupper($row[1]);
					$Selected="";
					if($row[0]==$jcamp["valor"]) $Selected="selected";
					$varCampo.= "<option value='$row[0]' ".$Selected." >$MiValor</option>";
					}
				}
			$varCampo.= "</select>";
			return $varCampo;
			}
		}
	//function SetComboX
	function SetComboX($varCombo) {
		$varName = (isset($varCombo["name"]) && $varCombo["name"]<>"")?$varCombo["name"]:"comb";
		$varIde  = (isset($varCombo["id"]) && $varCombo["id"]<>"")?$varCombo["id"]:$varName;
		$varClas = (isset($varCombo["clase"]) && $varCombo["clase"]<>"")? "class='".$varCombo["clase"]."' " : "";
		$varLoad = (isset($varCombo["reload"]) && $varCombo["reload"]<>"")?"onChange=\"".$varCombo["reload"]."\" ":"";
		$varLock = (isset($varCombo["locked"]) && $varCombo["locked"]=="SI")?"disabled ":"";
		$varAnch = (isset($varCombo["ancho"]) && $varCombo["ancho"]<>"")?"width:".$varCombo["ancho"]."px":"";
		$varAlto = (isset($varCombo["alto"]) && $varCombo["alto"]<>"")?"height:".$varCombo["alto"]."px":"";
		$varReturn = "<select name='$varName' id='$varIde' $varClas $varLoad $varLock";
		$varReturn.= " style=\"$varAnch $varAlto\">";
		if(isset($varCombo["titulo"]) && $varCombo["titulo"]<>"") 
			$varReturn.= "<option value='Ninguno'>".strtoupper(html_entity_decode($varCombo["titulo"]))."</option>";
		//Detalle del Select
		if(isset($varCombo["sql"]) && $varCombo["sql"]<>"")  {
			$this->AbrirConexion();
			$rs = $this->Query($varCombo["sql"]);
			while($row=$this->FetchArray($rs)) {
				if(isset($varCombo["sincod"]) && $varCombo["sincod"]<>"") $MiValor = strtoupper($row[1]);
				else $MiValor = $row[0]." - ".strtoupper($row[1]);
				$Selected="";
				if(isset($varCombo["valor"]) && $row[0]==$varCombo["valor"]) $Selected="selected";
				$varReturn.= "<option value='$row[0]' ".$Selected.">$MiValor</option>";
				}
			$this->CerrarConexion();
			}
		$varReturn.= "</select>";
		return $varReturn;
		}
	//function SetCombo
	function SetCombo($Nombre,  	//Nombre del Combo				  
					  $CadSql,		//Cadena de Consulta SQL
					  $Valor,		//Valor Seleccionado
					  $Ancho,		//Ancho del Combo
					  $Reload=NULL,	//Opcion de Recargar el Combo
					  $Titulo=NULL,	//Campo Titulo a Mostrar en el Combo
					  $Todos =NULL,	//Campo Seleccionar Totos
					  $SinCod=NULL,	//Muestra el Codigo en el Combo
					  $Locked=NULL,	//Bloquear el Combo
					  $Clase =NULL	//Stylo
					  ) {
		if(isset($Reload) && $Reload<>"") $Reload=" onChange=\"$Reload\"";
		if(isset($Locked) && $Locked<>"" && $Locked=="SI") $Locked=" disabled";
		$varClass = (isset($Clase) && $Clase<>"")? " class='$Clase' " : " class='input' ";
		
		$combo = "<select name='$Nombre' id='$Nombre' $varClass $Reload ";
		$combo.= "style=\"width:".$Ancho."px; height:17px\" $Locked>";	
		//Opcion Titulo
		if(isset($Titulo)) 
			$combo.= "<option value='Ninguno'>".strtoupper(html_entity_decode($Titulo))."</option>";
		
		if(isset($CadSql) && $CadSql<>"") {
			$this->AbrirConexion();
			$rs = $this->Query($CadSql);
			while($row=$this->FetchArray($rs)) {
				if(isset($SinCod) && $SinCod<>"") $MiValor = strtoupper($row[1]);
				else $MiValor = $row[0]." - ".strtoupper($row[1]);
				$Selected="";
				if($row[0]==$Valor) $Selected="selected";
				$combo.= "<option value='$row[0]' ".$Selected.">".$MiValor."</option>";
				}
			$this->CerrarConexion();
			}
		//Opcion Todos
		$Selected="";
		if(isset($Todos)) {
			if($Valor=="Todos") $Selected="selected";
			$combo.= "<option value='Todos' $Selected>".strtoupper(html_entity_decode($Todos))."</option>";
			}
		$combo.= "</select>";
		
		return $combo;
		}	
	//function SetComboSimple
	function SetComboSimple ( 
		$Nombre,  		//Nombre del Combo				  
		$Array,			//Array Con Datos
		$Valor,			//Valor Seleccionado
		$Ancho,			//Ancho del Combo
		$Reload=NULL,	//Opcion de Recargar el Combo
		$Titulo=NULL,	//Campo Titulo a Mostrar en el Combo
		$Todos =NULL,	//Campo Seleccionar Totos
		$SinCod=NULL,	//Muestra el Codigo en el Combo
		$Locked=NULL	//Bloquear el Combo
		) {
		
		if(isset($Reload) && $Reload<>"") $Reload=" onChange=\"$Reload\"";
		if(isset($Locked) && $Locked=="SI") $Locked=" disabled";
		
		$combo = "<select name='$Nombre' id='$Nombre' class='input' $Reload ";
		$combo.= "style=\"width:".$Ancho."px; height:17px\" $Locked>";
		//Opcion Titulo
		if(isset($Titulo)) 
			$combo.= "<option value='Ninguno'>".strtoupper($Titulo)."</option>";		
		//Datos
		if(isset($Array)) {
			foreach ($Array as $CampoId=>$Campo) {
				$seleccionar="";	
				if(isset($SinCod) && $SinCod<>"") $MiValor = strtoupper($Campo);	
				else $MiValor = $CampoId." - ".strtoupper($Campo);
				
				if($CampoId==$Valor && isset($Valor)) $seleccionar="selected";
				$combo.= "<option value=".$CampoId." ".$seleccionar.">$MiValor</option>";
				}
			}
		//Opcion Todos
		$Selected="";
		if(isset($Todos)) {
			if($Valor=="Todos") $Selected="selected";
			$combo.= "<option value='Todos' $Selected>".strtoupper($Todos)."</option>";
			}
		$combo.= "</select>";
		return $combo;
		}	
	//function setCampos
	function setCampos($json) {
		$k = json_decode($json, true);
		$i = 0;
		while($i<count($k['contenido'])) {
			$Campo.=$this->SetCampo($k[contenido][$i]);
			$i++;
			}
		return $Campo;
		}
	//function setBotones
	function setBotones($json) {
		$k = json_decode($json, true);
		$i = 0;
		while($i<count($k['botones'])) {
			$Boton.=$this->SetBoton($k[botones][$i])."&nbsp;";
			$i++;
			}
		return $Boton;
		}
	//function setBoton		
	function setBoton($jcamp) {
		$Campo.= "<input ";
		$Campo.= (isset($jcamp["id"]))? 	" id=\"".$jcamp["id"]."\" " : NULL;
		$Campo.= (isset($jcamp["name"]))? 	" name=\"".$jcamp["name"]."\" " : NULL;
		$Campo.= (isset($jcamp["tipo"]))? 	" type=\"".$jcamp["tipo"]."\" " : "type=\"submit\" ";
		$Campo.= (isset($jcamp["texto"]))? 	" value=\"".$jcamp["texto"]."\" " : "value=\"\" ";
		$Campo.= (isset($jcamp["clase"]))? 	" class=\"".$jcamp["clase"]."\" " : NULL;
		$Campo.= (isset($jcamp["click"]))? 	" onclick=\"".$jcamp["click"]."\" " : NULL;	
		$Campo.= (isset($jcamp["toltip"]))? " onMouseOver=\"MensajeTip('".$jcamp["toltip"]."')\" onMouseOut=\"UnTip()\" ":NULL;
		$Campo.= " style=\"cursor:pointer;";
		$Campo.= (isset($jcamp["ancho"]))? 	" width:".$jcamp["ancho"]."px;" : NULL;
		$Campo.= (isset($jcamp["alto"]))? 	" height:".$jcamp["alto"]."px;" : NULL;
		$Campo.= "\"/>";
		return $Campo;
		}	
	//function setCampo
	function setCampo($jcamp) {
		$Campo = "";
		switch ($jcamp["tipo"]) {
			case "boton":
				$Campo.= "<input type=\"button\" ";
				$Campo.= (isset($jcamp["id"]))? 	" id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? 	" name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["texto"]))? 	" value=\"".$jcamp["texto"]."\" " : "value=\"\" ";
				$Campo.= (isset($jcamp["clase"]))? 	" class=\"".$jcamp["clase"]."\" " : NULL;
				$Campo.= (isset($jcamp["click"]))? 	" onclick=\"".$jcamp["click"]."\" " : NULL;	
				$Campo.= (isset($jcamp["toltip"]))? " onMouseOver=\"MensajeTip('".$jcamp["toltip"]."')\" onMouseOut=\"UnTip()\" ":NULL;
				$Campo.= " style=\"cursor:pointer;";
				$Campo.= (isset($jcamp["ancho"]))? 	" width:".$jcamp["ancho"]."px;" : NULL;
				$Campo.= (isset($jcamp["alto"]))? 	" height:".$jcamp["alto"]."px;" : NULL;
				$Campo.= "\"/>";
				break;
			case "imagen":
			case "image":
			case "img":
				$Campo.= "<img ";
				$Campo.= (isset($jcamp["id"]))? 	" id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? 	" name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["img"]))? " src=\"".$jcamp["img"]."\" " : "src=\"../images/b_error.png\" ";
				$Campo.= (isset($jcamp["ancho"]))? " width=\"".$jcamp["ancho"]."\" " : NULL;
				$Campo.= (isset($jcamp["alto"]))? "  height=\"".$jcamp["alto"]."\" " : NULL;
				$Campo.= (isset($jcamp["click"]))? " onclick=\"javascript:".$jcamp["click"]."\" " : NULL;	
				$Campo.= (isset($jcamp["toltip"]))? " onMouseOver=\"MensajeTip('".$jcamp["toltip"]."')\" onMouseOut=\"UnTip()\" ":NULL;
				$Campo.= " style=\"cursor:pointer\"/>";
				break;
			case "simple":
				$Campo.= (isset($jcamp["valor"]))? $jcamp["valor"] : NULL;
				break;
			case 'textarea':
			case 'area':
				$Campo.="<textarea ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]) && $jcamp["locked"]=="SI")? " disabled " : NULL;
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alto"]))?  " height:".$jcamp["alto"]."px; " : NULL;
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				$Campo.= " \" >";				
				$Campo.= (isset($jcamp["valor"]))? $jcamp["valor"]: NULL;
				$Campo.= "</textarea>";
				break;
			case 'texto': 
			case 'text' :
				$Campo.= "<input type=\"text\" ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]) && $jcamp["locked"]=="SI")? " readonly " : NULL;
				$Campo.= (isset($jcamp["bloqueado"]) && $jcamp["bloqueado"]=="SI")? " disabled " : NULL;
				$Campo.= (isset($jcamp["blur"]))? " onblur=\"".$jcamp["blur"]."\" " : NULL;
				$Campo.= (isset($jcamp["keyup"]))? " onkeyup=\"".$jcamp["keyup"]."\" " : NULL;
				$Campo.= (isset($jcamp["change"]))? " onchange=\"".$jcamp["change"]."\" " : NULL;
				$Campo.= (isset($jcamp["dclick"]))? " onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
				$Campo.= (isset($jcamp["keypress"]))? " onkeypress=\"".$jcamp["keypress"]."\" " : NULL;
				$Campo.= (isset($jcamp["maxchar"]))? " maxlength=\"".$jcamp["maxchar"]."\" " : NULL;	
				$Campo.= (isset($jcamp["clase"]) && $jcamp["clase"]<>"")? " class=\"".$jcamp["clase"]."\" ":"class=\"texto\" ";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alto"]))?  " height:".$jcamp["alto"]."px; " : " height:18px; ";
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				$Campo.= " \" autocomplete='off' >";
				break;
			case 'archivo': 
			case 'file' :
				$Campo.= "<input type=\"file\" ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]) && $jcamp["locked"]=="SI")? " readonly " : NULL;
				$Campo.= (isset($jcamp["bloqueado"]) && $jcamp["bloqueado"]=="SI")? " disabled " : NULL;
				$Campo.= (isset($jcamp["blur"]))? " onblur=\"".$jcamp["blur"]."\" " : NULL;
				$Campo.= (isset($jcamp["keyup"]))? " onkeyup=\"".$jcamp["keyup"]."\" " : NULL;
				$Campo.= (isset($jcamp["dclick"]))? " onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
				$Campo.= (isset($jcamp["keypress"]))? " onkeypress=\"".$jcamp["keypress"]."\" " : NULL;
				$Campo.= (isset($jcamp["maxchar"]))? " maxlength=\"".$jcamp["maxchar"]."\" " : NULL;	
				$Campo.= (isset($jcamp["clase"]) && $jcamp["clase"]<>"")? " class=\"".$jcamp["clase"]."\" ":"class=\"texto\" ";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alto"]))?  " height:".$jcamp["alto"]."px; " : " height:18px; ";
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				$Campo.= " \" autocomplete='off' >";
				break;
			case 'oculto':				
			case 'hidden':				
				$Campo.= "<input type=\"hidden\" ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]))? "readonly " : NULL;
				$Campo.= (isset($jcamp["blur"]))? " onblur=\"".$jcamp["blur"]."\" " : NULL;
				$Campo.= (isset($jcamp["keyup"]))? " onkeyup=\"".$jcamp["keyup"]."\" " : NULL;
				$Campo.= (isset($jcamp["dclick"]))? " onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
				$Campo.= (isset($jcamp["keypress"]))? " onkeypress=\"".$jcamp["keypress"]."\" " : NULL;
				$Campo.= (isset($jcamp["maxchar"]))? " maxlength=\"".$jcamp["maxchar"]."\" " : NULL;	
				$Campo.= (isset($jcamp["clase"]))?"class=\"".$jcamp["clase"]."\" ":"";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				$Campo.= " \" autocomplete='off' >";
				break;
			case 'clave':
			case 'pass':
			case 'password':
				$Campo.= "<input type=\"password\" ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]))? "readonly " : NULL;
				$Campo.= "class=\"texto\" ";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				$Campo.= " \" >";
				break;
			case 'select':
				$Campo.=$this->SetComboX($jcamp);						
				break;
			case 'lista':
				$varComboTodos = (isset($jcamp["combo"]["todos"]))?$jcamp["combo"]["todos"]:NULL;
				$Campo.=$this->SetLista((isset($jcamp["name"]))? $jcamp["name"] : NULL, 
										$jcamp["combo"]["sql"], 
										(isset($jcamp["valor"]))? $jcamp["valor"] : NULL,
										(isset($jcamp["combo"]["ancho"]))?$jcamp["combo"]["ancho"]:NULL,
										(isset($jcamp["combo"]["reload"]))?$jcamp["combo"]["reload"]:NULL,
										(isset($jcamp["combo"]["titulo"]))?$jcamp["combo"]["titulo"]:NULL,
										(isset($jcamp["combo"]["todos"]))?$jcamp["combo"]["todos"]:NULL,
										(isset($jcamp["combo"]["sincod"]))?$jcamp["combo"]["sincod"]:NULL,
										(isset($jcamp["combo"]["locked"]))?$jcamp["combo"]["locked"]:NULL,
										(isset($jcamp["combo"]["clase"]) && $jcamp["combo"]["clase"]<>"")?$jcamp["combo"]["clase"]:NULL
										);
				break;
			case "lista_doble":
				$Campo.= "<table>";
				$Campo.= "<tr>";
				$Campo.= "<td>";
				
				$varLista1 = array(	"id"	=> (isset($jcamp["id1"]))? $jcamp["id1"]:NULL, 
								  	"name"	=> (isset($jcamp["name1"]))? $jcamp["name1"]:NULL, 
								  	"sql"	=> (isset($jcamp["sql"]))? $jcamp["sql"] : NULL,
								  	"filas"	=> (isset($jcamp["filas"]))? $jcamp["filas"] : NULL, 
									"valor"	=> (isset($jcamp["valor"]))? $jcamp["valor"] : NULL,
									"ancho"	=> (isset($jcamp["ancho"]))?$jcamp["ancho"]:NULL,
									"alto"	=> (isset($jcamp["alto"]))?$jcamp["alto"]:NULL,
									"sincod"=> (isset($jcamp["sincod"]))?$jcamp["sincod"]:NULL,
									"clase"	=> (isset($jcamp["clase"]))?$jcamp["clase"]:NULL,
									"locked"=> (isset($jcamp["locked"]))?$jcamp["locked"]:NULL,
									"dclick"=> (isset($jcamp["dclick1"]))?$jcamp["dclick1"]:NULL
									);
				$Campo.= $this->setLista($varLista1);
				$Campo.= "</td>";
				$Campo.= "<td>";
				$Campo.="<input type=\"button\" value=\">>\" onclick=\"".$jcamp["dclick1"]."\">";
				$Campo.="<br><br><input type=\"button\" value=\"<<\"  onclick=\"".$jcamp["dclick2"]."\">";
				$Campo.= "</td>";
				$Campo.= "<td>";
				$varLista1 = array(	"id"	=> (isset($jcamp["id2"]))? $jcamp["id2"]:NULL, 
								  	"name"	=> (isset($jcamp["name2"]))? $jcamp["name2"]:NULL, 
								  	"filas"	=> (isset($jcamp["filas"]))? $jcamp["filas"] : NULL, 
									"valor"	=> (isset($jcamp["valor"]))? $jcamp["valor"] : NULL,
									"ancho"	=> (isset($jcamp["ancho"]))?$jcamp["ancho"]:NULL,
									"alto"	=> (isset($jcamp["alto"]))?$jcamp["alto"]:NULL,
									"sincod"=> (isset($jcamp["sincod"]))?$jcamp["sincod"]:NULL,
									"clase"	=> (isset($jcamp["clase"]))?$jcamp["clase"]:NULL,
									"locked"=> (isset($jcamp["locked"]))?$jcamp["locked"]:NULL,
									"dclick"=> (isset($jcamp["dclick2"]))?$jcamp["dclick2"]:NULL
									);
				$Campo.= $this->setLista($varLista1);
				$Campo.= "</td>";
				$Campo.= "</tr>";
				$Campo.= "</table>";
				break;
			case "fecha":
			case "date":
				$Campo.= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
				$Campo.= "<tr>";
				$Campo.= "<td ";
				$Campo.= (isset($jcamp["ancho"]))? " width=\"".($jcamp["ancho"]+10)."\" " : NULL;
				$Campo.= "valign=\"middle\">";
				$Campo.= "<input type=\"text\" autocomplete='off' ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]))? "readonly " : NULL;
				$Campo.= (isset($jcamp["blur"]))? " onblur=\"".$jcamp["blur"]."\" " : NULL;
				$Campo.= (isset($jcamp["dclick"]))? " onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
				$Campo.= (isset($jcamp["keypress"]))? " onkeypress=\"".$jcamp["keypress"]."\" " : NULL;	
				$Campo.= (isset($jcamp["clase"]) && $jcamp["clase"]<>"")? " class=\"".$jcamp["clase"]."\" ":"class=\"texto\" ";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : "width:100px; ";
				$Campo.= (isset($jcamp["alto"]))? " height:".$jcamp["alto"]."px; " : "height:18px; ";
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				
				$Campo.= " \" >";
				$Campo.= "</td>";
				$Campo.= "<td align=\"left\" valign=\"middle\">";
				$Campo.= "&nbsp;&nbsp;<img id=\"imgfech\" name=\"imgfech\" class=\"PopcalTrigger\" style=\"cursor:pointer\" src=\"".$this->RutaImage."/16x16/calendar.png\" ";
				$Campo.= "width=16 height=16 border=0 ";
				$Campo.= "onClick=\"if(self.gfPop)gfPop.fPopCalendar(";
				$Campo.= (isset($jcamp["name"]))?"document.getElementById('".$jcamp["name"]."')": NULL;
				$Campo.= ");return false;\" >";
				//$Campo.= ">";
				$Campo.= "</td>";
				if (!isset($jcamp["ayuda"]) || $jcamp["ayuda"]<>"NO") {
				$Campo.= "<td valign=\"middle\">";
				$Campo.= "&nbsp;&nbsp;(Ej. ".date("d/m/Y",time()).")";
				$Campo.= "</td>";
					}
				$Campo.= "</tr>";
				$Campo.= "</table>";
				break;
			
			case "fecha2":
			case "date2":
				$Campo.= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
				$Campo.= "<tr>";
				$Campo.= "<td ";
				$Campo.= (isset($jcamp["ancho"]))? " width=\"".($jcamp["ancho"]+10)."\" " : NULL;
				$Campo.= "valign=\"middle\">";
				$Campo.= "<input type=\"text\" autocomplete='off' ";
				$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
				$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : NULL;
				$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : NULL;
				$Campo.= (isset($jcamp["locked"]))? "readonly " : NULL;
				$Campo.= (isset($jcamp["blur"]))? " onblur=\"".$jcamp["blur"]."\" " : NULL;
				$Campo.= (isset($jcamp["dclick"]))? " onDblClick=\"".$jcamp["dclick"]."\" " : NULL;	
				$Campo.= (isset($jcamp["keypress"]))? " onkeypress=\"".$jcamp["keypress"]."\" " : NULL;	
				$Campo.= (isset($jcamp["clase"]) && $jcamp["clase"]<>"")? " class=\"".$jcamp["clase"]."\" ":"class=\"texto\" ";
				$Campo.= " style=\"";
				$Campo.= (isset($jcamp["ancho"]))? " width:".$jcamp["ancho"]."px; " : NULL;
				$Campo.= (isset($jcamp["alinear"]))? "text-align:".$jcamp["alinear"] : NULL;
				
				$Campo.= " \" >";
				$Campo.= "</td>";
				$Campo.= "<td align=\"left\" valign=\"middle\">";
				$Campo.= "&nbsp;&nbsp;<img id=\"imgfech\" name=\"imgfech\" class=\"ui-datepicker-trigger\" style=\"cursor:pointer\" src=\"../images/b_calendario.gif\" ";
				$Campo.= "width=34 height=22 border=0 >";
				//$Campo.= ">";
				$Campo.= "</td>";
				$Campo.= "<td valign=\"middle\">";
				$Campo.= "&nbsp;&nbsp;(Ej. ".date("d/m/Y",time()).")";
				$Campo.= "</td>";
				$Campo.= "</tr>";
				$Campo.= "</table>";
				break;
				
			case 'select_simple':
				$Campo.=$this->SetComboSimple($jcamp["name"], 
											  $jcamp["combo"]["sql"], 
											  $jcamp["valor"], 
											  (isset($jcamp["combo"]["ancho"]))?$jcamp["combo"]["ancho"]:NULL,
											  (isset($jcamp["combo"]["reload"]))?$jcamp["combo"]["reload"]:NULL,
											  (isset($jcamp["combo"]["titulo"]))?$jcamp["combo"]["titulo"]:NULL,
											  (isset($jcamp["combo"]["todos"]))?$jcamp["combo"]["todos"]:NULL,
											  (isset($jcamp["combo"]["sincod"]))?$jcamp["combo"]["sincod"]:NULL,
											  (isset($jcamp["combo"]["locked"]))?$jcamp["combo"]["locked"]:NULL
											  );
				break;	
			case 'varios':
				$i = 0;
				$Campo.= "<table><tr>";
				while($i<count($jcamp["contenido"])) {
					$Campo.= "<td";
					$Campo.= (isset($jcamp["contenido"][$i]["clase_in"]))?" class = \"".$jcamp["contenido"][$i]["clase_in"]."\" ":NULL;
					$Campo.= (isset($jcamp["contenido"][$i]["ancho"]))?" width = \"".$jcamp["contenido"][$i]["ancho"]."\" ":NULL;
					$Campo.= ">";
					$Campo.= (isset($jcamp["contenido"][$i]["div"]))?"<div id=\"".$jcamp["contenido"][$i]["div"]."\">":"";
					$Campo.= $this->SetCampo($jcamp["contenido"][$i]);
					$Campo.= (isset($jcamp["contenido"][$i]["div"]))?"</div>":"";
					$Campo.= "</td>";
					$i++;
					}
				$Campo.= "</tr></table>";
				break;
			case "tabla":
				$i = 0;
				$Campo.= "<table>";
				while($i<count($jcamp["contenido"])) {
					$Campo.= "<tr>";
					$Campo.= "<td>";
					$Campo.= (isset($jcamp["contenido"][$i]["div"]))?"<div id=\"".$jcamp["contenido"][$i]["div"]."\">":"";
					$Campo.= $this->SetCampo($jcamp["contenido"][$i]);
					$Campo.= (isset($jcamp["contenido"][$i]["div"]))?"</div>":"";
					$Campo.= "</td>";
					$Campo.= "</tr>";
					$i++;
					}
				$Campo.= "</table>";
				break;
			case "multiple":
			case "multi":
				if (isset($jcamp["sql"]) && $jcamp["sql"]<>"") {					
					$Campo.= "<table id=\"tabla\" width=\"100%\" cellspacing=0 cellpadding=0 align=\"center\" ";
					$Campo.= "style=\"padding:0;margin-top:0px;border-collapse:collapse;\">";
					$this->AbrirConexion();
					$rs = $this->Query($jcamp["sql"]);
					$this->CerrarConexion();
					while($fila = $this->FetchArray($rs)) {
						$Campo.="<tr>";						
						$Campo.="<td width=\"100\" nowrap=\"nowrap\"><b>";
						$Campo.= $fila[0]." - ".$fila[1]; 
						$Campo.="</b></td>";
						$Campo.="<td class=\"interior\">"; 
						$Campo.= $fila[1];
						$Campo.="</td>";
						$Campo.="</tr>"; 
						}					 
					$Campo.="</table>";
					}
				break;
			case "check":
				if (isset($jcamp["sql"]) && $jcamp["sql"]<>"") {					
					$Campo.= "<table width=\"100%\" border=0 cellpadding=0 cellspacing=0>";
					$this->AbrirConexion();
					$rs = $this->Query($jcamp["sql"]);
					$this->CerrarConexion();
					while($fila = $this->FetchArray($rs)) {
						$Campo.="<tr>";
						$Campo.="<td width=\"20\" height=\"18\" align=\"center\" valign=\"middle\">";						
						$varPos = $_POST[$jcamp["name"]][$fila[0]];
						$Campo.="<input ";
						$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
						$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."[".$fila[0]."]\" " : NULL;
						$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : " value=\"".$fila[0]."\" ";
						$Campo.= (isset($jcamp["checked"]) && $jcamp["checked"]=="SI")? " checked " : NULL;
						$Campo.= (isset($varPos))? " checked " : NULL;
						$Campo.=" type=\"checkbox\" >";
						$Campo.="</td>";
						$Campo.="<td width=\"100%\" valign=\"middle\">&nbsp;";
						$Campo.=$fila[0]." - ".$fila[1];
						$Campo.="</td>";
						$Campo.="</tr>";  
						}
					$Campo.="<tr>";
					$Campo.="<td width=\"20\" height=\"18\" align=\"center\" valign=\"middle\">";
					$Campo.="<input ";
					$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : NULL;
					$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."[Todos]\" " : NULL;
					$Campo.= " type=\"checkbox\" value=\"Todos\" ";
					$varPos = $_POST[$jcamp["name"]]["Todos"];
					$Campo.= (isset($varPos))? " checked " : NULL;
					$Campo.="/>";    
					$Campo.="</td>";
					$Campo.="<td width=\"100%\" valign=\"middle\">&nbsp;";
					$Campo.="Todos - TODOS LOS ANTERIORES";
					$Campo.="</td>";
					$Campo.="</tr>";  
					$Campo.="</table>";
					}
				else {
					$Campo.="<input ";
					$Campo.= (isset($jcamp["id"]))? " id=\"".$jcamp["id"]."\" " : "";
					$Campo.= (isset($jcamp["name"]))? " name=\"".$jcamp["name"]."\" " : "";
					$Campo.= (isset($jcamp["valor"]))? " value=\"".$jcamp["valor"]."\" " : "";
					$Campo.= (isset($jcamp["checked"]) && $jcamp["checked"]=="SI")? " checked " : "";
					$Campo.=" type=\"checkbox\" >";
					}
				break;
			}
		return $Campo;
		}
	//function setTablaForm
	function setTablaForm($varTable) {
		$Form = "";
		//Creamos la Cabecera del Formulario si Existe
		if(isset($varTable["formu"]) && count($varTable["formu"])>0) {
			$Form.= "<form ";
			$Form.= (isset($varTable["formu"]["id"]))? "id=\"".$varTable["formu"]["id"]."\" ":"";
			$Form.= (isset($varTable["formu"]["name"]))? "name=\"".$varTable["formu"]["name"]."\" ":"";
			$Form.= (isset($varTable["formu"]["metodo"]))?"method=\"".$varTable["formu"]["metodo"]."\" ":"";
			$Form.= (isset($varTable["formu"]["accion"]))?"action=\"".$varTable["formu"]["accion"]."\" ":"";
			$Form.= (isset($varTable["formu"]["onsubmit"]))?"onSubmit=\"".$varTable["formu"]["onsubmit"]."\" ":"";
			$Form.= (isset($varTable["formu"]["encripta"]) && $varTable["formu"]["encripta"]=="SI")?"enctype=\"multipart/form-data\" ":"";
			$Form.= ">";			
			}		
		//Cuerpo de la Tabla		
		$Form.= "<table style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$Form.= (isset($varTable["id"]))? "id=\"".$varTable["id"]."\" ":"";
		$Form.= (isset($varTable["name"]))? "name=\"".$varTable["name"]."\" ":"";
		$Form.= (isset($varTable["tamano"]))?"width=\"".$varTable["tamano"]."\" ":"";
		$Form.= "align=\"center\"  cellpadding=\"0\" cellspacing=\"0\">";
		// Si no Existe Contenido y no Existe Titulo no mostramos la fila de Titulo de Tabla
		if(count($varTable["titulo"])>0 || isset($varTable["titulo"])) {
		
			$Form.="<tr>";		
			$Form.="<td height=30 colspan=2 align=center valign=middle ";
			$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
			$Form.=">";
			$Form.= (isset($varTable["titulo"]))?$varTable["titulo"]:"SIN TITULO";
			//Contenido Campos Ocultos
			if(isset($varTable["ocult"]) && count($varTable["ocult"])>0) {
				foreach($varTable["ocult"] as $varCampo) {			
					if(isset($varCampo)) {
						$Form.= $this->SetCampo($varCampo);
						}
					}
				}
			$Form.="</td>";
			$Form.="</tr>";	
			}
		//Contenido Campos de la Tabla
		if(isset($varTable["conte"]) && count($varTable["conte"])>0) {
			foreach($varTable["conte"] as $varCampo) {
				if(isset($varCampo["tipo"]) && $varCampo["tipo"]=="titulo") {
					$Form.="<tr>";		
					$Form.="<td height=\"30\" colspan=2 align=center valign=middle ";
					$Form.= (isset($varCampo["clase"]))?"class=\"".$varCampo["clase"]."\" ":"";
					$Form.=">";
					$Form.= (isset($varCampo["titulo"]))?$varCampo["titulo"]:"SIN TITULO";
					$Form.="</td>";
					$Form.="</tr>";	
					}
				else {
					$Form.= "<tr><td ";
					$Form.= (isset($varCampo["tamano"]))?"width=\"".$varCampo["tamano"]."\" ":"";
					$Form.= (isset($varCampo["clase1"]))?"class=\"".$varCampo["clase1"]."\" ":"";		
					$Form.= ">";
					$Form.= (isset($varCampo["titulo"]))?$varCampo["titulo"]:"Sin Titulo";
					$Form.="</td><td ";
					$Form.= (isset($varCampo["clase2"]))?"class=\"".$varCampo["clase2"]."\" ":"";
					$Form.= ">";
					$Form.= (isset($varCampo["div"]))?"<div id=\"".$varCampo["div"]."\">":"";
					if(isset($varCampo["campo"])) {
						$Form.= $this->SetCampo($varCampo["campo"]);
						}
					elseif(isset($varCampo["texto"]) && $varCampo["texto"]<>"") {
						$Form.= $varCampo["texto"];
						}		
					$Form.= (isset($varCampo["div"]))?"</div>":"";			
					$Form.="</td>";
					$Form.="</tr>";
					}
				}
			}
		//Lista de Botones
		if(isset($varTable["boton"]) && count($varTable["boton"])>0) {
			$Form.= "<tr>";		
			$Form.= "<td height=\"35\" colspan=2 align=center valign=middle ";
			$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
			$Form.= ">";		
			foreach($varTable["boton"] as $varBoton) {
				$Form.=$this->SetBoton($varBoton)."&nbsp;";
				}
			$Form.="</td>";
			$Form.="<tr>";
			}	
		$Form.="</table>";
		
		//Creamos el Pie del Formulario si Existe
		if(isset($varTable["formu"]) && count($varTable["formu"])>0) {
			$Form.= "</form>";
			}
		return $Form;
		}
	
	function setTablaFormTabs($varForm, $varTable, $varTabs) {
		$Form = "";
		//Creamos la Cabecera del Formulario si Existe
		if(isset($varForm) && count($varForm)>0) {
			$Form.= "<form ";
			$Form.= (isset($varForm["id"]))? "id=\"".$varForm["id"]."\" ":"";
			$Form.= (isset($varForm["name"]))? "name=\"".$varForm["name"]."\" ":"";
			$Form.= (isset($varForm["metodo"]))?"method=\"".$varForm["metodo"]."\" ":"";
			$Form.= (isset($varForm["accion"]))?"action=\"".$varForm["accion"]."\" ":"";
			$Form.= (isset($varForm["onsubmit"]))?"onSubmit=\"".$varForm["onsubmit"]."\" ":"";
			$Form.= ">";			
			}
		if(isset($varTable) && count($varTable)>0) {	
			$Form.= $this->setTablaForm($varTable);
			}
		if(isset($varTabs) && count($varTabs)>0) {
			$Form.= "<table align=\"center\">";
			$Form.= "<tr>";
			$Form.= "<td>";
			$Form.= "<div id=\"TabbedPanels1\" class=\"TabbedPanels\">";
		  	$Form.= "<ul class=\"TabbedPanelsTabGroup\">";			
			/*Cabecera de los Tabs*/
			foreach($varTabs as $varCampo) {
				if (count($varCampo["tabla"])>0) {
					$Form.="<li class=\"TabbedPanelsTab\" tabindex=\"0\">";
					$Form.= (isset($varTable["name"]))? $varCampo["name"]:"Sin Nombre";
					$Form.="</li>";
					}
				}
			$Form.= "</ul>";
			$Form.= "<div class=\"TabbedPanelsContentGroup\">";
			/*Contenido de los Tabs*/
			foreach($varTabs as $varCampo) {
				if (count($varCampo["tabla"])>0) {
					$Form.="<div class=\"TabbedPanelsContent\" class=\"interiorForm\" style=\"";
					//$Form.= (isset($varCampo["alto"]))?  "height:".$varCampo["alto"]."px; ": NULL;
					$Form.= (isset($varCampo["ancho"]))?  "width:".$varCampo["ancho"]."px; ": NULL;
					$Form.="\">";
					if($varCampo["tipo"]=="form") {
						$Form.= $this->setTablaForm($varCampo["tabla"]);
						}
					elseif($varCampo["tipo"]=="det") {
						$Form.= $this->setTablaFormDet($varCampo["tabla"]);
						}
					else {
						$Form.= (isset($varTable["name"]))? $varCampo["name"]:"Sin Nombre";
						}
					$Form.="</div>";
					}
				}			
			$Form.= "</div>";
			$Form.= "</div>";
			$Form.= "</td>";
			$Form.= "</tr>";
			$Form.= "</table>";
			}
		//Creamos el Pie del Formulario si Existe
		if(isset($varForm) && count($varForm)>0) {
			$Form.= "</form>";
			}
		return $Form;
		}
	//function setTablaFormDet
	function setTablaFormDet($varTable) {	
		$varComb = count($varTable["conte"]);		
		
		//Cuerpo de la Tabla				
		$Form.= "<table style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$Form.= (isset($varTable["id"]))? "id=\"".$varTable["id"]."\" ":"";
		$Form.= (isset($varTable["name"]))? "name=\"".$varTable["name"]."\" ":"";
		$Form.= (isset($varTable["tamano"]))?"width=\"".$varTable["tamano"]."\" ":"";
		$Form.= "align=\"center\"  cellpadding=\"0\" cellspacing=\"0\">";		
		$Form.= "<thead>";	
		$Form.="<tr>";		
		$Form.="<td height=\"30\" colspan=$varComb align=center valign=middle ";
		$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
		$Form.=">";
		$Form.= (isset($varTable["titulo"]))?$varTable["titulo"]:"SIN TITULO";
		
		//Contenido Campos Ocultos
		if(isset($varTable["oculto"]) && count($varTable["oculto"])>0) {
			foreach($varTable["oculto"] as $varCampo) {			
				if(isset($varCampo)) {					
					$Form.= $this->SetCampo($varCampo);
					}
				}
			}
		if(isset($varTable["ocult"]) && count($varTable["ocult"])>0) {
			foreach($varTable["ocult"] as $varCampo) {			
				if(isset($varCampo)) {					
					$Form.= $this->SetCampo($varCampo);
					}
				}
			}
		$Form.="</td>";
		$Form.="</tr>";		
		
		//Contenido Cabecera de la Tabla		
		if(isset($varTable["conte"]) && count($varTable["conte"])>0) {						
			$Form.= "<tr>";
			foreach($varTable["conte"] as $varCampo) {
				if(!isset($varCampo["oculto"]) || $varCampo["oculto"]=="NO") {
					$Form.= "<td ";
					$Form.= (isset($varCampo["tamano"]))?"width=\"".$varCampo["tamano"]."\" ":"";
					$Form.= (isset($varCampo["alto"]))?"height=\"".$varCampo["alto"]."\" ":"";
					$Form.= (isset($varCampo["clase"]))?"class=\"".$varCampo["clase"]."\" ":"";		
					$Form.= ">";
					$Form.= (isset($varCampo["titulo"]))?$varCampo["titulo"]:"Sin Titulo";						
					$Form.="</td>";	
					}
				}
			$Form.="</tr>";			
			}
		$Form.= "</thead>";	
		
		//Contenido Detalle de la Tabla	
		if(isset($varTable["sql"]) && count($varTable["sql"])>0) {
			$this->AbrirConexion();
			$rs = $this->Query($varTable["sql"]);
			$this->CerrarConexion();
			$NumCol =  $this->NumField($rs);
			$j=0;
			$Form.= "<tbody>";
			$varPos=0;
			while($fila = $this->FetchArray($rs)) {
				$j++;
				$varPos=$varPos+1;
				$varChecke = (isset($varTable["conte"][0]["campo"]["id_check"]))? $fila[$varTable["conte"][0]["campo"]["id_check"]]:NULL;
				$varMarcar = (isset($varChecke) &&  $varChecke=="SI")?"marked":"";
				if($j%2==0) $Form.= "<tr class=\"par $varMarcar\">";
				else $Form.= "<tr class=\"impar $varMarcar\">";				
				for ($i=0;$i<=$NumCol-1;$i++) {	
					if(!isset($varTable["conte"][$i]["oculto"]) || $varTable["conte"][$i]["oculto"]=="NO") {
						$Form.= "<td class=\"interior\" height=\"22\" ";
						if(isset($varTable["conte"][$i]["alinear"])) $Form.="align=".$varTable["conte"][$i]["alinear"];
						if(isset($varTable["conte"][$i]["fijo"])) $Form.=" nowrap=\"nowrap\" ";
						$Form.= ">";										
						if(isset($varTable["conte"][$i]["campo"]) && count($varTable["conte"][$i]["campo"])>=1) {						
							//Funcion Doble Click
							$icon = 0;
							$varDClick="";
							if(count($varTable["conte"][$i]["campo"]["dclick"])>1) {
								foreach($varTable["conte"][$i]["campo"]["dclick"] as $valor=>$ArrayDClick) {
									if($valor=="funcion") {
										$varDClick.= $ArrayDClick."(";
										}
									else {
										foreach($ArrayDClick as $varCampo) {
											if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="IN") {
												if ($icon==0)
													$varDClick.= "'".$varCampo["campo"]."'";
												else
													$varDClick.= ",'".$varCampo["campo"]."'";
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX") {
												if ($icon==0)
													$varDClick.= "'".$varPos."'";
												else
													$varDClick.= ",'".$varPos."'";
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM") {
												if ($icon==0)
													$varDClick.= $varCampo["campo"];
												else
													$varDClick.= ",".$varCampo["campo"];
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEXTO") {
												if ($icon==0)
													$varDClick.= "'".$varCampo["campo"]."'";
												else
													$varDClick.= ",'".$varCampo["campo"]."'";
												}
											else
												if ($icon==0)
													$varDClick.= "'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
												else
													$varDClick.= ",'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
											$icon++;
											}									
										}
									
									}
								$varDClick.= ")";
								}
							else {
								$varDClick = $varTable["conte"][$i]["campo"]["dclick"];
								}
							
							//Funcion BLUR
							$icon = 0;
							$varBlur="";
							if(count($varTable["conte"][$i]["campo"]["blur"])>1) {
								foreach($varTable["conte"][$i]["campo"]["blur"] as $valor=>$ArrayBlur) {
									if($valor=="funcion") {
										$varBlur.= $ArrayBlur."(";
										}
									else {
										foreach($ArrayBlur as $varCampo) {
											if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="IN") {
												if ($icon==0)
													$varBlur.= "'".$varCampo["campo"]."'";
												else
													$varBlur.= ",'".$varCampo["campo"]."'";
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM") {
												if ($icon==0)
													$varBlur.= $varCampo["campo"];
												else
													$varBlur.= ",".$varCampo["campo"];
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX") {
												if ($icon==0)
													$varBlur.= "'".$varPos."'";
												else
													$varBlur.= ",'".$varPos."'";
												}
											else
												if ($icon==0)
													$varBlur.= "'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
												else
													$varBlur.= ",'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
											$icon++;
											}									
										}
									
									}
								$varBlur.= ")";
								}
							else {
								$varBlur = $varTable["conte"][$i]["campo"]["blur"];
								}
							
							//Funcion Key UP
							$icon = 0;
							$varKeyUp="";
							if(count($varTable["conte"][$i]["campo"]["keyup"])>1) {
								foreach($varTable["conte"][$i]["campo"]["keyup"] as $valor=>$ArrayKeyUp) {
									if($valor=="funcion") {
										$varKeyUp.= $ArrayKeyUp."(";
										}
									else {
										foreach($ArrayKeyUp as $varCampo) {
											if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="IN") {
												if ($icon==0)
													$varKeyUp.= "'".$varCampo["campo"]."'";
												else
													$varKeyUp.= ",'".$varCampo["campo"]."'";
												}
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX") {
												if ($icon==0)
													$varKeyUp.= "'".$varPos."'";
												else
													$varKeyUp.= ",'".$varPos."'";
												}
											else
												if ($icon==0)
													$varKeyUp.= "'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
												else
													$varKeyUp.= ",'".$varTable["conte"][$varCampo["campo"]]["campo"]["id"].$varPos."'";
											$icon++;
											}									
										}
									
									}
								$varKeyUp.= ")";
								}
							else {
								$varKeyUp = $varTable["conte"][$i]["campo"]["keyup"];
								}
							$varTipoDato = (isset($varTable["conte"][$i]["tipodat"]))? $varTable["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
							$varNumDec   = (isset($varTable["conte"][$i]["decimal"]))? $varTable["conte"][$i]["decimal"]:NULL;
							//17/07/2012 Para controlar el id_value
							//20/11/2013 Controlamos si existen diferentes id_value en el array
							if(count($varTable["conte"][$i]["campo"]["id_value"])>1) {
								$varValorTmp = "";
								foreach($varTable["conte"][$i]["campo"]["id_value"] as $varIdValue) {
									$varValorTmp.= ($varValorTmp=="")?$fila[$varIdValue]:",".$fila[$varIdValue];
									}
								$varValor = $varValorTmp;
								}
							else {
								$varIndex = (isset($varTable["conte"][$i]["campo"]["id_value"]))?$varTable["conte"][$i]["campo"]["id_value"]:$i;
								$varValor = ($varTable["conte"][$i]["campo"]["tipo"]<>"check")?$this->setFormatTipoDato($fila[$i], $varTipoDato, $varNumDec):$fila[$varIndex];
								}
							$varCheck = (isset($varTable["conte"][$i]["campo"]["id_check"]))? $fila[$varTable["conte"][$i]["campo"]["id_check"]]:NULL;
							
							//Reemplazamos variables del SQL
							$varSql = $varTable["conte"][$i]["campo"]["sql"];
							if(isset($varTable["conte"][$i]["campo"]["var"]) && count($varTable["conte"][$i]["campo"]["var"])>0) {
								foreach($varTable["conte"][$i]["campo"]["var"] as $varVarNom=>$varVarVal) {
									$varVal = $fila[$varVarVal];
									$varSql = str_replace($varVarNom, $varVal, $varSql);									
									//$Form.= $varVarNom.$varVal;
									}
								}
							$varIdeTemp = "";
							if(isset($varTable["conte"][$i]["campo"]["id_in"])) {
								$varIdeTemp = $varTable["conte"][$i]["campo"]["id"]."[".$fila[$varTable["conte"][$i]["campo"]["name_in"]]."]";
								}
							else {
								$varIdeTemp = $varTable["conte"][$i]["campo"]["id"].$varPos;
								}
								
							$varNamTemp = "";
							if(isset($varTable["conte"][$i]["campo"]["name_in"])) {
								$varNamTemp.= $varTable["conte"][$i]["campo"]["name"]."[".$fila[$varTable["conte"][$i]["campo"]["name_in"]]."]";
								}
							else {
								$varNamTemp = $varTable["conte"][$i]["campo"]["name"]."[]";
								}
							
							$varCampo = array("tipo"	=>$varTable["conte"][$i]["campo"]["tipo"], 
											  "id"		=>$varIdeTemp,
											  "name"	=>$varNamTemp, 										  
											  "locked"	=>$varTable["conte"][$i]["campo"]["locked"],
											  "clase"	=>$varTable["conte"][$i]["campo"]["clase"], 
											  "img"		=>$varTable["conte"][$i]["campo"]["img"], 
											  "click"	=>$varTable["conte"][$i]["campo"]["click"],
											  "titulo"	=>$varTable["conte"][$i]["campo"]["titulo"],
											  "sincod"	=>$varTable["conte"][$i]["campo"]["sincod"], 
											  "keypress"=>$varTable["conte"][$i]["campo"]["keypress"], 
											  "ancho"	=>$varTable["conte"][$i]["campo"]["ancho"],
											  "alinear"	=>$varTable["conte"][$i]["campo"]["alinear"],
											  "checked"	=>$varCheck, 
											  "dclick"	=>$varDClick, 
											  "blur"	=>$varBlur, 
											  "keyup"	=>$varKeyUp,											  
											  "valor"	=>$varValor,
											  "sql"		=>$varSql);
							$Form.=	$this->SetCampo($varCampo);
							
							}
						else {
							$varTipoDato = (isset($varTable["conte"][$i]["tipodat"]))? $varTable["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
							$varNumDec   = (isset($varTable["conte"][$i]["decimal"]))? $varTable["conte"][$i]["decimal"]:NULL;
							$Form.= $this->setFormatTipoDato($fila[$i], $varTipoDato, $varNumDec);							
							}
						$Form.="</td>";	
						}
					}
				$Form.="</tr>";
				}
			$Form.= "</tbody>";
			}
		//Lista de Botones
		if(isset($varTable["boton"]) && count($varTable["boton"])>0) {
			$Form.= "<tr>";		
			$Form.= "<td height=20 colspan=$varComb align=center valign=middle ";
			$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
			$Form.= ">";		
			foreach($varTable["boton"] as $varBoton) {
				$Form.=$this->SetBoton($varBoton)."&nbsp;";
				}
			$Form.="</td>";
			$Form.="<tr>";
			}	
		$Form.="</table>";
		return $Form;
		}
	//function setFormulario			
	function setFormulario(
		$varForm	  = NULL, //Parametros de Formulario,
		$varTable	  = NULL, //Parametros de la Tabla
		$varContenido = NULL, //Parametros del Contenido
		$varBotones   = NULL, //Parametros de los Botones
		$varOculto    = NULL  //Parametros de los Campos Ocultos
		) {
		//Formulario
		$Form = "<form ";
		$Form.= (isset($varForm["id"]))? "id=\"".$varForm["id"]."\" ":"";
		$Form.= (isset($varForm["name"]))? "name=\"".$varForm["name"]."\" ":"";
		$Form.= (isset($varForm["metodo"]))?"method=\"".$varForm["metodo"]."\" ":"";
		$Form.= (isset($varForm["accion"]))?"action=\"".$varForm["accion"]."\" ":"";
		$Form.= (isset($varForm["onsubmit"]))?"onSubmit=\"".$varForm["onsubmit"]."\" ":"";
		$Form.= ">";
		//Tabla		
		$Form.= "<table id=\"tabla\" style=\"padding: 0; margin-top:0px;border-collapse:collapse;\" ";		
		$Form.= (isset($varTable["tamano"]))?"width=\"".$varTable["tamano"]."\" ":"";
		$Form.= "align=\"center\"  cellpadding=\"0\" cellspacing=\"0\">";
		$Form.="<tr>";		
		$Form.="<td height=18 colspan=2 align=center valign=middle ";
		$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
		$Form.=">";
		$Form.= (isset($varTable["titulo"]))?$varTable["titulo"]:"SIN TITULO";
		//Contenido Campos Ocultos
		if(isset($varOculto)) {
			foreach($varOculto as $varCampo) {			
				if(isset($varCampo)) {
					$Form.= $this->SetCampo($varCampo);
					}
				}
			}
		$Form.="</td>";
		$Form.="</tr>";	
		//Contenido Campos
		foreach($varContenido as $varCampo) {
			$Form.= "<tr><td ";
			$Form.= (isset($varCampo["tamano"]))?"width=\"".$varCampo["tamano"]."\" ":"";
			$Form.= (isset($varCampo["clase1"]))?"class=\"".$varCampo["clase1"]."\" ":"";		
			$Form.= ">";
			$Form.= (isset($varCampo["titulo"]))?$varCampo["titulo"]:"Sin Titulo";
			$Form.="</td><td ";
			$Form.= (isset($varCampo["clase2"]))?"class=\"".$varCampo["clase2"]."\" ":"";
			$Form.= ">";
			$Form.= (isset($varCampo["div"]))?"<div id=\"".$varCampo["div"]."\">":"";
			if(isset($varCampo["campo"])) {
				$Form.= $this->SetCampo($varCampo["campo"]);
				}			
			$Form.= (isset($varCampo["div"]))?"</div>":"";			
			$Form.="</td>";
			$Form.="</tr>";
			}
		//Lista de Botones
		if(isset($varBotones) && count($varBotones)>0) {		
			$Form.= "<tr>";		
			$Form.= "<td height=20 colspan=2 align=center valign=middle ";
			$Form.= (isset($varTable["clase"]))?"class=\"".$varTable["clase"]."\" ":"";
			$Form.= ">";		
			foreach($varBotones as $varBoton) {
				$Form.=$this->SetBoton($varBoton)."&nbsp;";
				}
			$Form.="</td>";
			$Form.="<tr>";
			}		
		$Form.="</table>";
		$Form.= "</form>";
		return $Form;
		}
	//function SetTabla
	function SetTabla($json) {
		$k = json_decode($json, true);
		$Form ="<table id=\"$k[id]\" name=\"$k[name]\" style=\"padding: 0; margin-top:0px;border-collapse:collapse;\" ";
		$Form.="width=\"$k[tam_tabla]\" align=\"center\"  cellpadding=\"0\" cellspacing=\"0\">";
		$Form.="<!--DWLayoutTable-->";
		$Form.="<tr>";
		$Form.="<td height=18 colspan=2 align=center valign=middle class=\"$k[cla_titu]\">";
		$Form.= (isset($k["titulo"]))?$k["titulo"]:"";
		//Lista de Campos Ocultos
		$i = 0; 
		if(isset($k["oculto"])) {
			while($i<count($k["oculto"])) {
				$Form.=$this->SetCampo($k["oculto"][$i]);
				$i++;
				}
			}
		$Form.="</td>";
		$Form.="</tr>";
		
		//Lista de Campos
		$i = 0; 
		while($i<count($k["contenido"])) {
			$Form.="<tr>";
			$Form.="<td ";
			$Form.= (isset($k["tam_campo1"]))?"width=\"".$k["tam_campo1"]."\" ":"";
			$Form.= (isset($k["cla_campo1"]))?"class=\"".$k["cla_campo1"]."\" ":"";
			$Form.= ">";
			$Form.=$k['contenido'][$i]["texto"];
			$Form.="</td>";			
			$Form.="<td ";
			$Form.= (isset($k["tam_campo2"]))?"width=\"".$k["tam_campo2"]."\" ":"";
			$Form.= (isset($k["cla_campo2"]))?"class=\"".$k["cla_campo2"]."\" ":"";
			$Form.= ">";
			if(isset($k["contenido"][$i]["tipo"])) {
				$Form.=$this->SetCampo($k["contenido"][$i]);
				}
			else {
				$Form.=$k["contenido"][$i]["valor"];
				}
			$Form.="</td>";
			$Form.="</tr>";
			$i++;
			}
		if(isset($k["botones"])) {
			$Form.="<tr>";		
			//Lista de Botones
			$Form.="<td height=20 colspan=2 align=center valign=middle class=\"$k[cla_titu]\">";		
			$i = 0; 
			while($i<count($k["botones"])) {			
				$Form.="<input id=\"".$k["botones"][$i]["id"]."\" name=\"".$k["botones"][$i]["name"]."\" ";
				$Form.="type=\"".$k["botones"][$i]["tipo"]."\" style=\"width:".$k["botones"][$i]["ancho"]."px; ";
				$Form.="height:".$k["botones"][$i]["alto"]."px; font-size:10px; \" ";
				$Form.=" value=\"".$k["botones"][$i]["texto"]."\" onClick=\"".$k["botones"][$i]["click"]."\">&nbsp;";
				$i++;
				}
			$Form.="</td>";
			$Form.="<tr>";
			}
		$Form.="</table>";
		return $Form;
		}
	
	function setGridCombina($ArrayCabe 	  = NULL, //Array con las Cabeceras Combinadas
							$SqlDato	  = NULL, //Query que contiene los Datos para la Tabla
							$ArrayNivel	  = NULL, //Array con los Niveles de Agrupamiento de la Data
							$ArrayBoton	  = NULL, //Array con los Botones
							$ArrayFormat  = NULL  //Array con Formato Condicional
							)
	{	
	ini_set("memory_limit","128M");
	if(isset($ArrayCabe) && isset($SqlDato) && isset($ArrayNivel)) {		
		$varNumNiv = count($ArrayNivel);
		$varNumCol = 0;
		$varNumComb= count($ArrayCabe);
		foreach($ArrayCabe as $varCombina) {
			$varNumCol = $varNumCol + count($varCombina["det"]);
			}
		$varTamTab = $varNumCol*70+250;
		$this->AbrirConexion();
		$ArrayDato = $this->Query($SqlDato);
		$this->CerrarConexion();
		$Tabla = "<table class=\"matriz\" style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$Tabla.= "width=\"$varTamTab\" align=center cellpadding=0 cellspacing=0>";	
		$Tabla.= "<tr>";
		$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\" height=20 ></td>";
		$Tabla.= "<td width=20  align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
		$Tabla.= "<td width=150 align=\"center\" class=\"FormTitulo\" rowspan=\"2\" NOWRAP>".$ArrayNivel[0]["DES"]."</td>";
		$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
		foreach($ArrayCabe as $varCombina) {
			$varNumCob = count($varCombina["det"]);
			if(count($varCombina["bot"])>0)
				$varNumCob = $varNumCob + 1;
			$Tabla.= "<td width=".($varNumCob*60)."  align=\"center\" class=\"FormTitulo\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
			$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
			}	
		$Tabla.= "</tr>";
		$Tabla.= "<tr>";
		$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
		$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
		$varPos = $varNumNiv*2;
		
		$varDat[0] = $varDat[1] = $varDat[2] = $varDat[3] = $varDat[4] = $varDat[5] = $varDat[6] = $varDat[7] = 0;
		foreach($ArrayCabe as $varCombina) {
			foreach($varCombina["det"] as $varIndex=>$Data) {
				if(isset($varCombina["factor"])) {
					$varDat[$varPos] = $varCombina["factor"];
					}
				else {
					$varDat[$varPos] = 0;
					}
				
				$Tabla.= "<td width=50 align=\"center\" class=\"FormTitulo\">";
				if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
					$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
					$Tabla.= $Data;
					$Tabla.= "</a>";
					}
				else {
					$Tabla.= $Data;
					}
				$varPos = $varPos + 1;
				$Tabla.= "</td>";
				
				}
			if(count($varCombina["bot"])>0)
				$Tabla.= "<td  align=\"center\" class=\"FormTitulo\">OPT</td>";
			$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
			}
		$Tabla.= "</tr>";		
		
		$color1 = "#F5FAFA";
		$color2 = "#edf3f3";
		$colors = "#FFFF33";		
		$bgcolor1 = "bgcolor=$color1 onMouseOver=\"uno(this,'$colors')\" onMouseOut=\"dos(this,'$color1')\" ";		
		$bgcolor2 = "bgcolor=$color2 onMouseOver=\"uno(this,'$colors')\" onMouseOut=\"dos(this,'$color2')\" ";	
		
		$varNivel_3_Cod_ant = "";
		$varNivel_3_Cod_act = "";
		$varNivel_3_Nom = "";
		
		$varNivel_2_Cod_ant = "";
		$varNivel_2_Cod_act = "";
		$varNivel_2_Nom = "";
		
		$varNivel_1_Cod_ant = "";
		$varNivel_1_Cod_act = "";
		$varNivel_1_Nom = "";
		
		for($i=0; $i<=$varNumCol; $i++) {
			$varSumNiv_1[$i] = 0;
			$varSumNiv_2[$i] = 0;
			$varSumNiv_3[$i] = 0;
			$varSumTotal[$i] = 0;
			}
			
		$k=0;
		$varPosCol = 2;

		while($fila = $this->FetchArray($ArrayDato)) {	
			//KRSC 09/12/2014
			$varNivel_2_Verif = $fila[$ArrayNivel[2]["COD"]];
					
			//Nivel 1 Por lo General Grupo de Supervisores
			//=============================================
			if($varNumNiv >= 2) {
				$varPosCol = 4;
				if($varNivel_1_Cod_act=="" && $varNivel_1_Cod_ant=="") {
					$varNivel_1_Cod_act = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Nom = $fila[$ArrayNivel[1]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_1[$i] = $varSumNiv_1[$i] + 
											   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							//Aqui puede ser
							
								$varSumNiv_1[$i] = $varSumNiv_1[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_1_Cod_act = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Cod_ant = $varNivel_1_Cod_ant;
					if($varNivel_1_Cod_act == $varNivel_1_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_1[$i] = $varSumNiv_1[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								if($varNivel_2_Cod_act<>$varNivel_2_Verif) {
									$varSumNiv_1[$i] = $varSumNiv_1[$i] + $fila[$i+$varNumNiv*2-1];							
									}
							}	
						}
					}
				
				if($varNivel_1_Cod_act <> $varNivel_1_Cod_ant || ($varNivel_2_Cod_act<>$varNivel_2_Verif && $varNivel_2_Cod_act<>"")) {
					$Tabla.= "<tr>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_1_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_1_Nom NIVEL 11 
								Nivel1=>$varNivel_1_Cod_act <> $varNivel_1_Cod_ant
								Nivel2=>$varNivel_2_Cod_act <> $varNivel_2_Cod_ant
								$varNivel_2_Verif
								</td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";	
					
					$varPos = 1;
					$varPosSum  = $varNumNiv*2-1;
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
							if($varSumNiv_1[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_1[$varPos]/$varFactor) + round($varSumNiv_1[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_1[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',')."Ejemplo";
									}
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+5]["tipodat"]=="porc")  $Tabla.="%";
								}							
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
						}		
					$Tabla.= "</tr>";
					
					$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Nom     = $fila[$ArrayNivel[1]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_1[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_1[$i] = $fila[$i+$varNumNiv*2-1];
						}
					}
				}
			
			//Nivel 2: Por lo General Grupo de CD'S
			//=============================================
			if($varNumNiv >= 3) {
				$varPosCol = 6;
				$varColData = $i+$varNumNiv*2-1;
				if($varNivel_2_Cod_act=="" && $varNivel_2_Cod_ant=="") {
					$varNivel_2_Cod_act = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Nom = $fila[$ArrayNivel[2]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_2[$i] = $varSumNiv_2[$i] + floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_2[$i] = $varSumNiv_2[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_2_Cod_act = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Cod_ant = $varNivel_2_Cod_ant;
					if($varNivel_2_Cod_act == $varNivel_2_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_2[$i] = $varSumNiv_2[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								$varSumNiv_2[$i] = $varSumNiv_2[$i] + $fila[$i+$varNumNiv*2-1];							
							}	
						}
					}
				
				if($varNivel_2_Cod_act <> $varNivel_2_Cod_ant && $varNivel_2_Cod_ant<>"") {
					$Tabla.= "<tr>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_2_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_2_Nom 
								NIVEL 222
								Nivel1=>$varNivel_1_Cod_act <> $varNivel_1_Cod_ant
								Nivel2=>$varNivel_2_Cod_act <> $varNivel_2_Cod_ant
								$varNivel_2_Verif
								</td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$varPos = 1;		
					$varPosSum  = $varNumNiv*2-1;	
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
							if($varSumNiv_2[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_2[$varPos]/$varFactor) + round($varSumNiv_2[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_2[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_2[$ArrayFormat[$varPos+5]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_2[$ArrayFormat[$varPos+5]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',');
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  
									$Tabla.="%";
								}
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
						}			
					$Tabla.= "</tr>";
					
					$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Nom     = $fila[$ArrayNivel[2]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_2[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_2[$i] = $fila[$i+$varNumNiv*2-1];	
						}
					
					if($varNumNiv == 3) {
						$Tabla.= "<tr>";
						$Tabla.= "<td height=25></td>";
						$Tabla.= "</tr>";
						
						$Tabla.= "<tr>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\" height=20 ></td>";
						$Tabla.= "<td width=20  align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
						$Tabla.= "<td width=350 align=\"center\" class=\"FormTitulo\" rowspan=\"2\" nowrap >".$ArrayNivel[0]["DES"]."</td>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						foreach($ArrayCabe as $varCombina) {
							$varNumCob = count($varCombina["det"]);
							$Tabla.= "<td width=50  align=\"center\" class=\"FormTitulo\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
							$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
							}	
						$Tabla.= "</tr>";
						$Tabla.= "<tr>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						foreach($ArrayCabe as $varCombina) {
							foreach($varCombina["det"] as $varIndex=>$Data) {
								$Tabla.= "<td width=50 align=\"center\" class=\"FormTitulo\">";
								if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
									$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
									$Tabla.= $Data;
									$Tabla.= "</a>";
									}
								else {
									$Tabla.= $Data;
									}
								$Tabla.= "</td>";
								}
							$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
							}
						$Tabla.= "</tr>";
						}
					}
				}
			
			// NIVEL 3: AGRUPACION NUEVA AGREGADA EL 17/05/2011
			// ================================================
			if($varNumNiv >= 4) {
				$varPosCol = 8;
				$varColData = $i+$varNumNiv*2-1;
				if($varNivel_3_Cod_act=="" && $varNivel_3_Cod_ant=="") {
					$varNivel_3_Cod_act = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Cod_ant = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Nom = $fila[$ArrayNivel[3]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_3[$i] = $varSumNiv_3[$i] + 
											   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_3[$i] = $varSumNiv_3[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_3_Cod_act = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Cod_ant = $varNivel_3_Cod_ant;
					if($varNivel_3_Cod_act == $varNivel_3_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_3[$i] = $varSumNiv_3[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								$varSumNiv_3[$i] = $varSumNiv_3[$i] + $fila[$i+$varNumNiv*2-1];							
							}	
						}
					}
				
				if($varNivel_3_Cod_act <> $varNivel_3_Cod_ant) {
					$Tabla.= "<tr>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_3_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_3_Nom</td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$varPos = 1;
					$varPosSum  = $varNumNiv*2-1;
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
							if($varSumNiv_3[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_3[$varPos]/$varFactor) + round($varSumNiv_3[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_3[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_3[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_3[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+5]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',');
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="%") 
									$Tabla.="%";
								}
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
						}			
					$Tabla.= "</tr>";
					
					$varNivel_3_Cod_ant = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Nom     = $fila[$ArrayNivel[3]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_3[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_3[$i] = $fila[$i+$varNumNiv*2-1];	
						}
					$Tabla.= "<tr>";
					$Tabla.= "<td height=25></td>";
					$Tabla.= "</tr>";
					
					$Tabla.= "<tr>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\" height=20 ></td>";
					$Tabla.= "<td width=20  align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
					$Tabla.= "<td width=350 align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["DES"]."</td>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					foreach($ArrayCabe as $varCombina) {
						$varNumCob = count($varCombina["det"]);
						$Tabla.= "<td width=50  align=\"center\" class=\"FormTitulo\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						}	
					$Tabla.= "</tr>";
					$Tabla.= "<tr>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $varIndex=>$Data) {
							$Tabla.= "<td width=50 align=\"center\" class=\"FormTitulo\">";
							if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
								$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
								$Tabla.= $Data;
								$Tabla.= "</a>";
								}
							else {
								$Tabla.= $Data;
								}
							$Tabla.= "</td>";
							}
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						}
					$Tabla.= "</tr>";
					
					}
				}
				
			//Data del Contenido
			//=============================================
			$k++;
			$Tabla.= ($k%2==0)?"<tr class=\"par\">":"<tr class=\"impar\">";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\">";
			if(isset($ArrayBoton) && count($ArrayBoton)>0) {
				foreach($ArrayBoton as $varBoton) {
					if(count($varBoton)>0)
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion CLICK																									//
						//--------------------------------------------------------------------------------------------------------------//
						$icon = 0;
						$varClick="";
						if(count($varBoton["click"])>1) {
							foreach($varBoton["click"] as $valor=>$ArrayClick) {
								if($valor=="funcion") {
									$varClick.= $ArrayClick."(";
									}
								elseif($valor=="param") {
									foreach($ArrayClick as $varCampo) {
										if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
											$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
											$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
										else
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
															
										$icon++;
										}									
									}
								
								}
							$varClick.= ")";
							}
						else {
							$varClick = $varBoton["click"];
							}
						
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion TOLTIP																									//
						//--------------------------------------------------------------------------------------------------------------//
						$varTolTip = "";
						if(count($varBoton["toltip"])>1) {
							foreach($varBoton["toltip"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									//$varTolTip.= str_replace("'","\'",$fila[$varCampo["valor"]]) ;
									$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
								else
									$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
								}
							
							//if($MyValor=="") $MyValor = "'".str_replace("'","\'",$row[$Contenido["Valor"]])."'";
							//else $MyValor = $MyValor.",'".mysql_real_escape_string(str_replace("\"","'",$row[$Contenido["Valor"]]))."'";
											
							}
						else {
							$varTolTip = $varBoton["toltip"];
							}
							
						$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
											  "id"		=>$varBoton["id"],
											  "name"	=>$varBoton["name"], 										  
											  "locked"	=>$varBoton["locked"],
											  "clase"	=>$varBoton["clase"], 
											  "img"		=>$varBoton["img"], 
											  "click"	=>$varClick, 
											  "toltip"	=>$varTolTip, 
											  "dclick"	=>$varBoton["dclick"],
											  "keyup"	=>$varBoton["keyup"],
											  "keypress"=>$varBoton["keypress"], 
											  "valor"	=>$varBoton["valor"], 											  
											  "ancho"	=>$varBoton["ancho"],
											  "alinear"	=>$varBoton["alinear"]);
						$Tabla.= $this->setCampo($varCampoBoton)."&nbsp;";
					}
				}
			$Tabla.= "</td>";
			$Tabla.= "<td align=\"center\" class=\"interior\" height=18><b>".$fila[$ArrayNivel[0]["COD"]]."</b></td>";
			$Tabla.= "<td class=\"interior\" NOWRAP>".$fila[$ArrayNivel[0]["DES"]]."</td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
			
//			$varPos = $varPosCol;
			$varPos = $varNumNiv*2;
			$varTexto = "";
			// RECORREMOS EL CONTENIDO DEL GRID
			// ================================
			foreach($ArrayCabe as $varCombina) {
				$varFlagContenido = "";
				foreach($varCombina["det"] as $Data) {
					//Formato de Texto Condicional
					$varClase = "interior";
					if(isset($ArrayFormat[$varPos]["formato"]) && count($ArrayFormat[$varPos]["formato"])>0) {
						foreach($ArrayFormat[$varPos]["formato"] as $varCond) {
							$varClase1 = $this->setFormatCondicion($fila[$varPos], $varCond["cond"], $varCond["formato"], 
																   $varCond["valor1"], $varCond["valor2"]);
							if(isset($varClase1)) $varClase = $varClase1;
							}
						}
					//Formato Estilo de Texto
					$varClase = (isset($ArrayFormat[$varPos]["estilo"]))?$ArrayFormat[$varPos]["estilo"]:$varClase;
					$varAling = $ArrayFormat[$varPos]["alinear"];
					$varAling = (isset($varAling) && $varAling<>"")?$varAling:"right";						
					//Formato Tipo de Dato
					$varTipoDato = (isset($ArrayFormat[$varPos]["tipodat"]))? strtoupper($ArrayFormat[$varPos]["tipodat"]):$this->Fieldtype($ArrayDato, $varPos);
					$varNumDec   = (isset($ArrayFormat[$varPos]["decimal"]))? $ArrayFormat[$varPos]["decimal"]:NULL;
					$varTexto	 = $this->setFormatTipoDato($fila[$varPos], $varTipoDato, $varNumDec);
					//Formato Hipervinculo
					if(isset($ArrayFormat[$varPos]["hiper"]) && count($ArrayFormat[$varPos]["hiper"])>0) {
						$varBoton = $ArrayFormat[$varPos]["hiper"];
						//-------------------------------//
						//Opcion CLICK		 			 //
						//-------------------------------//
						$icon = 0;
						$varClick="";
						if(count($varBoton["click"])>1) {
							foreach($varBoton["click"] as $valor=>$ArrayClick) {
								if($valor=="funcion") {
									$varClick.= $ArrayClick."(";
									}
								elseif($valor=="param") {
									foreach($ArrayClick as $varCampo) {
										if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
											$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
											$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
										else
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
															
										$icon++;
										}									
									}
								
								}
							$varClick.= ")";
							}
						else {
							$varClick = $varBoton["click"];
							}
						
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion TOLTIP																									//
						//--------------------------------------------------------------------------------------------------------------//
						$varTolTip = "";
						if(count($varBoton["toltip"])>1) {
							foreach($varBoton["toltip"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
								else
									$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
								}			
							}
						else {
							$varTolTip = $varBoton["toltip"];
							}
						$varTexto = $this->setFormatHipervinculo($varTexto, $varClick, $varTolTip);
						}					
					$Tabla.= "<td align=\"$varAling\" class=\"$varClase\" nowrap=\"nowrap\">";
					$Tabla.= $varTexto;
					$varFlagContenido.= $varTexto;
					$Tabla.="</td>";
					$varPos = $varPos + 1;
					}
				//+-==>>INICIO: BOTONES DENTRO DE UN GRUPO DE DATOS
				if(count($varCombina["bot"])>0) {					
					$Tabla.= "<td align=\"center\" class=\"$varClase\">";					
					foreach($varCombina["bot"] as $varBoton) {
						if(count($varBoton)>0)
							//Opcion CLICK																									//
							$icon = 0;
							$varClick="";
							if(count($varBoton["click"])>1) {
								foreach($varBoton["click"] as $valor=>$ArrayClick) {
									if($valor=="funcion") {
										$varClick.= $ArrayClick."(";
										}
									elseif($valor=="param") {
										foreach($ArrayClick as $varCampo) {
											if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
												$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
												$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
												$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
											else
												$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
																
											$icon++;
											}									
										}
									
									}
								$varClick.= ")";
								}
							else {
								$varClick = $varBoton["click"];
								}
							//Opcion TOLTIP
							$varTolTip = "";
							if(count($varBoton["toltip"])>1) {
								foreach($varBoton["toltip"] as $varCampo) {
									if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
										$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
									else
										$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
									}								
								}
							else {
								$varTolTip = $varBoton["toltip"];
								}
								
							$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
												  "id"		=>$varBoton["id"],
												  "name"	=>$varBoton["name"], 										  
												  "locked"	=>$varBoton["locked"],
												  "clase"	=>$varBoton["clase"], 
												  "img"		=>$varBoton["img"], 
												  "click"	=>$varClick, 
												  "toltip"	=>$varTolTip, 
												  "dclick"	=>$varBoton["dclick"],
												  "keyup"	=>$varBoton["keyup"],
												  "keypress"=>$varBoton["keypress"], 
												  "valor"	=>$varBoton["valor"], 											  
												  "ancho"	=>$varBoton["ancho"],
												  "alinear"	=>$varBoton["alinear"]);
						if($varFlagContenido<> "")
							$Tabla.= $this->setCampo($varCampoBoton)."&nbsp;";
						}					
					$Tabla.= "</td>";
					}
				//<<==FIN: BOTONES DENTRO DE UN GRUPO DE DATOS
				$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
				}				
			$Tabla.= "</tr>";
			}
		//Ultimo Nivel 1
		if($varNumNiv >= 2) {
			$Tabla.= "<tr>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\">&nbsp;</td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_1_Cod_ant</b></td>";
			$Tabla.= "<td class=\"FormTituloSub\" nowrap>$varNivel_1_Nom</td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\">&nbsp;</td>";	
			$varPos = 1;
			$varPosSum  = $varNumNiv*2-1;
			foreach($ArrayCabe as $varCombina) {
				foreach($varCombina["det"] as $Data) {
					$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
					if($varSumNiv_1[$varPos]>0) {
						if($varDat[$varPos+$varPosSum]<>0) {
							$varFactor = $varDat[$varPos+$varPosSum];
							$varSuma = floor($varSumNiv_1[$varPos]/$varFactor) + round($varSumNiv_1[$varPos])%round($varFactor)/100;								
							}
						else
							$varSuma = $varSumNiv_1[$varPos];
						
						if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
							
							$varPos1 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
							$varPos2 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
							$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
							}
						if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
						   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
							$Tabla.= number_format($varSuma, 2,'.',',');
							}
						if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  $Tabla.="%";
						}
					$Tabla.= "</td>";
					$varPos = $varPos + 1;
					}				
				$Tabla.= "<td align=\"center\" class=\"FormTituloSub\">&nbsp;</td>";
				
				}			
			$Tabla.= "</tr>";
			
			$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
			$varNivel_1_Nom     = $fila[$ArrayNivel[1]["DES"]];
			for($i=1; $i<=$varNumCol;$i++) {
				if($varDat[$i+$varNumNiv*2-1]<>0) {
					$varFactor = $varDat[$i+$varNumNiv*2-1];
					$varSumNiv_1[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
					}
				else
					$varSumNiv_1[$i] = $fila[$i+$varNumNiv*2-1];
				}
			}
		if($varNumNiv >= 3) {
			$Tabla.= "<tr>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_2_Cod_ant</b></td>";
			$Tabla.= "<td class=\"FormTituloSub\" nowrap >$varNivel_2_Nom</td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";	
			$varPos = 1;
			$varPosSum  = $varNumNiv*2-1;	
			foreach($ArrayCabe as $varCombina) {
				foreach($varCombina["det"] as $Data) {
					$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
					if($varSumNiv_2[$varPos]>0) {
						if($varDat[$varPos+$varPosSum]<>0) {
							$varFactor = $varDat[$varPos+$varPosSum];
							$varSuma = floor(round($varSumNiv_2[$varPos])/$varFactor) + (round($varSumNiv_2[$varPos],0))%$varFactor/100;								
							}
						else
							$varSuma = $varSumNiv_2[$varPos];
						if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
							$varPos1 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
							$varPos2 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
							$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
							}
						if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
						   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
							$Tabla.= number_format($varSuma, 2,'.',',');
							}
						if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  $Tabla.="%";
						}
					$Tabla.="</td>";
					$varPos = $varPos + 1;
					}
				$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
				}			
			$Tabla.= "</tr>";
			
			$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
			$varNivel_2_Nom     = $fila[$ArrayNivel[2]["DES"]];
			for($i=1; $i<=$varNumCol;$i++) {
				if($varDat[$i+$varNumNiv*2-1]<>0) {
					$varFactor = $varDat[$i+$varNumNiv*2-1];
					$varSumNiv_2[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
					}
				else
					$varSumNiv_2[$i] = $fila[$i+$varNumNiv*2-1];
				}
			}
		$Tabla.= "</table>";
		}
	else
		{
		$Tabla = $this->ErrorConsulta();
		}
	return $Tabla;
	}
	
	function setGridCombinaPrint($ArrayCabe   = NULL, //Array con las Cabeceras Combinadas
								 $SqlDato	  = NULL, //Query que contiene los Datos para la Tabla
								 $ArrayNivel  = NULL, //Array con los Niveles de Agrupamiento de la Data
								 $ArrayBoton  = NULL, //Array con los Botones
								 $ArrayFormat = NULL  //Array con Formato Condicional
								 )
	{	
	ini_set("memory_limit","128M");
	if(isset($ArrayCabe) && isset($SqlDato) && isset($ArrayNivel)) {		
		$varNumNiv = count($ArrayNivel);
		$varNumCol = 0;
		$varNumComb= count($ArrayCabe);
		foreach($ArrayCabe as $varCombina) {
			$varNumCol = $varNumCol + count($varCombina["det"]);
			}
		$varTamTab = $varNumCol*70+250;
		$this->AbrirConexion();
		$ArrayDato = $this->Query($SqlDato);
		$this->CerrarConexion();
		$Tabla = "<table style=\"padding:0;margin-top:0px;border-collapse:collapse;\" ";
		$Tabla.= "width=\"95%\" align=center cellpadding=0 cellspacing=0>";	
		$Tabla.= "<tr class=\"titu_tabla\">";
		$Tabla.= "<td width=5   align=\"center\" rowspan=\"2\" height=20 style=\"border-left:1px solid #000033;\"></td>";
		$Tabla.= "<td width=20  align=\"center\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
		$Tabla.= "<td width=150 align=\"center\" rowspan=\"2\" NOWRAP>".$ArrayNivel[0]["DES"]."</td>";
		$Tabla.= "<td width=5   align=\"center\ rowspan=\"2\" style=\"border-left:1px solid #000033;\"></td>";
		foreach($ArrayCabe as $varCombina) {
			$varNumCob = count($varCombina["det"]);
			if(count($varCombina["bot"])>0)
				$varNumCob = $varNumCob + 1;
			$Tabla.= "<td width=".($varNumCob*60)."  align=\"center\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
			$Tabla.= "<td width=5   align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
			}	
		$Tabla.= "</tr>";
		$Tabla.= "<tr class=\"titu_tabla\">";
		$Tabla.= "<td width=5   align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
		$varPos = $varNumNiv*2;

		$varDat[0] = $varDat[1] = $varDat[2] = $varDat[3] = $varDat[4] = $varDat[5] = $varDat[6] = $varDat[7] = 0;
		foreach($ArrayCabe as $varCombina) {
			foreach($varCombina["det"] as $varIndex=>$Data) {
				if(isset($varCombina["factor"])) {
					$varDat[$varPos] = $varCombina["factor"];
					}
				else {
					$varDat[$varPos] = 0;
					}
				
				$Tabla.= "<td width=50 align=\"center\" >";
				if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
					$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
					$Tabla.= $Data;
					$Tabla.= "</a>";
					}
				else {
					$Tabla.= $Data;
					}
				$varPos = $varPos + 1;
				$Tabla.= "</td>";
				
				}
			$Tabla.= "<td width=5   align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
			}
		$Tabla.= "</tr>";		
				
		$color1 = "#F5FAFA";
		$color2 = "#edf3f3";
		$colors = "#FFFF33";		
		$bgcolor1 = "bgcolor=$color1 onMouseOver=\"uno(this,'$colors')\" onMouseOut=\"dos(this,'$color1')\" ";		
		$bgcolor2 = "bgcolor=$color2 onMouseOver=\"uno(this,'$colors')\" onMouseOut=\"dos(this,'$color2')\" ";	
		
		$varNivel_3_Cod_ant = "";
		$varNivel_3_Cod_act = "";
		$varNivel_3_Nom = "";
		
		$varNivel_2_Cod_ant = "";
		$varNivel_2_Cod_act = "";
		$varNivel_2_Nom = "";
		
		$varNivel_1_Cod_ant = "";
		$varNivel_1_Cod_act = "";
		$varNivel_1_Nom = "";
		
		for($i=0; $i<=$varNumCol; $i++) {
			$varSumNiv_1[$i] = 0;
			$varSumNiv_2[$i] = 0;
			$varSumNiv_3[$i] = 0;
			$varSumTotal[$i] = 0;
			}
			
		$k=0;
		$varPosCol = 2;

		while($fila = $this->FetchArray($ArrayDato)) {			
			//Nivel 1 Por lo General Grupo de Supervisores
			//=============================================
			if($varNumNiv >= 2) {
				$varPosCol = 4;
				if($varNivel_1_Cod_act=="" && $varNivel_1_Cod_ant=="") {
					$varNivel_1_Cod_act = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Nom = $fila[$ArrayNivel[1]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_1[$i] = $varSumNiv_1[$i] + 
											   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_1[$i] = $varSumNiv_1[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_1_Cod_act = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Cod_ant = $varNivel_1_Cod_ant;
					if($varNivel_1_Cod_act == $varNivel_1_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_1[$i] = $varSumNiv_1[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								$varSumNiv_1[$i] = $varSumNiv_1[$i] + $fila[$i+$varNumNiv*2-1];							
							}	
						}
					}
				
				if($varNivel_1_Cod_act <> $varNivel_1_Cod_ant) {
					$Tabla.= "<tr class=\"titu_tabla\">";
					$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
					$Tabla.= "<td align=\"center\" height=20><b>$varNivel_1_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_1_Nom</td>";
					$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";	
					
					$varPos = 1;
					$varPosSum  = $varNumNiv*2-1;		
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\">";
							if($varSumNiv_1[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_1[$varPos]/$varFactor) + round($varSumNiv_1[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_1[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+5]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',');
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  
									$Tabla.="%";
								}							
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
						}		
					$Tabla.= "</tr>";
					
					$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
					$varNivel_1_Nom     = $fila[$ArrayNivel[1]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_1[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_1[$i] = $fila[$i+$varNumNiv*2-1];
						}
					}
				}
			
			//Nivel 2: Por lo General Grupo de CD'S
			//=============================================
			if($varNumNiv >= 3) {
				$varPosCol = 6;
				$varColData = $i+$varNumNiv*2-1;
				if($varNivel_2_Cod_act=="" && $varNivel_2_Cod_ant=="") {
					$varNivel_2_Cod_act = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Nom = $fila[$ArrayNivel[2]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_2[$i] = $varSumNiv_2[$i] + floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_2[$i] = $varSumNiv_2[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_2_Cod_act = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Cod_ant = $varNivel_2_Cod_ant;
					if($varNivel_2_Cod_act == $varNivel_2_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_2[$i] = $varSumNiv_2[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								$varSumNiv_2[$i] = $varSumNiv_2[$i] + $fila[$i+$varNumNiv*2-1];							
							}	
						}
					}
				
				if($varNivel_2_Cod_act <> $varNivel_2_Cod_ant) {
					$Tabla.= "<tr class=\"titu_tabla\">";
					$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
					$Tabla.= "<td align=\"center\" height=20><b>$varNivel_2_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_2_Nom</td>";
					$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
					$varPos = 1;
					$varPosSum  = $varNumNiv*2-1;		
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\">";
							if($varSumNiv_2[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_2[$varPos]/$varFactor) + round($varSumNiv_2[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_2[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',');
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  
									$Tabla.="%";
								
								}
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
						}			
					$Tabla.= "</tr>";
					
					$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
					$varNivel_2_Nom     = $fila[$ArrayNivel[2]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_2[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_2[$i] = $fila[$i+$varNumNiv*2-1];	
						}
					
					if($varNumNiv == 3) {
						$Tabla.= "<tr>";
						$Tabla.= "<td height=25></td>";
						$Tabla.= "</tr>";
						//TituloTemporal
						$Tabla.= "<tr class=\"titu_tabla\">";
						$Tabla.= "<td width=5   align=\"center\" rowspan=\"2\" height=20 style=\"border-left:1px solid #000033;\"></td>";
						$Tabla.= "<td width=20  align=\"center\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
						$Tabla.= "<td width=150 align=\"center\" rowspan=\"2\" NOWRAP>".$ArrayNivel[0]["DES"]."</td>";
						$Tabla.= "<td width=5   align=\"center\ rowspan=\"2\" style=\"border-left:1px solid #000033;\"></td>";
						foreach($ArrayCabe as $varCombina) {
							$varNumCob = count($varCombina["det"]);
							if(count($varCombina["bot"])>0)
								$varNumCob = $varNumCob + 1;
							$Tabla.= "<td width=".($varNumCob*60)."  align=\"center\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
							$Tabla.= "<td width=5   align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
							}	
						$Tabla.= "</tr>";
						$Tabla.= "<tr class=\"titu_tabla\">";
						$Tabla.= "<td width=5   align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
						$varPos = $varNumNiv*2;
				
						$varDat[0] = $varDat[1] = $varDat[2] = $varDat[3] = $varDat[4] = $varDat[5] = $varDat[6] = $varDat[7] = 0;
						foreach($ArrayCabe as $varCombina) {
							foreach($varCombina["det"] as $varIndex=>$Data) {
								if(isset($varCombina["factor"])) {
									$varDat[$varPos] = $varCombina["factor"];
									}
								else {
									$varDat[$varPos] = 0;
									}
								
								$Tabla.= "<td width=50 align=\"center\" >";
								if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
									$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
									$Tabla.= $Data;
									$Tabla.= "</a>";
									}
								else {
									$Tabla.= $Data;
									}
								$varPos = $varPos + 1;
								$Tabla.= "</td>";
								
								}
							$Tabla.= "<td width=5   align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
							}
						$Tabla.= "</tr>";
						}
						
					}
				}
			
			// NIVEL 3: AGRUPACION NUEVA AGREGADA EL 17/05/2011
			// ================================================
			if($varNumNiv >= 4) {
				$varPosCol = 8;
				$varColData = $i+$varNumNiv*2-1;
				if($varNivel_3_Cod_act=="" && $varNivel_3_Cod_ant=="") {
					$varNivel_3_Cod_act = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Cod_ant = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Nom = $fila[$ArrayNivel[3]["DES"]];
					for($i=0; $i<=$varNumCol; $i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_3[$i] = $varSumNiv_3[$i] + 
											   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
											   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_3[$i] = $varSumNiv_3[$i] + $fila[$i+$varNumNiv*2-1];
						}		
					}
				else{
					$varNivel_3_Cod_act = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Cod_ant = $varNivel_3_Cod_ant;
					if($varNivel_3_Cod_act == $varNivel_3_Cod_ant) {
						for($i=0; $i<=$varNumCol; $i++) {
							if($varDat[$i+$varNumNiv*2-1]<>0) {
								$varFactor = $varDat[$i+$varNumNiv*2-1];
								$varSumNiv_3[$i] = $varSumNiv_3[$i] + 
												   floor($fila[$i+$varNumNiv*2-1])*$varFactor + 
												   ($fila[$i+$varNumNiv*2-1] - floor($fila[$i+$varNumNiv*2-1]))*100;
								}
							else
								$varSumNiv_3[$i] = $varSumNiv_3[$i] + $fila[$i+$varNumNiv*2-1];							
							}	
						}
					}
				
				if($varNivel_3_Cod_act <> $varNivel_3_Cod_ant) {
					$Tabla.= "<tr class=\"titu_tabla\">";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_3_Cod_ant</b></td>";
					$Tabla.= "<td class=\"FormTituloSub\" NOWRAP>$varNivel_3_Nom</td>";
					$Tabla.= "<td align=\"center\" class=\"FormTituloSub\"></td>";
					$varPos = 1;
					$varPosSum  = $varNumNiv*2-1;		
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $Data) {
							$Tabla.= "<td align=\"right\" class=\"FormTituloSub\">";
							if($varSumNiv_3[$varPos]>0) {
								if($varDat[$varPos+$varPosSum]<>0) {
									$varFactor = $varDat[$varPos+$varPosSum];
									$varSuma = floor($varSumNiv_3[$varPos]/$varFactor) + round($varSumNiv_3[$varPos])%round($varFactor)/100;								
									}
								else
									$varSuma = $varSumNiv_3[$varPos];
								
								if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
									$varPos1 = $varSumNiv_3[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
									$varPos2 = $varSumNiv_3[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
									$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+5]["formula"]["funcion"]);
									}
								if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
								   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
									$Tabla.= number_format($varSuma, 2,'.',',');
									}
								if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="%")  $Tabla.="%";
								
								}
							$Tabla.="</td>";
							$varPos = $varPos + 1;
							}
						$Tabla.= "<td align=\"center\"></td>";
						}			
					$Tabla.= "</tr>";
					
					$varNivel_3_Cod_ant = $fila[$ArrayNivel[3]["COD"]];
					$varNivel_3_Nom     = $fila[$ArrayNivel[3]["DES"]];
					for($i=1; $i<=$varNumCol;$i++) {
						if($varDat[$i+$varNumNiv*2-1]<>0) {
							$varFactor = $varDat[$i+$varNumNiv*2-1];
							$varSumNiv_3[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
							}
						else
							$varSumNiv_3[$i] = $fila[$i+$varNumNiv*2-1];	
						}
					$Tabla.= "<tr>";
					$Tabla.= "<td height=25></td>";
					$Tabla.= "</tr>";
					
					$Tabla.= "<tr>";
					$Tabla.= "<td width=5   align=\"center\" height=20 ></td>";
					$Tabla.= "<td width=20  align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["COD"]."</td>";
					$Tabla.= "<td width=350 align=\"center\" class=\"FormTitulo\" rowspan=\"2\">".$ArrayNivel[0]["DES"]."</td>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					foreach($ArrayCabe as $varCombina) {
						$varNumCob = count($varCombina["det"]);
						$Tabla.= "<td width=50  align=\"center\" class=\"FormTitulo\" colspan=\"$varNumCob\">".$varCombina["cab"]."</td>";
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						}	
					$Tabla.= "</tr>";
					$Tabla.= "<tr>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
					foreach($ArrayCabe as $varCombina) {
						foreach($varCombina["det"] as $varIndex=>$Data) {
							$Tabla.= "<td width=50 align=\"center\" class=\"FormTitulo\">";
							if(isset($varCombina["toltip"][$varIndex]) && $varCombina["toltip"][$varIndex]<>"") {		
								$Tabla.= "<a href=\"#\" onMouseOver=\"MensajeTip('".$varCombina["toltip"][$varIndex]."')\" onMouseOut=\"UnTip()\"/>";
								$Tabla.= $Data;
								$Tabla.= "</a>";
								}
							else {
								$Tabla.= $Data;
								}
							$Tabla.= "</td>";
							}
						$Tabla.= "<td width=5   align=\"center\" class=\"FormTitulo\"></td>";
						}
					$Tabla.= "</tr>";
					
					}
				}
				
			//Data del Contenido
			//=============================================
			$k++;
			$Tabla.= ($k%2==0)?"<tr class=\"par\">":"<tr class=\"impar\">";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\">";
			if(isset($ArrayBoton) && count($ArrayBoton)>0) {
				foreach($ArrayBoton as $varBoton) {
					if(count($varBoton)>0)
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion CLICK																									//
						//--------------------------------------------------------------------------------------------------------------//
						$icon = 0;
						$varClick="";
						if(count($varBoton["click"])>1) {
							foreach($varBoton["click"] as $valor=>$ArrayClick) {
								if($valor=="funcion") {
									$varClick.= $ArrayClick."(";
									}
								elseif($valor=="param") {
									foreach($ArrayClick as $varCampo) {
										if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
											$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
											$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
										else
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
															
										$icon++;
										}									
									}
								
								}
							$varClick.= ")";
							}
						else {
							$varClick = $varBoton["click"];
							}
						
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion TOLTIP																									//
						//--------------------------------------------------------------------------------------------------------------//
						$varTolTip = "";
						if(count($varBoton["toltip"])>1) {
							foreach($varBoton["toltip"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									//$varTolTip.= str_replace("'","\'",$fila[$varCampo["valor"]]) ;
									$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
								else
									$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
								}
							
							//if($MyValor=="") $MyValor = "'".str_replace("'","\'",$row[$Contenido["Valor"]])."'";
							//else $MyValor = $MyValor.",'".mysql_real_escape_string(str_replace("\"","'",$row[$Contenido["Valor"]]))."'";
											
							}
						else {
							$varTolTip = $varBoton["toltip"];
							}
							
						$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
											  "id"		=>$varBoton["id"],
											  "name"	=>$varBoton["name"], 										  
											  "locked"	=>$varBoton["locked"],
											  "clase"	=>$varBoton["clase"], 
											  "img"		=>$varBoton["img"], 
											  "click"	=>$varClick, 
											  "toltip"	=>$varTolTip, 
											  "dclick"	=>$varBoton["dclick"],
											  "keyup"	=>$varBoton["keyup"],
											  "keypress"=>$varBoton["keypress"], 
											  "valor"	=>$varBoton["valor"], 											  
											  "ancho"	=>$varBoton["ancho"],
											  "alinear"	=>$varBoton["alinear"]);
						$Tabla.= $this->setCampo($varCampoBoton)."&nbsp;";
					}
				}
			$Tabla.= "</td>";
			$Tabla.= "<td align=\"center\" height=18><b>".$fila[$ArrayNivel[0]["COD"]]."</b></td>";
			$Tabla.= "<td class=\"interior\" NOWRAP>".$fila[$ArrayNivel[0]["DES"]]."</td>";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
			
//			$varPos = $varPosCol;
			$varPos = $varNumNiv*2;
			$varTexto = "";
			// RECORREMOS EL CONTENIDO DEL GRID
			// ================================
			foreach($ArrayCabe as $varCombina) {
				$varFlagContenido = "";
				foreach($varCombina["det"] as $Data) {
					//Formato de Texto Condicional
					$varClase = "interior";
					if(isset($ArrayFormat[$varPos]["formato"]) && count($ArrayFormat[$varPos]["formato"])>0) {
						foreach($ArrayFormat[$varPos]["formato"] as $varCond) {
							$varClase1 = $this->setFormatCondicion($fila[$varPos], $varCond["cond"], $varCond["formato"], 
																   $varCond["valor1"], $varCond["valor2"]);
							if(isset($varClase1)) $varClase = $varClase1;
							}
						}
					//Formato Estilo de Texto
					$varClase = (isset($ArrayFormat[$varPos]["estilo"]))?$ArrayFormat[$varPos]["estilo"]:$varClase;	
					
					$varAling = $ArrayFormat[$varPos]["alinear"];
					$varAling = (isset($varAling) && $varAling<>"")?$varAling:"right";
										
					//Formato Tipo de Dato
					$varTipoDato = (isset($ArrayFormat[$varPos]["tipodat"]))? strtoupper($ArrayFormat[$varPos]["tipodat"]):$this->Fieldtype($ArrayDato, $varPos);
					$varNumDec   = (isset($ArrayFormat[$varPos]["decimal"]))? $ArrayFormat[$varPos]["decimal"]:NULL;
					$varTexto	 = $this->setFormatTipoDato($fila[$varPos], $varTipoDato, $varNumDec);
					//Formato Hipervinculo
					if(isset($ArrayFormat[$varPos]["hiper"]) && count($ArrayFormat[$varPos]["hiper"])>0) {
						$varBoton = $ArrayFormat[$varPos]["hiper"];
						//-------------------------------//
						//Opcion CLICK		 			 //
						//-------------------------------//
						$icon = 0;
						$varClick="";
						if(count($varBoton["click"])>1) {
							foreach($varBoton["click"] as $valor=>$ArrayClick) {
								if($valor=="funcion") {
									$varClick.= $ArrayClick."(";
									}
								elseif($valor=="param") {
									foreach($ArrayClick as $varCampo) {
										if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
											$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
											$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
										else
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
															
										$icon++;
										}									
									}
								
								}
							$varClick.= ")";
							}
						else {
							$varClick = $varBoton["click"];
							}
						
						//--------------------------------------------------------------------------------------------------------------//
						//Opcion TOLTIP																									//
						//--------------------------------------------------------------------------------------------------------------//
						$varTolTip = "";
						if(count($varBoton["toltip"])>1) {
							foreach($varBoton["toltip"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
								else
									$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
								}			
							}
						else {
							$varTolTip = $varBoton["toltip"];
							}
						$varTexto = $this->setFormatHipervinculo($varTexto, $varClick, $varTolTip);
						}					
					$Tabla.= "<td align=\"$varAling\" class=\"$varClase\" nowrap=\"nowrap\">";
					$Tabla.= $varTexto;
					$varFlagContenido.= $varTexto;
					$Tabla.="</td>";
					$varPos = $varPos + 1;
					}
				//+-==>>INICIO: BOTONES DENTRO DE UN GRUPO DE DATOS
				if(count($varCombina["bot"])>0) {					
					$Tabla.= "<td align=\"center\" class=\"$varClase\">";					
					foreach($varCombina["bot"] as $varBoton) {
						if(count($varBoton)>0)
							//Opcion CLICK																									//
							$icon = 0;
							$varClick="";
							if(count($varBoton["click"])>1) {
								foreach($varBoton["click"] as $valor=>$ArrayClick) {
									if($valor=="funcion") {
										$varClick.= $ArrayClick."(";
										}
									elseif($valor=="param") {
										foreach($ArrayClick as $varCampo) {
											if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
												$varClick.= ($icon==0)?$varCampo["valor"]:",".$varCampo["valor"];
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
												$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
											elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
												$varClick.= ($icon==0)?"'".$fila[$varCampo["valor"]]."'": ",'".$fila[$varCampo["valor"]]."'";
											else
												$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
																
											$icon++;
											}									
										}
									
									}
								$varClick.= ")";
								}
							else {
								$varClick = $varBoton["click"];
								}
							//Opcion TOLTIP
							$varTolTip = "";
							if(count($varBoton["toltip"])>1) {
								foreach($varBoton["toltip"] as $varCampo) {
									if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
										$varTolTip.= htmlentities(utf8_encode($fila[$varCampo["valor"]]));							
									else
										$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));							
									}								
								}
							else {
								$varTolTip = $varBoton["toltip"];
								}
								
							$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
												  "id"		=>$varBoton["id"],
												  "name"	=>$varBoton["name"], 										  
												  "locked"	=>$varBoton["locked"],
												  "clase"	=>$varBoton["clase"], 
												  "img"		=>$varBoton["img"], 
												  "click"	=>$varClick, 
												  "toltip"	=>$varTolTip, 
												  "dclick"	=>$varBoton["dclick"],
												  "keyup"	=>$varBoton["keyup"],
												  "keypress"=>$varBoton["keypress"], 
												  "valor"	=>$varBoton["valor"], 											  
												  "ancho"	=>$varBoton["ancho"],
												  "alinear"	=>$varBoton["alinear"]);
						if($varFlagContenido<> "")
							$Tabla.= $this->setCampo($varCampoBoton)."&nbsp;";
						}					
					$Tabla.= "</td>";
					}
				//<<==FIN: BOTONES DENTRO DE UN GRUPO DE DATOS
				$Tabla.= "<td align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
				}				
			$Tabla.= "</tr>";
			}
		//Ultimo Nivel 1
		if($varNumNiv >= 2) {
			$Tabla.= "<tr class=\"titu_tabla\">";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\">&nbsp;</td>";
			$Tabla.= "<td align=\"center\" class=\"FormTituloSub\" height=20><b>$varNivel_1_Cod_ant</b></td>";
			$Tabla.= "<td class=\"FormTituloSub\" nowrap>$varNivel_1_Nom</td>";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\">&nbsp;</td>";	
			$varPos = 1;
			$varPosSum  = $varNumNiv*2-1;
			foreach($ArrayCabe as $varCombina) {
				foreach($varCombina["det"] as $Data) {
					$Tabla.= "<td align=\"right\">";
					if($varSumNiv_1[$varPos]>0) {
						if($varDat[$varPos+$varPosSum]<>0) {
							$varFactor = $varDat[$varPos+$varPosSum];
							$varSuma = floor($varSumNiv_1[$varPos]/$varFactor) + round($varSumNiv_1[$varPos])%round($varFactor)/100;								
							}
						else
							$varSuma = $varSumNiv_1[$varPos];
						
						if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
							
							$varPos1 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
							$varPos2 = $varSumNiv_1[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
							$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
							}
						if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
						   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
							$Tabla.= number_format($varSuma, 2,'.',',');
							}
						if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  $Tabla.="%";
						}
					$Tabla.= "</td>";
					$varPos = $varPos + 1;
					}				
				$Tabla.= "<td align=\"center\" style=\"border-right:1px solid #000033;\">&nbsp;</td>";
				
				}			
			$Tabla.= "</tr>";
			
			$varNivel_1_Cod_ant = $fila[$ArrayNivel[1]["COD"]];
			$varNivel_1_Nom     = $fila[$ArrayNivel[1]["DES"]];
			for($i=1; $i<=$varNumCol;$i++) {
				if($varDat[$i+$varNumNiv*2-1]<>0) {
					$varFactor = $varDat[$i+$varNumNiv*2-1];
					$varSumNiv_1[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
					}
				else
					$varSumNiv_1[$i] = $fila[$i+$varNumNiv*2-1];
				}
			}
		if($varNumNiv >= 3) {
			$Tabla.= "<tr class=\"titu_tabla\">";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";
			$Tabla.= "<td align=\"center\" height=20><b>$varNivel_2_Cod_ant</b></td>";
			$Tabla.= "<td class=\"FormTituloSub\" nowrap >$varNivel_2_Nom</td>";
			$Tabla.= "<td align=\"center\" style=\"border-left:1px solid #000033;\"></td>";	
			$varPos = 1;	
			$varPosSum  = $varNumNiv*2-1;		
			foreach($ArrayCabe as $varCombina) {
				foreach($varCombina["det"] as $Data) {
					$Tabla.= "<td align=\"right\">";
					if($varSumNiv_2[$varPos]>0) {
						if($varDat[$varPos+$varPosSum]<>0) {
							$varFactor = $varDat[$varPos+$varPosSum];
							$varSuma = floor(round($varSumNiv_2[$varPos])/$varFactor) + (round($varSumNiv_2[$varPos],0))%$varFactor/100;								
							}
						else
							$varSuma = $varSumNiv_2[$varPos];
						if(isset($ArrayFormat[$varPos+$varPosSum]["formula"]) && count($ArrayFormat[$varPos+$varPosSum]["formula"])>0) {
							$varPos1 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor1"]-$varPosSum];
							$varPos2 = $varSumNiv_2[$ArrayFormat[$varPos+$varPosSum]["formula"]["valor2"]-$varPosSum];
							$varSuma = $this->setFormatFuncion($varPos1, $varPos2, $ArrayFormat[$varPos+$varPosSum]["formula"]["funcion"]);
							}
						if(strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXT" && 
						   strtoupper($ArrayFormat[$varPos+$varPosSum]["tipodat"])<>"TEXTO") {
							$Tabla.= number_format($varSuma, 2,'.',',');
							}
						if(isset($ArrayFormat[$varPos+$varPosSum]["tipodat"]) && $ArrayFormat[$varPos+$varPosSum]["tipodat"]=="porc")  $Tabla.="%";
						}
					$Tabla.="</td>";
					$varPos = $varPos + 1;
					}
				$Tabla.= "<td align=\"center\" style=\"border-right:1px solid #000033;\"></td>";
				}			
			$Tabla.= "</tr>";
			
			$varNivel_2_Cod_ant = $fila[$ArrayNivel[2]["COD"]];
			$varNivel_2_Nom     = $fila[$ArrayNivel[2]["DES"]];
			for($i=1; $i<=$varNumCol;$i++) {
				if($varDat[$i+$varNumNiv*2-1]<>0) {
					$varFactor = $varDat[$i+$varNumNiv*2-1];
					$varSumNiv_2[$i] = floor($fila[$i+$varNumNiv*2-1])*$varFactor + ($fila[$i+$varNumNiv*2-1]-floor($fila[$i+$varNumNiv*2-1]))*100;
					}
				else
					$varSumNiv_2[$i] = $fila[$i+$varNumNiv*2-1];
				}
			}
		$Tabla.= "</table>";
		}
	else
		{
		$Tabla = $this->ErrorConsulta();
		}
	return $Tabla;
	}
	
	function setFormatCondicion($varReal=NULL, $varCond=NULL, $varFormato=NULL, $varMeta1=NULL, $varMeta2=NULL) {
		switch($varCond) {
			case "entre":
				if($varReal >= $varMeta1 && $varReal <= $varMeta2 )  $varResp = $varFormato;
				break;
			case "=":
				if($varReal == $varMeta1)  $varResp = $varFormato;
				break;
			case ">":
				if($varReal > $varMeta1)  $varResp = $varFormato;
				break;
			case ">=":
				if($varReal >= $varMeta1)  $varResp = $varFormato;
				break;
			case "<":
				if($varReal < $varMeta1)  $varResp = $varFormato;
				break;
			case "<=":
				if($varReal <= $varMeta1)  $varResp = $varFormato;
				break;
			default;
				$varResp = NULL;
				break;
			}
		return $varResp;
		}	
	
	function setFormatFuncion($varValor1=NULL, $varValor2=NULL, $varFuncion=NULL) {
		$varResp = NULL;
		switch($varFuncion) {
			case "porc":
			case "PORC":
			case "%":
				if($varValor2==0) $varResp = "0.00";
				else $varResp =  $varValor2/$varValor1*100;
				break;
			case "crec":
				if($Sum[$valor1]==0) $varResp="0.00";
				else $varResp =  $varValor1/$varValor2*100-100;
				break;
			case "suma":
				$varResp = $varValor1+$varValor1;
				break;
			case "resta":
				$varResp = $varValor1-$varValor1;
				break;
			default:
				$varResp = $varValor1+$varValor1;
				break;
			}
		return $varResp;
		}
	function setFormatHipervinculo($varDato=NULL, $varClick = NULL, $varTolTip=NULL) {
		$varResp ="<a href='javascript:void(0)' onclick = \"$varClick\"  onmouseover=\"MensajeTip('$varTolTip')\" onmouseout=\"UnTip()\">".$varDato."</a>";				
		return $varResp;
		}
		
	function setFormatTipoDato($varDato=NULL, $varTipoDato="TEXTO", $varNumDecimales=NULL) {
		$varResp = NULL;
		if(isset($varDato)) {
			switch(strtoupper($varTipoDato)) {
				case "TEXTO":
				case "TEXT":
				case "STRING":
				case "CHAR":
					$varResp = $varDato;
					break;
				case "NUMERO":
				case "DECIMAL":
				case "DOUBLE":
				case "REAL":
				case "FLOAT":				
					$varResp = (isset($varNumDecimales))?number_format($varDato, $varNumDecimales,'.',','):number_format($varDato, 2,'.',',');
					break;
				case "ENTERO":
				case "INT":
					$varResp = number_format($varDato, 0,'.',',');
					break;
				case "PORC":
				case "PORCENTAJE":
					$varResp = (isset($varNumDecimales))?number_format($varDato, $varNumDecimales,'.',',')."%":number_format($varDato, 2,'.',',')."%";
					break;
				default:
					$varResp = $varDato;
					break;
				}
			}
		return $varResp;
		}	
	

function SetGridTabla($varTabla) {	
	$tabla 	= "";
	$color1 = "#F5FAFA";
	$color2 = "#edf3f3";
	$colors = "#FFFF33";//"#99FFCC";	
	$bgcolor1 = "bgcolor=$color1 onMouseOver=\"uno(this,'$colors')\"";
	$bgcolor1.= "onMouseOut=\"dos(this,'$color1')\"";		
	$bgcolor2 = "bgcolor=$color2 onMouseOver=\"uno(this,'$colors')\"";
	$bgcolor2.= "onMouseOut=\"dos(this,'$color2')\"";
	if(!isset($varTabla["sql_cab"]) || $varTabla["sql_cab"]=="") {
		$tabla.= $this->ErrorConsulta();
		}
	else {
		$this->AbrirConexion();
		$rs = $this->Query($varTabla["sql_cab"]);
		$this->CerrarConexion();
		$varNumCol = $this->NumField($rs);
		$varNumFil = $this->NumFilas($rs);
		/*===============================================================================================
		-------------------------------------PROPIEDADES DE LA TABLA------------------------------------
		===============================================================================================*/
		$tabla.= "<table ";
		$tabla.= (isset($varTabla["id"]))?"id=\"".$varTabla["id"]."\" ": NULL;
		$tabla.= (isset($varTabla["name"]))?"name=\"".$varTabla["name"]."\" ": NULL;
		$tabla.= "style=\"padding: 0; margin-top:5px; margin-bottom:10px; border-collapse:collapse;\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" ";
		$tabla.= (isset($varTabla["tamano"]))?"width=\"".$varTabla["tamano"]."\" ": NULL;
		$tabla.= "class=\"max-pages-7 paginate-";
		$tabla.= (isset($varTabla["pages"]))?$varTabla["pages"]: 20;
		$tabla.= " \" >";
		
		/*===============================================================================================
		--------------------------------------CABECERA DE LA TABLA--------------------------------------
		===============================================================================================*/
		$tabla.= "<thead>";
		if(isset($varTabla["titulo"])) {
			$tabla.= "<tr>";
			$tabla.= "<td align=\"center\" class=\"FormTitulo\" height=\"35\" colspan=\"$varNumCol\"><b>".$varTabla["titulo"]."</b></td>";
			$tabla.= "</tr>";
			}
		$tabla.= "<tr>";
		if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
			$tabla.= "<th class=\"sortable\" ";
			$vartam = count($varTabla["boton"])*15;
			$tabla.= "width=\"".$vartam."\" ";
			$tabla.= ">OPT</th>";	
			}
		for ($j=0; $j< $varNumCol; $j++) {
			if(!isset($varTabla["conte"][$j]["oculto"]) || $varTabla["conte"][$j]["oculto"]<>"SI") {
				$tabla.= "<th height=\"35\" ";
				$tabla.= (isset($varTabla["conte"][$j]["ancho"]))?"width=\"".$varTabla["conte"][$j]["ancho"]."\" ":NULL;
				$tabla.= (isset($varTabla["conte"][$j]["clase"]))?"class=\"".$varTabla["conte"][$j]["clase"]."\" ":" class=\"sortable\" ";
				$tabla.= ">";			
				$tabla.= (isset($varTabla["conte"][$j]["titulo"]))?$varTabla["conte"][$j]["titulo"]:$this->FieldName($rs,$j);
				$tabla.= "</th>";
				}
			}		
		$tabla.= "</tr>";
		$tabla.= "</thead>";		
		/*===============================================================================================
		--------------------------------------CONTENIDO DE LA TABLA--------------------------------------
		===============================================================================================*/
		$tabla.= "<tbody id=cuerpoTabla>";
		$j=0;
		while($row = $this->FetchArray($rs)) {
			$j++;
			
			if($j%2==0) $tabla.= "<tr class=\"par\">";
			else $tabla.= "<tr class=\"impar\">";
				
			if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
				$tabla.= "<td class=\"FormTituloSub\" nowrap=\"nowrap\">";
				foreach($varTabla["boton"] as $varBoton) {
					//===================================================================================================================================//
					// FUNCION CLICK
					//===================================================================================================================================//
					$icon = 0;
					$varClick="";
					if(count($varBoton["click"])>1) {
						foreach($varBoton["click"] as $valor=>$ArrayClick) {
							if($valor=="funcion") {
								$varClick.= $ArrayClick."(";
								}
							elseif($valor=="param") {
								foreach($ArrayClick as $varCampo) {
									if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM")
										$varClick.= ($icon==0)?htmlentities($varCampo["valor"]):",".htmlentities($varCampo["valor"]);
									elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
										$varClick.= ($icon==0)?"'".htmlentities($varCampo["valor"])."'":",'".htmlentities($varCampo["valor"])."'";
									elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
										$varClick.= ($icon==0)?"'".htmlentities($row[$varCampo["valor"]])."'": ",'".htmlentities($row[$varCampo["valor"]])."'";
									else
										$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
														
									$icon++;
									}									
								}
							
							}
						$varClick.= ")";
						}
					else {
						$varClick = $varBoton["click"];
						}
					//===================================================================================================================================//
					// FUNCION TOOLTIP
					//===================================================================================================================================//
					$varTolTip = "";
					if(count($varBoton["toltip"])>1) {
						foreach($varBoton["toltip"] as $varCampo) {
							if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
								$varTolTip.= htmlentities(utf8_encode($row[$varCampo["valor"]]));
							else
								$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));
							}
						}
					else {
						$varTolTip = $varBoton["toltip"];
						}
					//Si el tipo de Boton es un CHEKBOX
					if(isset($varBoton["valor"]) && is_array($varBoton["valor"])) {
						$varValor = "";
						foreach($varBoton["valor"] as $varCampo) {
							if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
								$varValor.= ($varValor=="")?$row[$varCampo["valor"]]:"-".$row[$varCampo["valor"]];
							else
								$varValor.= ($varValor=="")?$varCampo["valor"]:"-".$varCampo["valor"];
							}
						}
					else {
						$varValor = $varBoton["valor"];
						}
					$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
									      "id"		=>$varBoton["id"],
										  "name"	=>$varBoton["name"], 										  
										  "locked"	=>$varBoton["locked"],
										  "clase"	=>$varBoton["clase"], 
										  "img"		=>$varBoton["img"], 
										  "checked"	=>$varBoton["checked"], 
										  "click"	=>$varClick, 
										  "toltip"	=>$varTolTip, 
										  "dclick"	=>$varBoton["dclick"],
										  "keyup"	=>$varBoton["keyup"],
										  "keypress"=>$varBoton["keypress"], 
										  "valor"	=>$varValor, 
										  "ancho"	=>$varBoton["ancho"],
										  "alinear"	=>$varBoton["alinear"]);

					/*Si existe condicion para mostrar el boton*/
					if (isset($varBoton["cond"])) {						
						$varRespCond_1="SI";						
						foreach($varBoton["cond"] as $varCond) {						
							if($varRespCond_1 == "SI") {
								$varRespCond = $this->CumpleCondicion($row[$varCond[0]], $varCond[1], $varCond[2]);
								if($varRespCond=="NO"){
									$varRespCond_1="NO";
									}
								}
							}
						if($varRespCond=="SI")
							$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
						else {
							$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
												  "id"		=>$varBoton["id"],
												  "name"	=>$varBoton["name"], 										  
												  "img"		=>$this->RutaImage."16x16/b_none.png", 
												  );
							$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
							}
						}
					else {
						$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
						}
					}				
				$tabla.="</td>";	
				}
			$varFlagAlto = 0;
			for ($i=0;$i<$varNumCol;$i++) {				
				if(isset($varTabla["conte"][$i]["factor"]))
					$varSum[$i] = $varSum[$i] + floor($row[$i])*$varTabla["conte"][$i]["factor"] + ($row[$i]-floor($row[$i]))*100;
				else
					$varSum[$i] = $varSum[$i] + $row[$i];	
				
				if(!isset($varTabla["conte"][$i]["oculto"]) || $varTabla["conte"][$i]["oculto"]<>"SI") {
					
					$tabla.= "<td class=\"interior\" ";
					if(isset($varTabla["conte"][$i]["fijo"]) || $varTabla["conte"][$i]["fijo"]=="SI") {
						$tabla.= " NOWRAP ";
						}
					$tabla.= ($varFlagAlto==0)?"height=\"22\" ":NULL;
					$varFlagAlto++;
					$tabla.= (isset($varTabla["conte"][$i]["alinear"]))? "align=\"".$varTabla["conte"][$i]["alinear"]."\" ": NULL;
					$tabla.= ">";					
					$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
					$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;
					if(isset($varTabla["conte"][$i]["campo"]) && count($varTabla["conte"][$i]["campo"])>0) {
						$varId_In 	= (isset($varTabla["conte"][$i]["campo"]["id_in"]))?"[".$row[$varTabla["conte"][$i]["campo"]["id_in"]]."]":NULL;
						$varName_In = (isset($varTabla["conte"][$i]["campo"]["name_in"]))?"[".$row[$varTabla["conte"][$i]["campo"]["name_in"]]."]":NULL;
						$varCampoBoton= array("tipo"	=>$varTabla["conte"][$i]["campo"]["tipo"], 
											  "id"		=>$varTabla["conte"][$i]["campo"]["id"].$varId_In,
											  "name"	=>$varTabla["conte"][$i]["campo"]["name"].$varName_In,
											  "combo"	=>$varTabla["conte"][$i]["campo"]["combo"],											  
											  "locked"	=>$varTabla["conte"][$i]["campo"]["locked"],
											  "clase"	=>$varTabla["conte"][$i]["campo"]["clase"], 
											  "img"		=>$varTabla["conte"][$i]["campo"]["img"], 
											  "checked"	=>$varTabla["conte"][$i]["campo"]["checked"], 
											  "click"	=>$varClick, 
											  "toltip"	=>$varTolTip, 
											  "dclick"	=>$varTabla["conte"][$i]["campo"]["dclick"],
											  "keyup"	=>$varTabla["conte"][$i]["campo"]["keyup"],
											  "keypress"=>$varTabla["conte"][$i]["campo"]["keypress"], 
											  "valor"	=>$row[$i], 
											  "ancho"	=>$varTabla["conte"][$i]["campo"]["ancho"],
											  "alinear"	=>$varTabla["conte"][$i]["campo"]["alinear"]);
						$tabla.= $this->SetCampo($varCampoBoton);
						}
					else {
						$tabla.= $this->setFormatTipoDato($row[$i], $varTipoDato, $varNumDec);
						}
					$tabla.= "</td>";
					}
				}			
			$tabla.= "</tr>";
			}
		$tabla.= "</thead>";
		/*===============================================================================================
		--------------------------------------PIE DE LA TABLA--------------------------------------
		===============================================================================================*/
		$tabla.= "<tfoot>";
		$tabla.= "<tr>";
		if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
			$tabla.= "<td class=\"FormTituloSub\" align=\"center\"></td>";				
			}
		for ($i=0;$i<$varNumCol;$i++) {
			if(!isset($varTabla["conte"][$i]["oculto"]) || $varTabla["conte"][$i]["oculto"]<>"SI") {
				$tabla.= "<td class=\"FormTituloSub\" ";
				$tabla.= ($i==0)?"height=\"22\" ":NULL;
				$tabla.= (isset($varTabla["conte"][$i]["alinear"]))? "align=\"".$varTabla["conte"][$i]["alinear"]."\" ": NULL;
				$tabla.= ">";
				if(isset($varTabla["conte"][$i]["autosuma"]) && $varTabla["conte"][$i]["autosuma"]=="SI") {
					$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
					$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;					
					$tabla.= $this->setFormatTipoDato($varSum[$i], $varTipoDato, $varNumDec);
					}
				elseif(isset($varTabla["conte"][$i]["funcion"]) && count($varTabla["conte"][$i]["funcion"])>0) {
					$varFuncion  = $varTabla["conte"][$i]["funcion"][0];
					if($varFuncion == "autosuma") $varValor1 = $varSum[$i];
					elseif($varFuncion == "contar")	$varValor1 = $varNumFil;				
					else {
						$varValor1 = $varSum[$varTabla["conte"][$i]["funcion"][1]];
						$varValor2 = $varSum[$varTabla["conte"][$i]["funcion"][2]];						
						}
					$varValor  	 = $this->calcularPiePagina($varFuncion, $varValor1, $varValor2);
					$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
					$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;					
					$tabla.= $this->setFormatTipoDato($varValor, $varTipoDato, $varNumDec);
					}
				$tabla.= "</td>";
				}
			}
		$tabla.= "</tr>";
		$tabla.= "</tfoot>";
		$tabla.= "</table>";		
		}
	return $tabla;
	}	
		
	function calcularPiePagina($varTipo, $varValor1, $varValor2) {
		switch ($varTipo) {
			case "autosuma":
				$varReturn = $varValor1;
				break;
			case "contar":
				$varReturn = "&nbsp;".$varValor1." Registros";
				break;
			case "porcentaje":
			case "porc":
			case "%":
				if ($varValor2==0) 
					$varReturn = 0;
				else
					$varReturn = round($varValor1/$varValor2*100,2);
				break;
			}
		return $varReturn;
		}
		
	function CumpleCondicion($varDato, $varParametro, $varCondicion, $varTipoDato = NULL) {
		if ($varTipoDato=="FECHA") {
			$varDato = str_replace('/', '-', $varDato);
			$varDato = strtotime($varDato);
			
			$varCondicion = str_replace('/', '-', $varCondicion);
			$varCondicion = strtotime($varCondicion); 
			}
		switch ($varParametro) {
			case "=":
			case "==":
			case "IGUAL":
			case "IGU":
				$varResp = ($varDato==$varCondicion)?"SI":"NO"; 
				break;
			case "<>":
			case "=!":
			case "DIFER":
			case "DIF":
				$varResp = ($varDato<>$varCondicion)?"SI":"NO"; 
				break;
			case ">":
			case "MAYOR":
				$varResp = ($varDato>$varCondicion)?"SI":"NO"; 
				break;
			case "<":
			case "MENOR":
				$varResp = ($varDato<$varCondicion)?"SI":"NO"; 
				break;
			case ">=":
			case "MAYIG":
				$varResp = ($varDato>=$varCondicion)?"SI":"NO"; 
				break;
			case "<=":
			case "MENIG":
				$varResp = ($varDato<=$varCondicion)?"SI":"NO"; 
				break;
			}
		return $varResp;
		}
	
	function SetGridTabla2($varTabla) {	
		$tabla 	= "";
		$color1 = "#F5FAFA";
		$color2 = "#edf3f3";
		$colors = "#FFFF33";//"#99FFCC";	
		$bgcolor1 = "bgcolor=$color1 onMouseOver=\"uno(this,'$colors')\"";
		$bgcolor1.= "onMouseOut=\"dos(this,'$color1')\"";		
		$bgcolor2 = "bgcolor=$color2 onMouseOver=\"uno(this,'$colors')\"";
		$bgcolor2.= "onMouseOut=\"dos(this,'$color2')\"";
		if(!isset($varTabla["sql_cab"]) || $varTabla["sql_cab"]=="") {
			$tabla.= $this->ErrorConsulta();
			}
		else {
			$this->AbrirConexion();
			$rs = $this->Query($varTabla["sql_cab"]);
			$this->CerrarConexion();
			$varNumCol = $this->NumField($rs);
			$varNumFil = $this->NumFilas($rs);
			/*===============================================================================================
			-------------------------------------PROPIEDADES DE LA TABLA------------------------------------
			===============================================================================================*/
			$tabla.= "<table ";
			$tabla.= (isset($varTabla["id"]))?"id=\"".$varTabla["id"]."\" ": " ";
			$tabla.= (isset($varTabla["name"]))?"name=\"".$varTabla["name"]."\" ": " ";
			$tabla.= "style=\"padding: 0; margin-top:5px; margin-bottom:10px; border-collapse:collapse;\" ";
			$tabla.= "align=\"center\" cellpadding=\"0\" cellspacing=\"0\" ";
			$tabla.= (isset($varTabla["tamano"]))?"width=\"".$varTabla["tamano"]."\" ": " ";
			$tabla.= (isset($varTabla["clase"]) && $varTabla["clase"]<>"")?"class=\"".$varTabla["clase"]."\" ":"class=\"matriz\" ";
			$tabla.= ">";
			
			/*===============================================================================================
			--------------------------------------CABECERA DE LA TABLA--------------------------------------
			===============================================================================================*/
			$tabla.= "<thead>";
			if(isset($varTabla["titulo"])) {
				$tabla.= "<tr>";
				$tabla.= "<th align=\"center\" class=\"FormTitulo\" colspan=\"$varNumCol\">".$varTabla["titulo"]."</th>";
				$tabla.= "</tr>";
				}
			$tabla.= "<tr>";
			if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
				$tabla.= "<th class=\"sortable\" nowrap=\"nowrap\" ";
				$vartam = count($varTabla["boton"])*15;
				$tabla.= "width=\"".$vartam."\" ";
				$tabla.= ">OPT</th>";	
				}
			for ($j=0; $j< $varNumCol; $j++) {
				if(!isset($varTabla["conte"][$j]["oculto"]) || $varTabla["conte"][$j]["oculto"]<>"SI") {
					$varCab = (isset($varTabla["conte"][$j]["titulo"]))?$varTabla["conte"][$j]["titulo"]:$this->FieldName($rs,$j);
					$tabla.= "<th height=\"35\" ";
					$tabla.= (isset($varTabla["conte"][$j]["ancho"]))?"width=\"".$varTabla["conte"][$j]["ancho"]."\" ":NULL;
					$tabla.= (isset($varTabla["conte"][$j]["clase"]))?"class=\"".$varTabla["conte"][$j]["clase"]."\" ":" class=\"ordenar\" ";
					$tabla.= ">";
					$tabla.= "<table><tr>";
					$tabla.= "<th>";
					$tabla.= $varCab;
					$tabla.= "</th>";
					$tabla.= "<th>";
					$varOrderFun = (isset($varTabla["orderfun"]) && $varTabla["orderfun"]<>"")?$varTabla["orderfun"]:"xBuscarJS";
					$tabla.= "<img onclick=\"".$varOrderFun."('".$this->FieldName($rs,$j)."','ASC');return false;\" ";
					$tabla.= "style=\"cursor: pointer;\" title=\"Ordenar por $varCab de Forma Ascendente\" src=\"".$this->RutaImage."sort_incr.png\">";
					$tabla.= "<img onclick=\"".$varOrderFun."('".$this->FieldName($rs,$j)."','DESC');return false;\" ";
					$tabla.= "style=\"cursor: pointer;\" title=\"Ordenar por $varCab de Forma Descendente\" src=\"".$this->RutaImage."sort_decrease.png\">";
					$tabla.= "</th>";
					$tabla.= "</tr></table>";
					
									
	
					$tabla.= "</th>";
					}
				}		
			$tabla.= "</tr>";
			$tabla.= "</thead>";		
			/*===============================================================================================
			--------------------------------------CONTENIDO DE LA TABLA--------------------------------------
			===============================================================================================*/
			$tabla.= "<tbody id=cuerpoTabla>";
			$j=0;
			while($row = $this->FetchArray($rs)) {
				$j++;
				if($j%2==0) $tabla.= "<tr class=\"par\">";
				else $tabla.= "<tr class=\"impar\">";
				
				if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
					$tabla.= "<td class=\"FormTituloSub\" nowrap=\"nowrap\" >";
					foreach($varTabla["boton"] as $varBoton) {
						//==========================================================================================================//
						// FUNCION CLICK
						//==========================================================================================================//
						$icon = 0;
						$varClick="";
						if(count($varBoton["click"])>1) {
							foreach($varBoton["click"] as $valor=>$ArrayClick) {
								if($valor=="funcion") {
									$varClick.= $ArrayClick."(";
									}
								elseif($valor=="param") {
									foreach($ArrayClick as $varCampo) {
										if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="NUM" || 
																	   strtoupper($varCampo["tipo"])=="NUMERO" || 
																	   strtoupper($varCampo["tipo"])=="NUMBER")
											$varClick.= ($icon==0)?htmlentities($varCampo["valor"]):",".htmlentities($varCampo["valor"]);
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="TEX")
											$varClick.= ($icon==0)?"'".htmlentities($varCampo["valor"])."'":",'".htmlentities($varCampo["valor"])."'";
										elseif(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
											$varClick.= ($icon==0)?"'".htmlentities(utf8_encode($row[$varCampo["valor"]]))."'": ",'".htmlentities(utf8_encode($row[$varCampo["valor"]]))."'";
										else
											$varClick.= ($icon==0)?"'".$varCampo["valor"]."'":",'".$varCampo["valor"]."'";
															
										$icon++;
										}									
									}
								
								}
							$varClick.= ")";
							}
						else {
							$varClick = $varBoton["click"];
							}
						//=========================================================================================//
						// FUNCION TOOLTIP
						//=========================================================================================//
						$varTolTip = "";
						if(count($varBoton["toltip"])>1) {
							foreach($varBoton["toltip"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									$varTolTip.= htmlentities(utf8_encode($row[$varCampo["valor"]]));
								else
									$varTolTip.= htmlentities(utf8_encode($varCampo["valor"]));
								}
							}
						else {
							$varTolTip = $varBoton["toltip"];
							}
						//Si el tipo de Boton es un CHEKBOX
						if(isset($varBoton["valor"]) && is_array($varBoton["valor"])) {
							$varValor = "";
							foreach($varBoton["valor"] as $varCampo) {
								if(isset($varCampo["tipo"]) && strtoupper($varCampo["tipo"])=="INDEX")
									$varValor.= ($varValor=="")?$row[$varCampo["valor"]]:"-".$row[$varCampo["valor"]];
								else
									$varValor.= ($varValor=="")?$varCampo["valor"]:"-".$varCampo["valor"];
								}
							}
						else {
							$varValor = $varBoton["valor"];
							}
						$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
											  "id"		=>$varBoton["id"],
											  "name"	=>$varBoton["name"], 										  
											  "locked"	=>$varBoton["locked"],
											  "clase"	=>$varBoton["clase"], 
											  "img"		=>$varBoton["img"], 
											  "checked"	=>$varBoton["checked"], 
											  "click"	=>$varClick, 
											  "toltip"	=>$varTolTip, 
											  "dclick"	=>$varBoton["dclick"],
											  "keyup"	=>$varBoton["keyup"],
											  "keypress"=>$varBoton["keypress"], 
											  "valor"	=>$varValor, 
											  "ancho"	=>$varBoton["ancho"],
											  "alinear"	=>$varBoton["alinear"]);
	
						/*Si existe condicion para mostrar el boton*/
						if (isset($varBoton["cond"])) {						
							$varRespCond_1="SI";						
							foreach($varBoton["cond"] as $varCond) {						
								if($varRespCond_1 == "SI") {
									$varRespCond = $this->CumpleCondicion($row[$varCond[0]], $varCond[1], $varCond[2], $varCond[3]);
									if($varRespCond=="NO"){
										$varRespCond_1="NO";
										}
									}
								}
							if($varRespCond=="SI")
								$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
							else {
								$varCampoBoton= array("tipo"	=>$varBoton["tipo"], 
													  "id"		=>$varBoton["id"],
													  "name"	=>$varBoton["name"], 										  
													  "img"		=>"../images/16x16/b_none.png", 
													  );
								$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
								}
							}
						else {
							$tabla.=$this->SetCampo($varCampoBoton)."&nbsp;";
							}
						}				
					$tabla.="</td>";	
					}
				$varFlagAlto = 0;
				for ($i=0;$i<$varNumCol;$i++) {				
					if(isset($varTabla["conte"][$i]["factor"]))
						$varSum[$i] = $varSum[$i] + floor($row[$i])*$varTabla["conte"][$i]["factor"] + ($row[$i]-floor($row[$i]))*100;
					else
						$varSum[$i] = $varSum[$i] + $row[$i];	
					
					if(!isset($varTabla["conte"][$i]["oculto"]) || $varTabla["conte"][$i]["oculto"]<>"SI") {
						$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
						$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;
						if(isset($varTabla["conte"][$i]["campo"]) && count($varTabla["conte"][$i]["campo"])>0) {
							$varId_In 	= (isset($varTabla["conte"][$i]["campo"]["id_in"]))?"[".$row[$varTabla["conte"][$i]["campo"]["id_in"]]."]":NULL;
							$varName_In = (isset($varTabla["conte"][$i]["campo"]["name_in"]))?"[".$row[$varTabla["conte"][$i]["campo"]["name_in"]]."]":NULL;
							$varCampoBoton= array("tipo"	=>$varTabla["conte"][$i]["campo"]["tipo"], 
												  "id"		=>$varTabla["conte"][$i]["campo"]["id"].$varId_In,
												  "name"	=>$varTabla["conte"][$i]["campo"]["name"].$varName_In,
												  "combo"	=>$varTabla["conte"][$i]["campo"]["combo"],											  
												  "locked"	=>$varTabla["conte"][$i]["campo"]["locked"],
												  "clase"	=>$varTabla["conte"][$i]["campo"]["clase"], 
												  "img"		=>$varTabla["conte"][$i]["campo"]["img"], 
												  "checked"	=>$varTabla["conte"][$i]["campo"]["checked"], 
												  "click"	=>$varClick, 
												  "toltip"	=>$varTolTip, 
												  "dclick"	=>$varTabla["conte"][$i]["campo"]["dclick"],
												  "keyup"	=>$varTabla["conte"][$i]["campo"]["keyup"],
												  "keypress"=>$varTabla["conte"][$i]["campo"]["keypress"], 
												  "valor"	=>$row[$i], 
												  "ancho"	=>$varTabla["conte"][$i]["campo"]["ancho"],
												  "alinear"	=>$varTabla["conte"][$i]["campo"]["alinear"]);
							$tabla.= $this->SetCampo($varCampoBoton);
							}
						else {
							$varValorDat = $this->setFormatTipoDato($row[$i], $varTipoDato, $varNumDec);
							// Funcion MAXCHAR: para mostrar cierta cantidad de caracteres en la celda
							if(isset($varTabla["conte"][$i]["maxchar"]) && 
							   		 $varTabla["conte"][$i]["maxchar"]<>0 &&
							   	     strlen($varValorDat)>$varTabla["conte"][$i]["maxchar"]) {
									$varValorDat = substr($varValorDat,0,$varTabla["conte"][$i]["maxchar"])."...";
									
								}
							}
						/* KRSC 15/04/2013
						Funcion: FormatCondi
						Si el valor de la celda cumple con alguna de las condiciones se le aplica el formato indicado
						*/
						if(isset($varTabla["conte"][$i]["formatcondi"]) && count($varTabla["conte"][$i]["formatcondi"])>0) {
							$varClase = $this->FormatCondi($varValorDat, $varTabla["conte"][$i]["formatcondi"]);
							}
						else {
							$varClase = "interior";
							}
						$tabla.= "<td class=\"".$varClase."\" ";
						if(isset($varTabla["conte"][$i]["fijo"]) || $varTabla["conte"][$i]["fijo"]=="SI") {
							$tabla.= " NOWRAP ";
							}
						$tabla.= ($varFlagAlto==0)?"height=\"22\" ":NULL;
						$varFlagAlto++;
						$tabla.= (isset($varTabla["conte"][$i]["alinear"]))? "align=\"".$varTabla["conte"][$i]["alinear"]."\" ": NULL;
						$tabla.= ">";
						$tabla.= $varValorDat;
						$tabla.= "</td>";
						}
					}			
				$tabla.= "</tr>";
				}
			$tabla.= "</thead>";
			/*===============================================================================================
			--------------------------------------PIE DE LA TABLA--------------------------------------
			===============================================================================================*/
			$tabla.= "<tfoot>";
			$tabla.= "<tr>";
			if(isset($varTabla["boton"]) && count($varTabla["boton"])>0) {
				$tabla.= "<td class=\"FormTituloSub\" align=\"center\"></td>";				
				}
			for ($i=0;$i<$varNumCol;$i++) {
				if(!isset($varTabla["conte"][$i]["oculto"]) || $varTabla["conte"][$i]["oculto"]<>"SI") {
					$tabla.= "<td class=\"FormTituloSub\" ";
					$tabla.= ($i==0)?"height=\"22\" ":NULL;
					$tabla.= (isset($varTabla["conte"][$i]["alinear"]))? "align=\"".$varTabla["conte"][$i]["alinear"]."\" ": NULL;
					$tabla.= ">";
					if(isset($varTabla["conte"][$i]["autosuma"]) && $varTabla["conte"][$i]["autosuma"]=="SI") {
						$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
						$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;					
						$tabla.= $this->setFormatTipoDato($varSum[$i], $varTipoDato, $varNumDec);
						}
					elseif(isset($varTabla["conte"][$i]["funcion"]) && count($varTabla["conte"][$i]["funcion"])>0) {
						$varFuncion  = $varTabla["conte"][$i]["funcion"][0];
						if($varFuncion == "autosuma") $varValor1 = $varSum[$i];
						elseif($varFuncion == "contar")	$varValor1 = $varNumFil;				
						else {
							$varValor1 = $varSum[$varTabla["conte"][$i]["funcion"][1]];
							$varValor2 = $varSum[$varTabla["conte"][$i]["funcion"][2]];						
							}
						$varValor  	 = $this->calcularPiePagina($varFuncion, $varValor1, $varValor2);
						$varTipoDato = (isset($varTabla["conte"][$i]["tipodat"]))? $varTabla["conte"][$i]["tipodat"]:$this->Fieldtype($rs, $i);
						$varNumDec   = (isset($varTabla["conte"][$i]["decimal"]))? $varTabla["conte"][$i]["decimal"]:NULL;					
						$tabla.=$this->setFormatTipoDato($varValor, $varTipoDato, $varNumDec);
						}
					$tabla.= "</td>";
					}
				}
			$tabla.= "</tr>";
			$tabla.= "</tfoot>";
			$tabla.= "</table>";		
			}
		return $tabla;
		}
		
	function FormatCondi($varDat, $varArr){
		foreach($varArr as $varIde => $varFormat) {
			switch ($varFormat["cond"]) {
				case "entre":
				case "ENTRE":
					if($varDat >= $varFormat["valor1"] && $varDat <= $varFormat["valor2"])
						$varClase = $varFormat["clase"];
					else
						$varClase = "interior";
					break;
				case "igual":
				case "IGUAL":
				case "=":
					if($varDat == $varFormat["valor1"])
						$varClase = $varFormat["clase"];
					else
						$varClase = "interior";
					break;
				default:
					$varClase = "interior";
					break;
				}
			}
		return $varClase;
		}
	function GetFilas($sql) {
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		return $this->FetchArray($rs);
		}
	function SysConfig($varParam="") {
		$sql = "select valor from _sys_config where ide = '$varParam';";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		return $fila[0];
		}
	function SysPiePagina() {
		$sql = "select CONCAT((select valor from _sys_config where ide='SYSABR'), ' ', 
							  (select valor from _sys_config where ide='SYSVER'), ' | ',
							  (select valor from _sys_config where ide='EMPNOM'), '<br>', 
							  (select valor from _sys_config where ide='SYSCOR')) as piepag; ";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		return $fila[0];
		}
	function SysValor($varTab, $varFie, $varCon="") {
		$sql = "select $varFie from $varTab where _estado='A' ";
		$sql.= ($varCon<>"")?"and ".$varCon:"";
		$this->AbrirConexion();
		$rs = $this->Query($sql);
		$this->CerrarConexion();
		$fila = $this->FetchArray($rs);
		return $fila[0];
		}
	}
?>