var mainCatId = null, subCatId = null;
function xbDetectBrowser()
{
  var oldOnError = window.onerror;
  var element = null;

  window.onerror = null;
  
  // work around bug in xpcdom Mozilla 0.9.1
  window.saveNavigator = window.navigator;

  navigator.OS    = '';
  navigator.version  = parseFloat(navigator.appVersion);
  navigator.org    = '';
  navigator.family  = '';

  var platform;
  if (typeof(window.navigator.platform) != 'undefined')
  {
    platform = window.navigator.platform.toLowerCase();
    if (platform.indexOf('win') != -1)
      navigator.OS = 'win';
    else if (platform.indexOf('mac') != -1)
      navigator.OS = 'mac';
    else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
      navigator.OS = 'nix';
  }

  var i = 0;
  var ua = window.navigator.userAgent.toLowerCase();
  
  if (ua.indexOf('opera') != -1)
  {
    i = ua.indexOf('opera');
    navigator.family  = 'opera';
    navigator.org    = 'opera';
    navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
  }
  else if ((i = ua.indexOf('msie')) != -1)
  {
    navigator.org    = 'microsoft';
    navigator.version  = parseFloat('0' + ua.substr(i+5), 10);
    
    if (navigator.version < 4)
      navigator.family = 'ie3';
    else
      navigator.family = 'ie4'
  }
  else if (ua.indexOf('gecko') != -1)
  {
    navigator.family = 'gecko';
    var rvStart = ua.indexOf('rv:');
    var rvEnd   = ua.indexOf(')', rvStart);
    var rv      = ua.substring(rvStart+3, rvEnd);
    var rvParts = rv.split('.');
    var rvValue = 0;
    var exp     = 1;

    for (var i = 0; i < rvParts.length; i++)
    {
      var val = parseInt(rvParts[i]);
      rvValue += val / exp;
      exp *= 100;
    }
    navigator.version = rvValue;

    if (ua.indexOf('netscape') != -1)
      navigator.org = 'netscape';
    else if (ua.indexOf('compuserve') != -1)
      navigator.org = 'compuserve';
    else
      navigator.org = 'mozilla';
  }
  else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  {
    var is_major = parseFloat(navigator.appVersion);
    
    if (is_major < 4)
      navigator.version = is_major;
    else
    {
      i = ua.lastIndexOf('/')
      navigator.version = parseFloat('0' + ua.substr(i+1), 10);
    }
    navigator.org = 'netscape';
    navigator.family = 'nn' + parseInt(navigator.appVersion);
  }
  else if ((i = ua.indexOf('aol')) != -1 )
  {
    // aol
    navigator.family  = 'aol';
    navigator.org    = 'aol';
    navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
  }
  else if ((i = ua.indexOf('hotjava')) != -1 )
  {
    // hotjava
    navigator.family  = 'hotjava';
    navigator.org    = 'sun';
    navigator.version  = parseFloat(navigator.appVersion);
  }

  window.onerror = oldOnError;
}

xbDetectBrowser();

function Folder(folderDescription, href, catId) {
	// constructor
	// constant data
	this.desc = folderDescription;
	this.href = href;
	this.id = -1;
	this.navObj = 0;
	this.iconImg = 0;
	this.nodeImg = 0;
	this.isLastNode = 0;
	this.iconSrc = Param_iconImagePath + "ftv2folderopen.gif";
	this.iconSrcClosed = Param_iconImagePath + "ftv2folderclosed.gif";
	this.children = new Array;
	this.nChildren = 0;
	this.level = 0;
	this.leftSideCoded = "";
	this.isLastNode = false;

	// NEW 20020904
	this.catId = catId;
	// END NEW 20020904

	// dynamic data
	this.isOpen = false;
	this.isLastOpenedFolder = false;
	this.isRendered = 0;

	// methods
	this.initialize = initializeFolder;
	this.setState = setStateFolder;
	this.addChild = addChild;
	this.createIndex = createEntryIndex;
	this.escondeBlock = escondeBlock;
	this.esconde = escondeFolder;
	this.mostra = mostra;
	this.renderOb = drawFolder;
	this.totalHeight = totalHeight;
	this.subEntries = folderSubEntries;
	this.linkHTML = linkFolderHTML;
	this.blockStartHTML = blockStartHTML;
	this.blockEndHTML = blockEndHTML;
	this.nodeImageSrc = nodeImageSrc;
	this.iconImageSrc = iconImageSrc;
}

