// OPENS CENTERED POPUP WINDOW. ADJUSTS SIZE TO FIT WITHIN SCREEN.
// Example:
// <a href="theurl/index.html" target="_blank" onclick="return launchCentered('theurl/index.html','windowname','760','480','scrollbars=no')">
// scrollbars can be yes or no (not auto).

function launchCentered(url, name, width, height, scrollbars) {
  var str = "";
  if (window.screen) {
    if (screen.availWidth < width) {
      width = screen.availWidth - 10;
    }
    if (screen.availHeight < height) {
      height = screen.availHeight - 30;
    }
    var aw = screen.availWidth - 10;
    var ah = screen.availHeight - 30;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += "left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += ",";
  }
  str += "width=" + width + ",innerWidth=" + width;
  str += ",height=" + height + ",innerHeight=" + height;
  str += "," + scrollbars;
  str += ",toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,copyhistory=no";
  window.open(url, name, str);
  return false;
}