function buildWindowFeaturesString(
    left,
    top,
    screenX,
    screenY,
    height,
    width,
    menubar,
    scrollbars,
    titlebar,
    directories,
    fullscreen,
    status,
    toolbar,
    location,
    resizable) {

    var windowFeatures =
      "left=" + left + "," +
      "top=" + top + "," +
      "screenX=" + screenX + "," +
      "screenY=" + screenY + "," +
      "height=" + height + "," +
      "width=" + width + "," +
      "menubar=" + menubar + "," +
      "scrollbars=" + scrollbars + "," +
      "titlebar=" + titlebar + "," +
      "directories=" + directories + "," +
      "fullscreen=" + fullscreen + "," +
      "status=" + status + "," +
      "toolbar=" + toolbar + "," +
      "location=" + location + "," +
      "resizable=" + resizable;

    return windowFeatures;
}

function popupFixed(windowURL) {
    var left = 0;
    var top = 0;
    var screenX = 0;
    var screenY = 0;
    var height = 480;
    var width = 680;
    var menubar = 1;
    var scrollbars = 1;
    var titlebar = 1;
    var directories = 1;
    var fullscreen = 1;
    var status = 1;
    var toolbar = 1;
    var location = 1;
    var resizable = 1;

    var windowFeatures = buildWindowFeaturesString(
      left,
      top,
      screenX,
      screenY,
      height,
      width,
      menubar,
      scrollbars,
      titlebar,
      directories,
      fullscreen,
      status,
      toolbar,
      location,
      resizable);

    popup(windowURL, "popup_fixed", windowFeatures);
}

function popupOptimum(windowURL) {

    var left = 0;
    var top = 0;
    var screenX = 0;
    var screenY = 0;
    var height = (screen.availHeight - 50);
    var width = (screen.availWidth - 10);
    var menubar = 0;
    var scrollbars = 0;
    var titlebar = 0;
    var directories = 0;
    var fullscreen = 0;
    var status = 0;
    var toolbar = 0;
    var location = 0;
    var resizable = 1;


    var windowFeatures = buildWindowFeaturesString(
      left,
      top,
      screenX,
      screenY,
      height,
      width,
      menubar,
      scrollbars,
      titlebar,
      directories,
      fullscreen,
      status,
      toolbar,
      location,
      resizable);

    popup(windowURL, "popup_fixed", windowFeatures);

}

function popup(windowURL, windowName, windowFeatures) {
    var popupWindow = window.open(windowURL, windowName, windowFeatures);
    // check to see if the popup was blocked
    if ((popupWindow == null) && (document.location.href.indexOf("popup_blocked") == -1)) {
        var queryString = "";
        if (document.location.href.indexOf("?") == -1) {
            queryString = "?";
        } else {
            queryString = "&";
        }
        queryString += "popup_blocked=true"
        document.location.href = document.location.href + queryString;
    } else {
        popupWindow.focus();
    }

}