if (typeof(strTreeIconURL) != "string")
	strTreeIconURL = "";
else {
	var strEndChar = strTreeIconURL.charAt(strTreeIconURL.length - 1);
	if (strEndChar != "/" && strEndChar != "\\")
		strTreeIconURL += "/";
}

///////////////////////////////////////////////////////////////////////////////////////////////

function ImageItem() {
	this.image = null;
	this.key = null;
	this.index = null;
}

function ImageList() {
	this.length = 0;

	this.item = __IstItem;
	this.index = __IstIndex;
	
	this.add = __IstAdd;
	this.remove = __IstRemove;
	this.clear = __IstClear;
}

function __IstAdd(strImageURL, key, index) {
	if (typeof(key) != "string") return null;
	if (key == "") return null;
	
	for (var i = 0; i < this.length; i ++)
	{
		if (this[i].key == key)
		{
			return null;
		}
	}
	
	if (typeof(index) != "number" || (typeof(index) == "number" && index >= this.length))
		index = this.length;

	this.length ++;
	
	if (index < this.length -2) {
		for (var i = this.length - 2;i >= index;i --)
		{
			this[i + 1] = this[i];
		}
	}
	
	var item = new ImageItem();
	var image = new Image();
	image.src = strImageURL;
	
	item.image = image;
	item.key = key;
	item.index = index;
	
	this[index] = item;
	
	delete image;
	delete item;

	return this[index];	
}

function __IstRemove(key) {

	var i = 0;
	var index = -1;
	
	if (typeof(key) == "number")
	{
		if (typeof(index) != "number") return false;
		if (index < 0 || index > this.length) return false;
		
		var i = -1;
		
		for (i = index;i < this.length - 1;i ++)
			this[i] = this[i + 1];
		delete this[length - 1];
		this.length --;

		return true;
	}
	else if (typeof(key) == "string")
	{
		if (key == "") return false;

		for (i = 0; i < this.length; i ++)
		{
			if (this[i].key == key)
			{
				index = i;
				break;
			}
		}
		
		for (i = index;i < this.length - 1;i ++)
		{
			this[i] = this[i + 1];
		}
		
		delete this[length - 1];
		
		this.length --;
		
		return true;
	}
	else
	{
		return false;
	}
}

function __IstClear() {
	for (var i = 0;i < this.length;i ++)
	{
		delete	this[i];
	}

	this.length = 0;
}

function __IstItem(key)
{
	if (typeof(key) == "number")
	{
		return this[key];
	}
	else if (typeof(key) == "string")
	{
		for (var i = 0; i < this.length; i ++)
		{
			if (this[i].key == key)
			{
				return this[i];
			}
		}
	}
	else
	{
		return null;
	}	
}

function __IstIndex(key)
{
	var index = -1;
	
	if (typeof(key) == "string")
	{
		for (var i = 0; i < this.length; i ++)
		{
			if (this[i].key == key)
			{
				index = i;
			}
		}
	}
	
	return index;
}

///////////////////////////////////////////////////////////////////////////////////////////////

function EventList() {
	this.length = 0;
	
	this.add = __EstAdd;
	this.remove = __EstRemove;
	this.clear = __EstClear;
}

function __EstAdd(fnAttach) {
	if (typeof(fnAttach) != "function") return -1;
				
	for (var i = 0; i < this.length; i ++) {
		if (this[i] == null) {
			this[i] = fnAttach;
			return i;
		}
	}
	
	this[i] = fnAttach;
	this.length ++;

	return i;	
}

function __EstRemove(index) {
	if (typeof(index) != "number") return false;
	
	this[index] = null;

	return true;
}

