Emv.Tab = {
    /**
     * Select a tab.
     * If overrideAnchor is set to false, the tab is only selected if no anchor in the url exists.
     * Anchors are not evaluable for the server!!!
     *
     * @param string tabContainerId The id of the tab container.
     * @param integer tabNameToSelect The name of the tab which should be selected.
     * @param boolean overrideAnchor If set to false, the tab is only selected if no anchor in the url exists.
     * @return boolean
     */
    selectTab: function (tabContainerId, tabNameToSelect, overrideAnchor) {

        if (typeof(tabContainerId) != "undefined" && typeof(tabNameToSelect) != "undefined") {

            var tabContainer = $('#'+tabContainerId).tabs();

            if (typeof(overrideAnchor) != "undefined" && overrideAnchor === true) {

                // Select tab if it is a part of this container (if anchor exist or not).
                if ($('#'+tabContainerId).find("#"+tabNameToSelect).length == 1) {

                    tabContainer.tabs({ selected: '#'+tabNameToSelect });
                }

            } else {

                var anchor = window.location.href.split('#')[1];
                if (typeof(anchor) == "undefined" || $('#'+tabContainerId).find("#"+anchor).length === 0) {

                    // Select tab because anchor does not exist or anchor exist but is not a tab in this tab container.
                    tabContainer.tabs({ selected: '#'+tabNameToSelect });
                } 
                /* else {

                    // Do not select tab because anchor exists and anchor is a tab in this tabcontainer.
                    // The anchor should automatically select this tab.
                } */
            }

            return true;
        }

        return false;
    }
};
