<!--
//////////////////
//
// drawBranch() - Usada por drawTree(). Pinta recursivamente todos los nodos ahora visibles

function drawBranch(startNode,structureString) {
	var children = extractChildrenOf(startNode);
	var currentIndex = 1;
	while (currentIndex <= children.length) {
		outputFrame.write(structureString);
		if (children[currentIndex].type == 'link') {
			//APUNTAMOS AL FRAME POR DEFECTO O AL QUE INDIQUE LA PROPIEDAD TARGET
			if (children[currentIndex].target == ""){var targetFrame = defaultTargetFrame;}else{var targetFrame = children[currentIndex].target	}
			outputFrame.write("<A HREF='" +children[currentIndex].url+ "' TARGET='" +targetFrame+ "'><IMG SRC='" +img_link+ "' BORDER=0 WIDTH=13 HEIGHT=10 ALIGN=TEXTTOP>&nbsp;" +children[currentIndex].name+ "</A><BR>\n")	
		}else{
			var newStructure = structureString;
			//SI ESTÁ CERRADO, NO HAY QUE PINTAR LAS RAMAS, EN CASO CONTRARIO, LLAMAMOS A DRAWBRANCH() OTRA VEZ
			if (children[currentIndex].open == 0) {
				outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" +children[currentIndex].id+ "',1)\">")
				outputFrame.write("<IMG SRC='" +img_cerrado+ "' BORDER=0 WIDTH=13 HEIGHT=10 ALT='Click para abrir' ALIGN=TEXTTOP>&nbsp;<B>" +children[currentIndex].name+ "</B></A><BR>\n")
			}else{
				outputFrame.write("<A HREF=\"javascript:top.toggleFolder('" +children[currentIndex].id+ "',0)\">");
				outputFrame.write("<IMG SRC='" +img_abierto+ "' BORDER=0 WIDTH=13 HEIGHT=10 ALT='Click para cerrar' ALIGN=TEXTTOP>&nbsp;<B>" +children[currentIndex].name+ "</B></A><BR>\n");
				newStructure = newStructure + "<IMG SRC='" +img_blank+ "' BORDER=0 WIDTH=10 HEIGHT=10 ALIGN=TEXTTOP>";
				drawBranch(children[currentIndex].id,newStructure); 
			}
		}
		currentIndex++;
	}
}

//////////////////
//
// toggleFolder() - Abre/cierra las carpetas (folder nodes)

function toggleFolder(id,status) {
	var nodeIndex = indexOfNode(id); 
	treeData[nodeIndex].open = status; 
	timeOutId = setTimeout("drawTree()",100)}

//////////////////
//
// indexOfNode() -  Encuentra el índice del nodo cuya id buscamos en la colección treeData

function indexOfNode(id) {
	var currentIndex = 1;
	while (currentIndex <= treeData.length) {
		if ((treeData[currentIndex].type == 'root') || (treeData[currentIndex].type == 'folder')) {
			if (treeData[currentIndex].id == id) {return currentIndex}} 
		currentIndex++} 
	return -1}

//////////////////
//
// extractChildrenOf() - Extrae y devuelve una colección conteniendo todos los hijos del nodo

function extractChildrenOf(node) {
	var children = new Collection();
	var currentIndex = 1; 
	while (currentIndex <= treeData.length) {
		if ((treeData[currentIndex].type == 'folder') || (treeData[currentIndex].type == 'link')) {
			if (treeData[currentIndex].parent == node) {
				children.add(treeData[currentIndex])}}
		currentIndex++} 
	return children}

//////////////////
//
// Collection() Creamos la colección

function Collection() {
	this.length = 0; 
	this.add = add; 
	return this}

//////////////////
//
// add() - Añadimos un objeto a la colección

function add(object) {
	this.length++; 
	this[this.length] = object}


//////////////////
//
// RootNode() - Objeto nodo raiz
//  USO: treeData.add(new RootNode("<ID>","<NAME>","<URL>","<TARGET>")); 
// NOTA: Sólo debe haber un único root node, y debe ser el primer nodo
//       <TARGET> puede omitirse; usará el (defaultTargetFrame)

function RootNode(id,name,url,target) {
	this.id = id;
	this.name = name;
	this.url = url;
	this.target = target;
	this.type = 'root';
	return this}

//////////////////
//
// FolderNode() - Objeto nodo con hijos (carpeta)
//  USO: treeData.add(new FolderNode("<ID>","<PARENT ID>","<NAME>"));
// NOTA: Los folder nodes deben tener un nodo padre válido y deberían tener hijos

function FolderNode(id,parent,name) {
	this.id = id;
	this.parent = parent;
	this.name = name;
	this.type = 'folder';
	this.open = 0;
	return this}

//////////////////
//
// LinkNode() - Objeto nodo sin hijos (página)
//  USO: treeData.add(new LinkNode("<PARENT ID>","<NAME>","<URL>","<TARGET>"));
//       <TARGET> puede omitirse; se usará el (defaultTargetFrame)

function LinkNode(parent,name,url,target) {
	this.parent = parent;
	this.name = name;
	this.url = url;
	this.target = target;
	this.type = 'link';
	return this}

// -->