
var isMSIE=0;

if (navigator.userAgent.indexOf("MSIE") != -1)
   { isMSIE = 1; }
else
   { isMSIE = 0; }

function ieVersion50()

{
if (isMSIE)
   {
   var s = navigator.userAgent;
   return ( (s.indexOf("MSIE 5.0") != -1) )
   }
else
   return false;
}

function ieTrueTop(AnElement)

{
var y=0;
while (AnElement)
   {
   y += AnElement.offsetTop;
   AnElement = AnElement.offsetParent;
   }
return y;
}

function ieTrueLeft(AnElement)

{
var x=0;
while (AnElement)
   {
   x += AnElement.offsetLeft;
   AnElement = AnElement.offsetParent;
   }
return x;
}

var MouseX;
var MouseY;

function MouseEvent(Evt)

{
  if (evt)
    {
    MouseX = evt.pageX;
    MouseY = evt.pageY;
    }
  else
    {
    MouseX = event.x;
    MouseY = event.y;
    }
}

function TrackMouse()

{
if (document.layers)
   document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = function (evt)
  {
  if (evt)
    {
    MouseX = evt.pageX;
    MouseY = evt.pageY;
    }
  else
    {
    MouseX = event.x;
    MouseY = event.y;
    }
  }
}


function InstallHideableCombos(DIVname,Hideable)

{
//if (isMSIE)
//   {
//   var ImageDIV = document.all[DIVname];
//   }
//else
//   {
//   var ImageDIV = document.layers[DIVname];
//   }

var ImageDIV = document.getElementById(DIVname);

if (ImageDIV)
   ImageDIV.HideCombos = Hideable;
}


var OpenDIVname;
var OpenIMGname;
var UseAutoClose=false;

function AutoClose()

{
if (!UseAutoClose) return;

if (OpenDIVname) RemoveImage(OpenDIVname,OpenIMGname);
}

function DoHideCombos(HideCombos)

{
if (HideCombos)
   {
   var i;
   var Item;

   for(i=0;i<HideCombos.length;i++)
      {
      Item = HideCombos[i];
      if (Item)
         Item.style.visibility = "hidden";
      }
   }
}

function DoShowCombos(HideCombos)

{
if (HideCombos)
   {
   var i;

   for(i=0;i<HideCombos.length;i++)
      {
      Item = HideCombos[i];
      if (Item)
         Item.style.visibility = "visible";
      }
   }
}

function PlaceImage(DIVname,IMGname)

{
var ImageDIV;
var ImageAnchor;
var HideCombos;

AutoClose();

OpenDIVname = DIVname;
OpenIMGname = IMGname;

//if (isMSIE)

   {
   //ImageDIV            = document.all[DIVname];
   //ImageAnchor         = document.all[IMGname];
   ImageDIV            = document.getElementById(DIVname);
   ImageAnchor         = document.getElementById(IMGname);
   if (!ImageAnchor)
      {
      alert(IMGname+" not found.");
      return;
      }
   else if (ImageDIV)
      {
      ImageDIV.style.top  = ieTrueTop(ImageAnchor);
      ImageDIV.style.left = ieTrueLeft(ImageAnchor);
      ImageDIV.style.visibility = "visible";
      }
   else
      {
      alert(DIVname+" not found.");
      return;
      }
   }

//else
//   {
//   ImageDIV   = document.layers[DIVname];
//   ImageDIV.y = document.images[IMGname].y;
//   ImageDIV.x = document.images[IMGname].x;
//   ImageDIV.visibility = "visible";
//   }

HideCombos = ImageDIV.HideCombos;
DoHideCombos(HideCombos);
}

function PlaceImageLeft(DIVname,IMGname)

{
PlaceImage(DIVname,IMGname)
}


function PlaceImageRight(DIVname,IMGname)

