//*** 
//*
//* @version 		2.12
//* @fecha 
//* @autor 
//* @ubicacion 
//* @dependecias 	

//* @version 		
//* @dependecias 	Se añadio la funcion STsendLovValue()

//* @version 		2.20
//* @dependecias 	Se añade la posibilidad del tag <HEADER> 
//*			El resultado se evalua y se coloca delante del arbol
//* @version 		2.22
//* @dependecias 	Se pueden añadir herramientas de usuario con addUserTool
//*			Los botones o imagenes se ordenan junto a la TOOLBOX
//* @version 		3.3
//* @dependecias 	Se añaden funciones y estilos para que las TOOL de usuario 
//*			se marquen en el mouseover y el mouseout
//* @version 		4.0 
//* @dependecias 	Se añade de forma automática todo el control de exportacion 
//*			de datos (botones, funciones,...)
//* @version 		4.01 
//* @dependecias 	Se añaden los parametros style y alt a la funcion addUserTool 
//*			Se permite cambiar el mensaje de No hay registros en noregMessage
//*			

//* @version 		5.00 
//* @dependecias 	Se mejora la recarga del menu para IE y Mozilla sin que haya que recargar
//*			toda la pagina
//*			Se añade una funcion de usuario  USER_ST_ongeneratemenu() que se ejecuta cada
//*			vez que el menu es repintado

//*			

//* @version 		5.10 
//* @dependecias 	Se añaden funciones para iluminar los TR por filas

//* @version 		5.30 
//* @dependecias 	Se añaden en servidor la inclusion de ficheros js y css

//* @version 		5.40
//* @dependecias 	Se mejora la apertura y cierre de las ramas con los estilos display
//*                 y se añade la funcion showNodesOfLevel(n) para mostrar el arbol abierto hasta los nodos
//*                 de nivel n y cerrado por debajo de ese nivel

//*******************************************************************************************************


var JSVERSION	= '5.40';




var AUTONUMBER = new Array();



// Establece la cookie
var current ;
var global_tem ;
var explodeState = false;

var prevIndentDisplayed;
var showMyDaughter;
var Outline;
var db = new Array();
var total = 1;

var FINDFORM = '';
var ADVFINDFORM = '';
var FORM_TREE_WIDTH = 600;
var CAPTION_FINDFORM = 'Filtrar';
var CAPTION = '';
var DEFAULT_TARGET 	= '';



var TOOLBOX	=true;
var USERTOOLBOX	=true;
var REGMESSAGE  =true;

var noregMessage 	= '<br>**No se encontró NINGÚN resultado <br>&nbsp;';

var __srcUSERTOOLBOX = "";


var selectedTR = new Object();



function USER_ST_onload(){}
function USER_ST_onunload(){}

function USER_ST_ongeneratemenu(){}



function TextToHtml ( str )
{

	TXTstr = new Array ('á','é','í','ó','ú','Á','É','Í','Ó','Ú');
	HTMLstr = new Array('&aacute;','&eacute;','&iacute;','&oacute;','&uacute;','&Aacute;','&Eacute;','&Iacute;','&Oacute;','&Uacute;');


	var i=0;
	while ( i<TXTstr.length )
	{
		reg = new RegExp(TXTstr[i], "g")
		str = str.replace ( reg, HTMLstr[i] )
		i++;

	}
return str;
}


//-----------------------------------------
function NextPage()
{
	
	document.forms[0].page.value = 1*document.forms[0].page.value +1 ;
	mkFilter();
	document.forms[0].submit();
	
}


//-----------------------------------------
function PreviousPage()
{
	
	document.forms[0].page.value = 1*document.forms[0].page.value -1 ;
	mkFilter();
	document.forms[0].submit();
	
}


//-----------------------------------------
function gotoPage(pg)
{
	
	document.forms[0].page.value = pg;
	mkFilter();
	document.forms[0].submit();
		
}








function getCurrState() {
  var label = "currState="
  var labelLen = label.length
  var cLen = document.cookie.length
  var i = 0
  while (i < cLen) {
    var j = i + labelLen
    if (document.cookie.substring(i,j) == label) {
      var cEnd = document.cookie.indexOf(";",j)
      if (cEnd == -1) { cEnd = document.cookie.length }
      return unescape(document.cookie.substring(j,cEnd))
    }
    i++
  }
  return ""
}

// Añade una nueva entrada
function dbAdd(mother,display,URL,indent,top,newitem, pub) {
  db[total] = new Object;
  db[total].mother = mother
  db[total].display = autoNumerate(indent) + TextToHtml(display);
  db[total].URL = URL
  db[total].indent = indent
  db[total].top = top
  db[total].newitem = newitem;
  total++
  }


