/* Control RADWindows Component */

function GetRadWindow() {
 var oWindow = null;
  if (window.radWindow)
     oWindow = window.radWindow;
  else if (window.frameElement.radWindow)
     oWindow = window.frameElement.radWindow;
  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);
//}

//Imagesmage Function
var imgButtonPressed = new Image();
imgButtonPressed.src = "";

function clickOnce(btn, msg) {
    if (typeof (Page_ClientValidate) == 'function') {
        if (Page_ClientValidate() == false) { return false; }
    }

    if (btn.getAttribute('type') == 'button') {
        if (!msg || (msg = 'undefined')) { msg = 'Loading...'; }
        btn.value = msg;
        btn.disabled = true;
        return true;
    }
    else {
        btn.src = imgButtonPressed.src;
        //  btn.disabled = true;
        //var s = "document.getElementById('" + btn.id + "').click()";
        //window.setTimeout(parent.window,10); // give enough time to display
        return true;
    }
}

//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();
    }
}