function __EstClear() {
	for (var i = 0; i < this.length; i ++)
		delete this[i];

	this.length = 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////

var __GblEventList = new EventList();

function __Callback() {
	for (var i = 0; i < __GblEventList.length; i ++) {
		if (__GblEventList[i] != null) {
			try {
				__GblEventList[i]();
			}
			catch (e) {}
		}
	}
}

function AddCallback(fnBackCall) {
	return __GblEventList.add(fnBackCall);
}

function RemoveCallback(fnBackCall) {
	for (var i = 0; i < __GblEventList.length; i ++) {
		if (__GblEventList[i] == fnBackCall) {
			__GblEventList.remove(i);
			return true;
			break;
		}
	}
	
	return false;
}

///////////////////////////////////////////////////////////////////////////////////////////////

var TvwFirst = 0;
var TvwLast = 1;
var TvwNext = 2;
var TvwPrevious = 3;
var TvwChild = 4;

var TvwCollapse = 0;
var TvwExpand = 1;
var TvwLeaf = 2;

var TvwUnknownNode = -1;
var TvwLeafNode = 16;
var TvwParentNode = 32;

var TvwPlusMinus = 4;
var TvwImage = 8;

var StlFontFamily = 1
var StlFontSize = 2;
var StlFontWeight = 3;
var StlBorder = 4;
var StlBackgroudColor = 5;
var StlLeft = 6;
var StlTop = 7;
var StlWidth = 8;
var StlHeight = 9;

var TvwIcons = new ImageList();
TvwIcons.add(strTreeIconURL + "collapse.gif", "1");
TvwIcons.add(strTreeIconURL + "expand.gif", "2");
TvwIcons.add(strTreeIconURL + "leaf.gif", "3");

var TvwGlobalIndex = 0;

function TreeView(nLeft, nTop, nWidth, nHeight, bFlow) {
	var	strID = "TREE_" + TvwGlobalIndex ++;
	var strHTML;
	
	if (typeof(nLeft) != "number") nLeft = 0;
	if (typeof(nTop) != "number") nTop = 0;
	if (typeof(nWidth) != "number") nWidth = 100;
	if (typeof(nHeight) != "number") nHeight = 100;
	if (typeof(bFlow) != "boolean") bFlow = false;
	
	this.backgroundColor = "white";
	this.border = "2px inset";
	this.fontFamily = "Tahoma,Arial";
	this.fontSize = "9pt";
	this.fontWeight = "normal";
	this.height = nHeight;
	this.id = strID;
	this.imageList = null;
	this.indent = 20;
	this.left = nLeft;
	this.showRootLines = true;
	this.selectedNode = null;
	this.currentNode = null;
	this.top = nTop;
	this.width = nWidth;

	this.onNodeClick = null;
	this.onNodeContextmenu = null;
	this.onNodeExpand = null;
	this.onNodeCollapse = null;
	
	this.add = __TvwAdd;
	this.clear = __TvwClear;
	this.remove = __TvwRemove;
	this.isExists = __TvwIsExists;
	
	this.getNodeText = __TvwGetNodeText;
	this.setNodeText = __TvwSetNodeText;
	
	this.getStyle = __TvwGetStyle;
	this.setStyle = __TvwSetStyle;
	
	this.getExpanded = __TvwGetExpanded;
	this.setExpanded = __TvwSetExpanded;
	
	this.setSelected = __TvwSetSelected;
	this.clickNode = __TvwClickNode;
	this.expand = __TvwExpand

	this.getPath = __TvwGetPath;
	this.getChildrenCount = __TvwGetChildrenCount;
	this.getParent = __TvwGetParentNode;
	
	this.node = __TvwGetNode;
	
	strHTML = "<STYLE id=STL_" + strID + "> SPAN.TITEM_" + strID + 
			" {FONT-size:" + this.fontSize + ";FONT-FAMILY:" + this.fontFamily + 
			";FONT-WEIGHT:" + this.fontWeight + "}</STYLE>";
	document.write(strHTML);
	
	strHTML = "<DIV align=left nowrap id=" + strID + " language=\"javascript\" " +
			"onkeyup=\"__TvwKeyUp('" + this.id + "');\" " + 
			"onkeydown=\"__TvwKeyDown('" + this.id + "');\" " +
			"onselectstart=\"window.event.cancelBubble = true; window.event.returnValue " +
			"= false; return false;\" ondragstart=\"window.event.cancelBubble = true;" +
			"window.event.returnValue = false; return false;\" style=\"BACKGROUND-COLOR: " + 
			this.backgroundColor + "; BORDER: " + this.border + "; LEFT: " + this.left + 
			"px;TOP: " + this.top + "px; WIDTH: " + this.width + "px; HEIGHT: " + this.height + 
			"px; OVERFLOW: auto; PADDING: 1px;" + (bFlow ? "POSITION: static;" : "POSITION: absolute;") +
			"\" m_objTree selectedNode></DIV>";

	document.write(strHTML);
	
	document.all[strID].m_objTree = this;
}

function __TvwMouseOver(strTree, strKey) {  
	var objNode = document.all[strTree + "_" + strKey];
	window.setTimeout("window.status=window.defaultStatus;", 0);
	if (! objNode.selected) {
		var nChildIndex = objNode.children.length - 2;

		if (nChildIndex >= 0 && 
			objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
			var objLabel = objNode.children(nChildIndex);
			objLabel.children(0).style.color = "#003399";
			objLabel.children(0).style.textDecoration = "underline";
		}
		
	}
}

function __TvwMouseOut(strTree, strKey) {
	var objNode = document.all[strTree + "_" + strKey];
	
	if (! objNode.selected) {
		var nChildIndex = objNode.children.length - 2;
		
		if (nChildIndex >= 0 && 
			objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
			var objLabel = objNode.children(nChildIndex);
			objLabel.children(0).style.color = "black";
			objLabel.children(0).style.textDecoration = "none";
		}
	}
}

function __TvwMouseDown(strTree, strKey) {
	var objNode = document.all[strTree + "_" + strKey];
	
	window.setTimeout("window.status=window.defaultStatus;", 0);
	
	var nChildIndex = objNode.children.length - 2;

	if (nChildIndex >= 0 && 
		objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
		try	{
			objNode.children(nChildIndex).focus();
		}
		catch (e){}
		
	}
}

function __TvwToggleNode(strTree, strKey) {
	var objNode = document.all[strTree + "_" + strKey];
	var objExpanded = document.all[strTree + "_" + strKey + "_Children"];
	var oTree = document.all[strTree].m_objTree;
	
	if (objNode.state == TvwLeafNode) return;
	
	if (objNode.expanded == true) {
		if (typeof(oTree) == "object" && oTree.onNodeCollapse != null)
			if (oTree.onNodeCollapse(strKey) == false) return;
		
		objNode.expanded = false;
		if (objNode.children(0).type == TvwPlusMinus) 
			objNode.children(0).src = TvwIcons[TvwCollapse].image.src;
		objExpanded.style.display = "none";
		
	}
	else {
		if (typeof(oTree) == "object" && oTree.onNodeExpand != null)
			if (oTree.onNodeExpand(strKey) == false) return;
		
		if (objExpanded.children.length > 0) {
			objNode.expanded = true;
			objExpanded.style.display = "";
			if (objNode.children(0).type == TvwPlusMinus) {
				objNode.children(0).src = TvwIcons[TvwExpand].image.src;
			}
		}
		else {
			if (objNode.children(0).type == TvwPlusMinus) 
				objNode.children(0).src = TvwIcons[TvwLeaf].image.src;
			objNode.state = TvwLeafNode;
		}
	}
}

function __TvwNodeSelect(strTree, strKey, bSelected) {
	var nChildIndex;
	var objNode = document.all[strTree + "_" + strKey];
	var objTree = document.all[strTree].m_objTree;
	
	if (objNode == null) return;
	
	objNode.selected = bSelected;
	
	if (bSelected)
		objTree.selectedNode = objNode;
	else
		objTree.selectedNode = null;
	
	nChildIndex = objNode.children.length - 2;
		
	if (nChildIndex >= 0 && 
		objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
		var objLabel = objNode.children(nChildIndex);
		if (bSelected) {
			objLabel.style.backgroundColor = "#003399";
			objLabel.children(0).style.color = "white";
			try	{
				objLabel.focus();
			}
			catch (e) {}
		}
		else {
			objLabel.style.backgroundColor = "";
			objLabel.children(0).style.color = "black";
		}
		objLabel.children(0).style.textDecoration = "none";
	}
	
	nChildIndex = objNode.children.length - 3;
	
	if (nChildIndex >= 0 && 
		objNode.children(nChildIndex).tagName.toUpperCase() == "IMG" &&
		objNode.children(nChildIndex).type == TvwImage) {
		var objImg = objNode.children(nChildIndex);
		var nImgIndex = -1;
			
		if (bSelected)
			nImgIndex = objImg.selectedImage;
		else
			nImgIndex = objImg.image;

		var objItem = objTree.imageList.item(nImgIndex);
		if (objItem != null)
			objImg.src = objItem.image.src;
	}

}

function __TvwGetParent(strTree, strNode) {
	var objNode = document.all[strNode];
	var objParent = objNode.parentElement.parentElement;
	var objTop = document.all[strTree].parentElement;
	if (objParent == objTop)
		return null;
	else
		return objParent;
}

function __TvwGetFirstChild(strNode) {
	var objChildren = document.all[strNode + "_Children"];
	
	if (objChildren.children.length > 0)
		return objChildren.children[0];

	return null;
}

function __TvwGetLastChild(strNode) {
	var objChildren = document.all[strNode + "_Children"];
	
	if (objChildren.children.length > 0) {
		var nChildIndex = objChildren.children.length - 1;
		return objChildren.children[nChildIndex];
	}
	
	return null;
}

function __TvwGetNextSibling(strNode) {
	var objNode = document.all[strNode];

	if (typeof(objNode.nextSibling) == "object")
		return objNode.nextSibling;

	return null;
}

function __TvwGetPreviousSibling(strNode) {
	var objNode = document.all[strNode];
	if (typeof(objNode.previousSibling) == "object")
		return objNode.previousSibling;

	return null;
}

function __TvwNodeClick(strTree, strKey, bRunEventHandler) {
	var objNode = document.all[strTree + "_" + strKey];
	var objTree = document.all[strTree].m_objTree;
	
	window.setTimeout("window.status=window.defaultStatus;", 0);
		
	if (typeof(bRunEvent) != "boolean") bRunEventHandler = true;
	

	if (objTree.selectedNode != null)
		__TvwNodeSelect(strTree, objTree.selectedNode.key, false);

	__TvwNodeSelect(strTree, strKey, true);
	
	if (bRunEventHandler) {	
		var oTree = document.all[strTree].m_objTree;
		
		if (typeof(oTree) == "object" && oTree.onNodeClick != null)
			oTree.onNodeClick(strKey);
	}
}

function __TvwNodeContextmenu(strTree, strKey) {
	var oTree = document.all[strTree].m_objTree;
	oTree.currentNode = document.all[strTree + "_" + strKey];
	if (typeof(oTree) == "object" && oTree.onNodeContextmenu != null)
	{
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		oTree.onNodeContextmenu(strKey);
		return false;
	}
	return true;
}

function __TvwKeyDown(strTree) {
	var bRetVal = false;
	var objLI;
	if (typeof(g_objMenu) != "undefined" && g_objMenu != null) {
		if (g_objMenu.m_objPopup.isOpen)
			return;
	}
	if (window.event.ctrlKey == false && window.event.altKey == false) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		
		switch (window.event.keyCode) {
			case 13:
				break;
			case 37:
				__TvwMoveLeft(strTree)
				break;
			case 38:
				__TvwMoveUp(strTree)
				break;
			case 39:
				__TvwMoveRight(strTree)
				break;
			case 40:
				__TvwMoveDown(strTree)
				break;
			default:
				window.event.cancelBubble = false;
				window.event.returnValue = true;
				bRetVal = true;
			break;
		}
	}
	else {
		window.event.cancelBubble = false;
		window.event.returnValue = true;
		bRetVal = true;
	}

	return bRetVal;
}

