

/// RadWindow Functions

function ShowDialog() {
    //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(null, "EditWindow");
    oWnd.SetUrl(oWnd.GetUrl());
    oWnd.center();
}

//Called when a window is being shown. Good for setting an argument to the window 
function OnClientShow(radWindow) {
    //Create a new Object to be used as an argument to the radWindow
    var arg = new Object();
    //Using an Object as a argument is convenient as it allows setting many properties.

    //Set the argument object to the radWindow        
    radWindow.Argument = arg;
}

function CloseOnReload() {
    GetRadWindow().Close();
}


function CallBackFunction(radWindow, returnValue) {
    //    var oArea = document.getElementById("InfoArea");
    //    if (returnValue) oArea.value = returnValue;
    //    else alert ("No text was returned");

    alert('callback');
}

// Called when a window is being closed.
function OnClientClose(radWindow) {
    //Another option for passing a callback value
    //Set the radWindow.Argument property in the dialog
    //And read it here --> var oValue = radWindow.Argument;                                        
    //Do cleanup if necessary
    RefreshParentPage();
}

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; //IE (and Moz az well)
    return oWindow;
}

function getParameter(queryString, parameterName) {
    var parameterName = parameterName + "=";
    if (queryString.length > 0) {
        begin = queryString.indexOf(parameterName);
        if (begin != -1) {
            begin += parameterName.length;
            end = queryString.indexOf("&", begin);
            if (end == -1) {
                end = queryString.length;
            }
            return unescape(queryString.substring(begin, end));
        }
        return "null";
    }
}

function RefreshParentPage() {
    try {
        var oWnd = GetRadWindow().BrowserWindow;   
        oWnd.location.href = oWnd.location.href;

        //        window.location.reload();
        GetRadWindow().BrowserWindow.location.reload();
        CloseOnReload();
    }
    catch (e) {
    }
}

function GetId() {
    return getParameter(window.top.location.search.substring(1), 'id');
}

// EditWindow, EditText.aspx
function OpenDialog(windowName, windowUrl) {
    try {
        var sVal = windowUrl + '?id=' + GetId();
        var aWnd = window.radopen(null, windowName);
        aWnd.SetUrl(sVal);
    }
    catch (e) {
    }
}

// UploadWindow, Upload.aspx, uploadType
function OpenTypeDialog(windowName, windowUrl, windowType) {
    try {
        var sVal = windowUrl + '?type=' + windowType + '&id=' + GetId();
        var aWnd = window.radopen(null, windowName);
        aWnd.SetUrl(sVal);
    }
    catch (e) {
    }
}

//Contacts.aspx
function OpenContactDialog(windowName, windowUrl, windowType) {
    try {
        var sVal = windowUrl + '?type=' + windowType + '&id=' + getParameter(window.top.location.search.substring(0), '?id');
        var aWnd = window.radopen(null, windowName);
        aWnd.SetUrl(sVal);
    }
    catch (e) {
    }
}

function ShowEditWindow(textType) {
    OpenTypeDialog('EditWindow', 'EditText.aspx', textType);
}

function ShowEditWindowWithDate(textType) {
    OpenTypeDialog('EditWindowWithDate', 'EditTextWithDate.aspx', textType);
}

function ShowUploadWindow(uploadType) {
    OpenTypeDialog('UploadWindow', 'Upload.aspx', uploadType);
}

function ShowContactWindow(contactType) {
    OpenContactDialog('ContentWindow', 'Contacts.aspx', contactType);
}

function ShowPhotoUpload() {
    OpenDialog('UploadWindow', 'UploadPhoto.aspx');
}

function ShowStepUpload() {
    OpenDialog('StepWindow', 'UploadStep.aspx');
}

function ShowFlashUpload() {
    OpenDialog('FlashWindow', 'UploadFlash.aspx');
}

function ShowPRUpload() {
    OpenDialog('PressReleaseWindow', 'UploadPressRelease.aspx');
}

/// End RadWindow functions


