﻿var winModalWindow;

function ignoreEvents(e) {
    return false;
}

function modalDialog(cURL, cDlgName, nWidth, nHeight) {
    if (isIE() && window.showModalDialog) {
        window.showModalDialog(cURL, cDlgName, "dialogWidth=" + nWidth + "px;dialogHeight=" + nHeight + "px;;scroll:auto;status:off;help:off");
    } else {
        //window.top.captureEvents(Event.CLICK | Event.FOCUS);
        window.top.addEventListener("click", ignoreEvents, true);
        window.top.addEventListener("focus", handleFocus, true);
        //window.top.onclick = ignoreEvents;
        //window.top.onfocus = handleFocus;
        winModalWindow = window.open(cURL, cDlgName, "dependent=yes, width=" + nWidth + ",height=" + nHeight);
        winModalWindow.focus();
    }

    return winModalWindow;
}

function handleFocus() {
    if (winModalWindow) {
        if (!winModalWindow.closed) {
            winModalWindow.focus();
        } else {
            //window.top.releaseEvents(Event.CLICK | Event.FOCUS);
            window.top.removeEventListener("click", ignoreEvents, true)
            window.top.removeEventListener("focus", handleFocus, true)
            //window.top.onclick = "";
        }
    }

    return false;
}