function __TvwMoveLeft(strTree) {
	var objTop = document.all[strTree];
	var objTree = objTop.m_objTree;
	
	if (objTop.children.length > 0) {
		var strNode = "";

		if (objTree.selectedNode != null)
			strNode = objTree.selectedNode.id;
		
		if (strNode != "") {		
			var objNode = document.all[strNode];
			var objTemp = document.all[strNode + "_Children"];
			if (objTemp.children.length > 0) {
				if (objNode.expanded) {
					__TvwToggleNode(strTree, objNode.key);
					return;
				}
			}
			
			objTemp = __TvwGetParent(strTree, objNode.id);
			if (objTemp != null)
				__TvwNodeClick(strTree, objTemp.key, false);
		}
		else
			__TvwNodeClick(strTree, objTop.children[0].key, false);
	}
}

function __TvwMoveRight(strTree) {
	var objTop = document.all[strTree];
	var objTree = objTop.m_objTree;
	
	if (objTop.children.length > 0) {
		var strNode = "";
		
		if (objTree.selectedNode != null)
			strNode = objTree.selectedNode.id;

		if (strNode != "") {
			var objNode = document.all[strNode];
			var objTemp = document.all[strNode + "_Children"];
			if (! objNode.expanded)
				__TvwToggleNode(strTree, objNode.key);
			else if (objTemp.children.length > 0)
				__TvwNodeClick(strTree, objTemp.children[0].key, false);
		}
		else
			__TvwNodeClick(strTree, objTop.children[0].key, false);
	}
}