function initializeFolder(level, lastNode, leftSide) {
	var j = 0;
	var i = 0;
	nc = this.nChildren;

	this.createIndex();
	this.level = level;
	this.leftSideCoded = leftSide;

	if (browserVersion == 0 || Param_openAll == 1) {
		this.isOpen = true;
	}

	// MOD 20020904
	// indentation start from level 2 instead of level 1
	/* if (level>0) */
	if (level > 1) {
		if (lastNode) { // the last child in the children array
			leftSide = leftSide + "0"
		}
		else {
			leftSide = leftSide + "1"
		}
	}

	this.isLastNode = lastNode;

	if (nc > 0) {
		level = level + 1;

		for (i = 0; i < this.nChildren; i++) {
			if (i == this.nChildren - 1) {
				this.children[i].initialize(level, 1, leftSide);
			}
			else {
				this.children[i].initialize(level, 0, leftSide);
			}
		}
	}
}

function drawFolder(insertAtObj) {
	var nodeName = "";
	var auxEv = "";
	var docW = "";

	var leftSide = leftSideHTML(this.leftSideCoded);

	if (browserVersion > 0) {
		auxEv = "<a style='cursor: pointer; cursor: hand' onmouseover='clickOnNode("+this.id+")'>";
	}
	else {
		auxEv = "<a>";
	}

	nodeName = this.nodeImageSrc();

	if (this.level > 0) {
/*		if (this.isLastNode) { // the last child in the children array */
			leftSide = leftSide + "<td valign=top id='nodeBg" + this.id+ "'>" + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + nodeName + "' width=20 height=18 border=0></a></td>"; // MOD 20020904 new tree icons; /* leftSide = leftSide + "<td valign=top>" + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + nodeName + "' width=16 height=22 border=0></a></td>" */
/*		}
		else {
			 leftSide = leftSide + "<td valign=top background=" + Param_iconImagePath + "ftv2vertline.gif>" + auxEv + "<img name='nodeIcon" + this.id + "' id='nodeIcon" + this.id + "' src='" + nodeName + "' width=20 height=18 border=0></a></td>";
		}
*/
	}
	var idParam = "id=\'folder" + this.id + "\'";

	this.isRendered = 1;

	if (browserVersion == 2) {
		if (!doc.yPos) {
			doc.yPos = 20;
		}
	}

	docW = this.blockStartHTML("folder");

	docW = docW + "<tr>" + leftSide + "<td valign=top>";

	if (Param_useIcons) {
		docW = docW + this.linkHTML();
		docW = docW + "<img id='folderIcon" + this.id + "' name='folderIcon" + this.id + "' src='" + this.iconImageSrc() + "' border=0></a>";
	}
	else {
		docW = docW + "<img src=" + Param_iconImagePath + "ftv2blank.gif height=2 width=2>";
	}

	if (Param_wrapItemText) {
		docW = docW + "</td><td valign=middle width=100%>";
	}
	else {
		docW = docW + "</td><td valign=middle nowrap width=100%>";
	}

	if (Param_useLinks) {
		docW = docW + this.linkHTML();
		docW = docW + this.desc + "</a>";
	}
	else {
		docW = docW + this.desc;
	}

	docW = docW + "</td>";

	docW = docW + this.blockEndHTML();

	if (insertAtObj == null) {
		if (supportsDeferral) {
			doc.write("<div id=domRoot></div>"); // transition between regular flow HTML, and node-insert DOM DHTML
			insertAtObj = getElById("domRoot");
			insertAtObj.insertAdjacentHTML("beforeEnd", docW);
		}
		else {
			doc.write(docW);
		}
	}
	else {
		insertAtObj.insertAdjacentHTML("afterEnd", docW);
	}

	if (browserVersion == 2) {
		this.navObj = doc.layers["folder"+this.id];
		if (Param_useIcons) {
			this.iconImg = this.navObj.document.images["folderIcon"+this.id];
		}
		this.nodeImg = this.navObj.document.images["nodeIcon"+this.id];
		doc.yPos = doc.yPos+this.navObj.clip.height;
	}
	else if (browserVersion != 0) {
		this.navObj = getElById("folder"+this.id);
		if (Param_useIcons) {
			this.iconImg = getElById("folderIcon"+this.id);
		}
		this.nodeImg = getElById("nodeIcon"+this.id);
	}
}

