var NTrees =[];

  var NAV_FORMAT =
  [
  //0.
  	0,
  //1.
  	0,
  //2.
  	true,
  //3.
  	["", "", "", "", ""],
  //4.
  	[14,11,0],
  //5.
  	true,
  //6.
  	[null, null, null],
  //7.
  	[14,11],
  //8.
  	[0,0,14,28,42,80,96,112,124],
  //9.
  "#F7F7F7",
  //10.
  	"NavNode",
  //11.
  	["navTop", "navFirst", "navSecond", "navThird"],
  //12.
  	true,
  //13.
  	[0,0],
  //14.
  	false,
  //15.
  	[],
  //16.
  	[],
  //17.
  	true,
  //18.
  	true,
  //19.
  	[170,150],
  //20.
  	false,
  //21.
  	true,
  //22.
  	true,
  //23.
  	["#F7F7F7","#F7F7F7"],
  //24.
  	[6,7],
  //25.
  	-1
];


function bw_check()
{
  var is_major = parseInt(navigator.appVersion);
  this.nver = is_major;
  this.ver = navigator.appVersion;
  this.agent = navigator.userAgent;
  this.dom = document.getElementById ? 1 : 0;
  this.opera = window.opera ? 1 : 0;
  this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom && !this.opera) ? 1 : 0;
  this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom && !this.opera) ? 1 : 0;
  this.ie4 = (document.all && !this.dom && !this.opera) ? 1 : 0;
  this.ie = this.ie4 || this.ie5 || this.ie6;
  this.mac = this.agent.indexOf("Mac") > -1;
  this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
  this.ie3 = (this.ver.indexOf("MSIE") && (is_major < 4));
  this.hotjava = (this.agent.toLowerCase().indexOf('hotjava') != -1) ? 1 : 0;
  this.ns4 = (document.layers && !this.dom && !this.hotjava) ? 1 : 0;
  this.bw = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera);
  this.ver3 = (this.hotjava || this.ie3);
  this.opera7 = ((this.agent.toLowerCase().indexOf('opera 7') > -1) || (this.agent.toLowerCase().indexOf('opera/7') > -1));
  this.operaOld = this.opera && !this.opera7;
  return this;
};

function pldImg(arg)
{
  for (var i in arg)
  {
    var im = new Image();
    
    if (arg[i])
    {
      im.src = arg[i]
    }
  }
}

function getObjectHeight(obj)
{
  if (document.layers)
  {
    return obj.clip.height;  
  }
  else 
  {
    if (this.dom && !this.operaOld)
    {
      return obj.firstChild.offsetHeight;
    }
    else
    {
      return obj.offsetHeight;
    }
  }
}

function TreeFmt(fmt, tree)
{
  this.init = function(fmt, tree)
  {
    this.left = fmt[0];
    this.top = fmt[1];
    this.showB = fmt[2];
    this.clB = fmt[3][0];
    this.exB = fmt[3][1];
    this.ndB = fmt[3][2];
    this.iE = fmt[3][3];
    this.sep = fmt[3][4];
    this.Bw = fmt[4][0];
    this.Bh = fmt[4][1];
    this.Ew = fmt[4][2];
    this.showF = fmt[5];
    this.clF = fmt[6][0];
    this.exF = fmt[6][1];
    this.iF = fmt[6][2];
    this.Fw = fmt[7][0];
    this.Fh = fmt[7][1];
    this.ident = fmt[8];
    if (!tree.ver3)
      this.back = new TreeBack(this.left, this.top, fmt[9], 'cls' + tree.name + '_back');

    this.bgCol = fmt[9];
    this.nst = fmt[10];
    this.nstl = fmt[11];
    this.so = fmt[12];
    this.pg = fmt[13][0];
    this.sp = fmt[13][1];
    this.exp = fmt[14];
    this.expimg = fmt[15];
    this.expimgsize = fmt[16];
    this.cook = fmt[17];
    this.rel = fmt[18];
    this.rels = fmt[19];
    this.resizeH = fmt[20];
    this.resizeV = fmt[21];

    this.sel = fmt[22];
    this.selC = fmt[23];
    this.selClass = fmt[23] ? fmt[23][2] : '';
    
    this.seps = fmt[24];
    
    this.tpSpc = fmt[25];
    
    if (this.showB)
      pldImg([this.clB, this.exB, this.ndB, this.iE, this.sep]);
  };

  this.nstyle = function(lvl)
  {
    return und(this.nstl[lvl]) ? this.nst : this.nstl[lvl]
  };

  this.idn = function(lvl)
  {
    return und(this.ident[lvl]) ? this.ident[0] * lvl : this.ident[lvl]
  };

  this.init(fmt, tree);
}

