/**************************************
* Copyright (c) 2001,2002 Blackfire Internet Solutions, Inc. All rights reserved.
**************************************/

function loadImageCache(image_sources)
{
  var ImageCache = new Array(image_sources.length);

  for (var i = 0; i < ImageCache.length; ++i)
  {
    ImageCache[i]     = new Image;
    ImageCache[i].src = image_sources[i];
  }

  return ImageCache;
}

function imageToggle(image, images, caption, captions)
{
  if (images.length >= 2)
  {
    var img = images[image.src == images[0].src ? 1 : 0];

    image.src     = img.src;
    image.width   = img.width;
    image.height  = img.height;
  }

  if (captions && captions.length >= 2)
    imageToggle(caption, captions);
}

function wait(milliseconds)
{
  var curTime = new Date;
  var stopTime = new Date;

  stopTime.setMilliseconds(curTime.getMilliseconds() + milliseconds);
  while (curTime = new Date, curTime < stopTime)
    ;
}

function getFormElement(name)
{
  return document.forms[0].elements(name);
}

function footer(prompts, links, copyright, doc)
{
  if (!doc)
    doc = document;

  var html = "";
  var anchor;

  for (var i = 0; i < prompts.length; ++i)
    if (prompts[i] == '\n')
      html += "<br>";
    else
      if (links[i] == "")
        html += prompts[i];
      else
      {
        anchor = new bisAnchor(prompts[i], links[i]);
        //anchor.target = "main";
        html += "[" + anchor + "]";
      }

  html += new bisParagraph(copyright);

  html += "Website designed by ";
  anchor = new bisAnchor("Blackfire Internet Solutions, Inc.", "http://www.blackfireinternetsolutions.net");
  anchor.target = "_blank";
  html += anchor;

  var div = new bisDiv(html);

  div.style.font.family = "arial";
  div.style.font.size   = "smaller";
  div.style.font.color  = "black";
  div.style.align       = "center";
  doc.writeln("<hr>");
  doc.writeln(div);
}

function windowWidth()
{
  var width;

  if (!isBrowserNS4())
    width = document.body.clientWidth;
  else
    width = window.innerWidth;

  return width;
}

function windowHeight()
{
  var height;

  if (!isBrowserNS4())
    height = document.body.clientHeight;
  else
    height = window.innerHeight;

  return height;
}

function fade(oElement, bOut)
{
  if (isBrowserNS())
    if (bOut)
      visibilityHide(oElement);
    else
      visibilityShow(oElement);
  else
  {
    oElement.style.filter = "blendTrans(duration=2)";

    // Make sure the filter is not playing.
    if (oElement.filters.blendTrans.status != 2)
    {
      oElement.filters.blendTrans.apply();
      if (bOut)
        visibilityHide(oElement);
      else
        visibilityShow(oElement);

      oElement.filters.blendTrans.play();
    }
  }
}

function revealTrans(oElement, bOut, transition)
{
  if (isBrowserNS())
    if (bOut)
      visibilityHide(oElement);
    else
      visibilityShow(oElement);
  else
  {
    oElement.style.filter = "revealTrans(duration=2,transition=" + transition + ")";

    // Make sure the filter is not playing.
    if (oElement.filters.revealTrans.status != 2)
    {
      oElement.filters.revealTrans.apply();
      if (bOut)
        visibilityHide(oElement);
      else
        visibilityShow(oElement);

      oElement.filters.revealTrans.play();
    }
  }
}

function setTarget(sTarget)
{
  return "top.main.location='" + sTarget + "'";
}

function isArray(object)
{
  return object[0] != null;
}

function styleVisibility(oElement, visibility)
{
  var curVisibility;

  if (oElement.style)       // HTML object
  {
    if (visibility)
      oElement.style.visibility = visibility;
    curVisibility = oElement.style.visibility;
  }
  if (oElement.visibility)  // layer object
  {
    if (visibility)
      oElement.visibility = visibility;
    curVisibility = oElement.visibility;
  }

  return curVisibility;
}

function visibilityShow(oElement)
{
  styleVisibility(oElement, typeof(oElement) == "Layer" ? "show" : "visible");
}

function visibilityHide(oElement)
{
  styleVisibility(oElement, typeof(oElement) == "Layer" ? "hide" : "hidden");
}

function styleDisplay(oElement, display)
{
  var curDisplay;

  if (oElement.visibility)  // layer object
    curDisplay = styleVisibility(oElement, display);

  if (oElement.style)       // HTML object
  {
    if (display)
      oElement.style.display = display;
    curDisplay = oElement.style.display;
  }

  if (oElement.display)     // NS4 CSS object
  {
    if (display)
      oElement.display = display;
    curDisplay = oElement.display;
  }

  return curDisplay;
}

function displayToggle(oElement)
{
  if (isArray(oElement))
    for (var i = 0; i < oElement.length; ++i)
      displayToggle(oElement[i]);
  else
    if (isDisplayRendered(oElement))
      displayNoRender(oElement);
    else
      displayRender(oElement);
}

function isDisplayRendered(oElement)
{
  var curDisplay = styleDisplay(oElement);

  return curDisplay == "show" || curDisplay == "block";
}

function displayRender(oElement)
{
  return styleDisplay(oElement, oElement.visibility ? "show" : "block");
}

function displayNoRender(oElement)
{
  return styleDisplay(oElement, oElement.visibility ? "hide" : "none");
}
