$(document).ready(function () {
    $('#btnClose').removeAttr('onclick');
    $('#btnClose').click(function () {
        ClosePopup(false);
    });

    if ($('#DoClose').val() == '1') {
        ClosePopup(true);
    }

    $('body').keydown(function (e) {
        if (new SysHandleKey(e).IsEscapeKey())
            ClosePopup(false);
    });
});

function ClosePopup(doRefresh) {
    var r;
    if (doRefresh)
        r = new Array('refresh');
    else
        r = new Array();

    if (opener && !opener.closed) {
        top.opener.SysDialog.returnValue = r;
        top.opener.SysDialog.returnFunc()
        window.close();
    }
    else {
        window.parent.returnValue = r;
        window.parent.SysCloseModalPopup();
    }
}