function Tree(name, nodes, format)
{
  this.name = name;
  this.bw = new bw_check();
  this.ver3 = this.bw.ver3;
  this.ns4 = this.bw.ns4;
  this.opera = this.bw.opera;
  this.fmt = new TreeFmt(format, this);
  if (und(NTrees))
    NTrees =[];
  NTrees[this.name] = this;
  this.Nodes =[];
  this.rootNode = new TreeNode(null, "", "", "", null);
  this.rootNode.treeView = this;
  this.selectedNode = null;
  this.maxWidth = 0;
  this.maxHeight = 0;
  this.ondraw = null;
  this.moveTo = function(x, y)
  {
    this.fmt.back.top = y;
    this.fmt.back.left = y;
    this.fmt.back.moveTo(x, y);
    this.fmt.top = y;
    this.fmt.left = x;
    this.draw();
  };

  this.nbn = function(nm)
  {
    for (var i = 0; i < this.Nodes.length; i++)
      if (this.Nodes[i].text == nm)
        return this.Nodes[i];

    return null;
  };

  this.nodeByName = this.nbn;

  this.nodeByID = function(id)
  {
    for (var i = 0; i < this.Nodes.length; i++)
      if (this.Nodes[i].nodeID == id)
        return this.Nodes[i];

    return null;
  };

  this.nodeByURL = function(u)
  {
    for (var i = 0; i < this.Nodes.length; i++)
      if (this.Nodes[i].url == u)
        return this.Nodes[i];

    return null;
  };

  this.addNode = function(node)
  {
    var parentNode = node.parentNode;
    this.Nodes[this.Nodes.length] = node;
    node.index = this.Nodes.length - 1;
    if (parentNode == null)
      this.rootNode.children[this.rootNode.children.length] = node;
    else
      parentNode.children[parentNode.children.length] = node;

    return node;
  };

  this.rebuildTree = function()
  {
    var s = '';
    
    assemlbleChildren(this.rootNode);

    this.rootNode.next = null;

    var nodes = this.Nodes;

	  var lastNode = null;

    for (var i = 0; i < nodes.length; i++)
    {
    	if (nodes[i].level() == 1)
    	{
    		lastNode = nodes[i];
    	}
    }

    for (var i = 0; i < nodes.length; i++)
    {
      nodes[i].initImages();
      if (this.ver3 && nodes[i].hasChildren())
        nodes[i].expanded = true;
        
      var c = nodes[i].init((i==0), (lastNode == nodes[i]));
      
      s += c;
    }
    
    if (this.fmt.rel) 
    {
      var bgc = this.fmt.back.color == "" ? "" : " background-color:" + this.fmt.back.color + ";";
      s = '<div id="cls' + this.name + '_back" style="position:relative;left:0px;' + bgc + 'top:0px;width:' + this.fmt.rels[0] + 'px;height:' + this.fmt.rels[1] + 'px;">' + s + '</div>';
    }
    
    document.write(s);
        
    this.fmt.back.el = document.all ? document.all[this.fmt.back.name] : document.getElementById(this.fmt.back.name);
    
    if ((!this.ver3) && (!this.ns4))
      for (var i = 0; i < this.Nodes.length; i++)
        this.getEl(this.Nodes[i]);
  };

  this.getEl = function(node)
  {
    node.el = document.all ? document.all[node.id() + "d"] : document.getElementById(node.id() + "d");
  };

  this.getImg = function(node)
  {
    if (this.fmt.showB)
      node.nb = node.el.all ? node.el.all[node.id() + "nb"] : document.getElementById(node.id() + "nb");
  };

  this.draw = function()
  {
    if (this.ver3 || this.ns4)
      return;

    if (this.fmt.tpSpc > 0)
    {
      this.currTop = this.fmt.top + this.fmt.tpSpc;
    }
    else
    {
      this.currTop = this.fmt.top;
    }

    this.maxHeight = 0;
    this.maxWidth = 0;
    for (var i = 0; i < this.rootNode.children.length; i++)
      this.rootNode.children[i].draw(true);

    if (this.fmt.rel && (this.fmt.resizeH || this.fmt.resizeV) || !this.fmt.rel)
    {
      if ((this.fmt.resizeH) && (this.fmt.resizeV))
      {
        this.fmt.back.resize(this.maxWidth - this.fmt.left, this.maxHeight - this.fmt.top);
      }
      else if ((!this.fmt.resizeH) && (this.fmt.resizeV))
      {
        this.fmt.back.resize(this.maxWidth, this.maxHeight - this.fmt.top);
      }

    }

    if (this.ondraw != null)
      this.ondraw(this);

    var navTop = document.all ? document.all["navTop"] : document.getElementById("navTop");
  
    if (navTop)
    {
      navTop.style.visibility = "visible";
    }  
      
  };

  this.updateImages = function(node)
  {
    this.getImg(node);
    var srcB = node.expanded ? node.ebtn : node.cbtn;
    //var srcF = node.expanded ? node.eimg : node.cimg;
    if ((node.treeView.fmt.showB || node.treeView.fmt.exp) && node.nb && node.nb.src != srcB)
      node.nb.src = srcB;
  };

  this.openClose = function(index) {
    var node=this.Nodes[index];
    if (!node.expanded) this.expandNode(index,0,1);
  };

  this.expandNode = function(index, nd, sel) {
    if (this.ver3) return;
    var node = this.Nodes[index];
    var pNode = node.parentNode ? node.parentNode : null;
    if (sel == true) this.selectNode(index);
    if (!und(node) && node.hasChildren()) {
      node.expanded=!node.expanded;
      this.updateImages(node);
      if (!node.expanded) {
      	node.hideChildren();
      } else if (this.fmt.so)
        for (var i = 0; i < this.Nodes.length; i++) {
          this.Nodes[i].show(false);
          if (this.Nodes[i] != node && this.Nodes[i].parentNode == pNode) {
            this.Nodes[i].expanded = false;
            this.updateImages(this.Nodes[i]);
          }
        }
      if (!nd) this.draw();
      if (!nd && this.fmt.cook) this.saveState();
    }
  };

  this.selectNode = function(index, force)
  {
    var node = this.Nodes[index];
    if (force || this.selectedNode != node)
      if (!und(node))
      {
        var os = this.selectedNode;
        this.selectedNode = node;
        if (this.fmt.sel && os != null)
          os.setBGColor(this.fmt.selC[0]);

        if (this.fmt.sel)
          node.setBGColor(this.fmt.selC[1]);

        this.swapClass(os, node);
        if (this.onSelectNode != null)
          this.onSelectNode(os, node);

        this.saveState();
      }
  };

  this.swapClass = function(os, node)
  {
    if (this.ns4 || und(this.fmt.selClass) || this.fmt.selClass == '')
      return;

    if (os)
      os.chClass(os.oldClass);

    if (node)
    {
      node.chClass(this.fmt.selClass);
    }
  };

  this.readOne = function(par, arr, tree)
  {
    if (und(arr))
      return;

    var i = 0;
    var nid = 0;
    if (arr[i].id)
    {
      nid = arr[i].id;
      i++
    };
  
    var node = this.addNode(new TreeNode(this, par, arr[i], arr[i + 1] == null ? "" : arr[i + 1], arr[i + 2] == null ? "" : arr[i + 2]));
    
    node.nodeID = nid;
    
    if (!und(arr[i + 3]) && !und(arr[i + 3]["format"]))
    {
      node.f = arr[i + 3]["format"];

      node.expanded = und(node.f.expanded) ? false : node.f.expanded;
      
      i++;
    }
  
  
    while (!und(arr[i + 3]))
    {
      par = node;
      this.readOne(par, arr[i + 3]);
      i++;
    }
  };

  this.readNodes = function(nodes)
  {
    var ind = 0;
    var par = null;
    if (und(nodes) || und(nodes[0]) || und(nodes[0][0]))
      return;

    for (var i = 0; i < nodes.length; i++)
    {
      par = null;
      this.readOne(par, nodes[i], this);
    }
  };

  this.collapseAll = function(rd)
  {
    if (this.ver3)
      return;

    for (var i = 0; i < this.Nodes.length; i++)
    {
      if (this.Nodes[i].parentNode != this.rootNode)
        this.Nodes[i].show(false);

      this.Nodes[i].expanded = false;
      this.updateImages(this.Nodes[i]);
    }
    if (this.fmt.cook)
      this.saveState();

    if (rd)
      this.draw();
  };

  this.expandAll = function(rd)
  {
    if (this.ver3)
      return;

    for (var i = 0; i < this.Nodes.length; i++)
    {
      if (this.Nodes[i].hasChildren())
      {
        this.Nodes[i].expanded = true;
        this.updateImages(this.Nodes[i]);
      }
    }
    if (this.fmt.cook)
      this.saveState();

    if (rd)
      this.draw();
  };

  this.expandTopNodes = function(rd)
  {
    if (this.ver3)
      return;

    for (var i = 0; i < this.Nodes.length; i++)
    {
      if (this.Nodes[i].level() == 0)
      {
        this.Nodes[i].expanded = true;
        this.updateImages(this.Nodes[i]);
      }
    }
    if (this.fmt.cook)
      this.saveState();

    if (rd)
      this.draw();
  };


  this.init = function()
  {
    this.readNodes(nodes);
    
    //if (!this.ver3 && !this.fmt.rel)
    //  this.fmt.back.init();

    this.rebuildTree();
    
    if (this.fmt.cook)
      this.restoreState();

    //if (!this.fmt.rel)
    //  this.draw();
  };

  this.getCookie = function(sName)
  {
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++)
    {
      var aCrumb = aCookie[i].split("=");
      if (sName == aCrumb[0])
        return unescape(aCrumb[1]);
    }
    return null;
  };

  this.saveState = function()
  {
    var state = "";
    for (var i = 0; i < this.Nodes.length; i++)
      state += this.Nodes[i].expanded ? '1' : '0';
    /* Uncomment this to keep cookies during month var d = new Date(); d.setMonth(d.getMonth()+15); document.cookie=this.name+'State='+state+'; path=/'+'; expires='+d.toGMTString(); */

    if (this.selectedNode != null)
      document.cookie = this.name + 'Selected=' + this.selectedNode.index;

    document.cookie = this.name + 'State=' + state + '; path=/';
  };

  this.restoreState = function()
  {
    var state = this.getCookie(this.name + 'State');
    if (state == null)
      return;
    for (var i = 0; i < this.Nodes.length; i++)
      if (state.charAt(i) == '1' && this.Nodes[i].hasChildren())
        this.expandNode(i, true);

    var sel = this.getCookie(this.name + 'Selected');
    if (sel)
      this.selectNode(sel, 1);
  };

}

