var topTab = null;
var subTab = null;
var topOn = 0;
var bottomOn = 0;
var selectedTab = null;

function tabIn (tabName) {

	var thisTab = document.getElementById(tabName);
	var thisSubTab = document.getElementById(tabName + 'SubTab');
	selectedTab = getElementsByName_iefix("selectedTab","div")[0]

	topOn = 1;
	if (topTab) topTab.className = 'unselectedTab';
	topTab = thisTab;	
	thisTab.className = 'selectedTab';

	if (subTab) {
		subTab.style.display = 'none';
		subTab = null;
	}

	if (thisSubTab) {
		thisSubTab.style.display='inline';
		subTab = thisSubTab;
	}

	if (selectedTab && topTab != selectedTab)
		selectedTab.className = 'unselectedTab';
}
function tabOut () {
	topOn = 0;
	if (subTab) subClear();
	else {
		if (topTab) topTab.className = 'unselectedTab';
		if (selectedTab) selectedTab.className = 'selectedTab';
	}
}
function bottomIn () {
	bottomOn = 1;
}
function bottomOut () {
	bottomOn = 0;
	if (subTab) subClear();
}

function subClear () {
	setTimeout(function () {
		if (subTab && !topOn && !bottomOn) {
			subTab.style.display = 'none';
			subTab = null;
			if (topTab) topTab.className = 'unselectedTab';
			if (selectedTab) selectedTab.className = 'selectedTab';
		}
	}, 1000);
}

function getElementsByName_iefix(elementName, tagName) {
	if (!tagName) tagName = "*";
	var tags = document.getElementsByTagName(tagName);
	var elementArray = new Array();
	var attribute = null;
	for(var i = 0; i < tags.length; i++) {
		attribute = tags[i].getAttribute("name");
		if(attribute == elementName)
			elementArray.push(tags[i]);
	}
	return elementArray;
}