function setStateFolder(isOpen) {
	var subEntries;
	var totalHeight;
	var fIt = 0;
	var i = 0;
	var currentOpen;

	if (isOpen == this.isOpen) {
		return;
	}

	if (browserVersion == 2) {
		totalHeight = 0;
		for (i = 0; i < this.nChildren; i++) {
			totalHeight = totalHeight + this.children[i].navObj.clip.height;
		}

		subEntries = this.subEntries();

		if (this.isOpen) {
			totalHeight = 0 - totalHeight;
		}

		for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) {
			indexOfEntries[fIt].navObj.moveBy(0, totalHeight);
		}
	}

	this.isOpen = isOpen;

	if (this.id != 0 && Param_preserveState && !this.isOpen) { // closing
		currentOpen = getCookie("clickedFolder");

		if (currentOpen != null) {
			currentOpen = currentOpen.replace(this.id + "-", "");
			setCookie("clickedFolder", currentOpen);
		}
	}

	if (!this.isOpen && this.isLastOpenedfolder) {
		lastOpenedFolder = -1;
		this.isLastOpenedfolder = false;
	}

	propagateChangesInState(this);
}

function propagateChangesInState(folder) {
	var i = 0;

	// change icon
	if (folder.nChildren > 0 && folder.level > 0) { // otherwise the one given at render stays
		folder.nodeImg.src = folder.nodeImageSrc();
	}

	// change node
	if (Param_useIcons) {
		folder.iconImg.src = folder.iconImageSrc();
	}

	// propagate changes
	for (i = folder.nChildren - 1; i >= 0; i--) {
		if (folder.isOpen) {
			folder.children[i].mostra(folder.navObj)
		}
		else {
			folder.children[i].esconde();
		}
	}
}

function escondeFolder() {
	this.escondeBlock();
	this.setState(0);
}

function linkFolderHTML() {
	var docW = "";

	if (this.href) 	{
		if (Param_useFrames) {
			docW = docW + "<a href='" + this.href + "' TARGET=\"basefrm\" ";
		}
		else {
			docW = docW + "<a href='" + this.href + "' "; /* docW = docW + "<a href='" + this.href + "' TARGET=mainFrame "; *//* docW = docW + "<a href='" + this.href + "' TARGET=_top "; */
		}

		if (browserVersion > 0 && Param_useFrames) {
			docW = docW + "onClick='javascript:clickOnFolder("+this.id+")'";
		}

		docW = docW + ">";
	}
	else {
		docW = docW + "<a>";
	}

	return docW;
}

function addChild(childNode) {
	this.children[this.nChildren] = childNode;
	this.nChildren++;
	return childNode;
}

function folderSubEntries() {
	var i = 0;
	var se = this.nChildren;

	for (i = 0; i < this.nChildren; i++) {
		if (this.children[i].children) { // is a folder
			se = se + this.children[i].subEntries();
		}
	}

	return se;
}

