/* Control RADWindows Component */

function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //ImagesE (and Moz az well)            
    return oWindow;
}

function CloseOnReload() {
    GetRadWindow().Close();
}

function RefreshParentPage() {
    GetRadWindow().BrowserWindow.location.reload();
    //GetRadWindow().BrowserWindow.Page.GetPostBackEventReference(this, "@@@@@buttonPostBack"");
    //GetRadWindow().BrowserWindow.document.forms[0].submit();
}

function RedirectParentPage(newUrl) {
    GetRadWindow().BrowserWindow.document.location.href = newUrl;
}

function CallFunctionOnParentPage(fnName) {
    var oWindow = GetRadWindow();
    if (oWindow.BrowserWindow[fnName] && typeof (oWindow.BrowserWindow[fnName]) == "function") {
        oWindow.BrowserWindow[fnName](oWindow);
    }
}


//show Task window
function showTaskDialog() {
    //Force reload in order to guarantee that the onload event handler of the dialog which configures it executes on every show.
    var oWnd = window.radopen("", "TaskDialog");
    oWnd.setUrl(oWnd.get_NavigateUrl());
}

function CallBackFunction(radWindow, returnValue) {
    __doPostBack("ContactSelect", radWindow.argument);
}


//This function is a work around to prevent RadGrid CSS style loss on postback
function OnGridRowDeselect(row) {
    row.Control.cells[0].style.height = '22px';
    var cellCount = row.Control.cells.length;
    for (i = 0; i < cellCount; i++) {
        row.Control.cells[i].style.paddingLeft = '4px';
    }
}

//Open a Window
function showDlg(dlg, Arg) {
    var oManager = GetRadWindowManager();
    var oWindow = oManager.GetWindowByName(dlg);
    oWindow.SetUrl(Arg);
    var oWnd = window.radopen(null, "TaskDialog");
    return true;
}


//Force Set Width and height for the window
function SetCurrentSize(awidth, aheight) {
    var aWnd = GetRadWindow();
    if (aWnd != null) { //Exception check
        aWnd.set_width(awidth);
        aWnd.set_height(aheight);
        aWnd.center();
    }
}



