function openTab(id, link) {
  parent.curTab = id;
  parent.options.location = link;
}

function printTabs() {
  var curSet = 0, skipped = 0;
  var maxWidth, width, broke;
  var multiplier = 9;
  var endTab = tabs;

  maxWidth = this.innerWidth;
  if (maxWidth == null)
    maxWidth = this.document.body.clientWidth;
  maxWidth -= 30;

  while (curSet < parent.tabSet) {
    width = 0;
    broke = 0;
    for (var x = skipped; x < tabs; x++) {
      var curWidth = 0;
      if (tabArray[x][1].search(/.* &amp;.*/) == -1)
        curWidth = tabArray[x][1].length * multiplier + 20;
      else
        curWidth = (tabArray[x][1].length - 4) * multiplier + 20;
      if ((width+curWidth) > maxWidth) {
        if ((width+35) > maxWidth)
          endTab = x - 1;
        else
          endTab = x;
        broke = 1;
        break;
      }
      width += curWidth;
    }
    if (!broke)
      endTab = tabs;
    curSet++;
    if (curSet < parent.tabSet)
      skipped = endTab;
  }

  document.writeln('<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">');
  document.writeln('  <TR>');
  document.writeln('    <TD ROWSPAN="2">');
  document.writeln('      <IMG SRC="../icons/spacer.gif" BORDER="0" WIDTH="6" HEIGHT="1" ALT=""></A>');
  document.writeln('    </TD>');

  if (curSet > 1)
    printPromptEdges();
  else
    skipped = 0;
  for (var x = skipped; x < endTab; x++) {
    printTabEdges(skipped, x, endTab, tabArray[x][1], tabArray[x][2]);
  }
  if (skipped != endTab)
    printFinalTabEdge(endTab);
  if (tabs > endTab)
    printPromptEdges();

  document.writeln('  </TR>');
  document.writeln('  <TR>');

  if (curSet > 1)
    printPromptArrow('prevtab', parent.tabSet - 1);
  for (var x = skipped; x < endTab; x++) {
    printTabText(x, tabArray[x][1], tabArray[x][2]);
  }
  if (tabs > endTab)
    printPromptArrow('nexttab', parent.tabSet + 1);

  document.writeln('  </TR>');
  document.writeln('</TABLE>');
}

function printPromptEdges() {
  document.writeln('<TD ROWSPAN="2"></TD>');
  document.writeln('<TD></TD>');
  document.writeln('<TD ROWSPAN="2"></TD>');
}

function printPromptArrow(direction, tabSet) {
  document.write('<TD VALIGN="bottom">');
  document.write('<A HREF="javascript:location.reload()" TARGET="_self"');
  document.write('  ONCLICK="parent.tabSet=' + tabSet + '"');
  document.write('  ONMOUSEOVER="window.status=\'More Tabs\'; return true;">');
  document.write('<IMG SRC="../icons/' + direction + '.gif" WIDTH="35" HEIGHT="21" BORDER="0" ALT="More Tabs" TITLE="More Tabs">');
  document.write('</A>');
  document.write('</TD>');
}

function printTabEdges(firstTab, thisTab, endTab, name, link) {
  var prevTabType;
  if (thisTab == firstTab) {
    prevTabType = 'none';
  } else if (parent.curTab == (thisTab - 1)) {
    prevTabType = 'selected';
  } else {
    prevTabType = 'unselected';
  }

  var thisTabType;
  if (thisTab == parent.curTab) {
    thisTabType = 'selected';
  } else {
    thisTabType = 'unselected';
  }

  document.writeln('<TD ROWSPAN="2"><IMG SRC="../icons/' + prevTabType + '-' + thisTabType + '.gif" WIDTH="19" HEIGHT="23" BORDER="0" ALT=""></TD>');
  document.writeln('<TD BACKGROUND="../icons/top-' + thisTabType + '.gif"><IMG SRC="../icons/spacer.gif" WIDTH="1" HEIGHT="2" ALT=""></TD>');
}

function printFinalTabEdge(endTab) {
  var prevTabType;
  if (parent.curTab == (endTab - 1)) {
    prevTabType = 'selected';
  } else {
    prevTabType = 'unselected';
  }

  document.writeln('<TD ROWSPAN="2"><IMG SRC="../icons/' + prevTabType + '-none.gif" WIDTH="19" HEIGHT="23" BORDER="0" ALT=""></TD>');
}

function printTabText(thisTab, name, link) {
  var tabBgColor;
  var tabTextColor;
  if (thisTab == parent.curTab) {
    tabBgColor = '#CCCCCC';
    tabTextColor = '#000000';
  } else {
    tabBgColor = '#999999';
    tabTextColor = '#FFFFFF';
  }

  document.write('<TD BGCOLOR="' + tabBgColor + '" HEIGHT="21" NOWRAP>');
  document.write('<A HREF="javascript:location.reload()" TARGET="_self"');
  document.write('  ONCLICK="openTab(' + thisTab + ', \'' + link + '\')"');
  document.write('  ONMOUSEOVER="window.status=\'' + name + '\'; return true;">');
  document.write('<FONT SIZE="2" FACE="PrimaSans BT, Verdana, sans-serif" COLOR="' + tabTextColor + '">');
  document.write('<B>' + name + '</B>');
  document.write('</FONT>');
  document.write('</A>');
  document.write('</TD>');
}