function autoNumerate(indent)
{

var atn = '';
 if (typeof AUTONUM=='undefined' || AUTONUM==false)
 	return '';
 	
 if (typeof AUTONUMBER[indent]=='undefined')  
 		AUTONUMBER[indent]=1 
 	else
 		{ AUTONUMBER[indent]++; AUTONUMBER[indent+1]=0 } ;
 	for (i=0 ; i<=indent; i++) atn+= AUTONUMBER[i] + '.';
 	atn += ' ';

return atn;
}


// Guarda la seleccion actual en la cookie
function setCurrState(setting) {
  var expire = new Date();
  expire.setTime(expire.getTime() + ( 7*24*60*60*1000 ) ); // expire in 1 week
  document.cookie = "currState=" + escape(setting) + "; expires=" + expire.toGMTString();
  
  }

// cambia al padre, y actualiza la entrada
function toggle(n) {
  if (n != 0) {
    var newString = ""
    var expanded = current.substring(n-1,n) // of clicked item
    newString += current.substring(0,n-1)
    newString += expanded ^ 1 // Bitwise XOR clicked item
    newString += current.substring(n,current.length)
    setCurrState(newString) // write new state back to cookie
  }

  if (CBM_typeofNavigator()=='NN4' )
  {
  	history.go(0);
  	
  }
  else
  {
	  obj = CBM_getDocumentElement('ifmain');
      redrawMenuFrom(n);
	  	
	  USER_ST_ongeneratemenu();

  }
  
  
}



//abre todas las ramas del nodo n
// si n=-1 recorre el arbol completo

function redrawMenuFrom(n)
{

	if ( db.length==0 )
		return;

	current = getCurrState();

	if ( n==-1)
	{n=1; maxlevel=-1}
	else
	{maxlevel = db[n].indent;}
	




	
	prevIndentDisplayed = db[n].indent;
	showMyDaughter = current.substring(i-1,i);
	


	// recorre cada entrada del array
	for (var i =n; i < db.length; i++) 
	{

		if ( i>n && db[i].indent<=maxlevel)
			break;

		  currIndent = db[i].indent           // obtiene nivel de indentacion
		  expanded = current.substring(i-1,i) // estado actual


	  // muestra la entrada solo si encuentra una de las condiciones
		obj = document.getElementById('STid'+i);
		  if (currIndent == 0 || currIndent <= prevIndentDisplayed || 
			  (1*showMyDaughter == 1 && 1*currIndent-prevIndentDisplayed == 1) ) 
		  {

				obj.style.display = 'block';
				prevIndentDisplayed = currIndent;
				showMyDaughter = expanded;


				  var iconplus = typeof ICON_PLUS[currIndent]!='undefined' ? ICON_PLUS[currIndent] : ICON_PLUS[0];
				  var iconminus = typeof ICON_MINUS[currIndent]!='undefined' ? ICON_MINUS[currIndent] : ICON_MINUS[0];

				  icon = document.getElementById('STiconid_' + i);

				  if ( icon!=null )
				  {
					if ( expanded=='1' )
							icon.src =  IMG_BASE +'/selector/'+iconminus;
					else
							icon.src =  IMG_BASE+'/selector/'+iconplus; 
				   }
				  

		  }
		  else 
		  {

				obj.style.display = 'none';

		  }
		  
		  
	


	  
    }



	
}



// Muestra el arbol abierto hasta el nivel l
// y lo cierra para los niveles inferiores
function showNodesOfLevel(l)
{

	current = getCurrState();
	
	// recorre cada entrada del array
	for (var i =1; i < db.length; i++) 
	{
		cs = (db[i].indent<l) ? '1' : '0';
			
		current = current.substring(0,i-1) + cs + current.slice(i);
	
	}
	
	setCurrState(current);
	redrawMenuFrom(-1);
	USER_ST_ongeneratemenu();
	
	
	
}



// retorna con espacios (multiplos de 2) para indentar
function pad(n) {
  var result = ""
  for (var i = 1; i <= n; i++) { result += "&nbsp;&nbsp;&nbsp;&nbsp;" }
  return result
}

// expande todo
function explode() {
	  current = "";
	  initState="";
	  for (var i = 1; i < db.length; i++) {
	    initState += "1"
	    current += "1"
	    }
	  setCurrState(initState);


	  if (CBM_typeofNavigator()=='NN4' )
	  {
		history.go(0);

	  }
	  else
	  {
		  obj = CBM_getDocumentElement('ifmain');
		  redrawMenuFrom(-1);

		  USER_ST_ongeneratemenu();
	  }


  }

// colapsa todo
function contract() {
	  current = "";
	  initState="";
	  for (var i = 1; i < db.length; i++) {
	    initState += "0"
	    current += "0"
	    }
	  setCurrState(initState);



	  if (CBM_typeofNavigator()=='NN4' )
	  {
		history.go(0);

	  }
	  else
	  {
		  obj = CBM_getDocumentElement('ifmain');
		  redrawMenuFrom(-1);

		  USER_ST_ongeneratemenu();
	  }
  }

