// File: util.js
// This file contains a number of utilities that are used by other routines.
// Requirements: dom.js

function moveObject(object, x, y) {
   if (object.style.pixelLeft) {
      object.style.pixelLeft = x;
      object.style.pixelTop = y;
    } else {
      object.style.left = x;
      object.style.top = y;
    }
}

function getWindowSize() {
  // This function returns an object ("size") with 2 properties: "size.width" and "size.height".
  // The size.width property is the width of the window in pixels.
  // The size.height property is the height of the window in pixels.
  // If the DOM is not recognized, the function returns a null Object;

  var size = new Object();
  if (window.innerWidth != null) {
    size.width = window.innerWidth;
    size.height = window.innerHeight;
  } else if (document.body.clientWidth != null) {
    size.width = document.body.clientWidth;
    size.height = document.body.clientHeight;
  }
  return (size);
}

function getPos(object) {
  // This function returns an object ("point") with 2 properties: "point.x" and "point.y".
  // The point.x property is the pixel position of the left of the object.
  // The point.y property is the pixel position of the top of the object.
  // If the DOM is not recognized, the function returns a null Object;

  var point = new Object();

  if (object.style.pixelLeft) {
    point.x = object.style.pixelLeft;
    point.y = object.style.pixelTop;
  } else if (object.id.offsetLeft) {
    point.x = object.id.offsetLeft;
    point.y = object.id.offsetTop;
  } else if (object.style.left) {
    point.x = object.style.left;
    point.y = object.style.top;
  }
  return (point);
}

function getSize(object) {
  // This function returns an object ("size") with 2 properties: "size.width" and "size.height".
  // The size.width property is the width of the object in pixels.
  // The size.height property is the height of the object in pixels.
  // If the DOM is not recognized, the function returns a null Object;

  var size = new Object();

  if (object.id.offsetWidth) {
    size.width = object.id.offsetWidth;
    size.height = object.id.offsetHeight;
  } else if (object.id.clip.width) {
    size.width = object.id.clip.width;
    size.height = object.id.clip.height;
  }
  return (size);
}

function getZindex(object) {
   return (object.style.zIndex );
}

function setZindex(object, index) {
  object.style.zIndex  = index;
}

var childWindow;
function openWindow(url, childName, height, width, parentName) {
  window.name = parentName;
  childWindow = window.open(url, childName, 'height='+height+',width='+width); 
  childWindow.focus();
}

function setClass(ID, newClass) {
  // WARNING: This function doesn't work with Layer DOM.
  var object = getObject(ID);
  object.className = newClass;
}

