/**************************************************************************************************
Copyright (C) 2000 Caspar-David Senfft aliasing CDS-Virtuallender.
This javascript is made by and copyrighted to CDS-Virtuallender at 

http://www.scriptlender.de/

Wherever the source code state that the script or demo is free to use, 
the source is free to use as long the copyright notice is kept in the source. 

As mentioned; the only thing I require if you use any of my scripts or demos on your own pages is 
that you keep the copyright notice in there. 

Very simple; All may be used freely as long as this message is intact!
**************************************************************************************************/

var oNodeMgr = new cNodeMgr();

/*************************************************************************************************/

function cNodeMgr()
{
	/*********************************/
	/* Declaration of public members */
	/*********************************/

	this.meNodeAry  = new Array();
	
	this.meRootNode = new sNode();
	this.meRootNode.meKey = 0;
	this.meNodeAry[0] = this.meRootNode;
	
	this.meActiveNode = null;

	/****************************************/
	/* Declaration of public memberfunctions*/
	/****************************************/

	this.addNode   = cNodeMgr_addNode;
	this.getNode   = cNodeMgr_getNode;
	this.getParent = cNodeMgr_getParent;
	this.getChild  = cNodeMgr_getChild;
	this.getSpacer = cNodeMgr_getSpacer;

	this.isActiveNode = cNodeMgr_isActiveNode;
	this.isParentNode = cNodeMgr_isParentNode;

	this.closeParents = cNodeMgr_closeParents;
	this.showTreeMenu = cNodeMgr_showTreeMenu;
	
	this.searchForLnk = cNodeMgr_searchForLnk;
}

/*************************************************************************************************/

function cNodeMgr_addNode(prmParent,prmChild)
{
	var bAdded = false;

	// You can remove the following statement if you want to have more performance.
	if (prmParent == prmChild) {
		alert("ERROR:\nInvalid Node Structure detected!\nConcerning Node ignored!");
		return(bAdded);
	}

	if (prmChild) {
		prmParent = prmParent ? prmParent : this.meRootNode;
		
		prmChild.meKey    = this.meNodeAry.length;
		prmChild.meImgId += prmChild.meKey;
	
		bAdded = prmParent.appendChild(prmChild);
	
		if (bAdded) {
			this.meNodeAry[this.meNodeAry.length] = prmChild;
		}
	}
	
	return(bAdded);
}

/*************************************************************************************************/

function cNodeMgr_isActiveNode(prmKey)
{
	if (this.meActiveNode && (this.meActiveNode.meKey==prmKey)) {
		return(true);
	}

	return(false);
}

function cNodeMgr_isParentNode(prmKey)
{
	var theNode = this.getParent(prmKey);

	if (theNode) return(true);

	return(false);
}

/*************************************************************************************************/

function cNodeMgr_getSpacer()
{
	var theSpacer = new sNode();
	theSpacer.meSpacer = true;
	    
	return(theSpacer);
}

function cNodeMgr_getParent(prmKey)
{
	var theNode = this.getNode(prmKey);

	if (theNode && (theNode.meChildAry.length)) {
		return(theNode);
	} else {
		return(null);
	}
}

function cNodeMgr_getChild(prmKey)
{
	var theNode = this.getNode(prmKey);

	if (theNode && (!theNode.meChildAry.length)) {
		return(theNode);
	} else {
		return(null);
	}
}

function cNodeMgr_getNode(prmKey)
{
	var theNode = null;

	for (var i=0; i<this.meNodeAry.length; i++) {
		theNode = this.meNodeAry[i];
		if (theNode && (theNode.meKey == prmKey)) {
			return(theNode);
		}
	}

	return(null);
}

function cNodeMgr_closeParents()
{
	var theNode = null;

	for (var i=0; i<this.meNodeAry.length; i++) {
		theNode = this.meNodeAry[i];
		if (theNode && theNode.meChildAry.length && !theNode.meRoot && !theNode.meHeader) {
			theNode.meOpen = false;
		}
	}
}

/*************************************************************************************************/

function cNodeMgr_showTreeMenu(prmShow)
{
	this.meRootNode.meOpen = prmShow ? true : false;

	getMenuPosition();

	var strHtml = this.meRootNode.getTreeString();
	writeMenuString(strHtml);
}

function cNodeMgr_searchForLnk(prmLink)
{
	if (!prmLink) return(null);
	
	var theNode = null;
	var idx = -1;
	
	for (var i=0; i<this.meNodeAry.length; i++) {
		theNode = this.meNodeAry[i];
		if (theNode && theNode.meLink) {
			idx = theNode.meLink.lastIndexOf(prmLink);
			//if (idx > -1) { 
			//Erweiterung der Suchabfrage für doppeldeutige Namen (access.htm und objaccess.htm)
			//allen Links in der nodeinit.js müssen zur eindeutigen Identifizierung den Präfix "./" besitzen
			if (idx > -1 && theNode.meLink.substr(idx-1,1) == "/") { 
				return(theNode);
			}
		}
	}
	
	return(null);
}

/*************************************************************************************************/