function TreeNode(treeView, parentNode, text, url, target)
{
  this.index = -1;
  this.treeView = treeView;
  this.parentNode = parentNode;
  this.text = text;
  this.url = url;
  this.target = target;
  this.f =[];
  this.expanded = false;
  this.children =[];
  this.hasChildren = function()
  {
    return this.children.length > 0 || (this.f.hasChildren)
  };

  this.level = function()
  {
    var node = this;
    var i = 0;
    while (node.parentNode != null)
    {
      i++;
      node = node.parentNode;
    }
    return i
  };

  this.initImages = function()
  {
    if (!this.treeView)
      return;

    if (this.treeView.fmt.exp)
    {
    }
    else
    {
      //this.cimg  = this.hasChildren() ? (!und(this.f.folders)) ? this.f.folders[0] : this.treeView.fmt.clF : (!und(this.f.folders)) ? this.f.folders[2] : this.treeView.fmt.iF;
      //this.eimg  = this.hasChildren() ? (!und(this.f.folders)) ? this.f.folders[1] : this.treeView.fmt.exF : (!und(this.f.folders)) ? this.f.folders[2] : this.treeView.fmt.iF;
      this.cbtn  = this.hasChildren() ? (!und(this.f.buttons)) ? this.f.buttons[0] : this.treeView.fmt.clB : (!und(this.f.buttons)) ? this.f.buttons[2] : this.treeView.fmt.iE;
      this.ebtn  = this.hasChildren() ? (!und(this.f.buttons)) ? this.f.buttons[1] : this.treeView.fmt.exB : (!und(this.f.buttons)) ? this.f.buttons[2] : this.treeView.fmt.iE;
      
      
      this.ndbtn = this.hasChildren() ?              (!und(this.f.buttons)) ? this.f.buttons[2] : this.treeView.fmt.ndB                 :               (!und(this.f.buttons)) ? this.f.buttons[3] : this.treeView.fmt.iE;
      
      if (this.hasChildren())
      {
        if ((!und(this.f.buttons)))
        {
          this.ndbtn = this.f.buttons[2] 
        }
        else
        {
          this.ndbtn = this.treeView.fmt.ndB  
        }  
      }
      else
      {
        if (!und(this.f.buttons))
        {
          this.ndbtn = this.f.buttons[2]
        }
        else
        {
          this.ndbtn = this.treeView.fmt.ndB;
        }
      
      }
      
      this.wbtn = this.treeView.fmt.Bw;
      this.hbtn = this.treeView.fmt.Bh;
    }
  };

  this.init = function(isFirst, isLast)
  {
    if ((!this.treeView.ver3) && (!this.treeView.ns4))
    {
      return '<div id="' + this.id() + 'd" style="position:absolute;visibility:hidden;z-index:' + this.index + 10 + ';">' + this.getContent(isFirst, isLast) + '</div>'; 
    }
    else
    {
    	
      return getContent(isFirst, isLast);
    }
  };

  this.getH = function()
  {
    if (!this.h)
      this.h = this.treeView.bw.dom && !this.treeView.bw.operaOld ? this.el.firstChild.offsetHeight : this.el.offsetHeight;

    return this.h
  };

  this.getW = function()
  {
    if (!this.w)
      this.w = this.treeView.bw.dom && !this.treeView.bw.operaOld ? this.el.firstChild.offsetWidth : this.el.offsetWidth;

    return this.w
  };

  this.id = function()
  {
    return 'nt' + this.treeView.name + this.index;
  };

  this.getContent = function(isFirst, isLast)
  {
    function buttonSquare(node, isFirst)
    {
      // If root node then do not display a button square - MARCUS
      if (node.f.isHeading)
        return "";
      
      var img = node.expanded ? node.ebtn : node.cbtn;  

      var valign = "top";
      
      if (node.hasChildren())
      {
        var s = '<td valign="' + valign + '">';  
        var i = '<img name=\'' + node.id() + 'nb\' id=\'' + node.id() + 'nb\' src="' + img + '" width="' + node.wbtn + '" height="' + node.hbtn + '" border=0>';  
        var onm = node.treeView.fmt.nnOnMOver ? ' onmouseout="window.status=\'\';return true" onmouseover="window.status=\'' + node.text + '\';return true"' : '';  
        
        return s + '<a onclick="this.blur()"' + onm + ' href="javascript:NTrees[\'' + node.treeView.name + '\'].expandNode(' + node.index + ')">' + i + '</a>&nbsp;</td>\n';
      }
      else
      {
        var s = '<td valign="' + valign + '">';  
        var i = '<img src="' + node.ndbtn + '" width="' + (node.wbtn) + '" height="' + node.hbtn + '" border=0>';  

        return s + i + '&nbsp;</td>\n';
      }
    }
    

    function blankSquares(node, ww, ll)
    {
      var i;
      var ii;
      var res = "";
      var pnode = node;
      for (i = ll; i > 1; i--)
      {
        if (pnode.parentNode != null) pnode = pnode.parentNode;
        	res = "<td width=\"" + node.treeView.fmt.Bw + "\"><img src=\"" + node.treeView.fmt.iE + "\" width=" + node.treeView.fmt.Bw + " height=" + node.treeView.fmt.Bh + " border=0></td>" + res;
      }

      return res;
    }

    if ((this.f.isHeading) && (this.text=="Login Options")) {
      return "<table cellspacing=0 cellpadding=0><tr><td></td></tr></table>";
    }
    
    var s = '';
    var ll = this.level();
    s += '<table cellpadding=' + this.treeView.fmt.pg + ' cellspacing=' + this.treeView.fmt.sp + ' border="0" class="cls' + this.treeView.name + '_back' + ll + '"><tr>';
    // Indent all the items by 10 pixels from the left browser border
    s += '<td><img src="' + this.treeView.fmt.iE + '" height="1" width="10"></td>';
    var idn = this.treeView.fmt.idn(ll);
    s+= blankSquares(this, idn, ll);
    if (this.treeView.fmt.showB) {
      s += buttonSquare(this, isFirst);
    }
    
    var exp = 'NTrees[\'' + this.treeView.name + '\'].expandNode(' + this.index + ', 0, 1)';
    var u = !this.url ? "javascript:" + exp : this.url;
//    var onc = this.url ? 'onclick="' + exp + ';this.blur()"' : 'onclick="this.blur()"';
		var onc='onclick="this.blur()"';
		if (this.url) {
			onc='onclick="NTrees[\''+this.treeView.name+'\'].openClose('+this.index+');this.blur()"';
		}
    var targ = this.target ? ' target="' + this.target + '"' : '';
    var onm = this.treeView.fmt.nnOnMOver && this.hasChildren() ? ' onmouseout="window.status=\'\';return true" onmouseover="window.status=\'' + this.text + '\';return true"' : '';
    
    var t = null;
    
    // [STYLECLASS][1] - Allow the style class specified by the format option to override the default style class for the level of the node. See below as well - MARCUS
    var styleClass = null;
    
    if (this.f.styleClass) {
      styleClass = this.f.styleClass;
    } else {
      styleClass = this.treeView.fmt.nstyle(ll);
    }
    
    if (this.f.isHeading) {
      t='<b class="'+styleClass+'">'+this.text+'</b>&nbsp;&nbsp;';
  	} else {
      t='<a'+onm+' id="'+this.id()+'an" class="'+styleClass+'" href="'+u+'" '+onc+targ+'>'+this.text+'</a>';
    }
    
    /*
    // FIX FOR IE TD BACKGROUND BUG - MARCUS
    var sep = ""
    
    if ((ll == 0) && (!this.f.isHeading))
      sep = '<tr><td colspan="' + (ll+3) + '" align="center" nowrap>';
    else
      sep = '<tr><td colspan="' + (ll+2) + '" align="center" nowrap>';

   	for (i = 0; i < ((treeView.fmt.rels[0]/this.treeView.fmt.seps[0])-3); i++)
   	{
   		sep += '<img border="0" width="' + this.treeView.fmt.seps[0] + '" height="' + this.treeView.fmt.seps[1] + '" src="' + this.treeView.fmt.sep + '">';
   	}
	   	
    sep += '</td></tr>';
    
    if (isLast)
    {
      sep += '<tr><td colspan="' + (ll+2) + '" align="center" nowrap>';
      sep += '<img border="0" width="1" height="5" src="' + this.treeView.fmt.iE + '">';
      sep += '</td></tr>';
    }
    */
    
    // THIS IS A BETTER WAY OF DOING IT - MARCUS
    if ((ll == 0) && (!this.f.isHeading))
    {
      sep = '<tr><td></td><td colspan="' + (ll+2) + '" align="center" class="navSeperator" nowrap><img border="0" width="1" height="5" src="' + this.treeView.fmt.iE + '"></td><td></td></tr>';
    }
    else
      sep = '<tr><td></td><td colspan="' + (ll+1) + '" align="center" class="navSeperator" nowrap><img border="0" width="1" height="5" src="' + this.treeView.fmt.iE + '"></td><td></td></tr>';
      
    if (isLast)
    {
      sep += '<tr><td></td><td colspan="' + (ll+1) + '" align="center" nowrap>';
      sep += '<img border="0" width="1" height="5" src="' + this.treeView.fmt.iE + '">';
      sep += '</td><td></td></tr>';
    }

    // FIX FOR IE TD BACKGROUND BUG - MARCUS
    // s +=  '<td width="' + (treeView.fmt.rels[0] - ((ll)*10)) + '"><div id="' + this.id() + 'a">' + t + '</div></td><td><img src="' + this.treeView.fmt.iE + '" height="1" width="10"></td></tr>' + sep + '</table>';    

    // THIS IS A BETTER WAY OF DOING IT - MARCUS  
    s +=  '<td width="100%"><div id="' + this.id() + 'a">' + t + '</div></td><td><img src="' + this.treeView.fmt.iE + '" height="1" width="10"></td></tr>' + sep + '</table>';    
    return s;
  };

  this.moveTo = function(x, y)
  {
    if (this.treeView.opera)
    {
      this.el.style.left = x;
      this.el.style.top = y;
    }
    else
    {
      this.el.style.left = x + 'px';
      this.el.style.top = y + 'px';
    }
  };

  this.show = function(sh)
  {
    if (this.visible == sh)
      return;

    this.visible = sh;
    var vis = (sh ? 'visible' : 'hidden');

    this.el.style.visibility = vis;
  };

  this.hideChildren = function()
  {
    this.show(false);
    for (var i = 0; i < this.children.length; i++)
      this.children[i].hideChildren();
  };

  this.draw = function()
  {
    var ll = this.treeView.fmt.left;
    var left = this.treeView.fmt.rel && this.treeView.bw.operaOld ? this.treeView.fmt.left + this.treeView.operaLeft : this.treeView.fmt.left;
    var top = this.treeView.fmt.rel && this.treeView.bw.operaOld ? this.treeView.currTop + this.treeView.operaTop : this.treeView.currTop;
    this.moveTo(left, top);
    var w = this.getW();
    this.show(true);
    if (ll + w > this.treeView.maxWidth)
      this.treeView.maxWidth = ll + w;

    this.treeView.currTop += this.getH();
    if (this.treeView.currTop > this.treeView.maxHeight)
      this.treeView.maxHeight = this.treeView.currTop;
      

    if (this.expanded && this.hasChildren())
      for (var i = 0; i < this.children.length; i++)
        this.children[i].draw();
  };

  this.setBGColor = function(color)
  {
    var el = this.treeView.bw.ns4 ? this.el.layers[this.id() + 'a'] : document.all ? document.all[this.id() + 'a'] : document.getElementById(this.id() + 'a');
    if (el.style)
      el.style.backgroundColor = color;
  };

  this.chClass = function(cls)
  {
    var el = document.all ? document.all[this.id() + "an"] : document.getElementById(this.id() + "an");
    this.oldClass = el.className;
    this.show(0);
    el.className = cls;
    this.show(1);
  };

  return this;
}

