function jsTree() {
    //Public Properties (NCZ, 1/27/02)
    this.objNode0 = null;           //the root node of the tree
 
     //Public Collections (NCZ, 1/27/02)
    this.nodes = new Array;     //array for all nodes in the tree
   
    //Constructor
    //assign to local copy of the tree (NCZ, 1/27/02)
    objLocalTree = this;
}

jsTree.prototype.createRoot = function(strIcon, strText, strURL, strTarget) {

    //create a new node (NCZ, 1/27/02)
    this.objNode0 = new jsTreeNode(strIcon, strText, strURL, strTarget);

    //assign an ID for internal tracking (NCZ, 1/27/02)
    this.objNode0.id = "root";
    
    //add it into the array of all nodes (NCZ, 1/27/02)
    this.nodes["root"] = this.objNode0;
    
    //make sure that the root is expanded (NCZ, 1/27/02)
    this.objNode0.expanded = true;
    
    //return the created node (NCZ, 1/27/02)
    return this.objNode0;
}

jsTree.prototype.buildDOM = function() {

    //call method to add root to document, which will recursively
    //add all other nodes (NCZ, 1/27/02)
    this.objNode0.addToDOM(document.getElementById('navitd'));
    
    var parentnode = GetCookie('ParentNode');

    if (parentnode){
    	if (objTree.nodes){
    		if (objTree.nodes[parentnode]){
    			objTree.nodes[parentnode].expand();
    		}
    	}
    }
}

jsTree.prototype.toggleExpand = function(strNodeID) {

    //get the node (NCZ, 1/27/02)
    var objNode = this.nodes[strNodeID];

    if (objNode.childNodes.length > 0){
    	for (nodeid in jsTree.nodes){
			//throw objTree.nodes[nodeid].childNodes.length;
		    if (jsTree.nodes[nodeid].childNodes.length > 0){
		    	if (objTree.nodes[nodeid].expanded){
	    			objTree.nodes[nodeid].collapse();
		    	}
	    	}
    	}
    	document.cookie = 'ParentNode='+strNodeID;
    }
    
    //determine whether to expand or collapse
    if (!objNode.expanded){
        objNode.expand();
    }
}

function jsTreeNode(strIcon, strText, strURL, strTarget) {

    //Public Properties (NCZ, 1/27/02)
    this.icon = strIcon;            //the icon to display
    this.text = strText;            //the text to display
    this.url = strURL;              //the URL to link to
    this.target = strTarget;        //the target for the URL
    
    //Private Properties (NCZ, 1/27/02)
    this.indent = 0;                //the indent for the node
    
    //Public States (NCZ, 1/27/02)
    this.expanded = false;          //is this node expanded?
 
    //Public Collections (NCZ, 1/27/02)   
    this.childNodes = new Array;    //the collection of child nodes
}

jsTreeNode.prototype.addChild = function (strIcon, strText, strURL, strTarget) {

    //create a new node (NCZ, 1/27/02)
    var objNode = new jsTreeNode(strIcon, strText, strURL, strTarget);
    
    //assign an ID for internal tracking (NCZ, 1/27/02)
    objNode.id = this.id + "_" + this.childNodes.length;

    //assign the indent for this node
    objNode.indent = this.indent + 1;
    
    //add into the array of child nodes (NCZ, 1/27/02)
    this.childNodes[this.childNodes.length] = objNode;
    
    //add it into the array of all nodes (NCZ, 1/27/02)
    objLocalTree.nodes[objNode.id] = objNode;
    
    //return the created node (NCZ, 1/27/02)
    return objNode;
}

