//	***************************************
//	***************************************
//	***                                 ***
//	***        jsDynamicTree v1.0       ***
//	*** Developed by Yari Podio Casares ***
//	***   Barcelona, Spain; june 2003   ***
//	***                                 ***
//	***************************************
//	***************************************

jsDTreeDefaultPage = 'jsDynamicTreeDefault.html';
if (!document.jsDTreeImagePath) {document.jsDTreeImagePath = 'js/jsDynamicTree/images/';}

jsDTreePunto = new Image();
jsDTreePunto.src = document.jsDTreeImagePath + 'punto.gif';
jsDTreePuntoon = new Image();
jsDTreePuntoon.src = document.jsDTreeImagePath + 'puntoon.gif';
jsDTreeDown = new Image();
jsDTreeDown.src = document.jsDTreeImagePath + 'down.gif';
jsDTreeDownon = new Image();
jsDTreeDownon.src = document.jsDTreeImagePath + 'downon.gif';
jsDTreeUp = new Image();
jsDTreeUp.src = document.jsDTreeImagePath + 'up.gif';
jsDTreeUpon = new Image();
jsDTreeUpon.src = document.jsDTreeImagePath + 'upon.gif';
jsDTreeRefresh = new Image();
jsDTreeRefresh.src = document.jsDTreeImagePath + 'refresh.gif';
jsDTreeRefreshon = new Image();
jsDTreeRefreshon.src = document.jsDTreeImagePath + 'refreshon.gif';
jsDTreeClose = new Image();
jsDTreeClose.src = document.jsDTreeImagePath + 'close.gif';
jsDTreeCloseon = new Image();
jsDTreeCloseon.src = document.jsDTreeImagePath + 'closeon.gif';
jsDTreePlus = new Image();
jsDTreePlus.src = document.jsDTreeImagePath + 'plus.gif';
jsDTreeMinus = new Image();
jsDTreeMinus.src = document.jsDTreeImagePath + 'minus.gif';
jsDTreePoint = new Image();
jsDTreePoint.src = document.jsDTreeImagePath + 'point.gif';

jsDTreeMessages = new Array(
	new Array(
		'Move down to the next node in the tree',
		'Move up to the previous node in the tree',
		'Refresh the selected node',
		'Close the tree',
		'Loading...'
	),
	new Array(
		'Seleccionar el siguiente nodo del árbol',
		'Seleccionar el nodo anterior del árbol',
		'Actualizar el nodo seleccionado',
		'Cerrar el árbol',
		'Cargando...'
	),
	new Array(
		'Seleccionar el següent node de l\'arbre',
		'Seleccionar el node anterior de l\'arbre',
		'Actualitzar el node seleccionat',
		'Tancar l\'arbre',
		'Carregant...'
	)
);

function strltrim() {return this.replace(/^\s+/,'');}
function strrtrim() {return this.replace(/\s+$/,'');}
function strtrim() {return this.replace(/^\s+/,'').replace(/\s+$/,'');}
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

