/******************************************************************************/
/*                                                                            */
/* GENERAL INFORMATION                                                        */
/*                                                                            */
/* kx_library.js - Common DHTML Routines                                      */
/*                                                                            */
/* (C) Copyright 2003 - 2005, Keropac Computing.  All rights reserved.        */
/*                                                                            */
/* Provides common DHTML functions and routines.  The Common Javascript file  */
/* kx_common.js must be included so that the various variable are set         */
/* depending on the browser being used and it's settings and abilities.       */
/*                                                                            */
/* MODIFICATIONS                                                              */
/*                                                                            */
/* Ref.  By    Date    Description                                            */
/* ----  --    ----    -----------                                            */
/* @001  KP  28/07/05  Added the clipElement function.                        */
/* @002  KP  24/08/05  Changes to the getPage functions.                      */
/* @003  KP  24/08/05  Added the getElementStyle function.                    */
/* @004  KP  09/05/08  Added "display" controls like "visibility".            */
/*                                                                            */
/******************************************************************************/

<!-- Begin

// ---------------------------------------------------------------------------
// Element and style object.
// ---------------------------------------------------------------------------

function getElement(elementName)
{
  if (isDOM)
    return document.getElementById(elementName);

  if (isDocAll)
    return document.all(elementName);

  if (isLayers)
    return findLayer(document, elementName);
}

// For Layers we have to find the object.

function findLayer(doc, name) 
{
  var x = doc.layers;
  var foundLayer;

  for (var i = 0; i < x.length; i++)
  {
    if (x[i].id == name)
      foundLayer = x[i];
    else if 
      (x[i].layers.length)

    var tmp = findLayer(x[i],name);
    if (tmp) 
      foundLayer = tmp;
  }

  return foundLayer;
}

// @003 - Start of modification.

// Get the style of an object.

function getElementStyle(elementName)
{
  if (isLayers)
    return findLayer(document, elementName);

  if (isDocAll && document.all(elementName))
    return document.all(elementName).style;

  if (isDOM && document.getElementById(elementName))
    return document.getElementById(elementName).style;
}

// Get the style of an element 
// (i.e. the getElement function has been used to store the element in a variable)

function getStyle(elementName)

{
  if (isLayers)
    return elementName;

  if ((isDocAll) || (isDOM))
    return elementName.style;
}

// @003 - End of modification.

// ---------------------------------------------------------------------------
// Element height and width.
// ---------------------------------------------------------------------------

function getElementWidth(elementName)
{
  if (isLayers)
  {
    if (elementName.document.width)
      return (elementName.document.width);
    else
      return (elementName.clip.right - elementName.clip.left);
  }

  if ((isDocAll) || (isDOM))
  {
    if (elementName.style.width)
      return (parseInt(elementName.style.width));
    else
      return (parseInt(elementName.offsetWidth));
  }
}

function getElementHeight(elementName)
{
  if (isLayers)
  {
    if (elementName.document.height)
      return (elementName.document.height);
    else
      return (elementName.clip.bottom - elementName.clip.top);
  }

  if ((isDocAll) || (isDOM))
  {
    if (false && elementName.style.height)
      return (parseInt(elementName.style.height));
    else
      return (parseInt(elementName.offsetHeight));
  }
}

// ---------------------------------------------------------------------------
// Element positions.
// ---------------------------------------------------------------------------

function getElementLeft(elementName)
{
  if (isLayers)
    return (elementName.left);

  if ((isDocAll) || (isDOM))
    return (parseInt(elementName.style.left));
}

function getElementRight(elementName)
{
  if (isLayers)
    return (elementName.left + getElementWidth(elementName));

  if ((isDocAll) || (isDOM))
    return (parseInt(elementName.style.right + getElementWidth(elementName)));
}

function getElementTop(elementName)
{
  if (isLayers)
    return (elementName.top);

  if ((isDocAll) || (isDOM))
    return (parseInt(elementName.style.top));
}

function getElementBottom(elementName)
{
  if (isLayers)
    return (elementName.top + getElementHeight(elementName));

  if ((isDocAll) || (isDOM))
    return (parseInt(elementName.style.top) + getElementHeight(elementName));
}

// ---------------------------------------------------------------------------
// Element visibility.
// ---------------------------------------------------------------------------

function hideElement(elementName)
{
  if (elementName.visibility)
    elementName.visibility = "hide";

  else if (elementName.style.visibility)
    elementName.style.visibility = "hidden";
}

function showElement(elementName)
{
  if (elementName.visibility)
    elementName.visibility = "show";

  else if (elementName.style.visibility)
    elementName.style.visibility = "visible";
}

function getVisibility(elementName)
{
  if (elementName.visibility != null)
  {
    if (elementName.visibility == "show")
      return "visible";
    if (elementName.visibility == "hide")
      return "hidden";
    return elementName.visibility;
  }

  if (elementName.style.visibility != null)
    return elementName.style.visibility;
}

function isVisible(elementName)
{
  if (elementName.visibility != null)
  {
    if (elementName.visibility == "show")
    return(true);
       
    return(false);
  }

  if (elementName.style.visibility != null)
  {
    if (elementName.style.visibility == "visible")
      return(true);

    return(false);
  }

  return(false);

}

// @004 - Start of modification.

// ---------------------------------------------------------------------------
// Element display.
// ---------------------------------------------------------------------------

function nonDisplayElement(elementName)
{
  if (elementName.style.display == "")
  {
    elementName.style.display = "none";
  }
}

function displayElement(elementName)
{
  if (elementName.style.display)
    elementName.style.display = "";
}

