﻿
function GISP_ReportTabs(pTabCollection) {
    var me = this;
    this._TabCollection = pTabCollection;
    this._SetTab = function(pIndex) {
        for (var i = 0; i < me._TabCollection.length; i++) {
            if (i == pIndex) {
                me._TabCollection[i].SetActive();
            } else {
                me._TabCollection[i].SetInactive();
            }; //end ifelse index
        }; //end for each tab
    }; //end nethod

    this._GetTabIndexByToken = function(pToken) {
        var myIndex = -1;
        for (var i = 0; i < me._TabCollection.length; i++) {
            if (me._TabCollection[i].Token == pToken) {
                myIndex = i;
                break;
            }; //end if tab found
        };
        return myIndex;
    };  //end method

    this._SetTabByToken = function(pToken) {
        me._SetTab(me._GetTabIndexByToken(pToken));
    }; //end method

    this._Dispose = function() {
        for (var i = 0; i < me._TabCollection.length; i++) {
            me._TabCollection[i].Dispose();
            me._TabCollection[i] = null;
        }; //end for each tab

        me._TabCollection = null;
    };   //end dispose

    return new function() {
        this.SetTab = me._SetTab;
        this.SetTabByToken = me._SetTabByToken;
        this.GetTabIndexByToken = me._GetTabIndexByToken;
        this.Dispose = me._Dispose;
    };   //end constructor
}; //end class

function GISP_ReportTab(pLink, pOptions) {
    var me = this;
    this._link = pLink;
    this._SetActive = function() {
        GISPlanning_SetImageActive($(me._link).find("img")[0]);
        me._Active = true;
        if (me._Callback != null) {
            me._Callback();
        }; //end if a callback exists
    };
    this._SetInactive = function() {
        GISPlanning_SetImageInactive($(me._link).find("img")[0]);
        me._Active = false;
    };

    this._Dispose = function() {
        me._Callback = null;
        me._link = null;
        me = null;
    };   //end dispose




    var myOptions = { Token: "", Name: "", Active: false, Tooltip: "Click here to view this report", Callback: null };
    for (var o in myOptions) {
        if (typeof (pOptions[o]) != "undefined") {
            me['_' + o] = pOptions[o];
        }; //end if option was passed in
    }; //end for each option

    me._link.style.visibility = "visible";
    $(me._link).find("span")[0].innerHTML = me._Name;
    if (me._Active) {
        setTimeout(me._SetActive, 100); //lets the tabs load etc...
    };

    return new function() {
        this.Link = me._link;
        this.Name = me._Name;
        this.Token = me._Token; //used to find the tab
        this.Active = me._Active;
        this.Tooltip = me._Tooltip;
        this.Callback = me._Callback;
        this.SetActive = me._SetActive;
        this.SetInactive = me._SetInactive;
        this.Dispose = me._Dispose;


    }

}; //end class

