﻿var sRootUrl = 'http://www.etaglive.com/';

if (window.HTMLElement) {

    var element = HTMLElement.prototype;

    var capture = ["click",    "mousedown", "mouseup",    "mousemove", "mouseover", "mouseout" ];
    if (!element.setCapture )
    {
        element.setCapture = function(){
            var self = this;
            var flag = false;
            this._capture = function(e){
                if (flag) {return}
                flag = true;
                var event = document.createEvent("MouseEvents");
                event.initMouseEvent(e.type,
                    e.bubbles, e.cancelable, e.view, e.detail,
                    e.screenX, e.screenY, e.clientX, e.clientY,
                    e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
                    e.button, e.relatedTarget);
                self.dispatchEvent(event);
                flag = false;
            };
            for (var i=0; i<capture.length; i++) {
                window.addEventListener(capture[i], this._capture, true);
            }
        };

        element.releaseCapture = function(){
            for (var i=0; i<capture.length; i++) {
                window.removeEventListener(capture[i], this._capture, true);
            }
            this._capture = null;
        };
    }
}

function site_TreeToolClass(){
    this.orgWidth = "250px";
    this.orgHeight = "350px";
    this.orgChildHeight = "328px";
	this.treePaneDiv = null;
	this.enabledMove = false;
	var theLink;
	theLink = document.getElementById("hplTagIt");
	if (theLink)
	{
	    this.FrameLeft = theLink.offsetLeft;
	    this.FrameTop = theLink.offsetTop;
	}
	this.oldcursor = "auto";
	this.vani_divTree = null;
	this.topPaneTreeTool = null;
	this.nowX = 0;
	this.nowY = 0;
	this.offsetx = 0;
	this.offsety = 0;
	this.oldcursor = "auto";
	this.oldMoveFunc = null;
	this.oldUpFunc = null;
    this.baseScriptURL  = sRootUrl + "WebServices/scripted/";
    this.strJsonTreeFolder = "";
    //for tree control
    // Arrays for nodes and icons
    this.nodes		= new Array();
    this.openNodes	= new Array();
    this.icons		= new Array(6);
    this.space		= "&nbsp;";
    this.RootNode = 0;
    this.CrtNodeId   = -1;
    this.vani_arrTreeHTML = new Array;
    this.vani_arrTreeHTML.push("<br/>");
    this.maxvalue = vani_maxvalue;
    this.arrNodeSelected = new Array;
    this.strNodesSelected = "";
    this.mapNodeAddedName = new Array;
    this.strNewFolderCreated = "";
} 

