/*
 *
 * Tab Control JavaScript
 * v1.1 dan.murray@i-to-i.com
 * 09/05/2007
 *
 * Import this JS file and:
 * Requires the following vars in the document.
 * standardTabClass = "tab" - the class name of a default-state tab
 * tabHoldingUl = "tabArea" - The UL holding the tab LI's
 *
 *	more stuff added by A H O <abdul.othman@i-to-i.com>
 *	28/02/2008
 *
 */

	function toggleTab ( tabId ) {
		var thisTab = document.getElementById(tabId);
		if(thisTab.style.display=="none") {
			thisTab.style.display = "block";
		}
		else {
			thisTab.style.display = "none";
		}
	}

	function changeState( tabId, stateType) {
		var thisTab = document.getElementById( tabId );
		var positionOfBreak = thisTab.className.indexOf(' '+stateType);

		if(thisTab.className.indexOf('active')<0) {
		//if(thisTab.className.indexOf(stateType)<0) {
			if(positionOfBreak==-1) {
				thisTab.className = thisTab.className + " " +stateType;
			}
			else {
				thisTab.className = thisTab.className.substring(0, positionOfBreak );
			}
		}
	}

	function selectTab( tabBodyId, makeActiveTab, tabToShow ) {
		var containerDiv = document.getElementById(tabBodyId);
		var childrenNodes = containerDiv.childNodes;

		for(var i=0; i<childrenNodes.length; i++) {
			if(childrenNodes[i].nodeType === 1)	{
				if(childrenNodes[i].getAttribute('id').indexOf('tabContent')!=1) {
					childrenNodes[i].style.display='none';
				}
			}
		}

		// Now sort out the tabs
		var childrenTop = document.getElementById(tabHoldingUl).childNodes;
		for(var k=0; k<childrenTop.length; k++) {
			if(childrenTop[k].nodeType === 1) {
				childrenTop[k].className = standardTabClass;
			}
		}

 		changeState(makeActiveTab, "active");
 		document.getElementById(tabToShow).style.display='block';
	}

	// ------------------- enhancement -------------- //

	// css class switcher
	function switchCssState(tabHoldingUl,standardTabClass,makeActiveTab,activeTabClass) {
		var childrenTop = document.getElementById(tabHoldingUl).childNodes;

		for(var k=0; k<childrenTop.length; k++) {
			if(childrenTop[k].nodeType === 1) {
				childrenTop[k].className = standardTabClass;
			}
		}
 		changeState(makeActiveTab,activeTabClass);
	}