function assemlbleChildren(node)
{
  if (node.children.length > 0)
    node.children[node.children.length - 1].next = null;

  for (var i = 0; i < node.children.length; i++)
  {
    if (i + 1 < node.children.length)
      node.children[i].next = node.children[i + 1];
    if (node.children[i].children.length > 0)
      assemlbleChildren(node.children[i]);
  }
  return;
}

function TreeBack(aleft, atop, color, name)
{
  this.pa =[];
  this.bw = new bw_check();
  this.ver3 = this.bw.ver3;
  this.ns4 = this.bw.ns4;
  this.left = aleft;
  this.top = atop;
  this.name = name;
  this.color = color;
  this.tt = false;
  this.resize = function(w, h)
  {
   this.el.style.width = w;
   this.el.style.height = h;
  };

  this.init = function()
  {
      var bgc = this.color == "" ? "" : " background-color:" + this.color + ";";
      document.write('<div id="' + this.name + '" style="' + bgc + 'position:absolute;z-index:0;top:' + this.top + 'px;left:' + this.left + 'px"></div>');
      this.el = document.all ? document.all[this.name] : document.getElementById(this.name);
  };
}

function und(val)
{
  return typeof(val) == 'undefined'
}

function RedrawAllTrees()
{
  for (var tree in NTrees)
    NTrees[tree].draw()
}