function nodeImageSrc() {
	var srcStr = "";

	// NEW 20020904
	// new node images for folders with catId specified
	if (this.catId != '') {
		if (this.nChildren == 0) {
			srcStr = Param_iconImagePath + "blank_" + this.catId + ".gif";
		}
		else {
			if (this.isOpen) {
				srcStr = Param_iconImagePath + "minus_" + this.catId + ".gif";
			}
			else {
				srcStr = Param_iconImagePath + "plus_" + this.catId + ".gif";
			}
		}

		return srcStr;
	}
	// END NEW 20020904

	if (this.isLastNode) { // the last child in the children array
		if (this.nChildren == 0) {
			srcStr = Param_iconImagePath + "ftv2lastnode.gif";
		}
		else {
			if (this.isOpen) {
				srcStr = Param_iconImagePath + "ftv2mlastnode.gif";
			}
			else {
				srcStr = Param_iconImagePath + "ftv2plastnode.gif";
			}
		}
	}
	else {
		if (this.nChildren == 0) {
			srcStr = Param_iconImagePath + "ftv2node.gif";
		}
		else {
			if (this.isOpen) {
				srcStr = Param_iconImagePath + "ftv2mnode.gif";
			}
			else {
				srcStr = Param_iconImagePath + "ftv2pnode.gif";
			}
		}
	}

	return srcStr;
}

function iconImageSrc() {
	if (this.isOpen) {
		return this.iconSrc;
	}
	else {
		return this.iconSrcClosed;
	}
}

/*
 * Class Item
 * Defines a leaf node in the tree, which is a document or a link inside a folder.
 *
 */
function Item(itemDescription, itemLink, catId) {
	// constructor
	// constant data
	this.desc = itemDescription;
	this.link = itemLink;
	this.id = -1; // initialized in initalize()
	this.navObj = 0; // initialized in render()
	this.iconImg = 0; // initialized in render()
	this.iconSrc = Param_iconImagePath + "ftv2doc.gif";
	this.isRendered = 0;
	this.isLastNode = false;
	this.level = 0;
	this.leftSideCoded = "";
	this.nChildren = 0;

	// NEW 20020916
	this.catId = catId;
	// END NEW 20020916

	// methods
	this.initialize = initializeItem;
	this.createIndex = createEntryIndex;
	this.escondeBlock = escondeBlock;
	this.esconde = escondeBlock;
	this.mostra = mostra;
	this.renderOb = drawItem;
	this.totalHeight = totalHeight;
	this.blockStartHTML = blockStartHTML;
	this.blockEndHTML = blockEndHTML;
}

function initializeItem(level, lastNode, leftSide) {
	this.createIndex();
	this.level = level;
	this.leftSideCoded = leftSide;
	this.isLastNode = lastNode;
}

function drawItem(insertAtObj) {
	var leftSide = leftSideHTML(this.leftSideCoded);
	var docW = "";

	this.isRendered = 1;

	if (this.level > 0) {
		if (this.isLastNode) { // the last sibling in the children array
			/* leftSide = leftSide + "<td valign=top><img src='" + Param_iconImagePath + "ftv2lastnode.gif' width=16 height=22></td>" */
			// MOD 20020904
			// use new tree lines; this is image for plain last node
			leftSide = leftSide + "<td valign=top><img src='" + Param_iconImagePath + "line_lastnode.gif' width=20 height=18></td>";
		}
		else 	{
			/* leftSide = leftSide + "<td valign=top background=" + Param_iconImagePath + "ftv2vertline.gif><img src='" + Param_iconImagePath + "ftv2node.gif' width=16 height=22></td>" */
			// MOD 20020904
			// use new tree lines; this is image for plain vertical line
			leftSide = leftSide + "<td valign=top background=" + Param_iconImagePath + "spacer.gif><img src='" + Param_iconImagePath + "line_node.gif' width=20 height=18></td>";
		}
	}

	docW = docW + this.blockStartHTML("item");

	docW = docW + "<tr>" + leftSide + "<td valign=top>";
	if (Param_useIcons) {
		docW = docW + "<a href=" + this.link + ">" + "<img id='itemIcon"+this.id+"' " + "src='"+this.iconSrc+"' border=0>" + "</a>";
	}
	else {
		docW = docW + "<img src=" + Param_iconImagePath + "ftv2blank.gif height=2 width=3>";
	}

	if (Param_wrapItemText) {
		docW = docW + "</td><td valign=middle width=100%>";
	}
	else {
		docW = docW + "</td><td valign=middle nowrap width=100%>";
	}

	if (Param_useLinks) {
		docW = docW + "<a href=" + this.link + ">" + this.desc + "</a>";
	}
	else {
		docW = docW + this.desc;
	}

	docW = docW + "</td>";

	docW = docW + this.blockEndHTML();

	if (insertAtObj == null) {
		doc.write(docW);
	}
	else 	{
		insertAtObj.insertAdjacentHTML("afterEnd", docW);
	}

	if (browserVersion == 2) {
		this.navObj = doc.layers["item"+this.id];
		if (Param_useIcons) {
			this.iconImg = this.navObj.document.images["itemIcon"+this.id];
		}
		doc.yPos = doc.yPos + this.navObj.clip.height;
	}
	else if (browserVersion != 0) {
		this.navObj = getElById("item"+this.id);
		if (Param_useIcons) {
			this.iconImg = getElById("itemIcon"+this.id);
		}
	}
}

