// begin buttons.js
var IE = document.all ? true:false;
var NS = document.layers ? true:false;
var origHeight, origWidth;

// set up REs for validating button-related text
var reSpaceAnywhere    = new RegExp ();
var reSpaceFirstOrLast = new RegExp ();
   reSpaceAnywhere.compile ('\\s', 'g');
   reSpaceFirstOrLast.compile ('(\\s+$)|(^\\s+)', 'g');

// Ensure that buttonList ARRAY exists
var buttonList; // Global for bw compatibility, won't alter predef arrays
   if (!buttonList) buttonList = new Array(); // no array then create, else continue
   else if (buttonList.length % 3 != 0) buttonList = new Array(); // bad array start over

function makeColor () { // pulls styles down from global css
   if (IE) {
      this.buttonOff = "#003366";
      this.textOff   = "#FFFFFF";
      this.buttonOn  = "#006699";
      this.textOn    = "#FFFFFF";
   } 
   else {
      this.buttonOff = document.classes.buttonOffStyle.all.backgroundColor;
      this.textOff   = document.classes.regText.all.color;
      this.buttonOn  = document.classes.buttonOnStyle.all.backgroundColor;
      this.textOn    = document.classes.overText.all.color;
   } 
	// Commented-out alert function to debug color selection
	// window.alert(this.buttonOn +":"+this.buttonOff+":t-"+this.textOn+":"+this.textOff);
} // end constructor makeColor

var colors = new makeColor (); // instantiate styles

function PlaceButton2 (bName, bTarget, bWidth, bHeight, altMsg, addException) { // requires bName and bTarget
var bName, bTarget, bWidth, bHeight, altMsg, addException; // args
var bLen, bTitle;
   if (2 > arguments.length || arguments.length > 6 || !bName || !bTarget)
      return; // return if args DNE
   if (arguments.length == 2)  { bWidth = 100; altMsg = ''; }
   else if (isNaN (parseInt (bWidth))) { altMsg = bWidth; bWidth = 100; bHeight = 18; }
   else if (!altMsg) altMsg = '';
   if (!bHeight) bHeight = 18;
   if (IE) bHeight = parseInt (bHeight) + 2;
   bLen       = buttonList.length;   
   bTitle     = String (bName).replace (reSpaceFirstOrLast, '');
   bName      = String (bName).replace (reSpaceAnywhere, '').toLowerCase ().concat (String ((buttonList.length / 3)));
   bTarget    = String (bTarget).replace (reSpaceFirstOrLast, '');
   buttonList[bLen] = bName; buttonList[bLen + 1] = bTitle; buttonList[bLen + 2] = bTarget;
   bName      = String ('button_').concat (bName);
   document.write ('<IMG src="images/spacer.gif" width="' + bWidth + '" height="' + bHeight + '" border="0" name="' + bName + '" id="' + bName + '" alt="' + altMsg + '" align="absmiddle" >');
   //document.write ('<br>');
   document.close ();
} // end fun PlaceButton

function getX(o) { // used by IE to find placeholder
  var x=1;
  var tableCount=0;
  while (o.offsetParent.tagName != 'BODY') {
    if (o.offsetParent.tagName == 'TABLE') tableCount+=1;
    x+=o.offsetLeft;
    o=o.offsetParent;
  }
  x+=Math.floor(tableCount/3);
  return x+o.offsetLeft;
} // end fun getX

function getY(o) { // used by IE to find placeholder
  var y=1;
  var tableCount=0;
  while (o.offsetParent.tagName != 'BODY') {
    if (o.offsetParent.tagName == 'TABLE') tableCount+=1;
    y+=o.offsetTop;
    o=o.offsetParent;
  }
  y+=Math.floor(tableCount/3);
  return y+o.offsetTop;
} // end fun getY

function mOver () { // changes layer on mouseover
   if (IE) {
      this.style.backgroundColor="#006699";
      return;
   } else {
      this.parentLayer.bgColor="#006699";
      this.parentLayer.textLyr.document.write(this.parentLayer.overText);
      this.parentLayer.textLyr.document.close();
      return;
   } // end if-else
} // end fun mOver

function mOut () { // restores layer on mouseout
   if (IE) {
      this.style.backgroundColor="#003366";
      return;
   } else {
      this.parentLayer.bgColor="#003366";
      this.parentLayer.textLyr.document.write(this.parentLayer.regText);
      this.parentLayer.textLyr.document.close();
      return;
   } // end if-else
} // end fun mOut

function linkIt() {
var theLink = new String ();
   theLink = String (this.link);
   if (theLink.indexOf ('javascript:') != -1)
      eval (theLink);   
   else   
      location.href = theLink;
   return (true);
} // end fun linkIt

