/*
 *
 * 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
 *
 *	modified by A H O <abdul.othman@i-to-i.com>
 *	to fix with new homepage layout (placement view)
 *	16/10/2008
 *
 */
 
 	// called by onclick event
	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;	// 2nd <li>
				var childrenTop1 = childrenTop[k].childNodes;
				for(var k1=0; k1<childrenTop1.length; k1++) {
					if(childrenTop1[k1].nodeType === 1) {
						//childrenTop1[k1].className = standardTabClass;	// 2nd <ul> 
						var childrenTop2 = childrenTop1[k1].childNodes;
						for(var k2=0; k2<childrenTop2.length; k2++) {
							if(childrenTop2[k2].nodeType === 1) {
								childrenTop2[k2].className = standardTabClass;	// last <li>
							}
						}				
					}
				}				
			}
		}

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

	// called by onmouseover & onmouseout event
	// to fixed with new css state
	function changeState(tabId, stateType) {
		if (thisTab = document.getElementById(tabId)) {
			var positionOfBreak = thisTab.className.indexOf('-'+stateType);
			
			if(thisTab.className.indexOf('active')<0) {
				if(positionOfBreak==-1) {					
					thisTab.className = thisTab.className + "-" +stateType;
				}
				else {
					thisTab.className = thisTab.className.substring(0, positionOfBreak );
				}
			}
		}
	}
