﻿function openPopupWindow(url, name, width, height, returnWindow) {
    var horizontalOffset, verticalOffset, offsetAmount, windowToReturn, closethiswindow;

    offsetAmount = 0;

    if (width == -1) {

        if ((screen.Height >= 0) && (screen.Width >= 0)) {
            width = screen.Width - 10;
        }
        else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
            width = screen.availWidth - 10;
        }
    }

    if (height == -1) {
        if ((screen.Height >= 0) && (screen.Width >= 0)) {
            height = screen.Height - 75;
        }
        else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
            height = screen.availHeight - 45;
        }
    }

    if (navigator.appName == "Microsoft Internet Explorer") {
        horizontalOffset = window.screenLeft + offsetAmount;
        verticalOffset = window.screenTop + offsetAmount;
    }
    else {
        horizontalOffset = window.screenX + offsetAmount;
        verticalOffset = window.screenY + offsetAmount;
    }

    if (horizontalOffset + width > screen.availWidth || verticalOffset + height > screen.availHeight) {
        horizontalOffset = 0;
        verticalOffset = 0;
    }

    windowToReturn = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
}

