var AltaTabRegisters = Array();

function AltaTab(instanceName, active, tabs, isPopup, extend, heightnoset, noCookie)
{
	this.Change = function(active) {
		this.Active = (active ? parseInt(active) : 0);
		this.updateCookie();
		if(this.Tabs[this.Active][3]) 
		{
			window.location.href=this.Tabs[this.Active][3];
		}
		else
		{
			this.Render();
		}
	}
	
	this.Intilize = function() 
	{
		obj_btn = document.getElementById("Holder_" + this.InstanceName);
		if(!this.HeightNoSet) obj_btn.style.height = "100%";
		if(obj_btn)
		{
			var TOPTabRender = this.GetTOPTabRender();
			var RIGHTTabRender = this.GetRIGHTTabRender();
			
			var ret = "";
			ret += "<table width='100%' height='100%' cellpadding='0' cellspacing='0' border='0'>";
				ret += "<tr>";
					if(RIGHTTabRender != "" ) ret += "<td></td>";
					ret += "<td valign='bottom' height='1'>";
						ret += "<div id='TT_" + this.InstanceName + "'>" + TOPTabRender + "</div>";
					ret += "</td>";
					//if(this.Extend) ret += "<td align='right' valign='middle'>" + this.Extend + "</td>";
				ret += "</tr>";
				ret += "<tr>";
					if(RIGHTTabRender != "" ) ret += "<td valign='top' align='right'><div id='TR_" + this.InstanceName + "' style='height:100%'>" + this.GetRIGHTTabRender() + "</div></td>";
					ret += "<td valign='top' width='100%' height='100%' >";//" + (this.Extend ? "colspan='2'" : "") + "
						ret += "<table border='0' width='100%' height='100%' class='tab_bB tab_bR' cellpadding='0' cellspacing='0'>";
							ret += "<tr>";
								ret += "<td class='tab_C n' width='100%' height='100%' valign='top'>";//" + (this.Extend ? "tab_CGradient " : "") + "
									ret += "<div class='n' id='TC_" + this.InstanceName + "'>";
				
			//obj_btn.innerHTML = ret + obj_btn.innerHTML;
			var rret = "";
									
									rret += "</div>";
								rret += "</td>";
							rret += "</tr>";
						rret += "</table>";
					rret += "</td>";
				rret += "</tr>";
			rret += "</table>";
			
			obj_btn.innerHTML = ret + obj_btn.innerHTML + rret;
			//obj_btn.innerHTML += ret;
		}	
	}
	
	this.Render = function() 
	{
		//"TC_" + this.InstanceName - PLACEHOLDER
	
		for(var i=0;i<this.Tabs.length;i++)
		{
			var obj = document.getElementById(this.Tabs[i][0]);
			if(obj) obj.className="tab_NV";
		}
				
		var obj = document.getElementById(this.Tabs[this.Active][0]);
		if(obj) obj.className="";
		
		/*
		var obj_TT = document.getElementById("TT_" + this.InstanceName);
		if(obj_TT) obj_TT.innerHTML = this.GetTOPTabRender();
		
		var obj_TR = document.getElementById("TR_" + this.InstanceName);
		if(obj_TR) obj_TR.innerHTML = this.GetRIGHTTabRender();
		*/
		for(var i=0;i<this.Tabs.length;i++)
		{
			if(i == this.Active)
			{
				if(GetObject("d_p1_"+this.Active+this.InstanceName)) GetObject("d_p1_"+this.Active+this.InstanceName).className="tab_A tab_AT";
				if(GetObject("d_p2_"+this.Active+this.InstanceName)) GetObject("d_p2_"+this.Active+this.InstanceName).className="tab_A tab_AT";	
			}
			else
			{
				if(GetObject("d_p1_"+i+this.InstanceName)) GetObject("d_p1_"+i+this.InstanceName).className="tab_NA";
				if(GetObject("d_p2_"+i+this.InstanceName)) GetObject("d_p2_"+i+this.InstanceName).className="tab_NA";
			}
		}
		
	}
	
	this.GetTOPTabRender = function ()
	{
		var temp_ret = this.GetTabRender(1);
		var ret = "";
		//if(temp_ret != "")
		//{
			ret += "<table border='0' width='100%' height='1' cellpadding='0' cellspacing='0' class='tab'>";
				ret += "<tr>";
					ret += temp_ret;
					ret += "<td width='100%' class='tab_bB'>&nbsp;</td>";
					if(this.Extend)
					{
						ret += "<td align='right' class='tab_bB'><nobr>" + this.Extend + "</nobr></td>";
					}
				ret += "</tr>";
			ret += "</table>";
		//}
		return ret;
	}
	
	this.GetRIGHTTabRender = function ()
	{
		var temp_ret = this.GetTabRender(2);
		var ret = "";
		//if(temp_ret != "")
		//{
			ret += "<table border='0' height='100%' cellpadding='0' cellspacing='0' class='tab'>";
				ret += "<tr><td class='tab_bR'>&nbsp;</td></tr>";
				ret += temp_ret;
				ret += "<tr><td height='100%' class='tab_bR'>&nbsp;</td></tr>";
			ret += "</table>";
		//}
		return ret;
	}
	
	this.GetTabRender = function (possition)
	{
		var ret = "";
		for(var i=0;i<this.Tabs.length;i++)
		{						
			if(this.Tabs[i][2] == possition)
			{
				if(possition == 1)
				{
					//if(i == this.Active) ret += "<td class='tab_bB' valign='bottom'>&nbsp;</td><td valign='bottom'><div class='tab_A tab_AT'>" + this.Tabs[i][1] + "</div></td>";
					//else 
					ret += "<td class='tab_bB' valign='bottom'>&nbsp;</td><td valign='bottom'><div id='d_p1_" + i + this.InstanceName + "' class='tab_NA' onclick='" + this.InstanceName + ".Change(" + i + ");' onmouseover='" + this.InstanceName + ".over(this,\"T\");' onmouseout='" + this.InstanceName + ".out(this," + i + ");'>" + this.Tabs[i][1] + "</div></td>";
				}
				else if(possition == 2)
				{
					//if(i == this.Active) ret += "<tr><td class='tab_bR'></td></tr><tr><td><div class='tab_A tab_AL'>" + this.Tabs[i][1] + "</div></td></tr>";
					//else 
					ret += "<tr><td class='tab_bR'></td></tr><tr><td><div id='d_p2_" + i + this.InstanceName + "'class='tab_NA' onclick='" + this.InstanceName + ".Change(" + i + ");' onmouseover='" + this.InstanceName + ".over(this,\"L\");' onmouseout='" + this.InstanceName + ".out(this," + i + ");'>" + this.Tabs[i][1] + "</div></td></tr>";
				}
			}
		}
		return ret;
	}
	
	this.over = function (obj,prefix)
	{
		obj.className = "tab_A tab_A" + prefix;
		obj.style.cursor = "pointer";
	}
	
	this.out = function (obj,i)
	{
		if(i != this.Active) obj.className = "tab_NA";
	}
	
	this.getSelected = function() {
		var sn = getCookie('gt' + this.InstanceName);
		return (sn) ? sn : null;
	};
	
	this.updateCookie = function() {
		if(this.NoCookie==0) setCookie('gt' + this.InstanceName, this.Active);
	};
	
	AltaTabRegisters[instanceName] = isPopup ? 1 : 0;
		
	this.InstanceName = instanceName;
	this.Tabs = tabs;
	this.NoCookie = noCookie ? 1 : 0;
	this.Active = (this.NoCookie==1) ? active : (this.getSelected() != null ? this.getSelected() : active);
	if(this.Active >= this.Tabs.length) this.Active = active;
	this.Extend = extend;
	this.HeightNoSet = heightnoset;	
	this.Intilize();	
	this.Render();	
	this.updateCookie();
}

