function TabGroup( resultObjId, activeTabCSS, inactiveTabCSS )
{
	this.activeTabCSS = activeTabCSS;
	this.inactiveTabCSS = inactiveTabCSS;
	this.resultObjId = resultObjId;
	this.resultObj = document.getElementById( resultObjId );
	this.activeTab = null;
	this.counter = 0;
	this.tabs = Array();
	this.urls = Array();
	this.script_urls = Array();
}
TabGroup.prototype.addTab = function ( tabId, requestURL, isActive )
{
	if( !this.resultObj )
		return false;

	var tab = document.getElementById( tabId );
	if( !tab )
		return false;
	this.tabs[tabId] = tab;
	this.tabs[this.counter] = tabId;
	this.urls[tabId] = requestURL;
	this.counter ++;
	var lnk = tab.getElementsByTagName("A");
	if( lnk.length > 0 )
	{
		var l = lnk.length;
		for( var i=0; i<l; i++ )
		{
			lnk.item(i).onclick = function(){return false;};
		}
	}
	tab.onclick = function () {this.tabgroup.switchTab(this.id, false );}
	tab.tabgroup = this;
	if( isActive == true )
		this.activeTab = tabId;
}
TabGroup.prototype.switchTab = function ( tabId, reload )
{
	if( !this.tabs[tabId] )
		return false;
	if( this.activeTab == tabId && reload == false )
		return false;
	if( ajax.is_busy )
		return false;
	
	var tab = this.tabs[tabId];
	if( this.activeTab )
	{
		var activeTab = document.getElementById(this.activeTab);
		for( var property in this.inactiveTabCSS )
		{
			activeTab.style[property] = this.inactiveTabCSS[property];
			if( property == "color" )
			{
				var ch = activeTab.getElementsByTagName("A");
				var l = ch.length;
				for( var i=0; i<l; i++ )
					ch.item(i).style.color = this.inactiveTabCSS[property];
			}
		}
	}

	this.resultObj.innerHTML = "<div style='text-align: center; padding: 4px;'><img src='/images/loading2.gif' width='23' height='23' alt='Loading...'/></div>";
	ajax.ownedQuery( this.urls[tabId], this, '_setData', false );
	for( var property in this.activeTabCSS )
	{
		tab.style[property] = this.activeTabCSS[property];
		if( property == "color" )
		{
			var ch = tab.getElementsByTagName("A");
			var l = ch.length;
			for( var i=0; i<l; i++ )
				ch.item(i).style.color = this.activeTabCSS[property];
		}
	}
	tab.className = "inactiveTab";
	this.activeTab = tabId;

	return true;
}
TabGroup.prototype._setData = function ( respHTML ) 
{
	this.resultObj.innerHTML = respHTML;
	var scripts = this.resultObj.getElementsByTagName("SCRIPT");
	if( scripts && scripts.length > 0 )
	{
		var l = scripts.length;
		for(var i=0; i<l; i++ )
		{
			if( scripts.item(i).src )
			{
				var script = document.createElement("SCRIPT");
				script.setAttribute("type","text/javascript");
				script.setAttribute("src",scripts.item(i).src);
				this.resultObj.appendChild(script);
			}
		}
	}
	
	
	
	if( this.script_urls[this.activeTab] )
		for( var i in this.script_urls[this.activeTab] )
		{	
			var script = document.createElement("SCRIPT");
			script.setAttribute( "type", "text/javascript" );
			script.src = this.script_urls[this.activeTab][i];
			this.resultObj.appendChild(script);
		}
}
TabGroup.prototype.switchURL = function ( url )
{
	var prevUrl = this.urls[this.activeTab];
	this.urls[this.activeTab] = prevUrl+"&"+url;
	this.switchTab( this.activeTab, true );
	this.urls[this.activeTab] = prevUrl;
	
	return false;
}
TabGroup.prototype.addScript = function ( tabId, url )
{
	if( !this.script_urls[tabId] )
		this.script_urls[tabId] = Array();
	
	this.script_urls[tabId][this.script_urls[tabId].length] = url;
}