/*
 * Common methods for both classes.
 *
 */
function escondeBlock() {
	if (browserVersion == 1 || browserVersion == 3) {
		if (this.navObj.style.display == "none") {
			return;
		}
		this.navObj.style.display = "none";
	}
	else {
		if (this.navObj.visibility == "hidden") {
			return;
		}
		this.navObj.visibility = "hidden";
	}
}

function mostra(domObj) {
	if (!this.isRendered) {
		 this.renderOb(domObj);
	}
	else {
		if (browserVersion == 1 || browserVersion == 3) {
			this.navObj.style.display = "block";
		}
		else {
			this.navObj.visibility = "show";
		}
	}
}

function blockStartHTML(idprefix) {
	var idParam = "id='" + idprefix + this.id + "'";
	var docW = "";

	if (browserVersion == 2) {
		docW = "<layer "+ idParam + " top=" + doc.yPos + " visibility=show>";
	}
	else if (browserVersion != 0) {
		docW = "<div " + idParam + " style='display:block; position:block;'>";
	}

	docW = docW + "<table border=0 cellspacing=0 cellpadding=0 width=100% >";

	return docW;
}

function blockEndHTML() {
	var docW = "";

	docW = "</table>";

	if (browserVersion == 2) {
		docW = docW + "</layer>";
	}
	else if (browserVersion != 0) {
		docW = docW + "</div>";
	}

	return docW;
}

function createEntryIndex() {
	this.id = nEntries;
	indexOfEntries[nEntries] = this;
	nEntries++;
}

function totalHeight() {
	// return the total height of subEntries opened;
	// used with browserVersion == 2
	var h = this.navObj.clip.height;
	var i = 0;

	if (this.isOpen) { // is a folder and _is_ open
		for (i = 0 ; i < this.nChildren; i++) {
			h = h + this.children[i].totalHeight();
		}
	}

	return h;
}

function leftSideHTML(leftSideCoded) {
	var i;
	var retStr = "";

	for (i = 0; i < leftSideCoded.length; i++) {
		if (leftSideCoded.charAt(i) == "1") {
			//retStr = retStr + "<td valign=top background=" + Param_iconImagePath + "line_vertline.gif><img src='" + Param_iconImagePath + "line_vertline.gif' width=20 height=18></td>"; // MOD 20020904 new tree lines; /* retStr = retStr + "<td valign=top background=" + Param_iconImagePath + "ftv2vertline.gif><img src='" + Param_iconImagePath + "ftv2vertline.gif' width=16 height=22></td>" */
			retStr = retStr + "<td valign=top><img src='" + Param_iconImagePath + "spacer.gif' width=20 height=18></td>"; // MOD 20020904 new tree lines; /* retStr = retStr + "<td valign=top background=" + Param_iconImagePath + "ftv2vertline.gif><img src='" + Param_iconImagePath + "ftv2vertline.gif' width=16 height=22></td>" */
		}

		if (leftSideCoded.charAt(i) == "0") {
			retStr = retStr + "<td valign=top><img src='" + Param_iconImagePath + "ftv2blank.gif' width=16 height=22></td>";
		}
	}

	return retStr;
}

