﻿// development only
var __enableRetainCode = false;

// hints
// - for use with access there is currently no solution

var __editVersion = "3.5.1125";

// set the server rel. path: needed if we have a rel. url and switch to HTML mode
try {
    var test = globalServerPathRelative;
} catch (Error) {
    globalServerPathRelative = "";
};
globalServerPathRelative = __editGetServer();

var system = "";
var __currentURL = "";
var __currentURLTemp = "";
var __editDocumentLoadedFlag = false;
var __editActiveObject = null;
var __editIsBR = globalIsBR;
var __editSaveMode = globalSaveMode;
var __editFieldCounter = 1;
var __editReloadAfterSave = false;
var __editUploadUrl = "";
var __editUploadPath = "";
var __editUploadedFile = "";
var __editSaveModeHtml = "";
var __editStyleSheetCombo = "";
var __editFormatCombo = null;
var __editContextMenu = null;
var __editToolbarCode = "";
var __editEditorStatus = "EDIT";
var __editMenuVisible = true;
var __editContent = "";
var __editChanged = false;
var __editControlVDisabled = globalControlVDisabled;
var __editHierarchy = null;
var __editMozParam;
var __editIsEvaluation = true;
var __editFocusTime = 0;
var __editDefaultFont = "";
var __editDefaultFontSize = "";
var __editSpecialChar1 = new Array();
var __editSpecialChar2 = new Array();
var __editSelectedTags = null;

if (globalTagColor) {
    var __editopenTag = "<FONT color=" + globalTagColor + ">&lt;</FONT>";
    var __editcloseTag = "<FONT color=" + globalTagColor + ">&gt;</FONT>";
} else {
    var __editopenTag = "&lt;";
    var __editcloseTag = "&gt;";
}
var __editfontTag = "<FONT color=" + globalTagNameColor + ">";
var __editfontAttribute = "<FONT color=" + globalAttributeColor + ">";
var __editfontStyle = "<FONT color=" + globalStyleColor + ">";
var __editfontClose = "</FONT>";

var __zindex = 1000;

var __isIntelli = false;
var __intelliPos = -1;
var __intelliRowCount = 10;
var __intelliLeft = 0;
var __intelliTop = 0;
var __intelliData = new Array();

var lastMode = 'EDIT';
var __lastHeight = 0;

__editTableHighlight = false;

var table;
var objSelected;
var popup;
var currentRow;
var currentCol;


function __editShowParameters() {
    var temp = "";
    var baseUrl = "";
    var basePath = "";
    temp += "<table style='font-family: arial;font-size: 11' border=0 width='100%'>";

    temp += "<tr><td nowrap>Context(application) URL</td><td>" + __editGetEditorWeb() + "</td></tr>";
    temp += "<tr><td nowrap>Context(application) path</td><td>" + globalRootPath + "</td></tr>";
    temp += "<tr><td nowrap>Editor URL</td><td>" + __editGetEditorUrl() + "</td></tr>";

    if (globalImageUrlAbsolute == "") {
        baseUrl = __editGetEditorWeb() + globalImageDir + "/";
        basePath = globalRootPath != "" ? (globalRootPath + globalImageDir + "/") : "";
    } else {
        baseUrl = globalImageUrlAbsolute;
        basePath = globalImagePathAbsolute;
    }
    temp += "<tr><td nowrap>Image URL</td><td>" + baseUrl + "</td></tr>";
    temp += "<tr><td nowrap>Image path</td><td>" + basePath + "</td></tr>";

    if (globalDocumentUrlAbsolute == "") {
        baseUrl = __editGetEditorWeb() + globalDocDir + "/";
        basePath = globalRootPath != "" ? (globalRootPath + globalDocDir + "/") : "";
    } else {
        baseUrl = globalDocumentUrlAbsolute;
        basePath = globalDocumentPathAbsolute;
    }

    temp += "<tr><td nowrap>Document URL</td><td>" + baseUrl + "</td></tr>";
    temp += "<tr><td nowrap>Document path</td><td>" + basePath + "</td></tr>";
    temp += "<tr><td nowrap>Template URL</td><td>" + globalTemplateUrlAbsolute + "</td></tr>";
    temp += "<tr><td nowrap>Template path</td><td>" + globalTemplatePathAbsolute + "</td></tr>";

    temp += "</table>";

    editWriteBody(temp);
};

function editProcess() {
    __toolbar_setkey(false);
};

function globalGetPositonY(obj) {
    var y = 0;
    var parent = obj;
    while (parent.tagName.toUpperCase() != "BODY") {
        if (parent.tagName.toUpperCase() != "TD") {
            y = y + parent.offsetTop;
        }
        parent = parent.parentNode;
    }
    if (browser.ns)
        return y - 2;
    else
        return y - 2;
};

function globalGetPositonY2(obj) {
    var y = 0;
    var parent = obj;
    while (parent.tagName.toUpperCase() != "BODY") {
        y = y + parent.offsetTop;
        parent = parent.parentNode;
    }
    return y - 4;
};

function globalGetPositonX(obj) {
    var x = 0;
    var parent = obj;
    while (parent.tagName.toUpperCase() != "BODY") {
        x = x + parent.offsetLeft;
        parent = parent.parentNode;
    }
    if (browser.ns)
        return x;
    else
        return x - 2;
};

function __editGetEditorUrl() {
    if (globalEditorUrl != "") {
        return globalEditorUrl;
    } else {
        var url = document.location.href;
        var pos = url.indexOf("pinEdit.html");
        return url.substring(0, pos);
    }
};

function __editGetEditorWeb() {
    if (globalRootUrl != "") {
        return globalRootUrl;
    } else {
        var url = document.location.href;
        var pos = url.indexOf("editor");
        return url.substring(0, pos);
    }
};

function __editGetServer() {
    try {
        return document.location.protocol + "//" + document.location.host;
    } catch (Error) {
        return "";
    }
};

function onchangePINEDIT() {
    __intelliHide();

    // if we have an external toolbar then raise event
    if (globalSingleMode) {
        var temp = __editBuildToolbarStatus();
        eventOnChangeToolbar(temp);
        return;
    }

    try {
        // call method to close open popups
        toolbarstop.reset();

        if (objMenuBar) {
            var objMenu = objMenuBar.getActiveBarItem();
            if (objMenu)
                objMenu.reset();
        }

        if (!globalUpdateToolbarWithKey) {
            return;
        }
        // set buttons to active
        // get all buttons
        var objComponents = toolbarstop.getTagComponents();

        // check if active
        for (var i = 0; i < objComponents.length; i++) {
            var tag = objComponents[i].tag;
            var res = editQuery(tag);
            if (res != null) {
                objComponents[i].setStatus(res);
            }
        }
    } catch (Error) { };

    try {
        var isSelection = editHasSelection();
    } catch (Error) {
        var isSelection = false;
    }

    if (!isSelection) {
        try {
            if (__editStyleSheetCombo) {
                if (__editActiveObject.className)
                    __editStyleSheetCombo.setSelectedText(__editActiveObject.className);
                else
                    __editStyleSheetCombo.setSelectedText("STANDARD");
            }
        } catch (Error) { };

        try {
            cmbFont.setSelectedText(editQuery("FontName"));
        } catch (Error) { };

        try {
            cmbFontSize.setSelectedText(editQuery("FontSize"));
        } catch (Error) { };

        try {
            if (__editActiveObject.tagName == "H1") {
                cmbFormat.setSelectedText("<h1>");
            } else if (__editActiveObject.tagName == "H2") {
                cmbFormat.setSelectedText("<h2>");
            } else if (__editActiveObject.tagName == "H3") {
                cmbFormat.setSelectedText("<h3>");
            } else if (__editActiveObject.tagName == "H4") {
                cmbFormat.setSelectedText("<h4>");
            } else if (__editActiveObject.tagName == "H5") {
                cmbFormat.setSelectedText("<h5>");
            } else if (__editActiveObject.tagName == "H6") {
                cmbFormat.setSelectedText("<h6>");
            } else if (__editActiveObject.tagName == "ADDRESS") {
                cmbFormat.setSelectedText("<address>");
            } else if (__editActiveObject.tagName == "LI") {
                if (__editActiveObject.parentNode.tagName == "DIR")
                    cmbFormat.setSelectedText("<dir>");
                if (__editActiveObject.parentNode.tagName == "MENU")
                    cmbFormat.setSelectedText("<menu>");
            } else if (__editActiveObject.tagName == "PRE") {
                cmbFormat.setSelectedText("<pre>");
            } else {
                cmbFormat.setSelectedText("NORMAL");
            }
        } catch (Error) { };
    }
};

function __editBuildToolbarStatus() {
    var temp = "";
    var delimiter = ":";

    if (browser.ie) {
        // get button status
        temp += (editQuery("bold") ? "1" : "0") + delimiter;
        temp += (editQuery("italic") ? "1" : "0") + delimiter;
        temp += (editQuery("underline") ? "1" : "0") + delimiter;
        temp += (editQuery("superscript") ? "1" : "0") + delimiter;
        temp += (editQuery("subscript") ? "1" : "0") + delimiter;
        temp += (editQuery("justifyleft") ? "1" : "0") + delimiter;
        temp += (editQuery("justifycenter") ? "1" : "0") + delimiter;
        temp += (editQuery("justifyright") ? "1" : "0") + delimiter;
        temp += (editQuery("justifyfull") ? "1" : "0") + delimiter;
        temp += (editQuery("insertorderedlist") ? "1" : "0") + delimiter;
        temp += (editQuery("insertunorderedlist") ? "1" : "0") + delimiter;
    } else {
        temp += "0:0:0:0:0:0:0:0:0:0:0:";
    }

    var activeObject = editGetActiveObject();

    try {
        // style combo
        var cn = activeObject.className;
        var style = cn ? cn : "Standard";
        temp += style + delimiter;
    } catch (Error) {
        temp += delimiter;
    }

    try {
        // format
        if (activeObject.tagName == "H1")
            temp += "<h1>" + delimiter;
        else if (activeObject.tagName == "H2")
            temp += "<h2>" + delimiter;
        else if (activeObject.tagName == "H3")
            temp += "<h3>" + delimiter;
        else if (activeObject.tagName == "H4")
            temp += "<h4>" + delimiter;
        else if (activeObject.tagName == "H5")
            temp += "<h5>" + delimiter;
        else if (activeObject.tagName == "H6")
            temp += "<h6>" + delimiter;
        else if (activeObject.tagName == "ADDRESS")
            temp += "<address>" + delimiter;
        else if (activeObject.tagName == "ADDRESS")
            temp += "<address>" + delimiter;
        else if (activeObject.tagName == "MENU")
            temp += "<menu>" + delimiter;
        else if (activeObject.tagName == "PRE")
            temp += "<pre>" + delimiter;
        else if (activeObject.tagName == "LI") {
            if (activeObject.parentNode.tagName == "DIR")
                temp += "<dir>" + delimiter;
            if (activeObject.parentNode.tagName == "MENU")
                temp += "<menu>" + delimiter;
        } else {
            temp += "NORMAL" + delimiter;
        }
    } catch (Error) {
        temp += delimiter;
    }
    // font combo
    temp += editQuery("FontName") + delimiter;
    // font combo
    temp += editQuery("FontSize") + delimiter;

    return temp;
};

function oncontextmenuPINEDIT(e) {
    //lert(document.frames['pinEdit'].window.event.srcElement.tagName);
    //  editPopup(document.frames['pinEdit'].window.event);
    if (browser.ie) {
        editPopup(getWindow().event);
    } else {
        e.preventDefault();
        editPopup(e);
    }

    return false;
};

function onblurPINEDIT() {
    eventOnBlur();
};

function onfocusPINEDIT() {
    __editSetFocusStatus();
};

function onmousedownPINEDIT(e) {
    if (browser.ns) {
        if (eventOnMouseDown(e))
            return;

        try {
            editSetFocus();
            // hide popup
            popup.style.visibility = "hidden";
            // call method to close open popups
            if (toolbarstop)
                toolbarstop.reset();

            if (objMenuBar) {
                var objMenu = objMenuBar.getActiveBarItem();
                if (objMenu)
                    objMenu.reset();
            }
        } catch (Error) { };

        __editActiveObject = e.target;

        // active object is needed
        var temp = __editBuildToolbarStatus();
        if (eventOnChangeToolbar(temp))
            return;

        try {
            cmbFont.setSelectedText(editQuery("FontName").toUpperCase());
        } catch (Error) { };
        try {
            cmbFontSize.setSelectedText(editQuery("fontsize"));
        } catch (Error) { };
        try {
            var format = editQuery("FormatBlock");
            if (format == "p")
                cmbFormat.setSelectedText("NORMAL");
            else
                cmbFormat.setSelectedText("<" + format + ">");
        } catch (Error) { };
        try {
            if (__editActiveObject.className == "")
                cmbStyle.setSelectedText("STANDARD");
            else
                cmbStyle.setSelectedText(__editActiveObject.className);
        } catch (Error) { };
    } else {
        var evt = getWindow().event;
        // call event routine
        if (eventOnMouseDown(evt))
            return;
        __editActiveObject = getWindow().event.srcElement;
    }
    // build tag hierarchy
    __editBuildTagHierarchy();
};

function onkeydownPINEDIT(e) {
    var evt;

    if (browser.ns)
        evt = e;
    else
        evt = getWindow().event;

    // call event routine
    if (eventOnKeyDown(evt))
        return;

    try {
        if (evt.keyCode >= 48 || evt.keyCode <= 90 || evt.keyCode == 13) {
            __editOnChanged(true);
        }
    } catch (Error) { };

    try {
        // Ctrl + F10
        if (evt.keyCode == 121 && evt.ctrlKey) {
            if (__editIsEvaluation)
                alert("pinEdit Evaluation: " + __editVersion);
            else
                alert("pinEdit Release: " + __editVersion);
        }
        // Ctrl + F9
        if (globalDebug) {
            if (evt.keyCode == 120 && evt.ctrlKey)
                __editShowParameters();
        }

        if (__editControlVDisabled) {
            if (evt.keyCode == 86 && evt.ctrlKey) {
                // call event
                eventControlV();
                evt.cancelBubble = true;
                evt.returnValue = false;
                return false;
            }
        }
    } catch (Error) { };

    if (browser.ns)
        return;

    if (__intelliAction())
        return;

    // if content not editable then cancel keys (bug of IE)
    try {
        if (getDoc().selection.createRange().parentElement().contenteditable == "false") {
            // allow cursor keys
            if (evt.keyCode < 37 || evt.keyCode > 40) {
                evt.cancelBubble = true;
                evt.returnValue = false;
                return;
            }
        }
    } catch (Error) { };

    if (__isIntelli) {
        evt.cancelBubble = true;
        evt.returnValue = false;
        return;
    }

    if (__editIsBR) {
        if (evt.keyCode == 13) {
            var sel = getDoc().selection;
            if (sel.type == "Control")
                return;
            var r = sel.createRange();
            if (__editIsBR)
                r.pasteHTML("<BR>");
            else
            // this does not work in LI tags
                r.pasteHTML("<P>");

            evt.cancelBubble = true;
            evt.returnValue = false;

            r.select();
            r.moveEnd("character", 1);
            r.moveStart("character", 1);
            r.collapse(false);

            return false;
        }
    } else {
        if (evt.keyCode == 13) {
            evt.cancelBubble = true;
            //evt.returnValue = false;
            //return false;
        }
    }

    if (evt.keyCode == 9) {
        try {
            var parent = __editActiveObject;
            while (parent.tagName.toUpperCase() != "BODY") {
                if (parent.tagName.toUpperCase() == "TD") {
                    __editActiveObject = parent;
                    break;
                }
                parent = parent.parentNode;
            }

            if (__editActiveObject.tagName == "TD") {
                var currentRow = __editActiveObject.parentNode;
                // check if Shift is pressed
                if (evt.shiftKey) {
                    if (__editActiveObject.cellIndex > 0) {
                        nextCell = currentRow.cells[__editActiveObject.cellIndex - 1];
                    } else {
                        // previous row
                        if (currentRow.rowIndex > 0)
                            var table = currentRow.parentNode;
                        var lastCell = table.rows[currentRow.rowIndex - 1].cells.length - 1;
                        nextCell = table.rows[currentRow.rowIndex - 1].cells[lastCell];
                    }
                } else {
                    // next cell
                    if (currentRow.cells.length - 1 > __editActiveObject.cellIndex) {
                        nextCell = currentRow.cells[__editActiveObject.cellIndex + 1];
                    } else {
                        // next row
                        var idx = currentRow.rowIndex + 1;
                        var table = currentRow.parentNode;
                        if (idx <= table.rows.length - 1) {
                            nextCell = table.rows[idx].cells[0];
                        } else {
                            // add new row
                            var row = table.insertRow(currentRow.rowIndex + 1);
                            for (var i = 0; i < currentRow.cells.length; i++) {
                                row.insertCell();
                            }
                            nextCell = row.cells[0];
                        }
                    }
                }
                __editActiveObject = nextCell;
                var r = getDoc().body.createTextRange();
                r.moveToElementText(nextCell);
                r.select();
                evt.cancelBubble = true;
                evt.returnValue = false;
            }
        } catch (Error) { };
    }
};

