var tabContainers = {};

TabType = function()
{
  this.id = 0;
  this.name = '';
  this.link = '';
}

TabContainerType = function()
{
  this.id = 1;
  this.name = "";
  this.classPrefix = "";
  this.tabs = {};
    
  this.Load_From_Json = function(theData)
  {
    this.id = theData.id;
    this.name = theData.name;
    this.classPrefix = theData.classPrefix;
    for(var i=0; i<theData.tabs.length; i++)
    {
      var theTab = new TabType();
      theTab.id = theData.tabs[i].id;
      theTab.name = theData.tabs[i].name;
      theTab.link = theData.tabs[i].link;
      this.tabs[theTab.id] = theTab;
    }
    
    //this.InitialEvents();
  };
  
  this.Change_Tab = function(tabId)
  {
    var prefix = 'tab_'+this.id+'_';
    var i = 0;
    var selectedClass = this.classPrefix+'tab_selected';
    var notSelectedClass = this.classPrefix+'tab';
    var thisTab = null;
    for(i in this.tabs)
    {
        var containerId = 'tab_container_'+this.id+'_'+i+'_main_module';
        var theTabId = prefix + i;
        if (theTabId != tabId)
        {
          document.getElementById(theTabId).className = notSelectedClass;
          document.getElementById(containerId).style.display = 'none';
        }
        else
        {
          document.getElementById(theTabId).className = selectedClass;
          document.getElementById(containerId).style.display = 'block';
          thisTab = this.tabs[i];
        }
    }
    
    if (thisTab.initialized)
    {
      return false;
    }
    else
    {
      thisTab.initialized = true;
      return true;
    }
  }
  
  this.InitialEvents = function()
  {
    var prefix = 'tab_'+this.id+'_';
    for(i in this.tabs)
    {
        var theTabId = prefix + i;
        var el = document.getElementById(theTabId);
        el.onlcick = window.TabOnClick;
    }
  }
}

Get_TabContainerId_Of_Tab = function(theTabId)
{
  var tempStr = theTabId.replace('tab_','');
  var uIndex = tempStr.indexOf('_');
  var tcId = tempStr.substr(0,uIndex);
  return tcId;
}


TabOnClick = function()
{
  var theId = this.id;
  var tcId = Get_TabContainerId_Of_Tab(theId);
  this.blur();
  return tabContainers[tcId].Change_Tab(theId);
}

