// Description: mnuLeftBar object - creating simple vertical menu panel
// Author: Ruslan Kiryan <ruslan_kiryan@yahoo.com>
// Last update: 17/11/2000

var useIE = false; useNN = false;
if (document.all) useIE = true; else useNN = true;
var instances = 0;

function mnuLeftBar(imgSingle, imgClosed, imgOpened, imgSub, lnkTarget) {

	this.imgSingle = imgSingle;
	this.imgClosed = imgClosed;
	this.imgOpened = imgOpened;
	this.imgSub    = imgSub;

	this.openedNode = -1;
	this.Items      = new Array();
	this.stlIE      = new Array('foo1','foo2');
	this.stlNN      = new Array('foo1','foo2');

	this.addTopItem   = addTopItem;
	this.addSubItem   = addSubItem;
	this.propertiesIE = propertiesIE;
	this.propertiesNN = propertiesNN;

	this.lnkTarget     = lnkTarget;
//	this.updateFunc    = updateFunc;
	this.refreshMenu   = refreshMenu;
	this.setOpenedNode = setOpenedNode;

	this.openNode     = openNode;

	instances++;

	return this;
}

function setOpenedNode(idx) {
	this.openedNode = idx - 1;
}

function addTopItem(lbl, issingle, lnk) {
	var items = this.Items.length;
	this.Items[items] = new Array(lbl, new Array(), lnk, issingle);
	return (items + 1);
}

function addSubItem(idx, lbl, lnk) {
	var items = this.Items.length;
	if (idx < 1) return;
	if (idx > (items + 1)) return;
	var subitems = this.Items[idx-1][1].length;
	this.Items[idx-1][1][subitems] = new Array(lbl, lnk);
}

function propertiesIE(stlHeader, stlItem) {
	this.stlIE[0]  = stlHeader;
	this.stlIE[1]  = stlItem;
}

function propertiesNN(stlHeader, stlItem) {
	this.stlNN[0]  = stlHeader;
	this.stlNN[1]  = stlItem;
}

function openNode(idx) {
	var items = this.Items.length;

	this.openedNode = (this.openedNode == (idx-1)) ? -1 : idx - 1;

	for (idx=0; idx<items; idx++) {
		var groupName = "" + instances + "Block" + idx;
		var itemsName = "mnuRKdiv" + instances + "Items" + idx;
		var opened = this.openedNode == idx;
		var subitems = this.Items[idx][1].length;
        var itmObj = document.getElementById(itemsName);

		if (subitems > 0) {
			if (opened) {
				//document.all(itemsName).style.display = '';
                itmObj.style.display = 'block';
				document.images['mnuRKimg' + groupName].src = this.imgOpened;
			} else {
				//document.all(itemsName).style.display = 'none';
                itmObj.style.display = 'none';
				document.images['mnuRKimg' + groupName].src = this.imgClosed;
			}
		}
	}
}

function getCodeNN() {
	var retValue = '';
	var stl      = this.stlNN;
	var items    = this.Items.length;

	retValue += '<table border=0 cellspacing=0 cellpadding=1>';

	for (idx=0; idx<items; idx++) {
		var opened = this.openedNode == idx;
		var subitems = this.Items[idx][1].length;
		var mnulbl = this.Items[idx][0];
		var mnulnk = this.Items[idx][2];
		var mnusingle = this.Items[idx][3];

		var mnuimg = this.imgClosed;
		var mnusub = "return false;";
		if (mnusingle) {
			mnuimg = this.imgSingle;
			mnusub = "return true;";
		} else {
			mnuimg = (opened && useIE) ? this.imgOpened : this.imgClosed;

			if (mnulnk.length != 0) {
				mnusub = "return true;";
			} else {
				if (subitems>0) {
					mnusub = "openNode(" + (idx+1) + "); return false;";
				}
			}
		}

		retValue += "<tr><td align=center><img src='" + mnuimg + "' border=0></td><td class='" + stl[0] + "'>&nbsp;<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[0] + "'>" + mnulbl + "</a></td></tr>";
		for (jdx=0; jdx<subitems; jdx++) {
			mnuimg = this.imgSub;
			mnusub = "return true;";
			mnulbl = this.Items[idx][1][jdx][0];
			mnulnk = this.Items[idx][1][jdx][1];
			retValue += "<tr><td></td><td><table border=0 cellspacing=0 cellpadding=1><tr><td align=center><img src='" + mnuimg + "' border=0></td><td colspan=2 class='" + stl[1] + "'>&nbsp;<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[1] + "'>" + mnulbl + "</a></td></tr></table></td></tr>";
		}
	}
	retValue += '</table>';
	return retValue;
}