function onkeypressPINEDIT() {
    var evt = getWindow().event;

    if (__isIntelli) {
        evt.cancelBubble = true;
        evt.returnValue = false;
        return;
    }

    if (evt.keyCode == globalISKey) {
        var sel = getDoc().selection;
        var r = sel.createRange();
        r.moveStart("character", -1);
        var text = r.text;
        var moved = 0;
        while (text.charCodeAt(0) != "32" && text.charCodeAt(0) != "13" && text.charCodeAt(0) != "10") {
            if (r.moveStart("character", -1) == 0)
                break;
            text = r.text;
        }
        // the first char must be excluded
        if (text.charCodeAt(0) == "32" || text.charCodeAt(0) == "13" || text.charCodeAt(0) == "10") {
            text = text.substring(1, text.length);
            if (text.charCodeAt(0) == "32" || text.charCodeAt(0) == "13" || text.charCodeAt(0) == "10") {
                text = text.substring(1, text.length);
            }
        }
        for (var i = 0; i < text.length + 1; i++) {
            r.moveStart("character", 1);
        }
        // save position
        __intelliLeft = r.boundingLeft + 7;
        var top = globalGetPositonY(getEdit());
        __intelliTop = r.boundingTop + r.boundingHeight + top;
        // call server
        __comm = new Comm(targetIntellisense);
        __comm.execute("INTELLI", text, "");
    }

    if (__editIsBR) {
        var evt = getWindow().event;
        __NoBr(evt);
    }
};

function onkeyupPINEDIT() {

    try {
        if (browser.ns) {
            //__editActiveObject = e.target;
        } else {
            if (getDoc().selection.createRange().text.length == 0) {
                __editActiveObject = getDoc().selection.createRange().parentElement();
            }
        }

        var evt = getWindow().event;

        if (__isIntelli) {
            evt.cancelBubble = true;
            evt.returnValue = false;
            return;
        }

        onchangePINEDIT();
        /*
        if(globalSingleMode) {
        var temp = __editBuildToolbarStatus();
        if(eventOnChangeToolbar(temp))
        return;

        } else {
        // pressing ctrl+b shall actiualize the BOLD button
        if((evt.keyCode == 66 || evt.keyCode == 73 || evt.keyCode == 85) && evt.ctrlKey) {
        var objComponents = toolbarstop.getTagComponents();
        // check if active
        for(var i=0;i<objComponents.length;i++) {
        var tag = objComponents[i].tag;
        if(tag == "BOLD" || tag == "ITALIC" || tag == "UNDERLINE") {
        var res = editQuery(tag);
        if(res != null) {
        objComponents[i].setStatus(res);
        }
        }
        }
        }
        }
        */
        if (__editIsBR) {
            var evt = getWindow().event;
            __NoBr(evt);
        }
    } catch (Error) { };
};

function onkeydownPINEDITHtml() {
    var evt = document.frames('pinEditHtml').window.event;

    if (evt.keyCode == 13) {
        var sel = pinEditHtml.document.selection;
        if (sel.type == "Control")
            return;

        var r = sel.createRange();
        r.pasteHTML("<BR>");
        evt.cancelBubble = true;
        evt.returnValue = false;

        r.select();
        r.moveEnd("character", 1);
        r.moveStart("character", 1);
        r.collapse(false);

        return false;
    }
};

function __intelliHide() {
    try {
        __isIntelli = false;
        document.getElementById("__popup").style.visibility = "hidden";
        document.getElementById("__intelli0").scrollIntoView(false);
        __intelliPos = -1;
        __intelliData = new Array();
    } catch (Error) { };
};

function __intelliMouseClick(row) {
    editInsertHtml(document.getElementById("__intelli" + row).innerHTML);
    __intelliHide();
};

function __intelliAction() {
    if (__isIntelli) {
        for (var i = 0; i < __intelliRowCount; i++) {
            document.getElementById("__intelli" + i).style.backgroundColor = "white";
            document.getElementById("__intelli" + i).style.borderColor = "white";
        }
        var evt = getWindow().event;

        if (evt.keyCode == 40) {
            __intelliPos++;
            if (__intelliPos >= __intelliRowCount)
                __intelliPos = 0;
            document.getElementById("__intelli" + __intelliPos).style.backgroundColor = "#B1C0D2";
            document.getElementById("__intelli" + __intelliPos).style.borderColor = "#0A246A";
            document.getElementById("__intelli" + __intelliPos).scrollIntoView(false);
        }
        if (evt.keyCode == 38) {
            __intelliPos--;
            if (__intelliPos < 0)
                __intelliPos = __intelliRowCount - 1;
            document.getElementById("__intelli" + __intelliPos).style.backgroundColor = "#B1C0D2";
            document.getElementById("__intelli" + __intelliPos).style.borderColor = "#0A246A";
            document.getElementById("__intelli" + __intelliPos).scrollIntoView(false);
        }
        if (evt.keyCode == 13 || evt.keyCode == 32) {
            if (__intelliPos >= 0 && __intelliPos <= __intelliRowCount)
                editInsertHtml(__intelliData[__intelliPos]);
            evt.cancelBubble = true;
            evt.returnValue = false;
            __intelliHide();
            return true;
        }
        if (evt.keyCode == 27 || evt.keyCode == 8) {
            __intelliHide();
        }
    }
};

function __intelliProcess(data) {
    var temp = "";
    temp += "<table width='100%' cellspacing='0' cellpadding='0' border=0 style='padding: 1px;font-family: arial;font-size: 11px'>";
    temp += "<tr><td>";

    var aTexts = __data.split("&&;");
    __intelliRowCount = aTexts.length - 1;
    for (var i = 0; i < aTexts.length - 1; i++) {
        var aText = aTexts[i].split("&&:");
        var temp1 = aText[0];
        var image = "";
        if (temp1 != "")
            image = "<img src='" + temp1 + "' border='0'>";
        var text = aText[1];
        var value = aText[2];
        __intelliData[i] = value;
        //temp += "<table id='__intelli" + i + "' onmouseover='this.style.borderColor=\"#0A246A\";this.style.background=\"#B1C0D2\"' onmouseout='this.style.borderColor=\"white\";this.style.background=\"white\"' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'>" + image + "</td><td style='margin-left: 2px;color: black' onclick='javascript: __intelliMouseClick(" + i + ")'>" + text + "</td></tr><table>"
        temp += "<table id='__intelli" + i + "' style='border: 1px solid white;background: white;font-family: arial;font-size: 11px' border='0' cellspacing='0' cellpadding='1' width='100%'><tr><td width='1'>" + image + "</td><td style='margin-left: 2px;color: black'>" + text + "</td></tr><table>"
    }
    temp += "</td></tr>";
    temp += "</table>";
    var objPopup = document.getElementById("__popup");
    objPopup.innerHTML = temp;
    objPopup.style.left = __intelliLeft;
    objPopup.style.top = __intelliTop;
    objPopup.style.visibility = "visible";
    __isIntelli = true;
};


function __editOnChanged(value) {
    __editChanged = value;

    // fire event
    try {
        if (value)
            eventOnChanged();
    } catch (Error) {

     };

    if (browser.ns)
        return;

    // when we are in HTML mode
    if (editGetMode() == "HTML") {
        if (browser.ns)
            var docHtml = document.getElementById('pinEditHtml').contentWindow.document;
        else
            var docHtml = pinEditHtml.document;

        if (globalHTMLMode == "1") {
            if (globalHTMLModeExtended) {
                html = editGetHtmlFormatted(1);
                docHtml.body.innerHTML = html;
            } else {
                html = doc.body.innerHTML;
                if (browser.ns) {
                    html = html.replace(/</gi, "&lt;");
                    html = html.replace(/>/gi, "&gt;");
                    docHtml.body.innerHTML = html;
                } else {
                    docHtml.body.innerText = html;
                }
            }
        }
        if (globalHTMLMode == "2") {
            if (globalHTMLModeExtended) {
                html = editGetHtmlFormatted(2);
                docHtml.body.innerHTML = html;
            } else {
                html = doc.documentElement.innerHTML;
                docHtml.body.innerText = html;
            }
        }
        __editContent = docHtml.body.innerText;
    }
};

function __NoBr(evt) {
    if (evt.keyCode == 13) {
        evt.cancelBubble = true;
        evt.returnValue = false;
        return false;
    }
};

function getDoc() {
    if (browser.ns)
        return document.getElementById('pinEdit').contentWindow.document;
    else
        return pinEdit.document;
};

function getDocHtml() {

    if (browser.ns)
        return document.getElementById('pinEditHtml').contentWindow.document;
    else
        return pinEditHtml.document;
};

function getDocPreview() {
    if (browser.ns)
        return document.getElementById('pinEditPreview').contentWindow.document;
    else
        return pinEditPreview.document;
};

function getWindow() {
    try {
        if (browser.ns)
            return document.getElementById('pinEdit').contentWindow;
        else
            return document.frames('pinEdit').window;
    }
    catch (err) {
        return document.getElementById('pinEdit').contentWindow;
    }
};

function getEdit() {
    return document.getElementById('pinEdit');
};

function setEvent() {
    if (!browser.ns) {
        getDoc().oncontextmenu = oncontextmenuPINEDIT;
        getDoc().onselectionchange = onchangePINEDIT;
        getDoc().onmousedown = onmousedownPINEDIT;
        getDoc().onkeydown = onkeydownPINEDIT;
        getDoc().onkeypress = onkeypressPINEDIT;
        getDoc().onkeyup = onkeyupPINEDIT;
        getDocHtml().oncontextmenu = oncontextmenuDisabled;
        getDocPreview().oncontextmenu = oncontextmenuDisabled;
    } else {
        getDoc().addEventListener("mouseup", onmousedownPINEDIT, false);
        getDoc().addEventListener("contextmenu", oncontextmenuPINEDIT, false);
        getDoc().addEventListener("blur", onblurPINEDIT, false);
        getDoc().addEventListener("focus", onfocusPINEDIT, false);
        getDoc().addEventListener("keydown", onkeydownPINEDIT, false);
    }
};

function oncontextmenuDisabled() {
    return false;
};

function editCancel() {
    document.location.href = __currentURL;
};

