/** DIV HANDLING FUNCTIONS ****************************************************/
// Dec 17, 2004 - v2: getDiv() now returns null if the element was not found.
//                    getX/getY() now correctly dynamically calculate the x and y.
//                    No longer supports w/h in %, which was buggy anyway.
//                    w/h variables replaced by getWidth() and getHeight().

function getDiv(divName)
{
  var div = null;
  if (DOM) div = new DOMDiv(divName);
  else if (IE4) div = new IE4Div(divName);
  else return null;
  if (div.div == null) return null;
  return div;
}

function DOMDiv(divName)
{
  this.div = document.getElementById(divName);
  if (this.div == null) return;
  this.name = divName;
  this.isHidden = false;

  this.move = function(x,y)
    {
      this.div.style.left = x;
      this.div.style.top = y;
    }
  this.resize = function(w,h)
    {
      this.div.style.width = w;
      this.div.style.height = h;
    }
  this.getX = function()
    {
      var div =  this.div;
      var x = div.offsetLeft; // though documented only for IE, it also works for NS6 and FF
      while (div.offsetParent != null)
      {
        div = div.offsetParent;
        x += div.offsetLeft;
      }
      return x;
    }
  this.getY = function()
    {
      var div =  this.div;
      var y = div.offsetTop;
      while (div.offsetParent != null)
      {
        div = div.offsetParent;
        y += div.offsetTop;
      }
      return y;
    }
  this.getWidth = function()
    {
      return this.div.offsetWidth;
    }
  this.getHeight = function()
    {
      return this.div.offsetHeight;
    }
  this.setContent = function(text)
    {
      var children = this.div.childNodes;
      for (var n=0; n<children.length; ++n)
      {
        this.div.removeChild(children[n]);
      }
      if (text == "")
      {
        var img = document.createElement("img");
        img.setAttribute("src","images/spacer.gif");
        img.setAttribute("width","10");
        this.div.appendChild(img);
      }
      else
      {
        this.div.appendChild(document.createTextNode(text));
      }
    }
  this.show = function()
    {
      this.div.style.display = "";
      this.isHidden = false;
    }
  this.hide = function()
    {
      this.div.style.display = "none";
      this.isHidden = true;
    }
}

function IE4Div(divName)
{
  this.div = document.all[divName];
  if (this.div == null) return;
  this.name = divName;
  this.isHidden = false;

  this.move = function(x,y)
    {
      this.div.style.left = x;
      this.div.style.top = y;
    }
  this.resize = function(w,h)
    {
      this.div.style.width = w;
      this.div.style.height = h;
    }
  this.getX = function()
    {
      var div =  this.div;
      var x = div.offsetLeft;
      while (div.offsetParent != null)
      {
        div = div.offsetParent;
        x += div.offsetLeft;
      }
      return x;
    }
  this.getY = function()
    {
      var div =  this.div;
      var y = div.offsetTop;
      while (div.offsetParent != null)
      {
        div = div.offsetParent;
        y += div.offsetTop;
      }
      return y;
    }
  this.getWidth = function()
    {
      return this.div.offsetWidth;
    }
  this.getHeight = function()
    {
      return this.div.offsetHeight;
    }
  this.setContent = function(text)
    {
      if (text == "") text = "&nbsp;";
      this.div.innerHTML = text;
    }
  this.show = function()
    {
      this.div.style.display = "";
      this.isHidden = false;
    }
  this.hide = function()
    {
      this.div.style.display = "none";
      this.isHidden = true;
    }
}