window.oldCTOnLoad=window.onload;function CTOnLoad()
{
  var bw = new bw_check();
  if (bw.ns4 || bw.operaOld)
  {
    window.origWidth = window.innerWidth;
    window.origHeight = window.innerHeight;
  }
  if (bw.operaOld)
  {
    if (!window.operaResizeTimer)
      resizeHandler();

    for (var tree in NTrees)
    {
      for (var j = 0; j < NTrees[tree].Nodes.length; j++)
      {
        if (NTrees[tree].fmt.rel)
        {
          var l = NTrees[tree].fmt.back.el.offsetParent.offsetLeft;
          var t = NTrees[tree].fmt.back.el.offsetParent.offsetTop;
          var par = NTrees[tree].fmt.back.el.offsetParent;
          while (par != document.body)
          {
            l += par.offsetLeft;
            t += par.offsetTop;
            par = par.offsetParent;
          }
          NTrees[tree].operaTop = t;
          NTrees[tree].operaLeft = l;
        }
        if (NTrees[tree].Nodes[j].visible)
          NTrees[tree].Nodes[j].el.style.visibility = 'visible';
      }
      NTrees[tree].draw();
    }
  }
  if (typeof(window.oldCTPOnLoad) == 'function')
    window.oldCTPOnLoad();
  if (bw.ns4)
    window.onresize = resizeHandler;
}

window.onload=CTOnLoad;function resizeHandler()
{
  if (window.reloading)
    return;

  var reload = window.innerWidth != window.origWidth || window.innerHeight != window.origHeight;
  window.origWidth = window.innerWidth;
  window.origHeight = window.innerHeight;
  if (window.operaResizeTimer)
    clearTimeout(window.operaResizeTimer);

  if (reload)
  {
    window.reloading = 1;
    document.location.reload();
    return
  };

  if (new bw_check().operaOld)
    window.operaResizeTimer = setTimeout('resizeHandler()', 500);
}