// Loads all icons that are used in the tree
site_TreeToolClass.prototype.preloadIcons = function() {
	this.icons[0] = new Image();
	this.icons[0].src = site_objTreeTool.baseScriptURL + "images/plus.gif";
	this.icons[1] = new Image();
	this.icons[1].src = site_objTreeTool.baseScriptURL + "images/plusbottom.gif";
	this.icons[2] = new Image();
	this.icons[2].src = site_objTreeTool.baseScriptURL + "images/minus.gif";
	this.icons[3] = new Image();
	this.icons[3].src = site_objTreeTool.baseScriptURL + "images/minusbottom.gif";
	this.icons[4] = new Image();
	this.icons[4].src = "/img/folder_yellow.png";
	this.icons[5] = new Image();
	this.icons[5].src = "/img/folder_red.png";
}
// Create the tree
site_TreeToolClass.prototype.createTree = function(arrName, startNode ) {
	this.nodes = arrName;
	//if (this.nodes.length > 0) {
		this.preloadIcons();
		if (startNode == null){
			startNode = 0;	
			this.RootNode = 0;
		}
		/* default startNode is RootNode */
		if (startNode !=0) {
			/* wasn't used due to no root node.
			this.RootNode = startNode;
			var nodeValues = this.nodes[this.getArrayId(startNode)].split("|");		
			this.ReplaceDocumentWrite("<a id=\"vani_idtreehref"+ nodeValues[0] +"\"  style=\"color:#8b008b\" href=\"#\" onclick=\"site_objTreeTool.OnNodeClick('"+nodeValues[0]+"','"+ nodeValues[3] +"');return false;\" onmouseout=\"window.status=' ';return true;\"><img src=\"" + site_objTreeTool.baseScriptURL  + "Images/root.gif\" align=\"absbottom\" alt=\"Root\" />"+  nodeValues[2] + "</a>");
			this.ReplaceDocumentWrite("(<a id=\"vani_idtreenew"+ nodeValues[0] +"\" class=\"treenewfolder\" ");
			this.ReplaceDocumentWrite("href=\"#\" onclick=\"site_objTreeTool.OnNewFolder('"+nodeValues[0]+ "','');return false;\">");
			this.ReplaceDocumentWrite("New folder</a>)<br />"); 

			//mark the curretn node			
			this.CrtNodeId = startNode;			*/
		}
		else
		{
		    //this.ReplaceDocumentWrite("<a id=vani_idtreenew0 class=\"treenewfolder\" ");
			//this.ReplaceDocumentWrite("href=\"#\" onclick=\"site_objTreeTool.OnNewFolder('0','');return false;\">");
			//this.ReplaceDocumentWrite("+(add new label)</a><br />"); 
			this.ReplaceDocumentWrite("<A class=\"treenewfolder\" id=\"site_idtreenew0\" onclick=\"site_objTreeTool.OnNewFolder('0','');return false;\" href=\"#\" style=\"margin: auto auto auto auto;\" >");
            this.ReplaceDocumentWrite("<span style=\"top:0px;position:static;\">");
            this.ReplaceDocumentWrite("<img align=\"middle\" src=\"" + sRootUrl + "Webservices/scripted/images/add.gif\" border=\"0\"></span><span style=\"position:static;color:#003366;\">Add new eFolder   </span></A> <BR/>");
		}
		var recursedNodes = new Array();
		this.addNode(startNode, recursedNodes);
	//}
}
// Returns the position of a node in the array
site_TreeToolClass.prototype.getArrayId= function(node) {
	for (i=0; i<this.nodes.length; i++) {
		var nodeValues = this.nodes[i].split("|");
		if (nodeValues[0]==node) return i;
	}
}
// Puts in array nodes that will be open
site_TreeToolClass.prototype.setOpenNodes = function(openNode) {
	for (i=0; i<this.nodes.length; i++) {
		var nodeValues = this.nodes[i].split("|");
		if (nodeValues[0]==openNode) {
			this.openNodes.push(nodeValues[0]);
			this.setOpenNodes(nodeValues[1]);
		}
	} 
}
// Checks if a node is open
site_TreeToolClass.prototype.isNodeOpen = function(node) {
	for (i=0; i<this.openNodes.length; i++)
		if (this.openNodes[i]==node) return true;
	return false;
}
// Checks if a node has any children
site_TreeToolClass.prototype.hasChildNode = function(parentNode) {
	for (i=0; i< this.nodes.length; i++) {
		var nodeValues = this.nodes[i].split("|");
		if (nodeValues[1] == parentNode) return true;
	}
	return false;
}
// Checks if a node is the last sibling
site_TreeToolClass.prototype.lastSibling = function(node, parentNode) {
	var lastChild = 0;
	for (i=0; i< this.nodes.length; i++) {
		var nodeValues = this.nodes[i].split("|");
		if (nodeValues[1] == parentNode)
			lastChild = nodeValues[0];
	}
	if (lastChild==node) return true;
	return false;
}
// Adds a new node in the tree
site_TreeToolClass.prototype.addNode = function(parentNode, recursedNodes) {
	for (var i = 0; i < this.nodes.length; i++) {

		var nodeValues = this.nodes[i].split("|");
		if (nodeValues[1] == parentNode) {
			
			var ls	= this.lastSibling(nodeValues[0], nodeValues[1]);
			var hcn	= this.hasChildNode(nodeValues[0]);
			var ino = this.isNodeOpen(nodeValues[0]);
			var NodeType = nodeValues[4];

			// Write out line & empty icons
			for (g=0; g<recursedNodes.length; g++) {
				if (recursedNodes[g] == 1) this.ReplaceDocumentWrite("<img src=\"" + site_objTreeTool.baseScriptURL  + "Images/line.gif\" align=\"absbottom\" alt=\"\" />");
				else  this.ReplaceDocumentWrite("<img src=\"" + site_objTreeTool.baseScriptURL + "Images/empty.gif\" align=\"absbottom\" alt=\"\" />");
			}

			// put in array line & empty icons
			if (ls) recursedNodes.push(0);
			else recursedNodes.push(1);

			// Write out join icons
			if (hcn) {
				if (ls) {
					this.ReplaceDocumentWrite("<a href=\"#\" onclick=\"site_objTreeTool.oc('" + nodeValues[0] + "', 1); return false;\"><img id=\"site_idtreejoin" + nodeValues[0] + "\" src=\""+site_objTreeTool.baseScriptURL + "Images/");
					 	if (ino) this.ReplaceDocumentWrite("minus");
						else this.ReplaceDocumentWrite("plus");
					this.ReplaceDocumentWrite("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				} else {
					this.ReplaceDocumentWrite("<a href=\"#\" onclick=\"site_objTreeTool.oc('" + nodeValues[0] + "', 1); return false;\"><img id=\"site_idtreejoin" + nodeValues[0] + "\" src=\"" + site_objTreeTool.baseScriptURL + "Images/");
						if (ino) this.ReplaceDocumentWrite("minus");
						else this.ReplaceDocumentWrite("plus");
					this.ReplaceDocumentWrite(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
				}
			} else {
				if (ls) this.ReplaceDocumentWrite("<img src=\""+site_objTreeTool.baseScriptURL +"Images/join.gif\" align=\"absbottom\" alt=\"\" />");
				else this.ReplaceDocumentWrite("<img src=\"" + site_objTreeTool.baseScriptURL  + "Images/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
			}

			// Start link			
			this.ReplaceDocumentWrite("<a id=\"site_idtreehref"+ nodeValues[0] +"\" ");
			this.ReplaceDocumentWrite("href=\"#\" onclick= \"site_objTreeTool.OnNodeClick('"+nodeValues[0]+"','"+ nodeValues[3] +"');\"");
			this.ReplaceDocumentWrite(" onmouseout=\"window.status=' ';return true;\">");					
			this.ReplaceDocumentWrite("<input type=checkbox ");
			if (nodeValues[4] == '0')
			    this.ReplaceDocumentWrite("checked ");
			this.ReplaceDocumentWrite("style=\"border-style:none;vertical-align:bottom;\" onclick=\"event.cancelBubble = true; site_objTreeTool.OnChecked('"+nodeValues[0]+"', this.checked);\" onchange=\"event.cancelBubble = true; site_objTreeTool.OnChecked('"+nodeValues[0]+"', this.checked);\" />");				
			this.ReplaceDocumentWrite("<img id=\"site_idtreeicon" + nodeValues[0] + "\" src=\"/img/folder_yellow.png\" align=\"absbottom\" alt=\"eFolder\" />")
			
			// Write out node name
			this.ReplaceDocumentWrite(this.space + this.HtmlEncode(nodeValues[2]));

			// End link
			var strDump = this.DumpArray(recursedNodes);
			this.ReplaceDocumentWrite("</a>");
			this.ReplaceDocumentWrite("&nbsp;&nbsp;<a id=\"site_idtreenew"+ nodeValues[0] +"\" class=\"treenewfolder\" ");
			this.ReplaceDocumentWrite("href=\"#\" onclick=\"site_objTreeTool.OnNewFolder('"+nodeValues[0]+ "','" + strDump + "');return false;\">");
			this.ReplaceDocumentWrite("<img align=middle alt=\"New Child eFolder\" style=\"border:0;\" src=\"" + sRootUrl + "Webservices/scripted/images/sadd.gif\"></a>"); 
			if (nodeValues[3] == "0")
			{
			    this.ReplaceDocumentWrite("&nbsp;&nbsp;<a id=\"site_idtreedelete"+ nodeValues[0] +"\" class=\"treenewfolder\" ");
			    this.ReplaceDocumentWrite("href=\"#\" onclick=\"site_objTreeTool.OnDelete('"+nodeValues[0]+ "','" + strDump.substr(0, strDump.length - 1) + "');return false;\">");
			    this.ReplaceDocumentWrite("<img align=middle alt=\"Remove eFolder\" style=\"border:0;\" src=\"" + sRootUrl + "Webservices/scripted/images/sdelete.gif\"></a>"); 
			}
			this.ReplaceDocumentWrite("<br/>");
			
			// If node has children write out divs and go deeper
			if (hcn) {
				this.ReplaceDocumentWrite("<div id=\"site_idtreediv" + nodeValues[0] + "\"");
					if (!ino) this.ReplaceDocumentWrite(" style=\"display: none;\"");
				this.ReplaceDocumentWrite(">");
				this.addNode(nodeValues[0], recursedNodes);
				this.ReplaceDocumentWrite("</div>");
			}
			
			// remove last line or empty icon 
			recursedNodes.pop();
		}
	}
}
// Opens or closes a node
site_TreeToolClass.prototype.oc = function(node, bottom) {
	//Root node  always opened
	if(this.RootNode == node)
		return;
	var theDiv = document.getElementById("site_idtreediv" + node);
	var theJoin	= document.getElementById("site_idtreejoin" + node);
	var theIcon = document.getElementById("site_idtreeicon" + node);
	if (theDiv.style.display == 'none') {
		if (bottom==1) theJoin.src = this.icons[3].src;
		else theJoin.src = this.icons[2].src;
		theIcon.src = this.icons[5].src;
		theDiv.style.display = '';
	} else {
		if (bottom==1) theJoin.src = this.icons[1].src;
		else theJoin.src = this.icons[0].src;
		theIcon.src = this.icons[4].src;
		theDiv.style.display = 'none';
	}
}

site_TreeToolClass.prototype.OpenNode = function(node,bottom)
{
	if(this.RootNode == node)
		return;
	var theDiv = document.getElementById("site_idtreediv" + node);
	var theJoin	= document.getElementById("site_idtreejoin" + node);
	var theIcon = document.getElementById("site_idtreeicon" + node);
	
	if (bottom==1) theJoin.src = this.icons[3].src;
	else theJoin.src = this.icons[2].src;

	theIcon.src = this.icons[5].src;
	theDiv.style.display = '';
}

site_TreeToolClass.prototype.DumpArray = function(recursedNodes)
{
	var strDump = "";
	for (var g=0; g<recursedNodes.length; g++) {
		if (recursedNodes[g] == 1) 
			strDump = strDump +"1";
		else
			strDump = strDump +"0";
	}
	return strDump;
}

site_TreeToolClass.prototype.RedumpArray = function(strDump)
{
	var recursedNodes = new Array();
	while (strDump.length > 0)
	{
		var firstChar;
		firstChar = strDump.charAt(0);
		if (firstChar=='1')
			recursedNodes.push(1);
		else
			recursedNodes.push(0);
		strDump = strDump.substr(1);
	}
	return recursedNodes;
}

site_TreeToolClass.prototype.AddMinus = function(id, index, grandparent, isbottom, isReversed)
{
	for (var i=index-1; i >=0; i-- )
	{
		var oElement = grandparent.childNodes[i];
		if (!isReversed)
		{
			if (oElement.tagName == "IMG")
			{
				if (isbottom)
				{
					if (oElement.src.toLowerCase().indexOf("joinbottom.gif") != -1)
						break;
				}
				else
				{
					if (oElement.src.toLowerCase().indexOf("join.gif") != -1)
						break;
				}
			}
		}
		else
		{
			if ((oElement.tagName == "A") &&(oElement.childNodes.length > 0))
			{
				oElement = oElement.childNodes[0];
				if (oElement.tagName == "IMG")
				{
					if (isbottom)
					{
						if (oElement.src.toLowerCase().indexOf("minusbottom.gif") != -1)
						{
							oElement = oElement.parentNode;
							break;
						}
					}
					else
					{
						if (oElement.src.toLowerCase().indexOf("minus.gif") != -1)
						{
							oElement = oElement.parentNode;
							break;
						}
					}
				}
			}
		}
	}
	if (!isReversed)
	{
		var oHref = document.createElement("a");
		//oHref.href = "javascript: oc('" + id + "'," + isbottom + ")";
		oHref.href = "#";
		oHref.onclick = Function("site_objTreeTool.oc('" + id + "'," + isbottom + "); return false;")
		oElement.parentNode.insertBefore(oHref,oElement.nextSibling);
		var oImg = document.createElement("img");
		oImg.id = "site_idtreejoin" + id;
		if (isbottom)
			oImg.src = site_objTreeTool.baseScriptURL + "Images/minusbottom.gif";
		else
			oImg.src = site_objTreeTool.baseScriptURL + "Images/minus.gif";
		oImg.align="absbottom";
		oImg.alt = "Open/Close node";
		oHref.appendChild(oImg);
	}
	else
	{
		var oImg = document.createElement("img"); 
		if (isbottom)
			oImg.src = site_objTreeTool.baseScriptURL  +"Images/joinbottom.gif";
		else
			oImg.src = site_objTreeTool.baseScriptURL  + "Images/join.gif";
		oImg.align="absbottom";
		oImg.alt = "";
		oElement.parentNode.insertBefore(oImg,oElement.nextSibling);
	}
	var parentNode = oElement.parentNode;
	parentNode.removeChild(oElement);
}

site_TreeToolClass.prototype.OnNewFolder = function(id, strDump)
{
	var recursedNodes;
	recursedNodes= this.RedumpArray(strDump);
	//find parent tag
	var parentAtag =  document.getElementById("site_idtreenew" + id);
	//find <BR> to define where to insert 
	var grandparent =  parentAtag.parentNode;
	var findAtag = false;
	var needInsertDivTag = false;
	var referenceNode;
	for (var i=0;i < grandparent.childNodes.length ; i++ )
	{
		if (grandparent.childNodes[i].tagName == "A")
		if (grandparent.childNodes[i].id == "site_idtreenew" + id)
			findAtag = true;
		if (findAtag)
		if (grandparent.childNodes[i].tagName == "BR")
		{
			//the last BR
			referenceNode = grandparent.childNodes[i];
			if ((strDump !='')&&(i == grandparent.childNodes.length -1 ))
			{
				//is parent is bottom
				this.AddMinus(id, i, grandparent, 0, false);
				needInsertDivTag = true;
			}
			else if ((strDump =='')||(grandparent.childNodes[i+1].tagName == "DIV") )
			{
				if (i+1 == grandparent.childNodes.length-1)
				{
					if (grandparent.childNodes[i+1].style.display=='none')
						this.oc(id, 1);
				}
				else if ( i+1 != grandparent.childNodes.length)
				{			
					if (grandparent.childNodes[i+1].style.display=='none')
					    this.oc(id, 0); 
				}
				if (strDump != '')
					referenceNode = grandparent.childNodes[i+1];
				else
					referenceNode = grandparent;
				needInsertDivTag = false;
				this.changeTheLastSibling(referenceNode, strDump, false);
			}
			else
			{
				//parent is not bottom
				this.AddMinus(id, i, grandparent, 1, false);
				needInsertDivTag = true;
			}
			break;
		}
	}
	if (findAtag)
	{
		if (needInsertDivTag)
		{
			//create Div tag.
			var oDivTag = document.createElement("div");
			oDivTag.id = "site_idtreediv" + id;
			oDivTag.style.display = '';
			referenceNode.parentNode.insertBefore(oDivTag, referenceNode.nextSibling);
			referenceNode = oDivTag;
		}
		this.AddNewFolderTextbox(id, this.maxvalue,referenceNode, recursedNodes);
		this.maxvalue ++ ;
	}
}

site_TreeToolClass.prototype.changeLastSiblingOnNewFolder = function(oDivtag, strDump)
{
    var isTheLast = true;
    var newstrDump;
    for (var i=oDivtag.childNodes.length-1; i >= 0; i --)
    {
        var oElement = oDivtag.childNodes[i];
        if (oElement.tagName == "A" && oElement.id.indexOf("site_idtreenewSN") == 0 )
        {
            if (isTheLast)
            {
                oElement.onclick = Function("site_objTreeTool.OnNewFolder('"+ oElement.id.substr(14) + "','" + strDump + "0'); return false;");
                idTheLast = false;
            }
            else
                oElement.onclick = Function("site_objTreeTool.OnNewFolder('"+ oElement.id.substr(14) + "','" + strDump + "1'); return false;");                
        }
        if (oElement.tagName == "DIV")
        {
            if (isTheLast)
                this.changeLastSiblingOnNewFolder(oElement, strDump + "0");
            else
                this.changeLastSiblingOnNewFolder(oElement, strDump + "1");    
         }
    }
}

site_TreeToolClass.prototype.changeTheLastSibling = function(oDivtag, strDump, isReversed)
{
	var isLast = false;
	for (var i=oDivtag.childNodes.length-1; i >= 0; i --)
	{
		var oElement = oDivtag.childNodes[i];
		if (!isLast)
		{
			//Div contains childs of the last sibling
			if (oElement.tagName == "DIV")
			{
				//replace image at (strDump.length+1) position
				var newstrDump;
				if (!isReversed)
				{
					this.insertLineImage(oElement, strDump + "1",isReversed);
					newstrDump = strDump + "1";
			    }
				else
				{
					this.insertLineImage(oElement, strDump + "0",isReversed);
					newstrDump = strDump + "0";
			    }
                this.changeLastSiblingOnNewFolder(oElement, newstrDump);
			}
			//encounter the last sibling, exit (isLast = true)
			if (oElement.tagName == "A" && oElement.id.indexOf("site_idtreenewSN") == 0 )
			{
				if (!isReversed)
				{
					oElement.href= "#";
					oElement.onclick = Function("site_objTreeTool.OnNewFolder('"+ oElement.id.substr(14) + "','" + strDump + "1'); return false;");
				}
				else
				{
					oElement.href= "#";
					oElement.onclick = Function("site_objTreeTool.OnNewFolder('"+ oElement.id.substr(14) + "','" + strDump + "0'); return false;");
				}
				isLast = true;
			}
		}
		else
		{
			if (oElement.tagName == "BR")
			{
				break;
			}
			if (oElement.tagName == "A")
			{
				oElement = oElement.childNodes[0];
				// create a bottom line from the last sibling.
				if (oElement.tagName == "IMG")
				{
					var nFilename;
					if (!isReversed)
					{
						var index = oElement.src.indexOf("minus.gif");
						nFilename = 5;
						if (index == -1)
						{
							index = oElement.src.indexOf("plus.gif");
							nFilename = 4;
						}
						if (index != -1)
						{
							oElement.src = oElement.src.substr(0, index + nFilename) + "bottom" + oElement.src.substr(index + nFilename);
							break;
						}
					}
					else
					{
						var index = oElement.src.indexOf("minusbottom.gif");
						nFilename = 5;
						if (index == -1)
						{
							index = oElement.src.indexOf("plusbottom.gif");
							nFilename = 4;
						}
						if (index != -1)
						{
							oElement.src = oElement.src.substr(0, index + nFilename) + oElement.src.substr(index + nFilename + 6);
							break;
						}
					}
				}
			}
			if (oElement.tagName == "IMG")
			{
				if (!isReversed)
				{
					var index = oElement.src.indexOf("join.gif");
					if (index != -1)
					{
						oElement.src = oElement.src.substr(0, index + 4) + "bottom" + oElement.src.substr(index+4);
						break;
					}
				}
				else
				{
					var index = oElement.src.indexOf("joinbottom.gif");
					if (index != -1)
					{
						oElement.src = oElement.src.substr(0, index + 4) + oElement.src.substr(index+10);
						break;
					}
				}
			}
		}
	}
}

site_TreeToolClass.prototype.insertLineImage = function(oElement, strDumpEx,isReversed)
{
	var nCountImage = 0;
	lineImageOrder = strDumpEx.length;
	if (lineImageOrder == 0)
		return;
	for (var i=0; i < oElement.childNodes.length ; i++)
	{
		var oChildElement = oElement.childNodes[i];
		if (oChildElement.tagName == "IMG")
			nCountImage++; 
		else
			nCountImage = 0; 
		if (nCountImage == lineImageOrder)
			if (!isReversed)
				oChildElement.src = site_objTreeTool.baseScriptURL + "Images/line.gif";
			else
				oChildElement.src = site_objTreeTool.baseScriptURL  + "Images/empty.gif";
		/*if (oChildElement.tagName == "A" && oChildElement.id.indexOf("vani_idtreenewSN") == 0)
		{
			var iIndex = oChildElement.href.indexOf(",'");
			oChildElement.href = oChildElement.href.substr(0,iIndex+2) + strDumpEx + oChildElement.href.substr(iIndex+2+strDumpEx.length);
		}*/
		if (oChildElement.tagName == "DIV")
		    this.insertLineImage(oChildElement, strDumpEx, isReversed);
	}
}


site_TreeToolClass.prototype.AddNewFolderTextbox = function(id, max,referenceNode,recursedNodes)
{
	for (var g=0; g<recursedNodes.length; g++)
	{
		//insert images
		var oImg = document.createElement("img");
		if (recursedNodes[g] == 1)
			oImg.src = site_objTreeTool.baseScriptURL + "Images/line.gif";
		else
			oImg.src = site_objTreeTool.baseScriptURL  + "Images/empty.gif";
		oImg.align = "absbottom";
		oImg.alt = "";
		referenceNode.appendChild(oImg);
	}
	var oImg = document.createElement("img");
	oImg.src = site_objTreeTool.baseScriptURL  + "Images/join.gif";
	oImg.align = "absbottom";
	oImg.alt = "";
	referenceNode.appendChild(oImg);
	var oTextbox = document.createElement("input");
	oTextbox.type = "text";
	oTextbox.value = "";
	oTextbox.style.width = "80px";
	oTextbox.style.height= "14px";
	oTextbox.style.borderStyle="solid";
	oTextbox.style.borderWidth = "1px";
	oTextbox.style.fontFamily = "Verdana, Geneva, Arial, Helvetica, sans-serif";
	oTextbox.style.fontSize = "11px";
	oTextbox.onchange = Function("site_objTreeTool.finishCreate(this,'" + id + "',"  + max + ",'" + this.DumpArray(recursedNodes)+ "');");
	oTextbox.onblur = Function("site_objTreeTool.finishCreate(this,'" + id + "',"  + max + ",'" + this.DumpArray(recursedNodes)+ "');");
	oTextbox.ondeactivate= Function("site_objTreeTool.finishCreate(this,'" + id + "',"  + max + ",'" + this.DumpArray(recursedNodes)+ "');");
	oTextbox.onkeypress = site_objTreeTool.finishChange;
	oTextbox.varID =  id;
    oTextbox.varMax = max;
    oTextbox.varDump = this.DumpArray(recursedNodes);
	referenceNode.appendChild(oTextbox);
	oTextbox.focus();
}

site_TreeToolClass.prototype.finishChange = function(e)
{
    var keynum = 0;
    var obj;
    if (window.event)
    {
	    keynum = window.event.keyCode;
	    obj = window.event.srcElement;
	}
	else if (e.which)
	{
	    keynum = e.which;
	    obj = e.target;
    }
	if (keynum == 13)
	{
		site_objTreeTool.finishCreate(obj,obj.varID,obj.varMax,obj.varDump);
		return false;
	}
	return true;
}

site_TreeToolClass.prototype.trim = function(str1)
{
	var str= str1; 
	if (str.length == "") return str;
	while(str.length != 0 && str.charAt(0)==' ')
		str = str.substr(1);
	while(str.length != 0 && str.charAt(str.length-1)==' ')
		str = str.substr(0, str.length - 1);
	return str;
}

site_TreeToolClass.prototype.OnChecked = function(value, checked)
{
    var index = site_objTreeTool.getArrayId(value) ;
    var NodeValues = site_objTreeTool.nodes[index].split("|");
    var nStrPos;
    // set to label
    var strNameSelected = site_objTreeTool.trim(NodeValues[2]);
    //nodevalue[4] == 0 mean checked
    
    if (checked)
    {
        if (NodeValues[4] == '0')
            return;
        if ((NodeValues[3] != '0') && (NodeValues[3] != '-1'))
	        site_objTreeTool.arrNodeSelected.push(NodeValues[3]);
	    else
	        site_objTreeTool.mapNodeAddedName.push(NodeValues[0] + "|" + strNameSelected);
	    site_objTreeTool.nodes[index] = NodeValues[0] + "|" + NodeValues[1] + "|" + NodeValues[2] + "|" + NodeValues[3] + "|0" ; 
	    if (site_objTreeTool.strNodesSelected != '')
	        site_objTreeTool.strNodesSelected += ",";
	    site_objTreeTool.strNodesSelected += strNameSelected; 
	}
	else
	{
	    if (NodeValues[4] == '1')
	        return;
	    site_objTreeTool.nodes[index] = NodeValues[0] + "|" + NodeValues[1] + "|" + NodeValues[2] + "|" + NodeValues[3] + "|1" ;     
	    if ((NodeValues[3] != '0') && (NodeValues[3] != '-1'))
	    {
	        for (var i=0; i<site_objTreeTool.arrNodeSelected.length; i++)
	        {
	            if (site_objTreeTool.arrNodeSelected[i] == NodeValues[3])
	            {
	                site_objTreeTool.arrNodeSelected.splice(i,1);
	                break;
	            }
	        }
	    }
	    else
	    {
	        for (var i=0; i<site_objTreeTool.mapNodeAddedName.length; i++)
	        {
	            if (site_objTreeTool.mapNodeAddedName[i].indexOf(NodeValues[0] + ",") == 0 )
	            {
	                site_objTreeTool.mapNodeAddedName.splice(i,1);
	                break;
	            }
	        }
	    }
	    if (strNameSelected == site_objTreeTool.strNodesSelected)
	        site_objTreeTool.strNodesSelected = "";
	    else
	    {
	        nStrPos = site_objTreeTool.strNodesSelected.indexOf(strNameSelected + ",");
	        if (nStrPos == -1)
	            nStrPos = site_objTreeTool.strNodesSelected.indexOf("," + strNameSelected);
	        if (nStrPos != -1)    
	            site_objTreeTool.strNodesSelected = site_objTreeTool.strNodesSelected.substr(0,nStrPos) +  site_objTreeTool.strNodesSelected.substr(nStrPos + strNameSelected.length + 1);
	    }    
	}
	if (site_objTreeTool.strNodesSelected.length > 10 )
        strNameSelected = site_objTreeTool.strNodesSelected.substr(0,10) + "...";
    else
        strNameSelected = site_objTreeTool.strNodesSelected;
    document.getElementById('site_idTreeNodeSelected').innerHTML = "Selected eFolder: " + strNameSelected;
    
    //assign into strTagIt
    var strTagIt;
    if (site_objTreeTool.strNodesSelected != "")
    {
        strTagIt = site_objTreeTool.strNodesSelected;
        if (site_objTreeTool.strNodesSelected.length > 75)    
            strTagIt = site_objTreeTool.strNodesSelected.substr(0,75) + "..." ;
    }
    else
        strTagIt = "-- Select eFolder --";
    if (document.getElementById("hplTagIt"))    
        document.getElementById("hplTagIt").innerHTML =  strTagIt;
}

site_TreeToolClass.prototype.finishCreate = function(obj,id,max, strDump)
{
	var oDiv = obj.parentNode;
	var str = this.trim(obj.value); 
	var isCreated = false;
	if (str!="")
	    if (str.length <=30)
	        isCreated = true;    
	if (isCreated)
	{
		var oElement = document.createElement("a");
		var oChild;
		oElement.id = "site_idtreehrefSN" + max;
		//oElement.href = "javascript:OnNodeClick('SN" + max + "','')";
		oElement.href = "#";
		oElement.onclick = Function("site_objTreeTool.OnNodeClick('SN" + max + "',''); ");
		oElement.onmouseout =  Function("window.status=''; return true;");
		oDiv.appendChild(oElement);
		oChild = document.createElement("input");
		oChild.type ="checkbox";
		oChild.style.borderStyle = "none";
		oChild.onclick = Function("event.cancelBubble = true; site_objTreeTool.OnChecked('SN" + max + "', this.checked);");
		oChild.onchange = Function("event.cancelBubble = true; site_objTreeTool.OnChecked('SN" + max + "', this.checked);")
		oChild.style.verticalAlign = "bottom";
		oElement.appendChild(oChild);
		oChild.checked = false;
		oChild = document.createElement("img");
		oChild.id = "site_idtreeiconSN" + max;
		oChild.src = "/img/folder_yellow.png";
		oChild.align = "absbottom";
		oChild.alt = "eFolder";
		oElement.appendChild(oChild);
		oChild = document.createTextNode(" " + this.trim(str))
		oElement.appendChild(oChild);
		oElement = document.createTextNode("  ");
		oDiv.appendChild(oElement);
		oElement = document.createElement("a");
		oElement.id = "site_idtreenewSN" + max;
		oElement.className = "treenewfolder";
		oElement.href = "#";
		oElement.onclick = Function("site_objTreeTool.OnNewFolder('SN" + max +"','" + strDump +"0'); return false;");
		oDiv.appendChild(oElement);
		//create <img> as add button
		oChild = document.createElement("img");
		oChild.align = "middle";
		oChild.style.border= "0";
		oChild.alt = "New Child eFolder";
		oChild.src = sRootUrl + "Webservices/scripted/images/sadd.gif";
		oElement.appendChild(oChild);
		//create delete link
		oElement = document.createTextNode("  ");
		oDiv.appendChild(oElement);
		oElement = document.createElement("a");
		oElement.id = "site_idtreedeleteSN" + max;
		oElement.className = "treenewfolder";
		oElement.href = "#";
		oElement.onclick = Function("site_objTreeTool.OnDelete('SN" + max +"','" + strDump +"'); return false;");
		oDiv.appendChild(oElement);
		oChild = document.createElement("img");
		oChild.align = "middle";
		oChild.style.border= "0";
		oChild.alt = "Remove eFolder";
		oChild.src = sRootUrl + "Webservices/scripted/images/sdelete.gif";
		oElement.appendChild(oChild);
		//end create delete link
		oElement = document.createElement("br");
		oDiv.appendChild(oElement);
		this.nodes.push("SN" + max + "|" + id  + "|" + str + "|0|1");
		obj.value = ""; //chrome fixed, removeChild will raise event on Chrome
		oDiv.removeChild(obj);
		this.OnNodeClick("SN" + max);
		//site_objTreeTool.OnChecked('SN' + max, true);
	} 
	else
	{
		//roll back
		oDiv  = obj.parentNode;
		var oElement;
		while (oDiv.childNodes.length > 0)
		{
			oElement = oDiv.childNodes[oDiv.childNodes.length - 1];
			if (oElement.tagName == "BR" || oElement.tagName == "DIV")
				break;
			oDiv.removeChild(oElement);
		}
		if (oDiv.childNodes.length == 0)
		{
			//findout Element before.
			var oParent = oDiv.parentNode;
			oElement = null;
			var i;
			for (i =0 ; i< oParent.childNodes.length ; i++  )
			{
				var oTempEle = oParent.childNodes[i];
				if (oTempEle.tagName == "BR")
				{
					oElement = oTempEle;
				}
				if ((oTempEle.tagName == "DIV")&&(oTempEle.id == oDiv.id))
				{
					i--;
					break;
				}
			}
			if (oElement != null)
			{
				oParent.removeChild(oDiv);
				var isbottom;
				if (i == oParent.childNodes.length-1)
					isbottom =0;
				else
					isbottom =1;
				this.AddMinus(id, i, oParent, isbottom, true);
			}
		}
		else
		{
			this.changeTheLastSibling(oDiv, strDump, true);
		}
		if (str.length > 30)
	        alert("Folder name must be less than 30 characters.");
	}
}

site_TreeToolClass.prototype.ReCheckNamesSelected = function(id)
{
    for (var i=0; i < this.mapNodeAddedName.length; i++)
    {
        if (this.mapNodeAddedName[i].indexOf(id) == 0)
        {
            var arrTemp = this.mapNodeAddedName[i].split('|');
            this.mapNodeAddedName.splice(i, 1);
            strNameSelected = arrTemp[1];
            if (strNameSelected == this.strNodesSelected)
	            this.strNodesSelected = "";
	        else
	        {
	            nStrPos = this.strNodesSelected.indexOf(strNameSelected + ",");
	            if (nStrPos == -1)
	                nStrPos = this.strNodesSelected.indexOf("," + strNameSelected);
	            if (nStrPos != -1)    
	                this.strNodesSelected = this.strNodesSelected.substr(0,nStrPos) +  this.strNodesSelected.substr(nStrPos + strNameSelected.length + 1);
	        }    
            if (this.strNodesSelected.length > 10 )
                strNameSelected = this.strNodesSelected.substr(0,10) + "...";
            else
                strNameSelected = this.strNodesSelected;
            document.getElementById('site_idTreeNodeSelected').innerHTML = "Selected eFolder: " + strNameSelected;
            // assign to strTagIt
            var strTagIt;
            if (site_objTreeTool.strNodesSelected != "")
            {
                strTagIt = site_objTreeTool.strNodesSelected;
                if (site_objTreeTool.strNodesSelected.length > 10)    
                    strTagIt = site_objTreeTool.strNodesSelected.substr(0,10) + "..." ;
            }
            else
                strTagIt = "-- Pick or create a new eFolder for this note --";
            if (document.getElementById("hplTagIt"))
                document.getElementById("hplTagIt").innerHTML =  strTagIt;
            break;
        }
    }
}

//delete in array this.nodes
site_TreeToolClass.prototype.DeleteNode = function(id)
{
    var nodesDeleted =new Array;
    var firstIndex = this.getArrayId(id);
    var isDeleted;
    //Get Parent of nodes
    var nodeValues = this.nodes[i].split("|");
    /*if (nodeValues[1] != "0")
        this.OnNodeClick(nodeValues[1]);*/
    this.nodes.splice(firstIndex,1);
    this.ReCheckNamesSelected(id);
    nodesDeleted.push(id);
   	i = firstIndex
   	while (i<this.nodes.length) {
        nodeValues = this.nodes[i].split("|");
        var isDeleted = false;
        for(j=0; j<nodesDeleted.length; j++)
            if (nodeValues[1]== nodesDeleted[j])
            {
                isDeleted = true;
                break;
            }
        if (isDeleted)
        {
            nodesDeleted.push(nodeValues[0]);
            this.nodes.splice(i,1 );
            this.ReCheckNamesSelected(nodeValues[0]);
        }
        else
            i ++ ;
    }
}

//call to delete a folder.
site_TreeToolClass.prototype.OnDelete = function(id, strDump)
{
    //delete node
    var obj =  document.getElementById("site_idtreedelete" + id);
	var oDiv  = obj.parentNode;
	var oAdjacent;
	var oElement;
	// BR tag "end of information of this node"
	while(obj.tagName != "BR") 
	    obj = obj.nextSibling;
	// if the node having children, delete children 
	if (obj.nextSibling != null)
	    if (obj.nextSibling.tagName == "DIV")
	        oDiv.removeChild(obj.nextSibling);
	//delete the node itself
	oAdjacent = obj.previousSibling;
	while(true)
	{
	    oDiv.removeChild(obj);
	    if (oAdjacent == null) 
	        break;
	    if (oAdjacent.tagName == "BR")
	        break;
	    if (oAdjacent.tagName == "DIV")
	        break;
	    obj = oAdjacent;
	    oAdjacent = obj.previousSibling;
	}
	
	this.DeleteNode(id);
	
	if (oDiv.childNodes.length == 0)
	{
		//findout Element before.
		var oParent = oDiv.parentNode;
		oElement = null;
		var i;
		for (i =0 ; i< oParent.childNodes.length ; i++  )
		{
			var oTempEle = oParent.childNodes[i];
			if (oTempEle.tagName == "BR")
			{
				oElement = oTempEle;
			}
			if ((oTempEle.tagName == "DIV")&&(oTempEle.id == oDiv.id))
			{
				i--;
				break;
			}
		}
		if (oElement != null)
		{
			oParent.removeChild(oDiv);
			var isbottom;
			if (i == oParent.childNodes.length-1)
				isbottom =0;
			else
				isbottom =1;
			this.AddMinus(id, i, oParent, isbottom, true);
		}
	}
	else
	{
		this.changeTheLastSibling(oDiv, strDump, true);
	}
}

/* User Click into Node*/

site_TreeToolClass.prototype.OnNodeClick = function(id,href)
{	
	var Alink;		
	var index;
	var NodeValues;
	var NodeType;
	/*if(this.CrtNodeId != 1)
	{
		Alink = document.getElementById("vani_idtreehref" + this.CrtNodeId);
		if(Alink != null)
		{
			Alink.style.color = "#006666";
			Alink.style.backgroundColor = "white";
		}
	}*/
	Alink = document.getElementById("site_idtreehref" + id);
	if(Alink != null)	
	{
//		Alink.style.color = "#8b008b";
		//Alink.style.color = "white";
		//Alink.style.backgroundColor = "blue";
		var checkbox = Alink.getElementsByTagName('INPUT')[0];
		if (checkbox)
		{
	        if (checkbox.checked)
	            checkbox.checked = false;
	        else
	            checkbox.checked = true;    
	        site_objTreeTool.OnChecked(id, checkbox.checked);    
	    }       
		this.CrtNodeId = id;
	}
}

site_TreeToolClass.prototype.SetNodeOpened = function(id)
{
	//travel from this node id up to the root and open every node on its way
	var index;
	var prtNodeValues;
	var prtNodeId;
	var OpenedNodeValues;
	var NodesLength;
	var IsLastSibling;
	var OpenedNodeAlink;
	var ALink;

	//set current node

	ALink = document.getElementById("site_idtreehref" + this.CrtNodeId);
	if(ALink != null)
		ALink.style.color = "#006666";

	this.CrtNodeId   = id;
	NodesLength = this.nodes.length;
	index = this.getArrayId(id);
	if(index < NodesLength)
	{
		//get the first parent
		OpenedNodeValues = this.nodes[index].split("|");
		prtNodeId = OpenedNodeValues[1];
		//loop up to the root
		while(prtNodeId != "0")
		{			
			//get parent's parent
			index = this.getArrayId(prtNodeId);
			if(index < NodesLength)
			{
				prtNodeValues = this.nodes[index].split("|");
				prtNodeId = prtNodeValues[1];
				//open parent node
				IsLastSibling = this.lastSibling(prtNodeValues[0],prtNodeId);
				if(IsLastSibling)
					{
					this.OpenNode(prtNodeValues[0],1);
					}
				else
					{
					this.OpenNode(prtNodeValues[0],0);
					}	
					
			}
			else
			{
				this.OpenNode(prtNodeId,0);	
				prtNodeId = 0;		
			}			
			
		}		
	}	
	//change color for the opened node
	OpenedNodeAlink = document.getElementById("site_idtreehref" + id);
	if(OpenedNodeAlink != null)
	{
		OpenedNodeAlink.style.color = "#8b008b";
	}	
}

// Push and pop not implemented in IE
if(!Array.prototype.push) {
	function array_push() {
		for(var i=0;i<arguments.length;i++)
			this[this.length]=arguments[i];
		return this.length;
	}
	Array.prototype.push = array_push;
}
if(!Array.prototype.pop) {
	function array_pop(){
		lastElement = this[this.length-1];
		this.length = Math.max(this.length-1,0);
		return lastElement;
	}
	Array.prototype.pop = array_pop;
}

site_TreeToolClass.prototype.HtmlEncode = function(str)
{
    var strResult = str;
    strResult = this.replaceAll(strResult,"&","&amp;");
    strResult = this.replaceAll(strResult,"<","&lt;");
    strResult = this.replaceAll(strResult,">","&gt;");
    return strResult;
}

site_TreeToolClass.prototype.replaceAll = function( oldStr,findStr,repStr ) {
    var srchNdx = 0; 
  var newStr = "";  
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
    newStr += repStr;
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
  return newStr;
}

///replaceing ReplaceDocumentWrite
site_TreeToolClass.prototype.ReplaceDocumentWrite = function(strHTML)
{
	this.vani_arrTreeHTML.push(strHTML);
}



/* Hide The Pane */
site_TreeToolClass.prototype.hideTreeToolPane = function(){
	ShowEditTree();
}

site_TreeToolClass.prototype.getScroll = function(dimension)
{
    if (dimension == 0)
        if (document.documentElement.scrollLeft > document.body.scrollLeft)
            return document.documentElement.scrollLeft;
        else
            return document.body.scrollLeft;    
   else
        if (document.documentElement.scrollTop > document.body.scrollTop)
            return document.documentElement.scrollTop;
        else
            return document.body.scrollTop;         
}



site_TreeToolClass.prototype.buildTree = function(){
    this.createTree(Tree,null);
    
    document.getElementById("idChildDivTree").innerHTML = this.vani_arrTreeHTML.join("");
    var strNameSelected;
    if (this.strNodesSelected.length > 10 )
        strNameSelected = this.strNodesSelected.substr(0,10) + "...";
    else
        strNameSelected = this.strNodesSelected;
    document.getElementById('site_idTreeNodeSelected').innerHTML = "Selected eFolder: " + strNameSelected;
}	

/* Json functions*/

site_TreeToolClass.prototype.ToTreeJsonText = function(parentID)
{
    var strJsonText ="";
    if (parentID == "0")    
        strJsonText = "[";
    var i = 0;
    while (i<this.nodes.length)
    { 
        var nodeValues = this.nodes[i].split("|");
        if (nodeValues[1] == parentID)
        {
            strJsonText += "{\"FolderID\":";
            strJsonText += nodeValues[3];
            strJsonText += ",\"FolderName\":\"";
            strJsonText += this.replaceJson(nodeValues[2]);
            strJsonText += "\"";
            if ('0' == nodeValues[4])
                strJsonText += ",\"Selected\":\"Y\"";
            else
                strJsonText += ",\"Selected\":\"N\"";    
            if (this.hasChildNode(nodeValues[0]))
            {
                strJsonText += ",\"Children\":[";
                strJsonText += this.ToTreeJsonText(nodeValues[0]); 
                strJsonText += "]";
            }
            strJsonText += "}";
            if (!this.lastSibling(nodeValues[0], parentID))
                strJsonText += ",";
        }
        i++;
    }
    
    if (parentID == 0)    
        strJsonText += "]";
    return strJsonText;
}

site_TreeToolClass.prototype.FormTreeNewFolder = function()
{
    var objJson = this.strJsonTreeFolder.parseJSON();
    this.BrowseTreeAndFormJsonNewFolder(objJson,0);
    if (this.strNewFolderCreated != "")
		this.strNewFolderCreated += "]";
}

site_TreeToolClass.prototype.BrowseTreeAndFormJsonNewFolder = function(objJson, parentID)
{
    var isNewFolder = false;
    var FolderID = 0;
    if (typeof objJson[0] == "undefined")
    {
       FolderID = parseInt(objJson.FolderID);
       if (FolderID == 0)    
       {
            isNewFolder = true;
            if (this.strNewFolderCreated == "")
                this.strNewFolderCreated = "[";//this.strNewFolderCreated = "\"NewFolders\":[";
            else if (parentID >= 0)
                this.strNewFolderCreated  += ","; 
            this.strNewFolderCreated   += "{";
            if (parentID >=0)
			{
				this.strNewFolderCreated += "\"parentID\":";
				this.strNewFolderCreated  +=  parentID;
				this.strNewFolderCreated +=  ",";
			}
			var strName;
			this.strNewFolderCreated += "\"Name\":\"";
			this.strNewFolderCreated += this.replaceJson(objJson.FolderName);
			this.strNewFolderCreated  += "\"";
			if (objJson.Selected == "Y")
				this.strNewFolderCreated += ",\"Selected\":\"Y\"";
		    else
		        this.strNewFolderCreated += ",\"Selected\":\"N\"";
       }
       if (objJson.Children != null)
            objJson = objJson.Children
       else
       {
            if (isNewFolder)
				this.strNewFolderCreated += "}";
			return isNewFolder;
       }
    }
    var child;
    var hasChildNewFolder = false;        
    var i;
    var nChildParentID;
    if (objJson.length > 0)
    {
        if (isNewFolder)
			this.strNewFolderCreated += ",\"Children\":[";
		for (i=0; i<objJson.length; i++)
		{	
			child = objJson[i];
			if ((!isNewFolder)&&(FolderID == 0))
				nChildParentID = parentID;
			else if (isNewFolder)
				nChildParentID = -1;
			else 
				nChildParentID = FolderID; 
			if (hasChildNewFolder && (nChildParentID == -1))
				this.strNewFolderCreated += ",";
			if (this.BrowseTreeAndFormJsonNewFolder(child, nChildParentID))
				hasChildNewFolder= true;
		}
		if (isNewFolder)
			this.strNewFolderCreated += "]";
    }
    if (isNewFolder)
		this.strNewFolderCreated += "}";
	return isNewFolder;
}

site_TreeToolClass.prototype.replaceJson = function(str)
{
    var strResult = str;
    strResult = this.replaceAll(strResult,"\\","\\\\");
    strResult = this.replaceAll(strResult,"\"","\\\"");
//    strResult = this.replaceAll(strResult,"/", "\\/");
	strResult = this.replaceAll(strResult,"\b", "\\b");
	strResult = this.replaceAll(strResult,"\t", "\\t");
	strResult = this.replaceAll(strResult,"\n", "\\n");
	strResult = this.replaceAll(strResult,"\f", "\\f");
	strResult = this.replaceAll(strResult,"\r", "\\r");
    return strResult;
}
/* string functions */
site_TreeToolClass.prototype.replaceAll = function( oldStr,findStr,repStr ) {
    var srchNdx = 0; 
  var newStr = "";  
  while (oldStr.indexOf(findStr,srchNdx) != -1)  
  {
    newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
    newStr += repStr;
    srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
  }
  newStr += oldStr.substring(srchNdx,oldStr.length);
  return newStr;
}