function tree_close() {
  window.parent.location = window.parent.content.location;
  }

// expande todo
function setExplodeState() {

	explodeState = true;

  }


function GenerateMenu()
{
	
	initTree();
	
	prevIndentDisplayed = 0;
	showMyDaughter = 0;
	Outline = "<form name=consulta id=consulta action='' onsubmit='return false;'>\n";
	
	
	// recorre cada entrada del array
	for (var i = 1; i < db.length; i++) 
	{
	  var currIndent = db[i].indent           // obtiene nivel de indentacion
	  var expanded = current.substring(i-1,i) // estado actual
	  var TARGET = db[i].top == "" ? DEFAULT_TARGET : db[i].top;
	  
	 
	  // muestra la entrada solo si encuentra una de las condiciones
	  //if (currIndent == 0 || currIndent <= prevIndentDisplayed || 
	  //    (1*showMyDaughter == 1 && 1*currIndent-prevIndentDisplayed == 1) ) 
	  {
		  newitem = "";
		  var itemgif = ( db[i].newitem == 1 ) ? '_new' : '';
		  
		  //*************** AÑADE EL INDENTADO
	  if (currIndent == 0 || currIndent <= prevIndentDisplayed || 
	      (1*showMyDaughter == 1 && 1*currIndent-prevIndentDisplayed == 1) ) 
	      	styledisplay = 'block';
	  else
	  		styledisplay = 'none';
	      
	      
	  	  Outline += "<table id=STid" + i + " style='display:" + styledisplay + "' border=0 cellspacing=1 cellpadding=1 width=" + TREE_WIDTH + ">" ; 
	  	  Outline += "<tr ><td ><IMG SRC=" + IMG_BASE + "/selector/blank.gif BORDER=0 width=" + (1+INDENT_WIDTH*currIndent) + " height=1></td>" ;
		   
		  
		  //*************** AÑADE LOS ICONOS plegado/desplegado
		  if ( !db[i].mother ) {
	
			// -------------------Items que son padres: indentacion
			var iconnoson = typeof ICON_NOSON[currIndent]!='undefined' ? ICON_NOSON[currIndent] : ICON_NOSON[0];
			Outline += "<td  width=" + PLUS_WIDTH + " valign=middle align=right><IMG SRC=" + IMG_BASE + "/selector/blank.gif BORDER=0 ><IMG SRC=\"" + IMG_BASE + "/selector/" + iconnoson + "\" BORDER=0>" 
		    }
		  else {
	
			// -------------------- Items hijos:  icono plegado/desplegado
		      var pWidth = currIndent>0 ? " width=" + PLUS_WIDTH : "";
		      var iconplus = typeof ICON_PLUS[currIndent]!='undefined' ? ICON_PLUS[currIndent] : ICON_PLUS[0];
		      var iconminus = typeof ICON_MINUS[currIndent]!='undefined' ? ICON_MINUS[currIndent] : ICON_MINUS[0];
	      	      if (current.substring(i-1,i) == '1') {
			Outline += "<td " + pWidth + "   valign=middle align=right>";
			Outline += "<A HREF=\"#\" onMouseOver=\"window.parent.status=\'Click to collapse\';return true;\" onClick=\"toggle(" + i + ");return false;\">"
			Outline += "<IMG SRC=" + IMG_BASE + "/selector/blank.gif BORDER=0 ><IMG ID=STiconid_" + i + " SRC=\"" + IMG_BASE + "/selector/" + iconminus + "\" BORDER=0>"   
			Outline += "</A>"
			}
		      else 
		      {
			Outline += "<td " + pWidth + " valign=middle align=right>";
			Outline += "<A HREF=\"#\" onMouseOver=\"window.parent.status=\'Click to expand\';return true;\" onClick=\"toggle(" + i + ");return false;\">"
			Outline += "<IMG SRC=" + IMG_BASE + "/selector/blank.gif BORDER=0 ><IMG ID=STiconid_" + i + "  SRC=\"" + IMG_BASE + "/selector/" + iconplus + "\"  BORDER=0>"  
			Outline += "</A>"
			}
	
		    }
	
		  //*************** AÑADE EL ICONO DEL TIPO DE ELEMENTO
		    if ( ITEMTYPE[db[i].newitem]!= '' )
		    	Outline += "<IMG SRC=\"" + ITEMTYPE[db[i].newitem] + "\" BORDER=0></td>";
		    
		     Outline += "</td>";
	    
		    // ********************** AÑADE EL URL 
		    var lclass = ( selectedItem == i ) ? 'selected' : 'level' + db[i].indent;
		    
		    if  (db[i].URL == "" || db[i].URL == null) 
		    	var display = '<font class=' + lclass + '>' + db[i].display + '</font>' 
		    else
		    {
		    	var href = '<A HREF=\"' + db[i].URL + '\"  TARGET=' + TARGET + '><font class=' + lclass + '>' ;
		    	
		    	if ( db[i].display.match(/·/) )
		    		var display = db[i].display.replace (/·([^·]*)·/g, href + '$1'  + '</font></A>');
			
			else
				var display = '<A HREF=\"' + db[i].URL + '\"  TARGET=' + TARGET + '><font class=' + lclass + '>' + db[i].display + '</font></A>';
		    			    	
//if ( i==4 ) alert(display);
		     }
		    
	            //Outline += " <td class=" + lclass + " width=" + parseInt(TREE_WIDTH-(1+INDENT_WIDTH*currIndent)) + " >" + display  + "</td></tr></table>\n"
	            Outline += " <td class=" + lclass + " width=" + parseInt(TREE_WIDTH-(1+INDENT_WIDTH*currIndent)) + " >" + display  + "</td></tr></table>\n"
		    
		    prevIndentDisplayed = currIndent
		    showMyDaughter = expanded
	
	    }
	
	
	
	
	  }
	
	Outline += '</td></tr></table></form>';
	
	
	Outline +=  ( (totalvisiblerows==0) ? '<table width=100% border=0><tr><td   class=pager align=center ><br><font color=red>' + noregMessage + '</td></tr></table>' : '');


	/*
	w=window.open()
	w.document.open('text/plain')
	w.document.write(Outline);
	w.document.close();
	*/	
	return (Outline )
	// end -->
	

	
	
}


