/**
 * @class Provides helper methods for Modal Dialog elements.
 */
AJAXDialog = function(dialog, veil) {
  if (arguments.length==0) return;

  if (this.veilOverlay == null) { // once per page
    this.veilOverlay = document.createElement('div');
    this.veilOverlay.className = veil; // CSS className
    this.veilOverlay.style.zIndex = 200;
    this.veilOverlay.innerHTML = "&nbsp;";
    this.setVeilWidth();
    this.addListener(window, "resize", this.setVeilWidth);
    document.body.appendChild(this.veilOverlay);
  }

  this.container = document.getElementById(dialog);
  this.container.style.zIndex=201;
}

AJAXDialog.prototype.setVeilWidth = function() {
    this.veilOverlay.style.width = document.body.scrollWidth;
    this.veilOverlay.style.height = document.body.scrollHeight;
}

AJAXDialog.prototype.show = function() {
    this.container.style.display = "block";
    this.veilOverlay.style.display = "block";
}

AJAXDialog.prototype.hide = function(ok) {
    this.container.style.display = "none";
    this.veilOverlay.style.display = "none";
}

AJAXDialog.prototype.moveTo = function(x, y) {
    if (x == -1) x = Math.round((document.body.clientWidth - this.container.offsetWidth) / 2);
    if (y == -1) y = Math.round((document.body.clientHeight - this.container.offsetHeight) / 2) + document.body.scrollTop;
    this.container.style.left = x + "px";
    this.container.style.top = y + "px";
}  

AJAXDialog.prototype.addListener = function(obj, evType, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, false);
    return true;
    }
  else if (obj.attachEvent) return obj.attachEvent('on' + evType, fn);
  else return false;
}
