function JsUtil() {
}

JsUtil.getLeft = function (node) {
  if (node.x !== undefined) {
    return node.x;
  } else if (node.offsetLeft !== undefined) {
    if (node.offsetParent) {
      return node.offsetLeft + JsUtil.getLeft(node.offsetParent);
    }
    else {
      return node.offsetLeft;
    }
  } else {
    throw "JsUtil.getLeft: Can't figure out how to work with this browser.";
  }
};

JsUtil.getTop = function (node) {
  if (node.y !== undefined) {
    return node.y;
  } else if (node.offsetTop !== undefined) {
    if (node.offsetParent) {
      return node.offsetTop + JsUtil.getTop(node.offsetParent);
    }
    else {
      return node.offsetTop;
    }
  } else {
    throw "JsUtil.getTop: Can't figure out how to work with this browser.";
  }
};

JsUtil.getWidth = function (node) {
  if (node.offsetWidth !== undefined ) {
    return node.offsetWidth;
  } else if (node.clientWidth !== undefined ) {
    return node.clientWidth;
  } else if (node.width !== undefined ) {
    return node.width;
  } else {
	  throw "JsUtil.getWidth: Can't figure out how to work with this browser.";
  }
};

JsUtil.getHeight = function (node) {
  if (node.offsetHeight !== undefined ) {
    return node.offsetHeight;
  } else if (node.clientHeight !== undefined ) {
    return node.clientHeight;
  } else if (node.height !== undefined ) {
    return node.height;
  } else {
	  throw "JsUtil.getHeight: Can't figure out how to work with this browser.";
  }
};

/**
 * Set the position of a Node to the specified coordinates.
 * @param node the Node to set the position of
 * @param x the horizontal position
 * @param y the vertical position
 */
JsUtil.setPosition = function (node, x, y) {
  if (node.style.left !== undefined) {
    node.style.left = x + 'px';
    node.style.top = y + 'px';
  } else if (node.style.pixelLeft !== undefined) {
    node.style.pixelLeft = x;
    node.style.pixelTop = y;
  } else {
	  throw "JsUtil.setPosition: Can't figure out how to work with this browser.";
  }
};

/**
 * Find the first node within a parent node which matches the specified tag name
 * and name.
 * @param parentNode the Node to look in
 * @param tagName a string containing the tag name of the node to find
 * @param name a string containing the name of the node to find
 */
JsUtil.findNode = function(parentNode, tagName, name) {
  var nodes = parentNode.getElementsByTagName(tagName.toUpperCase());
  for (var i = 0, node; (node = nodes[i]); i++) {
    if (node.getAttribute('name') == name) {
      return node;
    }
  }
  return null;
};

JsUtil.findParentByTagName = function(node, tagName) {
  tagName = tagName.toUpperCase();
  while (node && node.tagName != tagName) {
    node = node.parentNode;
  }
  return node;
};

JsUtil.findParentByName = function(node, name) {
  while (node && node.getAttribute('name') != name) {
    node = node.parentNode;
  }
  return node;
};

JsUtil.getScrollLeft = function() {
  var doc = self.document;

  if (self.pageXOffset) {
    // all except Explorer
    return self.pageXOffset;
  } else if (doc.documentElement && doc.documentElement.scrollLeft) {
    // Explorer 6 Strict
    return doc.documentElement.scrollLeft;
  } else {
    // all other Explorers
    return doc.body.scrollLeft;
  }
};

JsUtil.getScrollTop = function() {
  var doc = self.document;

  if (self.pageYOffset) {
    // all except Explorer
    return self.pageYOffset;
  } else if (doc.documentElement && document.documentElement.scrollTop) {
    // Explorer 6 Strict
    return doc.documentElement.scrollTop;
  } else {
    // all other Explorers
    return doc.body.scrollTop;
  }
};

JsUtil.getViewportWidth = function() {
  var doc = self.document;

  if (self.innerWidth) {
    // all except IE
    return self.innerWidth;
  } else if (doc.documentElement && doc.documentElement.clientWidth) {
    // IE6 strict
    return Math.min(doc.documentElement.clientWidth, doc.body.clientWidth);
  } else {
    // other IE
    return doc.body.clientWidth;
  }
};

JsUtil.getViewportHeight = function() {
  var doc = self.document;

  if (self.innerHeight) {
    // all except IE
    return self.innerHeight;
  } else if (doc.documentElement && doc.documentElement.clientHeight) {
    // IE6 strict
    return Math.min(doc.documentElement.clientHeight, doc.body.clientHeight);
  } else {
    // other IE
    return doc.body.clientHeight;
  }
};