function initTree()
{


	// Establece la cookie
	current = getCurrState()
	global_tem = new Array();

	//****************** Marca el estado inicial
	if (current == "" || current.length != db.length-1 ) 
	{
		current = ""
		initState = ""
		var initval = explodeState ? '1' : '0';
	
		for (i = 1; i < db.length; i++) 
		{
			initState += initval;
			current += initval;
		}
		
		setCurrState(initState)
	}
	

}



function hideTree()
{
	
	
	obj = CBM_getDocumentElement('ifmain');	
	
	obj.style.display ='none';
	
	
}




function showTree()
{
	
	obj = CBM_getDocumentElement('ifmain');
	
	obj.style.display ='block';
	
	
}








function GenerateTitle()
{
	
	var line = '';
	if (CAPTION!='')
	{
		line +=   (' <table width=' + TREE_WIDTH + ' cellspacing=0 cellpadding=0 border=0 height=20>  \n');
		line +=   (' <tr><td class=caption >' + CAPTION + '</td>  \n');
		line +=   (' </table>\n');
	}
	
	return (line)
}


function GenerateFindForm()
{
	
	var line = '';
	
	
	
	line +=  (' <!-- --------------FORMULARIO DE BUSQUEDA---------------->  \n');

	line +=  (' <form name="busquedas" id="FFbusquedas" action="selectTree.html" method="post" >  \n');


	fieldexist = false;
	var line_findform = '';
	if (FINDFORM != '' ) 
	{		

		var fnf = FINDFORM.split(',');

			for (var i=0; i<fnf.length; i++)
			{
				if ( fnf[i]!='' )
				{
					line_findform +=  (' <tr>  \n');
					line_findform +=  (' <td align=left  class=findform>' + fnf[i]  + '</td>  \n');
					line_findform +=  (' <td align=left  class=findform> <input type="text" name="rqfind_' + i + '"  id=label value="" size=20 maxlenght=45></td>  \n');
					line_findform +=  (' </tr>  \n');
					fieldexist = true;
				}
			}

	
	}

	if (ADVFINDFORM != '' ) 
	{		

		var fnf = ADVFINDFORM.split(',');
			for (var i=0; i<fnf.length; i+=3)
			{
				if ( fnf[i]!='' )
				{
					//line_findform +=  (' <tr>  \n');
					//line_findform +=  (' <td align=left  class=findform>' + fnf[i]  + '</td>  \n');
					//switch ( fnf[i+1] )
					//line_findform +=  (' <td align=left  class=findform> <input type="text" name="rqadvfind_' + fnf[i+2] + '"  id=label value="" size=20 maxlenght=45></td>  \n');
					j= Math.floor(1+i/3);
					Outline =  (' <tr>  \n');
					GenerateFormObject(FBdb[j], 'busquedas')  ;
					Outline +=  (' </tr>  \n');
					
					
					line_findform += Outline;
					
					line_findform +=  (' </tr>  \n');
					fieldexist = true;
				}
			}

	
	}


	if ( typeof WHEREFIELD!='undefined' && WHEREFIELD==true )
	{
		line_findform +=  (' <tr>  \n');
		line_findform +=  (' <td align=left  class=findform color=red>WHERE</td>  \n');
		//line_findform +=  (' <td align=left  class=findform> <input type="text" name="rqfindwh"  id=label value="" size=20 maxlenght=45></td>  \n');
		line_findform +=  (' <td align=left  class=findform> <textarea name="rqfindwh"  id=label value="" cols=20 rows=3 maxlenght=450 wrap></textarea></td>  \n');
		line_findform +=  (' </tr>  \n');
		fieldexist = true;
	}

	
	// si no hay campos de busque no añade la tabla para evitar el espacio que ocupa
	if ( fieldexist )
	{
		line +=  (' <table width=' + FORM_TREE_WIDTH + ' cellspacing=0 cellpadding=2 border=' + FORMBORDER + ' bgcolor=#f2f2f2 >  \n');
		line += line_findform;
		line +=  (' <tr><td align=center  colspan=2 ><input type=button id=findbtn value="' + CAPTION_FINDFORM + '" onclick=prepareForm();></td> <tr> \n');
		line +=  (' </table>  \n');
	}


	var HDN = HIDDENS.split(',');
	for (var j=0; j<HDN.length; j++)
		line +=  (' <input type=hidden  name=' + HDN[j] + ' value="">\n');
	
	//line +=  (' <input type=hidden  name=filter value="">\n');
	//line +=  (' <input type=hidden  name=page value="">\n');
	//line +=  (' <input type=hidden  name=config value="">\n');
	
	line +=  (' <input type=hidden  name=config value="' + STconfig + '">\n');
	
	line +=  (' </form>  \n');
	
	line +=  (' <!-- -------------- FIN FORMULARIO DE BUSQUEDA---------------->  \n');

	
	return (line)
}



