// +-----------------------------------------------------------------------+
// | Popup functions                                                       |
// | Copyright (C) 2004 Craig Manley                                       |
// +-----------------------------------------------------------------------+
// | You may not redistribute, sell, modify, copy, claim ownership of, nor |
// | incorporate this software into any other software or website without  |
// | the prior written permission of the author. This software may only be |
// | used in applications and web pages developed by the author.           |
// +-----------------------------------------------------------------------+
// | Author: Craig Manley                                                  |
// +-----------------------------------------------------------------------+
//
// $Id: popup.js,v 1.2 2005/12/22 23:17:34 cmanley Exp $
//



// Global _popup window object required by the function popUp().
var _popup;

/**
 * Opens a new popup window that is centered over the current window.
 * Only the 1st 4 parameters are required, the rest may have one of the
 * values null, 0, or 1. Optional parameters that are not specified or have
 * the value null will default to the value 0. See the Javascript
 * window.open() function documentation for the effect of these parameters.
 * The popup window will have the following custom properties set:
 *  opener: the owner window
 *  height: it's window height
 *  width: it's window width
 * This function always returns false.
 */
function popUp(p_url,p_title,p_width,p_height,p_resizable,p_scrollbars,p_status,p_toolbar,p_location,p_menubars) {
 // Close any existing _popup
 if (_popup) {
  if (!_popup.closed) {
   if (_popup.close) { // close() method does not exist in Opera.
    _popup.close();
   }
  }
  _popup = null;
 }
 // Set properties
 if (p_resizable == null) {
  p_resizable = 0;
 }
 if (p_scrollbars == null) {
  p_scrollbars = 0;
 }
 if (p_status == null) {
  p_status = 0;
 }
 if (p_toolbar == null) {
  p_toolbar = 0;
 }
 if (p_location == null) {
  p_location = 0;
 }
 if (p_menubars == null) {
  p_menubars = 0;
 }
 var properties = 'height=' + p_height + ',width=' + p_width + ',resizable=' + p_resizable +
                  ',scrollbars=' + p_scrollbars+ ',status=' + p_status + ',toolbar=' + p_toolbar +
                  ',location=' + p_location + ',menubars=' + p_menubars;
 // Determine left and top of new _popup window
 //var win = window.top;
 var win = self;
 var x;
 var y;
 if ((document.all) || ((win.innerHeight) && (win.screenX))) {
  var self_h = 0;
  var self_w = 0;
  var self_x;
  var self_y;
  if (typeof( win.innerWidth ) == 'number') {
   //Non-IE
   self_x = win.screenX;
   self_y = win.screenY;
   self_w = win.innerWidth;
   self_h = win.innerHeight;
  }
  else {
   self_x = win.screenLeft;
   self_y = win.screenTop;
   var doc = win.document;
   if (doc.documentElement && (doc.documentElement.clientWidth || doc.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    self_w = doc.documentElement.clientWidth;
    self_h = doc.documentElement.clientHeight;
   }
   else if (doc.body && (doc.body.clientWidth || doc.body.clientHeight)) {
    //IE 4 compatible
    self_w = doc.body.clientWidth;
    self_h = doc.body.clientHeight;
   }
  }
  if ((self_h > 0) && (self_w > 0)) {
   x = self_x + ((self_w - p_width) >> 1);
   y = self_y + ((self_h - p_height) >> 1);
   properties += ',left=' + x + ',top=' + y;
  }
 }

 if (window.showModalDialog) {
  var props = new Array('center:no');
  props.push('dialogHeight:' + p_height + 'px');
  props.push('dialogWidth:' + p_width + 'px');
  if (x) {
   props.push('dialogLeft:' + x);
  }
  if (y) {
   props.push('dialogTop:' + y);
  }
  // edge:{ sunken | raised } Specifies the edge style of the dialog window. The default is raised.
  // help:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays the context-sensitive Help icon. The default is yes.
  props.push('resizable:' + p_resizable);
  props.push('scroll:' + p_scrollbars);
  props.push('status:' + p_status);
  // unadorned:{ yes | no | 1 | 0 | on | off } Specifies whether the dialog window displays the border window chrome. This feature is only available when a dialog box is opened from a trusted application. The default is no.
  window.showModalDialog(p_url, win, props.join(';'));
 }
 else {
  // Create, show, and focus popup window.
  _popup = window.open(p_url,p_title,properties);
  if (_popup.opener == null) {
   _popup.opener = self;
  }
  _popup.width = p_width;
  _popup.height = p_height;
  _popup.focus();
 }
 return false;
}