﻿function tabControl(tabCtrlName) {
    this.tabCtrl = document.getElementById(tabCtrlName);

    this.switchToTabName = function(tabId) {
        this.switchTab(document.getElementById(tabId));
    }

    this.switchTab = function(tab) {
        if (this.tabCtrl.selectedTab != null) {
            this.tabCtrl.selectedTab.className = "fpTabHeader";
            this.tabCtrl.selectedTab.associatedPage.style.display = "none";
        }
        this.selectTab(tab);
    }

    this.selectTab = function(tab) {
        this.tabCtrl.selectedTab = tab;
        $(tab).attr("class", "fpTabHeader-sel");
        tab.associatedPage.style.display = "block";
    }

    this.linkControls = function(tabName, pageName) {
        var tab = document.getElementById(tabName);
        var page = document.getElementById(pageName);
        tab.associatedPage = page;
        tab.tabCtrl = this;
        $("#" + tabName).click(function() {
            if (this.className == "fpTabHeader-disabled")
                return;
            this.tabCtrl.switchTab(tab);
        });
        page.style.display = "none";
    }
}