function getDisplay(elementName)
{
  if (elementName.style.display != null)
    return elementName.style.visibility;
}

function isDisplay(elementName)
{
  if (elementName.style.display != null)
  {
    if (elementName.style.display == "")
      return(true);

    return(false);
  }

  return(false);
}

// @004 - End of modification.

// ---------------------------------------------------------------------------
// Element positions on the page.
// ---------------------------------------------------------------------------

function getPageLeft(elementName)
{
  var posLeft;

  if (elementName.pageX)
    return (elementName.pageX);

// @002 - Start of modification.

// *DEL*  posLeft = 0;

// *DEL*  while(elementName.offsetParent != null)
// *DEL*  {
// *DEL*    posLeft += elementName.offsetLeft;
// *DEL*    elementName = elementName.offsetParent;
// *DEL*  }

// *DEL*  posLeft += elementName.offsetLeft;

  posLeft = elementName.offsetLeft;
  tempEL = elementName.offsetParent;

  while(tempEL != null)
  {
    posLeft += tempEL.offsetLeft;
    tempEL = tempEL.offsetParent;
  }

// @002 - End of modification.

  return (posLeft);
}

function getPageTop(elementName)
{
  var posTop;

  if (elementName.pageY)
    return (elementName.pageY);

// @002 - Start of modification.

// *DEL*  posTop = 0;

// *DEL*  while(elementName.offsetParent != null)
// *DEL*  {
// *DEL*    posTop += elementName.offsetTop;
// *DEL*    elementName = elementName.offsetParent;
// *DEL*  }

// *DEL*  posTop += elementName.offsetTop;

  posTop = elementName.offsetTop;
  tempEL = elementName.offsetParent;

  while(tempEL != null)
  {
    posTop += tempEL.offsetTop;
    tempEL = tempEL.offsetParent;
  }

// @002 - End of modification.

  return (posTop);
}

// ---------------------------------------------------------------------------
// Moving an element.
// ---------------------------------------------------------------------------

function moveElementBy(elementName, vOffset, hOffset)
{

  if (isDOM)
  {
    if (vOffset != 0)
      elementName.style.top = parseInt(elementName.style.top) + vOffset + bwPX;
      
    if (hOffset != 0)
      elementName.style.left = parseInt(elementName.style.left) + hOffset + bwPX;
  }

  else if (isDocAll)
  {
    if (vOffset != 0)
      elementName.style.pixelTop += vOffset;

    if (hOffset != 0)
      elementName.style.pixelLeft += hOffset;
  }

  else if (isLayers)
  {
    if (vOffset != 0)
      elementName.top += vOffset;

    if (hOffset != 0)
      elementName.left += hOffset;
  }

}

function moveElementTo(elementName, topPos, leftPos)
{

  if (isDOM)
  {
    elementName.style.top = topPos + bwPX;
    elementName.style.left = leftPos + bwPX;
  }

  else if (isDocAll)
  {
    elementName.style.pixelTop = topPos;
    elementName.style.pixelLeft = leftPos;
  }

  else if (isLayers)
  {
    elementName.top = topPos;
    elementName.left = leftPos;
  }

}

// @001 - Start of modification. //

// ---------------------------------------------------------------------------
// Element clipping.
// ---------------------------------------------------------------------------

function clipElement(elementName, top, right, bottom, left)

{
  if (isLayers)
  {
    elementName.clip.top = top;
    elementName.clip.right = right; 
    elementName.clip.bottom = bottom;
    elementName.clip.left = left;
  }
  else
  {
    if (top < 0) top = 0;
    if (right < 0) right = 0;
    if (bottom < 0) bottom = 0;
    if (left < 0) left = 0; 
    elementName.style.clip = "rect(" + top + bwPX + "," + right + bwPX + "," + bottom + bwPX + "," + left + bwPX + ")";
  }
}

// @001 - End of modification. //

// ---------------------------------------------------------------------------
// Window height and width.
// ---------------------------------------------------------------------------

function getWindowHeight()
{
  if (isDocElem && document.documentElement.clientHeight)
    return (document.documentElement.clientHeight);

  if (isBody && document.body.clientHeight)
    return (document.body.clientHeight);

  if (typeof(window.innerHeight) == 'number')
    return (window.innerHeight);

  return -1;
}

function getWindowWidth()
{
  if (isDocElem && document.documentElement.clientWidth)
    return (document.documentElement.clientWidth);

  if (isBody && document.body.clientWidth)
    return (document.body.clientWidth);

  if (typeof(window.innerWidth) == 'number')
    return (window.innerWidth);

  return -1;
}

// ---------------------------------------------------------------------------
// Page (BODY) height and width.
// ---------------------------------------------------------------------------

function getPageHeight()
{
  if (isDocElem && document.documentElement.scrollHeight)
    return (document.documentElement.scrollHeight);

  if (isDocElem && document.documentElement.offsetHeight)
    return (document.documentElement.offsetHeight);

  if (isBody && document.body.scrollHeight)
    return (document.body.scrollHeight);

  if (typeof(document.height) == 'number')
    return (document.height);

  return -1;
}

function getPageWidth()
{
  if (isDocElem && document.documentElement.scrollWidth)
    return (document.documentElement.scrollWidth);

  if (isDocElem && document.documentElement.offsetWidth)
    return (document.documentElement.offsetWidth);

  if (isBody && document.body.scrollWidth)
    return (document.body.scrollWidth);

  if (typeof(document.width) == 'number')
    return (document.width);

  return -1;
}

// End -->