﻿
// from CKFinder
function popupWindow(width, height, name, url, scroll) {
    width = width || this.Width;
    height = height || this.Height;

    if (typeof width == 'string' && width.length > 1 && width.substr(width.length - 1, 1) == '%')
        width = parseInt(window.screen.width * parseInt(width) / 100);

    if (typeof height == 'string' && height.length > 1 && height.substr(height.length - 1, 1) == '%')
        height = parseInt(window.screen.height * parseInt(height) / 100);

    if (width < 200)
        width = 200;

    if (height < 200)
        height = 200;

    var top = parseInt((window.screen.height - height) / 2);
    var left = parseInt((window.screen.width - width) / 2);

    var options = 'location=no,menubar=no,toolbar=no,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes' +
			',width=' + width +
			',height=' + height +
			',top=' + top +
			',left=' + left +
			',scrollbars=' + scroll;

    var popupWindow = window.open('', name, options, true);

    // Blocked by a popup blocker.
    if (!popupWindow)
        return false;

    try {
//        popupWindow.moveTo(left, top);
//        popupWindow.resizeTo(width, height);
//        popupWindow.focus();
        popupWindow.location.href = url;
    }
    catch (e) {
        popupWindow = window.open(url, name, options, true);
    }
    return popupWindow;
}