function jsDTree() {
	
	if (isNaN(jsDTree.count)) {jsDTree.count = 0;}
	this.index = jsDTree.count;
	this.name = "jsDTree" + (jsDTree.count++);
 	this.obj = this.name + "Object";
 	eval(this.obj + " = this")

	if (arguments[0]) {this.width = arguments[0];} else {this.width = '100%';}
	if (arguments[1]) {this.height = arguments[1];}
	if (arguments[2]) {this.language = arguments[2];} else {this.language = 0;}
	if (arguments[3]) {this.Page = arguments[3];} else {this.Page = jsDTreeDefaultPage;}

	this.ShowBar = true;
	this.Loading = false;
	this.AllowClose = true;
	this.ShowPlusMinus = true;

	this.MainClass;
	this.BarClass;
	this.OverClass;
	this.SelectedClass;
	this.ScrollClass;

	this.Elements = new Array();
	this.ElementsToLoad = new Array();
	this.SelectAfterLoad = -1;

	this.doLoad = jsDTreeDoLoad;
	this.endLoad = jsDTreeEndLoad;
	this.beginLoad = jsDTreeBeginLoad;
	this.build = jsDTreeBuild;
	this.buildTree = jsDTreeBuildTree;
	this.serialize = jsDTreeSerialize;
	this.deserialize = jsDTreeDeserialize;
	
	this.doOut = jsDTreeDoOut;
	this.doOver = jsDTreeDoOver;
	this.doClick = jsDTreeDoClick;
	this.selectPrev = jsDTreeSelectPrev;
	this.selectNext = jsDTreeSelectNext;
	this.makeVisible = jsDTreeMakeVisible;
	this.selectElement = jsDTreeSelectElement;
	this.getElementById = jsDTreeGetElementById;
	this.getElementIndex = jsDTreeGetElementIndex;
	
	this.setPage = jsDTreeSetPage;
	this.setTitle = jsDTreeSetTitle;
	this.setStyles = jsDTreeSetStyles;
	this.setLanguage = jsDTreeSetLanguage;

	this.resize = jsDTreeResize;
	this.addElement = jsDTreeAddElement;
	this.addElementRuntime = jsDTreeAddElementRuntime;
	this.getElementById = jsDTreeGetById;
	this.clear = jsDTreeClear;
	
}

function jsDTreeSerialize() {
	var txt = ' ',i;
	if (this.SelectedElement) {txt += this.SelectedElement.id;}
	for (i=0;i<this.Elements.length;i++) {txt += this.Elements[i].serialize();}
	return txt;
}

function jsDTreeDeserialize() {
	if (arguments[0]) {
		var elems = arguments[0].split('|'),i,cel,tosel;
		if (elems.length > 0) {
			if (elems[0].trim() != '') {tosel = elems[0].trim();}
			for (i=1;i<elems.length;i++) {
				var cel = this.getElementById(elems[i].trim());
				if ((cel)&&(!cel.opened)) {cel.expand();}
			}
		} else if (arguments[0].trim() != '') {tosel = arguments[0].trim();}
		if (tosel) {this.selectElement(tosel);}
	}
}

function jsDTreeMakeVisible() {
	if (arguments[0]) {
		var el = this.getElementById(arguments[0]);
		if (el) {el.makeVisible();}
	}
}

function jsDTreeSelectElement() {
	if (arguments[0]) {
		var el = this.getElementById(arguments[0]);
		if (el) {
			if ((el.parent)&&(!el.parent.opened)) {el.parent.expand();}
			el.select();
			return true;
		}
	}
	return false;
}

function jsDTreeGetElementById() {
	if (arguments[0]) {
		var i,el;
		for (i=0;i<this.Elements.length;i++) {
			if (el = this.Elements[i].getElementById(arguments[0])) {return el;}
		}
	}
	return null;
}

function jsDTreeSetPage() {
	if (arguments[0]) {this.Page = arguments[0];}
}

function jsDTreeSetTitle() {
	if (arguments[0]) {this.Title = arguments[0];}
}

function jsDTreeSetStyles() {
	if (arguments[0]) {this.MainClass = arguments[0];}
	if (arguments[1]) {this.BarClass = arguments[1];}
	if (arguments[2]) {this.OverClass = arguments[2];}
	if (arguments[3]) {this.SelectedClass = arguments[3];}
	if (arguments[4]) {this.ScrollClass = arguments[4];}
}

function jsDTreeSetLanguage() {
	if (arguments[0]) {this.language = arguments[0];}
}

function jsDTreeDoLoad() {
	if (this.ElementsToLoad.length > 0) {
		this.Loading = true;
		this.ElementLoading = this.ElementsToLoad[0];
		document.ElementLoading = this.ElementLoading;
		var url = this.Page + '?element=' + this.ElementLoading.id;
		this.DownloadObject.src = url;
	}
}

function jsDTreeEndLoad(src) {
	if (document.ElementLoading) {document.ElementLoading.endLoad(src);}
}

function jsDTreeBeginLoad() {
	if (arguments[0]) {
		this.ElementsToLoad = this.ElementsToLoad.concat(arguments[0]);
		if (!this.Loading) {this.doLoad();}
	}
}