function __TvwMoveUp(strTree) {
	var objTop = document.all[strTree];
	var objTree = objTop.m_objTree;
	
	if (objTop.children.length > 0) {
		var strNode = "";

		if (objTree.selectedNode != null)
			strNode = objTree.selectedNode.id;

		if (strNode != "") {
			var objNode = document.all[strNode];
			var objTemp = __TvwGetPreviousSibling(objNode.id);
			
			if (objTemp == null) {
				objTemp = __TvwGetParent(strTree, objNode.id);
				if (objTemp != null)
					__TvwNodeClick(strTree, objTemp.key, false);
			}
			else {
				if (objTemp.expanded) {
					objNode = __TvwGetLastChild(objTemp.id);
					if (objNode != null) {
						while (objNode != null) {
							if (! objNode.expanded) {
								__TvwNodeClick(strTree, objNode.key, false);
								return;
							}
							else {
								objTemp = objNode;
								objNode = __TvwGetLastChild(objNode.id);
							}
						}
					}
				}
				if (objTemp != null) 
					__TvwNodeClick(strTree, objTemp.key, false);
			}
		}
		else
			__TvwNodeClick(strTree, objTop.children[0].key, false);
	}
}

function __TvwMoveDown(strTree) {
	var objTop = document.all[strTree];
	var objTree = objTop.m_objTree;
	
	if (objTop.children.length > 0) {
		var strNode = "";

		if (objTree.selectedNode != null)
			strNode = objTree.selectedNode.id;

		if (strNode != "") {
			var objTemp;
			
			var objNode = document.all[strNode];
			if (objNode.expanded) {
				objTemp = __TvwGetFirstChild(objNode.id);
				if (objTemp != null) {
					__TvwNodeClick(strTree, objTemp.key, false);
					return;
				}
			}
			
			objTemp = __TvwGetNextSibling(objNode.id);
			
			if (objTemp != null)
				__TvwNodeClick(strTree, objTemp.key, false);
			else {
				objNode = __TvwGetParent(strTree, objNode.id);
				while (objNode != null) {
					objTemp = __TvwGetNextSibling(objNode.id);
					if (objTemp != null) {
						__TvwNodeClick(strTree, objTemp.key, false);
						break;
					}
					objNode = __TvwGetParent(strTree, objNode.id);
				}
			}
		}
		else
			__TvwNodeClick(strTree, objTop.children[0].key, false);
	}
}

