//--------------------------------------------------------------------------------------------
// Layer utilities.
//--------------------------------------------------------------------------------------------
//Function gets the layer for the passed name.
function FI_fcnGetLayer(a_strLayerName)
{
  if (FI_IS_NS4)
    return FI_fcnFindLayer(a_strLayerName, document);

  if (FI_IS_NS6)
    return document.getElementById(a_strLayerName);

  if (FI_IS_IE)
    return eval('document.all.' + a_strLayerName);

  return null;
}

//Function finds the layer from the document object model.
function FI_fcnFindLayer(a_strLayerName, a_objDocument)
{
  var intCount;
  var objLayer;

  for (intCount = 0; intCount < a_objDocument.layers.length; intCount++)
  {
    objLayer = a_objDocument.layers[intCount];
    if (objLayer.name == a_strLayerName)
      return objLayer;
    if (objLayer.document.layers.length > 0)
    {
      objLayer = FI_fcnFindLayer(a_strLayerName, objLayer.document);
      if (objLayer != null)
        return objLayer;
    }
  }
  return null;
}

//--------------------------------------------------------------------------------------------
// Layer visibility.
//--------------------------------------------------------------------------------------------
//This function hides the layer.
function FI_fcnHideLayer(a_objLayer)
{
  if (FI_IS_NS4)
    a_objLayer.visibility = "hide";

  if (FI_IS_IE || FI_IS_NS6)
    a_objLayer.style.visibility = "hidden";
}

//This function displays the layer.
function FI_fcnShowLayer(a_objLayer)
{
  if (FI_IS_NS4)
    a_objLayer.visibility = "show";

  if (FI_IS_IE || FI_IS_NS6)
    a_objLayer.style.visibility = "visible";
}

//--------------------------------------------------------------------------------------------
// Layer positioning.
//--------------------------------------------------------------------------------------------
//Function moves a layer to the passed coordinates.
function FI_fcnMoveLayerTo(a_objlayer, a_intXAxis, a_intYAxis)
{
  if (FI_IS_NS4)
    a_objlayer.moveTo(a_intXAxis, a_intYAxis);

  if (FI_IS_IE || FI_IS_NS6)
  {
    a_objlayer.style.left = a_intXAxis;
    a_objlayer.style.top = a_intYAxis;
  }
}

//Function moves layer and then displays the layer.
function FI_fcnMoveToShow(a_strLayerName, a_intXAxis, a_intYAxis)
{
  FI_fcnMoveLayerTo(FI_fcnGetLayer(a_strLayerName), a_intXAxis, a_intYAxis);
  FI_fcnShowLayer(FI_fcnGetLayer(a_strLayerName));

  // sets a visibility flag to 1
  eval(a_strLayerName + "vis = 1");
}

//Function moves layer and then hides the layer.
function FI_fcnMoveToHide(a_strLayerName, a_intXAxis, a_intYAxis)
{
  FI_fcnMoveLayerTo(FI_fcnGetLayer(a_strLayerName), a_intXAxis, a_intYAxis);
  FI_fcnHideLayer(FI_fcnGetLayer(a_strLayerName));

  // sets a visibility flag to 0
  eval(name + "vis = 0");
}

//Function moves the passed layer to new coordinates.
function FI_fcnMoveLayerBy(a_objLayer, a_intXPixels, a_intYPixels)
{
  var intXSpot;
  var intYSpot;

  if (FI_IS_NS4)
    a_objLayer.moveBy(a_intXPixels, a_intYPixels);

  if (FI_IS_NS6)
  {
    intXSpot = parseInt(a_objLayer.style.left);
    intYSpot = parseInt(a_objLayer.style.top);

    intXSpot += a_intXPixels;
    intYSpot += a_intYPixels;

    a_objLayer.style.left = intXSpot;
    a_objLayer.style.top  = intYSpot;
  }

  if (FI_IS_IE)
  {
    a_objLayer.style.pixelLeft += a_intXPixels;
    a_objLayer.style.pixelTop  += a_intYPixels;
  }
}

//Function gets the left side coordinate of the passed layer.
function FI_fcnGetLeft(a_objLayer)
{
  if (FI_IS_NS4)
    return(a_objLayer.left);

  if (FI_IS_NS6)
    return(parseInt(a_objLayer.style.left));

  if (FI_IS_IE)
    return(a_objLayer.style.pixelLeft);

  return(-1);
}

//Function gets the top side coordinate of the passed layer.
function FI_fcnGetTop(a_objLayer)
{
  if (FI_IS_NS4)
    return(a_objLayer.top);

  if (FI_IS_NS6)
    return(parseInt(a_objLayer.style.top));

  if (FI_IS_IE)
    return(a_objLayer.style.pixelTop);

  return(-1);
}

//--------------------------------------------------------------------------------------------
// Gathering Image coordinates.
//--------------------------------------------------------------------------------------------
// Obtain X coordinate of imageName
function FI_fcnFindX(a_strImageName)
{
  var objImage;
  var intCount;
  var intTotal;

  objImage = document.images[a_strImageName]
  if (FI_IS_NS4)
  {
    // Test for image in document object
    if (document.images[a_strImageName])
    {
      return eval(objImage).x
    }
    // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)
    else
    {
      for (intCount = 0; intCount < document.layers.length; intCount++)
      {
        if (document.layers[intCount].document.images[a_strImageName])
        {
          intTotal = document.layers[intCount].left + document.layers[intCount].document.images[a_strImageName].x;
          return intTotal;
        }
      }
    }
  }
  else
  {
    return FI_fcnGetXPosition(objImage);
  }
}

//Get X Coordinate by a different mean.
function FI_fcnGetXPosition(a_objImage)
{
  var intXPosition;
  var objTemp;

  intXPosition = eval(a_objImage).offsetLeft;
  objTemp = eval(a_objImage).offsetParent;

  while (objTemp != null)
  {
    intXPosition += objTemp.offsetLeft;
    objTemp = objTemp.offsetParent;
  }
  return intXPosition;
}

// Obtain Y coordinate of imageName
function FI_fcnFindY(a_strImageName)
{
  var objImage;
  var intCount;
  var intTotal;

  objImage = document.images[a_strImageName];
  if (FI_IS_NS4)
  {
     // Test for image in document object
    if (document.images[a_strImageName])
    {
      return eval(objImage).y;
    }
    // Fix for Netscape 4 div bug - find image in document.layers object instead (will NOT work for nested divs)
    else
    {
      for (intCount = 0; intCount < document.layers.length; intCount++)
      {
        if (document.layers[intCount].document.images[a_strImageName])
        {
          intTotal = document.layers[intCount].top + document.layers[intCount].document.images[a_strImageName].y;
          return intTotal;
        }
      }
    }
  }
  else
  {
    return FI_fcnGetWindowWidth(objImage);
  }
}

//Get Y Coordinate by a different mean.
function FI_fcnGetWindowWidth(a_objImage)
{
  var intYPosition;
  var objTemp;

  intYPosition = eval(a_objImage).offsetTop;
  objTemp = eval(a_objImage).offsetParent;
  while (objTemp != null)
  {
    intYPosition += objTemp.offsetTop;
    objTemp = objTemp.offsetParent;
  }
  return intYPosition;
}

