// JavaScript Document
var idTabSelected = new String();

function setMouseOverColor() {
	this.style.backgroundColor = "#33FFFF";
}
function setMouseOutColor() { // simulate CSS hover state
	if (this.id == idTabSelected) {
		this.style.backgroundColor = "#339999";
	} else {
		this.style.backgroundColor = "#66CCCC";
	}
}
function setMouseDownColor() { // simulate CSS active state
	if (this.id != idTabSelected) {
		this.style.backgroundColor = "#339999";
	}
}

function InitTabbedBlocks() {
	// assign mouse actions to tabs
	var allTabs = document.getElementsByTagName("a");  
	for (var i=0; i<allTabs.length; i++) {
		if (allTabs[i].id.match("Tab")) {
			if ((idTabSelected == "") && (allTabs[i].className == "")) { // set first tab as default tab
				idTabSelected = allTabs[i].id;
				allTabs[i].style.backgroundColor = "#339999";
			}
			if (allTabs[i].id == allTabs[i].className) { // check current tab selection from php script
				idTabSelected = allTabs[i].id;
				allTabs[i].style.backgroundColor = "#339999";
			}
			allTabs[i].onclick = SelectTabbedBlock;
			allTabs[i].onmouseover = setMouseOverColor;
			allTabs[i].onmouseout = setMouseOutColor;
			allTabs[i].onmousedown = setMouseDownColor;
		}
	}
	// set default div.display attribute
	var allDivs = document.getElementsByTagName("div");
	var matchFound = false;
	for (var i=0; i<allDivs.length; i++) {
		if (allDivs[i].id.match("TabContent")) {
			if (allDivs[i].id.match(idTabSelected)) {
				allDivs[i].style.display = "block";
			} else {
				allDivs[i].style.display = "none";
			}
			matchFound = true;
		}
	}
	if (!matchFound) {
		document.getElementById("TabbedMenuBarBorder").style.display = "none";
		return false;
	}
}

function SelectTabbedBlock() {
	// display selected block and hide all other blocks
	var allDivs = document.getElementsByTagName("div");
	var blockFound = false;
	for (var i=0; i<allDivs.length; i++) {
		if (allDivs[i].id.match("TabContent")) {
			if (allDivs[i].id.match(this.id)) { // match tab label to block label
				allDivs[i].style.display = "block";
			} else {
				allDivs[i].style.display = "none";
			}
			blockFound = true;
		}
	}
	if (!blockFound) {
		history.back();
		return false;
	}
	// set color of selected tab and reset all other tabs
	var allTabs = document.getElementsByTagName("a");  
	for (var i=0; i<allTabs.length; i++) {
		if (allTabs[i].id.match("Tab")) {
			if (allTabs[i].id == this.id) {
				allTabs[i].style.backgroundColor = "#339999";
			} else {
				allTabs[i].style.backgroundColor = "#66CCCC";
			}
		}
	}
	
	idTabSelected = this.id;
	return false;
}

addOnload(InitTabbedBlocks);
