// =====================================================================================
// Switch Menu script - NS4/IE4 compatibility
// =====================================================================================

var persistmenu = "yes"; //"yes" or "no".
var persisttype = "sitewide"; //enter "sitewide" for menu to persist across site, "local" for this page only.

if (document.getElementById){ 
	document.write('<style type="text/css">\n');
	document.write('.subMenu{display: none;}\n');
	document.write('.selectPic{display: none;}\n');
	document.write('</style>\n');		
}

function SwitchMenu(obj, strId){

	if (document.getElementById) {

		var objElement  = document.getElementById(strId);
		var arrSpan     = document.getElementById("masterdiv").getElementsByTagName("span");
		var arrDiv      = document.getElementById("masterdiv").getElementsByTagName("div");
		var intCount    = strId.substring(3, 4);
		//var objElement2 = document.getElementById("selectpic" + intCount);
		
		for (var i = 0; i < arrDiv.length; i++) {
			if (arrDiv[i].className == 'mainMenuHover') {
				arrDiv[i].className = 'mainMenu';
			}
		}
		obj.className = 'mainMenuHover';

		if (objElement.style.display != "block"){ 
			for (var i = 0; i < arrSpan.length; i++){
				if (arrSpan[i].className == "subMenu" || arrSpan[i].className == "selectPic") {
					arrSpan[i].style.display = "none";
				}
			}
			objElement.style.display  = "block";
			document.getElementById('picture').src = imageDir + 'common/leftnav_bullet_on.gif';
		}
		else {
			objElement.style.display  = "none";
			document.getElementById('picture').src = imageDir + 'common/leftnav_bullet.gif';
		}
		
	}
}

function get_cookie(Name) { 

	var search      = Name + "=";
	var returnvalue = "";

	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);

		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);

			if (end == -1) {
				end = document.cookie.length;
			}	
			returnvalue = unescape(document.cookie.substring(offset, end));
		}
	}

	return returnvalue;
}

function onloadfunction() {

	if (persistmenu == "yes") {

		var cookiename  = (persisttype == "sitewide") ? "switchmenu" : window.location.pathname;
		var cookievalue = get_cookie(cookiename);

		if (cookievalue != "") {
			document.getElementById(cookievalue).style.display = "block";
			var intCount = cookievalue.substring(3, 4);
			//document.getElementById('picture').src = 'http://www.netzed.net/vendez/images/common/leftnav_bullet_on.gif';
			document.getElementById('picture').src = imageDir + 'common/leftnav_bullet_on.gif';
			//document.getElementById("selectpic" + intCount).style.display = "inline";
		}
	}
}

function savemenustate() {

	var intCount = 1
	var blockid  = "";

	while (document.getElementById("sub" + intCount)) {
		if (document.getElementById("sub" + intCount).style.display == "block") {
			blockid = "sub" + intCount;
			break;
		}
		intCount++;
	}

	//--Set Cookie[cookiename] = cookievalue
	var cookiename  = (persisttype == "sitewide") ? "switchmenu"        : window.location.pathname;
	var cookievalue = (persisttype == "sitewide") ? blockid + ";path=/" : blockid;
	document.cookie = cookiename + "=" + cookievalue;
}

if (window.addEventListener) { //-For Mozilla Firefox
	window.addEventListener("load", onloadfunction, false);
}
else if (window.attachEvent) { //-For IE
	window.attachEvent("onload", onloadfunction);
}
else if (document.getElementById) {
	window.onload = onloadfunction;
}

if (persistmenu == "yes" && document.getElementById) {
	window.onunload = savemenustate;
}