	function split(strInput, delimiter) {
		var startPoint = 0;
		var endPoint;
		var arrReturn = new Array;
		
		ok = true;
		i = 0;	
		while (ok) {				
			endPoint = strInput.indexOf(delimiter, startPoint);
			if (endPoint == -1)  {
				endPoint = strInput.length;
				ok = false;
			}
			arrReturn[i] = strInput.substring(startPoint, endPoint);		
			startPoint = endPoint + delimiter.length;		
			i = i + 1; 
		}
		
		return 	arrReturn
	}
	
	function join(arrInput, delimiter) {
		var strReturn = ''; 
	
		for (var i=0; i<arrInput.length; i++) {
				if (strReturn!='') strReturn = strReturn + delimiter + arrInput[i];
				else  strReturn = arrInput[i];			
		}
		
		return 	strReturn;
	}
	
	function split(strInput, delimiter) {
		var startPoint = 0;
		var endPoint;
		var arrReturn = new Array;
		
		ok = true;
		i = 0;	
		while (ok) {				
			endPoint = strInput.indexOf(delimiter, startPoint);
			if (endPoint == -1)  {
				endPoint = strInput.length;
				ok = false;
			}
			arrReturn[i] = strInput.substring(startPoint, endPoint);		
			startPoint = endPoint + delimiter.length;		
			i = i + 1; 
		}
		
		return 	arrReturn
	}
	
	function join(arrInput, delimiter) {
		var strReturn = ''; 
	
		for (var i=0; i<arrInput.length; i++) {
				if (strReturn!='') strReturn = strReturn + delimiter + arrInput[i];
				else  strReturn = arrInput[i];			
		}
		
		return 	strReturn;
	}
	
	function replace(expression, findchr, replacechr, start) {
		 var str=expression;
		 var strlength=str.length;
		 var startpos=start;
		 
		 if (startpos==null) { startpos=0  }
		   for (var i = startpos; i < strlength; i++)  { 
		    var chr = str.charAt(i);
		    if (str.indexOf(findchr,startpos)!=-1) { 
		      num=str.indexOf(findchr,startpos); 
		      str=str.substring(0,num)+replacechr+str.substring(num+1,str.length);
		     }
		 } 
		 return str; 
	}
	
	function getOtherQueryString() {
		var strQueryString = window.location.search;
		var arrTemp = new Array;
		var strReturn = '';
		
		strQueryString = replace(strQueryString, "?", "")
		arrTemp = split(strQueryString, '&');
		for (var i=0; i<arrTemp.length; i++) {		
			if (arrTemp[i].indexOf("NdI")==-1 && arrTemp[i].indexOf("RwI")==-1 && arrTemp[i].indexOf("bOp")==-1 && arrTemp[i].indexOf("bSel")==-1) {
				if(arrTemp[i].indexOf("action=add")==-1) 
					strReturn += '&' + arrTemp[i] 				
			}
		}			
		return 	strReturn;		
	}

	
	function getSelfUrl(){
			sSelfUrl = self.location.href; 
			iIndx = sSelfUrl.indexOf("?");
			if (iIndx > 0)
				sSelfUrl = sSelfUrl.substring(0, iIndx);
			return sSelfUrl;				
	}

	function openNode(item){
//		alert(self.location.pathname)
		if (theCollect[item].open){
			//	Close the node			
			self.location.href=getSelfUrl()+"?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bOp=False" + getOtherQueryString();			
			//self.location.href="AceDbTree.asp?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bSel=False" + getOtherQueryString();						
		}
		else{
			//	Open the node
			//self.location.href="AceDbTree.asp?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bOp=True" + getOtherQueryString();
			self.location.href=getSelfUrl()+"?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bOp=True" + getOtherQueryString();						
		}		
	}

	function select(item){
		if (theCollect[item].selected){
			//	Close the node
			self.location.href="AceDbTree.asp?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bSel=False" + getOtherQueryString();			
		}
		else{
			//	Open the node
			self.location.href="AceDbTree.asp?NdI=" + theCollect[item].DbNodeId + "&RwI=" + theCollect[item].DbRowId + "&bSel=True" + getOtherQueryString();
		}		
	}

	function locate(item){
		
		//parent.right.location.href=theCollect[item].href+"?"+theCollect[item].typename+"=" + theCollect[item].DbRowId;		
		self.location.href=theCollect[item].href+"?"+theCollect[item].typename+"=" + theCollect[item].DbRowId;
	}

	function CreateNode(id, title)
	{
		this.id=id;					//	refered to by the parent property
		this.DbNodeId=0;			//	Number of DataBase Level
		this.DbRowId=0;				//	Id of DataBase record
		
		this.title=title;			//	the text string that appears In the list

		this.parent=null;			// parent is the ID of the parent list item
		this.level=1;				// level is the depth of the list item, 0 being the furthest left on the tree
		this.href="";				// href is the location to open when selected
		
		this.open=false;			// open is a flag that determines whether children are displayed
		this.state=0;				//	state by default

		this.lastChild=false;		

		this.deleted=false;			
		this.selected=false;		// selected is an interenal flag
		
		this.typename = "";
		this.isCached=false;

		dir="_images/tree/";
		this.icon="";
	}

	global=new CreateGlobal();

	function CreateGlobal(){
		// Fonts
		//this.face="Helv,Arial";
		//this.fSize=1;

		// Spacing
		this.vSpace=2;
		this.hSpace=4;
		this.tblWidth=500;
		this.selTColor="#FFCC00";
		this.selFColor="#000000";
		this.selUColor="#CCCCCC";

		// Images
		this.imagedir="_images/tree/";
		this.spaceImg=this.imagedir  + "nothing.gif";
		this.lineImg=this.imagedir  + "vertline.gif";
		this.plusImg=this.imagedir  + "open.gif";
		this.minusImg=this.imagedir  + "close.gif";
		this.emptyImg=this.imagedir + "empty.gif";
		this.plusImgLast=this.imagedir  + "openl.gif";
		this.minusImgLast=this.imagedir  + "closel.gif";
		this.emptyImgLast=this.imagedir + "emptyl.gif";
		
		// ID of selected item
		this.selId=0;
		this.selName="";
	}


	function getGrandParent(item,numLevels){
		var theItem=item;
		for (z=0; z < numLevels; z++) {
			theItem=theCollect[theItem].parent;	
		}
		
		return theItem;
	}
	
	function writeSelected(isSelected){
		writeStr = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR><TD>";

		for (x=1; x < theLevel; x++) {

			gParent=getGrandParent(i,theLevel-x)
			if (theCollect[gParent].lastChild){
				writeStr += "<IMG SRC='"+global.spaceImg+"' WIDTH=16>";
			}
			else{		
				writeStr += "<IMG SRC='"+global.lineImg+"' WIDTH=16>";
			}
		}

		writeStr += "</TD><TD>";

		if (((i+1) < listLength) && (theCollect[i+1].parent==i) && (!theCollect[i+1].deleted) || (!theCollect[i].isCached)) {
			if (theCollect[i].open){
				//	+	picture
				writeStr += "<A HREF='javascript:openNode("+i+")'><IMG SRC='";
				if (!theCollect[i].lastChild){
					writeStr += global.minusImg;	
				}
				else{
					writeStr += global.minusImgLast;	
				}
				writeStr += "' WIDTH=16 HEIGHT=18 Border=0 ALT='close'></A>";	
			}
			else{
				//	-	picture
				writeStr += "<A HREF='javascript:openNode("+i+")'><IMG SRC='";
			
				if (!theCollect[i].lastChild){
				writeStr += global.plusImg;
				}
				else{
					writeStr += global.plusImgLast;
				}
				writeStr += "' WIDTH=16 HEIGHT=18  Border=0 ALT='open'></A>";	
			}
		}
		else{
			writeStr += "<IMG SRC='";
			if (theCollect[i].lastChild){
				writeStr += global.emptyImgLast;	
			}
			else{
				writeStr += global.emptyImg;	
			}
			writeStr += "' WIDTH=16 HEIGHT=18 Border=0>";			
		}

		writeStr += "</TD>";


		if (isSelected){
			writeStr += "<TD vAlign=top><A NAME='here'></A><A HREF='javascript:edit("+i+")'>";
			if (theCollect[i].icon !=""){

				if (theCollect[i].isCached){
					if (theCollect[i].icon.indexOf(".") > 0)
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+"'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";
					else						
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+theCollect[i].state+".gif'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";
				}
				else{
					if (theCollect[i].icon.indexOf(".") > 0)
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+"'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";
					else						
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+theCollect[i].state+".gif'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";					
				}
			}
			writeStr += "</A></TD>";		
			writeStr +=  "<TD BGCOLOR='"+global.selTColor+"'>";
			writeStr += "<FONT FACE="+global.face+" SIZE="+global.fSize+" COLOR='"+global.selFColor+"'>";
			writeStr += "<A HREF='javascript:editItem("+i+")'>";
			writeStr += theCollect[i].title;
			//if (theCollect[i].vtype == "server"){writeStr += " " + global.displaystate[theCollect[i].state];}
			writeStr += "</A></TD>";
			
		}
		else{
			writeStr += "<TD vAlign=top><A HREF='javascript:locate("+i+")'>";
			if (theCollect[i].icon !=""){
				if (theCollect[i].isCached){
					//	node picture
					if (theCollect[i].icon.indexOf(".") > 0)
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+"'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";
					else						
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+theCollect[i].state+".gif'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";					
				}
				else{
					//	node picture
					if (theCollect[i].icon.indexOf(".") > 0)					
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+"'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";
					else
						writeStr += "<IMG BORDER=0 SRC='"+theCollect[i].icon+theCollect[i].state+".gif'><IMG BORDER=0 SRC='"+global.spaceImg+"' HSPACE="+global.hSpace+"></TD>";											
				}
			}
			writeStr += "</A></TD>";
			
			writeStr += "<TD>";
			writeStr += "<FONT FACE="+global.face+" SIZE="+global.fSize+" COLOR='"+global.selFColor+"'>";
			//	title
			writeStr += "<A class=tree HREF='javascript:locate("+i+")' onmouseover=\"this.className='treeSel'\" onmouseout=\"this.className='tree'\" >";
			writeStr += theCollect[i].title;
			writeStr += "</A></TD>";
		}

		writeStr += "</TR></TABLE>";
		var buffStr = unescape(writeStr)
		document.write(buffStr);
	}
	


