﻿
if(!Sollers) var Sollers = {};
Sollers.ClTabs = Class.create();

Sollers.ClTabs.prototype =
{
    initialize : function(tabPanelId, tabNames, contentPanelIds, activateHandlers, deactivateHandlers, selectedTabName)
    {
        this.tabPanelId = tabPanelId;
        this.tabRow = GetChildElement(GetChildElement(GetChildElement($(tabPanelId),0),0),0);
        this.tabNames = tabNames;
        this.activateHandlers = activateHandlers;
        this.deactivateHandlers = deactivateHandlers;
        this.contentPanels = new Array();
        var i;
        for(i=0;i<contentPanelIds.length;i++) this.contentPanels[i] = $(contentPanelIds[i]);
        this.selectedTabName = GetCookie(tabPanelId, '');
        if (selectedTabName && (selectedTabName != '')) this.selectedTabName = selectedTabName;
        if ((this.selectedTabName == '')&&(this.tabNames.length > 0)) this.selectedTabName = this.tabNames[0];
        this.SelectTab(this.selectedTabName);
    },
    dispose : function()
    {
    },
    SelectTab : function(tabName)
    {
        if ((tabName == '')||(this.tabNames.length <= 0)) return;
        var i;
        var j = -1;
        for(i=0;i<this.tabNames.length;i++)
        {
            if (tabName != this.tabNames[i])
            {
                if (this.deactivateHandlers && (this.deactivateHandlers.length > 0)) this.deactivateHandlers[i]();
                this.contentPanels[i].style.display = 'none';
                var cell = GetChildElement(this.tabRow,1+i*3+0);
                cell.className = 'TabLeft';
                cell = GetChildElement(this.tabRow,1+i*3+1);
                cell.className = 'TabCenter';
                cell = GetChildElement(this.tabRow,1+i*3+2);
                cell.className = 'TabRight';
            }
            else j = i;
        }
        if ((j < 0)&&(this.tabNames.length > 0))
        {
            j = 0;
            tabName = this.tabNames[j];
        }
        if (j >= 0)
        {
            this.contentPanels[j].style.display = '';
            if (this.activateHandlers && (this.activateHandlers.length > 0)) this.activateHandlers[j]();
            var cell = GetChildElement(this.tabRow,1+j*3+0);
            cell.className = 'ActiveTabLeft';
            cell = GetChildElement(this.tabRow,1+j*3+1);
            cell.className = 'ActiveTabCenter';
            cell = GetChildElement(this.tabRow,1+j*3+2);
            cell.className = 'ActiveTabRight';
    
            this.selectedTabName = tabName;
            SetCookie(this.tabPanelId, this.selectedTabName, 'none');
        }
    }
}

