function TabsObject(Ptr,Tabs)
{
  Ptr.onselectstart = function() { return false };
  this.row = document.createElement('DIV');
  this.row.self = this;
  this.row.maxIndex = 0;
  this.row.tabs = 0;
  this.row.MaxTabs = 99;
  this.row.MaxMsg = 'Maximum Tabs Reached';
  this.row.SelectedTab = false;
  if(arguments.length == 3)
  {
    this.row.ScrollPoint = 0;
    this.row.ScrollSize = arguments[2];
  }
  Ptr.appendChild(this.row);
  for(var i=0,j=1;i<Tabs.length;i+=2,j++)
  {
    Ptr.tp = new Tab(this.row,Tabs[i],Tabs[i+1],j);
    if(this.row.ScrollSize && j > this.row.ScrollSize)
    {
      Ptr.tp.previousSibling.style.display = 'none';
      Ptr.tp.style.display = 'none';
    }
  }
  if(this.row.tabs > this.row.ScrollSize)
  {
    var btelm = document.createElement('DIV');
    btelm.style.width = '100%';
    btelm.style.textAlign = 'right';
    this.row.appendChild(btelm);
    var scrollb = document.createElement('BUTTON');
    scrollb.onclick = function () { TabsObject.ScrollLeft(this); };
    scrollb.disabled = true;
    scrollb.style.height = 20;
    scrollb.style.marginLeft = 3;
    scrollb.innerHTML = '&lt;';
    btelm.appendChild(scrollb);
    scrollb = document.createElement('BUTTON');
    scrollb.onclick = function () { TabsObject.ScrollRight(this); };
    scrollb.style.height = 20;
    scrollb.innerHTML = '&gt;';
    btelm.appendChild(scrollb);
  }
}
function Tab(row,TabTxt,AlwaysShow,Indx)
{
  if(row.tabs == row.MaxTabs)
  {
    document.getElementById('Tab'+Indx+'_Content').parentNode.removeChild(document.getElementById('Tab'+Indx+'_Content'));
    alert(row.MaxMsg);
    this.created = false;
    return;
  }
  row.tabs++;
  row.maxIndex = Indx;
  var elm = document.createElement('DIV');
  elm.innerHTML = '&nbsp;';
  elm.className = 'tableft';
  row.appendChild(elm);
  elm = document.createElement('A');
  elm.created = true;
  elm.id = 'Tab'+Indx;
  elm.index = Indx;
  elm.AlwaysShow = AlwaysShow;
  elm.innerHTML = '&nbsp;&nbsp;'+TabTxt+'&nbsp;&nbsp;';
  elm.className = 'tab';
  elm.owner = row;
  row.appendChild(elm);
  elm.onclick     = function () { row.self.SelectTab(this); };
  elm.onmouseover = function () { TabsObject.RollOver(this); };
  elm.onmouseout  = function () { TabsObject.RollOut(this); };
  if(arguments.length == 5)
    row.self.SelectTab(elm);
  else if(Indx == 1)
    TabsObject.show(elm);
  else
    TabsObject.hide(elm);
  return elm;
}
TabsObject.prototype.SelectTab = function(which)
{
  if(which == which.owner.SelectedTab)
    return;
  if(which.owner.SelectedTab)
    TabsObject.hide(which.owner.SelectedTab);
  TabsObject.show(which);
};
TabsObject.show = function(which)
{
  which.owner.SelectedTab = which;
  which.previousSibling.className = 'tableft-active';
  which.className = 'tab selected';
  document.getElementById(which.id+'_Content').style.display = "block";
  if(typeof(tab_callback) != 'undefined')
    tab_callback(which.id);
};
TabsObject.hide = function(which)
{
  which.previousSibling.className = 'tableft';
  which.className = 'tab';
  if(which.AlwaysShow == '1')
    return;
  document.getElementById(which.id+'_Content').style.display = "none";
};
TabsObject.RollOver = function(which)
{
  var tmp = which.className + " hover";
if(tmp.indexOf('selected') == -1) which.className = 'tab hover'; else
  which.className = tmp.replace(/ +/g, " ");
};
TabsObject.RollOut = function(which)
{
  which.className = which.className.replace(/ hover/g, "");
};
TabsObject.prototype.DestroyTab = function(which)
{
  if(which == this.row.SelectedTab)
  {
    for(var i=which.index-1;i>0;i--)
      if(TabPtr = document.getElementById('Tab'+i))
      {
        this.SelectTab(TabPtr);
        break;
      }
    if(i == 0 && this.row.tabs > 1)
    {
      for(var i=which.index;i<=this.row.maxIndex;i++)
      {
        if(TabPtr = document.getElementById('Tab'+(i+1)))
        {
          this.SelectTab(TabPtr);
          break;
        }
      }
    }
  }
  document.getElementById(which.id+'_Content').parentNode.removeChild(document.getElementById(which.id+'_Content'));
  which.previousSibling.parentNode.removeChild(which.previousSibling);
  which.parentNode.removeChild(which);
  this.row.tabs--;
};
TabsObject.ScrollRight = function(btn)
{
  var ptr = btn.parentNode.parentNode;
  if(ptr.ScrollPoint/2 == ptr.tabs - ptr.ScrollSize)
    return;
  which = ptr.childNodes[ptr.ScrollPoint];
  which.style.display = which.nextSibling.style.display = 'none';
  which = ptr.childNodes[ptr.ScrollPoint+(ptr.ScrollSize*2)];
  which.style.display = which.nextSibling.style.display = 'inline';
  ptr.ScrollPoint+=2;
  btn.previousSibling.disabled = false;
  if(ptr.ScrollPoint/2 == ptr.tabs - ptr.ScrollSize)
    btn.disabled = true;
};
TabsObject.ScrollLeft = function(btn)
{
  var ptr = btn.parentNode.parentNode;
  if(!ptr.ScrollPoint)
    return;
  ptr.ScrollPoint-=2;
  which = ptr.childNodes[ptr.ScrollPoint];
  which.style.display = which.nextSibling.style.display = 'inline';
  which = ptr.childNodes[ptr.ScrollPoint+(ptr.ScrollSize*2)];
  which.style.display = which.nextSibling.style.display = 'none';
  btn.nextSibling.disabled = false;
  if(!ptr.ScrollPoint)
    btn.disabled = true;
};