function mkFilter()
{
	
	// compone el filtro
	if (FINDFORM != '' )
	{
	var fnf = FINDFORM.split(',');
	for (i=0; i<fnf.length; i++)
		document.forms.busquedas.filter.value += ( fnf[i]!='' ) ? document.forms.busquedas['rqfind_'+i].value + ',' : ',';
	document.forms.busquedas.filter.value = document.forms.busquedas.filter.value.slice(0,-1);
	}

	if (ADVFINDFORM != '' )
	{
		var fnf = ADVFINDFORM.split(',');
		for (i=0; i<fnf.length; i+=3)
		{
			if ( fnf[i+1].indexOf('between')!=-1 )
				document.forms.busquedas.advfilter.value +=  document.forms.busquedas['rqadvfind_'+ fnf[i+2] + '_A'].value + '::' + document.forms.busquedas['rqadvfind_'+ fnf[i+2] + '_B'].value + ',' + fnf[i+1] + ',' + fnf[i+2] + ',';
			else
			{
				var val = NVL( GetFormElementValue( document.forms.busquedas , 'rqadvfind_'+ fnf[i+2] ),'')
				document.forms.busquedas.advfilter.value += val  + ',' + fnf[i+1].replace(/=.*/,'') + ',' + fnf[i+2] + ',';
			}
		
		}
		document.forms.busquedas.advfilter.value = document.forms.busquedas.advfilter.value.slice(0,-1);
	}
}



function mkOrderby(i,j,or)
{
	
	// compone el filtro
	var ob = document.forms.busquedas.orderby.value;

	document.forms.busquedas.orderby.value = '' +  i + ',' + j + ',' + or;
	prepareForm();
	document.forms.busquedas.submit();
}



function prepareForm()
{

	if ( checkFindForm() )
	{
		mkFilter();

		//reinicia paginas
		document.forms.busquedas.page.value=1;
		document.forms.busquedas.submit();	
	}

}


function submitFindForm()
{
	prepareForm();
	
	
}


function checkFindForm()
{
	
	var ERROR = false;

	eval ( CheckerFUNCTION  ) ;

	return !ERROR ;
	
	
}



function GenerateWaiting()  // obsoleto: se hace en servidor
{
	
	var line = '';
	line +=   (' <table width=' + TREE_WIDTH + ' cellspacing=0 cellpadding=0 border=0 height=20>  \n');
	line +=   (' <tr><td ><br><br> &nbsp</td>  \n');
	line +=   (' <tr><td class=waiting ><br><br> Esta consulta puede llevar algunos segundos.</td>  \n');
	line +=   (' <tr><td class=waiting > Espere un momento, por favor...</td>  \n');
	line +=   (' <tr><td class=waiting >  <img src=' + IMG_BASE + '/selector/wait.gif border=0><br>&nbsp;</td>  \n');
	line +=   (' </table>\n');
	
	
	return (line)
}


function HideWaiting()
{
	
/*
	if (navigator.appName=="Netscape"){
		if ( typeof document['WAIT']!='undefined' )
			document['WAIT'].visibility="hide";
	} else {
		if ( typeof document.all['WAIT']!='undefined') 
			document.all['WAIT'].style.visibility="hidden";
	}
*/



if (typeof CBM_getDocumentElement('WAIT')!='undefined')
			CBM_hideLabel('WAIT');
	
	
}



