//------------------------------
// GLOBAL VARIABLES
var currentTabIds = new Array();    // Stores the current active tab. It's an array because it can hold multipe tab instances on a single page

//------------------------------
// GLOBAL "CONSTANTS"
var TAB_PREFIX = 'tab_';                // Prefix for the tab's name, ie: "tab_234d451"
var CONTENT_PREFIX = 'tab_content_';    // Prefix for the actual content, ie: "tab_content_e46f4666"


var selectedTabGroupId = 0;             // Store the latest selected tab group id

/**
 * Function in charge of all the magic, shows a tab and hides the other one
 * @param string tabId Identifier of the tab withing the tab component
 * @param string tabGroupId Identifier of the tab component within the page
 */
function showTab(tabId, tabGroupId){
    var tabObj = document.getElementById(TAB_PREFIX + tabGroupId + tabId);
    var contentObj = document.getElementById(CONTENT_PREFIX + tabGroupId + tabId);
    
    selectedTabGroupId = tabGroupId;
    
    if( typeof(contentObj) != 'undefined' && typeof(tabObj) != 'undefined' ){

        // if no current tab has been assigned to the current tab component (determined
        // by the tabGroupId), then initialize it's value with the first tab (ie: 0)
        if( typeof (currentTabIds[tabGroupId]) == 'undefined'){
            currentTabIds[tabGroupId] = 0;
        }

        var tabName = tabGroupId + currentTabIds[tabGroupId];

        var currentTabObj = document.getElementById(TAB_PREFIX + tabName);
        var currentContentObj = document.getElementById(CONTENT_PREFIX + tabName);

        if(typeof(currentTabObj) != 'undefined' && typeof(currentContentObj) != 'undefined' ){
            if (currentTabObj != null)
               currentTabObj.className = 'unselected';
            if (currentContentObj != null)
               currentContentObj.className = 'unselected';
        }

        if (tabObj != null)
           tabObj.className = 'selected';
        if (contentObj != null)
           contentObj.className = 'selected';
        
        // ijiron - Fix: DE684 - DE685
        var browser=navigator.appName; 
        
        if (browser=="Microsoft Internet Explorer") {
           try {
              tabObj.focus();
           }
           catch(err) { ; }
        }
        currentTabIds[tabGroupId] = tabId;
    }
}

function initTabs(tabId, tabGroupId){
    currentTabIds[tabGroupId] = tabId;
}

function getCurrentTab(tabGroupId){
    return currentTabIds[tabGroupId];
}