﻿//open window
function OpenWindow(url, title, width, height, autosize) {
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    //Success. Getting existing window DialogWindow using GetWindowByName
    // DialogWindow Is defined in the Master Page
    var oWnd = oManager.getWindowByName("DialogWindow");
    //Success. Setting a size and a Url to the window using its client API before showing
    if (oWnd == null) {
        oWnd = radopen(url, null);
        oWnd.setSize(width, height);
        oWnd.set_title(title);
        oWnd.set_modal(false);
        if (autosize != null) { oWnd.autoSize(autosize); }
        //Success. Opening window
        oWnd.show();
    }
    else { 
        oWnd.setSize(width, height);
        oWnd.setUrl(url);
        oWnd.set_title(title);
        if (autosize != null) { oWnd.autoSize(autosize); }
        oWnd.show();
    }
}

//open modal window
function OpenModalWindow(url, title, width, height, autosize) {
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    // DialogWindowModal Is defined in the Master Page
    var oWnd = oManager.getWindowByName("DialogWindowModal");
    //Success. Setting a size and a Url to the window using its client API before showing
    if (oWnd == null) {
        oWnd = radopen(url, null);
        oWnd.setSize(width, height);
        oWnd.set_title(title);
        oWnd.set_modal(true);
        if (autosize != null) { oWnd.autoSize(autosize); }
        //Success. Opening window
        oWnd.show();
    }
    else {
        oWnd.setSize(width, height);
        oWnd.setUrl(url);
        oWnd.set_title(title);
        if (autosize != null) { oWnd.autoSize(autosize); }
        //Success. Opening window
        oWnd.show();
    }
}

function OpenModalWindowCallBack(url, title, width, height) {
    //Getting rad window manager
    var oManager = GetRadWindowManager();
    // DialogWindowModal Is defined in the Master Page
    var oWnd = oManager.getWindowByName("DialogWindowModal");
    //Success. Setting a size and a Url to the window using its client API before showing
    if (oWnd == null) {
        oWnd = radopen(url, null);
        oWnd.setSize(width, height);
        oWnd.set_title(title);
        oWnd.set_modal(true);
        oWnd.add_close(OnClientClose);
        //Success. Opening window
        oWnd.show();
    }
    else {
        oWnd.setSize(width, height);
        oWnd.setUrl(url);
        oWnd.set_title(title);
        oWnd.add_close(OnClientClose);
        //Success. Opening window
        oWnd.show();
    }
}


function OnClientClose(oWnd, eventArgs) {
    //your code here
    //remove the OnClientClose function to avoid
    //adding it for a second time when the window is shown again
    oWnd.remove_close(OnClientClose);
}

//GetRadWindow obtains a reference to the hosting RadWindow"
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow)
        oWindow = window.radWindow;
    else if (window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
    return oWindow;
}

// CallFnOnParent shows how to call a function
// in the parent page. A javascript function named CalledFn
// must exist in the parent page.
function CallFnOnParent() {
    GetRadWindow().BrowserWindow.CalledFn();
}
  

//print
function PrintIframeContent() {
    var oWnd = GetRadWindow();
    var content = oWnd.GetContentFrame().contentWindow;
    var printDocument = content.document;

    if (document.all) {
        printDocument.execCommand("Print");
    }
    else {
        content.print();
    }
}

//close functions

function CloseOnReload() {
    GetRadWindow().close();
}

function CloseWithReturn(val) {
    var oWnd = GetRadWindow();
    oWnd.close(val);

}

function cancelAndClose() {
    var oWindow = GetRadWindow();
    oWindow.argument = null;
    oWindow.close();
} 

function RefreshParentPage() {
    GetRadWindow().BrowserWindow.location.href = GetRadWindow().BrowserWindow.location.href;
}

function RefreshParentPageGrid() {
    var theLocation = new Location(GetRadWindow().BrowserWindow.location.href.toString());
    theLocation.AddRequestParameter("RetrieveSearch", "1");
    theLocation.AddRequestParameter("RadUrid", "");
    GetRadWindow().BrowserWindow.location.href = theLocation.toString();
}