var PopupTabs = Array();
function ShowPopupTab(obj)
{
	var insID = obj.id.replace("_btn","");
	var tObj = GetObject("Holder_" + insID + "_tab");
	
	//for html editor
	if(GetObject(insID + "___Frame")) insID = insID + "___Frame";
	if(tObj.style.display == "none")
	{
		if(!PopupTabs[tObj.id])
		{
			var txtObj = GetObject(insID);
			tObj.style.position = "absolute";
			tObj.style.width = cmGetWidth(txtObj);
			tObj.style.top = cmGetY(txtObj) + cmGetHeight(txtObj);
			tObj.style.left = cmGetX(txtObj);
			PopupTabs[tObj.id] = true;
		}
		ShowPopupEffect(tObj);
	}
}

/*
HOW TO 

<div id="Holder_AltaTab1">
	<div id="tab1" class="tab_NV">
		sdA<Vsa><br>sadvsa<br>
	</div>
	<div id="Div2" class="tab_NV">
		SDAfva fgte 4egh bte<br>fsdagvwds sd<br>d
	</div>
</div>
<script language="javascript">
	var mTabArray = [['tab1','ALTANET','1'],['Div2','ALTANET1','1'],['tab1','ALTANET','2'],['Div2','ALTANET1','2']];	
	var AltaTab1 = new AltaTab("AltaTab1",0,mTabArray);
</script>

*/