function jsDTreeBuild() {

	this.Messages = jsDTreeMessages[this.language];
	this.innerHeight = (this.ShowBar) ? this.height - 17 : this.height;
	
	this.innerHTML = '<iframe id="' + this.name + 'Dwn" name="' + this.name + 'Dwn" style="display:none;" onload="' + this.obj + '.endLoad();"></iframe>';
	this.innerHTML += '<div id="' + this.name + 'Div" style="width:' + this.width;
	if (this.height) {this.innerHTML += ';height:' + this.height + ';';}
	this.innerHTML += '">';
	if (this.ShowBar) {
		this.innerHTML += '<table border="0" cellpadding="0" cellspacing="0" width="100%" class="' + this.BarClass + '" height="17">';
		this.innerHTML += '<tr><td width="10"' + ((this.ShowPlusMinus) ? '' : ' style="display:none;"') + '><img src="' + jsDTreePunto.src + '" border="0"></td>';
		this.innerHTML += '<td valign="middle" width="20"><a onmouseover="Javascript:' + this.name + 'Object.doOver(\'Down\');" onmouseout="Javascript:' + this.name + 'Object.doOut(\'Down\');" onclick="Javascript:' + this.name + 'Object.doClick(\'Down\');" style="cursor:hand;"><img id="' + this.name + 'Down" src="' + jsDTreeDown.src + '" border="0" alt="' + this.Messages[0] + '"></a></td>';
		this.innerHTML += '<td valign="middle" width="20"><a onmouseover="Javascript:' + this.name + 'Object.doOver(\'Up\');" onmouseout="Javascript:' + this.name + 'Object.doOut(\'Up\');" onclick="Javascript:' + this.name + 'Object.doClick(\'Up\');" style="cursor:hand;"><img id="' + this.name + 'Up" src="' + jsDTreeUp.src + '" border="0" alt="' + this.Messages[1] + '"></a></td>';
		if (this.Title) {this.innerHTML += '<td align="center" valign="middle" class="' + this.BarClass + '">' + this.Title + '</td>';}
		this.innerHTML += '<td valign="middle" align="right"';
		if (this.Title) {this.innerHTML += ' width="20"';}
		this.innerHTML += '><a onmouseover="Javascript:' + this.name + 'Object.doOver(\'Refresh\');" onmouseout="Javascript:' + this.name + 'Object.doOut(\'Refresh\');" onclick="Javascript:' + this.name + 'Object.doClick(\'Refresh\');" style="cursor:hand;"><img id="' + this.name + 'Refresh" src="' + jsDTreeRefresh.src + '" border="0" alt="' + this.Messages[2] + '"></a></td>';
		if (this.AllowClose) {
			this.innerHTML += '<td valign="middle" width="20" align="right"><a onmouseover="Javascript:' + this.name + 'Object.doOver(\'Close\');" onmouseout="Javascript:' + this.name + 'Object.doOut(\'Close\');" onclick="Javascript:' + this.name + 'Object.doClick(\'Close\');" style="cursor:hand;"><img id="' + this.name + 'Close" src="' + jsDTreeClose.src + '" border="0" alt="' + this.Messages[3] + '"></a></td>';
		}
		this.innerHTML += '<td width="5"><img src="' + jsDTreePunto.src + '" border="0"></td>';
		this.innerHTML += '</tr></table>';
	}
	this.innerHTML += '<div id="' + this.name + 'ContentDiv" style="width:' + this.width + ';height:' + this.innerHeight + ';overflow:visible;" class="' + this.ScrollClass + '">';
	this.innerHTML += '<table id="' + this.name + 'ContentTable" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td><img src="' + jsDTreePunto.src + '"></td></tr></table>';
	this.innerHTML += '</div>';
	this.innerHTML += '</div>';

	document.write(this.innerHTML);
	
	this.div = document.getElementById(this.name + 'Div');
	this.ContentDiv = document.getElementById(this.name + 'ContentDiv');
	this.ContentTable = document.getElementById(this.name + 'ContentTable');
	this.ContentTable.className = this.MainClass;
	this.DownloadObjectFrame = window.frames[this.name + 'Dwn'];
	this.DownloadObject = document.getElementById(this.name + 'Dwn');
	
	this.buildTree();
	
}

