
jsStuff = new function () {

  this.openCenteredWindow = function (link, width, height, scrollbars, resizable) {
    scrollbars = "scrollbars=" + (scrollbars == "scrollbars" ? "1" : "0");
    resizable = "resizable=" + (resizable == "resizable" && window.resizeTo ? "1" : "0");

    var maxWidth = Math.round(screen.width * .85),
        maxHeight = Math.round(screen.height * .85),
        windowLeft = Math.round((screen.width - width)/2),
        windowTop = Math.round((screen.height - height)/2);


    var windowParams = "menubar=0," + scrollbars + ",titlebar=1," + resizable + ",width=" + width + ",height=" + height + ",left=" + windowLeft + ",top=" + windowTop + ",screenX=" + windowLeft + ",screenY=" + windowTop + ",status=0",
        currWindow = window.open(link.href, link.target, windowParams);

    if (currWindow._alreadyOpened) {
      currWindow.close();
      currWindow = null;
      currWindow = window.open(link.href, link.target, windowParams);
    }
    currWindow._alreadyOpened = true;

    currWindow.focus();
    return currWindow;
  }

}

function openWindow(url, target, width, height) {
    var left = Math.round((screen.width - width)/2);
    var top = Math.round((screen.height - height)/2);

    var args = "menubar=0, scrollbars=0, titlebar=1, resizable=0,"
    + "width=" + width + ","
    + "height=" + height + ","
    + "status=0,"
    + "left=" + left + ","
    + "top=" + top + ","
    + "screenX=" + left + ","
    + "screenY=" + top;

  window.open(url, target, args )
}