function CTabStrip(webPartQ)
{
	this.id = webPartQ;
	this.currentTabSelected = null;
	this.previousTabSelected = null;
	
	function SetTabActive(tabName)
	{
		if( this.previousTabSelected == tabName )
			return;
			
		if (this.previousTabSelected != null)
			this.setTabInactive(this.previousTabSelected);
			
		var oTab = getElByID(tabName + "Tab");
		var oTR = oTab.parentElement;			
		if (oTab != null) {
			if ((oTab.cellIndex-1)>=0)
				oTR.cells[oTab.cellIndex-1].className = "UserTabNavItemSel";
			oTR.cells[oTab.cellIndex].className   = "UserTabNavItemSel";
			if ((oTab.cellIndex+1)<=oTR.cells.length)
				oTR.cells[oTab.cellIndex+1].className = "UserTabNavItemSel";
		}
		
		var oTRGlobalTab = GetParentElementToTagName(oTR.parentElement, "TR");
		var oTable = GetParentElementToTagName(oTRGlobalTab.parentElement, "table");
		if( oTable.rows.length > 0 && oTRGlobalTab.rowIndex < (oTable.rows.length -1) )
			oTable.moveRow(0,oTable.rows.length);
		
		
		var oDiv = getElByID(tabName+"Div");
		if (oDiv != null) {
			oDiv.className = "UserTabItemSel";
		}
		
		this.previousTabSelected = tabName;
		
		if( RaiseEvent != undefined )
		{
			var oObjectEvent = new Object();
			oObjectEvent.TabName = tabName;
			oObjectEvent.DocumentID = oDiv.DocumentID;
			oObjectEvent.DocumentQualifier = oDiv.DOCQualifier;
			oObjectEvent.WebpartQualifier = this.id;
				
			RaiseEvent("www.activportal.mc:WebpartTabStrip","TabActivated",oObjectEvent);
		}
	}
	
	function SetTabInactive(tabName)
	{
		
		var oTab = getElByID(tabName+"Tab");
		var oTR = oTab.parentElement;
		
		if (oTab != null) {
			if ((oTab.cellIndex-1)>=0)
				oTR.cells[oTab.cellIndex-1].className = "UserTabNavItem";
			oTR.cells[oTab.cellIndex].className   = "UserTabNavItem";
			if ((oTab.cellIndex+1)<=oTR.cells.length)
				oTR.cells[oTab.cellIndex+1].className = "UserTabNavItem";
		}

		var oDiv = getElByID(tabName+"Div");
		if (oDiv != null) {
			oDiv.className = "UserTabItem";
		}
	}
	
	this.setTabActive = SetTabActive;
	this.setTabInactive = SetTabInactive;	
	
}

var oTabStripCollection = new Collection();

function RegisterTabStrip(webPartQualifier,defaultTab)
{
	var index;
	var TabStrip;
	
	index = oTabStripCollection.FindIndexByID(webPartQualifier);
	if( index >= 0 )
		return oTabStripCollection.Item(index);
	TabStrip = new CTabStrip(webPartQualifier);
	oTabStripCollection.Add(TabStrip);
	
	TabStrip.setTabActive(defaultTab);
	
	
	/*var oHTMLTabStrip = getElByID(webPartQualifier + "TabStrip");
	var iRow = 0;
	var iCol = 0;
	var oDiv
	var oWP
	
	for( iRow=0; iRow<oHTMLTabStrip.rows.length;iRow++)
	{
		alert(oHTMLTabStrip.rows[iRow].cells.length);
		for( iCol=0; iCol<oHTMLTabStrip.rows[iRow].cells.length; iCol++)
		{
			oTab = oHTMLTabStrip.rows[iRow].cells[iCol];
			if( oTab.DOCQualifier != undefined )
			{
				oWP = GetWebPart(webPartQualifier);
				sHeight = oWP.style.height + '';
				oDiv = getElByID(oTab.DOCQualifier + "Div");
				alert(sHeight);
				if( sHeight != '' && !sHeight.search(/%/i) )
				{
					oDiv.style.Height = sHeight - oTab.offsetHeight;
				}
			
			}
		}
	}*/
		
	
	

	return TabStrip;	
}

function TabStrip_ChangeTab(webPartQualifier, TabName )
{
	var oTabStrip = null;
	
	oTabStrip = oTabStripCollection.FindByID(webPartQualifier);
	if( ! oTabStrip ) return;
	
	oTabStrip.setTabActive(TabName);
}

