/* -------------------------------------------------------
 :: navi.js 3.3.22 :: DHTML View Tree
 
 Usage:
 
	var Nodes = new Array();
	Nodes[0] = new Node('Node 0', 'GoTo("index.html")', 'img/navi/closed.gif', '0', 'Nodes', null);
	main.innerHTML = Nodes[0].DrawTree();
	
	Nodes[1] = Nodes[0].AddNode('Node 1', 'GoTo("page1.html")', 'img/navi/closed.gif', '1');
	Nodes[2] = Nodes[0].AddNode('Node 2', 'GoTo("page2.html")', 'img/navi/closed.gif', '2');
	Nodes[3] = Nodes[1].AddNode('Node 3', 'GoTo("page3.html")', 'img/navi/closed.gif', '3');
	Nodes[4] = Nodes[2].AddNode('Node 4', 'GoTo("page4.html")', 'img/navi/closed.gif', '4');
	Nodes[2].MoveUp();
	Nodes[2].DelNode();
	alert(Nodes[0].FindNode('1').mID);
                                                            
-------------------------[ (c)2002 nataniel@xpect.pl ]--- */

var current;

function Node(pName, pOnClick, pImage, pID, pPrefix, pParent) {
	this.mName = pName;
	this.mOnClick = pOnClick + '; ' + pPrefix + '[\'' + pID + '\'].Activate(); return false;';
	this.mImage = pImage;
	this.mID = pID;
	this.mPrefix = pPrefix;
	this.mActive = false;
	this.cParent = pParent;
	this.cNODES = new Array();
	this.oChild = null;
	
	// Methods
	this.AddNode = AddNode;
	this.FindNode = FindNode;
	this.GetChild = GetChild;
	this.ExpandNode = ExpandNode;
	this.RepaintNode = RepaintNode;
	this.DrawChild = DrawChild;
	this.DrawNode = DrawNode;
	this.DrawTree = DrawTree;
	this.MoveUp = MoveUp;
	this.MoveDown = MoveDown;
	this.DelNode = DelNode;
	this.FindPos = FindPos;
	this.SetName = SetName;
	this.Activate = Activate;
}

function AddNode(pName, pOnClick, pImage, pID, pPrefix, pAfter) {
	var len = this.cNODES.length;
	if (!pPrefix) {
		pPrefix = this.mPrefix;
	}
	
	if (typeof pAfter != 'undefined') {
		pos = 0;
		if (pAfter != '') {
			for (var i in this.cNODES) {
				if (this.cNODES[i].mID == pAfter) {
					pos = parseInt(i)+1;
				}
			}
		}
		this.cNODES.splice(pos, 0, new Node(pName, pOnClick, pImage, pID, pPrefix, this));
	} else {
		pos = len;
		this.cNODES.push(new Node(pName, pOnClick, pImage, pID, pPrefix, this));
	}
	return this.cNODES[pos*1];
}

function SetName(pName) {
	this.mName = pName;
	if (objName = document.getElementById(this.mPrefix + this.mID + "Name")) {
		objName.innerHTML = this.mName;
	}
}

function Activate() {
	if (current) {
		if (objName = document.getElementById(current.mPrefix + current.mID + "Name")) {
			objName.style.backgroundColor = "";
			current.mActive = false;
		}
	}
	
	if (objName = document.getElementById(this.mPrefix + this.mID + "Name")) {
		objName.style.backgroundColor = "#CCCCCC";
		this.mActive = true;
		current = this;
	}
}

function GetChild() {
	if (this.oChild = document.getElementById(this.mPrefix + this.mID + "Child")) {
		return this.oChild;
	} else {
		return null;
	}
}

function FindNode(pID) {
	if (this.mID == pID) {
		return this;
	} else {
		for (var i in this.cNODES) {
			var node = this.cNODES[i].FindNode(pID);
			if (node != null) {
				return node;
			}
		}
	}
	
	return null;
}
	
function ExpandNode(pForce) {
	if (this.GetChild() != null) {
		objImg = document.getElementById(this.mPrefix + this.mID + "Img");
		objBack = document.getElementById(this.mPrefix + this.mID + "Back");
		objChild = this.oChild;
		
		if ((objChild.style.display == "none") || pForce)
		{
			objChild.style.display = "block";
			objBack.background = "img/navi/dot.gif";
			if (pForce) {
				objExpand = document.getElementById(this.mPrefix + this.mID + "Expand");
				objExpand.outerHTML = '<A id=' + this.mPrefix + this.mID + 'Expand onclick="' + this.mPrefix + '[\'' + this.mID + '\'].ExpandNode(); return false;"><IMG id=' + this.mPrefix + this.mID + 'Img height=16 alt="" src="img/navi/minus.gif" width=19 border=0></A>';
			} else {
				objImg.src = "img/navi/minus.gif";
			}
		}
		else
		{
			objChild.style.display = "none";
			objImg.src = "img/navi/plus.gif";
			objBack.background = "";
		}
	}
}

function DrawChild() {
	var html = '<TABLE cellSpacing=0 cellPadding=0 border=0 width="100%"><TBODY>';
	
	for (var i in this.cNODES) {
		if (i < this.cNODES.length-1) {
			html = html + this.cNODES[i].DrawNode(0);
		} else {
			html = html + this.cNODES[i].DrawNode(1);
		}
	}
	
	html = html + '</TBODY></TABLE>';
	
	return html;
}

