// Launches a pop-up window.
//
// url: 
//    the url of the document the window should contain (required)
// name: 
//    the name of the window, used in link targets. default is "popWindow".
// type: 
//    string indicating type of window. instead of passing in specific 
//    aspects like width, height, etc., we pass in the type of window to 
//    pop-up and control the details internally. 
// width & height: 
//    window dimensions in pixels. Generally we want to 
//    standardize our popup window dimensions by using types, not dimensions,
//    so don't override width or height unless you have a damn good reason!
function pop(url, name, type, width, height, limitOptions) {
  // defaults 
  name = (name != null && name != '') ? name : 'popUpWindow';
  width = (width != null && width != '') ? width : 780;
  height = (height != null && height != '') ? height : 500;

  var features = 
    (limitOptions ? 
    'titlebar=no,scrollbars=no,resizable=no,status=no' :
    'titlebar=1,scrollbars=1,resizable=1,status=1');

  // when we have types, we'll override width, height, and features here.

  features += ',width=' + width + ',height=' + height;

  url = makePopupUrl(url);
  var popUpWindow = open(url, name, features); 
  popUpWindow.focus();
}


// INTERNAL FUNCTIONS. DO NOT ACCESS DIRECTLY. IMPLEMENTATION MAY CHANGE.

function makePopupUrl(url) {
  var hasQueryParameters = url.indexOf('?') != -1;
  if (hasQueryParameters) {
    return url + '&_pop';
  }
  else {
    return url + '?_pop';
  }
}