{
var ImageDIV;
var ImageAnchor;

AutoClose();

OpenDIVname = DIVname;
OpenIMGname = IMGname;

//if (isMSIE)

   {
   //ImageDIV            = document.all[DIVname];
   //ImageAnchor         = document.all[IMGname];
   ImageDIV            = document.getElementById(DIVname);
   ImageAnchor         = document.getElementById(IMGname);
   if (!ImageAnchor)
      {
      alert(IMGname+" not found.");
      return;
      }
   else if (ImageDIV)
      {
      ImageDIV.style.top  = ieTrueTop(ImageAnchor);
      ImageDIV.style.left = ieTrueLeft(ImageAnchor) - ImageDIV.offsetWidth - 2;
      ImageDIV.style.visibility = "visible";
      }
   else
      {
      alert(DIVname+" not found.");
      return;
      }
   }

//else
//   {
//   ImageDIV   = document.layers[DIVname];
//   ImageDIV.y = document.images[IMGname].y;
//   ImageDIV.x = document.images[IMGname].x - ImageDIV.clip.width - 2;
//   ImageDIV.visibility = "visible";
//   }

}

function RemoveImage(DIVname,IMGname)

{
var ImageDIV;
var HideCombos;

//if (isMSIE)

   {
   //ImageDIV = document.all[DIVname];
   ImageDIV = document.getElementById(DIVname);
   if (ImageDIV)
      {
      ImageDIV.style.visibility = "hidden";
      ImageDIV.style.origTop = ImageDIV.style.top;
      ImageDIV.style.top = -1000;
      }
   }

//else
//   {
//   ImageDIV   = document.layers[DIVname];
//   if (ImageDiv)
//      ImageDIV.visibility = "hidden";
//   }

HideCombos = ImageDIV.HideCombos;
DoShowCombos(HideCombos);
}

function ShowFloatingWindow(DIVname,IMGname)

{
PlaceImage(DIVname, IMGname);
}

function CloserButtonClick(DIVname)

{
RemoveImage(DIVname,"");
}

//////////////////////////////////////////////////////////////////////////////

function TimeNow()

{
//Used to defeat browser caching...

var d = new Date();
return d.getTime();
}

function TimeNowParam()

{
return "~"+TimeNow();
}

var
   WLWopen = false;

//////////////////////////////////////////////////////////////////////////////

function FourDecPlaces(Nbr)

{
var p=Math.round(Nbr*10000);
var n=(p < 0 ? "-" : " ");
var s=new String(Math.abs(p));
while (s.length < 4)
   s = "0" + s;
var i=s.length-4;
var fd = new String(s.substring(0,i)+'.'+s.substring(i,i+4));
if (fd.substring(0,1)==".")
   fd = "0"+fd;
return (n+fd);
}

function TwoDecPlaces(Nbr)

{
var s=new String(Math.round(Nbr*100));
var i=s.length-2;
var td=new String(s.substring(0,i)+'.'+s.substring(i,i+2));
if ( (td.length==2) && (td.substring(0,1)==".") )
   td = "0"+td+"0"
else if (i==0)
   td = "0" + td;

return (td);
}

function ThouSep(Nbr)

{
var s=new String(Nbr);
var i=s.indexOf(".");
if (i==-1) i = s.length;
if (i < 4) return s;

var c="";
var i,j;
var r=new String(s.substr(i,s.length));
while (i != 0)
   {
   j = i;
   i = (i < 3) ? 0 : i-3;
   r = s.substr(i,j-i) + c + r;
   c = ",";
   }
return r;
}

//////////////////////////////////////////////////////////////////////////////

function GoWebLinkWindow(AURL)
   {
   var wlw = window.open("","wlw");
   if (WLWopen)
      {
      wlw.blur();
      wlw.focus();
      }
   else
      {
      WLWopen = true;
      }

   wlw.location = AURL;
   }

//////////////////////////////////////////////////////////////////////////////

var LastWasNumber;
var FocusChangeOnEnter;

function isNumber(n)
{
return (LastWasNumber = !isNaN(n/1))
}

function EditKeyDown(AnEdit)

{
if (!isMSIE) return;

if (event.keyCode == 13)
   {
   FocusChangeOnEnter = true;
   event.keyCode = 9;
   }
}

function ComboKeyDown(AnEdit)

{
if (!isMSIE) return;

if (event.keyCode == 13)
   {
   FocusChangeOnEnter = true;
   event.keyCode = 9;
   }
}

//////////////////////////////////////////////////////////////////////////////

function FieldOf(AName)

{
//return (document.all[AName]);
return (document.getElementById(AName));

}

function NextFieldAfter(AField)

