﻿/* Function used for setting the visible tabs along with their contentes */
function SetVisibleTabs(level, tabId) {

	var currentTab = document.getElementById(tabId + 'currentTabTitleLevel' + level)
	var currentTabTitle = currentTab.value;

	var currentRootTabTitle = "";

	if (level > 1) 
	{
		var currentRootTab = document.getElementById(tabId + 'currentTabTitleLevel' + (level - 1));
		currentRootTabTitle = RemoveSpaces(currentRootTab.value);
	}

	var tabs = document.getElementById(tabId + 'tabsLevel' + level + currentRootTabTitle);

	if (tabs == null)
		return false;

	var ul = tabs.childNodes[0];
	
	var currentContentIdx = 0;
    
	//set list header 
	for (var i = 0; i < ul.childNodes.length; i++) {		
			ul.childNodes[i].style.display = "block";
			if (ul.childNodes[i].title == currentTabTitle) {
				SetAttribute(ul.childNodes[i], "class", "on");
				currentContentIdx = i;
			}
			else {
				SetAttribute(ul.childNodes[i], "class", "");
			}		
	}
    
	//set contents
	var divContents = tabs.childNodes[1];
	for (var i = 0; i < divContents.childNodes.length; i++) {
		if (i == currentContentIdx) {
			SetAttribute(divContents.childNodes[i], "class", "tab on");
		}
		else {
			SetAttribute(divContents.childNodes[i], "class", "tab");
		}
	}

	if (level <  2) {
		SetVisibleTabs(level + 1, tabId);
	}
}

/* Function used for setting an attribute value */
function SetAttribute(node, name, value) {
	var i;
	for (i = 0; i < node.attributes.length; i++) {
		if (node.attributes[i].name == name) {
			node.attributes[i].value = value;
		}
	}
}

/* Function used to remove spaces from string*/
function RemoveSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for (i = 0; i < splitstring.length; i++)
		tstring += splitstring[i];
	return tstring;
}

/*FIX for 'Click is not recognized in FireFox'*/
if (navigator.appName != "Microsoft Internet Explorer")
{
    HTMLElement.prototype.click = function() {
    var evt = this.ownerDocument.createEvent('MouseEvents');
    evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
    this.dispatchEvent(evt);
    } 
}