jsTreeNode.prototype.addToDOM = function (objDOMParent) {
	
    //create the URL (NCZ, 1/27/02)
    if (this.url != ""){
    	var strHTMLLink = "<a class=\"navi\" href=\"" + this.url + "\">";
    } else {
    	var strHTMLLink = ""; 	
    }

    //if (this.target)strHTMLLink += " target=\"" + this.target + "\">";

    //create the layer for the node (NCZ, 1/27/02)
    var objNodeDiv = document.createElement("div");
    
    //add it to the DOM parent element (NCZ, 1/27/02)
    objDOMParent.appendChild(objNodeDiv);
    
    //create string buffer (NCZ, 1/27/02)
    var d = new jsDocument;
    
    
    //begin the table (NCZ, 1/27/02)
    d.writeln("<table style=\"width:100%;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
    
    d.write("<td><table style=\"width:99%;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
    if (drawborder == 1){
    	d.write("<td></td>");
    } else {
    	d.write("<td style=\"width:1px;\"></td>");
    }
    
    if ((this.url == activenode) && (this.url != "")){
		//border for active entry
    	d.write("<td style=\"background-color:#FFCC00;border:1px solid #000000;\"><table style=\"width:100%;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
    } else {
		d.write("<td style=\"padding:1px;\"><table style=\"width:100%;\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
	}
    
    //no indent needed for root or level under root (NCZ, 1/27/02)
    if (this.indent > 1) {
        d.write("<td style=\"width:");
        d.write((this.indent * 8) + ((this.indent-2) * 10));
        d.write("px;");
        d.write("\"></td>");
    }
    
    d.write("<td style=\"width:2px;\" align=\"center\">");
	d.write("</td>");
	
    if (this.indent > 1) {
	    //finish by drawing the icon and text (NCZ, 1/27/02)d.write("<img hspace=\"1\" src=\"" + this.icon + "\" border=\"0\" align=\"absmiddle\" />");
	    if (strHTMLLink != ""){
	    	//throw "link" + this.text;
	    	if ((this.childNodes.length > 0)) {
	    		d.write("<td style=\"font-size:13px;\"><a class=\"navi\" href=\"javascript:objLocalTree.toggleExpand('"+this.id+"');self.location.href='" + this.url + "';\">" + this.text + "</a></td>");
	    	} else {
	    		d.write("<td style=\"font-size:13px;\">" + strHTMLLink + this.text + "</a></td>");
	    	}
	    } else {
	    	d.write("<td style=\"font-size:13px;\">");
	    	//throw "nolink" + this.text;
	    	if ((this.childNodes.length > 0) && (this.text != activenode)) {
	            d.write("<a class=\"navi\" href=\"javascript:objLocalTree.toggleExpand('"+this.id+"')\">");
	        }
	    	d.write(this.text);
	    	if ((this.childNodes.length > 0) && (this.text != activenode)) {
	    		d.write("</a>");
	    	}
	    	d.write("</td>");
	    }
    } else {
      	//finish by drawing the icon and text (NCZ, 1/27/02)
      	if (strHTMLLink != ""){
      		//throw "link" + this.text;
	    	if ((this.childNodes.length > 0)) {
	    		d.write("<td style=\"font-size:13px;\"><a class=\"navi\" href=\"javascript:objLocalTree.toggleExpand('"+this.id+"');self.location.href='" + this.url + "';\">" + this.text + "</a></td>");
	    	} else {
	    		d.write("<td style=\"font-size:13px;\">" + strHTMLLink + this.text + "</a></td>");
	    	}
	    } else {
	    	d.write("<td style=\"font-size:13px;\">");
	    	//throw "nolink" + this.text;
	    	if ((this.childNodes.length > 0) && (this.text != activenode)) {
	            d.write("<a class=\"navi\" href=\"javascript:objLocalTree.toggleExpand('"+this.id+"')\">");
	        }
	    	d.write(this.text);
	    	if ((this.childNodes.length > 0) && (this.text != activenode)) {
	    		d.write("</a>");
	    	}
	    }
	    
    }
    
    if (this.text == activenode){
    	d.write("<td style=\"width:2px;\"></td></tr></table></td><td style=\"width:1px;");
    	d.write("\"></td></tr></table></td></tr>");
    }
    d.writeln("</tr></table>");
    
    //assign the HTML to the layer (NCZ, 1/27/02)
    objNodeDiv.innerHTML = d;
    
    //create the layer for the children (NCZ, 1/27/02)
    var objChildNodesLayer = document.createElement("div");
    objChildNodesLayer.setAttribute("id", "divChildren_" + this.id);
    objChildNodesLayer.style.position = "relative";
    objChildNodesLayer.style.display = (this.expanded ? "block" : "none");
    objNodeDiv.appendChild(objChildNodesLayer);
    
    //call for all children (NCZ, 1/27/02)
    for (var i=0; i < this.childNodes.length; i++)
        this.childNodes[i].addToDOM(objChildNodesLayer);

}

jsTreeNode.prototype.collapse = function () {

    //check to see if the node is already collapsed (NCZ, 1/27/02)
    if (!this.expanded) {
    
        //throw an error (NCZ, 1/27/02)
        throw "Node is already collapsed"

    } else {
    
        //change the state of the node (NCZ, 1/27/02)
        this.expanded = false;

        //hide the child nodes (NCZ, 1/27/02)
        document.getElementById("divChildren_" + this.id).style.display = "none";

        //document.cookie = 'ExpandedNode_' + this.id + '=0';
    }
}


jsTreeNode.prototype.expand = function () {	
    //check to see if the node is already expanded (NCZ, 1/27/02)
    if (this.expanded) {
        //throw an error (NCZ, 1/27/02)
        throw "Node is already expanded"
    
    } else {
        //change the state of the node (NCZ, 1/27/02)
        this.expanded = true;
 
        if (document.getElementById("divChildren_" + this.id)){
	    	//show the child nodes (NCZ, 1/27/02)
	    	document.getElementById("divChildren_" + this.id).style.display = "block";
	    	
	    	//document.cookie = 'ExpandedNode_' + this.id + '=1';
        }
    }
}

function GetCookie(CookieName) {
	var cname = CookieName + "=";
	var i = 0;
	while (i < document.cookie.length) {
	var j = i + cname.length;
	if (document.cookie.substring(i, j) == cname){
	    var leng = document.cookie.indexOf (";", j);
	    if (leng == -1) leng = document.cookie.length;
	    return unescape(document.cookie.substring(j, leng));
	}
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break; 
	}
	return "*";
}