/*
 * =============================
 * Event Handlers
 * =============================
 */
function clickOnFolder(folderId) {
	var clicked = indexOfEntries[folderId];

	if (!clicked.isOpen) {
		clickOnNode(folderId);
	}

	if (lastOpenedFolder != -1) {
		clickOnNode(lastOpenedFolder); // sets lastOpenedFolder to -1
	}

	if (clicked.nChildren == 0) {
		lastOpenedFolder = folderId;
		clicked.isLastOpenedfolder = true;
	}
}

function clickOnNode(folderId) {
	var clickedFolder = 0;
	var state = 0;
	var currentOpen;

	clickedFolder = indexOfEntries[folderId];
	state = clickedFolder.isOpen;

	clickedFolder.setState(!state); // open<->close

	if (folderId != 0 && Param_preserveState) {
		currentOpen = getCookie("clickedFolder");
		if (currentOpen == null) {
			currentOpen = "";
		}

		if (!clickedFolder.isOpen) { // closing
			currentOpen = currentOpen.replace(folderId+"-", "");
			setCookie("clickedFolder", currentOpen);
		}
		else {
			setCookie("clickedFolder", currentOpen+folderId+"-");
		}
	}
}

function ld() {
	return document.links.length - 1;
}

/*
 * =============================
 * Helper Functions
 * =============================
 */
function createTreeFolder(description, href, catId) {
	// MOD 20020904
	// added new param for catId, highlight and lowlight colors
	return new Folder(description, href, catId);
}

function createTreeNode(description, linkData, catId, optionFlags) {
	var fullLink = "";
	var targetFlag = "";
	var target = "";
	var protocolFlag = "";
	var protocol = "";

	if (optionFlags >= 0) { // is numeric (old style) or empty (error)
		return oldCreateTreeNode(description, linkData, catId, optionFlags);
	}

	targetFlag = optionFlags.charAt(0);
	if (targetFlag == "B")
		target = "_blank"
	if (targetFlag == "P")
		target = "_parent"
	if (targetFlag == "R")
		target = "basefrm"
	if (targetFlag == "S")
		target = "_self"
	if (targetFlag == "T")
		target = "" /* target = "mainFrame" *//* target = "_top" */

	if (optionFlags.length > 1) {
		protocolFlag = optionFlags.charAt(1);
		if (protocolFlag == "h")
			protocol = "http://"
		if (protocolFlag == "s")
			protocol = "https://"
		if (protocolFlag == "f")
			protocol = "ftp://"
		if (protocolFlag == "m")
			protocol = "mailto:"
	}

	fullLink = "'" + protocol + linkData + "' target=" + target;

	return new Item(description, fullLink, catId);
}

/*
 * Version of createTreeNode() for old browser compatibility.
 *
 */
function oldCreateTreeNode(description, linkData, catId, target) {
	var fullLink = "";

	// backwards compatibility code
	if (Param_useFrames) {
		if (target == 0) {
			fullLink = "'"+linkData+"' target=\"basefrm\"";
		}
		else 	{
			if (target == 1) {
				fullLink = "'http://"+linkData+"' target=_blank";
			}
			else 	if (target == 2) {
				fullLink = "'http://"+linkData+"' target=\"basefrm\"";
			}
			else {
				fullLink = linkData+" target=\"_top\"";
			}
		}
	}
	else {
		if (target == 0) {
			fullLink = "'"+linkData+"' target=_top";
		}
		else 	{
			if (target == 1) {
				fullLink = "'http://"+linkData+"' target=_blank";
			}
			else {
				fullLink = "'http://"+linkData+"' target=_top";
			}
		}
	}

	return new Item(description, fullLink, catId);
}