function DrawNode(pLast) {
	var tdBackground = (pLast != 1) ? 'background=img/navi/dot.gif' : '';
	var displayStyle = 'none';
	var expandImg = '<A id=' + this.mPrefix + this.mID + 'Expand><IMG id=' + this.mPrefix + this.mID + 'Img height=16 alt="" src="img/navi/empty.gif" width=19 border=0></A>';
	var divBackground = this.mActive ? 'background-color: #CCCCCC' : '';
	
	if (this.GetChild() != null) {
		displayStyle = this.oChild.style.display;
	}
	
	if (this.cNODES.length > 0) {
		if (displayStyle == 'none') {
			var expandImg = '<A id=' + this.mPrefix + this.mID + 'Expand onclick="' + this.mPrefix + '[\'' + this.mID + '\'].ExpandNode(); return false;"><IMG id=' + this.mPrefix + this.mID + 'Img height=16 alt="" src="img/navi/plus.gif" width=19 border=0></A>';
			var tdBack = '';
		} else {
			var expandImg = '<A id=' + this.mPrefix + this.mID + 'Expand onclick="' + this.mPrefix + '[\'' + this.mID + '\'].ExpandNode(); return false;"><IMG id=' + this.mPrefix + this.mID + 'Img height=16 alt="" src="img/navi/minus.gif" width=19 border=0></A>';
			var tdBack = 'background=img/navi/dot.gif';
		}
	}
	
	var html = '<TR id=' + this.mPrefix + this.mID + 'Node>'
		+ '<TD ' + tdBackground + ' vAlign=top width=19>' + expandImg + '</TD>'
		+ '<TD vAlign=top>'
		+ '<TABLE cellSpacing=0 cellPadding=0 border=0 WIDTH="100%">'
		+ '<TBODY>'
		+ '<TR>'
		+ '<TD vAlign=top width=19 height=16><TABLE cellSpacing=0 cellPadding=0 border=0 height="100%"><TBODY><TR><TD HEIGHT="16"><A href=# onclick="' + this.mOnClick + '"><IMG height=16 alt="" src="' + this.mImage + '" width=19 border=0></A></TD></TR><TR><TD id=' + this.mPrefix + this.mID + 'Back ' + tdBack + '><IMG src="img/_.gif" width=1 height=2></TD></TR></TBODY></TABLE></TD>'
		+ '<TD vAlign=top>'
		+ '<A href=# class=navi onclick="' + this.mOnClick + '" onfocus="blur();"><DIV id=' + this.mPrefix + this.mID + 'Name STYLE="margin: 0px 0px 0px 2px; padding: 1px 3px 1px 3px; ' + divBackground + '" WIDTH="100%">' + this.mName + '</DIV></A>'
		+ '</TD></TR></TBODY></TABLE>'
		+ '<DIV id=' + this.mPrefix + this.mID + 'Child style="DISPLAY: ' + displayStyle + '">'
		+ this.DrawChild()
		+ '</DIV></TD>'
		+ '</TR>';
	
	return html;
}

function DrawTree() {
	var displayStyle = 'block';
	var divBackground = this.mActive ? 'background-color: #CCCCCC' : '';
	
	if (this.GetChild() != null) {
		displayStyle = this.oChild.style.display;
	}
	
	var html = '<TABLE cellSpacing=0 cellPadding=0 border=0><TBODY>'
		+ '<TR id=' + this.mPrefix + this.mID + 'Node>'
		+ '<TD vAlign=top>'
		+ '<TABLE cellSpacing=0 cellPadding=0 border=0 WIDTH="100%">'
		+ '<TBODY>'
		+ '<TR>'
		+ '<TD vAlign=top width=19><A href=# onclick="' + this.mOnClick + '"><IMG height=16 alt="" src="' + this.mImage + '" width=19 border=0></A></TD>'
		+ '<TD vAlign=top>'
		+ '<A href=# class=navi onclick="' + this.mOnClick + '" onfocus="blur();"><DIV id=' + this.mPrefix + this.mID + 'Name STYLE="margin: 0px 0px 0px 2px; padding: 1px 3px 1px 3px; ' + divBackground + '" WIDTH="100%">' + this.mName + '</DIV></A>'
		+ '</TD></TR></TBODY></TABLE>'
		+ '<DIV id=' + this.mPrefix + this.mID + 'Child style="DISPLAY: ' + displayStyle + '">'
		+ this.DrawChild()
		+ '</DIV></TD>'
		+ '</TR>'
		+ '</TBODY></TABLE>';
	
	return html;
}

function RepaintNode() {
	if (this.GetChild() != null) {
		var html = this.DrawChild();
		this.oChild.innerHTML = html;
	}
}

function FindPos() {
	var pos = -1;
	if (this.cParent != null) {
		for (var i in this.cParent.cNODES) {
			if (this.cParent.cNODES[i] == this) {
				pos = i;
			}
		}
	}
	
	return parseInt(pos);
}
	
function MoveUp() {
	var pos = this.FindPos();
	if ((pos > -1) && (pos > 0)) {
		this.cParent.cNODES[pos] = this.cParent.cNODES[pos-1];
		this.cParent.cNODES[pos-1] = this;
		this.cParent.RepaintNode();
	}
}

function MoveDown() {
	var pos = this.FindPos();
	if ((pos > -1) && (pos < this.cParent.cNODES.length-1)) {
		this.cParent.cNODES[pos] = this.cParent.cNODES[pos+1];
		this.cParent.cNODES[pos+1] = this;
		this.cParent.RepaintNode();
	}
}

function DelNode() {
	var pos = this.FindPos();
	if (pos > -1) {
		this.cParent.cNODES.splice(pos, 1);
		if ((this.cParent.cNODES.length < 1) && (this.cParent.cParent != null)) {
			this.cParent.cParent.RepaintNode();
		} else {
			this.cParent.RepaintNode();
		}
	}
}