function Tab(tabView, tab, frame)
{
    this.tabView = tabView;
    this.tab = tab;
    this.frame = frame;
    
    this.getId = function()
    {
        return(this.frame.id);
    };
    
    this.activate = function()
    {
        this.tab.className += " active";
        this.frame.className += " active";
    };
    
    this.deactivate = function()
    {
        this.tab.className = this.tab.className.replace(/ active/, "");
        this.tab.className = this.tab.className.replace(/active/, "");
        
        this.frame.className = this.frame.className.replace(/ active/, "");
        this.frame.className = this.frame.className.replace(/active/, "");
    };
}

function TabView(container, tabFrames)
{
    this.tabsTable = null;
    this.tabs = null;
    this.activeTab = null;
    
    this.getActiveTab = function()
    {
        return(this.activeTab);
    };
    
    this.switchTab = function(tab_id)
    {
        if (this.activeTab != null)
            this.activeTab.deactivate();
        
        this.activeTab = this.tabs[tab_id];
        this.activeTab.activate();
    };
    
    this.contruct = function(tabFrames)
    {
        // Tabelle mit den Tabs finden
        var tables = this.container.getElementsByTagName("table");
        for (var i = 0; i < tables.length; i++)
        {
            var classNames = tables[i].className.split(" ");
            for (var j = 0; j < classNames.length; j++)
            {
                if (classNames[j] == "tabs")
                {
                    this.tabsTable = tables[i];
                    break;
                }
            }
            
            if (this.tabsTable != null)
                break;
        }
        
        // Alle Tabs und aktiven Tab finden
        this.tabs = new Array();
        for (var i = 0; i < this.tabsTable.rows[0].cells.length; i++)
        {
            var cell = this.tabsTable.rows[0].cells[i];
            var tab = new Tab(this, cell, tabFrames[i]);
            this.tabs[tabFrames[i].id] = tab;
            var classNames = tab.tab.className.split(" ");
            for (var j = 0; j < classNames.length; j++)
            {
                if (classNames[j] == "active")
                    this.activeTab = tab;
            }
        }
    };
    
    this.container = container;
    this.contruct(tabFrames);
}