function insertTreeFolderTo(childFolder, parentFolder) {
	return parentFolder.addChild(childFolder);
}

function insertTreeNodeTo(document, parentFolder) {
	return parentFolder.addChild(document);
}

function preLoadIcons() {
	// preload icon images
	var auxImg;
	auxImg = new Image();
	//auxImg.src = Param_iconImagePath + "line_vertline.gif";
	auxImg.src = Param_iconImagePath + "line_lastnode.gif";
	auxImg.src = Param_iconImagePath + "line_node.gif";
	auxImg.src = Param_iconImagePath + "ftv2blank.gif";
}

/*
 * Open some folders for initial layout, if necessary.
 *
 */
function setInitialLayout() {
	if (browserVersion > 0 && !Param_openAll) {
		clickOnNode(0);
	}

	if (!Param_openAll && (browserVersion > 0) && Param_preserveState) {
		Param_preserveState = 0; // temporarily disable recording of clickOnNode
		openPersistentFolders();
		Param_preserveState = 1;
	}
}

/*
 * Used when the broswer is NS4 or Param_openAll is enabled.
 *
 */
function renderAllTree(nodeObj, parent) {
	var i = 0;
	nodeObj.renderOb(parent);

	if (supportsDeferral) {
		for (i = nodeObj.nChildren - 1; i >= 0; i--) {
			renderAllTree(nodeObj.children[i], nodeObj.navObj);
		}
	}
	else {
		for (i = 0; i < nodeObj.nChildren; i++) {
			renderAllTree(nodeObj.children[i], null);
		}
	}
}

function hideWholeTree(nodeObj, hideThisOne, nodeObjMove) {
	var i = 0;
	var heightContained = 0;
	var childrenMove = nodeObjMove;

	if (hideThisOne) {
		nodeObj.escondeBlock();
	}

	if (browserVersion == 2) {
		nodeObj.navObj.moveBy(0, 0 - nodeObjMove);
	}

	for (i = 0; i < nodeObj.nChildren; i++) {
		heightContainedInChild = hideWholeTree(nodeObj.children[i], true, childrenMove);
		if (browserVersion == 2) {
			heightContained = heightContained + heightContainedInChild + nodeObj.children[i].navObj.clip.height;
			childrenMove = childrenMove + heightContainedInChild;
		}
	}

	return heightContained;
}

/*
 * Emulate inserAdjacentHTML on NS6.
 *
 */
if (typeof HTMLElement != "undefined" && !HTMLElement.prototype.insertAdjacentElement) {
	HTMLElement.prototype.insertAdjacentElement = function(where, parsedNode) {
		switch (where) {
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode, this);
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode, this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) {
				this.parentNode.insertBefore(parsedNode, this.nextSibling);
			}
			else {
				this.parentNode.appendChild(parsedNode);
			}
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where, htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where, parsedHTML);
	}
}

function getElById(idVal) {
	if (document.getElementById != null) {
		return document.getElementById(idVal);
	}

	if (document.all != null) {
		return document.all[idVal];
	}

	return null;
}

/*
 * =============================
 * Cookie Handling
 * OPTIONAL: No cookies are used unless
 * Param_preserveState is set to 1 (default 0)
 * =============================
 */
