﻿function GetMyWindowManager(iFU, UorC, w, h, ap) {
    var MyRWManager = null;
    try {
        MyRWManager = GetRadWindowManager();
        
        var MyWindow;
        if (iFU == true) {
            MyWindow = MyRWManager.getWindowByName("rwUrl");
            MyWindow.setUrl(UorC);

        }
        else {
            MyWindow = MyRWManager.getWindowByName("rwContent");
            document.getElementById('vrwContent').innerHTML = UorC;
            MyWindow.argument = ap;
        }
        MyWindow.argument = ap;
        MyWindow.show();
        //MyWindow.setSize(w, h);
        MyWindow.center();
    } catch (e) {
        var fn = function () { GetMyWindowManager(iFU, UorC, w, h, ap) };
        setTimeout(fn, 500);
    }
}

function PopWindow(isFromUrl, isAuthReq, UrlorContent, Width, Height, argParent) {
    
    if (isAuthReq == true) {
        UrlorContent = "../signin.aspx?st=c&sUrl=" + UrlorContent;
        Width = 318 + 40;
        Heigh = 410 + 40;
    }
    else {
        Width = Width + 40;
        Height = Height + 40;
    }
    var fn = function () { GetMyWindowManager(isFromUrl, UrlorContent, Width, Height, argParent) };
    setTimeout(fn, 500);
}

function OnPopClose(radWnd, args) {
    try {
        if (args._argument.isRefreshRequired == '1') {
            if (args._argument.Url == '')//this code has to be revisted so that it should handle when argument.Url is undefined - Note to Vamsi
                window.location.href = location.href;
            else
                window.location.href = args._argument.Url;
        }
        PopUpClosed(radWnd, args);
    } catch (e) { }
}

var DontCloseWindow = false;
function OnKeyPress(keyCode) {
    if (keyCode == 27) {
        var MyWindow = GetActivePopWindow();
        if (MyWindow == null)
            try { EscapeKeyHandler(); } catch (e) { }
        else
            ClosePopWindow(MyWindow,null);
    }
    else if (keyCode == 13) {
        try { EnterKeyHandler(); } catch (e) { }
    }
}

function OnMouseClicked(e) {
    var PopWindow = GetActivePopWindow()
    if (PopWindow != null) {
        if (!DontCloseWindow) {
            ClosePopWindow(PopWindow,null);
        }
        DontCloseWindow = false;
    }
}

function GetActivePopWindow() {
    try {
        MyRWManager = GetRadWindowManager();
        return MyRWManager.getActiveWindow();
    } catch (e) {return null; }
}

function ClosePopWindow(pw, oArg) {
    pw.close(oArg);
    try {
        PopUpClosed(null, oArg);
    } catch (e) { }
}