function __TvwKeyUp(strTree) {
	var bRetVal = false;
	var objLI;
	
	if (window.event.ctrlKey == false && window.event.altKey == false) {
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		
		switch (window.event.keyCode) {
			case 37:
			case 38:
			case 39:
			case 40:
				var strKey = document.all[strTree].selectedNode;
				var oTree = document.all[strTree].m_objTree;
			
				if (typeof(oTree) == "object" && oTree.onClickNode != null)
					oTree.onClickNode(strKey);
			default:
				window.event.cancelBubble = false;
				window.event.returnValue = true;
				bRetVal = true;
			break;
		}
	}
	else {
		window.event.cancelBubble = false;
		window.event.returnValue = true;
		bRetVal = true;
	}

	return bRetVal;
}

function __TvwAdd(relative, relationship, key, text, image, selectedImage, state) {
	var objNode = null;
	var strHTML = "";
	var nChildIndex = 0;
	
	if (relative != "") {
		if (document.all[this.id + "_" + relative] == null) {
			return null;
		}
	}
	if (key == "") {
		return null;
	}
	if (document.all[this.id + "_" + key] != null) {
		return null;
	}
	if (typeof(image) != "number" && typeof(image) != "string") image = -1;
	if (this.imageList == null) image = -1;
	if (typeof(selectedImage) != "number" && typeof(selectedImage) != "string") selectedImage = -1;
	if (image == -1)  selectedImage = -1;
	if (typeof(state) != "number") state = TvwLeafNode;
	
	
	strHTML = "<DIV key=\"" + key + "\" state=" + state + " expanded tag=\"\" selected id=" + 
				this.id + "_" + key + " language=\"javascript\" " + 
				"oncontextmenu=\"return __TvwNodeContextmenu('" + this.id +
				"', '" + key + "');\" onmousedown=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;__TvwMouseDown('" + this.id + "', '" + 
				key + "');__Callback();\" onclick=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;__TvwNodeClick('" + this.id + "', '" + 
				key + "');\" ondblclick=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;__TvwToggleNode('" + this.id + "', '" + 
				key + "');\" onmouseout=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;__TvwMouseOut('" + this.id + "', '" + 
				key + "');\" onmouseover=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;__TvwMouseOver('" + this.id + "', '" + 
				key + "');\">";

	if (relative == "" && this.showRootLines || relative != "") {
	
		strHTML += "<IMG type=" + TvwPlusMinus + " src=\"" 
					+ TvwIcons[((state == TvwLeafNode) ? TvwLeaf : TvwCollapse)].image.src + 
					"\" " + " align=absmiddle onmousedown=\"__Callback();" + 
					"window.event.cancelBubble = true; window.event.returnValue = false; " +
					"if (event.button == 1) {__TvwToggleNode('" + this.id + "', '" + 
					key + "');}\" onclick=\"window.event.cancelBubble = true; " + 
					"window.event.returnValue = false;\" width=20 height=16>";
	}
	
	var objItem = this.imageList.item(image);
	if (objItem != null)
		strHTML += "<IMG type=" + TvwImage + " src=\"" + objItem.image.src + 
					"\" style=\"MARGIN: 1 3 1 0;\" align=absmiddle image=" + image +
					" selectedImage=" + selectedImage + ">";

	strHTML += "<A style=\"COLOR: black; TEXT-DECORATION: none;CURSOR: default\" " + 
				"href=\"javascript:\" title=\"" + text + "\"><SPAN class=\"TITEM_" + this.id + 
				"\" style=\"PADDING-LEFT: 2px;PADDING-RIGHT: 2px;HEIGHT: 1em;PADDING-TOP: 2px\">" + text + "</SPAN></A><DIV id=" +
				 this.id + "_" + key + "_Children " + "style=\"DISPLAY: none; PADDING-LEFT: " + 
				 this.indent + "px\" " + "oncontextmenu=\"window.event.cancelBubble = true;\" onmousedown=\"" + 
				"window.event.cancelBubble = true; window.event.returnValue = false;" + 
				"__Callback();\" onmouseover=\"window.event.cancelBubble = true; " + 
				"window.event.returnValue = false;\" onmouseout=\"" + 
				"window.event.cancelBubble = true; window.event.returnValue = false;\" " +
				"onclick=\"window.event.cancelBubble = true; window.event.returnValue = false;\" " +
				"ondblclick=\"window.event.cancelBubble = true; window.event.returnValue = false;\">" + 
				"</DIV></DIV>";
	
	if (relative == "") {
		objNode = document.all[this.id];
		objNode.insertAdjacentHTML("beforeEnd", strHTML);
	}
	else {
		switch (relationship) {
			case TvwFirst:
				objNode = document.all[this.id + "_" + relative].parentElement;
				objNode.children(0).insertAdjacentHTML("beforeBegin", strHTML);
				iIndex = 0;
				break;
			case TvwLast:
				objNode = document.all[this.id + "_" + relative].parentElement;
				nChildIndex = objNode.children.length - 1;
				objNode.children(0).insertAdjacentHTML("afterEnd", strHTML);
				break;
			case TvwNext:
				objNode = document.all[this.id + "_" + relative];
				objNode.insertAdjacentHTML("afterEnd", strHTML);
				break;
			case TvwPrevious:
				objNode = document.all[this.id + "_" + relative];
				objNode.insertAdjacentHTML("beforeBegin", strHTML);
				break;
			default:
				objNode = document.all[this.id + "_" + relative + "_Children"];
				objNode.insertAdjacentHTML("beforeEnd", strHTML);
			
				objNode = document.all[this.id + "_" + relative];
				if (objNode.children.length > 0) {
					objNode.state = TvwParentNode;
					nChildIndex = objNode.children.length - 1;
					if (objNode.expanded == true)
						objNode.children(nChildIndex).style.display = "";
					else
						objNode.children(nChildIndex).style.display = "none";

					if (objNode.children(0).type == TvwPlusMinus) {
						if (objNode.expanded == true)
							objNode.children(0).src = TvwIcons[TvwExpand].image.src;
						else
							objNode.children(0).src = TvwIcons[TvwCollapse].image.src;
					}
				}
				break;
		}
	}
	
	objNode = document.all[this.id + "_" + key];
	objNode.expanded = false;
	objNode.selected = false;
	return objNode;
}

