/* TAB OBJECT */
function tab(oTabHead, oTrak, oBody, oBottom, oVisible)
{
	this.tabHead = oTabHead;
	this.trak = oTrak;
	this.body = oBody;
	this.bottom = oBottom;
	this.visible = oVisible;
	this.show = function(){
		if(!this.visible){
			this.tabHead.className+=" selected";
			this.trak.className = this.trak.className.replace(/ hide/,"");
			this.body.className = this.body.className.replace(/ hide/,"");
			this.bottom.className = this.bottom.className.replace(/ hide/,"");
			this.visible=true;
		}
	}
	this.hide = function(){
		if(this.visible){
			this.tabHead.className = this.tabHead.className.replace(/ selected/,"");
			this.trak.className+= " hide";
			this.body.className+= " hide";
			this.bottom.className+= " hide";
			this.visible=false;
		}
	}
}

/* TAB LIST OBJECT */
function tabList(selTab)
{
	this.tabs = new Array();
	this.selectedIndex = selTab<0 ? 0 : selTab;
	this.addTab	= function(oTabHead, oTrak, oBody, oBottom, oVisible){
		this.tabs.push(new tab(oTabHead, oTrak, oBody, oBottom, oVisible));
	}
	this.init = function(tableId)
	{
		var tabTable = document.getElementById(tableId);
		if(tabTable==null) return;
		
		// find all tabs
		var tabs = tabTable.getElementsByTagName("TH");
		
		var trs = tabTable.getElementsByTagName("TR");
		var traks = new Array();
		var bodys = new Array();
		var bottoms = new Array();
		
		for(var i=0; i<trs.length; i++)
		{
			if(trs[i].className.indexOf("trak_")!=-1)
			{
				traks.push(trs[i]);
				continue;
			}
			if(trs[i].className.indexOf("body_")!=-1)
			{
				bodys.push(trs[i]);
				continue;
			}
			if(trs[i].className.indexOf("bottom_")!=-1)
			{
				bottoms.push(trs[i]);
				continue;
			}
		}
		
		if( tabs.length == traks.length && tabs.length == bodys.length && tabs.length == bottoms.length){				
			for(var i=0; i<tabs.length; i++)
				if(this.selectedIndex>tabs.length-1 && i==0)
					this.addTab(tabs[i], traks[i], bodys[i], bottoms[i], true);
				else
					this.addTab(tabs[i], traks[i], bodys[i], bottoms[i], i==this.selectedIndex);
		}
	}
	this.changeTab = function(index){
		if(this.selectedIndex==index) return;
		
		this.selectedIndex=index;
		
		// change visibility for other tabs
		for(var i=0; i<this.tabs.length; i++)
		{ 
			if(i==this.selectedIndex)
				this.tabs[i].show();
			else
				this.tabs[i].hide();
		}
	}
}