function editOpen(mode, localPath) {
    // define editor url
    var editorUrl = __editGetEditorUrl();
    var type = "OPEN";
    var filter = "";

    if (mode == 0) {
        parent.editFile.click();
    }
    // document
    if (mode == 1 || mode == 4 || mode == 5 || mode == 6) {
        // in relative mode built the absolute path
        var baseUrl = "";
        var basePath = "";
        if (globalDocumentUrlAbsolute == "") {
            baseUrl = __editGetEditorWeb() + globalDocDir + "/";
            basePath = globalRootPath != "" ? (globalRootPath + globalDocDir + "/") : "";
        } else {
            baseUrl = globalDocumentUrlAbsolute;
            basePath = globalDocumentPathAbsolute;
        }
        if (mode == 1) {
            type = "OPEN";
            filter = globalDialogFilterDoc;
        } else if (mode == 4) {
            type = "OPEN";
            filter = "swf;";
        } else if (mode == 5) {
            type = "OPEN";
            filter = "avi;";
            if (__NotSupportedByMozilla()) return;
        } else if (mode == 6) {
            type = "OPEN";
            filter = "htm;html;";
            baseUrl = globalTemplateUrlAbsolute;
            basePath = globalTemplatePathAbsolute;
        }

        if (browser.ns) {
            var left = screen.width / 2 - 600 / 2;
            var top = screen.height / 2 - 300 / 2;
            window.open(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=" + type + "&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + filter, "color", "modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
        } else {
            var path = window.showModalDialog(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=" + type + "&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + filter, "", "dialogHeight:300px;dialogWidth:600px;resizable:1;status:0;scroll:0");
            if (path != "0" && path != null) {
                if (mode == 1) {
                    editLoad(path);
                } else if (mode == 4) {
                    var html = "<EMBED src='" + path + "' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' loop='false' menu='false' quality='high' play='true'>";
                    editInsertHtml(html);
                } else if (mode == 5) {
                    var html = "<EMBED src='" + path + "' type='application/x-mplayer2' pluginspage='http://download.microsoft.com/download/winmediaplayer/nsplugin/6.4/WIN98/EN-US/wmpplugin.exe'>";
                    editInsertHtml(html);
                } else if (mode == 6) {
                    editLoad(path);
                }
            }
        }
    }
    if (mode == 2) {
        setPropertyValue("editPath", localPath);
        invokeMethodInModel("onLoad");
    }
    // Image
    if (mode == 3) {
        // in relative mode built the absolute path
        var baseUrl = "";
        var basePath = "";
        if (globalImageUrlAbsolute == "") {
            baseUrl = __editGetEditorWeb() + globalImageDir + "/";
            basePath = globalRootPath != "" ? (globalRootPath + globalImageDir + "/") : "";
        } else {
            baseUrl = globalImageUrlAbsolute;
            basePath = globalImagePathAbsolute;
        }
        if (browser.ns) {
            var left = screen.width / 2 - 600 / 2;
            var top = screen.height / 2 - 300 / 2;
            window.open(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=IMAGE&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + globalDialogFilterImage, "color", "modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
        } else {
            var path = window.showModalDialog(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=IMAGE&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + globalDialogFilterImage, "", "dialogHeight:300px;dialogWidth:600px;resizable:1;status:0;scroll:0");
            if (path != "0" && path != null) {
                content = "<img src='" + path + "'>";
                editInsertHtml(content);
            }
        }
    }
};

function editSave(url) {
    var text;

    if (__editSaveMode == 0)
        text = editGetHtml();
    if (__editSaveMode == 1)
        text = editGetBodyHtml();
    if (__editSaveMode == 2)
        text = editGetHtmlRel();
    if (__editSaveMode == 3)
        text = editGetBodyHtmlRel();
    if (__editSaveMode == 4)
        text = editGetXHtml();
    if (__editSaveMode == 5)
        text = editGetXHtmlBody();

    __comm = new Comm(target);
    if (url) {
        __currentURLTemp = url;
        __comm.executeSave(text, url);
    } else {
        __currentURLTemp = __currentURL;
        __comm.executeSave(text, __currentURL);
    }
};

function editSaveDialog() {
    var editorUrl = __editGetEditorUrl();

    // in relative mode built the absolute path
    var baseUrl = "";
    var basePath = "";
    if (globalDocumentUrlAbsolute == "") {
        baseUrl = __editGetEditorWeb() + globalDocDir + "/";
        basePath = globalRootPath != "" ? (globalRootPath + globalDocDir + "/") : "";
    } else {
        baseUrl = globalDocumentUrlAbsolute;
        basePath = globalDocumentPathAbsolute;
    }

    if (browser.ns) {
        var left = screen.width / 2 - 600 / 2;
        var top = screen.height / 2 - 300 / 2;
        window.open(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=SAVE&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + globalDialogFilterDoc, "color", "modal=1,left=" + left + ",top=" + top + ",height=300,width=600,resizable=1,status=0,scrollbars=0");
    } else {
        var path = window.showModalDialog(editorUrl + "dialogs/" + globalTechnology + "/dialog.html?mode=SAVE&language=" + language + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology + "&filter=" + globalDialogFilterDoc, "", "dialogHeight:300px;dialogWidth:400px;resizable:1;status:0;scroll:0");
        if (path != "0" && path != null) {
            // set the temp variable so that we can reload the file after correct saving
            __currentURLTemp = path;
            // we want to reload that we have the url and can make a save
            __editReloadAfterSave = true;
            editSave(path);
        }
    }
};

function editNew() {
    // call event system
    eventOnBeforeNew();

    if (browser.ns) {
        editWrite("");
    } else {
        editWrite("");
        editSetStyleSheetRules();
    }
    __currentURL = "";
    __editOnChanged(false);
};

function editLoad(url) {
    if (url.indexOf("pinEdit.html") > 0)
        return;

    // call event system
    eventOnBeforeLoad();

    if (url != "") {
        if (browser.ns)
        // load in preview frame and read the content
            document.getElementById("pinEditPreview").src = url;
        else
            getEdit().src = url;
    }
    window.setTimeout("editInit()", 50);
};

function editInit() {
    __editOnChanged(false);
    __editDocumentLoadedFlag = false;

    if (browser.ie) {
        if (getDoc().readyState.toUpperCase() != "COMPLETE") {
            window.setTimeout("editInit()", 50);
            return;
        }
    } else {
        try {
            var egal = document.getElementById("pinEditPreview").contentWindow.document.body;
            // write content of preview to edit doc
            var doc = getDoc();
            doc.designMode = "on";
            doc.open();
            doc.write(document.getElementById("pinEditPreview").contentWindow.document.documentElement.innerHTML);
            doc.close();
        } catch (Error) {
            window.setTimeout("editInit()", 50);
            return;
        }
    }

    if (browser.ie)
        __currentURL = getDoc().location.href;
    else
        __currentURL = document.getElementById("pinEditPreview").contentWindow.document.location.href;

    if (__currentURL.indexOf("pinEdit.html") > 0 || __currentURL.indexOf("dummy.html") > 0)
        __currentURL = "";

    if (browser.ns) {
        var doc = getDoc();
        if (!doc.body.style.backgroundColor)
            doc.body.style.backgroundColor = "white";
        setEvent();
        editSetStyleSheetRules();
    } else {
        setEvent();
        editSetStyleSheetRules();
        editMultipleSelection();
        __editShowSymbols();
    }
    __editDocumentLoadedFlag = true;

    if (globalAutoFocus)
        editSetFocus();

};

function editSetStyleSheetObject(combo) {
    __editStyleSheetCombo = combo;
};

function editSetFormatObject(combo) {
    __editFormatCombo = combo;
};

function editSetStyleSheetRules() {

    

    if (!globalSingleMode) {
        if (!__editStyleSheetCombo) {
            return;
        }
    }
    
    try {
        if (!globalSingleMode) {
            __editStyleSheetCombo.clear();
            if (browser.ns) {
                __editStyleSheetCombo.add("Standard", "STANDARD");
            } else {
               __editStyleSheetCombo.add(new ComboItem("Standard", "", "", "STANDARD", "Standard"));
            }
        } else {
            eventOnAddStyleDelay("", "");
            eventOnAddStyleDelay("Standard", "Standard");
        }

        if (getDoc().styleSheets.length > 0) {
            
            var objStyleSheet = getDoc().styleSheets[0];
            var objRules;
            if (browser.ns) {
                objRules = objStyleSheet.cssRules;
            } else {
                objRules = objStyleSheet.rules;
            }
            for (var i = 0; i < objRules.length; i++) {
                var value = objRules[i].selectorText;
                // check for . classes, but only if there is not space like .table_td td {}
                if (value.substring(0, 1) == "." && value.indexOf(' ') < 0) {
                    value = value.substring(1, value.length);
                    // set some styles to the row
                    var style = objRules[i].style;

                    if (!globalSingleMode) {
                        if (browser.ns) {
                            __editStyleSheetCombo.add(value, value);
                        } else {
                            
                            // if color is white...
                            if (style.color == "#FFFFFF" || style.color == "#ffffff" || style.color == "white")
                                var html = "<span style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color: #c0c0c0'>" + value + "</span>";
                            else
                                var html = "<span style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color:" + style.backgroundColor + "'>" + value + "</span>";
                            __editStyleSheetCombo.add(new ComboItem(html, "", "", value, value));
                        }
                    } else {
                        if (style.color == "#FFFFFF" || style.color == "#ffffff" || style.color == "white")
                            var html = "<span unselectable='on' style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color: #c0c0c0'>" + value + "</span>";
                        else
                            var html = "<span unselectable='on' style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color:" + style.backgroundColor + "'>" + value + "</span>";
                        // now call event
                        eventOnAddStyleDelay(value, html);
                    }
                }
                if (!globalSingleMode) {
                    if (__editFormatCombo != null) {
                        // check for h1-h6 settings
                        value = value.toUpperCase();
                        if (value == "H1" || value == "H2" || value == "H3" || value == "H4" || value == "H5" || value == "H6") {
                            var item = __editFormatCombo.getItemByValue("<" + value + ">");
                            var style = objRules[i].style;
                            var html = "<span style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color:" + style.backgroundColor + "'>" + item.tag1 + "</span>";
                            item.text = html;
                        }
                    }
                } else {
                    value = value.toUpperCase();
                    if (value == "H1" || value == "H2" || value == "H3" || value == "H4" || value == "H5" || value == "H6") {
                        var style = objRules[i].style;
                        var html = "<span unselectable='on' style='font-family:" + style.fontFamily + ";font-size:" + style.fontSize + ";color:" + style.color + ";border:" + style.border + ";background-color:" + style.backgroundColor + "'>";
                        eventOnChangeFormat(value, html);
                    }
                }
            }
            if (!globalSingleMode)
                __editStyleSheetCombo.setSelectedText("Standard");
        }
    } catch (Error) {
    
     }
};

// delay is need when editor is faster than toolbar
function eventOnAddStyleDelay(name, html) {
    __editTempAddStyleName = name;
    __editTempAddStyleHtml = html;
    setTimeout("eventOnAddStyleDelay2(\"" + name + "\",\"" + html + "\")", 200);
};

function eventOnAddStyleDelay2(name, html) {
    eventOnAddStyle(name, html);
};

function editSetStyle(value) {
    var style = "";
    var sel = "";

    try {
        if (editHasSelection()) {
            if (editGetSelectionType() == "CONTROL") {
                if (value == "STANDARD") {
                    // remove style
                    __editActiveObject.removeAttribute("className", "", 0);
                } else {
                    // set style
                    __editActiveObject.className = value;
                }
            } else {
                // selection and text
                if (value == "STANDARD") {
                    //var tags = editGetSelectedTags();
                    //var selHtml = editGetSelectedHtml();
                    //selHtml = selHtml.replace(/class=[^ ]+ /gi, "");
                    //selHtml = selHtml.replace(/class=[^>]+>/gi, ">");
                    //editInsertHtml(selHtml);
                } else {
                    // set style
                    var selHtml = editGetSelectedHtml();
                    editInsertHtml("<span class='" + value + "'>" + selHtml + "</span>");
                }
            }
        } else {
            // no selection
            if (value == "STANDARD") {
                // remove style
                __editActiveObject.removeAttribute("className", "", 0);
            } else {
                // set style
                __editActiveObject.className = value;
            }
        }
        editSetFocus();
    } catch (Error) { };

    /*
    if(browser.ie) {
    if(editGetDocument().selection.type.toUpperCase() != "CONTROL")
    sel = "T";
    else
    sel = "C";
    } else {
    sel = "T";
    }

    if(sel == "T") {  
    if(editGetSelectedText() == "") {
    if(value == "STANDARD")
    style = "";
    else
    style = value;
    } else {
    var selHtml = editGetSelectedHtml();
    editInsertHtml("<span class='" + value + "'>" + selHtml + "</span>");
    }
    } else {
    if(value == "STANDARD")
    style = "";
    else
    style = value;
    }

    editSetFocus();
    if(__editActiveObject) {
    if(style == "") {
    __editActiveObject.removeAttribute("className","",0);
    } else {
    __editActiveObject.className = style;
    }
    }
    */
};


function editSearch() {
    if (__NotSupportedByMozilla()) return;

    var editorUrl = __editGetEditorUrl();

    var aParam = new Array();
    aParam[0] = language;
    aParam[1] = design;
    aParam[2] = "";
    aParam[3] = "";
    aParam[4] = "";
    aParam[5] = getDoc();

    var values = window.showModalDialog("dialogs/search.html", aParam, "dialogHeight:" + (165 + globalDialogOffset) + "px;dialogWidth:400px;resizable:0;status:0;scroll:0");
    editSetFocus();
};

// we need the uploaded file
function callback_editUpload(file) {
    __editUploadedFile = __editUploadUrl + file;
    content = "<img src='" + __editUploadedFile + "'>";
    editInsertHtml(content);
};

function editUpload(path, url, mode, insert) {
    var web = __editGetEditorUrl();
    var left = screen.width / 2 - 476 / 2;
    var top = screen.height / 2 - 166 / 2;

    if (insert) {
        insert = 1;
    } else {
        insert = 0;
    }
    var baseUrl = "";
    var basePath = "";
    if (path != "") {
        basePath = path;
        baseUrl = url;
    } else {
        if (mode == 0) {
            if (globalImageUrlAbsolute == "") {
                baseUrl = __editGetEditorWeb() + globalImageDir + "/";
                basePath = globalRootPath != "" ? (globalRootPath + globalImageDir + "/") : "";
            } else {
                baseUrl = globalImageUrlAbsolute;
                basePath = globalImagePathAbsolute;
            }
        }
        if (mode == 1) {
            if (globalDocumentUrlAbsolute == "") {
                baseUrl = __editGetEditorWeb() + globalDocDir + "/";
                basePath = globalRootPath != "" ? (globalRootPath + globalDocDir + "/") : "";
            } else {
                baseUrl = globalDocumentUrlAbsolute;
                basePath = globalDocumentPathAbsolute;
            }
        }
    }
    __editUploadUrl = baseUrl;
    __editUploadPath = basePath;
    window.open(web + "dialogs/" + globalTechnology + "/upload.html?language=" + language + "&insert=" + insert + "&urlabs=" + baseUrl + "&pathabs=" + basePath + "&tech=" + globalTechnology, "", "modal=1,left=" + left + ",top=" + top + ",height=166,width=476,resizable=0,status=0,scrollbars=0");
};

// upload and insert (for images only)
function editUploadInsert(path, url, mode) {
    editUpload(path, url, mode, 1);
};

function __editHideSymbols() {
    if (browser.ns)
        return;

    var aForms = getDoc().getElementsByTagName("form");
    for (i = 0; i < aForms.length; i++) {
        if (aForms[i].style.borderStyle.toUpperCase() == "DOTTED") {
            aForms[i].style.borderWidth = "";
            aForms[i].style.borderStyle = "";
            aForms[i].style.borderColor = "";
        }
    }

    var aAnchors = getDoc().getElementsByTagName("a");
    for (i = 0; i < aAnchors.length; i++) {
        if (aAnchors[i].name != "") {
            aAnchors[i].style.borderWidth = "";
            aAnchors[i].style.borderStyle = "";
            aAnchors[i].style.borderColor = "";
            // remove image
            aAnchors[i].innerHTML = "";
        }
    }

    /*
    var aTables = getDoc().getElementsByTagName("table");
    __editTableHighlight = false;
    for(i=0;i<aTables.length;i++) {
    aTables[i].title = "";
    }
    */

    // if table is highlighted
    if (__editTableHighlight)
        editTableHighlight();
};

function __editShowSymbols() {
    if (browser.ns)
        return;

    var aForms = getDoc().getElementsByTagName("form");
    for (i = 0; i < aForms.length; i++) {
        aForms[i].style.borderWidth = 1;
        aForms[i].style.borderStyle = "dotted";
        aForms[i].style.borderColor = "red";
    }

    var aAnchors = getDoc().getElementsByTagName("a");
    var url = __editGetEditorUrl();
    for (i = 0; i < aAnchors.length; i++) {
        if (aAnchors[i].name != "") {
            aAnchors[i].style.borderWidth = "1";
            aAnchors[i].style.borderStyle = "dotted";
            aAnchors[i].style.borderColor = "blue";
            // add image
            aAnchors[i].innerHTML = "<IMG src='" + url + "design/image/anchor.gif' border=0 unselectable='ON'>";
        }
    }
};

function editSelectAll() {
    if (browser.ie) {
        var rng = getDoc().body.createTextRange();
        rng.select();
    } else {
        execute('selectall', false, null);
    }
};

function editCut() { execute('cut', false, null); };
function editCopy() { execute('copy', false, null); };
function editPaste() { execute('paste', false, null); };
function editUndo() { execute('undo'); };
function editRedo() { execute('redo'); };

function editLink() {
    var editorUrl = __editGetEditorUrl();

    try {

        if (browser.ie) {
            // if we have a selection than check if it fits to an A tag
            var r = getDoc().selection.createRange();
            // if we have a text selection
            if (getDoc().selection.type.toUpperCase() != "CONTROL") {
                if (r.text.length > 0) {
                    var p = r.parentElement();
                    // if we have a link
                    if (p.tagName.toUpperCase() == "A") {
                        __editActiveObject = p;
                    } else {
                        // if we have only one child
                        if (p.childNodes.length == 1) {
                            var child = p.childNodes[0];
                            // if we have a link
                            if (child.nodeName.toUpperCase() == "A") {
                                __editActiveObject = child;
                            }
                        }
                    }
                }
            }
        }

        // in relative mode built the absolute path
        var baseUrl = "";
        var basePath = "";
        if (globalDocumentUrlAbsolute == "") {
            baseUrl = __editGetEditorWeb() + globalDocDir + "/";
            basePath = globalRootPath != "" ? (globalRootPath + globalDocDir + "/") : "";
        } else {
            baseUrl = globalDocumentUrlAbsolute;
            basePath = globalDocumentPathAbsolute;
        }
        // check if current object is a link
        var parent = __editActiveObject;
        if (__editActiveObject) {
            while (parent.tagName.toUpperCase() != "BODY") {
                if (parent.tagName.toUpperCase() == "A") {
                    __editActiveObject = parent;
                    break;
                }
                parent = parent.parentNode;
            }

            // if we have a link
            if (__editActiveObject.tagName.toUpperCase() == "A") {

                var aParam = new Array();
                aParam[0] = language;
                aParam[1] = design;
                aParam[2] = "0";
                aParam[3] = getDoc();
                aParam[4] = globalLinkPathRelative;
                aParam[5] = __editActiveObject;
                aParam[6] = globalTechnology;
                aParam[7] = globalDialogFilterLink;
                aParam[8] = globalServerPathRelative;
                aParam[9] = window;
                aParam[10] = baseUrl;
                aParam[11] = basePath;

                if (browser.ie) {
                    var values = window.showModalDialog(editorUrl + "dialogs/link.html", aParam, "dialogHeight:" + (210 + globalDialogOffset) + "px;dialogWidth:360px;resizable:0;status:0;scroll:0");
                } else {
                    __editMozParam = new Array();
                    __editMozParam[0] = language;
                    __editMozParam[1] = design;
                    __editMozParam[2] = "0";
                    __editMozParam[3] = getDoc();
                    __editMozParam[4] = "";
                    __editMozParam[5] = __editActiveObject;
                    __editMozParam[6] = globalTechnology;
                    __editMozParam[7] = globalDialogFilterLink;
                    __editMozParam[8] = globalServerPathRelative;
                    __editMozParam[9] = window;
                    __editMozParam[10] = baseUrl;
                    __editMozParam[11] = basePath;
                    var left = screen.width / 2 - 360 / 2;
                    var top = screen.height / 2 - 180 / 2;
                    window.open(editorUrl + "dialogs/link.html", "color", "modal=1,left=" + left + ",top=" + top + ",height=180,width=360,resizable=0,status=0,scrollbars=0");
                }
                editSetFocus();
                __editOnChanged(true);
            } else {
                // do we have a selection
                if (!editHasSelection()) {
                    alert(getLanguageString(language, 3012));
                } else {
                    if (browser.ie) {
                        var range = getDoc().selection.createRange();
                        if (getDoc().selection.type.toUpperCase() == "CONTROL") {
                            if (range.length > 1) {
                                alert("Please select only one object !");
                                return;
                            } else {
                                if (range(0).tagName.toUpperCase() != "IMG") {
                                    alert("You can set links only to images !");
                                    return;
                                }
                            }
                        }
                        var aParam = new Array();
                        aParam[0] = language;
                        aParam[1] = design;
                        aParam[2] = "1";
                        aParam[3] = getDoc();
                        aParam[4] = "";
                        aParam[5] = range;
                        aParam[6] = globalTechnology;
                        aParam[7] = globalDialogFilterLink;
                        aParam[8] = "";
                        aParam[9] = window;
                        aParam[10] = baseUrl;
                        aParam[11] = basePath;

                        var values = window.showModalDialog(editorUrl + "dialogs/link.html", aParam, "dialogHeight:" + (210 + globalDialogOffset) + "px;dialogWidth:360px;resizable:0;status:0;scroll:0");
                    } else {
                        __editMozParam = new Array();
                        __editMozParam[0] = language;
                        __editMozParam[1] = design;
                        __editMozParam[2] = "1";
                        __editMozParam[3] = getDoc();
                        __editMozParam[4] = "";
                        __editMozParam[5] = range;
                        __editMozParam[6] = globalTechnology;
                        __editMozParam[7] = globalDialogFilterLink;
                        __editMozParam[8] = "";
                        __editMozParam[9] = window;
                        __editMozParam[10] = baseUrl;
                        __editMozParam[11] = basePath;
                        var left = screen.width / 2 - 360 / 2;
                        var top = screen.height / 2 - 180 / 2;
                        window.open(editorUrl + "dialogs/link.html", "color", "modal=1,left=" + left + ",top=" + top + ",height=180,width=360,resizable=0,status=0,scrollbars=0");
                    }
                    editSetFocus();
                    __editOnChanged(true);
                }
            }
        } else {
            alert(getLanguageString(language, 3012));
        }
    } catch (error) { };
    //  }
};

function __editGetParam() {
    return __editMozParam;
};

function editMultipleSelection() { execute('MultipleSelection', '', true); };
function editInsert() { execute('OverWrite', '', false); };
function editOverwrite() { execute('OverWrite', '', true); };
function editFont(font) { execute('FontName', '', font); };
function editFontSize(size) { execute('fontsize', '', size); };
function editZoom(value) {
    if (__NotSupportedByMozilla()) return;
    getEdit().style.zoom = value;
};
function editPrint() { execute('print', true); };
function editBold() { execute('bold'); };
function editItalic() { execute('italic'); };
function editUnderline() { execute('underline'); };
function editSuperscript() { execute('superscript'); };
function editSubscript() { execute('subscript'); };
function editStikeThrough() { execute('stikethrough'); };
function editIndent() { execute('indent'); };
function editOutdent() { execute('outdent'); };
function editJustifyLeft() { execute('justifyleft'); };
function editJustifyCenter() { execute('justifycenter'); };
function editJustifyRight() { execute('justifyright'); };
function editJustifyFull() { execute('justifyfull'); };
function editOrderedList() { execute('InsertOrderedList'); };
function editUnorderedList() { execute('InsertUnorderedList'); };
function editRemoveFormat() { execute('RemoveFormat'); };
function editFormat(format) { execute('FormatBlock', false, format); };
function editParagraph() { execute('InsertParagraph'); };

var __editDelayDoc = null;
function editRefresh(doc) {
    //execute('Refresh');
    __editDelayDoc = doc;
    setTimeout("__editDelayRefresh()", 2);
};

function __editDelayRefresh() {
    __editDelayDoc.body.innerHTML = __editDelayDoc.body.innerHTML;
    // sets the cursor home
    if (globalAutoFocus)
        editSetCursorHome();
};

function editBookmark(value) {
    if (value)
        execute('createbookmark', null, 'Text');
    else
        execute('UnBookmark');
};

function editBackColor(color) {
    if (color == "NOCOLOR")
        color = "";

    if (browser.ns) {
        execute('hilitecolor', '', color)
    } else {
        execute('BackColor', '', color)
    }
};

function editColor(color) {
    if (color == "NOCOLOR") {
        execute('ForeColor', '', '');
    } else {
        execute('ForeColor', '', color);
    }
};


function editSetFocus() {
    getWindow().focus();
};


function editWriteFirstTime(htmlin) {
    // handle relative paths
    var html = __editProcessRelative(htmlin);

    if (browser.ie) {
        var doc = getDoc();
        doc.open();
        doc.write(html);
        doc.close();
        // this redraws the content to avoid wrong text display
        doc.body.innerHTML = doc.body.innerHTML;
        __editShowSymbols();
        
        setEvent();
        editSetStyleSheetRules();
        // this causes wrong text display 	
        editMultipleSelection();
        //ie macht warum auch immer eine Textselektion
        editRefresh(doc);
        
        if (globalAutoFocus)
           editSetFocus();

        editSetFocus();
        editSetCursorHome();
        editSetFocus();

    } else {
        var doc = getDoc();
        doc.designMode = "on";
        doc.open();
        doc.write(html);
        doc.close();
        // this is because access to doc after doc.close seems to be not working
        setTimeout("__edit_delay_write_moz()", 20);
    }
    __currentURL = "";
    __editOnChanged(false);
};

function editWrite(htmlin) {
    // handle relative paths
    var html = __editProcessRelative(htmlin);

    if (browser.ie) {
        var doc = getDoc();
        doc.open();
        doc.write(html);
        doc.close();
        // this redraws the content to avoid wrong text display
        doc.body.innerHTML = doc.body.innerHTML;
        __editShowSymbols();

        setEvent();
        editSetStyleSheetRules();
        // this causes wrong text display 	
        editMultipleSelection();
        editRefresh(doc);
        if (globalAutoFocus)
            editSetFocus();
    } else {
        var doc = getDoc();
        doc.designMode = "on";
        doc.open();
        doc.write(html);
        doc.close();
        // this is because access to doc after doc.close seems to be not working
        setTimeout("__edit_delay_write_moz()", 20);
    }
    __currentURL = "";
    __editOnChanged(false);
};

function __edit_delay_write_moz() {
    try {
        var temp = getDoc().body;
    } catch (error) {
        setTimeout("__edit_delay_write_moz()", 50);
    }
    var doc = getDoc();
    if (globalAutoFocus)
        editSetFocus();
    setEvent();
    editSetStyleSheetRules();
    // avoid blue color
    doc.body.style.backgroundColor = "white";
    __currentURL = "";
    __editOnChanged(false);
};


// used for spell checker
function editSetBodyHtml(html) {
    var doc = getDoc();
    doc.body.innerHTML = html;
    __editShowSymbols();
    __editOnChanged(false);
};

function editGetHtml() {
    var docHtml = getDocHtml();
    var doc = getDoc();
    if (browser.ns) {
        return doc.documentElement.innerHTML;
    } else {
        if (editGetMode() == "HTML") {
            return docHtml.body.innerText;
        } else {
            __editHideSymbols();
            return doc.documentElement.innerHTML;
        }
    }
};

function editGetHtmlRel() {
    var docHtml = getDocHtml();
    var doc = getDoc();
    if (editGetMode() == "HTML") {
        var html = docHtml.body.innerText;
        doc.open();
        doc.write(html);
        doc.close();
    }

    if (browser.ns) {
        return doc.documentElement.innerHTML;
    } else {
        // fix image
        //__editFixImage();
        // fix anchor url
        //__editFixAnchor();
        // fix link
        //__editFixLink();    
        // hide symbols
        __editHideSymbols();
        // 
        return __editProcessRelativeRead(doc.documentElement.innerHTML)
    }
};

function editGetHtmlBody() {
    return editGetBodyHtml();
};

function editGetBodyHtml() {
    var docHtml = getDocHtml();
    var doc = getDoc();
    if (browser.ns) {
        return doc.body.innerHTML;
    } else {
        if (editGetMode() == "HTML") {
            return docHtml.body.innerText;
        } else {
            __editHideSymbols();
            return doc.body.innerHTML;
        }
    }
};

function editGetHtmlBodyRel() {
    return editGetBodyHtmlRel();
};


function editGetBodyHtmlRel() {
    var docHtml = getDocHtml();
    var doc = getDoc();
    if (editGetMode() == "HTML") {
        var html = docHtml.body.innerText;
        doc.body.innerHTML = html;
    }

    if (browser.ns) {
        return __editProcessRelativeRead(doc.body.innerHTML);
    } else {
        // fix image
        //__editFixImage();
        // fix anchor url
        //__editFixAnchor();
        // fix link
        //__editFixLink();    
        __editHideSymbols();
        return __editProcessRelativeRead(doc.body.innerHTML);
    }
};

function __editProcessRelative(html) {
    if (globalImagePathRelative != "") {
        html = html.replace(/<img([^s]+)src=\"([^\"]+)\"/gi, "<img$1src=\"" + globalImagePathRelative + "$2\"");
        html = html.replace(/<img([^s]+)src='([^\"]+)'/gi, "<img$1src='" + globalImagePathRelative + "$2'");
    }
    if (globalLinkPathRelative != "") {
        html = html.replace(/href=\"([^\"]+)\"/gi, "href=\"" + globalLinkPathRelative + "$1\"");
        html = html.replace(/href='([^\"]+)'/gi, "href='" + globalLinkPathRelative + "$1'");
    }
    return html;
};

function __editProcessRelativeRead(html) {
    if (globalImagePathRelative != "") {
        var re = new RegExp(globalImagePathRelative, "gi");
        html = html.replace(re, "");
    }
    if (globalLinkPathRelative != "") {
        var re = new RegExp(globalLinkPathRelative, "gi");
        html = html.replace(re, "");
    }
    return html;
};


function editGetText() {
    var doc = getDoc();
    if (browser.ns) {
        var text = doc.body.innerHTML;
        text = text.replace(/&lt;/gi, "<");
        text = text.replace(/&gt;/gi, ">");
        return text; ;
    } else {
        var data = doc.body.innerText;
        document.getElementById('__editData').value = data;
        return data;
    }
};

function editSetText(text) {
    var doc = getDoc();

    if (browser.ns) {
        text = text.replace(/</gi, "&lt;");
        text = text.replace(/>/gi, "&gt;");
        doc.body.innerHTML = text;
    } else {
        doc.body.innerText = text;
    }
    __editOnChanged(true);
};

function editInsertHtml(htmlin, notProcessRelative) {
    var html = "";

    if (!notProcessRelative)
        html = htmlin;
    else
    // handle relative paths
        html = __editProcessRelative(htmlin);

    try {
        if (browser.ns) {
            __editOnChanged(true);
            editSetFocus();
            var buffer = document.createElement("div");
            var selection = getWindow().getSelection();
            var range = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
            selection.removeAllRanges();
            //var frag = range.cloneContents();
            buffer.innerHTML = html;
            range.deleteContents();
            var bufferRange = document.createRange();
            bufferRange.selectNodeContents(buffer);
            var frag = bufferRange.cloneContents();
            range.insertNode(frag);
            range.detach();
            //document.removeChild(buffer);
            editSetFocus();
        } else {
            editSetFocus();
            pasteHTML(html);
            editSetFocus();
        }
    } catch (Error) { };
};

function editInsertText(text) {
    __editOnChanged(true);
    editSetFocus();
    if (browser.ns) {
        __MozillaInsertNodeAtSelection(getDoc().createTextNode(text));
    } else {
        pasteText(text);
    }
    editSetFocus();
};

function pasteHTML(html) {
    try {
        __editOnChanged(true);
        var doc = getDoc();
        var range = doc.selection.createRange();
        range.pasteHTML(html);
    } catch (Error) { };
};

function pasteText(text) {
    try {
        if (editGetMode() == "HTML")
            var doc = getDocHtml();
        else
            var doc = getDoc();
        var range = doc.selection.createRange();
        range.text = text;
    } catch (Error) { };
};

function editGetSelectedHtml() {
    var html = "";
    var doc = getDoc();

    if (browser.ns) {
        try {
            editSetFocus();
            var buffer = document.createElement("div");
            var selection = getWindow().getSelection();
            var range = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
            //selection.removeAllRanges();
            var frag = range.cloneContents();
            buffer.appendChild(frag);
            html = buffer.innerHTML;
        } catch (Error) { };

    } else {
        var range = doc.selection.createRange();
        html = range.htmlText;
    }

    document.getElementById('__editData').value = html;
    return html;
};

function editGetSelectedTags() {
    //var buffer = document.createElement("div");
    //buffer.innerHTML = editGetSelectedHtml();
    var buffer = getDoc().selection.createRange().parentElement();

    __editSelectedTags = new Array();
    for (var i = 0; i < buffer.childNodes.length; i++) {
        var node = buffer.childNodes[i];
        if (node.nodeType == 1)
            __editBuildSelectedTags(node);
    }
    return __editSelectedTags;
}

function __editBuildSelectedTags(node) {
    __editSelectedTags[__editSelectedTags.length] = node;

    if (node.canHaveChildren || node.hasChildNodes()) {
        // process childs
        var childs = node.childNodes;
        for (var j = 0; j < childs.length; j++) {
            if (childs[j].nodeType == 1)
                __editBuildSelectedTags(childs[j]);
        }
    }
}

function editGetSelectedText() {
    var doc = getDoc();
    if (browser.ie) {
        var range = doc.selection.createRange();
        var data = range.text;
    } else {
        var selection = getWindow().getSelection();
        var data = selection.getRangeAt(selection.rangeCount - 1).toString();
    }
    document.getElementById('__editData').value = data;
    return data;
};

function executeSelection(command, value, ui) {
    __editOnChanged(true);
    var doc = getDoc();
    var range = doc.selection.createRange();
    range.execCommand(command, ui, value);
};

function execute(command, ui, value) {
    try {
        if (command != "AbsolutePosition" && command != "2D-Position" && command != "MultipleSelection" && command != "copy")
            __editOnChanged(true);
        if (globalAutoFocus && command != "MultipleSelection")
            editSetFocus();

        if (browser.ns && command == "print") {
            getWindow().print();
            return true;
        }

        return getDoc().execCommand(command, ui, value);
    } catch (Error) {
        if (browser.ns && (command == 'cut' || command == 'copy' || command == 'paste'))
            alert("'Cut','Copy' or 'Paste' functions are currently not available because of security reasons. Please goto http://mozilla.org/editor/midasdemo/securityprefs.html to find out how to enabled these functions.")
    }
};

function editQuery(command) {
    try {
        var doc = getDoc();
        if (browser.ns) {
            return doc.queryCommandValue(command);
        } else {
            var range = doc.selection.createRange();
            return range.queryCommandValue(command);
        }
    } catch (Error) {
        return false;
    }
};

function editAbsolute() {
    if (browser.ie) {
        var sel = getDoc().selection;
        if (sel.type.toUpperCase() != "CONTROL")
            return;
    }

    if (__editActiveObject) {
        if (__editActiveObject.style.position.toUpperCase() == "ABSOLUTE") {
            if (browser.ie) {
                //
                var range = sel.createRange();
                if (range.length == 1) {
                    execute('AbsolutePosition', '', false);
                    execute('2D-Position', '', false);
                } else {
                    execute('AbsolutePosition', '', true);
                    execute('2D-Position', '', true);
                }
            } else {
                __editActiveObject.style.position = "";
            }
        } else {
            if (browser.ie) {
                execute('AbsolutePosition', '', true);
                execute('2D-Position', '', true);
            } else {
                __editActiveObject.style.position = "absolute";
            }
        }
    }
};

function editCreateTable(row, col) {
    //  editSetFocus();
    __editOnChanged(true);

    if (browser.ns) {
        var doc = getDoc();
        var table = doc.createElement("table");
        table.setAttribute("border", "1");
        table.setAttribute("cellpadding", "1");
        table.setAttribute("cellspacing", "1");
        table.setAttribute("style", "width:50%");
        var tbody = doc.createElement("tbody");
        for (var i = 0; i < row; i++) {
            tr = doc.createElement("tr");
            for (var j = 0; j < col; j++) {
                if (globalFirstTableRowIsHeader && i == 0)
                    td = doc.createElement("th");
                else
                    td = doc.createElement("td");
                br = doc.createElement("br");
                td.appendChild(br);
                tr.appendChild(td);
            }
            tbody.appendChild(tr);
        }
        table.appendChild(tbody);
        __MozillaInsertNodeAtSelection(table);
    } else {
        var temp = "";
        temp = "<table style='width:50%' border='1'>";
        for (var i = 0; i < row; i++) {
            temp += "<tr>";
            for (var j = 0; j < col; j++) {
                if (globalFirstTableRowIsHeader && i == 0)
                    temp += "<th>&nbsp;</th>";
                else
                    temp += "<td>&nbsp;</td>";
            }
            temp += "</tr>";
        }
        temp += "</table>";
        editInsertHtml(temp);
    }
};

function editInsertObject(obj) {
    var editorUrl = __editGetEditorUrl();
    var content = '';

    editSetFocus();
    
    if (obj == 'FORM') {
        if (__NotSupportedByMozilla()) return;
        content = "<form style='border: 1px dotted red'>&nbsp;</form>&nbsp;";
    }
    if (obj == 'BUTTON') {
        if (browser.ie) {
            execute('InsertInputButton');
            return;
        } else {
            if (__NotSupportedByMozilla()) return;
            content = "<input type='button'>";
        }
    }
    if (obj == 'FIELDSET') {
        if (__NotSupportedByMozilla()) return;
        execute('InsertFieldset');
        return;
    }
    if (obj == 'INPUT') {
        if (browser.ie) {
            execute('InsertInputText');
            return;
        } else {
            content = "<input type='text'>";
        }
    }
    if (obj == 'LISTBOX') {
        if (browser.ie) {
            execute('InsertSelectListBox');
            return;
        } else {
            content = "<select multiple='true'></select>";
        }
    }
    if (obj == 'COMBO') {
        if (browser.ie) {
            execute('InsertSelectDropDown');
            return;
        } else {
            content = "<select></select>";
        }
    }
    if (obj == 'CHECK') {
        execute('InsertInputCheckbox');
        return;
    }
    if (obj == 'OPTION') {
        execute('InsertInputRadio');
        return;
    }
    if (obj == 'AREA') {
        execute('InsertTextArea');
        return;
    }
    if (obj == 'IFRAME') {
        execute('InsertIFrame');
        return;
    }
    if (obj == 'MARQUEE') {
        if (__NotSupportedByMozilla()) return;
        execute('InsertMarquee');
    }
    if (obj == 'HIDDEN') {
        execute('InsertInputHidden');
        return;
    }
    if (obj == 'UPLOAD') {
        execute('InsertInputFileUpload');
        return;
    }
    if (obj == 'TABLE') {
        content = "<table border='1' width='100%'><tr><td></td><td></td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr><table>";
    }
    if (obj == 'DIV') {
        content = "<div style='z-index:" + __zindex + ";width:100;height:100;background-color:#c0c0c0;position:absolute '></div>";
        __zindex++;
    }
    if (obj == 'LABEL') {
        content = "<p style='z-index:" + __zindex + ";padding-left: 3px;width:100px;height:25px;'>Text</p>";
        __zindex++;
    }
    if (obj == 'IMAGE') {
        execute('InsertImage', true);
        return;
    }
    if (obj == 'IMAGEWEB') {
        if (browser.ns) {
            var left = screen.width / 2 - 200;
            var top = screen.height / 2 - 115;
            window.open(editorUrl + "dialogs/webimage.html", "color", "modal=1,left=" + left + ",top=" + top + ",height=120,width=400,resizable=0,status=0,scrollbars=0");
        } else {
            var aParam = new Array();
            aParam[0] = language;
            aParam[1] = design;

            var url = window.showModalDialog(editorUrl + "dialogs/webimage.html", aParam, "dialogHeight:" + (120 + globalDialogOffset) + "px;dialogWidth:400px;resizable:0;status:0;scroll:0");
            if (url != "")
                content = "<img src='" + url + "' border=0>";
            else
                return;
        }
    }
    if (obj == 'RULE') {
        execute('inserthorizontalrule');
        return;
    }

    if (obj == 'ANCHOR') {
        if (__NotSupportedByMozilla()) return;

        var aParam = new Array();
        aParam[0] = language;
        aParam[1] = design;
        var name = window.showModalDialog(editorUrl + "dialogs/anchor.html?language=" + language, aParam, "dialogHeight:" + (120 + globalDialogOffset) + "px;dialogWidth:400px;resizable:0;status:0;scroll:0");
        var url = __editGetEditorUrl();
        if (name != "")
            content = "<a style='border: 1px dotted blue' name='" + name + "'><IMG src='" + url + "design/image/anchor.gif' border=0 unselectable='ON'></a>";
        else
            return;
    }
    if (obj == 'PAGEBREAK') {
        content = "<DIV title='Page Break' contentEditable=false style='FONT-SIZE: 1px; PAGE-BREAK-AFTER: always; HEIGHT: 1px; BACKGROUND-COLOR: #c0c0c0'></DIV>";
    }
    if (obj == 'FIELD') {
        content = "<Span id='" + "Field" + __editFieldCounter + "' class='FIELD' contentEditable=true class='FieldDesign' style='margin-left: 2px; height: 16px; width: 80px; BACKGROUND-COLOR: #c0c0c0'>Field " + __editFieldCounter + "</Span>";
        __editFieldCounter++;
    }
    if (obj == 'FLASH') {
        var aParam = new Array();
        aParam[0] = language;
        aParam[1] = design;
        var name = window.showModalDialog(editorUrl + "dialogs/flash.html?language=" + language, aParam, "dialogHeight:120px;dialogWidth:400px;resizable:0;status:0;scroll:0");
    }
    editInsertHtml(content, false);
};


function setMode(mode) {
    var html = "";
    var isUpdate = false;

    if (mode == lastMode)
        return;

    var doc = getDoc();
    if (mode == "EDIT") {
        __editDefaultFont != "" ? (doc.body.style.fontFamily = __editDefaultFont) : (doc.body.style.fontFamily = '');
        __editDefaultFontSize != "" ? (doc.body.style.fontSize = __editDefaultFontSize) : (doc.body.style.fontSize = '');

        // when called from pinToolbar
        try {
            toolbarstop.show();
            if (editGetMenuVisible())
                editMenuVisible(true);
        } catch (Error) { };

        if (globalHierarchyBarVisible)
            editSetHierachyBarVisible(true);

        // Mozilla does only work in design mode when iframe visible				
        document.getElementById("pinEditPreview").style.display = 'none';
        document.getElementById("pinEditHtml").style.display = 'none';
        document.getElementById("pinEdit").style.display = 'inline';

        if (browser.ns)
            doc.designMode = "on";

        // check if content changed
        if (browser.ns)
            var docHtml = document.getElementById('pinEditHtml').contentWindow.document;
        else
            var docHtml = pinEditHtml.document;

        if (browser.ie) {
            html = docHtml.body.innerText;

            if (__enableRetainCode) {
                // check if there a returns
                html = html.replace(/\r/gi, "");
                html = html.replace(/\n/gi, "<cr>");
                alert(html)
            }

            if (__editContent != html) {
                __editContent = html;
                __editChanged = true;
                eventOnChanged();
                if (globalHTMLMode == "1")
                    doc.body.innerHTML = __editProcessRelative(html);
                if (globalHTMLMode == "2") {
                    doc.open();
                    // in relative mode the path is new calculated relative to editor dir
                    // therefore the absolute path has to be set before
                    doc.write(__editProcessRelative(html));
                    doc.close();
                }
            }
            __editShowSymbols();
            if (lastMode == "HTML" && globalHTMLMode == "2") {
                setEvent();
                editSetStyleSheetRules();
                editMultipleSelection();
            }
            editSetFocus();
        } else {
            if (lastMode == "HTML") {
                var temp = docHtml.body.innerHTML.replace(/<[^>]+>/g, "");
                temp = temp.replace(/&lt;/gi, "<");
                temp = temp.replace(/&gt;/gi, ">");
                temp = temp.replace(/\&nbsp;/gi, "");
                doc.body.innerHTML = temp;
            }
        }
        __editEditorStatus = "EDIT";
        if (browser.ie)
            editRefresh(doc);
    }

    if (mode == "HTML") {
        __editHideSymbols();

        if (browser.ns)
            var docHtml = document.getElementById('pinEditHtml').contentWindow.document;
        else
            var docHtml = pinEditHtml.document;

        docHtml.body.style.fontFamily = 'Courier New';
        docHtml.body.style.fontSize = '10pt';
        docHtml.body.style.backgroundColor = "white";

        // when called from pinToolbar
        try {
            toolbarstop.hide();
            if (objMenuBar) {
                objMenuBar.setVisible(false);
                document.body.style.marginTop = 1;
            }
        } catch (Error) { };

        editSetHierachyBarVisible(false);
        document.getElementById("pinEditPreview").style.display = 'none';
        document.getElementById("pinEdit").style.display = 'none';
        document.getElementById("pinEditHtml").style.display = 'inline';

        if (browser.ns)
            docHtml.designMode = "on";

        if (globalHTMLMode == "1") {
            if (globalHTMLModeExtended) {
                html = editGetHtmlFormatted(1);
                docHtml.body.innerHTML = html;
            } else {
                html = doc.body.innerHTML;
                if (browser.ns) {
                    html = html.replace(/</gi, "&lt;");
                    html = html.replace(/>/gi, "&gt;");
                    docHtml.body.innerHTML = html;
                } else {
                    docHtml.body.innerText = html;
                }
            }
        }
        if (globalHTMLMode == "2") {
            if (globalHTMLModeExtended) {
                html = editGetHtmlFormatted(2);
                docHtml.body.innerHTML = html;
            } else {
                html = doc.documentElement.innerHTML;
                docHtml.body.innerText = html;
            }
        }
        __editContent = docHtml.body.innerText;
        __editEditorStatus = "HTML";

        if (!browser.ns) {
            pinEditHtml.document.onkeydown = onkeydownPINEDITHtml;
            try  {
            document.frames('pinEditHtml').window.focus();
            }
            catch (err) {
                document.getElementById('pinEditHtml').contentWindow.focus();
            }
        }

        if (browser.ie)
            editRefresh(docHtml);
    }

    if (mode == "PREVIEW") {
        __editHideSymbols();

        // when called from pinToolbar
        try {
            toolbarstop.hide();
            if (objMenuBar) {
                objMenuBar.setVisible(false);
                document.body.style.marginTop = 1;
            }
        } catch (Error) { };

        if (browser.ns) {
            var docHtml = document.getElementById('pinEditHtml').contentWindow.document;
            var docPreview = document.getElementById('pinEditPreview').contentWindow.document;
        } else {
            var docPreview = pinEditPreview.document;
            var docHtml = pinEditHtml.document;
        }

        // if HTML mode has changed then change edit mode
        if (browser.ie) {
            html = docHtml.body.innerText;
            if (__editContent != html) {
                __editChanged = true;
                if (globalHTMLMode == "1")
                    doc.body.innerHTML = __editProcessRelative(html);
                if (globalHTMLMode == "2") {
                    doc.open();
                    doc.write(__editProcessRelative(html));
                    doc.close();
                }
            }
        }

        if (__currentURL != "" && !__editChanged) {
            document.getElementById('pinEditPreview').src = __currentURL;
        } else {
            doc.body.innerHTML = doc.body.innerHTML;
            docPreview.open();
            docPreview.write(doc.documentElement.innerHTML);
            docPreview.close();
        }
        if (!browser.ns)
        {
            try  {
            document.frames('pinEditPreview').window.focus();
            }
            catch (err) {
                document.getElementById('pinEditPreview').contentWindow.focus();
            }
        }

        editSetHierachyBarVisible(false);
        document.getElementById("pinEditHtml").style.display = 'none';
        document.getElementById("pinEdit").style.display = 'none';
        document.getElementById("pinEditPreview").style.display = 'inline';
        if (browser.ie)
            editRefresh(docPreview);
    }
    lastMode = mode;
};

function __editHidePopup() {
    if (browser.ie)
        popup.hide();
    else
        popup.style.visibility = "hidden";
};

function __editInsertRow(mode) {
    try {
        __editOnChanged(true);
        var newRow = currentRow.cloneNode(true);

        var aCells = currentRow.cells;
        for (var i = 0; i < aCells.length; i++) {
            aCells[i].innerHTML = "&nbsp;";
        }
        if (mode == 1)
            currentRow.parentNode.insertBefore(newRow, currentRow);
        else
            currentRow.parentNode.insertBefore(newRow, currentRow.nextSibling);

        __editHidePopup();

    } catch (Error) { };
};

function __editDeleteRow() {
    try {
        __editOnChanged(true);
        /*
        if(browser.ie) {
        table.deleteRow(currentRow.rowIndex);
        popup.hide();
        } else {
        */
        currentRow.parentNode.removeChild(currentRow);
        //		}
        __editHidePopup();
    } catch (Error) { };
};

function __editConvertRow() {
    try {
        for (var i = 0; i < currentRow.cells.length; i++) {
            var cell = currentRow.cells[i];
            if (cell.tagName == "TD") {
                var th = getDoc().createElement("th");
                th.innerHTML = cell.innerHTML;
                currentRow.replaceChild(th, cell);
            }
            if (cell.tagName == "TH") {
                var td = getDoc().createElement("td");
                td.innerHTML = cell.innerHTML;
                currentRow.replaceChild(td, cell);
            }
        }
        __editHidePopup();
    } catch (Error) { };
};

function __editInsertColumn(mode) {
    try {
        __editOnChanged(true);
        if (browser.ie) {
            var index;
            if (mode == 0) {
                index = currentCol.cellIndex;
            } else {
                index = currentCol.cellIndex + 1;
            }
            for (var i = 0; i < table.rows.length; i++) {
                table.rows[i].insertCell(index);
            }
            popup.hide();
        } else {
            if (mode == 0) {
                index = currentCol.cellIndex;
            } else {
                index = currentCol.cellIndex + 1;
            }
            for (var i = 0; i < table.rows.length; i++) {
                var tr = table.rows[i];
                var curtd = tr.cells[index];
                var newtd = getDoc().createElement("td");
                newtd.innerHTML = "&nbsp;";
                tr.insertBefore(newtd, curtd);
            }
        }
        __editHidePopup();
    } catch (Error) { };
};

function __editDeleteColumn() {
    try {
        __editOnChanged(true);
        /*
        if(browser.ie) {
        var index = currentCol.cellIndex;
        for(var i=0;i<table.rows.length;i++) {
        table.rows[i].deleteCell(index);
        }
        popup.hide();
        } else {
        */
        var index = currentCol.cellIndex;
        for (var i = 0; i < table.rows.length; i++) {
            var tr = table.rows[i];
            var curtd = tr.cells[index];
            tr.removeChild(curtd);
        }
        //		}
        __editHidePopup();
    } catch (Error) { };
};

function __editDeleteCell() {
    try {
        __editOnChanged(true);
        //table.rows[currentRow.rowIndex].deleteCell(currentCol.cellIndex);
        //currentRow.removeChild(currentRow.cells[currentCol.cellIndex]);
        currentRow.removeChild(currentCol);
        __editHidePopup();
    } catch (Error) { };
};

function __editMergeCell() {
    try {
        __editOnChanged(true);
        var colspan1 = table.rows[currentRow.rowIndex].cells[currentCol.cellIndex].colSpan;
        var colspan2 = table.rows[currentRow.rowIndex].cells[currentCol.cellIndex + 1].colSpan;
        table.rows[currentRow.rowIndex].cells[currentCol.cellIndex].innerHTML = table.rows[currentRow.rowIndex].cells[currentCol.cellIndex].innerHTML + table.rows[currentRow.rowIndex].cells[currentCol.cellIndex + 1].innerHTML;
        table.rows[currentRow.rowIndex].deleteCell(currentCol.cellIndex + 1);
        table.rows[currentRow.rowIndex].cells[currentCol.cellIndex].colSpan = (colspan1 + colspan2);
    } catch (Error) { };
    __editHidePopup();
};

function __editDivideCell() {
    try {
        __editOnChanged(true);
        if (currentCol.colSpan > 1) {
            currentCol.colSpan = currentCol.colSpan - 1;
            //table.rows[currentRow.rowIndex].insertCell(currentCol.cellIndex);
            var newtd = getDoc().createElement("td");
            newtd.innerHTML = "&nbsp;";
            currentRow.insertBefore(newtd, currentCol);
        }
        __editHidePopup();
    } catch (Error) { };
};

function __editRemoveTable() {
    try {
        // deselect
        var range = getDoc().createRange();
        var referenceNode = getDoc().body;
        range.selectNode(referenceNode);

        // remove table
        table.parentNode.removeChild(table);

        popup.style.visibility = "hidden";
    } catch (Error) { };
};

function editSetForeground() {
    if (__NotSupportedByMozilla()) return;

    __editOnChanged(true);
    editSetToForeground();
    popup.hide();
};

function editSetBackground() {
    if (__NotSupportedByMozilla()) return;

    __editOnChanged(true);
    editSetToBackground();
    popup.hide();
};

function editSetToForeground() {
    var body = getDoc().body;
    var index = 0;

    for (var i = 0; i < body.all.length; i++) {
        var object = body.all[i];
        // remove form border
        var tag = object.tagName.toUpperCase();
        if (tag == "DIV" || tag == "SELECT" || tag == "INPUT" || tag == "P") {
            var curIndex = parseInt(object.style.zIndex);
            if (curIndex > index) {
                index = curIndex;
            }
        }
    }
    objSelected.style.zIndex = index + 1;
};

function editSetToBackground() {
    objSelected.style.zIndex = 0;
};

function __editRemoveAnchor() {
    try {
        __editOnChanged(true);
        objSelected.parentNode.removeNode(true);
    } catch (Error) { };
    popup.hide();
};

function __editRemoveForm() {
    try {
        __editOnChanged(true);
        objSelected.removeNode(true);
    } catch (Error) { };
    popup.hide();
};

function editProperties(type, inFile, inAttribute) {
    var editorUrl = __editGetEditorUrl();
    var file = "";
    var attribute = "";

    if (browser.ie) {
        var aParam = new Array();
        aParam[0] = language;
        aParam[1] = design;
        aParam[2] = "";
        aParam[3] = "";
        aParam[4] = getDoc();
    } else {
        __editMozParam = new Array();
        __editMozParam[0] = language;
        __editMozParam[1] = design;
        __editMozParam[2] = "";
        __editMozParam[3] = "";
        __editMozParam[4] = getDoc();
    }

    if (type == 0) {
        file = editorUrl + "dialogs/table.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[5] = table;
            attribute = "dialogHeight:" + (240 + globalDialogOffset) + "px;dialogWidth:400px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[5] = table;
            var left = screen.width / 2 - 400 / 2;
            var top = screen.height / 2 - 240 / 2;
            window.open(file, "table", "modal=1,left=" + left + ",top=" + top + ",height=200,width=400,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 2) {
        file = editorUrl + "dialogs/cell.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (210 + globalDialogOffset) + "px;dialogWidth:430px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 430 / 2;
            var top = screen.height / 2 - 185 / 2;
            window.open(file, "td", "modal=1,left=" + left + ",top=" + top + ",height=185,width=430,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 3) {
        file = editorUrl + "dialogs/image.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (220 + globalDialogOffset) + "px;dialogWidth:385px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 400 / 2;
            var top = screen.height / 2 - 170 / 2;
            window.open(file, "image", "modal=1,left=" + left + ",top=" + top + ",height=170,width=400,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 4) {
        if (__NotSupportedByMozilla()) return;
        aParam[5] = objSelected;
        file = editorUrl + "dialogs/body.html";
        if (inFile)
            file = inFile;
        attribute = "dialogHeight:" + (150 + globalDialogOffset) + "px;dialogWidth:250px;resizable:0;status:0;scroll:0";
        if (inAttribute)
            attribute = inAttribute;
        var values = window.showModalDialog(file, aParam, attribute);
    }
    if (type == 5) {
        file = editorUrl + "dialogs/input.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[2] = "DIV";
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (345 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[2] = "DIV";
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 290 / 2;
            var top = screen.height / 2 - 315 / 2;
            window.open(file, "image", "modal=1,left=" + left + ",top=" + top + ",height=315,width=290,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 6) {
        if (__NotSupportedByMozilla()) return;
        aParam[5] = objSelected;
        file = editorUrl + "dialogs/iframe.html";
        if (inFile)
            file = inFile;
        attribute = "dialogHeight:" + (175 + globalDialogOffset) + "px;dialogWidth:300px;resizable:0;status:0;scroll:0";
        if (inAttribute)
            attribute = inAttribute;
        var values = window.showModalDialog(file, aParam, attribute);
    }
    // label
    if (type == 7) {
        file = editorUrl + "dialogs/input.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[2] = "LABEL";
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (345 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[2] = "LABEL";
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 290 / 2;
            var top = screen.height / 2 - 315 / 2;
            window.open(file, "image", "modal=1,left=" + left + ",top=" + top + ",height=315,width=290,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 8) {
        if (__NotSupportedByMozilla()) return;
        aParam[5] = objSelected;
        file = editorUrl + "dialogs/anchor.html";
        if (inFile)
            file = inFile;
        attribute = "dialogHeight:" + (120 + globalDialogOffset) + "px;dialogWidth:400px;resizable:0;status:0;scroll:0";
        if (inAttribute)
            attribute = inAttribute;
        var values = window.showModalDialog(file, aParam, attribute);
    }
    if (type == 9) {
        if (__NotSupportedByMozilla()) return;
        aParam[5] = objSelected;
        file = editorUrl + "dialogs/form.html";
        if (inFile)
            file = inFile;
        attribute = "dialogHeight:" + (238 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
        if (inAttribute)
            attribute = inAttribute;
        var values = window.showModalDialog(file, aParam, attribute);
    }
    if (type == 10) {
        file = editorUrl + "dialogs/input.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[2] = "INPUT";
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (345 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[2] = "INPUT";
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 290 / 2;
            var top = screen.height / 2 - 315 / 2;
            window.open(file, "image", "modal=1,left=" + left + ",top=" + top + ",height=315,width=290,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 11) {
        file = editorUrl + "dialogs/input.html";
        if (inFile)
            file = inFile;
        if (browser.ie) {
            aParam[2] = "SELECT";
            aParam[5] = objSelected;
            attribute = "dialogHeight:" + (345 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
            if (inAttribute)
                attribute = inAttribute;
            var values = window.showModalDialog(file, aParam, attribute);
        } else {
            __editMozParam[2] = "SELECT";
            __editMozParam[5] = objSelected;
            var left = screen.width / 2 - 290 / 2;
            var top = screen.height / 2 - 315 / 2;
            window.open(file, "image", "modal=1,left=" + left + ",top=" + top + ",height=315,width=290,resizable=0,status=0,scrollbars=0");
        }
    }
    if (type == 12) {
        if (__NotSupportedByMozilla()) return;
        aParam[2] = "FLASH";
        aParam[5] = objSelected;
        file = editorUrl + "dialogs/flash.html";
        if (inFile)
            file = inFile;
        attribute = "dialogHeight:" + (396 + globalDialogOffset) + "px;dialogWidth:290px;resizable:0;status:0;scroll:0";
        if (inAttribute)
            attribute = inAttribute;
        var values = window.showModalDialog(file, aParam, attribute);
    }
    editSetFocus();
};

function __editOnContextMenuItemClick(id) {
    // hide popup
    if (browser.ns)
        popup.style.visibility = "hidden";

    // get item object
    var item = __editContextMenu.getItemById(id);
    // call event
    onContextMenuItemClick(item.value);
};

function editPopup(event) {
    if (!browser.ns)
        var source = event.srcElement;
    else
        var source = event.target;

    var mode = source.tagName;

    var isCell = false;
    var path = "";
    var popupWidth = 160;

    try {
        popupWidth = globalPopupWidth;
    } catch (Error) {
        popupWidth = 160;
    }

    try {
        objSelected = source;
        if (source.tagName == "TR") {
            currentRow = source;
            mode = "TR";
        } else {
            currentRow = null;
        }

        if (source.tagName == "TD" || source.tagName == "TH") {
            currentRow = source.parentNode;
            currentCol = source;
            mode = "TD";
        } else {
            currentCol = null;
        }
        // we need the table
        if (source.tagName == "TD" || source.tagName == "TH" || source.tagName == "TR") {
            var parent = source;
            while (parent.tagName != "TABLE") {
                parent = parent.parentNode;
            }
            table = parent;
            mode = "TD";
        }
        if (source.tagName == "TABLE") {
            table = source;
            mode = "TABLE";
        }
        if (source.tagName == "IMG") {
            var temp = objSelected.src;
            temp = temp.substring(temp.length - 10, temp.length).toUpperCase();
            if (temp == "ANCHOR.GIF")
                mode = "ANCHOR";
            else
                mode = "IMAGE";
        }
        if (source.tagName == "BODY") {
            mode = "BODY";
        }
        if (source.tagName == "DIV") {
            mode = "DIV";
        }
        if (source.tagName == "SPAN") {
            // check if it is a field
            if (objSelected.className == "FIELD")
                mode = "FIELD";
        }
        if (source.tagName == "IFRAME") {
            mode = "IFRAME";
        }
        if (source.tagName == "P") {
            mode = "P";
        }
        if (source.tagName == "FORM") {
            mode = "FORM";
        }
        if (source.tagName == "INPUT") {
            mode = "INPUT";
        }
        if (source.tagName == "SELECT") {
            mode = "SELECT";
        }
        if (source.tagName == "TEXTAREA") {
            mode = "TEXTAREA";
        }
        if (source.tagName == "FONT") {
            mode = "FONT";
        }
        if (source.tagName == "EMBED") {
            var src = source.src.toUpperCase();
            if (src.substring(src.length - 3, src.length) == "SWF")
                mode = "FLASH";
        }
    } catch (Error) { };

    if (mode == "")
        return;


    //  if(parent != null) {
    if (browser.ie) {
        var objPopup = window.createPopup();
        popup = objPopup;
    } else {
        //window.parent.
        var doc = window.parent.document;
        if (doc.getElementById("__MozPopup")) {
            var objPopup = doc.getElementById("__MozPopup");
        } else {
            var objPopup = doc.createElement("iframe");
            objPopup.id = "__MozPopup";
            objPopup.style.position = "absolute";
            objPopup.style.visibility = "hidden";
            objPopup.style.width = "200px";
            objPopup.style.zIndex = 10000;
            objPopup.frameBorder = 0;
            doc.body.appendChild(objPopup);
        }
        popup = objPopup;
    }

    // define new menu
    __editContextMenu = new Menu("");
    // set design
    if (design == "")
        __editContextMenu.design = "Office2000";
    if (design == "Office")
        __editContextMenu.design = "OfficeXP";
    if (design == "Office2003")
        __editContextMenu.design = "Office2003";
    // the callback from pinMenu.html
    if (browser.ie)
        __editContextMenu.callbackInternal = "__editOnContextMenuItemClick";
    else
        __editContextMenu.callbackInternal = "window.parent.document.getElementById('" + window.frameElement.id + "').contentWindow.__editOnContextMenuItemClick";
    // is a popup
    __editContextMenu.isPopupMode = true;
    // call config_context.js
    CreateContextMenu(mode, __editContextMenu, __editToolbarCode);
    // check if items have been added
    if (__editContextMenu.count() == 0 && mode != "FONT")
        return;

    // add a dynamic menu if object is not editable
    if (source.contenteditable == "false") {
        if (__editContextMenu.count() > 0)
            __editContextMenu.add(new MenuSeparator());
        __editContextMenu.add(new MenuItem(getLanguageString(language, 3100), "editor/design/image/" + design + "/edit.gif", "", "EDITABLE"));
    }

    var temp = "";
    temp += "<html><head><link rel='stylesheet' href='" + __editGetEditorUrl() + "menu/design/style/pinMenu.css' type='text/css'><script>";
    temp += "function onClick(table, row, design, func){ ";
    if (browser.ie)
        temp += "eval('parent.' + func + '(' + row + ')');};";
    else
        temp += "eval(func + '(' + row + ')');};";
    temp += "function onOver(table,row,design) { ";
    temp += "table.className = 'MenuItemHover' + design;";
    temp += " table.cellPadding = 1;";
    temp += "document.getElementById(row + '.2').className = 'MenuItemHoverText' + design;};";
    temp += "function onOut(table,row,design) { ";
    temp += "table.className = 'MenuItem' + design;";
    temp += " table.cellPadding = 2;";
    temp += "document.getElementById(row + '.2').className  = 'MenuItemFont' + design;};";
    temp += "</script></head><body style='background-color: white; border: 1px outset; margin:0;overflow:hidden'>";
    temp += __editContextMenu.create();
    temp += "</body></html>";

    if (browser.ie) {
        objPopup.document.open();
        objPopup.document.write(temp);
        objPopup.document.close();
        objPopup.show(event.clientX, event.clientY, popupWidth, __editContextMenu.height, getEdit());
    } else {
        var doc = objPopup.contentWindow.document;
        doc.open();
        doc.write(temp);
        doc.close();
        objPopup.style.height = __editContextMenu.height + 10;
        //alert(event.pageX)
        //alert(event.pageY)
        //alert("Document: " + window.parent.document.getElementById(window.frameElement.id).style.left);

        var frame = window.parent.document.getElementById(window.frameElement.id);
        var frameLeft = __editGetIframePositionX(frame);
        var frameTop = __editGetIframePositionY(frame);
        objPopup.style.left = parseInt(frameLeft) + event.layerX;
        objPopup.style.top = parseInt(frameTop) + event.layerY;
        objPopup.style.visibility = "visible";
    }

    return false;
};

function editInsertTextModule(comboID) {
    var combo = document.getElementById(comboID);
    var value = combo.options[combo.selectedIndex].value;
    if (value != '') {
        editInsertHtml(value);
    }
};

function __editCreateTextModule(name) {
    if (name == "")
        return;

    var text = editGetSelectedHtml();
    __comm = new Comm(targetTextModule);
    __comm.execute("SETTEXT", name, text);
};

function editSetTextModule(comboID) {
    var editorUrl = __editGetEditorUrl();
    try {
        var combo = document.getElementById(comboID);
    } catch (Error) { };

    var text = editGetSelectedHtml();
    if (text == "") {
        alert(getLanguageString(language, 3006));
        return;
    }

    if (browser.ie) {
        var name = window.showModalDialog(editorUrl + "dialogs/textmodule.html?language=" + language, "", "dialogHeight:" + (120 + globalDialogOffset) + "px;dialogWidth:355px;resizable:1;status:0;scroll:0");
        if (name == null || name == '')
            return;
        __editCreateTextModule(name);
    } else {
        var left = screen.width / 2 - 355 / 2;
        var top = screen.height / 2 - 100 / 2;
        window.open(editorUrl + "dialogs/textmodule.html?language=" + language, "tm", "modal=1,left=" + left + ",top=" + top + ",height=100,width=355,resizable=0,status=0,scrollbars=0");
    }
};

function editGetTextModule(comboID) {
    __comm = new Comm(targetTextModule);
    __comm.comboid = comboID;
    __comm.execute("GETTEXT", "", "");
};

function editDeleteTextModule(name) {
    editRemoveTextModule("", name);
};

function editRemoveTextModule(comboID, name) {
    try {
        var combo = document.getElementById(comboID);
        var value = combo.options[combo.selectedIndex].text;
    } catch (Error) { };

    if (name != "")
        value = name;

    if (value != '') {
        __comm = new Comm(targetTextModule);
        __comm.comboid = comboID;
        __comm.execute("REMOVETEXT", value, "");
    }
};

function __setFileToServer(path, text) {
    __comm = new Comm(target);
    __comm.execute("SAVE", path, text);
    return true;
};

function __getFileFromServer(path) {
    __comm = new Comm(target);
    __comm.execute("OPEN", path);
    return true;
};

function callbackMozilla(mode, para1, para2) {
    if (mode == "WEBIMAGE") {
        __MozillaInsertImage(para1);
    }
    if (mode == "OPENDOC") {
        if (para1 != "0" && para1 != null) {
            editLoad(para1);
        }
    }
    if (mode == "SAVEDOC") {
    }
    if (mode == "OPENIMAGE") {
        if (para1 != "0" && para1 != null) {
            __MozillaInsertImage(para1);
        }
    }
    if (mode == "TEXTMODULE") {
        __editCreateTextModule(para1);
    }
};

function __MozillaInsertLink(url) {
    execute('createlink', false, url);
};

function __MozillaInsertImage(url) {
    var doc = getDoc();
    var image = doc.createElement("img");
    image.setAttribute("border", "0");
    // prepare url
    //var temp = document.location.href;
    //var pos = temp.indexOf("?");
    //if(pos > 0)
    //  temp = temp.substring(0,pos);
    //pos = temp.lastIndexOf("/");
    //image.setAttribute("src", temp.substring(0,pos) + "/" + url);
    image.setAttribute("src", url);
    __MozillaInsertNodeAtSelection(image);
};

function __MozillaGetSelectedHtml() {
    // get current selection
    var sel = getWindow().getSelection();

    // get the first range of the selection
    // (there's almost always only one range)
    var range = sel.getRangeAt(0);

    // start node
    var startNode = range.startContainer;
    // end node
    var endNode = range.endContainer;

};

function __MozillaInsertNodeAtSelection(insertNode) {
    __editOnChanged(true);
    // get current selection
    var sel = getWindow().getSelection();
    // get the first range of the selection
    // (there's almost always only one range)
    var range = sel.getRangeAt(0);
    // deselect everything
    sel.removeAllRanges();
    // remove content of current selection from document
    range.deleteContents();
    // get location of current selection
    var container = range.startContainer;
    var pos = range.startOffset;
    // make a new range for the new selection
    range = document.createRange();
    if (container.nodeType == 3 && insertNode.nodeType == 3) {
        // if we insert text in a textnode, do optimized insertion
        container.insertData(pos, insertNode.nodeValue);
        // put cursor after inserted text
        range.setEnd(container, pos + insertNode.length);
        range.setStart(container, pos + insertNode.length);
    } else {
        var afterNode;
        if (container.nodeType == 3) {
            // when inserting into a textnode
            // we create 2 new textnodes
            // and put the insertNode in between
            var textNode = container;
            container = textNode.parentNode;
            var text = textNode.nodeValue;
            // text before the split
            var textBefore = text.substr(0, pos);
            // text after the split
            var textAfter = text.substr(pos);
            var beforeNode = document.createTextNode(textBefore);
            var afterNode = document.createTextNode(textAfter);
            // insert the 3 new nodes before the old one
            container.insertBefore(afterNode, textNode);
            container.insertBefore(insertNode, afterNode);
            container.insertBefore(beforeNode, insertNode);
            // remove the old node
            container.removeChild(textNode);
        } else {
            // else simply insert the node
            afterNode = container.childNodes[pos];
            container.insertBefore(insertNode, afterNode);
        }

        range.setEnd(afterNode, 0);
        range.setStart(afterNode, 0);
    }
    sel.addRange(range);
};

function __MozillaInnerHTML(html) {

    // get current selection
    var sel = getWindow().getSelection();
    // get the first range of the selection
    // (there's almost always only one range)
    var range = sel.getRangeAt(0);
    // deselect everything
    sel.removeAllRanges();
    // remove content of current selection from document
    range.deleteContents();
    var insertNode = range.createContextualFragment(html);
    // get location of current selection
    var container = range.startContainer;

    var pos = range.startOffset;
    // make a new range for the new selection
    range = document.createRange();

    if (container.nodeType == 3 && insertNode.nodeType == 3) {
        // if we insert text in a textnode, do optimized insertion
        container.insertData(pos, insertNode.nodeValue);
        // put cursor after inserted text
        range.setEnd(container, pos + insertNode.length);
        range.setStart(container, pos + insertNode.length);
    } else {
        var afterNode;
        if (container.nodeType == 3) {
            // when inserting into a textnode
            // we create 2 new textnodes
            // and put the insertNode in between
            var textNode = container;
            container = textNode.parentNode;
            var text = textNode.nodeValue;
            // text before the split
            var textBefore = text.substr(0, pos);
            // text after the split
            var textAfter = text.substr(pos);
            var beforeNode = document.createTextNode(textBefore);
            var afterNode = document.createTextNode(textAfter);
            // insert the 3 new nodes before the old one
            container.insertBefore(afterNode, textNode);
            container.insertBefore(beforeNode, afterNode);
            container.insertBefore(insertNode, afterNode);
            // remove the old node
            container.removeChild(textNode);
        } else {
            // else simply insert the node
            afterNode = container.childNodes[pos];
            container.insertBefore(insertNode, afterNode);
        }

        range.setEnd(afterNode, 0);
        range.setStart(afterNode, 0);
    }
    sel.addRange(range);
};

function __MozillaInnerHTML2(html) {
    /*
    var body = getDoc().body;
    var range = body.ownerDocument.createRange();
    range.selectNodeContents(body);
    range.deleteContents();
    */

    var sel = getWindow().getSelection();
    var range = sel.getRangeAt(0);
    sel.removeAllRanges();
    range.deleteContents();
    var container = range.startContainer;
    //alert(container)

    var df = range.createContextualFragment(html);
    //container.appendChild(df);
    //body.appendChild(df);
};

function __MozillaOuterHTML(html) {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var df = r.createContextualFragment(html);
    this.parentNode.replaceChild(df, this);
};


//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

var __xhtml = "";

function editGetXHtmlBody() {
    return editGetXHtml("1")
};

function editGetXHtml(mode) {
    // check if DOCTYPE is already available
    //if( mode == 1)
    //  var temp = editGetBodyHtml().toUpperCase();
    //else
    //  var temp = editGetHtml().toUpperCase();

    __xhtml = "";

    var doc = getDoc();

    if (editGetMode() == "HTML") {
        var docHtml = getDocHtml();
        if (mode == 1) {
            doc.body.innerHTML = docHtml.body.innerText;
        } else {
            var html = docHtml.body.innerText;
            doc.open();
            doc.write(html);
            doc.close();
        }
    }

    var childs;

    if (mode == 1)
        childs = doc.body.childNodes;
    else
        childs = doc.childNodes;

    var len = childs.length;

    for (var i = 0; i < len; i++) {
        __processNode(childs[i]);
    }

    if (__xhtml.toUpperCase().indexOf("!DOCTYPE HTML PUBLIC") < 0)
        __xhtml = globalXHtmlDocType + __xhtml;


    var data = __xhtml;
    document.getElementById('__editData').value = data;
    return data;
};

function __processNode(node) {

    //alert(node.nodeType)
    //alert(node.nodeName)
    //alert(node.text)
    //alert(node.nodeValue)

    switch (node.nodeType) {
        // process element 
        case 1:
            if (node.nodeName == "!") {	// IE5.0 and IE5.5
                __xhtml = __xhtml + node.text;
                break;
            }

            var name = node.nodeName;
            if (node.scopeName == "HTML")
                name = name.toLowerCase();
            __xhtml = __xhtml + "<" + name;

            // process node attributes
            var attributes = node.attributes;
            var len = attributes.length;
            for (var j = 0; j < len; j++)
                __getAttributes(attributes[j], node);

            if (node.canHaveChildren || node.hasChildNodes()) {
                __xhtml = __xhtml + ">";
                // process childs
                var __childs = node.childNodes;
                len = __childs.length;
                for (var j = 0; j < len; j++)
                    __processNode(__childs[j]);
                __xhtml = __xhtml + "</" + name + ">";
            } else if (name == "script") {
                __xhtml = __xhtml + ">" + node.text + "</" + name + ">";
            } else if (name == "title" || name == "style" || name == "comment") {
                __xhtml = __xhtml + ">" + node.innerHTML + "</" + name + ">";
            } else {
                __xhtml = __xhtml + " />";
            }
            break;

        // process text 
        case 3:
            var value = node.nodeValue;
            value = editReplaceSpecialChar(value);
            //__xhtml = __xhtml + __checkText(value);
            __xhtml = __xhtml + value;
            break;

        // process data 
        case 4:
            __xhtml = __xhtml + "<![CDA" + "TA[\n" + node.nodeValue + "\n]" + "]>";
            break;

        // process XML 
        case 8:
            __xhtml = __xhtml + node.text;
            if (/(^<\?xml)|(^<\!DOCTYPE)/.test(node.text))
                __xhtml = __xhtml + "\n";
            break;

        // process document 
        case 9:
            var curChilds = node.childNodes;
            len = curChilds.length;
            for (var j = 0; j < len; j++)
                __processNode(curChilds[j]);
            break;

        default:
            __xhtml = __xhtml; // + "<!-- Not found:" + "nodeName: " + node.nodeName + "-->";
    }
};

function __checkAttribute(s) {
    return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
};

function __checkText(s) {
    return String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;");
};

function __getAttributes(attributeNode, node) {
    var tagName = node.tagName.toLowerCase();
    var attribName = attributeNode.nodeName.toLowerCase();
    // 
    if (!attributeNode.specified &&
  	  !((tagName == "input" && (attribName == "value" || attribName == "type"))) &&
  	  !((tagName == "img" && (attribName == "vspace"))) &&
  	  !((tagName == "area" && (attribName == "coords" || attribName == "shape")))
    ) {
        return "";
    }

    if (browser.ns && attributeNode.nodeName == "_moz_dirty")
        return;

    var name = attributeNode.nodeName;
    var value = attributeNode.nodeValue;

    // fix anchor
    if (name.toUpperCase() == "HREF") {
        var temp = value;
        var anchorpos = temp.indexOf("#");
        if (anchorpos > 0) {
            // search for pinEdit 
            var temp2 = temp.toUpperCase();
            if (temp2.indexOf("PINEDIT.") > 0) {
                value = temp.substring(anchorpos, temp.length);
                temp = value;
            }
        }
    }

    if (globalLinkPathRelative != "") {
        if (name.toUpperCase() == "HREF") {
            var temp = value;
            if (temp.toUpperCase().indexOf(globalLinkPathRelative.toUpperCase()) == 0) {
                value = temp.substring(globalLinkPathRelative.length, temp.length);
            }
            /*
            // also remove the server path
            var temp = value;
            if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
            value = temp.substring(globalServerPathRelative.length,temp.length);
            }
            */
        }
    }
    if (globalImagePathRelative != "") {
        if (node.tagName.toUpperCase() == "IMG" && name.toUpperCase() == "SRC") {
            var temp = value;
            if (temp.toUpperCase().indexOf(globalImagePathRelative.toUpperCase()) == 0) {
                value = temp.substring(globalImagePathRelative.length, temp.length);
            }
            /*
            // also remove the server path
            var temp = value;
            if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
            value = temp.substring(globalServerPathRelative.length,temp.length);
            }
            */
        }
    }

    if (name != "style") {
        if (!isNaN(value))
            value = node.getAttribute(name);
        __xhtml = __xhtml + " " + (attributeNode.expando ? name : name.toLowerCase()) + "=\"" + __checkAttribute(value) + "\"";
    } else
        __xhtml = __xhtml + " style=\"" + __checkAttribute(node.style.cssText) + "\"";
};

function editPasteWord() {
    if (__NotSupportedByMozilla()) return;

    editPaste();
    editClean(0);
    editClean(3);
};

function editClean(mode) {
    editSetFocus();

    // Word
    if (mode == 3) {
        editRemoveAttribute("lang");
        __editCleanStyle();
        // Word specific
        var content = getDoc().body.innerHTML;
        content = content.replace(/o:title/gi, "title");
        content = content.replace(/v:imagedata/gi, "img");
        content = content.replace(/<\/IMG>/gi, "");
        content = content.replace(/<v:([^>]+)>/gi, "");
        content = content.replace(/<\/v:([^>]+)>/gi, "");
        content = content.replace(/<o:([^>]+)>/gi, "");
        content = content.replace(/<\/o:([^>]+)>/gi, "");
        content = content.replace(/<stl:([^>]+)>/gi, "");
        content = content.replace(/<\/stl:([^>]+)>/gi, "");
        content = content.replace(/<w:([^>]+)>/gi, "");
        content = content.replace(/<\/w:([^>]+)>/gi, "");
        content = content.replace(/<\?xml:([^>]+)>/gi, "");

        editSetBodyHtml(content);
        __editCleanTags();
    }
    // style and class
    if (mode == 0) {
        __editCleanStyle();
    }
    // tags
    if (mode == 2) {
        __editCleanTags();
    }
    // format
    if (mode == 1) {
        editRemoveFormat();
    }
};

function __editCleanStyle() {
    var body = getDoc().body;

    body.removeAttribute("style", "", 0);
    body.removeAttribute("className", "", 0);
    // remove the style and classes
    for (var i = 0; i < body.all.length; i++) {
        var object = body.all[i];
        object.removeAttribute("style", "", 0);
        object.removeAttribute("className", "", 0);
    }
};

function __editCleanTags() {
    var content = getDoc().body.innerHTML;
    // common
    content = content.replace(/\r/g, "");
    content = content.replace(/\n/g, "");
    content = content.replace(/\t/g, " ");
    content = content.replace(/<p>&nbsp;<\/p>/gi, "<br>");
    //content = content.replace(/&nbsp;/gi, " ");
    content = content.replace(/<font>/gi, "");
    content = content.replace(/^\s/i, "");
    content = content.replace(/\s$/i, "");
    content = content.replace(/<span><\/span>/gi, "");
    content = content.replace(/<p><\/p>/gi, "<br>");
    content = content.replace(/<b><\/b>/gi, "");

    //content = content.replace(/<font>([^|]+)<\/font>/gi, '$1');
    //content = content.replace(/<span>(.*)<\/span>/gi, '$1');
    //content = content.replace(/<SPAN lang=EN-GB>([^|]+)<\/span>/gi, '$1');

    editSetBodyHtml(content);
};

function __editFixAnchor() {

    // check for anchor first
    var aLinks = getDoc().getElementsByTagName("a");
    for (var i = 0; i < aLinks.length; i++) {
        var temp = aLinks[i].href;
        var anchorpos = temp.indexOf("#");
        if (anchorpos > 0) {
            var temp2 = temp.toUpperCase();
            if (temp2.indexOf("PINEDIT.") > 0) {
                aLinks[i].href = temp.substring(anchorpos, temp.length);
            }
        }
    }
};

/*
function __editFixImage()
{
if(globalImagePathRelative != "") {
var aImages = getDoc().getElementsByTagName("img");
for (var i=0; i<aImages.length;i++) {
var temp = aImages[i].src;

if(temp.toUpperCase().indexOf(globalImagePathRelative.toUpperCase()) == 0) {
aImages[i].src = temp.substring(globalImagePathRelative.length,temp.length);
}
// also remove the server path
var temp = aImages[i].src;
if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
aImages[i].src = temp.substring(globalServerPathRelative.length,temp.length);
}
}
}
};
*/

/*
function __editFixLink()
{
if(globalLinkPathRelative != "") {
var aLinks = getDoc().getElementsByTagName("a");
for (var i=0; i<aLinks.length;i++) {
var temp = aLinks[i].href;
// cut rel. url	
if(temp.toUpperCase().indexOf(globalLinkPathRelative.toUpperCase()) == 0) {
aLinks[i].href = temp.substring(globalLinkPathRelative.length,temp.length);
}
// also remove the server path
var temp = aLinks[i].href;
if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
aLinks[i].href = temp.substring(globalServerPathRelative.length,temp.length);
}
}
}
};
*/

function __editBuildTagHierarchy() {
    //if(browser.ns)
    //  return;

    if (!globalHierarchyBarVisible)
        return;

    try {
        var active = editGetActiveObject();

        __editHierarchy = new Array();
        __editHierarchy[0] = active;

        if (active.tagName.toUpperCase() != "BODY") {
            while (active.parentNode.tagName.toUpperCase() != "BODY") {
                active = active.parentNode;
                __editHierarchy[__editHierarchy.length] = active;
            }
            __editHierarchy[__editHierarchy.length] = active.parentNode;
        }

        var temp = "<table style='width:100%;border-width:1px;border-style: solid;border-left-color:	ButtonShadow;	border-right-color:	ButtonHighlight;	border-top-color:	ButtonShadow;	border-bottom-color:ButtonHighlight;' cellspacing=0 cellpadding=1 border=0><tr>";
        for (var i = __editHierarchy.length - 1; i >= 0; i--) {
            if (browser.ie)
                temp += "<td style='cursor:hand' onmouseup='__editHierachyClick(" + i + ")' onmouseover='this.style.backgroundColor=\"" + globalHierarchyBarSelectionColor + "\";__editHierachyOver(" + i + ")'  onmouseout='this.style.backgroundColor=\"" + globalToolbarColor + "\";__editHierachyOut(" + i + ")'>";
            else
                temp += "<td id='__hbElement" + i + "'>";
            if (i == 0)
                temp = temp + "<b>&lt;" + __editHierarchy[i].tagName.toLowerCase() + "&gt;</b>";
            else
                temp = temp + "&lt;" + __editHierarchy[i].tagName.toLowerCase() + "&gt;";
            temp += "</td>";
        }
        temp += "<td width='100%'></td>";
        temp += "</table>";
    } catch (Error) {
        temp = "<table style='width:100%;border-width:1px;border-style: solid;border-left-color:	ButtonShadow;	border-right-color:	ButtonHighlight;	border-top-color:	ButtonShadow;	border-bottom-color:ButtonHighlight;' cellspacing=0 cellpadding=1 border=0><tr><td>&nbsp;</td></tr></table>";
    }

    document.getElementById("hierarchyBar").innerHTML = temp;

    try {
        if (browser.ns) {
            for (var i = __editHierarchy.length - 1; i >= 0; i--) {
                if (globalHierarchyBarHighlight) {
                    document.getElementById("__hbElement" + i).addEventListener("mouseover", __editHierachyOver, false);
                    document.getElementById("__hbElement" + i).addEventListener("mouseout", __editHierachyOut, false);
                }
                document.getElementById("__hbElement" + i).addEventListener("mousedown", __editHierachyClick, false);
            }
        }
    } catch (Error) { }
};

var __editHierarchySave;
function __editHierachyOver(event) {
    if (!globalHierarchyBarHighlight) return;

    try {
        var index;

        if (browser.ie) {
            index = event;
        } else {
            var id = event.target.id;
            index = id.substring(id.length - 1, id.length);
        }
        var obj = __editHierarchy[index];
        __editHierarchySave = obj.style.backgroundColor;
        obj.style.backgroundColor = globalHierarchyBarSelectionColor;
    } catch (Error) { }
};

function __editHierachyOut(event) {
    if (!globalHierarchyBarHighlight) return;

    try {
        var index;

        if (browser.ie) {
            index = event;
        } else {
            var id = event.target.id;
            index = id.substring(id.length - 1, id.length);
        }
        var obj = __editHierarchy[index];
        obj.style.backgroundColor = __editHierarchySave;
    } catch (Error) { }
};

function __editHierachyClick(event) {
    try {
        var index;

        if (browser.ie) {
            index = event;
        } else {
            var id = event.target.id;
            index = id.substring(id.length - 1, id.length);
        }
        var obj = __editHierarchy[index];
        obj.style.backgroundColor = __editHierarchySave;
        __editActiveObject = __editHierarchy[index];
        __editBuildTagHierarchy();
    } catch (Error) { }
};

//---------------------------------------------------------------------------------------------
//
// NEW in 3.0
//
//---------------------------------------------------------------------------------------------
function editSetUserCode(code) {
    __editToolbarCode = code;
};

function editGetMode() {
    return lastMode;
};

function editSetMode(mode) {
    setMode(mode);
};

function editGetActiveObject() {
    return __editActiveObject;
};

function editGetDocument() {
    return getDoc();
};

function editMenuVisible(value) {
    __editMenuVisible = value;
    if (value) {
        if (objMenuBar) {
            objMenuBar.setVisible(true);
            document.body.style.marginTop = 22;
        }
    } else {
        if (objMenuBar) {
            objMenuBar.setVisible(false);
            document.body.style.marginTop = 1;
        }
    }
};

function editGetMenuVisible() {
    return __editMenuVisible;
};

function editTableHighlight() {
    var color = "#FF0000";

    try {
        color = globalHighlightColor;
    } catch (Error) { };

    try {
        var aTables = getDoc().getElementsByTagName("table");

        if (!__editTableHighlight) {
            __editTableHighlight = true;
            for (i = 0; i < aTables.length; i++) {
                if (browser.ie) {
                    aTables[i].title = aTables[i].border + "|" + aTables[i].borderColor;
                    aTables[i].border = 3;
                    aTables[i].borderColor = color;
                } else {
                    aTables[i].style.borderStyle = "solid";
                    aTables[i].style.borderColor = color;
                    aTables[i].style.borderWidth = "1px";
                }
            }
        } else {
            __editTableHighlight = false;
            for (i = 0; i < aTables.length; i++) {
                if (browser.ie) {
                    if (aTables[i].title != "") {
                        var aTemp = aTables[i].title.split("|");
                        aTables[i].border = aTemp[0];
                        aTables[i].borderColor = aTemp[1];
                    }
                    aTables[i].title = "";
                } else {
                    aTables[i].style.borderStyle = "";
                    aTables[i].style.borderColor = "";
                    aTables[i].style.borderWidth = "";
                }
            }
        }
    } catch (Error) { }
};

function editSetDirection(dir) {
    try {
        editSetFocus();
        if (__editActiveObject) {
            __editActiveObject.style.direction = dir;
        }
    } catch (Error) { };
};

function editPreview() {
    var win;
    var html = "";

    var left = screen.width / 2 - 900 / 2;
    var top = screen.height / 2 - 700 / 2;
    if (lastMode == 'HTML')
        html = editGetText();
    else
        html = editGetHtml();

    //  if(__currentURL == "") {
    win = window.open("", "color", "modal=1,left=" + left + ",top=" + top + ",height=700,width=900,resizable=1,status=0,menubar=1,scrollbars=1");
    win.document.open();
    win.document.write(html);
    win.document.close();
    //  } else {
    //    win = window.open(__currentURL,"color","modal=1,left=" + left + ",top=" + top + ",height=700,width=900,resizable=1,status=0,menubar=1,scrollbars=1");
    //  }
};

function editSetSaveMode(mode) {
    __editSaveMode = mode;
};

/*
function editGetHtmlFormatted2()
{
var html = editGetBodyHtml();

html = html.replace(/>/gi, ">_>");
html = html.replace(/</gi, "<FONT color=" + globalTagColor + ">&lt;</FONT>");
html = html.replace(/>_>/gi, "<FONT color=" + globalTagColor + ">&gt;</FONT>");

return html;
}
*/

function editSetBr(value) {
    if (browser.ie) {
        __editIsBR = value;
        try {
            if (btnReturnMode) {
                if (!__editIsBR) {
                    btnReturnMode.setImage("design/image/" + design + "/broff.gif");
                } else {
                    btnReturnMode.setImage("design/image/" + design + "/bron.gif");
                }
            }
        } catch (Error) { };
    }
};

function editGetBr() {
    return __editIsBR;
};


var sb = null;
function editGetHtmlFormatted(mode) {
    sb = new MakeString();
    if (mode == "1")
        var childs = getDoc().body.childNodes;
    if (mode == "2")
        var childs = getDoc().childNodes;

    for (var i = 0; i < childs.length; i++) {
        __formatProcessNode(childs[i], 0, true);
    }

    var data = ""; //"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";

    data = data + sb.get(); ;

    //data = data.replace(/<meta content="MSHTML([^>]+)>/gi, "");
    data = data.replace(/<br><br>/gi, "<br>");
    if (data.substring(0, 4) == "<br>")
        data = data.substring(4, data.length);
    return data;
};

function __getIndent(level) {
    var result = "";
    for (var i = 0; i < level; i++) {
        result += "&nbsp;&nbsp;";
    }
    return result;
};

function __formatProcessNode(node, level, prettyFormat) {
    /*
    alert("Type: " + node.nodeType)
    alert("Name: " + node.nodeName)
    alert("Text: " + node.text)
    alert("Value: " + node.nodeValue)
    */
    var cr = "<br>";

    switch (node.nodeType) {

        // process element 
        case 1:
            if (__enableRetainCode) {
                if (node.nodeName.toUpperCase() == "CR") {
                    sb.add("<br>");
                    return;
                }
            }

            if (node.nodeName == "!") {	// IE5.0 and IE5.5
                sb.add(node.text);
                break;
            }

            var name = node.nodeName;
            name = name.toLowerCase();

            /*
            if (node.scopeName == "HTML") {
            name = name.toLowerCase();
            } else {
            // M.Dearman 2004-06-03 - If it is a different scopeName than HTML, add XML namespace to element
            name = node.scopeName + ":" + name;
            }
            */

            if (globalPrettyFormat) sb.add(__getIndent(level));
            sb.add(__editopenTag + __editfontTag + name + __editfontClose);

            // process node attributes
            var attributes = node.attributes;
            var len = attributes.length;
            for (var j = 0; j < len; j++) {
                __formatGetAttributes(attributes[j], node);
            }

            if (node.canHaveChildren || node.hasChildNodes()) {
                sb.add(__editcloseTag);
                __addCR(name);

                // process childs
                var childs = node.childNodes;
                len = childs.length;

                for (var j = 0; j < len; j++) {
                    __formatProcessNode(childs[j], level + 1, prettyFormat);
                }

                if (globalPrettyFormat) sb.add(__getIndent(level));
                sb.add(__editopenTag + "/" + __editfontTag + name + __editfontClose + __editcloseTag);
                __addCR(name);

            } else if (name == "script") {
                sb.add(__editcloseTag + __processScript(node.text) + __editopenTag + "/" + __editfontTag + name + __editfontClose + __editcloseTag);
            } else if (name == "style") {
                sb.add(__editcloseTag + __processScript(node.innerHTML) + cr + __editopenTag + "/" + __editfontTag + name + __editfontClose + __editcloseTag);
            } else if (name == "title" || name == "comment") {
                sb.add(__editcloseTag + node.innerHTML + __editopenTag + "/" + __editfontTag + name + __editfontClose + __editcloseTag);
            } else {
                sb.add(__editcloseTag);
                if (globalPrettyFormat) __addCR(name);
            }
            break;

        // process text 
        case 3:
            var value = node.nodeValue;

            //alert(value.charCodeAt(0))
            // replace special characters
            value = editReplaceSpecialChar(value);
            if (value != "") {
                if (globalPrettyFormat) sb.add(__getIndent(level));
                sb.add(_checkText(value));
                __addCR(name);
            }
            break;

        // process data 
        case 4:
            sb.add("<![CDA" + "TA[\n" + node.nodeValue + "\n]" + "]>");
            //if (prettyFormat) sb.add("\n");
            break;

        // process XML 
        case 8:
            var temp = node.text;
            temp = temp.replace(/</gi, "&lt");
            temp = temp.replace(/>/gi, "&gt");

            /*******/
            //temp = temp.replace(/ /gi, "&nbsp;");
            temp = temp.replace(/\t/gi, "&nbsp;&nbsp;");
            sb.add(temp);
            //if (/(^<\?xml)|(^<\!DOCTYPE)/.test(node.text) )
            //  sb.add("\n");
            break;

        // process document 
        case 9:
            var childs = node.childNodes;
            len = childs.length;
            for (var j = 0; j < len; j++)
                __formatProcessNode(childs[j], level, prettyFormat);
            break;

        default:
            sb.add("<!-- Not found:" + "nodeName: " + node.nodeName + "-->");
    }
};

function _checkText(s) {
    var temp = s;

    /*
    alert(escape(s))
    for(var i=0;i<s.length;i++) {
    if(escape(s.substring(i,i+1)) == "%A0") {
      
    }
    }
    */

    //  temp = temp.replace(/\#160/gi, "&nbsp;");
    temp = temp.replace(/</g, "&lt;");
    temp = temp.replace(/>/g, "&gt;");
    temp = temp.replace(/\&/g, "&amp;");
    return temp;
};

function __addCR(name) {
    var cr = "<br>";

    if (globalPrettyFormat) {
        sb.add(cr);
        return;
    }

    if (name == "html" || name == "body" || name == "title" || name == "table" || name == "head" || name == "tr" || name == "tbody" || name == "meta" || name == "style") {
        sb.add(cr);
    }
};

function __processScript(text) {
    text = text.replace(/\&/g, "&amp;");
    text = text.replace(/</g, "&lt;");
    text = text.replace(/>/g, "&gt;");
    text = text.replace(/\n/gi, "");
    text = text.replace(/\r/gi, "<br>");
    text = text.replace(/\t/gi, "&nbsp;&nbsp;");
    /*******/
    //  text = text.replace(/ /g, "&nbsp;");

    return text;
};

function __formatGetAttributes(attributeNode, node) {
    var tagName = node.tagName.toLowerCase();
    var attribName = attributeNode.nodeName.toLowerCase();
    // 
    if (!attributeNode.specified &&
  	  !((tagName == "input" && (attribName == "value" || attribName == "type"))) &&
  	  !((tagName == "img" && (attribName == "vspace"))) &&
  	  !((tagName == "area" && (attribName == "coords" || attribName == "shape")))
    ) {
        return "";
    }


    if (browser.ns && attributeNode.nodeName.indexOf("_moz") >= 0)
        return;

    var name = attributeNode.nodeName;
    var value = attributeNode.nodeValue;

    //alert("Name: " + name)
    //alert("Value: " + value)

    // fix anchor
    if (name.toUpperCase() == "HREF") {
        var temp = value;
        var anchorpos = temp.indexOf("#");
        if (anchorpos > 0) {
            // search for pinEdit 
            var temp2 = temp.toUpperCase();
            if (temp2.indexOf("PINEDIT.") > 0) {
                value = temp.substring(anchorpos, temp.length);
                temp = value;
            }
        }
    }

    if (globalLinkPathRelative != "") {
        if (name.toUpperCase() == "HREF") {
            var temp = value;
            if (temp.toUpperCase().indexOf(globalLinkPathRelative.toUpperCase()) == 0) {
                value = temp.substring(globalLinkPathRelative.length, temp.length);
            }
            /*
            // also remove the server path
            var temp = value;
            if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
            value = temp.substring(globalServerPathRelative.length,temp.length);
            }
            */
        }
    }
    if (globalImagePathRelative != "") {
        if (node.tagName.toUpperCase() == "IMG" && name.toUpperCase() == "SRC") {
            var temp = value;
            if (temp.toUpperCase().indexOf(globalImagePathRelative.toUpperCase()) == 0) {
                value = temp.substring(globalImagePathRelative.length, temp.length);
            }
            // also remove the server path
            /*
            var temp = value;
            if(temp.toUpperCase().indexOf(globalServerPathRelative.toUpperCase()) == 0) {
            value = temp.substring(globalServerPathRelative.length,temp.length);
            }
            */
        }
    }

    if (name != "style") {
        if (!isNaN(value))
            value = node.getAttribute(name);
        sb.add(" " + __editfontAttribute + (attributeNode.expando ? name : name.toLowerCase()) + __editfontClose + "=\"" + __formatCheckAttribute(value) + "\"");
    } else {
        if (node.style.cssText.toUpperCase() != "FONT-FAMILY: ")
            sb.add(" " + __editfontAttribute + "style" + __editfontClose + "=\"" + __formatCheckAttribute(node.style.cssText) + "\"");
    }
};

function __formatCheckAttribute(s) {
    return __editfontStyle + String(s).replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;") + __editfontClose;
};

function MakeString() {
    this.pos = 0;
    this.add = __string_add;
    this.get = __string_get;

    this.aString = new Array();
};

function __string_add(sString) {
    this.aString[this.pos++] = String(sString);
};

function __string_get() {
    return this.aString.join("");
};


//-----------------------------------------------------------------------------------
// NEW in 3.5
//-----------------------------------------------------------------------------------
function editSetEditable(value) {
    if (__NotSupportedByMozilla()) return;

    try {
        editSetFocus();
        if (value) {
            if (__editActiveObject) {
                __editActiveObject.contenteditable = "true";
                __editActiveObject.unselectable = "OFF";
                if (globalEditableColor)
                    __editActiveObject.style.backgroundColor = "";
                // if called from popup
                popup.hide();
            }
        } else {
            if (__editActiveObject) {
                __editActiveObject.contenteditable = "false";
                __editActiveObject.unselectable = "ON";
                if (globalEditableColor)
                    __editActiveObject.style.backgroundColor = globalEditableColor;
            }
        }
    } catch (Error) { };
};

function editHasChanged() {
    return __editChanged;
};


function editSaveLocal() {
    if (__NotSupportedByMozilla()) return;

    //Get the current text from the editor
    var html = editGetHtml();
    //get the subframe, then write the new html to the doc
    var doc = document.getElementById('subframe').contentWindow.document;
    doc.open();
    doc.write(html);
    doc.close();
    //execute the save as.  Doing execCommand on a document object is an Internet Explorer built in function.
    doc.execCommand('SaveAs', 'true');
};

function editGetVersion() {
    return __editVersion;
};

function editSetActiveMode(mode) {
    try {
        if (mode == "EDIT") {
            if (btnEdit)
                btnEdit.setStatus(true);
            if (btnHTML)
                btnHTML.setStatus(false);
            if (btnPreview)
                btnPreview.setStatus(false);
        }
        if (mode == "HTML") {
            if (btnEdit)
                btnEdit.setStatus(false);
            if (btnHTML)
                btnHTML.setStatus(true);
            if (btnPreview)
                btnPreview.setStatus(false);
        }
        if (mode == "PREVIEW") {
            if (btnEdit)
                btnEdit.setStatus(false);
            if (btnHTML)
                btnHTML.setStatus(false);
            if (btnPreview)
                btnPreview.setStatus(true);
        }
    } catch (Error) { };
};

function editRemoveAttribute(attributeName) {
    var body = getDoc().body;
    body.removeAttribute(attributeName, "", 0);

    // remove the style and classes
    for (var i = 0; i < body.all.length; i++) {
        var object = body.all[i];
        object.removeAttribute(attributeName, "", 0);
    }
};

function editRemoveTag(tagName) {
    var body = getDoc().body;

    // remove tag
    for (var i = 0; i < body.all.length; i++) {
        var object = body.all[i];
        if (object.tagName.toUpperCase() == tagName.toUpperCase())
            object.removeNode(true);
    }
};

/*
function editReplaceTagWithContent(tagName)
{
var doc = getDoc();
var body = doc.body;

// remove tag
for (var i=0; i<body.all.length;i++) {
var object = body.all[i];
if(object.tagName.toUpperCase() == tagName.toUpperCase()) {
//var newNode = doc.createTextNode(object.innerHTML);
//object.replaceNode(newNode);
object.parentNode.innerHTML = object.innerHTML;
}
}
}
*/

function editSetControlVDisabled(value) {
    __editControlVDisabled = value;
};

function editRemoveLink() {
    if (browser.ns) {
        if (!editHasSelection())
            alert(getLanguageString(language, 3012));
    }
    execute('unlink', false, null);
};

function editGetSelectionType() {
    return editGetSelectionStyle();
}

function editGetSelectionStyle() {
    try {
        return getDoc().selection.type.toUpperCase();
    } catch (Error) {
        return "";
    }
};

function editGetFileUrl() {
    return __currentURL;
};

function editHasSelection() {
    try {
        if (browser.ns) {
            try {
                editSetFocus();
                //var buffer = document.createElement("div");
                var selection = getWindow().getSelection();
                var range = selection.getRangeAt(selection.rangeCount - 1);
                return range.toString().length > 0 ? true : false;
                //var range = selection.getRangeAt( selection.rangeCount-1 ).cloneRange();
                //selection.removeAllRanges();
                //var frag = range.cloneContents();
                //buffer.innerHTML = html;
                //range.deleteContents();
                //var bufferRange = document.createRange();
                //bufferRange.selectNodeContents( buffer );
                //var frag = bufferRange.cloneContents();
                //range.insertNode( frag );
                //range.detach();
                //document.removeChild(buffer);
                //editSetFocus();
            } catch (Error) { };
        } else {
            return getDoc().selection.createRange().text.length > 0 ? true : false;
        }
    } catch (Error) {
        return false;
    }
};

function editSpell() {
    __onSpell();
};

function editInsertDate() {
    var curdate = new Date();
    var date = "";

    if (language == "DE")
        date = curdate.getDate() + "." + (parseInt(curdate.getMonth()) + 1) + "." + curdate.getFullYear();
    else
        date = (parseInt(curdate.getMonth()) + 1) + "/" + curdate.getDate() + "/" + curdate.getFullYear();

    editInsertHtml(date);
};

function editInsertTime() {
    var curdate = new Date();
    var minutes = curdate.getMinutes();
    if (minutes < 10)
        minutes = "0" + minutes;
    var seconds = curdate.getSeconds();
    if (seconds < 10)
        seconds = "0" + seconds;

    var date = curdate.getHours() + ":" + minutes + ":" + seconds;
    editInsertHtml(date);
};

function editGetCharCount() {
    return charCount = editGetText().length;
};

function editGetWordCount() {
    var temp = editGetText();
    var aWords = temp.split(" ");
    return wordCount = aWords.length;
};

function editSetHierachyBarVisible(value) {
    try {
        document.getElementById("hierarchyBar").style.display = value ? "inline" : "none";
        if (!value)
            document.getElementById("hierarchyBar").innerHTML = "&nbsp;";
    } catch (Error) { }
};

function editSetDefaultFont(font, fontsize) {
    try {
        if (font) {
            getDoc().body.style.fontFamily = font;
            __editDefaultFont = font;
        }
        if (fontsize) {
            getDoc().body.style.fontSize = fontsize;
            __editDefaultFontSize = fontsize;
        }
    } catch (Error) { }
};

function __editSetFocusStatus(value) {
    if (browser.ie) {
        if (!value)
            eventOnBlur();
    }
    __editFocusTime = new Date().getTime();
};

function editGetFocus() {
    return __editFocusTime;
};

function editWriteBody(htmlin) {
    // handle relative paths
    var html = __editProcessRelative(htmlin);
    editSetBodyHtml(html);
};

function __NotSupportedByMozilla() {
    if (browser.ns) {
        alert("This feature is currently not supported !");
        return true;
    } else {
        return false;
    }
};

function editReplaceSpecialChar(value) {
    for (var i = 0; i < __editSpecialChar1.length; i++) {
        var re = new RegExp(__editSpecialChar1[i], "g");
        value = value.replace(re, __editSpecialChar2[i]);
    }
    return value;
};

function editAddSpecialCharReplacement(from, to) {
    try {
        var len = __editSpecialChar1.length;
        __editSpecialChar1[len] = from;
        __editSpecialChar2[len] = to;
    } catch (Error) { }
};

function editSetCursorHome() {
    try {
        var rng = getDoc().body.createTextRange();
        rng.moveEnd("character", -(rng.text.length));
        rng.select();
    } catch (Error) {
        
     }
};

function editCreateLink(url, target, title) {
    if (browser.ie) {
        var range = getDoc().selection.createRange();
        var doc = getDoc();
        if (doc.selection.type.toUpperCase() == "TEXT") {
            var text = range.htmlText;
            text = text.replace(/\r/gi, "");
            text = text.replace(/\n/gi, "");
            range.pasteHTML("<a href=''>" + text + "</a>");

            var len = range.parentElement().childNodes.length;
            var aLink = doc.getElementsByTagName("a");

            for (var i = 0; i < aLink.length; i++) {
                var item = aLink[i];
                var text1 = item.innerHTML.toUpperCase();
                text1 = text1.replace(/\r/gi, "");
                text1 = text1.replace(/\n/gi, "");
                var text2 = text.toUpperCase();
                text2 = text2.replace(/\r/gi, "");
                text2 = text2.replace(/\n/gi, "");
                if (text1 == text2) {
                    item.href = url;
                    item.target = target;
                    item.title = title;
                    break;
                }
            }
        }
        if (doc.selection.type.toUpperCase() == "CONTROL") {
            var newNode = doc.createElement("a");
            range(0).replaceNode(newNode);
            newNode.href = url;
            newNode.target = target;
            newNode.title = title;
            newNode.innerHTML = range(0).outerHTML;
        }
    } else {
        var html = editGetSelectedHtml();
        editInsertHtml("<a href='" + url + "' target='" + target + "' title = '" + title + "'>" + html + "</a>");
    }

}


try {
    if (__getKey() != "NHV56FD2SLOnhjUTgxysAqWW1I") {
        //		try {
        //			__toolbar_setkey(true);
        //		} catch(Err1) {};
        __editShowEvaluationMessage();
    } else {
        try {
            __toolbar_setkey(false);
        } catch (Err2) { };
        __editIsEvaluation = false;
    }
} catch (Error) {
    //__toolbar_setkey(true);
    __editShowEvaluationMessage();
}

function __editShowEvaluationMessage() {
    window.setTimeout("__editShowEvaluationMessageDelay()", 600000);
};

function __editShowEvaluationMessageDelay() {
    alert("Thank you for using pinEdit evaluation: " + __editVersion);
    __editShowEvaluationMessage();
};



var __comm;
var __data;

function Comm(target) {
    this.comboid = "";
    this.target = target;
};

Comm.prototype.execute = function (key, para, para2) {
    var html = "";
    html += "<html>";
    html += "<body>";
    html += "<form name='frmComm' id='frmComm' name='frmComm' method ='POST' action='" + this.target + "'>";
    html += "<input type='hidden' id='key' name='key'>";
    html += "<input type='hidden' id='para' name='para'>";
    html += "<input type='hidden' id='para2' name='para2'>";
    html += "</form>";
    html += "</body>";
    html += "</html>";

    if (browser.ns)
        doc = document.getElementById('subframe').contentWindow.document;
    else
        doc = subframe.document;

    doc.open();
    doc.write(html);
    doc.close();

    doc.getElementById("key").value = key;
    doc.getElementById("para").value = para;
    doc.getElementById("para2").value = para2;
    doc.getElementById("frmComm").submit();
};

Comm.prototype.executeSave = function (text, url) {

    var html = "";
    html += "<html>";
    //html+= "<head>";
    //html+= "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
    //html+= "</head>";
    html += "<body>";
    html += "<form name='frmComm' id='frmComm' name='frmComm' method ='POST' action='" + target + "'>";
    html += "<input type='hidden' id='key' name='key' value=''>";
    html += "<input type='hidden' id='para' name='para' value=''>";
    html += "<input type='hidden' id='para2' name='para2' value=''>";
    html += "<input type='hidden' id='html' name='html' value=''>";
    html += "<input type='hidden' id='url' name='url' value=''>";
    if (globalSaveValue != "")
        html += "<input type='hidden' id='custom' name='custom' value=''>";

    html += "</form>";
    html += "</body>";
    html += "</html>";

    var doc = null;
    if (browser.ns)
        doc = document.getElementById('subframe').contentWindow.document;
    else
        doc = subframe.document;

    doc.open();
    doc.write(html);
    doc.close();

    doc.getElementById("html").value = text;
    doc.getElementById("url").value = url;
    doc.getElementById("key").value = "SAVE";
    doc.getElementById("para").value = url;
    doc.getElementById("para2").value = text;
    if (globalSaveValue != "")
        doc.getElementById("custom").value = globalSaveValue;

    doc.getElementById("frmComm").submit();
};

Comm.prototype.receive = function (key) {
    if (key == 'SAVE') {
        if (__data != "") {
            if (__data != "OK") {
                alert(__data);
            } else {
                // now use the new path
                if (__editReloadAfterSave) {
                    editLoad(__currentURLTemp);
                    __editReloadAfterSave = false;
                }
            }
        }
        document.getElementById('subframe').src = 'dummy.html';
    }
    if (key == 'GETTEXT') {
        var aTexts = __data.split("~");
        var combo = null;
        try {
            combo = document.getElementById(__comm.comboid);
        } catch (Error) { };
        if (combo != null) {
            while (combo.length) {
                combo.remove(0);
            }

            for (var i = 0; i < aTexts.length - 1; i++) {
                var aText = aTexts[i].split("|");
                var item = document.createElement("option");
                item.text = aText[0];
                item.value = aText[1];
                if (browser.ie)
                    combo.add(item);
                else
                    combo.add(item, null);
            }
        }
        document.getElementById('subframe').src = 'dummy.html';
        // call event
        eventOnProcessTM(aTexts);
    }
    if (key == 'SETTEXT') {
        editGetTextModule(__comm.comboid);
    }
    if (key == 'REMOVETEXT') {
        editGetTextModule(__comm.comboid);
    }
    if (key == 'INTELLI') {
        __intelliProcess(__data);
    }
    //editSetFocus();
};


function __editGetIframePositionX(iframe) {
    if (iframe.style.position.toUpperCase() == "ABSOLUTE") {
        return iframe.style.left;
    } else {
        var parent = iframe;
        var x = 0;
        while (parent.tagName.toUpperCase() != "BODY") {
            if (parent.tagName.toUpperCase() != "FORM") {
                x = x + parent.offsetLeft;
            }
            parent = parent.parentNode;
        }
        return x;
    }
};

function __editGetIframePositionY(iframe) {
    if (iframe.style.position.toUpperCase() == "ABSOLUTE") {
        return iframe.style.top;
    } else {
        var parent = iframe;
        var y = 0;
        while (parent.tagName.toUpperCase() != "BODY") {
            if (parent.tagName.toUpperCase() != "TR" && parent.tagName.toUpperCase() != "FORM") {
                y = y + parent.offsetTop;
            }
            parent = parent.parentNode;
        }
        return y;
    }
}
