// You can find instructions for this file at http://www.treeview.net

//Environment variables are usually set at the top of this file.
USETEXTLINKS = 1
STARTALLOPEN = 0
USEFRAMES = 0
USEICONS = 0
WRAPTEXT = 1
PRESERVESTATE = 1
HIGHLIGHT=0

// In this case we want the whole tree to be built,
// even those branches that are closed. The reason is that
// otherwise some form elements might not be built at all
// before the user presses "Get Values"
BUILDALL = 1

// This configuration file is used to demonstrate how to add checkboxes to your tree.
// If your site will not display checkboxes, pick a different configuration file as
// the example to follow and adapt.

// Notes:
// If you are going to set USEICONS = 1, then you will want to edit the gif files and
// remove the white space on the right


// Auxiliary functions for the contruction of the tree
// You will mcertainly want to change these functions for your own purposes

// If you want to add checkboxes to the folder you will have to create a function
// similar to this one to do that and call it below in the tree construction section

// These functions are directly related with the additional JavaScript in the
// page holding the tree (demoCheckbox.html), where the form handling code
// resides

function generateCheckBox(parentfolderObject, itemLabel, checkBoxDOMId) {
        var newObj;

        // Read the online documentation for an explanation of insDoc and gLnk,
    // they are the base of the simplest Treeview trees
        newObj = insDoc(parentfolderObject, gLnk("R", itemLabel, "javascript:parent.op()"))

    // The trick to show checkboxes in a tree that was made to display links is to
        // use the prependHTML. There are general instructions about this member
    // in the online documentation
        newObj.prependHTML = "<td valign=middle><input type=checkbox id="+checkBoxDOMId+"></td>"
}

// Function similar to the above, but instead of creating checkboxes, it creates
// radio buttons
function generateRadioB(parentfolderObject, itemLabel, checkBoxDOMId) {
        var newObj;
        // Read the online documentation for an explanation of insDoc and gLnk,
    // they are the base of the simplest Treeview trees
        newObj = insDoc(parentfolderObject, gLnk("R", itemLabel, "javascript:parent.op()"))

    // The trick to show checkboxes in a tree that was made to display links is to
        // use the prependHTML. There are general instructions about this member
    // in the online documentation
        newObj.prependHTML = "<td valign=middle  style='font-size:8pt;font-family:Arial;text-decoration:none;color:black'><input type=radio class=myRadioBut name=hourPick id="+checkBoxDOMId+"></td>"
}


function expandTree(folderObj)
{
alert("hola")
    var childObj;
    var i;

    //Open folder
    if (!folderObj.isOpen)
      parent.treeframe.clickOnNodeObj(folderObj)

    //Call this function for all folder children
    for (i=0 ; i < folderObj.nChildren; i++)  {
      childObj = folderObj.children[i]
      if (typeof childObj.setState != "undefined") {//is folder
        expandTree(childObj)
      }
    }
}

function collapseTree()
{
        //hide all folders
        parent.treeframe.clickOnNodeObj(parent.treeframe.foldersTree)
        //restore first level
        parent.treeframe.clickOnNodeObj(parent.treeframe.foldersTree)
}

function get_consulta()
{
        if (typeof window.ActiveXObject != 'undefined' )
        {
                xmlDocCons = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
                xmlDocCons = new XMLHttpRequest();
        }
        coma='command=ora_consulta '+ cat
        serv='service=RAWTEXTPROVIDER'
        leng='lengua='+lengua
	d = new Date();
        TimeStamp=d.getTime()
        times='timeout=' +  TimeStamp
        url=http+'?'+app+'&'+coma+'&'+sav+'&'+serv+'&'+cat+'&'+leng+'&'+times
        xmlDocCons.open( "GET", url , false );
        xmlDocCons.send( null );
	recibir_lista_consulta();

	// Add the ruta options before calling translate.

	
        var actu_val=actu.substring(5,6);
        if ( actu_val == '1' )
        {
		add_utilidades();
        	add_rutas();
        }
}


function add_utilidades()
{

        var th = '<table border="0" cellspacing="0" cellpadding="0" width="200px">'
        th = th + '<tr bgcolor="#FFFFFF" >'

	// Si no pongo la anchura, no queda bien. No se porque.

        th = th + '<td width="27px"><input name="util_radiobutton" type="radio" class="myRadioBut" value="util_radiobutton"></td>'
        th = th + ' <td class="text_class1" id="text_desc_shape" ></td>'
        th = th + '   </tr>'
	th = th + '</table>'

        document.getElementById("formUTIL").innerHTML = document.getElementById("formUTIL").innerHTML + th
}