function addUserTool(type, value, code, style, alt)
{
	
	style = typeof style=='undefined' || style=='' ? 'usertoolbox' : style;
	alt = typeof alt=='undefined' ? '' : alt;
	

	switch (type)
	{
		
		case 'button':
			__srcUSERTOOLBOX += ' <input id=' + style + ' type=button value="' + value + '" onclick="' + code.replace(/"/g,"'") + '" valign=middle>&nbsp;&nbsp; ';
		break;
		
		case 'image':
			__srcUSERTOOLBOX += ' <a href=# onclick="javascript:' + code.replace(/"/g,"'") + '" onmouseover="STtoolbox_OMover(this)" onmouseout="STtoolbox_OMout(this)"><img src="' + value + '" border=0 valing=bottom alt="' + alt + '"></a>&nbsp;&nbsp;' ;
		break;
		
		case 'separator':
			__srcUSERTOOLBOX += ' </td><td class=usertoolbox valign=middle>&nbsp;&nbsp;&nbsp;&nbsp;';
		break;
	}
		
		
	
	
}



function GenerateTools()
{
	
	var srcSYSTOOLBOX = '<td class=systoolbox width=80 align=center><input id=systoolbox style="width:25px" type=button value="+" onclick=explode() > <input id=systoolbox style="width:25px" type=button value="-" onclick=contract() ></td>';
	var srcUSERTOOLBOX = __srcUSERTOOLBOX!='' ? '<td class=usertoolbox valign=middle >&nbsp;&nbsp;&nbsp;&nbsp;' + __srcUSERTOOLBOX + '&nbsp;&nbsp;&nbsp;&nbsp;</td>' : '';


	var line = '';
	var pg = '';
	var prevbt = currpage>1 ? '<a href="javascript:PreviousPage();">&lt;&lt;</a>&nbsp;&nbsp;':'';
	var nextbt = currpage==totalpages ? '' : '<a href="javascript:NextPage();">&gt;&gt;</a>' ;
	
	var regstart = (parseInt((currpage-1)*rowsperpage) + 1);
	var regend = (1*currpage*rowsperpage)>totalrows ? totalrows : (1*currpage*rowsperpage);
	
	if (totalpages>0)
	{
		st = 10*parseInt('0'+ (currpage-1)/10)+1;
		end = st+9 >=totalpages ? totalpages : st+9;
		for(i=st;i<=end;i++)
			if (currpage==i)
				pg += '<b><font color=red>' + i + '</font></b>&nbsp;&nbsp;';
			else
				pg += '<a href="javascript:gotoPage(' + i + ');">[' + i + ']</a>&nbsp;&nbsp;';
	}
	
	var regMessage = typeof dirQuery!='undefined' ? '<tr><td   class=pager align=center >(Mostrados ' +  totalrows + ' ficheros en ' + (1+1*lastlevel) + (1+1*lastlevel>1 ?' niveles':' nivel') + ')</td></tr>'  :'<tr><td   class=pager align=center >(Mostrados registros ' + regstart + ' - ' + regend + ' de  ' + totalrows + ' )</td></tr>' ;
	

	
	if ( (total>1 && TOOLBOX) || srcUSERTOOLBOX!='' )
	{
		line +=  ('<form> <table  cellspacing=0 cellpadding=2 border=2>  \n');
		line +=  (  '<tr>' + (total>1 && TOOLBOX ? srcSYSTOOLBOX :'\n') + '' + srcUSERTOOLBOX + ' </td></tr>\n' );
		line +=  (' </table></form>  \n');
	}



	var line_msg = '';
	
	// El mensaje de no hay registros se traslada a GenerateMenu v4.01 para que aparezca debajo de las Tool y el HEADER
	//line_msg +=  ( (totalrows==0) ? '<tr><td   class=pager align=center ><hr><font color=red>' + noregMessage + '</td></tr>' : '');
	
	
	line_msg +=  ( (totalrows>0 && REGMESSAGE) ? regMessage : '');
	line_msg +=  ( totalpages>1 && total>1 ? '<tr><td  class=pager   align=center>' + prevbt + pg + nextbt + '<hr></td></tr>' :'' );
	
	if ( line_msg!='' )
	{
		line +=  ('<table cellspacing=0 cellpadding=2 >  \n');
		line +=  line_msg;
		line +=  (' </table> \n');
	}

	return (line)
	
}



function openFic (  url, params )
{
	
	
	if ( typeof params == 'undefined' ) params = 'toolbar=0,width=350,height=500,scrollbars,resizable=yes';
	
		

	if ( typeof window.FicTarget=='undefined' || (typeof window.FicTarget!='undefined' && window.FicTarget.closed) )
		window.FicTarget=window.open( url,Date.parse(new Date()), params);

	else
		window.FicTarget.location = url;

	window.FicTarget.focus();
	
	
	
	
}



// Es similar a openFic pero se le pasa como parametros el nombre del fichero de configuracion  y 
// el identificador del campo de la lista de valores

function STopenSelector ( lovid, config, params )
{

	var url = '/dbalche/selectTree.html?lovid=' + lovid + '&config=' + config;
	
	if ( typeof params == 'undefined' ) params = 'toolbar=0,width=350,height=500,scrollbars,resizable=yes';
	
		

	if ( typeof window.FicTarget=='undefined' || (typeof window.FicTarget!='undefined' && window.FicTarget.closed) )
		window.FicTarget=window.open( url,Date.parse(new Date()), params);

	else
		window.FicTarget.location = url;

	window.FicTarget.focus();
	
	
	
	
}



// Version para el selector de FBaddValue
// Esta funcion va en el selector y no en el formulario por eso se llama tal cual desde el selector mientras
// que FBaddValue se llama opener.FBaddValue
// Hace exactamente lo mismo pero no es necesario indicar el lovid porque lo toma de URL del selector
// y las llamadas las realiza con los objetos del opener.
// Es decir   FBsendLovValue(p_hidden,p0show,p12show)  <-->   opener.FBaddValue(lovid,p_hidden,p0show,p1show)
// Si solo se pasa el parametro p_hidden se acepta por defecto que p0show exite y tiene el mismo valor
function STsendLovValue ()
{
	var form = opener.document.forms[0];
	 
	 InitFormElement(form, GetParameter(document.location.search,'lovid'), arguments[0] );
	 
	 if ( arguments.length==1)
	 	InitFormElement(form, GetParameter(document.location.search,'lovid') + '0', arguments[0] );
	 
	 else
		 for (var i=1; i<arguments.length; i++) 
		 {
			 var objname = lovid + 1*(i-1);
			 if (typeof form[objname]!='undefined')		 
				InitFormElement(form, objname, arguments[i]);
		 }

}





// Funciones de control para el highlight de los botones de la tool box
// Estas funciones se llaman desde el href de las imagenes de la toolbox
function STtoolbox_OMover (obj)
{
	
	if( typeof obj.style!='undefined')
		obj.style.backgroundColor = 'white';
	
	return true;
}



function STtoolbox_OMout (obj)
{

	if( typeof obj.style!='undefined')
		obj.style.backgroundColor = '';

	return true;

}



// Estas funciones muestran o esconden el formulario de filtros
function STfilterDisplay(mode)
{
	ff= document.getElementById('FFbusquedas');
	
	if ( typeof mode!='undefined')
	{
		if (mode)
			ff.style.display='block';
		else
			ff.style.display='none';
	}
	else
	{
		if ( ff.style.display =='none' || ff.style.display=='')
			ff.style.display='block';
		else
			ff.style.display='none';
		
	}
	
	
	
}



// Funcion de control para la exportacion de datos
//
function STexportData()
{

        var form= document.forms.EXPRTDATA;
        form.submit();
}



// Funciones que iluminan los TR
function ST_tdOver(col)
{
	cl = col.getAttribute('className');
	
	col.setAttribute('className', cl + '_TDover');

}
function ST_tdOut(col)
{
	cl = col.getAttribute('className');
	
	i= cl.indexOf('_');
	if ( i!=-1)
		col.setAttribute('className', cl.slice(0,i) );

}


// Funciones que iluminan los TR 
// Funciones de control para el highlight de una fila o columna (TR o TD)

// Obtiene el id del TR al que pertenece un objeto dado
// el objeto dado puede ser cualquier objeto que este dentro del TR 
function ST_getTRId(obj) 
{
	ixobj = obj;
	
	while ( typeof ixobj.parentNode.id!='undefined' && String(ixobj.parentNode.id).slice(0,2) !='TR'  )
	{
	
		ixobj = ixobj.parentNode;
		
	}
		
	
	ret =  (typeof ixobj.parentNode.id=='undefined' )  ? '' : ixobj.parentNode.id;

return ret;

	
}


function ST_trOver(row)
{

	if (!TABLEOVER)
		return;
	//*********************************  Revisar para DOM
	if ( 	CBM_typeofNavigator()=='NN7' || 
		CBM_typeofNavigator().indexOf('Moz')!=-1)
	{
		//anulado porque tarda mucho
		/*
			cl = row.className;

			re = new RegExp(cl, "g")
			if ( String(cl).indexOf('_over')==-1)
			{
				clrep = String(cl) + '_over';
				row.parentNode.innerHTML = row.parentNode.innerHTML.replace(re,clrep);
			}
		*/
	}
	else
	{
		
		cl = row.getAttribute('className');

		for (var i=0; i<document.styleSheets.length; i++)
			if (document.styleSheets.item(i).href=="")
				break;
		if (i==document.styleSheets.length ) i=0;
		
		cssobj = document.styleSheets.item(i);


		if ( cssobj.cssText.indexOf(cl + '_over')!=-1 )
			row.setAttribute('className', cl + '_over');
	}
}


function ST_trOut(row)
{

	if (!TABLEOVER)
		return;

	//*********************************  Revisar para DOM
		if ( 	CBM_typeofNavigator()=='NN7' || 
			CBM_typeofNavigator().indexOf('Moz')!=-1)
		{
		//anulado porque tarda mucho
		/*	
			cl = row.className;

			re = new RegExp(cl, "g")
			
			if ( cl.indexOf('_over')!=-1 )
			{
				clrep = String(cl).slice(0,cl.indexOf('_') );
				row.parentNode.innerHTML = row.parentNode.innerHTML.replace(re,clrep);
			}
		
		*/		
		
		}
		else
		{
		

			cl = row.getAttribute('className');

			for (var i=0; i<document.styleSheets.length; i++)
				if (document.styleSheets.item(i).href=="")
					break;
			if (i==document.styleSheets.length ) i=0;

			cssobj = document.styleSheets.item(i);

			if ( cssobj.cssText.indexOf(cl)!=-1 && cl.indexOf('_over')!=-1 )
				row.setAttribute('className', cl.slice(0,cl.indexOf('_over')) );
		}
	

}


// Esta funcion la sobreescribe el usuario
function ST_trClick(row)
{


}




// Selecciona un TR determinado, la seleccion se acumula en selectedTR
function ST_trOn(id)
{
	

	if (!TABLEOVER)
		return;

	row = document.getElementById(id);


	if ( 	CBM_typeofNavigator()=='NN7' || 
		CBM_typeofNavigator().indexOf('Moz')!=-1)
	{
		
		cl = row.className;
		re = new RegExp(cl, "g")
		if ( String(cl).indexOf('_selected')==-1)
		{
			selectedTR[id]= true;
			clrep = String(cl) + '_selected';
			row.parentNode.innerHTML = row.parentNode.innerHTML.replace(re,clrep) 
		}
	}
	else
	{


		cl = row.getAttribute('className');
		if ( String(cl).indexOf('_')!=-1)
			cl = String(cl).slice(0,cl.indexOf('_') )

		for (var i=0; i<document.styleSheets.length; i++)
			if (document.styleSheets.item(i).href=="")
				break;
		if (i==document.styleSheets.length ) i=0;
		
		cssobj = document.styleSheets.item(i);

		if ( cssobj.cssText.indexOf(cl + '_selected')!=-1 )
		{
			selectedTR[id]= true;
			row.setAttribute('className', String(cl) + '_selected');
		}
	}
	
}


// Deselecciona un TR determinado
function ST_trOff(id)
{



	

	if (!TABLEOVER)
		return;

	row = document.getElementById(id);


	if ( 	CBM_typeofNavigator()=='NN7' || 
		CBM_typeofNavigator().indexOf('Moz')!=-1)
	{

		cl = row.className;
		re = new RegExp(cl, "g")
		
		if ( String(cl).indexOf('_selected')!=-1)
		{
			delete selectedTR[id];
			clrep = String(cl).slice(0,cl.indexOf('_') );
			row.parentNode.innerHTML = row.parentNode.innerHTML.replace(re,clrep);
		}
	}
	else	
	{

		cl = row.getAttribute('className');
		if ( String(cl).indexOf('_')!=-1)
			cl = String(cl).slice(0,cl.indexOf('_') )

		for (var i=0; i<document.styleSheets.length; i++)
			if (document.styleSheets.item(i).href=="")
				break;
		if (i==document.styleSheets.length ) i=0;
		
		cssobj = document.styleSheets.item(i);
		if ( cssobj.cssText.indexOf(cl + '_selected')!=-1 )
		{
			delete selectedTR[id];
			row.setAttribute('className', cl );
		}

	}




}


// Selecciona un unico TR y deselecciona todo los demas
function ST_trOnX(id)
{
	

	if (!TABLEOVER)
		return;



	row = document.getElementById(id);



	//*********************************  Revisar para DOM
	if ( 	CBM_typeofNavigator()=='NN7' || 
		CBM_typeofNavigator().indexOf('Moz')!=-1)
	{
		
		cl = row.className;
		if ( String(cl).indexOf('_')!=-1)
			cl = String(cl).slice(0,cl.indexOf('_') )

		for ( var i in selectedTR)
			ST_trOff(i)

		ST_trOn(id);
		
	}
	else
	{
		
		cl = row.getAttribute('className');

		if ( String(cl).indexOf('_')!=-1)
			cl = String(cl).slice(0,cl.indexOf('_') )

		for (var i=0; i<document.styleSheets.length; i++)
			if (document.styleSheets.item(i).href=="")
				break;
		if (i==document.styleSheets.length ) i=0;
		
		cssobj = document.styleSheets.item(i);
		if ( cssobj.cssText.indexOf(cl + '_selected')!=-1 )
		{
			for ( var i in selectedTR)
				ST_trOff(i)

			ST_trOn(id);
		}
		
	}


	
	
}




