// popup_window.js
//
//  Javascript object for easily popupping up windows.
//
// Todo:
// 1. set a default height and width.  (I'm not sure what will happen if
//    none is defined.)
// 2. better creating of the window option string to give to window.open
//    command.  (Check to see if the arguments (height, weight, etc.) are
//    defined or not before using them.)


function popupWindowOpen(url) {
  if (this.windowObj == null || this.windowObj.closed == true) {
    this.windowObj = window.open(url,this.targetName,"height="+this.height+",width="+this.width);
  } else {
    this.windowObj.location.href = url;
  }
  this.windowObj.focus();
  return false;
}

function popupWindowSetHeight(h) {
  this.height = h;
}

function popupWindowSetWidth(w) {
  this.width = w;
}

// Define window object that can exist even when window is closed
function popupWindow(targetName) {
  this.targetName = targetName;
  this.windowObj = null;
  this.height=this.default_height;
  this.width=this.default_width;
}

function define_popupWindow_prototype() {
  // Set default window dimensions to current window dimensions
  if (window.innerHeight) {   // Mozilla
    popupWindow.prototype.default_height = window.innerHeight;
    popupWindow.prototype.default_width = window.innerWidth;
  } else if (document.documentElement.clientHeight) {  // IE w/ DOCTYPE
    popupWindow.prototype.default_height = document.documentElement.clientHeight;
    popupWindow.prototype.default_width = document.documentElement.clientWidth;
  } else if (document.body) {  // IE
    popupWindow.prototype.default_height = document.body.clientHeight;
    popupWindow.prototype.default_width = document.body.clientWidth;
  } else {
    popupWindow.prototype.default_height = 500;
    popupWindow.prototype.default_width = 700;
  }


  // Define the object methods
  popupWindow.prototype.open = popupWindowOpen;
  popupWindow.prototype.setHeight = popupWindowSetHeight;
  popupWindow.prototype.setWidth = popupWindowSetWidth;
}

define_popupWindow_prototype();