function __TvwClear(strKey) {
	var objCleared;
	
	if (typeof(strKey) != "string") strKey = "";
	
	if (strKey != "") {
		if (document.all[this.id + "_" + strKey] == null) {
			return false;
		}
		
		var objNode = document.all[this.id + "_" + strKey];
		objNode.state = TvwLeafNode;
		
		if (objNode.children(0).type == TvwPlusMinus)
			objNode.children(0).src = TvwIcons[TvwLeaf].image.src;

		objCleared = document.all[this.id + "_" + strKey + "_Children"];
		objCleared.style.display = "none";
		objNode.expanded = false;
	}
	else
		objCleared = document.all[this.id];
		
	objCleared.innerHTML = "";
	
	return true;
}

function __TvwRemove(strKey) {
	var strNode = this.id + "_" + strKey;
	var objNode = document.all[strNode];
	var strParent = "";
	if (objNode != null) {
		if (this.selectedNode == objNode)
			this.selectedNode = null;

		var objParent = objNode.parentElement.parentElement;
		var objSiblings = objNode.parentElement;
		
		objNode.outerHTML = "";
		if (objSiblings.children.length == 0) {
			if (objSiblings != document.all[this.id]) {
				objSiblings.style.display = "none";
				objParent.state = TvwLeafNode;
				objParent.expanded = false;
				if (objParent.children(0).type == TvwPlusMinus)
					objParent.children(0).src = TvwIcons[TvwLeaf].image.src;
			}
		}
		try {
			document.all[this.id].focus();
		}
		catch (e){}
	}
}