function makeButtonIE () {
var buttonStr = '<DIV id="button_' + this.buttonName + 
   '_" style="position:absolute;width:' + this.w + 
   ';height:' + this.h + ';"></DIV>';
var canvas;
var img = 'button_' + this.buttonName;
var str = this.buttonName;

   document.body.insertAdjacentHTML ("BeforeEnd", buttonStr);
   this.canvas                  = document.all ["button_"+this.buttonName+"_"];
   canvas                       = this.canvas;
   canvas.innerHTML             = this.buttonLabel;
   canvas.style.visibility      = 'hidden';
   canvas.style.pixelTop        = this.y;
   canvas.style.pixelLeft       = this.x;
   canvas.style.fontFamily      = 'sans-serif';
   canvas.style.fontSize        = '10pt';
   canvas.style.fontWeight      = 'bold';
   canvas.style.backgroundColor = "#003366";
   canvas.style.borderColor     = 'black';
   canvas.style.borderStyle     = 'outset';
   canvas.style.borderWidth     = '1px';
   canvas.style.color           = "#ffffff";
   canvas.style.textAlign       = 'center';
   canvas.style.cursor          = 'default';
   canvas.style.visibility      = 'visible';
   canvas.buttonName            = this.buttonName;
   canvas.link                  = this.link;
   canvas.onmouseover           = mOver;
   canvas.onmouseout            = mOut;
   canvas.onmouseup             = linkIt;
} // end fun makeButtonIE

function makeButtonNS () {
var img                 = 'button_' + this.buttonName;
var str                 = this.buttonLabel;
var midAdjustFS         = document.classes.regText.all.fontSize;
var midAdjust;
   // black border
   var canvasBG         = new Layer (this.w + 2);
   canvasBG.visibility  = 'hide';
   canvasBG.top         = (this.y - 1);
   canvasBG.left        = (this.x - 1);
   canvasBG.clip.right  = (this.w + 2);
   canvasBG.clip.bottom = (this.h + 2);
   canvasBG.bgColor     = 'black';
   canvasBG.visibility  = 'show';
   // main canvas
   this.canvas          = new Layer (this.w);
   var canvas           = this.canvas;
   canvas.visibility    = 'hide';
   canvas.top           = this.y;
   canvas.left          = this.x;
   canvas.clip.right    = this.w;
   canvas.clip.bottom   = this.h;
   midAdjust = parseInt (midAdjustFS.substring (0, (midAdjustFS.length - 2)));
   midAdjust = parseInt (Math.floor (parseFloat (this.h - midAdjust) / 2.)) -
      (('Win' == 'Win')? 4 : 0);
   canvas.bgColor       = colors.buttonOff;
   canvas.visibility    = 'show';
   canvas.regText       = '<DIV class="regText">' + str + '</DIV>';
   canvas.overText      = '<DIV class="overText">' + str + '</DIV>';
   canvas.textLyr       = new Layer (this.w, canvas);
   var textLyr          = canvas.textLyr;
   textLyr.top = midAdjust;
   textLyr.document.write (this.canvas.regText);
   textLyr.document.close ();
   textLyr.visibility   = 'inherit';
   // mask layer
   canvas.maskLyr       = new Layer (this.w, canvas);
   var maskLyr          = canvas.maskLyr;
   maskLyr.clip.right   = (this.w + 1);
   maskLyr.clip.bottom  = (this.h + 1);
   maskLyr.visibility   = 'inherit';
   maskLyr.onmouseover  = mOver;
   maskLyr.onmouseout   = mOut;
   maskLyr.buttonName   = this.buttonName;
   maskLyr.link         = this.link;
   maskLyr.captureEvents (Event.MOUSEUP);
   maskLyr.onmouseup    = linkIt;
} // end fun makeButtonNS

function initButton (x, y, w, h, name, label, l) {
   this.x           = x;
   this.y           = y;
   this.w           = w;
   this.h           = h;
   this.buttonName  = name;
   this.buttonLabel = label;
   this.link        = l;
   if (IE) this.makeButton = makeButtonIE;
   else    this.makeButton = makeButtonNS;
} // end fun initButton

function initButtons () { // called to invoke buttoning system
   origHeight = (NS)? window.innerHeight : document.body.clientHeight;
   origWidth  = (NS)? window.innerWidth  : document.body.clientWidth;
   for (var i = 0; i < buttonList.length / 3; ++i) {
      var thisName  = buttonList[i*3];
      var thisLabel = buttonList[i*3+1];
      btn = Array ();
      if (document.images["button_"+thisName]) {
         var x  = (NS)? document.images["button_"+thisName].x + 1 : getX (document.all["button_"+thisName]);
         var y  = (NS)? document.images["button_"+thisName].y + 1 : getY (document.all["button_"+thisName]);
         var w  = document.images["button_"+thisName].width;
         var h  = document.images["button_"+thisName].height;
         btn[i] = new initButton (x, y, w, h, thisName, thisLabel, buttonList[i*3+2]);
         btn[i].makeButton ();
         if (NS) btn.visibility = 'show';
      } // end if
   } // end for
   lastButton = thisName;
   lastNdx    = (buttonList.length / 3) - 1;
} // end fun initButtons

function reinit () {
var needReload = false;
   if (NS) needReload = (origHeight != window.innerHeight || origWidth != window.innerWidth);
   if (IE) needReload = (origHeight != document.body.clientHeight || origWidth != document.body.clientWidth);
   origHeight = (NS)? window.innerHeight : document.body.clientHeight;
   origWidth  = (NS)? window.innerWidth : document.body.clientWidth;
   if (needReload) location.reload();
} // end fun reinit

   if (NS) window.captureEvents (Event.RESIZE);
   window.onresize = reinit;

// Clears form targets automatically when popup opens
function clearFormTargets () {
var theParent = window.opener;
   for (var i = 0; i < theParent.document.forms.length; i++)
      theParent.document.forms[i].target = '';
} // end fun clearFormTargets

if (this.window.name == "PopWin") clearFormTargets ();

// end  buttons.js

