function tabFind()
{
    var t,tabs;
    // loop through all the divs
    tabs=document.getElementsByTagName('div');
    for(t=0;t<tabs.length;t++)
    {
        //show the button row
        if(/tabrow/.test(tabs[t].id))
        {
            // add the tabbing function to the events
            tabs[t].style.display = "block";
        }
    
        // see if it's a tab class
        if(/tabbutton/.test(tabs[t].className))
        {
            // add the tabbing function to the events
            tabs[t].onclick=function(){
                tabSelect(this);
            };
        }
    }
}

function tabSelectById(tabid)
{
    // set this tab as visible
    tabHideAll();
    document.getElementById("tabcontents_" + tabid).style.display = "block";
  
    // set the tab-selector active
    if(document.getElementById("tabbutton_" + tabid) != null)
    {
        document.getElementById("tabbutton_" + tabid).className = 'tabbutton_active';
    }
}

function tabSelect(o)
{
    // get the numerical tab id
    var id = o.id
    var tabid = id.substring(id.lastIndexOf('_')+1, id.length);
    tabSelectById(tabid)
}

function tabShowFirst()
{
    tabHideAll();
    tabs=document.getElementsByTagName('div');
  
    fullurl=window.location.href;
    requestedTab=parseInt(fullurl.substring(fullurl.indexOf('#')+1,fullurl.length))
    if(isNaN(requestedTab))
    {
        requestedTab=0
    }

    for(t=0;t<tabs.length;t++)
    {
        // see if it's a tab class
        if(/tabpage/.test(tabs[t].className))
        {
            // show the requested tab
            tabid=parseInt(tabs[t].id.substring(tabs[t].id.lastIndexOf('_')+1,tabs[t].id.length))

            if(tabid >= requestedTab)
            {
                tabs[t].style.display = "block";
                tabSelect(tabs[t]);
                t=tabs.length;
            }
        }
    }
}

function tabHideAll()
{
    tabs=document.getElementsByTagName('div');
    for(t=0;t<tabs.length;t++)
    {
        // see if it's a tab class
        if(/tabpage/.test(tabs[t].className))
        {
            // hide the tab
            tabs[t].style.display = "none";
        }
        if(/tabbutton/.test(tabs[t].className))
        {
            // set the class to a "non-selected" button
            tabs[t].className = 'tabbutton';
        }

    }
}

function tabOnLoad()
{
    tabFind();
    tabShowFirst();
}