function __TvwRefresh() {
	var objContainer = document.all[this.id + "_Container"];

	if (parseInt(objContainer.style.left) != this.left)
		objContainer.style.left = this.left;
	if (parseInt(objContainer.style.top) != this.top)
		objContainer.style.top = this.top;
	if (parseInt(objContainer.style.width) != this.width)
		objContainer.style.width = this.width;
	if (parseInt(objContainer.style.height) != this.height)
		objContainer.style.height = this.height;

	if (objContainer.style.border != this.border)
		objContainer.style.border = this.border;
}

function __TvwGetNodeText(strKey) {
	var objNode = document.all[this.id + "_" + strKey];
	
	if (objNode == null) return "";
	
	var nChildIndex = objNode.children.length - 2;
		
	if (nChildIndex >= 0 && 
		objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
		return objNode.children(nChildIndex).children(0).innerText;
	}
	return "";
}

function __TvwSetNodeText(strKey, strNewText) {
	var objNode = document.all[this.id + "_" + strKey];
	
	if (objNode == null) return;
	
	var nChildIndex = objNode.children.length - 2;
		
	if (nChildIndex >= 0 && 
		objNode.children(nChildIndex).tagName.toUpperCase() == "A") {
		objNode.children(nChildIndex).children(0).innerText = strNewText;
		objNode.title = strNewText;
	}
}

function __TvwGetStyle(nStyle) {
	var strStyle = "";
	switch (nStyle) {
		case StlFontFamily:
			strStyle = this.fontFamily;
			break;
		case StlFontSize:
			strStyle = this.fontSize;
			break;
		case StlFontWeight:
			strStyle = this.fontWeight;
			break;
		case StlBorder:
			strStyle = this.border;
			break;
		case StlBackgroudColor:
			strStyle = this.backgroudColor;
			break;
		case StlLeft:
			strStyle = this.left;
			break;
		case StlTop:
			strStyle = this.top;
			break;
		case StlWidth:
			strStyle = this.width;
			break;
		case StlHeight:
			strStyle = this.height;
			break;
	}
	return strStyle;
}

