﻿// JScript File
function TabHandler(name, ClientId, AutoPostBack, TabClickAction, TabType, DefaultTabCSS, ImageFolder)
{
	this.ClientId = ClientId;
	this.SelTabCtrl = getObj(ClientId + "hiddenSelectedTab");
	this.DataCtrl = getObj(ClientId + "hiddenTabData");
	this.name = name;
	this.id = name;
	this.disabled = false;
	this.TabData = new Array()
	var TabDataList = this.DataCtrl.value.split("|");
	this.TabNames = new Array();
	this.TabData = new Array();
	var SelectedTabName = this.SelTabCtrl.value.toLowerCase();
	for (var i=0; i< TabDataList.length; i++)
	{
		var subList = TabDataList[i].split("~");
		this.TabNames[i] = subList[0].toLowerCase();
		if (this.TabNames[i] == SelectedTabName)
		{
			this.SelectedIndex = i;
		}
		this.TabData[i] = subList[2];
	}
	this.Action = TabClickAction;
	this.tagName = "Tab";
	this.TabType = TabType;
	this.AutoPostBack = AutoPostBack;
	if (this.TabType != "Text")
	{
		this.ImageFolder = ImageFolder;
	}
	this.DefaultTabCSS = DefaultTabCSS;
}

TabHandler.prototype.MO = function(ClickTab, TabIndex, bMO)
{
	var TabName = this.TabNames[TabIndex].toLowerCase();
	if (this.disabled || this.SelectedIndex == TabIndex) return;
	if (this.TabType == "Text")
	{
		ClickTab.className = this.DefaultTabCSS + (bMO ? "_mo": "");
	}
	else
	{
		ClickTab.src = this.ImageFolder + this.name + TabName + (bMO ? "_mo" : "") + ".gif";
	}
}

TabHandler.prototype.TabClick = function(ClickTab, TabIndex)
{
	var TabName = this.TabNames[TabIndex].toLowerCase()
	if (this.disabled || this.SelectedIndex == TabIndex) return false;
	
	this.SelTabCtrl.value = TabName;
	
	if (this.Action == null)
	{
		Page.PopIn = false;
		if (this.AutoPostBack)
		{
			document.forms[0].submit();
		}
		else
		{
			window.top.location = this.TabData[TabIndex];
		}
	}
	else 
	{
		this.disabled = true;
		if (this.Action(TabName, TabIndex))
		{
			var PriorTab = DocAll(this.ClientId + this.SelectedIndex);
			if (this.TabType == "Text")
			{	
				PriorTab.className = this.DefaultTabCSS;
				ClickTab.className = this.DefaultTabCSS + "_sel";
			}
			else
			{
				PriorTab.src = this.ImageFolder + this.TabNames[this.SelectedIndex] + "." + this.TabType;
				ClickTab.src = this.ImageFolder + this.TabNames[TabIndex] + "_sel." + this.TabType;
			}
			this.SelectedIndex = TabIndex;
			if (this.AutoPostBack) document.forms[0].submit();
		}
		this.disabled = false;
	}
	return false;
}

TabHandler.prototype.Tab = function()
{
	return this.SelTabCtrl.value;
}

TabHandler.prototype.disable = function(bDisable)
{
	this.disabled = bDisable;
	for (var i=0; i< this.TabNames.length; i++)
	{
		if (i != this.SelectedIndex)
		{
			var Tab = DocAll(this.ClientId + i);
			if (this.TabType == "Text")
			{
				Tab.className = this.DefaultTabCSS + "_dis";			
			}
			else
			{
				Tab.src = this.ImageFolder + this.ClientId + this.TabNames[i] + (bDisable ? "_dis." : ".") + this.TabType;
			}
		}
	}
}