///Public varirables
var contanerIdCollection	= new Array();
var tabIdCollection			= new Array();

function fn_collectTabs(strActiveTab)
{
	try
	{
		if(document.getElementById("content-container") != null)
		{
			 var divCC		= document.getElementById("content-container");
			 
			 var divCCElm	= divCC.getElementsByTagName("div");
			 var foundFirstContainer = (strActiveTab.length == 0) ? false : true;
			 var divPostBackElm	= "";
			 //contanerIdCollection = new Array(divCCElm.length)
			 
			 
			 for(var i=0;i<divCCElm.length;i++)
			 {
				if(divCCElm[i].className.indexOf("tabMenu") > -1) 
				{
					for(var j=0; divCCElm[i].getElementsByTagName("li").length > j; j++)
					{
						if(divCCElm[i].getElementsByTagName("li")[j] != null)
						{		
							tabIdCollection.push(divCCElm[i].getElementsByTagName("li")[j].id);
						}
					}
				}
						
				if(divCCElm[i].className.indexOf("tabContainer") > -1)
				{
					contanerIdCollection.push(divCCElm[i].id);
					
					if(document.getElementById("tab" + divCCElm[i].id.slice(5)) != null)
					{
						document.getElementById("tab" + divCCElm[i].id.slice(5)).className = "";
					}
					
					if(!foundFirstContainer || divCCElm[i].id == strActiveTab)
					{
						divCCElm[i].className	= divCCElm[i].className.replace("tabHide", "");
						foundFirstContainer		= true;
						
						document.getElementById("tab" + divCCElm[i].id.slice(5)).className = "current";
						
						///if it's the last tab hide save & Continue
						if(document.getElementById("ctrlSaveAndContinue") != null)
						{
							document.getElementById("ctrlSaveAndContinue").style.display = ("divTC" + tabIdCollection[(tabIdCollection.length-1)].slice(3) == divCCElm[i].id) ? "none" : "";
						}
					}
				}
			}
		}
	}
	catch(e)
	{
		alert(e.message);
	}
}

function fn_activateNextTab()
{
	try
	{
		///the reason I’m using tabIdCollection instead of contanerIdCollection
		///is that the customer rearranged the order of tabs and it’s easier to 
		///change the tabs hen of all containers
		var activeTab		= document.getElementById("txtTabViewState");
		var foundActiveTab	= false;
		for(i=0; tabIdCollection.length > i; i++)
		{
			if	(
					(foundActiveTab == false && activeTab.value.length == 0 && i==0)
				||	(activeTab.value == "divTC" + tabIdCollection[i].slice(3))
				)
			{
				foundActiveTab	= true;
			}
			else if(foundActiveTab)
			{
				activeTab.value = "divTC" + tabIdCollection[i].slice(3);				
				break;
			}
		}
	}
	catch(e)
	{
		alert(e.meassge)
	}
}

function fn_displayTab(containerId, linkEl)
{
	try
	{
		if(contanerIdCollection.length > 0)
		{
			///loop all contentConationers
			for(var i=0; i<contanerIdCollection.length; i++)
			{
				document.getElementById(contanerIdCollection[i]).className = (containerId == contanerIdCollection[i] ? "" : "tabHide")
				if(containerId == contanerIdCollection[i])
				{
					document.getElementById("txtTabViewState").value = containerId;
				}
			}
			
			if(document.getElementById("txtTabViewState") != null)
			{
				document.getElementById("txtTabViewState").value = containerId;
			}
		}

		if(linkEl.parentNode.parentNode.tagName.toLowerCase() == "ul")
		{
			for(var i=0; i<linkEl.parentNode.parentNode.childNodes.length; i++)
			{
				linkEl.parentNode.parentNode.childNodes[i].className = "";
			}
			linkEl.parentNode.className = "current";
		}
		
		///if it's the last tab hide save & Continue
		if(document.getElementById("ctrlSaveAndContinue") != null)
		{
			document.getElementById("ctrlSaveAndContinue").style.display = ("divTC" + tabIdCollection[(tabIdCollection.length-1)].slice(3) == containerId) ? "none" : "block";
		}

	}
	catch(e)
	{
		alert(e.message);
	}
}
