function CTabStrip(webPartQ)
{
	this.id = webPartQ;
	this.currentTabSelected = null;
	this.SetTabActive = SetTabActive;
	
	function SetTabActive(tabName)
	{
		if( this.currentTabSelected == tabName )
			return;
			
		if (this.currentTabSelected != null)
			this.setTabInactive(this.currentTabSelected);
			
		var oTab = getElByID(tabName + "Tab");
		var oTR = oTab.parentNode;			
		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.parentNode, "TR");
		var oTable = GetParentElementToTagName(oTRGlobalTab.parentNode, "table");
		if( oTable.rows.length > 0 && oTRGlobalTab.rowIndex < (oTable.rows.length -1) )
			oTable.moveRow(oTRGlobalTab.rowIndex,oTable.rows.length-1);
		
		
		var oDiv = getElByID(tabName+"Div");
		if (oDiv != null) {
			oDiv.className = "UserTabItemSel";
		}
		
		this.currentTabSelected = 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.parentNode;
		
		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();
var oWebpartTabStripCollection = new Collection();


function GetTabStrip(webPartQualifier)
{
	if( !oTabStripCollection ) return null;
	return oTabStripCollection.FindByID(webPartQualifier);
}

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);
	
	if (defaultTab)	{
		TabStrip.setTabActive(defaultTab);
		TabStrip_ChangeTab(webPartQualifier, 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);
	var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
	if( !oDiv ) return;
	
	var oPushIcon = document.getElementById("PushableItems" + webPartQualifier);
	if( oPushIcon )
		oPushIcon.style.visibility = (oDiv.IsPushable != '' && (oDiv.IsPushable == '1' || oDiv.IsPushable == '3') && oDiv.IsPushable != undefined )?'visible':'hidden';
		
	var oSendEmailIcon = document.getElementById("SendEmailItems" + webPartQualifier);
	if( oSendEmailIcon )
		oSendEmailIcon.style.visibility = (oDiv.IsPushable != '' && (oDiv.IsPushable == '2' || oDiv.IsPushable == '3') && oDiv.IsPushable != undefined )?'visible':'hidden';		
	
	var oPrintIcon = document.getElementById("PrintItems" + webPartQualifier);
	if( oPrintIcon )
		oPrintIcon.style.visibility = (oDiv.IsPrintable != '' && oDiv.IsPrintable != '0' && oDiv.IsPrintable != undefined )?'visible':'hidden';

	var oWebQueryIcon = document.getElementById("WebQueryItems" + webPartQualifier);
	if( oWebQueryIcon )
		oWebQueryIcon.style.visibility = (oDiv.IsWebQueriable != '' && oDiv.IsWebQueriable != '0' && oDiv.IsWebQueriable != undefined )?'visible':'hidden';

		
	var oDependentIcon = document.getElementById("DependentItems" + webPartQualifier);
	if( oDependentIcon )
		oDependentIcon.style.visibility = (oDiv.HasDependents != '' && oDiv.HasDependents != '0' && oDiv.HasDependents != undefined )?'visible':'hidden';	
		
	return;
	
}

function PrintCurrentTabStrip(webPartQualifier)
{
	
	var oTabStrip = null;
	
	oTabStrip = oTabStripCollection.FindByID(webPartQualifier);
	if( ! oTabStrip ) return;
	if( ! oTabStrip.currentTabSelected ) return;
	
	var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
	if( !oDiv ) return;
	
	OpenPrintDocument(oDiv.DocumentID,oDiv.DOCQualifier)
}

function PushCurrentTabStrip(webPartQualifier)
{
	
	var oTabStrip = null;
	
	oTabStrip = oTabStripCollection.FindByID(webPartQualifier);
	if( ! oTabStrip ) return;
	if( ! oTabStrip.currentTabSelected ) return;
	
	var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
	if( !oDiv ) return;
	
	OpenPushDocument(oDiv.DocumentID,oDiv.DOCQualifier);
	
}

function SendMailCurrentTabStrip(webPartQualifier)
{
	
	var oTabStrip = null;
	
	oTabStrip = oTabStripCollection.FindByID(webPartQualifier);
	if( ! oTabStrip ) return;
	if( ! oTabStrip.currentTabSelected ) return;
	
	var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
	if( !oDiv ) return;
	
	OpenSendMailDocument(oDiv.DocumentID,oDiv.DOCQualifier);
	
}


function WebQueryCurrentTabStrip(webPartQualifier)
{
	
	var oTabStrip = null;
	
	oTabStrip = oTabStripCollection.FindByID(webPartQualifier);
	if( ! oTabStrip ) return;
	if( ! oTabStrip.currentTabSelected ) return;
	
	var oDiv = getElByID(oTabStrip.currentTabSelected + "Div");	
	if( !oDiv ) return;
	
	GetWebQuery(oDiv.DOCQualifier,oDiv.DocumentID);
	
}



