// Center an element in the window.
// If topY is unspecified, the element is centered vertically.

function centerElement (id, topY) {
 var element, windowWidth, windowHeight, elementWidth, elementHeight, cornerX, cornerY;
 if (document.layers) {
  element = document[id];
  windowWidth = window.innerWidth;
  windowHeight = window.innerHeight;
  elementWidth = element.document.width;
  elementHeight = element.document.height;
 }
 else if (document.all) {
  element = document.all[id];
  windowWidth = document.body.clientWidth;
  windowHeight = document.body.clientHeight;
  elementWidth = element.offsetWidth;
  elementHeight = element.offsetHeight;
 }
 else if (document.getElementById) {
  element = document.getElementById(id);
  windowWidth = window.innerWidth;
  windowHeight = window.innerHeight;
  elementWidth = element.offsetWidth;
  elementHeight = element.offsetHeight;
 }
 cornerX = Math.max(0, Math.floor((windowWidth - elementWidth) / 2));
 cornerY = isNaN(topY) ? Math.max(0, Math.floor((windowHeight - elementHeight) / 2)) : topY;
 if (document.layers) {
  element.left = cornerX;
  element.top = cornerY;
  element.visibility = 'show';
 }
 else if (document.all || document.getElementById) {
  element.style.left = cornerX + 'px';
  element.style.top = cornerY + 'px';
  element.style.visibility = 'visible';
 }
 return element;
}