function menu_hide_tabs() {
	var list = document.getElementById("tab_bar").getElementsByTagName("li");
	for(i=0;i<list.length;i++) {
		var anchor = list[i].getElementsByTagName("a")[0];
		if(anchor) {
			anchor.setAttribute("class","unselected");
			anchor.setAttribute("className","unselected"); // for IE
		}
	}
	var list = document.getElementById("sub_tabs").getElementsByTagName("ul");
	for(i=0;i<list.length;i++) {
		list[i].style.display="none";
	}
}

function menu_tabs_setup() {
	if(!document.getElementsByTagName) { return; }
	var anchors = document.getElementsByTagName("a");
	for(var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		var relAttribute = String(anchor.getAttribute("rel"));
		
		if(anchor.getAttribute("href") && (relAttribute.toLowerCase().match("menutrigger"))){
			anchor.onclick = function() {
				var nameAttribute = this.getAttribute("name") + "tab";
				// alert("onclick:"+nameAttribute);
				var thismenu = document.getElementById(nameAttribute);
				var anchorclass = this.getAttribute("class");
				menu_hide_tabs();
				if(thismenu) {
					thismenu.style.display="inline";
					if(anchorclass) {
						// alert(anchorclass);
						this.setAttribute("class","selected");
						this.setAttribute("className","selected"); // for IE
						// alert(this.getAttribute("className"));
					}
				// } else { alert("onclick:tab not found!");
				}
				// return false;
			}
		}
	}
}

function menu_tab_show(tab) {
	if(tab) {
		// alert("m_" + tab + "_tab");
		var thismenu = document.getElementById("m_" + tab + "_tab");
		if(thismenu) {
			// alert("found:"+"m_" + tab + "_tab");
			var anchors = document.getElementsByTagName("a");
			for(var i=0; i<anchors.length; i++){
				var anchor = anchors[i];
				var relAttribute = String(anchor.getAttribute("rel"));
				
				if(anchor.getAttribute("href") && (relAttribute.toLowerCase().match("menutrigger"))) {
					var nameAttribute = anchor.getAttribute("name")
					// if(nameAttribute.toLowerCase().match(tab)) {
					// alert("found:"+nameAttribute);
					
					if(nameAttribute.toLowerCase().match("m_"+tab+"_")) {
						// alert("matched:"+nameAttribute);
						anchor.setAttribute("class","selected");
						anchor.setAttribute("className","selected"); // for IE
						// menu_hide_tabs();
						if(thismenu) {
							thismenu.style.display="inline";
						}
					} else {
						anchor.setAttribute("class","unselected");
						anchor.setAttribute("className","unselected"); // for IE
					}
					/*
					if(nameAttribute.toLowerCase().match("m_"+tab+"_")
						anchor.setAttribute("class","selected");
						anchor.setAttribute("className","selected"); // for IE
						thismenu.style.display="inline";
					} else {
						
					}
					*/
				}
			}
			// return false;
		}
	}
}

function attach_event(obj,evt,fnc,useCapture){
	if(obj.addEventListener) {
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) {
		return obj.attachEvent("on"+evt,fnc);
	} else {
		obj["on"+evt]=fnc;
	}
	return true;
}

attach_event(window,'load',menu_tabs_setup,true);
