function openPickerDialog(sURL, Argument, nH, nW) {
    if (IsIE()) {
        
        if (window.screen.height < nH) { nH = window.screen.height - 30; }
        window.showModalDialog(sURL, Argument, "resizable:yes; help:no; status:yes; dialogHeight:" + nH + "px ;dialogWidth:" + nW + "px");
        if (Argument != null && Argument.CallBackFunc != null && Argument.HasResult == true) {
            Argument.CallBackFunc(Argument);
        }
    } else {
    
        window.dialogArguments = Argument;
        var oWin = window.open(sURL, sURL, "resizable=yes, modal=yes, width=" + nW + ", height=" + nH, 0);
        oWin.focus();
    }
}

function saveDialogResult(value) {
    DialogArgument.ReturnValue = value;
    DialogArgument.HasResult = true;
    if ((!IsIE()) && (DialogArgument.CallBackFunc != null)) {
        DialogArgument.CallBackFunc(DialogArgument);
    }
}

function DialogArgument() {
    this.CallBackFunc = null;
    this.Parameter = null;
    this.ActiveWin = null;
    this.HasResult = false;
    this.Selection = null;
    this.IsNewElement = false;
    this.ActiveCommand = null;
    this.ReturnValue = null;
}

function giveFocus() {
    this.focus();
}

//returns the current window url after the "?"-mark
function getQueryString() {
    var sURL = window.location.href;

    return sURL.substr(sURL.indexOf("?") + 1);
}

function IsIE() {
    return (window.navigator.appVersion.indexOf("MSIE") != -1);
}

function AttachmentDialogReturn(argument) {

    var sControlID = argument.ID;
    var sHTML = argument.ReturnValue;
    var oDoc = rt_GetDocument(sControlID);
    var oElement = argument.Parameter;

    if (IsIE()) {
        setFocus(oDoc);
        var sType;
        var sel = g_state.GetSelection(oDoc);

        sType = sel.type;
        if (g_state.bMode) {
            if (sType == "Control") {
                if ((sel.item(0).tagName == "IMG") && (argument.Parameter.tagName == "A") && (argument.Parameter.href.indexOf('loadState') > -1) && (argument.Parameter.href.indexOf('attachment') > -1)) {
                    oElement = sel.item(0).parentElement;
                    if ((oElement.tagName == "A") && (oElement.href.indexOf('loadState') > -1) && (oElement.href.indexOf('attachment') > -1) && ((oElement.href.indexOf("loadState(\'3\'") > -1) || ((oElement.href.indexOf("loadState(\'4\'") > -1)))) {
                        setAttachmentHTML(oElement, sHTML);
                    } else {
                        oElement.outerHTML = sHTML;
                    }
                } else {
                    sel.item(0).outerHTML = sHTML;
                }
            } else {
                sel.collapse(0);
                oElement = sel.parentElement();
                if ((oElement.tagName == "A") && (oElement.href.indexOf('loadState') > -1) && (oElement.href.indexOf('attachment') > -1) && ((oElement.href.indexOf("loadState(\'3\'") > -1) || ((oElement.href.indexOf("loadState(\'4\'") > -1)))) {
                    setAttachmentHTML(oElement, sHTML);
                } else {
                    oElement.outerHTML = sHTML;
                }
                //sel.pasteHTML(sHTML);
            }
        } else {
            sel.text = sHTML;
        }
    } else {
        if ((oElement.tagName == "A") && (oElement.href.indexOf('loadState') > -1) && (oElement.href.indexOf('attachment') > -1) && ((oElement.href.indexOf("loadState(\'3\'") > -1) || ((oElement.href.indexOf("loadState(\'4\'") > -1)))) {
            setAttachmentHTML(oElement, sHTML);
        } else {
            var r = oElement.ownerDocument.createRange();
            r.setStartBefore(oElement);
            var df = r.createContextualFragment(sHTML);
            oElement.parentNode.replaceChild(df, oElement);
        }
    }
}

function getEfmNodes() {
    if (document.getElementById("efmnodes")) {
        return "efmnodes=" + document.getElementById("efmnodes").value;
    } else {
        return "efmnodes=";
    }
}

function openAttachmentDialog(sUrl, sCtrlID, nHeight, nWidth) {
    if (nHeight == null) nHeight = 600;
    if (nWidth == null) nWidth = 600;
    var oArg = new DialogArgument;
    if (document.getElementById("efmnodes")) {
        oArg.Parameter = document.getElementById("efmnodes").value;
    }
    
    oArg.ID = sCtrlID.split(":")[0];
    oArg.CallBackFunc = ContentDialogReturn;
    openPickerDialog(sUrl, oArg, nHeight, nWidth);
}

//*****************************************************************************************************
//*************************************   ****************************************************************
//*****************************************************************************************************
//*****************************************************************************************************



//*****************************************************************************************************
//*************************************  ****************************************************************
//*****************************************************************************************************
//*****************************************************************************************************