function add_rutas()
{

        var th = '<table border="0" cellspacing="0" cellpadding="0" width="200px">'
        th = th + '<tr bgcolor="#FFFFFF" >'

	// Si no pongo la anchura, no queda bien. No se porque.

        th = th + '<td width="27px"><input name="rutas_radiobutton" type="radio" class="myRadioBut" value="rutas_radiobutton"></td>'
        th = th + ' <td class="text_class1" id="text_ruta_corta" ></td>'
        th = th + '   </tr>'
        th = th + ' <tr bgcolor="#FFFFFF">'
        th = th + '     <td><input name="rutas_radiobutton" type="radio" class="myRadioBut" value="rutas_radiobutton"></td>'
        th = th + '     <td class="text_class1" id="text_ruta_rapida"></td>'
        th = th + '   </tr>'
        th = th + ' <tr bgcolor="#FFFFFF">'
        th = th + '     <td><input name="rutas_radiobutton" type="radio" class="myRadioBut" value="rutas_radiobutton"></td>'
        th = th + '     <td class="text_class1" id="text_ruta_trp"></td>'
        th = th + '      </tr>'
	th = th + '</table>'

        document.getElementById("formRUTAS").innerHTML = document.getElementById("formRUTAS").innerHTML + th
}



function recibir_lista_consulta()
{
	var mytext, aux
	var id_gena, nodo, texto_es
	var indArrayDatos

	if ( typeof console != 'undefined' ) console.log("recibir_lista_consulta")

        if ( xmlDocCons.readyState != 4 )
	{
		alert(xmlDocCons.readyState)
		return ;
	}
        mytext=xmlDocCons.responseText

        // Quitamos la etiqueta HTML
        aux=mytext.split("<HTML>\n")
        mytext=aux[1]
        aux=mytext.split("\n</HTML>")
	if (aux[1] == null) 
	{
		alert('No hay consultas para el perfil actual')	;
		return	;
	}

       	mytext=aux[0] ;
	mytext=convertir_caracteres(mytext)

	// descomponer respuesta mytext en registros
	var array_lineas = mytext.split("\n")
	var array_datos
	for (var i = 0 ; i < array_lineas.length  ; i++)
	{
		array_datos=array_lineas[i].split(",")
		indArrayDatos=arbol_Consulta.length
		arbol_Consulta[indArrayDatos]= new Array(15)
		arbol_Consulta[indArrayDatos][0]=array_datos[1]  // ID_GENAMAP
		arbol_Consulta[indArrayDatos][1]=array_datos[2]  // NODO
		arbol_Consulta[indArrayDatos][2]=array_datos[3]  // TEXT_ES
		arbol_Consulta[indArrayDatos][3]=array_datos[4]  // TEXTO_EU
		arbol_Consulta[indArrayDatos][4]=array_datos[5]  // TEXTO_IN
		arbol_Consulta[indArrayDatos][5]=array_datos[6]  // TEXTO_FR
		arbol_Consulta[indArrayDatos][6]=array_datos[0]  // ID_TEXTO
		arbol_Consulta[indArrayDatos][7]=array_datos[7]  // F_AYUDA
		arbol_Consulta[indArrayDatos][8]=array_datos[8]  // SERV_GENASERVER
		arbol_Consulta[indArrayDatos][9]=array_datos[9]  // FUNCION
		arbol_Consulta[indArrayDatos][10]=array_datos[10]  // CAPA
		arbol_Consulta[indArrayDatos][11]=array_datos[11]  // RESP_CORTA
		arbol_Consulta[indArrayDatos][12]=array_datos[12]  // ACCION_PREVIA
		arbol_Consulta[indArrayDatos][13]=array_datos[13]  // SERV_GENA_PREVIO
		arbol_Consulta[indArrayDatos][14]=array_datos[14]  // FUNCION_PREVIA

		id_gena=arbol_Consulta[indArrayDatos][0]
		nodo=arbol_Consulta[indArrayDatos][1]
		texto_es=arbol_Consulta[indArrayDatos][2]

                // Generar boton
		if ( (id_gena != "") && (nodo == "") )
		{
			// no es null y no tiene nodo padre, se crea boton
			generateRadioB(foldersTree, "", id_gena)
		}
		else if (id_gena == "")
		{
			// es null, se crea nodo padre
			aux1 = insFld(foldersTree, gFld("", "javascript:parent.op()"))

		}
		else
		{
			// no es null, pero tiene nodo, se crea boton hijo
			generateRadioB(aux1, "", id_gena)
		}
	}
	if (i==0)
		alert("Arbol de consulta vacio")

	if (param_id == true)
		showLimpiarConsulta()
}


foldersTree = gFld("")
foldersTree.treeID = "ConsultaTree"