function openPersistentFolders() {
	var stateInCookie;
	var fldStr = "";
	var fldArr;
	var fldPos = 0;
	stateInCookie = getCookie("clickedFolder");

	if(stateInCookie != null) {
		fldArr = stateInCookie.split("-");
		for (fldPos = 0; fldPos < fldArr.length; fldPos++) {
			fldStr = fldArr[fldPos];
			if (fldStr != "") {
				clickOnNode(eval(fldStr));
			}
		}
	}
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;

		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) {
			break;
		}
	}

	return null;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function setCookie(name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	//var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	var path = "/"; // allows the tree to remain open across pages with diff names & paths
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function deleteCookie(name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

/*
 * =============================
 * Default Settings
 * These settings can be overriden.
 * =============================
 */
Param_useLinks = 0;
Param_openAll = 0;
Param_useFrames = 1;
Param_useIcons = 1;
Param_wrapItemText = 0;
Param_preserveState = 0;
Param_iconImagePath = '';

/*
 * =============================
 * Global Variables
 * =============================
 */
indexOfEntries = new Array;
nEntries = 0;
browserVersion = 0;
selectedFolder = 0;
lastOpenedFolder = -1;
t = 5;
doc = document;
doc.yPos = 0;
supportsDeferral = false;

/*
 * =============================
 * Initialization
 * Involved where the tree menu placed.
 * =============================
 */
function initializeTree() {
	preLoadIcons();

	switch(navigator.family) {
	case 'ie4':
		browserVersion = 1; // IE > 3.x
		break;
	case 'nn4':
		browserVersion = 2; // NS4.x
		break;
	case 'gecko':
		browserVersion = 3; // NS6.x
		break;
	default:
		browserVersion = 0; // other, possibly without DHTML
		break;
	}

	supportsDeferral = ((browserVersion == 1 && navigator.version >= 5 && navigator.OS != "mac") || browserVersion == 3);
//	supportsDeferral = false;
	if (!Param_useFrames && browserVersion == 2) {
		browserVersion = 0;
	}

	treeMenu.initialize(0, true, "");

	if (supportsDeferral && !Param_openAll) {
		treeMenu.renderOb(null); // delay construction of nodes
	}
	else {
		renderAllTree(treeMenu, null);
		if (browserVersion != 0 && !Param_openAll) {
			hideWholeTree(treeMenu, false, 0);
		}
	}

	if (browserVersion == 2) {
		doc.write("<layer top=" + indexOfEntries[nEntries-1].navObj.top + ">&nbsp;</layer>");
	}

	setInitialLayout();
}

	Param_useLinks = 1;
	Param_openAll = 0;
	Param_useFrames = 0;
	Param_useIcons = 0;
	Param_wrapItemText = 1;
	Param_preserveState = 0;
	Param_iconImagePath = "/src/menuitem/";

	var treeMenu = createTreeFolder("", "", "");
	var currFolder = null, currNode = null;
	var hlColors = new Array;

	function hl(obj) {
		if (document.all) {
			if (obj == null) {
				obj = event.srcElement;
			}
			obj.style.color = hlColors[obj.id];
		}
		else if (document.getElementById) {
			obj.style.color = hlColors[obj.id];
		}
	}

	function ll(obj) {
		var currNodeElemId = '';
		if (currNode != null) {
			currNodeElemId = "node_" + currNode.catId;
		}

	if (document.all) {
			if (obj == null) {
				obj = event.srcElement;
			}
			var elemId = obj.id;
			if (elemId == currNodeElemId) {
				return;
			}
			obj.style.color = '#666666';
		}
		else if (document.getElementById) {
			var elemId = obj.id;
			if (elemId == currNodeElemId) {
				return;
			}
			obj.style.color = '#666666';
		}
	}

	function collapseAll(folder) {
		var child = null;
		for (i = 0; i < folder.nChildren; i++) {
			child = folder.children[i];

		if (child != null && eval("child.setState")) {
				child.setState(false);
			}
		}
	}

	function expandAll(folder) {
		var child = null;
		for (i = 0; i < folder.nChildren; i++) {
			child = folder.children[i];

		if (child != null && eval("child.setState")) {
				child.setState(true);
			}
		}
	}

	function searchNode(parent, catId) {
		if (parent != null && catId != null) {
			for (var i = 0; i < parent.nChildren; i++) {
				if (parent.children[i].catId == catId) {
					return parent.children[i];
				}
			}
		}
	return null;
	}

	function setEffect(node) {
		if (node != null) {
			if (eval("node.setState")) {
				node.setState(true);
				return;
			}

		if (document.all) {
				hl(document.all["node_" + node.catId]);
			}
			else if (document.getElementById) {
				hl(document.getElementById("node_" + node.catId));
			}
		}
	}