{
var Next;

if (AField.NextField)
   {
   Next = AField.NextField;
   while ( (Next) && (Next.type=="hidden") )
     {
     Next = Next.NextField;
     }

   return Next;
   }

//alert("Slow way!");

var AForm=AField.form;
var Look;

for(var e=0; e<AForm.elements.length; e++)
  {
  Look = AForm.elements[e];
  if (AField==Look)
    break;
  }

do
  {
  Next = AForm.elements[++e % AForm.elements.length];
  }
while (Next.type=="hidden");

return Next;
}

var ConnectingForm;
var StartElement=0;

function ConnectFieldsSubSet()

{
var n=25;
var AField1,AField2;
var e,e2;

for(e=StartElement; ((e<ConnectingForm.elements.length)&&(n)); e++)
  {
  n--;
  AField1 = ConnectingForm.elements[e];
  AField2 = ConnectingForm.elements[(e+1) % ConnectingForm.elements.length];
  AField1.NextField = AField2;
  }

StartElement = ++e;
if (e<ConnectingForm.elements.length)
   setTimeout("ConnectFieldsSubSet();",500);
}

function ConnectFields(AFormName)

{
//ConnectingForm=document.all[AFormName];
ConnectingForm=document.getElementById(AFormName);
ConnectFieldsSubSet();
}

//////////////////////////////////////////////////////////////////////////////
//Requires calendar.js

function PickDate(AField,ATitle)

{
var F=document.all[AField];
var T=MouseY;
var L=MouseX;
setDateField(F,ATitle,2002,2099);
if ((L+215) > screen.width)
   L -= 240;

top.newWin = window.open("","cal","dependent=yes,width=215,height=200,left="+L+",top="+T+",titlebar=yes");
top.newWin.document.write(calendarDoc);
top.newWin.focus();
}

//////////////////////////////////////////////////////////////////////////////

var
   PoppedUp = 0;
   HidableCombos = new Array();

function RegisterHidableCombo(ACombo)

{
HidableCombos[HidableCombos.length] = ACombo;
}

function BeforePopupMenu()

{
var i;
for(i=0;i<HidableCombos.length;i++)
   HidableCombos[i].style.visibility = "hidden";
}

function AfterPopupMenu()

{
var i;
for(i=0;i<HidableCombos.length;i++)
   HidableCombos[i].style.visibility = "visible";
}

function MenuShowing(show,state)

{
if (show && (state == 'visible')) return;
if (!show && (state == 'hidden')) return;
if (!PoppedUp) BeforePopupMenu();
(show) ? PoppedUp++ : PoppedUp--;
if (!PoppedUp) AfterPopupMenu();
}

//////////////////////////////////////////////////////////////////////////////

function FormControl(ControlName,FormName)

{
if (isMSIE)
   return document.all[ControlName];
else
   return document.forms(FormName).elements(ControlName)
}


function FormObject(FormName)

{
if (isMSIE)
   return document.all[FormName];
else
   return document.forms(FormName)
}


//////////////////////////////////////////////////////////////////////////////

function CreateShortcut(url,title)

{
if (window.external)
  {
  window.external.AddFavorite(url,title);
  }
}

//////////////////////////////////////////////////////////////////////////////

function GetCookie(name)
{
  var result = null;
  var myCookie = " " + document.cookie + ";";
  var searchName = " " + name + "=";
  var startOfCookie = myCookie.indexOf(searchName);
  var endOfCookie;
  if (startOfCookie != -1) {
    startOfCookie += searchName.length; //skip past cookie name
    endOfCookie = myCookie.indexOf(";", startOfCookie);
    result = unescape(myCookie.substring(startOfCookie, endOfCookie));
  }
  return result;
}

////////

function SetCookie (name, value, expires, path, domain, secure)
{
  var expString = ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
  var pathString = ((path == null) ? "" : ("; path=" + path));
  var domainString = ((domain == null) ? "" : ("; domain=" + domain));
  var secureString = ((secure == true) ? "; secure" : "");

  document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}

function SetPermanentCookie (name, value, path, domain, secure)
{
  var Forever = new Date();
  
  Forever.setTime(Forever.getTime()+(365*24*60*60*1000));
  
  SetCookie(name, value, Forever, path, domain, secure);
}

//////////////////////////////////////////////////////////////////////////////