function __TvwSetStyle(nStyle, strNewStyle) {
	var objTree = document.all[this.id];

	switch (nStyle) {
		case StlFontFamily:
			objTree.style.fontFamily = strNewStyle;
			this.fontFamily = strNewStyle;
			document.styleSheets["STL_" + this.id].rules[0].style.fontFamily = this.fontFamily;
			break;
		case StlFontSize:
			objTree.style.fontSize = strNewStyle;
			this.fontSize = strNewStyle;
			document.styleSheets["STL_" + this.id].rules[0].style.fontSize = this.fontSize;
			break;
		case StlFontWeight:
			objTree.style.fontWeight = strNewStyle;
			this.fontWeight = strNewStyle;
			document.styleSheets["STL_" + this.id].rules[0].style.fontWeight = this.fontWeight;
			break;
		case StlBorder:
			objTree.style.border = strNewStyle;
			this.border = strNewStyle;
			break;
		case StlBackgroudColor:
			objTree.style.backgroudColor = strNewStyle;
			this.backgroudColor = strNewStyle;
			break;
		case StlLeft:
			objTree.style.left = strNewStyle;
			this.left = strNewStyle;
			break;
		case StlTop:
			objTree.style.top = strNewStyle;
			this.top = strNewStyle;
			break;
		case StlWidth:
			objTree.style.width = strNewStyle;
			this.width = strNewStyle;
			break;
		case StlHeight:
			objTree.style.height = strNewStyle;
			this.height = strNewStyle;
			break;
	}
}

function __TvwIsExists(strKey) {
	if (document.all[this.id + "_" + strKey] != null) 
		return true;
	else
		return false;
}

function __TvwGetExpanded(strKey) {
	return document.all[this.id + "_" + strKey].expanded;
}

function __TvwSetExpanded(strKey, bExpanded) {
	document.all[this.id + "_" + strKey].expanded = ! bExpanded;
	__TvwToggleNode(this.id, strKey);
}

function __TvwGetChildrenCount(strKey) {
	var objChildren = document.all[this.id + "_" + strKey + "_Children"];
	if (objChildren != null) {
		return objChildren.children.length;
		
	}
	return 0;
}

function __TvwGetNode(strKey) {
	var objNode = document.all[this.id + "_" + strKey];
	if (objNode != null) {
		return objNode;
		
	}
	return null;
}

function __TvwGetPath(strKey, strSeparator, bFirstLayer) {
	var strPath;
	var objParent;
	if (typeof(strSeparator) != "string") {
		strSeparator = "/";
	}
	
	if (typeof(bFirstLayer) != "boolean")
		bFirstLayer = true;
		
	if (bFirstLayer)
	{
		strPath = this.getNodeText(strKey);
		objParent = __TvwGetParent(this.id, this.id + "_" + strKey);
		while (objParent != null)	{
			strKey = objParent.key;
			strPath = this.getNodeText(strKey) + "/" + strPath;
			objParent = __TvwGetParent(this.id, this.id + "_" + strKey);
		}
		strPath = "/" + strPath;
		return strPath;
	}
	else
	{
		objParent = __TvwGetParent(this.id, this.id + "_" + strKey);
		
		if (objParent == null)		
			return "/";
		
		strPath = this.getNodeText(strKey);
			
		var objParent2 = __TvwGetParent(this.id, this.id + "_" + objParent.key);
		
		while (objParent != null && objParent2 != null)
		{
			strKey = objParent.key;
			strPath = this.getNodeText(strKey) + "/" + strPath;
			objParent = __TvwGetParent(this.id, this.id + "_" + strKey);
			
			if (objParent != null)		
				objParent2 = __TvwGetParent(this.id, this.id + "_" + objParent.key);
			else
				objParent2 = null;
		}
		strPath = "/" + strPath;
		return strPath;
				
	}
}

function __TvwSetSelected(strKey, bSelected) {
	__TvwNodeSelect(this.id, strKey, bSelected)
}

function __TvwClickNode(strKey) {
	__TvwNodeClick(this.id, strKey, true);
}

function __TvwGetParentNode(strKey) {
	return __TvwGetParent(this.id, this.id + "_" + strKey);
}

function __TvwExpand(strKey) {
	var objNode = this.node(strKey);
	if (objNode == null) return;

	while (true) {
		strKey = objNode.key;
		if (! objNode.expanded)
			this.setExpanded(strKey, true);
		objNode = this.getParent(strKey)
		if (objNode == null) return;
	}
}
