function Tab(iTabIndexId, bLinkText)
{
  this.bReady    = false;
  this.iIndexId  = iTabIndexId;
  this.bLinkText = bLinkText;
  
  if ((this.bReady = this.createNewTab()) == false)
  {
    debug("error creating tab");
  }
  
  debug("New Tab Created");
}

Tab.prototype.isReady = function()
{
  return this.bReady;
}

Tab.prototype.createNewTab = function()
{
  this.createTabLink();
  this.createTabContent();
}

Tab.prototype.createTabLink = function()
{
  this.oTabElement = document.createElement('li');
  this.oTabElement.setAttribute('class',"tabItem inactive");
  /* IE 7 attributes */
  this.oTabElement.className = "tabItem inactive";
  
  this.oTabLink = document.createElement('a');
  this.oTabLink.setAttribute('id',"tabLink-"+this.iIndexId);
  this.oTabLink.setAttribute('class',"tabLink");
  /* IE 7 attributes */
  this.oTabLink.className = "tabLink";
  this.oTabLink.setAttribute('href',"javascript:void(0)");
  this.oTabLink.setAttribute('onclick',"ContentTabs.showTab("+this.iIndexId+")");
 
  this.oTabLink.setAttribute('title',"Loading...("+this.iIndexId+")");
  this.oTabLink.innerHTML = "";
  
  this.oTabElement.appendChild(this.oTabLink);
  
  /* IE7 Compatability crap */
  this.oTabElement.innerHTML = this.oTabElement.innerHTML;
}

Tab.prototype.createTabContent = function()
{
  this.oTabContent = document.createElement('div');
  this.oTabContent.setAttribute('style',"display:none;");
  this.oTabContent.setAttribute('class',"tabContent");
  
  /* IE 7 attributes */
  this.oTabContent.className = "tabContent";
  this.oTabContent.style.display = "none";
  
  this.oTabContent.innerHTML = '<p>Loading Content</p><p><img src="in-base/images/loader-loadinfo.net.gif" title="Loading Content..."></p>';
}

Tab.prototype.display = function(iDisplayIndex, oElement)
{
  if (iDisplayIndex == 0)
  {
    this.oTabElement.setAttribute('class',"tabItem active");
    this.oTabContent.setAttribute('style',"display:block;");
    
    /* IE 7 attributes */
    this.oTabElement.className = "tabItem active";
    this.oTabContent.style.display = "block";
  }
  
  oElement.appendChild(this.oTabElement);
  oElement.parentNode.appendChild(this.oTabContent);
  //oElement.parentNode.insertBefore(this.oTabContent, oElement);
}

Tab.prototype.createContainer = function()
{
  var oTabContainer = document.getElementById('infoTabs');
  if (oTabContainer)
  {
    var oTabMainList = document.createElement('ul');
    oTabContainer.insertChild(oTabMainList);
  }
}

Tab.prototype.setTitle = function(oTitleElement)
{
  if ((this.oTabLink = document.getElementById('tabLink-'+this.iIndexId)))
  {
    this.oTabLink.title = oTitleElement.childNodes[0].nodeValue;
    this.oTabLink.setAttribute('title', oTitleElement.childNodes[0].nodeValue);
    if (this.bLinkText)
    {
      this.oTabLink.innerHTML = oTitleElement.childNodes[0].nodeValue;
    }
  }
}

Tab.prototype.setContent = function(oContentElement)
{
  debug("Setting new content for tab '"+this.iIndexId+"'");
  if (this.oTabContent)
  {
    for (var iIndex = 0; iIndex < oContentElement.childNodes.length; iIndex ++)
    {
      if (oContentElement.childNodes[iIndex])
      {
        if (oContentElement.childNodes[iIndex].nodeName == "#cdata-section")
        {
          this.oTabContent.innerHTML = oContentElement.childNodes[iIndex].nodeValue;
        }
      }
    }
  }
}

Tab.prototype.setLink = function(oTitleElement)
{
  if ((this.oTabLink = document.getElementById('tabLink-'+this.iIndexId)))
  {
    debug("Setting new link for tab '"+this.iIndexId+"'");
    this.sLink = oTitleElement.childNodes[0].nodeValue;
  }
}

Tab.prototype.show = function()
{
  this.oTabElement.setAttribute('class',"tabItem active");
  this.oTabContent.setAttribute('style',"display:block;");
  
  this.oTabElement.className = "tabItem active";
  this.oTabContent.style.display = "block";
}

Tab.prototype.hide = function()
{
  this.oTabElement.setAttribute('class',"tabItem inactive");
  this.oTabContent.setAttribute('style',"display:none;");
  
  this.oTabElement.className = "tabItem inactive";
  this.oTabContent.style.display = "none";
}