function jsDTreeBuildTree() {
	var tr = this.ContentTable.insertRow(this.ContentTable.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<img src="' + jsDTreePunto.src + '" border="0">';
	if (this.Elements.length > 0) {tr.height = 10;}
	for (var i=0;i<this.Elements.length;i++) {this.Elements[i].build();}
	if (this.ContentTable.offsetWidth < this.width) {this.ContentTable.width = this.width;}
	if (this.ContentTable.offsetHeight < this.innerHeight) {
		if (this.Elements.length > 0) {
			var tr = this.ContentTable.insertRow(this.ContentTable.rows.length);
			td = tr.insertCell(tr.cells.length);
			td.innerHTML = '<img src="' + jsDTreePunto.src + '" border="0">';
		}
		this.ContentTable.height = this.innerHeight;
	}
}

function jsDTreeDoOut() {
	if (arguments[0]) {
		img = document.getElementById(this.name + arguments[0]);
		eval('img.src = jsDTree' + arguments[0] + '.src');
		window.status = '';
	}
}

function jsDTreeDoOver() {
	if (arguments[0]) {
		img = document.getElementById(this.name + arguments[0]);
		eval('img.src = jsDTree' + arguments[0] + 'on.src');
		window.status = img.alt;
	}
}

function jsDTreeDoClick() {
	if (arguments[0] == 'Close') {this.div.style.display = 'none';}
 	else if (arguments[0] == 'Up') {this.selectPrev();}
	else if (arguments[0] == 'Down') {this.selectNext();}
	else if ((arguments[0] == 'Refresh')&&(!this.Loading)&&(this.SelectedElement)) {this.SelectedElement.beginLoad();}
}

function jsDTreeSelectPrev() {
	if (this.SelectedElement) {this.SelectedElement.selectPrev();}
	else if (this.Elements.length > 0) {this.Elements[this.Elements.length - 1].select();}
}

function jsDTreeSelectNext() {
	if (this.SelectedElement) {this.SelectedElement.selectNext(true);}	
	else if (this.Elements.length > 0) {this.Elements[0].select();}
}

function jsDTreeGetElementIndex() {
	if (arguments[0]) {
		for (var i=0;i<this.Elements.length;i++) {
			if (this.Elements[i] == arguments[0]) {return i;}
		}
	}
	return -1;
}

function jsDTreeGetById() {
	if (arguments[0]) {
		var i,tmp,id = arguments[0];
		for (i=0;i<this.Elements.length;i++) {
			tmp = this.Elements[i].getElementById(id);
			if (tmp != null) {return tmp;}
		}
	}
	return null;
}

function jsDTreeClear() {
	for (var i=this.Elements.length-1;i>=0;i--) {this.Elements[i].destroy();}
}

function jsDTreeResize() {
	if (arguments[0]) {
		this.ContentDiv.style.width = arguments[0];
		this.div.style.width = arguments[0];
	}
	if (arguments[1]) {
		var newheight = (this.ShowBar) ? arguments[1] - 17 : arguments[1];
		this.ContentDiv.style.height = newheight;
	}
}

function jsDTreeAddElement() {
	var id = arguments[0],parent = arguments[1],text = arguments[2],icon = arguments[3],haschilds = arguments[4],onclick = arguments[5],pElement,level = 0,mclass = arguments[6],oclass = arguments[7],sclass = arguments[8];
	if (parent) {
		pElement = this.getElementById(parent);
		if (!pElement) {alert('No se ha encontrado el elemento padre con id ' + parent); return;}
		level = pElement.level + 1;
	}
	var ne = new jsDElement(this,id,pElement,text,icon,haschilds,level,onclick,mclass,oclass,sclass);
	return ne;
}

function jsDTreeAddElementRuntime() {
	var id = arguments[0],parent = arguments[1],text = arguments[2],icon = arguments[3],haschilds = arguments[4],onclick = arguments[5],mclass = arguments[6],oclass = arguments[7],sclass = arguments[8];
	var el = this.addElement(id,parent,text,icon,haschilds,onclick,mclass,oclass,sclass);
	el.build();
	if (el.parent) {el.parent.afterCreate(false);}
	return el;
}

function jsDElement() {

	if (isNaN(jsDElement.count)) {jsDElement.count = 0;}
	this.index = jsDElement.count;
	this.name = "jsDElement" + (jsDElement.count++);
 	this.obj = this.name + "Object";
 	eval(this.obj + " = this")

	if (!arguments[0]) {alert('Error! Se ha intentado definir un elemento sin especificar a qué árbol pertenece');}
	this.tree = arguments[0];
	if (arguments[1]) {this.id = arguments[1];} else {this.id = this.index;}
	if (arguments[2]) {this.parent = arguments[2];}
	if (arguments[3]) {this.text = arguments[3];} else {this.text = '';}
	if (arguments[4]) {this.icon = arguments[4];}
	if (arguments[5]) {this.hasChilds = true;} else {this.hasChilds = false;}
	if (arguments[6]) {this.level = arguments[6];} else {this.level = 0;}
	if (arguments[7]) {this.onclick = arguments[7];}
	if (arguments[8]) {this.MainClass = arguments[8];} else {this.MainClass = this.tree.MainClass;}
	if (arguments[9]) {this.OverClass = arguments[9];} else {this.OverClass = this.tree.OverClass;}
	if (arguments[10]) {this.SelectedClass = arguments[10];} else {this.SelectedClass = this.tree.SelectedClass;}

	re = / /g;
	this.NoSpaceText = this.text.replace(re,'&nbsp;');

	this.opened = false;
	this.selected = false;
	this.canBeLoaded = true;
	this.hasBeenLoaded = false;
	this.Elements = new Array();
	this.ShowChilds = false;

	this.beginLoad = jsDElementBeginLoad;
	this.serialize = jsDElementSerialize;
	this.endLoad = jsDElementEndLoad;
	this.clear = jsDElementClear;
	this.build = jsDElementBuild;
	this.createChilds = jsDElementCreate;
	this.afterCreate = jsDElementAfterCreate;
	this.showLoadingRow = jsDElementShowLoadingRow;
	this.hideLoadingRow = jsDElementHideLoadingRow;

	this.doOut = jsDElementDoOut;
	this.doOver = jsDElementDoOver;
	this.doClick = jsDElementDoClick;

	this.hide = jsDElementHide;
	this.show = jsDElementShow;
	this.expand = jsDElementExpand;
	this.collapse = jsDElementCollapse;
	this.select = jsDElementSelect;
	this.deselect = jsDElementDeselect;
	this.getIndex = jsDElementGetIndex;
	this.selectNext = jsDElementSelectNext;
	this.selectPrev = jsDElementSelectPrev;
	this.makeVisible = jsDElementMakeVisible;
	this.selectElement = jsDElementSelectElement;

	this.getElementIndex = jsDElementGetElementIndex;
	this.getLastElementIndex = jsDElementGetLastElementIndex;
	this.symbolClicked = jsDElementSymbolClicked;

	this.addElement = jsDElementAdd;
	this.getElementById = jsDElementGetById;
	this.destroy = jsDElementDestroy;
	this.getXPath = jsDElementGetXPath;
	this.getDescriptiveXPath = jsDElementGetDescriptiveXPath;

	if (this.parent) {this.parent.addElement(this);} else {this.tree.Elements = this.tree.Elements.concat(this);}

}

function jsDElementExpand() {
	if ((this.hasChilds)&&(!this.opened)) {
		var obj = (this.parent) ? this.parent : this.tree;
		for (var i=0;i<obj.Elements.length;i++) {
			if (obj.Elements[i].opened) {obj.Elements[i].collapse();}
		}
		if ((this.parent)&&(!this.parent.opened)) {this.parent.expand();}
		this.SymbolImage.src = jsDTreeMinus.src;
		if (this.hasBeenLoaded) {
			for (var i=0;i<this.Elements.length;i++) {this.Elements[i].show();}
			this.opened = true;
		} else {this.beginLoad();}
	}
}

function jsDElementCollapse() {
	if (this.opened) {
		for (var i=0;i<this.Elements.length;i++) {this.Elements[i].hide();}
		this.opened = false;
		this.SymbolImage.src = jsDTreePlus.src;
	}	
}

function jsDElementMakeVisible() {
	if ((this.parent)&&(!this.parent.opened)) {this.parent.expand();}
}

function jsDElementSelectElement() {
	if (arguments[0]) {
		var el = this.getElementById(arguments[0]);
		if (el) {
			el.select();
			return true;
		}
	}
	return false;
}

function jsDElementSerialize() {
	var txt = '',i;
	if (this.opened) {txt += '|' + this.id;}
	for (i=0;i<this.Elements.length;i++) {txt += this.Elements[i].serialize();}
	return txt;
}

function jsDElementBeginLoad() {
	if ((this.hasChilds)&&(this.canBeLoaded)) {
		this.clear();
		this.SymbolImage.src = jsDTreeMinus.src;
		this.showLoadingRow();
		this.tree.beginLoad(this);
	}
}

function jsDElementEndLoad() {
	var src = this.tree.DownloadObjectFrame.document.body.innerHTML;
	if (this.tree.ElementLoading == this) {
		this.hideLoadingRow();
		this.LoadingRow = null;
		this.tree.ElementsToLoad.shift();
		this.tree.ElementLoading = null;
		document.ElementLoading = null;
		this.tree.Loading = false;
		this.tree.doLoad();
		this.createChilds(src);
	}
}

function jsDElementClear() {
	for (var i=0;i<this.Elements.length;i++) {
		this.Elements[i].clear();
		this.tree.ContentTable.deleteRow(this.Elements[i].tr.rowIndex);
	}
	this.Elements = new Array();
	this.hasChilds = false;
}

function jsDElementCreate(src) {
	var lines = src.split('<br>'),fields,id,icon,text,hasch,click;
	for (var i=0;i<lines.length;i++) {
		if (lines[i].trim() != '') {
			fields = lines[i].split('|');
			if (fields.length != 5) {alert('Los datos de carga son incorrectos:\n' + src); return;}
			id = fields[0].trim();
			icon = (fields[1].trim() != 'null') ? fields[1].trim() : null;
			text = fields[2].trim();
			hasch = (fields[3].trim().toLowerCase() == 'true');
			click = (fields[4].trim() != 'null') ? fields[4].trim() : null;
			var elem = new jsDElement(this.tree,fields[0].trim(),this,text,icon,hasch,this.level + 1,click);
			elem.canBeLoaded = hasch;
			this.addElement(elem);
			elem.build();
		}
	}
	this.afterCreate(true);
}

function jsDElementAfterCreate(sal) {
	this.hasBeenLoaded = true;
	this.canBeLoaded = false;
	this.hasChilds = (this.Elements.length > 0);
	if (this.hasChilds) {
		this.opened = true;
		this.SymbolImage.src = jsDTreeMinus.src;
		if (sal) {
			if (this.tree.SelectAfterLoad == 0) {this.Elements[0].select();}
			else if (this.tree.SelectAfterLoad == 1) {this.Elements[this.Elements.length - 1].select();}
			this.tree.SelectAfterLoad = -1;
		}
	} else {
		this.opened = false;
		this.SymbolImage.src = jsDTreePoint.src;
	}
}

function jsDElementBuild() {

	if (this.Elements.length > 0) {
		this.hasChilds = true;
		this.canBeLoaded = false;
		this.hasBeenLoaded = true;
		if (this.ShowChilds) {this.opened = true;}
	}

	this.innerHTML = '<table border="0" cellpadding="0" cellspacing="0" height="20"><tr>';
	this.innerHTML += '<td><img src="' + jsDTreePunto.src + '" border="0" width="' + ((this.level) * 15) + '" height="1"></td>';
	this.innerHTML += '<td valing="middle" align="center"' + ((this.tree.ShowPlusMinus) ? '' : ' style="display:none;"') + '><img id="' + this.name + 'Symbol" src="';
	if (this.hasChilds) {
		this.innerHTML += (this.ShowChilds) ? jsDTreeMinus.src : jsDTreePlus.src;
	} else {this.innerHTML += jsDTreePoint.src;}
	this.innerHTML += '" border="0" style="cursor:' + ((this.hasChilds) ? 'hand' : 'default') + ';" onclick="Javascript:' + this.obj + '.symbolClicked();"></td>';
	this.innerHTML += '<td><img src="' + jsDTreePunto.src + '" border="0" width="5" height="1"></td>';
	if (this.icon) {this.innerHTML += '<td valign="middle" width="1"><img src="' + this.icon + '" border="0"></td><td width="5"><img src="' + jsDTreePunto.src + '" border="0"></td>';}
	this.innerHTML += '<td><p id="' + this.name + 'Span" class="' + this.MainClass + '"';
	this.innerHTML += ' onmouseover="Javascript:' + this.obj + '.doOver();" onmouseout="Javascript:' + this.obj + '.doOut();" onclick="Javascript:' + this.obj + '.doClick();">' + this.NoSpaceText + '</p></td>';
	this.innerHTML += '</tr></table>';
	this.tr = this.tree.ContentTable.insertRow(this.getIndex());
	this.tr.style.height = 20;
	if (arguments[0]) {this.tr.style.display = 'none';}
	this.td = this.tr.insertCell(this.tr.cells.length);
	this.td.innerHTML = this.innerHTML;

	this.TextSpan = document.getElementById(this.name + 'Span');
	this.SymbolImage = document.getElementById(this.name + 'Symbol');

	for (var i=0;i<this.Elements.length;i++) {this.Elements[i].build(!this.ShowChilds);}
	
}

function jsDElementDestroy() {
	if (this.selected) {this.deselect();}
	if (this.Elements.length > 0) {
		for (var i=this.Elements.length - 1;i>=0;i--) {this.Elements[i].destroy();}
	}
	if (this.parent) {
		var index = this.parent.getElementIndex(this);
		this.parent.Elements.splice(index,1);
		this.parent.afterCreate(false);
	} else {
		var index = this.tree.getElementIndex(this);
		this.tree.Elements.splice(index,1);
	}
	this.tree.ContentTable.deleteRow(this.tr.rowIndex);
}

function jsDElementGetXPath() {
	var path = this.id;
	var obj = this;
	while (obj.parent) {
		obj = obj.parent;
		path = obj.id + '/' + path;
	}
	return path;
}

function jsDElementGetDescriptiveXPath() {
	var path = this.text;
	var obj = this;
	while (obj.parent) {
		obj = obj.parent;
		path = obj.text + ' / ' + path;
	}
	return path;
}

function jsDElementGetIndex() {
	var i,ei;
	if (this.parent) {
		ei = this.parent.getElementIndex(this);
		if (ei <= 0) {return (this.parent.tr.rowIndex + 1);}
		else {return (this.parent.Elements[ei - 1].getLastElementIndex() + 1);}
	} else {
		ei = this.tree.getElementIndex(this);
		if (ei <= 0) {return 0;}
		else {return (this.tree.Elements[ei - 1].getLastElementIndex() + 1);}
	}
}

function jsDElementGetLastElementIndex() {
	if (this.Elements.length == 0) {return this.tr.rowIndex;}
	else {return this.Elements[this.Elements.length - 1].getLastElementIndex();}
}

function jsDElementShowLoadingRow() {
	var str = '<table border="0" cellpadding="0" cellspacing="0" height="20"><tr>';
	str += '<td><img src="' + jsDTreePunto.src + '" border="0" width="' + ((this.level + 1) * 15) + '" height="1"></td>';
	str += '<td valing="middle" align="center"><img src="' + jsDTreePoint.src + '" border="0"></td>';
	str += '<td><img src="' + jsDTreePunto.src + '" border="0" width="5" height="1"></td>';
	str += '<td><p class="' + this.MainClass + '">' + this.tree.Messages[4] + '</p></td>';
	str += '</tr></table>';
	this.LoadingRow = this.tree.ContentTable.insertRow(this.tr.rowIndex + 1);
	this.LoadingRow.style.height = 20;
	td = this.LoadingRow.insertCell(this.LoadingRow.cells.length);
	td.innerHTML = str;
}

function jsDElementHideLoadingRow() {
	this.tree.ContentTable.deleteRow(this.LoadingRow.rowIndex);
}

function jsDElementDoOut() {
	if (this.selected) {this.TextSpan.className = this.SelectedClass;}
	else {this.TextSpan.className = this.MainClass;}
}

function jsDElementDoOver() {
	if (!this.selected) {this.TextSpan.className = this.OverClass;}
	if (this.onclick) {window.status = this.onclick;}
}

function jsDElementDoClick() {
	this.select();
	if (this.hasChilds) {this.symbolClicked();}
}

function jsDElementShow() {
	this.tr.style.display = '';
	if (this.opened) {
		for (var i=0;i<this.Elements.length;i++) {this.Elements[i].show();}
	}
}

function jsDElementHide() {
	for (var i=0;i<this.Elements.length;i++) {this.Elements[i].hide();}
	this.tr.style.display = 'none';
}

function jsDElementSelect() {
	if (!this.selected) {
		if (this.tree.SelectedElement) {this.tree.SelectedElement.deselect();}
		this.TextSpan.className = this.SelectedClass;
		this.selected = true;
		this.tree.SelectedElement = this;
		if (this.onclick) {eval(this.onclick);}
	}
}

function jsDElementDeselect() {
	if (this.selected) {
		this.TextSpan.className = this.MainClass;
		this.selected = false;
		this.tree.SelectedElement = null;
	}
}

function jsDElementSelectNext() {
	var canSelectChilds = arguments[0];
	if ((canSelectChilds)&&(this.hasChilds)) {
		if (this.Elements.length > 0) {
			if (!this.opened) {this.symbolClicked();}
			this.Elements[0].select();
		} else {
			this.tree.SelectAfterLoad = 0;
			this.beginLoad();
		}
	} else {
		if (this.parent) {
			var i = this.parent.getElementIndex(this);
			if (i < 0) {return;}
			if (i < this.parent.Elements.length - 1) {this.parent.Elements[i+1].select();}
			else {this.parent.selectNext(false);}
		} else {
			var i = this.tree.getElementIndex(this);
			if (i < 0) {return;}
			if (i < this.tree.Elements.length - 1) {this.tree.Elements[i+1].select();}
		}
	}
}

function jsDElementSelectPrev() {
	if (this.parent) {
		var i = this.parent.getElementIndex(this);
		if (i > 0) {this.parent.Elements[i - 1].select();}
		else {this.parent.select();}
	} else {
		var i = this.tree.getElementIndex(this);
		if (i > 0) {this.tree.Elements[i - 1].select();}
	}
}

function jsDElementGetElementIndex() {
	if (arguments[0]) {
		for (var i=0;i<this.Elements.length;i++) {
			if (this.Elements[i] == arguments[0]) {return i;}
		}
	}
	return -1;
}

function jsDElementSymbolClicked() {
	if (this.opened) {
		for (var i=0;i<this.Elements.length;i++) {this.Elements[i].hide();}
		this.opened = false;
		this.SymbolImage.src = jsDTreePlus.src;
	} else if (this.hasChilds) {this.expand();}
}

function jsDElementAdd() {
	if (arguments[0]) {this.Elements = this.Elements.concat(arguments[0]);}
	return arguments[0];
}

function jsDElementGetById() {
	if (arguments[0]) {
		var i,tmp,id = arguments[0];
		if (this.id == id) {return this;}
		for (i=0;i<this.Elements.length;i++) {
			tmp = this.Elements[i].getElementById(id);
			if (tmp != null) {return tmp;}
		}
	}
	return null;
}