function clicker () {
	this.blur();
	if (!this.defStyle) this.defStyle = this.className;
	this.state = (this.state=="none")?"block":"none";
	var UL = this.parentNode.getElementsByTagName("UL")[0];
	if (UL) UL.style.display = this.state;
	if (this.state=="none") {
		this.parentNode.className = this.defStyle+" closedMenuBranch";
	}
	else {
		this.parentNode.className = this.defStyle+" openedMenuBranch";
	}
	return false;
}

function recurse (elem) {
	var lis=elem.childNodes;
	for (var i=0; i<lis.length; i++) {
		if (lis[i].tagName=="LI") {
			var UL = lis[i].getElementsByTagName("UL")[0];
			var A = lis[i].getElementsByTagName("A")[0];
			if (A) A.className += " closedMenuBranch";
			if (UL) {
				A.onclick = clicker;
				A.onclick();
				recurse (UL);
			}
		}
	}
}

function menuMaker(elem) {
	if (!elem) return;
	var menu=document.getElementById(elem);
	if (!menu) return;

	nmMenuObj = menu;

	menu.style.display = "none";

	recurse(menu);

	menu.style.display = "block";

	var href=window.location.toString();

	if ((x=(href.indexOf("?")))<=0) return;
	href = trim(href.substring(x,href.length));

	//if (x=(href.indexOf("&"))) href = href.substring(0,x);

	if (href=="") return;
	if ((x=(href.indexOf("&")))>0) href=href.substring(0,x);
	var As = menu.getElementsByTagName('A');
	for (var i=0; i<As.length; i++) {
		href2=trim(As[i].href);
		if (x=href2.indexOf("?")) {
			href2 = href2.substring(x,href2.length);
			if (href==href2) {
				var parent=As[i].parentNode;
				while (parent!==menu) {
					parent=parent.parentNode;
					if ((parent.tagName=="LI")&&(A=parent.getElementsByTagName("A")[0])) {
						if (A.onclick) A.onclick();
					}
				}
			}
		}
	}
}

function mopen(elem, href) {
	if (!elem) return;
	var menu=document.getElementById(elem);
	if (!menu) return;
	
	if (href=="") return;
	if ((x=(href.indexOf("&")))>0) href=href.substring(0,x);
	var As = menu.getElementsByTagName('A');
	for (var i=0; i<As.length; i++) {
		href2=trim(As[i].href);
		if (x=href2.indexOf("?")) {
			href2 = href2.substring(x,href2.length);
			if (href==href2) {
				//alert(As[i].state == "none");
				if (As[i].state == "none" && As[i].onclick) As[i].onclick();
			}
		}
	}
}

function trim(s) {
  return rtrim(ltrim(s));
}

function ltrim(s) {
  return s.replace(/^\s+/, '');
}

function rtrim(s) {
  return s.replace(/\s+$/, '');
}
//menuMaker("mainMenu");