function hideAllContentDivs() {
    var DivElements = document.getElementsByTagName("div");
    var CurElement = 0;

    while (CurElement < DivElements.length) {
        if (DivElements[CurElement].className == "tab_container") {
            DivElements[CurElement].style.display = "none";
        }
        CurElement = CurElement + 1;
    }
}

function unselectTabs() {
    var TdElements = document.getElementsByTagName("td");
    var CurElement = 0;

    while (CurElement < TdElements.length) {
        if (TdElements[CurElement].className.search(/Active/i) > -1) {
            TdElements[CurElement].className = "Inactive";
        }
        CurElement = CurElement + 1;
    }
}

function setActiveTab(activeButtonID) {
    var activeContentID = activeButtonID + "_content";

    hideAllContentDivs();
    unselectTabs();

    document.getElementById(activeButtonID).className = "Active";
    document.getElementById(activeContentID).style.display = "block";
}

function pickTab() {
    var anchorLink = location.hash.replace("#", "");

    switch (anchorLink) {
        case "Tab_2":
        case "Tab_3":
        case "Tab_4":
        case "Tab_5":
            setActiveTab(anchorLink);
            break;
        default:
            setActiveTab("Tab_1");
    }
}

function anchorLinkToTab() {
    //$ is a jQuery-specific selector
    //requires all anchor links to a Tabbed Section within the same page to have class="tabAnchor"
    $("a.tabAnchor").click(function (e) {
        var tabAnchor = this.href;
        var tabAnchorIndex = tabAnchor.indexOf("#") + 1;
        tabAnchor = tabAnchor.substring(tabAnchorIndex);
        setActiveTab(tabAnchor);
    })
}

function testForTabbedSection() {
    if (document.getElementById("tabbedSection")) {
        pickTab();
        anchorLinkToTab();
    }
}

ExecuteOrDelayUntilScriptLoaded(testForTabbedSection, "sp.js");
/* This is a SharePoint-specific function to fire custom JS after all SP scripts have fired.
Use instead of window.onload to keep SP editing ribbon from breaking.
See also:
http://www.codeproject.com/Articles/60348/SharePoint-2010-Client-Object-Model-for-JavaScript.aspx
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/27a971b7-8f23-4f7f-aeef-69afad4ca504

window.onload = function () {
    testForTabbedSection();
}

*/
