// *--------------------------------------------------------------
// * Code of TabBar control
// * Version 1.0
// * (C) Projex 2001
// * Author: J.M.de Jong
// *--------------------------------------------------------------


  function FormatLayerText(x, y, width, height, item)
  {
    layerText = "";

    if (navigator.appName=="Netscape")
    {
      y = y - 7;
      x = x - 2;
      layerText = "<LAYER LEFT=" + x + " TOP=" + y + "WIDTH=" + width + " HEIGHT=" + height + ">";
      layerText = layerText + item;
      layerText = layerText + "</LAYER>";
    }
    else
    {
      layerText = "<DIV STYLE='position:absolute; left:" + x + "px; top:" + y + "px;";
      layerText = layerText + " width:" + width + "px; height:" + height + "px;'>"
      layerText = layerText + item;
      layerText = layerText + "</DIV>";
    }
    return layerText;
  }

  function Tab(Text, Link)
  {
    this.Text = Text;
    this.Link = Link;
  }

  function AddTab(Text, Link)
  {
    index = this.LastTabIndex;
    this.TabArray[index] = new Tab(Text, Link);
    this.LastTabIndex = this.LastTabIndex + 1;
  }

  function Paint()
  {
  theLeft = this.BarLeft;

  // ******* place the inactive tabs until the active one ****
  if ((this.ActiveTabIndex>=0) && (this.ActiveTabIndex<this.TabArray.length))
     toTab = this.ActiveTabIndex;
  else
     toTab = this.TabArray.length;

  for (i=0;i<toTab;i++)
  {
    theLeft = this.BarLeft + (i*(this.TabMoveFactor*this.TabWidth));

    text = "<img width=" + this.TabWidth + " height=" + this.TabHeight + " border=0 src='" +
	this.TabInActiveImage + "'>";
    document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));

    text = "<TABLE BORDER=0 WIDTH=" + this.TabWidth + " HEIGHT=" + this.TabHeight+ 
	" cellpadding=0 cellspacing=0><TR><TD ALIGN=CENTER><B><A Class=Tab HREF='" +
	this.TabArray[i].Link + "'>" + this.TabArray[i].Text + "</B></A></TD></TR></TABLE>";
    document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));
  }

  // ******* place the inactive tabs from end to active****
  if ((this.ActiveTabIndex>=0) && (this.ActiveTabIndex<this.TabArray.length))
  {
    toTab = this.ActiveTabIndex;

    for (i=this.TabArray.length-1;i>toTab;i--)
    {
      theLeft = this.BarLeft + (i*(this.TabMoveFactor*this.TabWidth));
      
      text = "<img width=" + this.TabWidth + " height=" + this.TabHeight + " border=0 src='" +
	   this.TabInActiveImage + "'>";
      document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));

      text = "<TABLE BORDER=0 WIDTH=" + this.TabWidth + " HEIGHT=" + this.TabHeight+ 
	" cellpadding=0 cellspacing=0><TR><TD ALIGN=CENTER><B><A Class=Tab HREF='" +
	this.TabArray[i].Link + "'>"	+ this.TabArray[i].Text + 
	"</B></A></TD></TR></TABLE>";
      document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));    }
  }

  // ******* place the active tab *******
  if ((this.ActiveTabIndex>=0) && (this.ActiveTabIndex<this.TabArray.length))
  {
    theLeft = this.BarLeft + (this.ActiveTabIndex*(this.TabMoveFactor*this.TabWidth));

    text = "<img width=" + this.TabWidth + " height=" + this.TabHeight + " border=0 src='" +
	this.TabActiveImage + "'>";
    document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));

    text = "<TABLE BORDER=0 WIDTH=" + this.TabWidth + " HEIGHT=" + this.TabHeight+ 
	" cellpadding=0 cellspacing=0><TR><TD ALIGN=CENTER><B><A Class=Tab HREF='" +
	this.TabArray[this.ActiveTabIndex].Link + "'>"	+ this.TabArray[this.ActiveTabIndex].Text + 
	"</B></A></TD></TR></TABLE>";
    document.write(FormatLayerText(theLeft, this.BarTop, this.TabWidth, this.TabHeight, text));
  }
  }

  function Debug(Text)
  {
    if (this.bug == 0) 
    {
      this.bug = window.open("", "bug", "status=0 toolbar=0 scrollbars=yes width=300 height=200");
      this.bug.document.writeln("<HTML><BODY BGCOLOR=#C0C0C0></BODY></HTML>");
    }
    this.bug.document.writeln(Text + "<BR>");
  }

  function ShowControlProperties()
  {
    if (this.bug == 0) 
    {
      this.bug = window.open("", "bug", "status=0 toolbar=0 scrollbars=yes width=300 height=200");
      this.bug.document.writeln("<HTML><BODY BGCOLOR=#C0C0C0></BODY></HTML>");
    }
    this.bug.document.writeln("<B>Parameters of TabBar Control:</B><BR>");
    this.bug.document.writeln("BarLeft: " + this.BarLeft + "<BR>");
    this.bug.document.writeln("BarTop: " + this.BarTop + "<BR>");
    this.bug.document.writeln("TabWidth: " + this.TabWidth + "<BR>");
    this.bug.document.writeln("TabHeight: " + this.TabHeight + "<BR>");
    this.bug.document.writeln("TabMoveFactor: " + this.TabMoveFactor + "<BR>");
    this.bug.document.writeln("TabActiveImage: '" + this.TabActiveImage + "'<BR>");
    this.bug.document.writeln("TabInActiveImage: '" + this.TabInActiveImage + "'<BR>");
    this.bug.document.writeln("ActiveTabIndex: " + this.ActiveTabIndex + "<BR>");
    for (counter=0;counter<this.TabArray.length;counter++)
    {
      this.bug.document.writeln("<B>Tab nr:" + counter + "</B><BR>");
      this.bug.document.writeln("Text:" + this.TabArray[counter].Text + "<BR>");
      this.bug.document.writeln("Link:" + this.TabArray[counter].Link + "<BR>");
    }
    this.bug.document.writeln("-.-.-.-.-.-.-.-.-.-<BR>");
  }

  function TabBar()
  {
    //Public Properties of TabBar Object
    this.BarLeft = 0;
    this.BarTop = 0;
    this.TabWidth = 0;
    this.TabHeight = 0;
    this.TabMoveFactor = 0.65;
    this.TabActiveImage = "";
    this.TabInActiveImage = "";
    this.ActiveTabIndex = 0;

    //Private Properties of TabBar Object
    this.TabArray = new Array(0);
    this.LastTabIndex = 0;
    this.bug = 0;

    //Methods of TabBar Object
    this.Paint = Paint;
    this.AddTab = AddTab;
    this.ShowControlProperties = ShowControlProperties;
    this.Debug = Debug;
  }

// *--------------------------------------------------------------
// * End of Code of TabBar control
// *--------------------------------------------------------------


