function DisplayTabs(sender)
{	
	if(sender != null)
	{
	var tab_childs = sender.CurrentTab.getElementsByTagName('span');
		for(var i = 0;i<tab_childs.length;i++)
		{
			if(tab_childs[i].className.indexOf("InactiveTabLeft") > -1)
			{
				tab_childs[i].className = tab_childs[i].className.replace('InactiveTabLeft','ActiveTabLeft');
			}
			else if(tab_childs[i].className.indexOf("InactiveTabInner ") >-1)
			{
				tab_childs[i].className = tab_childs[i].className.replace('InactiveTabInner','ActiveTabInner');
			}
			else if(tab_childs[i].className.indexOf("InactiveTabRight") >-1)
			{
				tab_childs[i].className = tab_childs[i].className.replace('InactiveTabRight','ActiveTabRight');
			}
		}	
		sender.CurrentTabContent.style.display = 'block';
	}
}

function ShowTab(new_tab,sender)
{
	if(sender != null )
	{	
		var tab_childs = sender.CurrentTab.getElementsByTagName('span');
			
		for(var i = 0;i<tab_childs.length;i++)
		{
			if(tab_childs[i].className.indexOf("ActiveTabLeft")> -1)
			{
				tab_childs[i].className = tab_childs[i].className.replace('ActiveTabLeft','InactiveTabLeft');
			}
			else if(tab_childs[i].className.indexOf("ActiveTabInner ")>-1)
			{
				tab_childs[i].className = tab_childs[i].className.replace( 'ActiveTabInner','InactiveTabInner');
			}
			else if(tab_childs[i].className.indexOf("ActiveTabRight")>-1)
			{
				tab_childs[i].className = tab_childs[i].className.replace('ActiveTabRight','InactiveTabRight');
			}
		}	

		sender.CurrentTabContent.style.display = 'none';		
		//change current tab and tab content		
		sender.CurrentTab = sender.Tabs[new_tab.getAttribute('index')];		
		sender.CurrentTabContent = sender.TabContents[new_tab.getAttribute('index')];	
		DisplayTabs(sender);
	}
}
	
function TabControl(container) {

this.Container = container;
this.CurrentTab = new Object();
this.CurrentTabContent = new Object();;
this.Tabs = new Array();
this.TabContents = new Array();	
var TabsCounter = 0;
var TabContentsCounter = 0;
var counter = 0;
var that = this;
	while(counter < this.Container.childNodes.length )
	{
		var temp = this.Container.childNodes[counter];
		if(temp != null && temp.className== 'Tab')
		{  		
			this.Tabs[TabsCounter] = temp;			
			if(temp.addEventListener)
			{ 
				temp.addEventListener("click",function(){ShowTab(this,that);},false); 							
			}
			else
			{
				temp.onclick = function(){ShowTab(this,that);};				
			}
			TabsCounter ++;		 
		}
		else if(temp != null && temp.className && temp.className.indexOf('TabContent') > -1)
		{
			this.TabContents[TabContentsCounter] = temp;
			TabContentsCounter ++;
		}
		counter ++;			
	}	
	this.CurrentTab = this.Tabs[0];  	
	this.CurrentTabContent = this.TabContents[0];		
	DisplayTabs(this);		
}

