/*********************************************************
 *
 * File:	nwc_panel.js
 * Created: 22-01-2003
 *
 * Copyright 2003 Naviga GmbH
 *
 */

 /**********************************************************
 * Tabpane
 */

function clickTab(val) {
	if (val == null)
		return;
		
	if (typeof val == "string") {
		submitForm(val);
	} else {
		var tab = val;

		var tabPage = document.getElementById(getTabPageId(tab));
		if (tabPage == null)
			return;

		var selTab = getSelectedTab(tab.parentNode);
		if (selTab == null)
			return;
 
		var selTabPage = document.getElementById(getTabPageId(selTab));
		if (selTabPage == null)
			return;

		selTab.className = "tab";
		selTabPage.style.display = "none";
	
		tab.className = "tab selected";
		tabPage.style.display = "block";
	}
}

function mouseOverTab(toEl) {
	var fromEl = window.event.fromElement;
	if (toEl == fromEl || toEl == null) 
		return;
	
	var className = toEl.className;
	if (/selected/.test(className))
		return;

	toEl.className = className + " hover";
}

function mouseOutTab(fromEl) {
	var toEl = window.event.toElement;
	if (toEl == fromEl || fromEl == null) 
		return;	

	var className = fromEl.className;	
	fromEl.className = className.replace(/ hover/, "");
}
 
function getSelectedTab(el) {
	if (el == null)
		return null;

	var childNodes = el.childNodes;
	for (var i = 0; i < childNodes.length; ++i) {
		var cur = childNodes[i];
		if (/selected/.test(cur.className))
			return cur;
	}
	return null;
}

function getTabPageId(el) {
	var id = el.id;
	return id.replace(/tab_/, "");
}