function getCodeIE() {
	var retValue = '';
	var stl      = this.stlIE;
	var items    = this.Items.length;

	for (idx=0; idx<items; idx++) {
		var opened = this.openedNode == idx;
		var subitems = this.Items[idx][1].length;
		var mnulbl = this.Items[idx][0];
		var mnulnk = this.Items[idx][2];
		var mnusingle = this.Items[idx][3];
		var groupName = "" + instances + "Block" + idx;
		var itemsName = "" + instances + "Items" + idx;

		var mnuimg = this.imgClosed;
		var mnusub = "return false;";
		if (mnusingle) {
			mnuimg = this.imgSingle;
			mnusub = "return true;";
		} else {
			mnuimg = (opened && useIE) ? this.imgOpened : this.imgClosed;

			if (mnulnk.length != 0) {
				mnusub = "return true;";
			} else {
				if (subitems>0) {
					mnusub = "openNode(" + (idx+1) + "); return false;";
				}
			}
		}

		retValue += "<div id='mnuRKdiv" + groupName + "' style='DISPLAY: block'>";
		retValue += "<img align='absMiddle' src='" + mnuimg + "' name='mnuRKimg" + groupName + "' border=0>&nbsp;";
		retValue += "<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[0] + "'>" + mnulbl + "</a>";
		retValue += "</div>";

		var displayFlg = "DISPLAY: none";

		if (opened) displayFlg = "";

		if (subitems > 0) {
			retValue += "<div id='mnuRKdiv" + itemsName + "' style='margin-left: 15px;" + displayFlg + "'>";
			for (jdx=0; jdx<subitems; jdx++) {
				mnuimg = this.imgSub;
				mnusub = "return true;";
				mnulbl = this.Items[idx][1][jdx][0];
				mnulnk = this.Items[idx][1][jdx][1];
				retValue += "<img align='absMiddle' src='" + mnuimg + "' border=0>&nbsp;";
				retValue += "<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[1] + "'>" + mnulbl + "</a><br>";
			}
			retValue += "</div>";
		}
	}
	return retValue;
}

function getCode() {
	var retValue = '';
	var stl = '';
	var items    = this.Items.length;
    
    if( useIE ) stl = this.stlIE;
    if( useNN ) stl = this.stlNN;

	for (idx=0; idx<items; idx++) {
		var opened = this.openedNode == idx;
		var subitems = this.Items[idx][1].length;
		var mnulbl = this.Items[idx][0];
		var mnulnk = this.Items[idx][2];
		var mnusingle = this.Items[idx][3];
		var groupName = "" + instances + "Block" + idx;
		var itemsName = "" + instances + "Items" + idx;

		var mnuimg = this.imgClosed;
		var mnusub = "return false;";
		if (mnusingle) {
			mnuimg = this.imgSingle;
			mnusub = "return true;";
		} else {
			mnuimg = (opened) ? this.imgOpened : this.imgClosed;

			if (mnulnk.length != 0) {
				mnusub = "return true;";
			} else {
				if (subitems>0) {
					mnusub = "openNode(" + (idx+1) + "); return false;";
				}
			}
		}

		retValue += "<div id='mnuRKdiv" + groupName + "' style='DISPLAY: block'>";
		retValue += "<img align='absMiddle' src='" + mnuimg + "' name='mnuRKimg" + groupName + "' border=0>&nbsp;";
		retValue += "<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[0] + "'>" + mnulbl + "</a>";
		retValue += "</div>";

		var displayFlg = "DISPLAY: none";

		if (opened) displayFlg = "";

		if (subitems > 0) {
			retValue += "<div id='mnuRKdiv" + itemsName + "' style='margin-left: 15px;" + displayFlg + "'>";
			for (jdx=0; jdx<subitems; jdx++) {
				mnuimg = this.imgSub;
				mnusub = "return true;";
				mnulbl = this.Items[idx][1][jdx][0];
				mnulnk = this.Items[idx][1][jdx][1];
				retValue += "<img align='absMiddle' src='" + mnuimg + "' border=0>&nbsp;";
				retValue += "<a href='" + mnulnk + "' target='" + this.lnkTarget + "' onClick='" + mnusub + "' class='" + stl[1] + "'>" + mnulbl + "</a><br>";
			}
			retValue += "</div>";
		}
	}
	return retValue;
}

function refreshMenu() {
	document.write("<div id='mnuRKdiv" + instances + "' ");
	if (useIE) document.write("style='font-size:11pt'");
	document.write(">");
	//if (useIE) document.write(this.getCodeIE());
	//if (useNN) document.write(this.getCodeNN());
    document.write(this.getCode());
	document.write("</div>");
}

