if (/msie/i.test(navigator.userAgent)) {
    document.nativeGetElementById = document.getElementById;
    document.getElementById = function (id) {
        var elem = document.nativeGetElementById(id);
        if (elem) {
            if (elem.attributes['id'].value == id) {
                return elem
            } else {
                for (var i = 1; i < document.all[id].length; i++) {
                    if (document.all[id][i].attributes['id'].value == id) {
                        return document.all[id][i]
                    }
                }
            }
        }
        return null
    }
}
if (typeof _editor_no_cache === 'undefined') {
    _editor_no_cache = false
}
if (typeof _xs_editor_url === 'string') {
    _xs_editor_url = _xs_editor_url.replace(/\x2f*$/, '/')
} else {
    alert('XHTMLSuite Critical Error:\n\nVariable _xs_editor_url is not set!\nAttempting to determine path to editor.\n\nThis however may not work!');
    var server = location.href.replace(/(https?:\/\/[^\/]*)\/.*/, '$1') + '/';
    _xs_editor_url = server + 'components/com_xhtmlsuite/'
}
if (typeof (_xs_editor_lang) === 'string') {
    _xs_editor_lang = _xs_editor_lang ? _xs_editor_lang.toLowerCase() : 'en'
} else {
    _xs_editor_lang = 'en'
}
if (typeof _editor_fullscreen === 'undefined') {
    _editor_fullscreen = false
}
if (!(typeof _xs_editor_theme === 'string') || typeof _xs_editor_theme == 'undefined' || _xs_editor_theme === '') {
    _xs_editor_theme = 'default'
}
if ((/_xsd/).test(_xs_editor_theme)) {
    _xs_icon_theme = 'default'
} else {
    _xs_icon_theme = _xs_editor_theme
}
if (!(typeof _xs_site_css_url === 'string')) {
    _xs_site_css_url = ''
}
if (!(typeof _xs_editing_css_url === 'string') || typeof _xs_editing_css_url === 'undefined' || _xs_editing_css_url === '') {
    _xs_editing_css_url = _xs_site_css_url
}
if (typeof _xs_site_in_subdir == 'undefined') {
    _xs_site_in_subdir = false
}
var __xhtmlsuites = [];
XHTMLSuite = function (textarea, config) {
    if (typeof textarea != 'object') {
        textarea = document.getElementById(textarea)
    }
    var textareaID = textarea.id;
    if (XHTMLSuite.checkSupportedBrowser(textareaID)) {
        if (typeof config == 'undefined') {
            this.config = new XHTMLSuite.Config()
        } else {
            this.config = config
        }
        this._xhtmlSuite = null;
        this._textArea = textarea;
        this._textArea.spellcheck = false;
        this.setLoadingMessage('Constructing XHTMLSuite object');
        this._editMode = 'wysiwyg';
        this.extensions = {};
        this._timerToolbar = null;
        this._timerUndo = null;
        this._undoQueue = [this.config.undoSteps];
        this._undoPos = -1;
        this.__xhtmlsuite_id_num = __xhtmlsuites.length;
        __xhtmlsuites[this.__xhtmlsuite_id_num] = this;
        this._notifyListeners = {};
        this._textareaID = textareaID;
        this._initial_ta_size = {
            w: textarea.style.width ? textarea.style.width : (textarea.offsetWidth ? (textarea.offsetWidth + 'px') : (textarea.cols + 'em')),
            h: textarea.style.height ? textarea.style.height : (textarea.offsetHeight ? (textarea.offsetHeight + 'px') : (textarea.rows + 'em'))
        }
    }
    XHTMLSuite.fL(this, '_textArea');
    XHTMLSuite.fL(this, '_notifyListeners')
};
XHTMLSuite.toFree = [];
XHTMLSuite._eventFlushers = [];
XHTMLSuite._objectCache = {};
XHTMLSuite._objectTypeCache = {};
XHTMLSuite._objectWidthCache = {};
XHTMLSuite._objectHeightCache = {};
XHTMLSuite._objectAlignCache = {};
XHTMLSuite._objectHspaceCache = {};
XHTMLSuite._objectVspaceCache = {};
XHTMLSuite._objectClassCache = {};
XHTMLSuite._objectParamCache = {};
XHTMLSuite.agt = navigator.userAgent.toLowerCase();
XHTMLSuite.is_ie = ((XHTMLSuite.agt.indexOf('msie') != -1) && (XHTMLSuite.agt.indexOf('opera') == -1));
XHTMLSuite.is_ie_6 = (XHTMLSuite.is_ie && XHTMLSuite.agt.indexOf('msie 6') != -1);
XHTMLSuite.is_ie_7 = (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_6 && XHTMLSuite.agt.indexOf('msie 7') != -1);
XHTMLSuite.ie_version = parseFloat(XHTMLSuite.agt.substring(XHTMLSuite.agt.indexOf('msie') + 5));
XHTMLSuite.is_safari = (XHTMLSuite.agt.indexOf('safari') != -1);
XHTMLSuite.safari_version = parseInt(navigator.appVersion.replace(/.*?AppleWebKit\/([\d]).*?/, '$1'), 10);
XHTMLSuite.is_opera = (XHTMLSuite.agt.indexOf('opera') != -1);
XHTMLSuite.is_camino = (XHTMLSuite.agt.indexOf('camino') != -1);
XHTMLSuite.opera_version = navigator.appVersion.substring(0, navigator.appVersion.indexOf(' ')) * 1;
XHTMLSuite.is_netscape = (navigator.appName == 'Netscape');
XHTMLSuite.is_mac = (XHTMLSuite.agt.indexOf('mac') != -1);
XHTMLSuite.is_mac_ie = (XHTMLSuite.is_ie && XHTMLSuite.is_mac);
XHTMLSuite.is_gecko = (navigator.product == 'Gecko' && !XHTMLSuite.is_safari);
XHTMLSuite.is_designMode = (typeof document.designMode != 'undefined' && !XHTMLSuite.is_ie && !XHTMLSuite.is_safari);
XHTMLSuite.RE_body = /<body[^>]*>((.|\n|\r|\t)*?)<\/body>/i;
XHTMLSuite.RE_Specials = /([\/\^$*+?.()|{}\[\]])/g;
XHTMLSuite.escapeStringForRegExp = function (string) {
    return string.replace(XHTMLSuite.RE_Specials, '\\$1')
};
XHTMLSuite.RE_XsMedia = /Xs(Flash|QuickTime|WindowsMedia|UnknownMedia)Object/gi;
XHTMLSuite.RE_xs_CSS = /(xs_tbb|xstbb|xs_anchor|xs_active_element|xs_active_element_RS|xs_active_element_RE|Xs(Flash|QuickTime|WindowsMedia|UnknownMedia)Object)/gi;
XHTMLSuite.RE_no_NLR = /(thead|tbody|tfoot|colgroup|rowgroup)/gi;
XHTMLSuite.RE_no_span = /(ol|ul|dl|img|table|thead|tbody|colgroup|rowgroup|col|tr|input|select|form|textarea|hr)/gi;
XHTMLSuite.prototype._createToolbar = function () {
    this.setLoadingMessage('Creating toolbar');
    var editor = this;
    var lbArray = [];
    var toolbar = document.createElement('div');
    this._toolBar = toolbar;
    toolbar.className = this.config.editorClassicStyle ? 'xs_toolbarClassic' : 'xs_toolbar';
    toolbar.unselectable = 'on';
    XHTMLSuite.fL(this, '_toolBar');
    XHTMLSuite.aD0E(toolbar, 'contextmenu', function () {
        return false
    });
    var toolBarTableDiv = [];
    this._toolBarTableDiv = toolBarTableDiv;
    XHTMLSuite.fL(this, '_toolBarTableDiv');
    var tb_objects = {};
    this._toolbarObjects = tb_objects;
    if (!this.config.editorClassicStyle) {
        editor.createToolBarTabs()
    }
    for (var i = 0; i < this.config.toolbar.length; i++) {
        if (!this.config.editorClassicStyle) {
            toolBarTableDiv[i] = document.createElement('div');
            toolBarTableDiv[i].id = 'panel_' + editor._textareaID + '_' + i;
            toolbar.appendChild(toolBarTableDiv[i]);
            toolBarTableDiv[i].className = 'xs_panelactive';
            if (i === 0) {
                toolBarTableDiv[i].style.display = ''
            } else {
                toolBarTableDiv[i].style.display = 'none'
            }
            toolBarTableDiv[i].style.overflow = 'hidden'
        }
        editor.toolBarPanel(i);
        var group = this.config.toolbar[i];
        for (var j = 0; j < group.length; ++j) {
            if (group[j] == 'linebreak') {
                lbArray.push(group[j])
            }
        }
        for (var k = 0; k < group.length; ++k) {
            if (typeof group[k] != 'string') {
                continue
            }
            if (lbArray.length > 1 && group[k] == 'linebreak') {}
            var code = group[k];
            editor.createButton(code, i)
        }
        var tb_cell_end = document.createElement('td');
        tb_cell_end.className = 'xs_tb_end';
        if (XHTMLSuite.is_ie) {
            tb_cell_end.unselectable = 'on'
        } else {
            tb_cell_end.style.MozUserSelect = 'none'
        }
        tb_cell_end.appendChild(document.createTextNode('\xa0'));
        this._toolBarTableRow[i].appendChild(tb_cell_end)
    }
    XHTMLSuite._addEvent(toolbar, 'mousedown', function (ev) {
        editor.activateEditor()
    });
    this._xhtmlSuite.appendChild(toolbar);
    return toolbar
};
XHTMLSuite.prototype.toolBarPanel = function (num) {
    var editor = this;
    var toolBarTable = [];
    this._toolBarTable = toolBarTable;
    XHTMLSuite.fL(this, '_toolBarTable');
    var toolBarTableBody = [];
    this._toolBarTableBody = toolBarTableBody;
    XHTMLSuite.fL(this, '_toolBarTableBody');
    toolBarTable[num] = document.createElement('table');
    toolBarTable[num].style.border = 'none';
    toolBarTable[num].cellSpacing = '0';
    toolBarTable[num].cellPadding = '0';
    toolBarTable[num].className = 'xs_tb';
    if (XHTMLSuite.is_ie) {
        toolBarTable[num].unselectable = 'on'
    } else {
        toolBarTable[num].style.MozUserSelect = 'none'
    }
    if (!this.config.editorClassicStyle) {
        this._toolBarTableDiv[num].appendChild(toolBarTable[num]);
        XHTMLSuite._addEvent(editor._toolBarTableDiv[num], 'mouseover', function () {
            editor._toolBarTableDiv[num].style.overflow = 'visible'
        });
        XHTMLSuite._addEvent(editor._toolBarTableDiv[num], 'mouseout', function () {
            editor._toolBarTableDiv[num].style.overflow = 'hidden'
        })
    } else {
        this._toolBar.appendChild(toolBarTable[num])
    }
    toolBarTableBody[num] = document.createElement('tbody');
    if (XHTMLSuite.is_ie) {
        toolBarTableBody[num].unselectable = 'on'
    } else {
        toolBarTableBody[num].style.MozUserSelect = 'none'
    }
    toolBarTable[num].appendChild(toolBarTableBody[num]);
    var toolBarTableRow = [];
    this._toolBarTableRow = toolBarTableRow;
    XHTMLSuite.fL(this, '_toolBarTableRow');
    toolBarTableRow[num] = document.createElement('tr');
    if (XHTMLSuite.is_ie) {
        toolBarTableRow[num].unselectable = 'on'
    } else {
        toolBarTableRow[num].style.MozUserSelect = 'none'
    }
    toolBarTableRow[num].style.padding = '0px';
    toolBarTableBody[num].appendChild(toolBarTableRow[num]);
    if (XHTMLSuite.is_opera && typeof DefinitionList != 'undefined') {
        editor.config.hideButtons(' definitionlist ')
    }
};
XHTMLSuite.prototype.createButton = function (txt, num) {
    var editor = this;
    var el, btn, obj, context, img, dropimg = null;
    switch (txt) {
    case 'separator':
        el = document.createElement('div');
        el.className = 'xsSeparator';
        if (XHTMLSuite.is_ie) {
            el.unselectable = 'on'
        } else {
            el.style.MozUserSelect = 'none'
        }
        break;
    case 'space':
        el = document.createElement('div');
        el.className = 'xsSpace';
        if (XHTMLSuite.is_ie) {
            el.unselectable = 'on'
        } else {
            el.style.MozUserSelect = 'none'
        }
        break;
    case 'linebreak':
        editor.toolBarPanel(num);
        return false;
    case 'textindicator':
        el = document.createElement('div');
        el.appendChild(document.createTextNode('Abc'));
        if (XHTMLSuite.is_ie) {
            el.unselectable = 'on'
        } else {
            el.style.MozUserSelect = 'none'
        }
        el.className = 'indicator';
        el.title = XHTMLSuite.I18N.tooltips.textindicator;
        obj = {
            name: txt,
            id: this._textareaID + '_' + txt,
            element: el,
            enabled: true,
            active: false,
            text: false,
            cmd: 'textindicator',
            state: XHTMLSuite.setButtonStatus
        };
        XHTMLSuite.fL(obj);
        this._toolbarObjects[txt] = obj;
        break;
    default:
        btn = editor.config.btnList[txt];
        break
    }
    if (!el && btn) {
        el = document.createElement('div');
        if (XHTMLSuite.is_ie) {
            el.unselectable = 'on'
        } else {
            el.style.MozUserSelect = 'none'
        }
        el.style.whiteSpace = 'nowrap';
        el.title = btn[0];
        el.className = 'xsButton';
        el.style.direction = 'ltr';
        el.id = this._textareaID + '_' + txt;
        obj = {
            name: txt,
            id: this._textareaID + '_' + txt,
            element: el,
            enabled: true,
            active: false,
            text: btn[2],
            cmd: btn[3],
            state: XHTMLSuite.setButtonStatus,
            context: btn[4] || null
        };
        XHTMLSuite.fL(el);
        XHTMLSuite.fL(obj);
        this._toolbarObjects[txt] = obj;
        XHTMLSuite._addEvent(el, 'mouseover', function () {
            if (obj.enabled) {
                if (txt == 'forecolor' || txt == 'hilitecolor' || (txt == 'inserttable' && editor.config.showQuickTableDialog)) {
                    XHTMLSuite._addClass(el, 'xsDropButtonHover')
                } else {
                    XHTMLSuite._addClass(el, 'xsButtonHover')
                }
            }
        });
        XHTMLSuite._addEvent(el, 'mouseout', function () {
            if (obj.enabled) {
                if (txt == 'forecolor' || txt == 'hilitecolor' || (txt == 'inserttable' && editor.config.showQuickTableDialog)) {
                    XHTMLSuite._removeClass(el, 'xsDropButtonHover');
                    XHTMLSuite._removeClass(el, 'xsDropButtonActive');
                    if (obj.active && !XHTMLSuite.is_opera) {
                        XHTMLSuite._addClass(el, 'xsDropButtonPressed')
                    }
                } else {
                    XHTMLSuite._removeClass(el, 'xsButtonHover');
                    XHTMLSuite._removeClass(el, 'xsButtonActive');
                    if (obj.active && !XHTMLSuite.is_opera) {
                        XHTMLSuite._addClass(el, 'xsButtonPressed')
                    }
                }
            }
        });
        XHTMLSuite._addEvent(el, 'mousedown', function (ev) {
            if (obj.enabled) {
                if (txt == 'forecolor' || txt == 'hilitecolor' || (txt == 'inserttable' && editor.config.showQuickTableDialog)) {
                    XHTMLSuite._removeClass(el, 'xsDropButtonPressed');
                    XHTMLSuite._addClass(el, 'xsDropButtonActive')
                } else {
                    XHTMLSuite._removeClass(el, 'xsButtonPressed');
                    XHTMLSuite._addClass(el, 'xsButtonActive')
                }
                if (editor.config.richDropDowns) {
                    editor.hideDropDownList()
                }
                var contextMenu = XHTMLSuite.getElementById('div', 'xs_contextmenu');
                if (typeof contextMenu != 'undefined' && contextMenu !== null && contextMenu.style.display != 'none') {
                    contextMenu.style.display = 'none'
                }
                XHTMLSuite._stopEvent(XHTMLSuite.is_ie ? window.event : ev)
            }
        });
        XHTMLSuite._addEvent(el, XHTMLSuite.is_ie ? 'mouseup' : 'click', function (ev) {
            ev = XHTMLSuite.is_ie ? window.event : ev;
            editor.btnClickEvent = ev;
            if (obj.enabled) {
                if (txt == 'forecolor' || txt == 'hilitecolor' || (txt == 'inserttable' && editor.config.showQuickTableDialog)) {
                    XHTMLSuite._removeClass(el, 'xsDropButtonActive');
                    XHTMLSuite._removeClass(el, 'xsDropButtonHover')
                } else {
                    XHTMLSuite._removeClass(el, 'xsButtonActive');
                    XHTMLSuite._removeClass(el, 'xsButtonHover')
                }
                if (XHTMLSuite.is_gecko || XHTMLSuite.is_opera) {
                    editor.activateEditor()
                }
                if (editor.config.richDropDowns) {
                    editor.hideDropDownList()
                }
                var contextMenu = XHTMLSuite.getElementById('div', 'xs_contextmenu');
                if (typeof contextMenu != 'undefined' && contextMenu !== null && contextMenu.style.display != 'none') {
                    contextMenu.style.display = 'none'
                }
                obj.cmd(editor, obj.name, obj, ev);
                XHTMLSuite._stopEvent(ev)
            }
        });
        if (XHTMLSuite.is_ie) {
            el.ondrag = function () {
                return false
            }
        }
        img = editor.createBtnImg(btn[1], 'xs_btn_img');
        editor._img = img;
        XHTMLSuite.fL(editor, '_img');
        el.appendChild(img);
        obj.imgel = img;
        obj.swapImageAndTitle = function (newimg, newtitle) {
            obj.imgel.src = newimg;
            el.title = newtitle
        };
        if (txt == 'forecolor' || txt == 'hilitecolor' || (txt == 'inserttable' && editor.config.showQuickTableDialog)) {
            el.className = 'xsDropButton';
            editor._createDropDownIframe(txt, el.options);
            dropimg = editor.createBtnImg(btn[1], 'xs_btn_img_drop');
            editor._dropimg = dropimg;
            XHTMLSuite.fL(editor, '_dropimg');
            el.appendChild(dropimg)
        }
    } else if (!el) {
        el = editor.createSelect(txt, num)
    }
    if (el) {
        var tb_cell = document.createElement('td');
        if (XHTMLSuite.is_ie) {
            tb_cell.unselectable = 'on'
        } else {
            tb_cell.style.MozUserSelect = 'none'
        }
        tb_cell.className = 'xs_tb_cell';
        if (typeof num != 'undefined') {
            this._toolBarTableRow[num].appendChild(tb_cell)
        } else {
            this._toolBarTabTableRow.appendChild(tb_cell)
        }
        tb_cell.appendChild(el)
    }
    return el
};
XHTMLSuite.prototype.createBtnImg = function (Url, btnClass) {
    var btnImg = document.createElement('img');
    if (btnClass == 'xs_btn_img_drop') {
        btnImg.src = _xs_editor_url + 'themes/' + _xs_icon_theme + '/images/ed_dropmenu.gif';
        btnImg.style.width = '7px';
        cssfloat = XHTMLSuite.is_ie ? btnImg.style.styleFloat : btnImg.style.cssFloat;
        cssfloat.style = 'left'
    } else {
        btnImg.src = Url;
        btnImg.style.width = '18px'
    }
    btnImg.style.height = '18px';
    btnImg.className = btnClass;
    if (XHTMLSuite.is_ie) {
        btnImg.unselectable = 'on'
    } else {
        btnImg.style.MozUserSelect = 'none'
    }
    return btnImg
};
XHTMLSuite.prototype.createSelect = function (txt, num) {
    var editor = this;
    var el, cmd, obj, options, context, op, i18n_i = null;
    var customSelects = editor.config.customSelects;
    var tooltip = '';
    switch (txt) {
    case 'fontsize':
    case 'fontname':
    case 'formatblock':
        options = editor.config[txt];
        cmd = txt;
        break;
    default:
        cmd = txt;
        var dropdown = customSelects[cmd];
        if (typeof dropdown != 'undefined') {
            options = dropdown.options;
            text = dropdown.text;
            context = dropdown.context;
            if (typeof dropdown.tooltip != 'undefined') {
                tooltip = dropdown.tooltip
            }
        }
        break
    }
    if (options) {
        el = document.createElement('select');
        el.unselectable = 'on';
        el.className = 'xs_selectbox';
        el.title = tooltip;
        el.name = txt;
        editor._formatSelects(el, txt);
        el.id = this._textareaID + '_' + txt;
        obj = {
            name: txt,
            id: this._textareaID + '_' + txt,
            element: el,
            enabled: true,
            active: false,
            text: false,
            cmd: cmd,
            state: XHTMLSuite.setButtonStatus,
            context: context
        };
        XHTMLSuite.fL(obj);
        this._toolbarObjects[txt] = obj;
        for (var i in options) {
            if (typeof options[i] != 'string') {
                continue
            }
            op = document.createElement('option');
            i18n_i = typeof XHTMLSuite.I18N.formatselects[i] != 'undefined' ? XHTMLSuite.I18N.formatselects[i] : i;
            op.appendChild(document.createTextNode(i18n_i));
            op.value = options[i];
            el.appendChild(op)
        }
    }
    if (el) {
        var tb_cell_dd = document.createElement('td');
        tb_cell_dd.unselectable = 'on';
        tb_cell_dd.className = 'xs_tb_cell';
        this._toolBarTableRow[num].appendChild(tb_cell_dd);
        tb_cell_dd.appendChild(el);
        if (this.config.richDropDowns) {
            editor._createDropDownIframe(txt, el.options);
            if ((XHTMLSuite.is_ie && XHTMLSuite.ie_version >= 7) || XHTMLSuite.is_opera) {
                XHTMLSuite._addEvent(el, 'mousedown', function (ev) {
                    editor.activateEditor();
                    el.blur();
                    el.disabled = true;
                    XHTMLSuite._stopEvent(ev)
                });
                XHTMLSuite._addEvent(el, 'click', function (ev) {
                    editor.hideDropDownList();
                    editor.showDropDownList(el, txt, el.options);
                    XHTMLSuite._stopEvent(ev)
                })
            } else {
                XHTMLSuite._addEvent(el, XHTMLSuite.is_opera ? 'click' : 'mousedown', function (ev) {
                    editor.activateEditor();
                    editor.hideDropDownList();
                    editor.showDropDownList(el, txt, el.options);
                    XHTMLSuite._stopEvent(ev)
                });
                XHTMLSuite._addEvent(el, 'mousedown', function (ev) {
                    XHTMLSuite._stopEvent(ev)
                })
            }
        } else {
            XHTMLSuite._addEvent(el, 'change', function () {
                editor._comboSelected(el, txt)
            })
        }
    }
    return el
};
XHTMLSuite.setButtonStatus = function (id, newval) {
    var oldval = this[id];
    var el = this.element;
    if (oldval != newval) {
        switch (id) {
        case 'enabled':
            if (newval) {
                XHTMLSuite._removeClass(el, 'xsButtonDisabled');
                el.disabled = false
            } else {
                XHTMLSuite._addClass(el, 'xsButtonDisabled');
                el.disabled = true
            }
            break;
        case 'active':
            if (newval && !XHTMLSuite.is_opera) {
                XHTMLSuite._addClass(el, 'xsButtonPressed')
            } else {
                XHTMLSuite._removeClass(el, 'xsButtonPressed')
            }
            break
        }
        this[id] = newval
    }
};
XHTMLSuite.prototype._formatSelects = function (el, txt) {
    switch (txt) {
    case 'fontsize':
    case 'formatblock':
        el.style.width = '90px';
        el.style.height = '18px';
        break;
    case 'fontname':
    case 'cssdropdown':
        el.style.width = '120px';
        el.style.height = '18px';
        break;
    default:
        el.style.width = '130px';
        el.style.height = '18px';
        break
    }
};
XHTMLSuite.prototype._createStatusBar = function () {
    this.setLoadingMessage('Creating statusbar');
    var editor = this;
    var statusbar = document.createElement('div');
    statusbar.style.height = '16px';
    statusbar.className = 'statusBar';
    this._xhtmlSuite.appendChild(statusbar);
    this._statusBar = statusbar;
    XHTMLSuite.fL(this, '_statusBar');
    var div = document.createElement('span');
    div.className = 'statusBarTree';
    div.style.padding = '2px';
    div.innerHTML = XHTMLSuite.I18N.msg['Path'] + ': ';
    this._statusBarTree = div;
    XHTMLSuite.fL(this, '_statusBarTree');
    this._statusBar.appendChild(div);
    if (XHTMLSuite.is_ie) {
        this._statusBar.unselectable = 'on';
        this._statusBarTree.unselectable = 'on'
    } else {
        this._statusBar.style.MozUserSelect = 'none';
        this._statusBarTree.style.MozUserSelect = 'none'
    }
    if (!this.config.statusBar) {
        statusbar.style.display = 'none'
    }
    this._statusBarItems = [];
    return statusbar
};
XHTMLSuite.prototype._createCssArray = function (url) {
    var editor = this;
    var cssArray = {};
    var css_style = null;
    if (editor.config.customCssClasses) {
        for (var i in editor.config.customCssClasses) {
            if (typeof editor.config.customCssClasses[i] != 'string') {
                continue
            }
            cssArray[i] = editor.config.customCssClasses[i]
        }
    } else {
        if (this.config.nativeCssClasses) {
            css_style = this.config.nativeCssClasses
        } else {
            try {
                css_style = XHTMLSuite.readCssFile(url)
            } catch (ex) {}
        }
        if (css_style) {
            var count = null;
            for (var y in css_style) {
                if (typeof css_style[y] != 'string') {
                    continue
                }
                if (css_style[y].charAt(0) == '<') {
                    count = 0;
                    continue
                }
            }
            if (count === 0) {
                if (!editor._shutUp) {
                    if (confirm('XHTMLSuite ERROR: could not load CSS styles\n\nPlease check XHTMLSuite\'s Global Settings section and see if a\npreview template is set.\n\nIf it is, please check that the path to the template is correct\nand that read/write permissions on the file are sufficient.\n\nAttempted to read file:\n' + url + '\n\nClick OK to disable this message.')) {
                        editor._shutUp = true
                    }
                }
                var errorArray = {
                    'ERROR - no CSS file defined': 'xs_void',
                    'You need to set a template': 'xs_void',
                    'in XHTMLSuite\'s Global Settings': 'xs_void'
                };
                return errorArray
            } else {
                for (var x in css_style) {
                    if (typeof css_style[x] != 'string') {
                        continue
                    }
                    var theClassName = x.trim();
                    var applicable = true;
                    if (/[^a-zA-Z0-9_.-]/.test(theClassName)) {
                        applicable = false
                    }
                    if (applicable && (theClassName.indexOf('.') < 0)) {
                        applicable = false
                    }
                    if (applicable) {
                        theClassName = theClassName.substring(theClassName.indexOf('.'), theClassName.length);
                        theClassName = theClassName.replace('.', ' ');
                        cssArray[theClassName.trim()] = theClassName.trim()
                    }
                }
            }
        }
    }
    return cssArray
};
XHTMLSuite.readCssFile = function (url) {
    var css = XHTMLSuite._geturlcontent(url);
    return XHTMLSuite.getStylesFromCssContent(css)
};
XHTMLSuite.getStylesFromCssContent = function (css) {
    RE_comment = /\/\*(.|\r|\n)*?\*\//g;
    RE_rule = /\{(.|\r|\n)*?\}/g;
    RE_import = /@import url\(.*?\)[\;]/g;
    css = css.replace(RE_comment, '');
    css = css.replace(RE_rule, ',');
    css = css.replace(RE_import, '');
    css = css.split(',');
    var selectors = {};
    for (var x = 0; x < css.length; x++) {
        if (css[x].trim()) {
            selectors[css[x].trim()] = css[x].trim()
        }
    }
    return selectors
};
XHTMLSuite.prototype.generate = function () {
    this.setLoadingMessage('Loading program libraries');
    var editor = this;
    var apiElements = [];
    var toolbar = this.config.toolbar;
    if (XHTMLSuite.is_opera || XHTMLSuite.is_safari) {
        this.config.liveSyntaxHighlighting = false
    }
    if (XHTMLSuite.is_opera) {
        this.config.syntaxHighlighting = false;
        this.config.keepSelectionInHtmlView = false
    }
    if (!editor.config.syntaxHighlighting) {
        if (typeof editor.toggleMode != 'function') {
            apiElements.push(_xs_editor_url + 'includes/api/toggleMode.js')
        }
    } else if (typeof editor.SyntaxHighlighter != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/syntaxHighlighter.js')
    }
    if (typeof Dialog == 'undefined') {
        apiElements.push(_xs_editor_url + 'includes/api/dialog.js')
    }
    if (!editor.config.editorClassicStyle && typeof editor.createToolBarTabs != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/createToolBarTabs.js')
    }
    if (editor.config.showResizeBar && typeof editor._createResizeBar != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/resizeBar.js')
    }
    if (typeof editor.importMediaHTML != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/parseRichMedia.js')
    }
    if (!editor.config.disableSpecialCharEncoding && typeof editor.htmlEncode != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/htmlEncode.js')
    }
    if (editor.config.showQuickTableDialog && typeof editor._showQuickTableDialog != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/quickTableDialog.js')
    }
    for (var i = toolbar.length; --i >= 0;) {
        for (var j = toolbar[i].length; --j >= 0;) {
            if ((toolbar[i][j] == 'forecolor' || toolbar[i][j] == 'hilitecolor' || this.config.propertiesInspector) && typeof editor.colorSwatch != 'function') {
                apiElements.push(_xs_editor_url + 'includes/api/colorSwatch.js')
            }
        }
    }
    if (editor.config.richDropDowns && typeof editor.showDropDownList != 'function') {
        apiElements.push(_xs_editor_url + 'includes/api/richDropdowns.js')
    }
    if ((XHTMLSuite.is_ie) && typeof XHTMLSuite.IE_Functions == 'undefined') {
        apiElements.push(_xs_editor_url + 'includes/specific/ie/xhtmlsuite_ie.js')
    }
    if ((XHTMLSuite.is_designMode || XHTMLSuite.is_safari) && typeof XHTMLSuite.Dom_Functions == 'undefined') {
        apiElements.push(_xs_editor_url + 'includes/specific/dom/xhtmlsuite_dom.js')
    }
    if (XHTMLSuite.is_designMode) {
        if (!editor.config.useParagraph) {
            if (typeof EnterDivs == 'undefined') {
                apiElements.push(_xs_editor_url + 'includes/specific/dom/modules/EnterDivs/enter-divs.js')
            }
        } else {
            if (typeof EnterParagraphs == 'undefined') {
                apiElements.push(_xs_editor_url + 'includes/specific/dom/modules/EnterParagraphs/enter-paragraphs.js')
            }
        }
    }
    if (this.config.propertiesInspector) {
        if (typeof editor._createPropertiesInspector != 'function') {
            apiElements.push(_xs_editor_url + 'includes/columbo/inspector.js')
        }
        if (typeof XHTMLSuite.defaultInsp_i18n == 'undefined' || typeof XHTMLSuite.cellInsp_i18n == 'undefined' || typeof XHTMLSuite.rowInsp_i18n == 'undefined' || typeof XHTMLSuite.imageInsp_i18n == 'undefined' || typeof XHTMLSuite.mediaInsp_i18n == 'undefined' || typeof XHTMLSuite.linkInsp_i18n == 'undefined' || typeof XHTMLSuite.tableInsp_i18n == 'undefined') {
            apiElements.push(_xs_editor_url + 'includes/columbo/lang/' + _xs_editor_lang + '.js')
        }
        if (typeof cssSelect == 'undefined' && typeof editor._createCssDropdown != 'function') {
            apiElements.push(_xs_editor_url + 'includes/api/createCssDropdown.js')
        }
    }
    for (var j = 0; j < apiElements.length; j++) {
        this.setLoadingMessage(XHTMLSuite.I18N.loading['Loading'] + apiElements[j]);
        XHTMLSuite._loadback(apiElements[j], function () {
            editor.generate()
        });
        return false
    }
    var textarea = this._textArea;
    textarea.className = 'xs_textarea';
    textarea.style.display = 'none';
    var xhtmlsuite = document.createElement('div');
    this._xhtmlSuite = xhtmlsuite;
    var toolbar = this._createToolbar();
    xhtmlsuite.className = 'xhtmlsuite';
    xhtmlsuite.unselectable = 'on';
    xhtmlsuite.style.width = this.config.width;
    xhtmlsuite.style.display = 'block';
    xhtmlsuite.style.zIndex = '10000000';
    var iFrame = document.createElement('iframe');
    iFrame.src = _xs_editor_url + 'dialogs/blank.html';
    iFrame.frameBorder = '0';
    xhtmlsuite.appendChild(iFrame);
    this._iFrame = iFrame;
    this._iFrame.className = 'xs_iframe';
    this._iFrame.spellcheck = false;
    this._iFrame.id = 'xs_editor_iframe_' + this._textareaID;
    XHTMLSuite.fL(this, '_iFrame');
    XHTMLSuite.aD0E(xhtmlsuite, 'contextmenu', function () {
        return false
    });
    XHTMLSuite.fL(this, '_xhtmlSuite');
    textarea.parentNode.insertBefore(xhtmlsuite, textarea);
    if (textarea.form) {
        XHTMLSuite.pD0E(this._textArea.form, 'submit', function () {
            editor.execCommand('selectall', false, false);
            editor._textArea.value = editor.getEditorContents();
            return true
        });
        var initialTAContent = textarea.value;
        XHTMLSuite.pD0E(this._textArea.form, 'reset', function () {
            editor.setHTML(editor.importHTML(initialTAContent));
            editor.updateToolbar();
            return true
        });
        if (!textarea.form.xhtmlsuite_submit) {
            try {
                textarea.form.xhtmlsuite_submit = textarea.form.submit;
                textarea.form.submit = function () {
                    this.onsubmit();
                    this.xhtmlsuite_submit()
                }
            } catch (ex) {}
        }
        XHTMLSuite.pD0E(this._textArea.form, 'unload', function () {
            textarea.value = editor.getEditorContents();
            return true
        })
    }
    if (editor.config.richDropDowns) {
        XHTMLSuite._addEvent(document, 'mouseup', function (e) {
            editor.hideDropDownList()
        })
    }
    XHTMLSuite.removeFromParent(textarea);
    xhtmlsuite.appendChild(textarea);
    textarea.style.margin = '-1px 0';
    if (this.config.syntaxHighlighting) {
        var hiliteFrame = this._createHighlightFrame()
    }
    var statusbar = this._createStatusBar();
    if (this.config.propertiesInspector) {
        var properties = this._createPropertiesInspector()
    }
    if (this.config.showResizeBar) {
        var resizebar = this._createResizeBar()
    }
    if (!this.config.editorClassicStyle) {
        this.tabMeasure = this._toolBarTabTable.offsetWidth
    }
    editor.initSize();
    editor._iFrameLoadDone = false;
    if (!XHTMLSuite.is_gecko) {
        if (iFrame && typeof iFrame != 'undefined') {
            editor._iFrameLoadDone = true;
            editor.initIframe();
            return true
        }
    }
    XHTMLSuite._addEvent(this._iFrame, 'load', function (e) {
        if (!editor._iFrameLoadDone) {
            editor._iFrameLoadDone = true;
            editor.initIframe()
        }
        return true
    });
    this._currentlyActiveElement = '';
    this._changesMade = false;
    return true
};
XHTMLSuite.prototype._fullScreen = function () {
    if (XHTMLSuite.is_ie) {
        document.body.style.overflow = 'hidden'
    }
    var editor = this;
    if (_editor_fullscreen && this.config.showResizeBar) {
        if (editor._resizeBar.style.display !== 'none') {
            editor._resizeBar.style.display = 'none'
        }
    }
    function sizeItUp() {
        if (!editor._isFullScreen || editor._sizing) {
            return false
        }
        _editor_fullscreen = true;
        if (typeof editor._toolbarObjects['fullscreenmode'] != 'undefined') {
            editor._toolbarObjects['fullscreenmode'].swapImageAndTitle(_xs_editor_url + 'themes/' + _xs_icon_theme + '/images/ed_fullscreen_minimize.gif', XHTMLSuite.I18N.tooltips.endfullscreenmode)
        }
        if (typeof editor._tabbarObjects != 'undefined') {
            if (typeof editor._tabbarObjects['fullscreenmode'] != 'undefined') {
                editor._tabbarObjects['fullscreenmode'].swapImageAndTitle(_xs_editor_url + 'themes/' + _xs_icon_theme + '/images/ed_fullscreen_minimize.gif', XHTMLSuite.I18N.tooltips.endfullscreenmode)
            }
        }
        editor._sizing = true;
        var x, y;
        if (window.innerHeight) {
            x = window.innerWidth;
            y = window.innerHeight
        } else if (document.documentElement && document.documentElement.clientHeight) {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight
        } else if (document.body) {
            x = document.body.clientWidth;
            y = document.body.clientHeight
        }
        editor.sizeEditor(x, y);
        editor._sizing = false;
        if (editor.config.propertiesInspector) {
            if (editor.config.collapsedPropertiesBar) {
                editor.config.height = (parseInt(editor.config.height, 10) - 135) + 'px'
            }
        }
    }
    function sizeItDown() {
        if (editor._isFullScreen || editor._sizing) {
            return false
        }
        _editor_fullscreen = false;
        if (typeof editor._toolbarObjects['fullscreenmode'] != 'undefined') {
            editor._toolbarObjects['fullscreenmode'].swapImageAndTitle(_xs_editor_url + 'themes/' + _xs_icon_theme + '/images/ed_fullscreen_maximize.gif', XHTMLSuite.I18N.tooltips.fullscreenmode)
        }
        if (typeof editor._tabbarObjects != 'undefined') {
            if (typeof editor._tabbarObjects['fullscreenmode'] != 'undefined') {
                editor._tabbarObjects['fullscreenmode'].swapImageAndTitle(_xs_editor_url + 'themes/' + _xs_icon_theme + '/images/ed_fullscreen_maximize.gif', XHTMLSuite.I18N.tooltips.fullscreenmode)
            }
        }
        if (editor.config.propertiesInspector) {
            if (editor.config.collapsedPropertiesBar) {
                editor.config.height = (parseInt(editor.config.height, 10) + 131) + 'px'
            }
        }
        editor._sizing = true;
        editor.initSize();
        editor._sizing = false
    }
    function resetScroll() {
        if (editor._isFullScreen) {
            window.scroll(0, 0);
            window.setTimeout(resetScroll, 150)
        }
    }
    if (typeof this._isFullScreen == 'undefined') {
        this._isFullScreen = false;
        if (editor.target != editor._iFrame) {
            XHTMLSuite._addEvent(window, 'resize', sizeItUp)
        }
    }
    this.deactivateEditor();
    var ancestor = this._xhtmlSuite;
    var bod = null;
    var selects = document.getElementsByTagName('select');
    var s, currentEditor;
    if (this._isFullScreen) {
        this._xhtmlSuite.style.position = '';
        try {
            if (XHTMLSuite.is_ie && document.compatMode == 'CSS1Compat') {
                bod = document.getElementsByTagName('html')
            } else {
                bod = document.getElementsByTagName('body')
            }
            bod[0].style.overflow = ''
        } catch (ex) {}
        this._isFullScreen = false;
        _editor_fullscreen = false;
        sizeItDown();
        while ((ancestor = ancestor.parentNode) && ancestor.style) {
            ancestor.style.position = ancestor._xhtmlsuite_fullScreenOldPosition;
            ancestor._xhtmlsuite_fullScreenOldPosition = null
        }
        for (var i = 0; i < selects.length; i++) {
            selects[i].style.display = ''
        }
        window.scroll(this._unScroll.x, this._unScroll.y)
    } else {
        this._unScroll = {
            x: window.pageXOffset ? window.pageXOffset : document.documentElement ? document.documentElement.scrollLeft : document.body.scrollLeft,
            y: window.pageYOffset ? window.pageYOffset : document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop
        };
        while ((ancestor = ancestor.parentNode) && ancestor.style) {
            ancestor._xhtmlsuite_fullScreenOldPosition = ancestor.style.position;
            ancestor.style.position = 'static'
        }
        for (var j = 0; j < selects.length; j++) {
            s = selects[j];
            currentEditor = false;
            while (s = s.parentNode) {
                if (s == this._xhtmlSuite) {
                    currentEditor = true;
                    break
                }
            }
            if (!currentEditor && selects[j].style.display != 'none') {
                selects[j].style.display = 'none'
            }
        }
        window.scroll(0, 0);
        this._xhtmlSuite.style.position = 'absolute';
        this._xhtmlSuite.style.zIndex = 100000;
        this._xhtmlSuite.style.left = '0px';
        this._xhtmlSuite.style.top = '0px';
        this._isFullScreen = true;
        resetScroll();
        try {
            if (XHTMLSuite.is_ie && document.compatMode == 'CSS1Compat') {
                bod = document.getElementsByTagName('html')
            } else {
                bod = document.getElementsByTagName('body')
            }
            bod[0].style.overflow = 'hidden'
        } catch (ex1) {}
        sizeItUp()
    }
    this.activateEditor();
    this.focusEditor()
};
XHTMLSuite.prototype.sizeEditor = function (width, height) {
    var editor = this;
    var iframeHeight;
    var textareaHeight;
    if (XHTMLSuite.is_ie) {
        iframeHeight = (XHTMLSuite.is_ie_7 ? document.documentElement.clientHeight : document.body.offsetHeight) - editor._toolBar.offsetHeight;
        textareaHeight = (XHTMLSuite.is_ie_7 ? document.documentElement.clientHeight : document.body.offsetHeight) - editor._toolBar.offsetHeight - 5
    } else {
        iframeHeight = window.innerHeight - editor._toolBar.offsetHeight;
        textareaHeight = window.innerHeight - editor._toolBar.offsetHeight - 5
    }
    if (editor.config.statusBar) {
        iframeHeight -= editor._statusBar.offsetHeight;
        textareaHeight -= editor._statusBar.offsetHeight
    }
    if (editor.config.propertiesInspector) {
        if (editor.config.collapsedPropertiesBar) {
            iframeHeight = iframeHeight + editor._propertiesBar.offsetHeight - editor._propertiesSwitch.offsetHeight
        } else {
            iframeHeight = iframeHeight - editor._propertiesBar.offsetHeight - editor._propertiesSwitch.offsetHeight
        }
    }
    editor._textArea.style.height = textareaHeight + 'px';
    editor._textArea.style.width = '100%';
    editor._iFrame.style.height = iframeHeight + 'px';
    editor._xhtmlSuite.style.width = width + 'px';
    if (this.config.syntaxHighlighting) {
        if (this._isFullScreen) {
            editor._sh_Iframe.style.height = iframeHeight + (this.config.propertiesInspector ? this._propertiesBar.offsetHeight + editor._propertiesSwitch.offsetHeight : 0) + 'px'
        } else {
            editor._sh_Iframe.style.height = iframeHeight + 'px'
        }
        editor._sh_Iframe.style.width = width + 'px'
    }
    this.notifyOf('resize', {
        width: this._xhtmlSuite.offsetWidth,
        height: this._xhtmlSuite.offsetHeight
    })
};
XHTMLSuite.prototype.initSize = function () {
    this.setLoadingMessage('Initialising editor size');
    if (XHTMLSuite.is_ie) {
        document.body.style.overflow = ''
    }
    var editor = this;
    if (!_editor_fullscreen && this.config.showResizeBar) {
        if (this._resizeBar.style.display !== '') {
            this._resizeBar.style.display = ''
        }
    }
    var xhtmlsuite = this._xhtmlSuite;
    var iframe = this._iFrame;
    var textarea = this._textArea;
    this._ta_size = {
        w: textarea.style.width,
        h: textarea.style.height
    };
    var height = (this.config.height == 'auto' ? (this._ta_size.h + 'px') : this.config.height);
    height = parseInt(height, 10);
    if (height < 0) {
        height = 0
    }
    if (!this.config.editorClassicStyle && (this.tabMeasure > parseInt(this.config.width, 10))) {
        this.config.width = (this.tabMeasure + 15) + 'px'
    }
    var width = (this.config.width == 'auto' ? (this._ta_size.w + 'px') : this.config.width);
    width = parseInt(width, 10);
    xhtmlsuite.style.width = this.config.width;
    try {
        iframe.style.width = XHTMLSuite.is_opera || (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_7) ? '100%' : '99.7%';
        if (this.config.propertiesInspector) {
            iframe.style.height = this.config.collapsedPropertiesBar ? (height + this._propertiesBar.offsetHeight) + 'px' : height + 'px'
        } else {
            iframe.style.height = height + 'px'
        }
        if (this.config.syntaxHighlighting) {
            this._sh_Iframe.style.width = XHTMLSuite.is_opera || (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_7) ? '100%' : '99.7%';
            if (this.config.propertiesInspector) {
                this._sh_Iframe.style.height = this.config.collapsedPropertiesBar ? (height + this._propertiesBar.offsetHeight) + 'px' : height + 'px'
            } else {
                this._sh_Iframe.style.height = height + 'px'
            }
        }
    } catch (ex) {}
    if (this._editMode == 'wysiwyg') {
        textarea.style.width = iframe.style.width
    } else {
        textarea.style.width = (this._toolBar.offsetWidth - 2) + 'px'
    }
    textarea.style.height = height + 'px';
    if (this._isFullScreen) {
        XHTMLSuite.aD0E(window, 'resize', function (e) {
            editor.sizeEditor()
        })
    }
};
XHTMLSuite.prototype.editorIsActivated = function () {
    try {
        return (XHTMLSuite.is_gecko || XHTMLSuite.is_opera) ? this._doc.designMode == 'on' : this._doc.body.contentEditable
    } catch (ex) {
        return false
    }
};
XHTMLSuite._sEHBA = false;
XHTMLSuite._cAE = false;
XHTMLSuite.prototype.activateEditor = function () {
    if (XHTMLSuite._cAE) {
        if (XHTMLSuite._cAE == this) {
            return true
        }
        XHTMLSuite._cAE.deactivateEditor()
    }
    if ((XHTMLSuite.is_gecko || XHTMLSuite.is_opera) && this._doc.designMode != 'on') {
        try {
            if (this._iFrame.style.display == 'none') {
                this._iFrame.style.display = '';
                this._doc.designMode = 'on';
                this._iFrame.style.display = 'none'
            } else {
                this._doc.designMode = 'on'
            }
            if (XHTMLSuite.is_gecko) {
                this._doc.execCommand('enableInlineTableEditing', false, false)
            }
        } catch (ex) {}
    } else if ((XHTMLSuite.is_ie || XHTMLSuite.is_safari) && (!XHTMLSuite.is_gecko && !XHTMLSuite.is_opera) && this._doc.body.contentEditable !== true) {
        this._doc.body.contentEditable = true
    }
    XHTMLSuite._sEHBA = true;
    XHTMLSuite._cAE = this;
    this.enableToolbar();
    return true
};
XHTMLSuite.prototype.deactivateEditor = function () {
    this.disableToolbar();
    if ((XHTMLSuite.is_gecko || XHTMLSuite.is_opera) && this._doc.designMode != 'off') {
        try {
            this._doc.designMode = 'off'
        } catch (ex) {}
    } else if ((XHTMLSuite.is_ie || XHTMLSuite.is_safari) && !XHTMLSuite.is_gecko && !XHTMLSuite.is_opera && this._doc.body.contentEditable !== false) {
        this._doc.body.contentEditable = false
    }
    if (XHTMLSuite._cAE != this) {
        return
    }
    XHTMLSuite._cAE = false
};
XHTMLSuite.prototype.initIframe = function () {
    this.setLoadingMessage('Initialising editor iframe');
    this.disableToolbar();
    var doc = null;
    var editor = this;
    try {
        if (this._iFrame.contentDocument) {
            this._doc = this._iFrame.contentDocument
        } else {
            this._doc = this._iFrame.contentWindow.document
        }
        doc = this._doc;
        if (!doc) {
            if (XHTMLSuite.is_gecko || XHTMLSuite.is_opera) {
                setTimeout(function () {
                    editor.initIframe()
                }, 50);
                return false
            } else {
                alert('XHTMLSuite Critical Error: Iframe can\'t be initialized.')
            }
        }
    } catch (ex) {
        setTimeout(function () {
            editor.initIframe()
        }, 50);
        return false
    }
    XHTMLSuite.fL(this, '_doc');
    doc.open('text/html', 'replace');
    var html = '';
    html += '<?xml version="1.0" encoding="' + editor.config.charSet + '" ?>\n';
    html += this.config.doctype + '\n';
    html += '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' + _xs_editor_lang + '" lang="' + _xs_editor_lang + '">\n';
    html += '<head>\n';
    html += '<meta http-equiv="Content-Type" content="text/html; charset=' + this.config.charSet + '" />\n';
    html += '<base href="' + editor.config.baseURL + '/" />\n';
    html += '<link href="' + _xs_editor_url + 'includes/css/common/xs_common_css.css" rel="stylesheet" type="text/css" media="screen" />\n';
    if (!this.config.wymiwygMode) {
        html += '<style type="text/css" media="screen">@import url(' + this.config.pageStyle + '); html, body { border: 0px; text-align: left; }</style>\n';
        if (this.config.customEditorCSS) {
            html += '<style type="text/css" media="screen">' + this.config.customEditorCSS + '</style>\n'
        }
    } else {
        html += '<link href="' + _xs_editor_url + 'includes/css/wymiwyg/xs_wymiwyg.css" rel="stylesheet" type="text/css" media="screen" />\n'
    }
    if (this.config.highlightAccessibilityTags) {
        html += '<link href="' + _xs_editor_url + 'includes/css/accessibility/xs_accessibility_css.css" rel="stylesheet" type="text/css" media="screen" />\n'
    }
    html += '</head>\n';
    if (this.config.editorBodyCssClass) {
        html += '<body id="xs_editor_body_' + this._textareaID + '" class="' + this.config.editorBodyCssClass + '" style="margin: 4px; padding: 4px; text-align: left;">\n'
    } else {
        html += '<body class="contentpaneopen" id="xs_editor_body_' + this._textareaID + '" style="margin: 4px; padding: 4px; text-align: left;">\n'
    }
    html += this.importHTML(this._textArea.value);
    html += '</body>\n';
    html += '</html>';
    doc.write(html);
    doc.close();
    this.setEditorEvents();
    return true
};
XHTMLSuite.prototype.whenDocReady = function (execFunc, doc) {
    var editor = this;
    if (!doc) {
        doc = this._doc
    } else {
        doc = doc
    }
    if (doc && doc.body) {
        execFunc()
    } else {
        setTimeout(function () {
            editor.whenDocReady(execFunc, doc)
        }, 50)
    }
};
XHTMLSuite.prototype.setEditorEvents = function () {
    var editor = this;
    var doc = this._doc;
    var iframe = editor._iFrame;
    editor.whenDocReady(function () {
        XHTMLSuite._addEvent(doc, 'mousedown', function (e) {
            if (editor.config.showResizeBar) {
                editor._endResize(e)
            }
            if (editor.config.richDropDowns) {
                editor.hideDropDownList()
            }
            if (XHTMLSuite.is_gecko || XHTMLSuite.is_safari) {
                var tagsToSelect = [];
                if (XHTMLSuite.is_gecko) {
                    tagsToSelect = ['hr']
                } else if (XHTMLSuite.is_safari || XHTMLSuite.is_opera) {
                    tagsToSelect = ['img', 'hr', 'input', 'form']
                }
                for (var i in tagsToSelect) {
                    if (typeof tagsToSelect[i] != 'string') {
                        continue
                    }
                    if (e.target.tagName.toLowerCase() == tagsToSelect[i]) {
                        editor.selectNode(e.target);
                        editor.updateToolbar();
                        return false
                    }
                }
            }
            editor.activateEditor();
            return true
        });
        var listener = null;
        if (XHTMLSuite.is_ie) {
            listener = function () {
                editor._editorEvent(editor._iFrame.contentWindow.event)
            }
        } else {
            listener = function (evt) {
                editor._editorEvent(evt)
            }
        }
        XHTMLSuite._addEvents(doc, ['keydown', 'keyup', 'keypress', 'mouseup', 'drag'], listener);
        if (XHTMLSuite.is_ie) {
            XHTMLSuite._addEvent(editor._doc.getElementsByTagName('html')[0], 'click', function () {
                if (editor._iFrame.contentWindow.event.srcElement.tagName.toLowerCase() == 'html') {
                    var r = editor._doc.body.createTextRange();
                    r.collapse();
                    r.select()
                }
            })
        }
        for (var j in editor.extensions) {
            var extension = editor.extensions[j].instance;
            XHTMLSuite.refreshExtension(extension)
        }
        if (typeof editor._onGenerate == 'function') {
            editor._onGenerate()
        }
        if (XHTMLSuite.is_gecko || XHTMLSuite.is_opera) {
            if (editor.config.useParagraph) {
                if (typeof EnterParagraphs != 'undefined') {
                    editor.registerExtension('EnterParagraphs')
                }
            } else {
                if (typeof EnterDivs != 'undefined') {
                    editor.registerExtension('EnterDivs')
                }
            }
        }
        editor.removeLoadingMessage();
        if (editor.config.fullScreen) {
            editor._fullScreen()
        }
        if (typeof editor.colorSwatch == 'function') {
            setTimeout(function () {
                editor.colorSwatch(false, 'forecolor', XHTMLSuite.getElementById('div', editor._textareaID + '_forecolor'), 'bottom, left');
                if (XHTMLSuite.is_gecko) {
                    editor.deactivateEditor()
                }
            }, XHTMLSuite.is_ie_6 ? 500 : 0)
        }
    })
};
XHTMLSuite.prototype.registerExtension = function () {
    var extension = arguments[0];
    if (extension === null || typeof extension == 'undefined' || (typeof extension == 'string' && typeof window[extension] == 'undefined')) {
        return false
    }
    var args = [];
    for (var i = 1; i < arguments.length; ++i) {
        args.push(arguments[i])
    }
    return this.registerExtension2(extension, args)
};
XHTMLSuite.prototype.registerExtension2 = function (extension, args) {
    if (typeof extension == 'string' && typeof window[extension] == 'function') {
        extension = window[extension]
    }
    if (typeof extension == 'undefined') {
        return false
    }
    var obj = new extension(this, args);
    if (obj) {
        var clone = {};
        var info = extension._extensionInfo;
        for (var i in info) {
            if (typeof info[i] != 'string') {
                continue
            }
            clone[i] = info[i]
        }
        clone.instance = obj;
        clone.args = args;
        this.extensions[extension._extensionInfo.name] = clone;
        return obj
    } else {
        alert('XHTMLSuite ERROR: Can\'t register extension ' + extension.toString() + '.')
    }
    return false
};
XHTMLSuite.loadExtension = function (extensionName) {
    var dir = _xs_editor_url + 'extensions/' + extensionName;
    var extension = extensionName.replace(/([a-z])([A-Z])([a-z])/g, '$1' + '-' + '$2' + '$3').toLowerCase() + '.js';
    var extension_file = dir + '/' + extension;
    var extension_lang_file = dir + '/lang/' + _xs_editor_lang + '.js';
    document.write('<script type="text/javascript" src="' + extension_file + '" charset="utf-8"></script>');
    document.write('<script type="text/javascript" src="' + extension_lang_file + '" charset="utf-8"></script>')
};
XHTMLSuite.refreshExtension = function (extension) {
    if (extension && typeof extension.onGenerate == 'function') {
        extension.onGenerate()
    }
    if (extension && typeof extension.onGenerateOnce == 'function') {
        extension.onGenerateOnce();
        extension.onGenerateOnce = null
    }
};
XHTMLSuite.loadStyle = function (style, file, doc) {
    var url = _xs_editor_url || '';
    if (typeof file != 'undefined' || file === null) {
        url += 'themes/' + style + '/' + file + '.css';
        if (/^\//.test(style)) {
            url = 'themes/' + style + '/' + file + '.css'
        }
    } else {
        url += 'themes/' + style + '/theme.css';
        if (/^\//.test(style)) {
            url = 'themes/' + style + '/theme.css'
        }
    }
    if (typeof doc != 'undefined') {
        doc = doc
    } else {
        doc = document
    }
    var head = doc.getElementsByTagName('head')[0];
    var link = doc.createElement('link');
    link.rel = 'stylesheet';
    link.type = 'text/css';
    link.href = url;
    head.appendChild(link)
};
XHTMLSuite.loadStyle(typeof _xs_editor_theme === 'string' ? _xs_editor_theme : 'default');
XHTMLSuite.prototype._createDropDownIframe = function (txt, el_options) {
    var iFrame = document.createElement('iframe');
    iFrame.src = _xs_editor_url + 'dialogs/blank.html';
    iFrame.style.display = 'none';
    iFrame.style.visibility = 'hidden';
    iFrame.frameBorder = '0';
    iFrame.unselectable = 'on';
    iFrame.className = 'xs_iframe';
    iFrame.scrolling = 'no';
    iFrame.id = this._textareaID + '_' + txt + '_iframe';
    switch (txt) {
    case 'forecolor':
    case 'hilitecolor':
    case 'backcolor':
    case 'pIcolorpicker':
        iFrame.className = 'xs_colorswatch_iframe';
        break;
    case 'inserttable':
        iFrame.className = 'xs_quicktable_iframe';
        break;
    default:
        iFrame.className = 'xs_selectbox_iframe';
        break
    }
    if (this.config.fadeMenus) {
        if (XHTMLSuite.is_ie) {
            iFrame.style.filter = 'alpha(opacity = 0) progid:DXImageTransform.Microsoft.Shadow(color=#BDC3BD, Direction=135, Strength=4)'
        } else {
            iFrame.style.MozOpacity = 0
        }
    } else {
        if (XHTMLSuite.is_ie) {
            iFrame.style.filter = 'progid:DXImageTransform.Microsoft.Shadow(color=#BDC3BD, Direction=135, Strength=4)'
        }
    }
    document.body.appendChild(iFrame);
    if (txt != 'forecolor' && txt != 'hilitecolor' && txt != 'backcolor' && txt != 'pIcolorpicker' && txt != 'inserttable') {
        this._initDropDownIframe(txt, el_options)
    } else {
        switch (txt) {
        case 'forecolor':
        case 'hilitecolor':
        case 'backcolor':
        case 'pIcolorpicker':
            break;
        case 'inserttable':
            this._initQuickTableIframe();
            break
        }
    }
};
XHTMLSuite.prototype._wordClean = function () {
    var editor = this;

    function clearClass(node) {
        var newc = node.className.replace(/(^|\s)mso.*?(\s|$)/gi, ' ');
        if (newc != node.className) {
            node.className = newc;
            if (!(/\S/.test(node.className))) {
                node.removeAttribute('className')
            }
        }
    }
    function clearStyle(node) {
        var declarations = node.style.cssText.split(/\s*;\s*/);
        for (var i = declarations.length; --i >= 0;) {
            if (/^mso|^tab-stops/i.test(declarations[i]) || /^margin\s*:\s*0..\s+0..\s+0../i.test(declarations[i])) {
                declarations.splice(i, 1)
            }
        }
        node.style.cssText = declarations.join('; ')
    }
    var stripTag = null;
    if (XHTMLSuite.is_ie) {
        stripTag = function (el) {
            el.outerHTML = editor.htmlEncode(el.innerText)
        }
    } else {
        stripTag = function (el) {
            var txt = document.createTextNode(XHTMLSuite.getInnerText(el));
            el.parentNode.insertBefore(txt, el);
            XHTMLSuite.removeFromParent(el)
        }
    }
    function checkEmpty(el) {
        if (/^(a|span|b|strong|i|em|font)$/i.test(el.tagName) && !el.firstChild) {
            XHTMLSuite.removeFromParent(el)
        }
    }
    function parseTree(root) {
        var tag = root.tagName.toLowerCase(),
            i, next;
        if ((XHTMLSuite.is_ie && root.scopeName != 'HTML') || (!XHTMLSuite.is_ie && (/:/.test(tag)))) {
            stripTag(root);
            return false
        } else {
            clearClass(root);
            clearStyle(root);
            for (var j = root.firstChild; j; j = next) {
                next = j.nextSibling;
                if (j.nodeType == 1 && parseTree(j)) {
                    checkEmpty(j)
                }
            }
        }
        return true
    }
    parseTree(this._doc.body);
    this._finishCleanUp()
};
XHTMLSuite.prototype._finishCleanUp = function () {
    var html = this.importHTML(this.getHTML());
    html = html.replace(/<\/?\s*!--[^-->]*-->/gi, '');
    html = html.replace(/<\?xml:[^>]*>/gi, '').replace(/<\/?st1:[^>]*>/g, '');
    html = html.replace(/  */gi, ' ');
    html = html.replace(/font-family: \'(.*?)\'/gi, 'font-family:$1;');
    html = html.replace(/font-family: &quot;(.*?)&quot;;/gi, 'font-family: $1;');
    this.setHTML(html);
    this.updateToolbar()
};
XHTMLSuite.getInnerText = function (el) {
    var txt = '',
        i;
    for (i = el.firstChild; i; i = i.nextSibling) {
        if (i.nodeType == 3) {
            txt += i.data
        } else if (i.nodeType == 1) {
            txt += XHTMLSuite.getInnerText(i)
        }
    }
    return txt
};
XHTMLSuite.prototype.forceRedraw = function () {
    this._doc.body.style.visibility = 'hidden';
    this._doc.body.style.visibility = 'visible'
};
XHTMLSuite.prototype.focusEditor = function () {
    switch (this._editMode) {
    case 'wysiwyg':
        try {
            if (XHTMLSuite._sEHBA) {
                this.activateEditor();
                try {
                    if (XHTMLSuite.is_safari) {
                        this._iFrame.contentWindow.focus()
                    } else {
                        this._iFrame.contentWindow.document.body.focus()
                    }
                } catch (ex) {}
            }
        } catch (ex1) {}
        break;
    case 'textmode':
        try {
            this._textArea.focus()
        } catch (ex2) {}
        break;
    default:
        alert('XHTMLSuite ERROR: mode ' + this._editMode + ' is not implemented.');
        break
    }
    return this._doc
};
XHTMLSuite.prototype._undoTakeSnapshot = function () {
    ++this._undoPos;
    if (this._undoPos >= this.config.undoSteps) {
        this._undoQueue.shift();
        --this._undoPos
    }
    var take = true;
    var txt = this.getInnerHTML();
    if (this._undoPos > 0) {
        take = (this._undoQueue[this._undoPos - 1] != txt)
    }
    if (take) {
        this._undoQueue[this._undoPos] = txt
    } else {
        this._undoPos--
    }
};
XHTMLSuite.prototype.undo = function () {
    if (this._undoPos > 0) {
        var txt = this._undoQueue[--this._undoPos];
        if (txt) {
            this.setHTML(txt)
        } else {
            ++this._undoPos
        }
    }
};
XHTMLSuite.prototype.redo = function () {
    if (this._undoPos < this._undoQueue.length - 1) {
        var txt = this._undoQueue[++this._undoPos];
        if (txt) {
            this.setHTML(txt)
        } else {
            this._undoPos--
        }
    }
};
XHTMLSuite.prototype.disableToolbar = function (except) {
    if (this._timerToolbar) {
        clearTimeout(this._timerToolbar)
    }
    if (typeof except == 'undefined') {
        except = []
    } else if (typeof except != 'object') {
        except = [except]
    }
    for (var i in this._toolbarObjects) {
        var tbO_btn = this._toolbarObjects[i];
        if (except.contains(i)) {
            continue
        }
        if (typeof tbO_btn.state != 'function') {
            continue
        }
        tbO_btn.state('enabled', false)
    }
    for (var j in this._tabbarObjects) {
        var tbbO_btn = this._tabbarObjects[j];
        if (except.contains(j)) {
            continue
        }
        if (typeof tbO_btn.state != 'function') {
            continue
        }
        tbbO_btn.state('enabled', false)
    }
    if (this.config.propertiesInspector) {
        this._pIFramework.piFieldSet.disabled = true
    }
    if (this.config.richDropDowns) {
        this.hideDropDownList()
    }
};
XHTMLSuite.prototype.enableToolbar = function () {
    this._updateToolbarButtons(this._toolbarObjects, false);
    if (typeof this._tabbarObjects != 'undefined') {
        this._updateToolbarButtons(this._tabbarObjects, false)
    }
};
XHTMLSuite.prototype.updateToolbar = function (noStatus) {
    var editor = this;
    var el, ancestors, activeElement, toRemove, txt, item, parent, nodeLink, params, removeNodeLink, removeClassLink = null;
    var text = (this._editMode == 'textmode');
    if (!text) {
        ancestors = this.getAllAncestors();
        if (ancestors.length > 5) {
            showTags = 5
        } else {
            showTags = ancestors.length
        }
        if (this.config.propertiesInspector) {
            this._propertiesInspector()
        }
        if (this.config.statusBar && !noStatus) {
            while (this._statusBarItems.length) {
                item = this._statusBarItems.pop();
                item.el = null;
                item.editor = null;
                if (XHTMLSuite.is_ie_6) {
                    item.href = null
                }
                item.onclick = null;
                item.oncontextmenu = null;
                item.onmouseover = null;
                item.onmouseout = null;
                item.onmousedown = null;
                item.onmouseup = null;
                item.onkeypress = null;
                item._xsd0Es.click = null;
                item._xsd0Es.contextmenu = null;
                item._xsd0Es.mouseover = null;
                item._xsd0Es.mouseout = null;
                item._xsd0Es.mousedown = null;
                item._xsd0Es.mouseup = null;
                item._xsd0Es.keypress = null;
                item = null
            }
            if (ancestors.length > (showTags + 1)) {
                this._statusBarTree.innerHTML = XHTMLSuite.I18N.msg['Path'] + ': ...'
            } else {
                this._statusBarTree.innerHTML = XHTMLSuite.I18N.msg['Path'] + ': '
            }
            for (var i = showTags; --i >= 0;) {
                el = ancestors[i];
                if (!el) {
                    continue
                }
                nodeLink = document.createElement('a');
                if (XHTMLSuite.is_ie_6) {
                    nodeLink.href = 'javascript:void(0)'
                }
                nodeLink.el = el;
                nodeLink.editor = this;
                this._statusBarItems.push(nodeLink);
                XHTMLSuite.aD0E(nodeLink, 'click', function () {
                    if (XHTMLSuite.is_ie) {
                        editor.selectNodeContents(this.el)
                    } else {
                        editor.selectNode(this.el)
                    }
                    editor._currentlyActiveElement = this.el;
                    editor.scrollToElement(this.el);
                    if (editor.config.propertiesInspector) {
                        editor._propertiesInspector(this.el)
                    }
                    XHTMLSuite._removeClass(this.el, 'xs_active_element');
                    editor.updateToolbar();
                    return false
                });
                if (this.config.statusbarHoverTips && !XHTMLSuite.is_opera) {
                    XHTMLSuite.aD0E(nodeLink, 'mouseover', function () {
                        XHTMLSuite._addClasses(this.el, 'xs_active_element');
                        return false
                    });
                    XHTMLSuite.aD0Es(nodeLink, ['mouseout', 'mousedown', 'mouseup', 'keypress'], function () {
                        XHTMLSuite._removeClass(this.el, 'xs_active_element');
                        return false
                    })
                }
                XHTMLSuite.aD0E(nodeLink, 'contextmenu', function () {
                    this.blur();
                    return false
                });
                txt = el.tagName.toLowerCase();
                if (!XHTMLSuite.is_opera) {
                    nodeLink.title = el.style.cssText.toLowerCase()
                }
                if (txt != 'body') {
                    if (el.className.match(XHTMLSuite.RE_XsMedia) && txt == 'img') {
                        params = XHTMLSuite._objectParamCache[el.id].split('|');
                        for (var divider = 1; divider < params.length; divider++) {
                            param = params[divider].split(',')
                        }
                        switch (el.className) {
                        case 'XsFlashObject':
                        case 'XsQuickTimeObject':
                        case 'XsWindowsMediaObject':
                        case 'XsUnknownMediaObject':
                            nodeLink.appendChild(document.createTextNode('\u003cobject\u003e'));
                            break;
                        default:
                            nodeLink.appendChild(document.createTextNode('\u003cobject\u003e'));
                            break
                        }
                    } else {
                        nodeLink.appendChild(document.createTextNode('\u003c' + txt + '\u003e'))
                    }
                    this._statusBarTree.appendChild(nodeLink)
                }
                if (i !== 0) {
                    this._statusBarTree.appendChild(document.createTextNode(String.fromCharCode(0xbb)))
                }
            }
            parent = editor.getParentElement();
            removeClassLink = document.createElement('a');
            if (XHTMLSuite.is_ie_6) {
                removeClassLink.href = 'javascript:void(0)'
            }
            removeClassLink.editor = this;
            this._statusBarItems.push(removeClassLink);
            XHTMLSuite.aD0E(removeClassLink, 'click', function () {
                this.blur();
                editor.focusEditor();
                el.setAttribute(XHTMLSuite.is_ie ? 'className' : 'class', '');
                XHTMLSuite._removeClass(el, 'xs_active_element_RS');
                if (editor.config.langMarks) {
                    el.removeAttribute('xml:lang');
                    el.removeAttribute('lang')
                }
                editor.updateToolbar();
                return false
            });
            XHTMLSuite.aD0E(removeClassLink, 'contextmenu', function () {
                this.blur();
                return false
            });
            if (this.config.statusbarHoverTips && !XHTMLSuite.is_opera) {
                XHTMLSuite.aD0E(removeClassLink, 'mouseover', function () {
                    XHTMLSuite._addClasses(el, 'xs_active_element_RS');
                    return false
                });
                XHTMLSuite.aD0Es(removeClassLink, ['mouseout', 'mousedown', 'mouseup', 'keypress'], function () {
                    XHTMLSuite._removeClass(el, 'xs_active_element_RS');
                    return false
                })
            }
            removeClassLink.title = XHTMLSuite.I18N.statusBarMsg['Remove CSS Class'] + ': ' + el.className;
            removeNodeLink = document.createElement('a');
            if (XHTMLSuite.is_ie_6) {
                removeNodeLink.href = 'javascript:void(0)'
            }
            removeNodeLink.editor = this;
            this._statusBarItems.push(removeNodeLink);
            XHTMLSuite.aD0E(removeNodeLink, 'click', function () {
                this.blur();
                editor.focusEditor();
                if (txt == 'li' || txt == 'ol' || txt == 'ul' || txt == 'dl' || txt == 'dd' || txt == 'dt' || txt == 'caption' || txt == 'table' || txt == 'td' || txt == 'th' || txt == 'tr') {
                    var p = el.parentNode;
                    p.removeChild(el)
                } else {
                    while (parent.firstChild) {
                        parent.parentNode.insertBefore(parent.firstChild, parent)
                    }
                    parent.parentNode.removeChild(parent)
                }
                XHTMLSuite._removeClass(el, 'xs_active_element_RE');
                editor.updateToolbar();
                editor._currentlyActiveElement = '';
                return false
            });
            XHTMLSuite.aD0E(removeNodeLink, 'contextmenu', function () {
                this.blur();
                return false
            });
            if (this.config.statusbarHoverTips && !XHTMLSuite.is_opera) {
                XHTMLSuite.aD0E(removeNodeLink, 'mouseover', function () {
                    XHTMLSuite._addClasses(el, 'xs_active_element_RE');
                    return false
                });
                XHTMLSuite.aD0Es(removeNodeLink, ['mouseout', 'mousedown', 'mouseup', 'keypress'], function () {
                    XHTMLSuite._removeClass(el, 'xs_active_element_RE');
                    return false
                })
            }
            if (el.className.match(XHTMLSuite.RE_XsMedia)) {
                toRemove = 'object'
            } else {
                toRemove = txt
            }
            removeNodeLink.title = XHTMLSuite.I18N.statusBarMsg['Remove Element'] + ': \u003c' + toRemove + '\u003e';
            if (txt && txt != 'body') {
                if (txt.indexOf(' ') > -1) {
                    txt = txt.split(' ');
                    txt = txt[0]
                }
                if (!txt.match(XHTMLSuite.RE_no_NLR)) {
                    this._statusBarTree.appendChild(document.createTextNode('\u00bb'));
                    removeNodeLink.appendChild(document.createTextNode(XHTMLSuite.I18N.statusBarMsg['Remove Element']));
                    this._statusBarTree.appendChild(removeNodeLink)
                }
                if (el.className && !el.className.match(XHTMLSuite.RE_xs_CSS) && !el.className.match(XHTMLSuite.RE_XsMedia)) {
                    this._statusBarTree.appendChild(document.createTextNode('\u00bb'));
                    removeClassLink.appendChild(document.createTextNode(XHTMLSuite.I18N.statusBarMsg['Remove CSS Class']));
                    this._statusBarTree.appendChild(removeClassLink)
                }
            }
        }
    }
    this._updateToolbarButtons(this._toolbarObjects);
    if (!this.config.editorClassicStyle) {
        if (!noStatus) {
            this._updateToolbarButtons(this._tabbarObjects, false)
        }
    }
    for (var iP in this.extensions) {
        var extension = this.extensions[iP].instance;
        if (extension && typeof extension.onUpdateToolbar == 'function') {
            extension.onUpdateToolbar()
        }
    }
};
XHTMLSuite.prototype._updateToolbarButtons = function (toolBarObjects, takeUndoSnapShot) {
    var editor = this;
    var doc = this._doc;
    var btn, btnPanel, cmd, ancestors, el, text, selectedText;
    el = this.getParentElement();
    text = (this._editMode == 'textmode');
    selectedText = this.hasSelectedText();
    ancestors = this.getAllAncestors();
    for (var i in toolBarObjects) {
        btn = toolBarObjects[i];
        if (typeof (btn.state) != 'function') {
            continue
        }
        btnPanel = btn.element.parentNode.parentNode.parentNode.parentNode.parentNode;
        if (btnPanel.style.display == 'none') {
            continue
        }
        cmd = i;
        var inContext = true;
        if (btn.context && !text) {
            inContext = false;
            var context = btn.context;
            var attrs = [];
            if (/(.*)\[(.*?)\]/.test(context)) {
                context = RegExp.$1;
                attrs = RegExp.$2.split(',')
            }
            context = context.toLowerCase();
            var match = (context == '*');
            for (var k = 0; k < ancestors.length; ++k) {
                if (!ancestors[k]) {
                    continue
                }
                if (match || (ancestors[k].tagName.toLowerCase() == context)) {
                    inContext = true;
                    for (var ka = 0; ka < attrs.length; ++ka) {
                        if (!eval('ancestors[k].' + attrs[ka])) {
                            inContext = false;
                            break
                        }
                    }
                    if (inContext) {
                        break
                    }
                }
            }
        }
        btn.state('enabled', (!text || btn.text) && inContext);
        if (typeof cmd == 'function') {
            continue
        }
        var dropdown = this.config.customSelects[cmd];
        if ((!text || btn.text) && (typeof dropdown != 'undefined')) {
            dropdown.refresh(this);
            continue
        }
        switch (cmd) {
        case 'fontname':
        case 'fontsize':
            if (!text) {
                try {
                    var value = ('' + doc.queryCommandValue(cmd)).toLowerCase();
                    if (!value || value === '' || value === null) {
                        btn.element.selectedIndex = 0;
                        break
                    }
                    var options = this.config[cmd];
                    var sIndex = 0;
                    for (var l in options) {
                        if (typeof (options[l]) != 'string') {
                            continue
                        }
                        if ((l.toLowerCase() == value) || (options[l].substr(0, value.length).toLowerCase() == value)) {
                            btn.element.selectedIndex = sIndex;
                            throw 'ok'
                        }++sIndex
                    }
                    btn.element.selectedIndex = 0
                } catch (ex) {}
            }
            break;
        case 'formatblock':
            var blocks = [];
            for (var indexBlock in this.config.formatblock) {
                if (typeof this.config.formatblock[indexBlock] == 'string') {
                    blocks[blocks.length] = this.config.formatblock[indexBlock]
                }
            }
            var deepestAncestor = this._getFirstAncestor(this._getSelection(), blocks);
            if (deepestAncestor) {
                for (var x = 0; x < blocks.length; x++) {
                    if (blocks[x].toLowerCase() == deepestAncestor.tagName.toLowerCase()) {
                        btn.element.selectedIndex = x
                    }
                }
            } else {
                btn.element.selectedIndex = 0
            }
            break;
        case 'textindicator':
            if (!text) {
                try {
                    var style = btn.element.style;
                    style.backgroundColor = XHTMLSuite._makeColor(doc.queryCommandValue((XHTMLSuite.is_ie || XHTMLSuite.is_safari) ? 'backcolor' : 'hilitecolor'));
                    if (/transparent/i.test(style.backgroundColor)) {
                        style.backgroundColor = XHTMLSuite._makeColor(XHTMLSuite._colorToRgb('#ffffff'))
                    }
                    style.color = XHTMLSuite._makeColor(doc.queryCommandValue('forecolor'));
                    style.fontFamily = doc.queryCommandValue('fontname');
                    style.fontWeight = doc.queryCommandState('bold') ? 'bold' : 'normal';
                    style.fontStyle = doc.queryCommandState('italic') ? 'italic' : 'normal';
                    style.textDecoration = doc.queryCommandState('underline') ? 'underline' : 'none'
                } catch (ex1) {}
            }
            break;
        case 'htmlmode':
            btn.state('active', text);
            break;
        case 'lefttoright':
        case 'righttoleft':
            while (el && !XHTMLSuite.isBlockElement(el)) {
                el = el.parentNode
            }
            if (el) {
                btn.state('active', (el.style.direction == (cmd == 'righttoleft' ? 'rtl' : 'ltr')))
            }
            break;
        case 'uppercasetext':
        case 'lowercasetext':
        case 'createlink':
        case 'cut':
        case 'copy':
            btn.state('enabled', (!text && selectedText));
            break;
        case 'undo':
            btn.state('enabled', (!text && this._undoPos > 0));
            break;
        case 'redo':
            btn.state('enabled', (!text && (this._undoPos < this._undoQueue.length - 1)));
            break;
        default:
            try {
                btn.state('active', (!text && doc.queryCommandState(cmd)))
            } catch (ex) {}
            break
        }
    }
    if (!this._timerUndo && !takeUndoSnapShot && cmd != 'htmlmode' && cmd != 'textmode' && this._editMode != 'textmode') {
        this._undoTakeSnapshot();
        this._timerUndo = setTimeout(function () {
            editor._timerUndo = null
        }, this.config.undoTimeout)
    }
};
XHTMLSuite.prototype.getAllAncestors = function () {
    var p = this.getParentElement();
    var a = [];
    while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
        a.push(p);
        p = p.parentNode
    }
    a.push(this._doc.body);
    return a
};
XHTMLSuite.prototype._getFirstAncestor = function (sel, types) {
    var prnt = this._activeElement(sel);
    if (prnt === null) {
        try {
            prnt = (XHTMLSuite.is_ie ? this._createRange(sel).parentElement() : this._createRange(sel).commonAncestorContainer)
        } catch (ex) {
            return null
        }
    }
    if (typeof types == 'string') {
        types = [types]
    }
    while (prnt) {
        if (prnt.nodeType == 1) {
            if (types === null) {
                return prnt
            }
            for (var i = 0; i < types.length; i++) {
                if (prnt.tagName.toLowerCase() == types[i]) {
                    return prnt
                }
            }
            if (prnt.tagName.toLowerCase() == 'body') {
                break
            }
            if (prnt.tagName.toLowerCase() == 'table') {
                break
            }
        }
        prnt = prnt.parentNode
    }
    return null
};
XHTMLSuite.prototype.surroundHTML = function (startTag, endTag) {
    var html = this.getSelectedHTML();
    if (html === null || html === '') {
        return
    }
    if (this.hasSelectedText()) {
        this.insertHTML(startTag + html.replace(XHTMLSuite.RE_body, '') + endTag)
    } else {
        alert(XHTMLSuite.I18N.msg['You need to select some text first'])
    }
    this.updateToolbar()
};
XHTMLSuite.prototype.surroundHTML2 = function (startTag, endTag) {
    if (this.getSelectedHTML() !== '' && this.getSelectedHTML() !== null && typeof this.getSelectedHTML() !== 'undefined') {
        this.insertHTML(startTag + this.getSelectedHTML().replace(XHTMLSuite.RE_body, '') + endTag)
    }
};
XHTMLSuite.prototype.hasSelectedText = function () {
    return this.getSelectedHTML() !== ''
};
XHTMLSuite.getAllEditorContents = function () {
    for (var i = 0; i < __xhtmlsuites.length; i++) {
        try {
            __xhtmlsuites[i]._textArea.value = __xhtmlsuites[i].getEditorContents()
        } catch (ex) {}
    }
};
XHTMLSuite.prototype._preview = function () {
    var html = '';
    var previewContent = '';
    for (var i = 0; i < __xhtmlsuites.length; i++) {
        try {
            html += __xhtmlsuites[i].getEditorContents()
        } catch (ex) {}
    }
    var preview = window.open('about:blank', 'xs_preview', 'width=' + this.config.width + ',height=480,menubar=0,status=1,location=0,toolbar=1,scrollbars=1,resizable=1');
    preview.document.open('text/html', 'replace');
    previewContent += '<html>\n';
    previewContent += '<head>\n';
    previewContent += '<title>XHTMLSuite ' + XHTMLSuite.I18N.preview["Preview"] + '</title>\n';
    previewContent += '<meta http-equiv="Content-Type" content="text/html; charset=' + this.config.charSet + '">\n';
    previewContent += '<base href="' + this.config.baseURL + '/" />\n';
    previewContent += '<style type="text/css">@import url(' + this.config.pageStyle + '); html, body { border: 0px; text-align: left; }</style>\n';
    previewContent += '</head>\n';
    if (this.config.editorBodyCssClass) {
        previewContent += '<body class="' + this.config.editorBodyCssClass + '" onblur="try{self.focus();}catch(ex){}" style="margin: 4px; padding: 4px;">\n'
    } else {
        previewContent += '<body class="contentpaneopen" onblur="try{self.focus();}catch(ex){}" style="margin: 4px; padding: 4px;">\n'
    }
    previewContent += html;
    previewContent += '<br />\n<div style="border-bottom: 1px solid #bbb;"></div>\n<br />\n<div align="center"><a href=\"javascript:self.close();\">' + XHTMLSuite.I18N.preview["Close this window"] + '</a></div><br />';
    previewContent += '</body>\n';
    previewContent += '<html>';
    preview.document.write(previewContent);
    preview.document.close();
    if (XHTMLSuite.is_ie) {
        setTimeout(function () {
            preview.focus()
        }, 500)
    } else {
        preview.focus()
    }
    this._changesMade = true
};
XHTMLSuite.prototype.removeParentTag = function (el) {
    while (el.firstChild) {
        el.parentNode.insertBefore(el.firstChild, el)
    }
    el.parentNode.removeChild(el)
};
XHTMLSuite.prototype.setTag = function (tag, attr, attrFunc) {
    if (typeof attr == 'undefined' || attr === '') {
        attr = ''
    } else {
        attr = ' ' + attr
    }
    var el = null;
    var p = this.getAllAncestors();
    for (var i = 0; i < p.length; ++i) {
        if (p[i].tagName.toLowerCase() == tag) {
            el = p[i];
            break
        }
    }
    if (el !== null) {
        var html = el.innerHTML;
        this.selectNodeContents(el);
        el.parentNode.removeChild(el);
        this.insertHTML(html);
        return
    }
    if (!el) {
        var sel = this._getSelection();
        var range = this._createRange(sel);
        var compare = 0;
        if (XHTMLSuite.is_ie) {
            compare = range.compareEndPoints('StartToEnd', range)
        } else {
            compare = range.compareBoundaryPoints(range.START_TO_END, range)
        }
        if (compare === 0) {
            alert(XHTMLSuite.I18N.msg['You need to select some text first']);
            return
        }
    }
    if (typeof attrFunc != 'undefined') {
        attr += ' ' + attrFunc()
    }
    if (attr === ' ') {
        return
    }
    this.surroundHTML('<' + tag + attr + '>', '</' + tag + '>');
    this.updateToolbar()
};
XHTMLSuite.prototype._accessibilitycheck = function () {
    var editor = this;
    this.updateToolbar();
    this._popupDialog('508_check.php', function (param) {
        editor.updateToolbar()
    }, editor, 'accessibility')
};
XHTMLSuite.prototype._xsacronym = function () {
    this.setTag('acronym', '', function () {
        var title = prompt(XHTMLSuite.I18N.msg['Please enter the definition of the abbreviation:'], '');
        if (title !== null && title !== '') {
            return ' title="' + title + '"'
        }
        return ''
    })
};
XHTMLSuite.prototype._xsabbr = function () {
    var editor = this;
    if (XHTMLSuite.is_ie) {
        alert(XHTMLSuite.I18N.msg['Internet Explorer does not support the abbr tag.\nPlease use "acronym" instead.']);
        return false
    } else {
        editor.setTag('abbr', '', function () {
            var title = prompt(XHTMLSuite.I18N.msg['Please enter the definition of the abbreviation:'], '');
            if (title !== null && title !== '') {
                return ' title="' + title + '"'
            }
            return ''
        })
    }
};
XHTMLSuite.prototype._xsquote = function () {
    var editor = this;
    editor.setTag('q', '', function () {
        var title = prompt(XHTMLSuite.I18N.msg["Please enter the source of the citation:"], "");
        if (title !== null && title !== '') {
            return ' title="' + title + '"'
        }
        return ''
    })
};
XHTMLSuite.prototype._insertCharacter = function () {
    var editor = this;
    this._popupDialog('insert_character.php', function (entity) {
        if (!entity) {
            return false
        }
        editor.insertHTML(entity)
    }, null)
};
XHTMLSuite.prototype._insertImage = function (viewmode, image) {
    var editor = this;
    var sel = this._getSelection();
    var range = this._createRange(sel);
    var outparam;
    if (typeof image == 'undefined') {
        image = this.getParentElement();
        if (image && (!(/^img$/i.test(image.tagName)))) {
            image = null
        }
    }
    if (image) {
        if (image.className !== null && image.className.match(XHTMLSuite.RE_XsMedia)) {
            return
        }
        outparam = {
            f_url: XHTMLSuite.is_ie ? this.stripBaseURL(image.src) : this.stripBaseURL(image.getAttribute('src')),
            f_alt: image.alt,
            f_border: image.border,
            f_align: image.align,
            f_vert: image.vspace,
            f_horiz: image.hspace,
            f_width: image.width,
            f_height: image.height,
            f_float: XHTMLSuite.is_ie ? image.style.styleFloat : image.style.cssFloat,
            f_class: image.className,
            f_title: image.title,
            f_longdesc: this.stripBaseURL(image.longDesc),
            f_css: this._createCssArray(_xs_editing_css_url),
            editor: editor
        }
    } else {
        outparam = {
            f_url: '',
            f_alt: '',
            f_border: '',
            f_align: '',
            f_vert: '',
            f_horiz: '',
            f_width: '',
            f_height: '',
            f_float: '',
            f_class: '',
            f_title: '',
            f_longdesc: '',
            f_css: this._createCssArray(_xs_editing_css_url),
            editor: editor
        }
    };
    var viewMode = null;
    if (typeof viewmode == 'undefined' || viewmode === null) {
        viewMode = this.config.ImageManagerViewMode
    } else {
        viewMode = viewmode
    }
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=insert_image&listmode=' + editor.config.ImageManagerListMode + '&viewmode=' + viewMode, function (param) {
        if (!param) {
            return false
        }
        var img = image;
        if (!img) {
            if (XHTMLSuite.is_ie) {
                editor._doc.execCommand('insertimage', false, param.f_url);
                img = range.parentElement();
                if (img.tagName.toLowerCase() != 'img') {
                    img = img.previousSibling
                }
            } else {
                img = document.createElement('img');
                img.src = ((XHTMLSuite.is_opera || XHTMLSuite.is_safari) && editor.config.stripBaseUrl) ? editor.config.baseURL + '/' + param.f_url : param.f_url;
                editor.insertNodeAtSelection(img);
                if (!img.tagName) {
                    img = range.startContainer.firstChild
                }
            }
        } else {
            img.src = param.f_url
        }
        for (var field in param) {
            var value = param[field];
            switch (field) {
            case 'f_alt':
                img.alt = XHTMLSuite.is_ie ? value.replace(/"/g, "'") : value;
                break;
            case 'f_border':
                img.border = parseInt(value || '0', 10);
                break;
            case 'f_align':
                img.align = value;
                break;
            case 'f_vert':
                if (value !== '') img.vspace = parseInt(value, 10);
                break;
            case 'f_horiz':
                if (value !== '') img.hspace = parseInt(value, 10);
                break;
            case 'f_width':
                if (parseInt(value, 10) > 0) img.width = parseInt(value, 10);
                break;
            case 'f_height':
                if (parseInt(value, 10) > 0) img.height = parseInt(value, 10);
                break;
            case 'f_float':
                XHTMLSuite.is_ie ? img.style.styleFloat = value : img.style.cssFloat = value;
                break;
            case 'f_class':
                img.className = value;
                break;
            case 'f_title':
                img.title = XHTMLSuite.is_ie ? value.replace(/"/g, "'") : value;
                break;
            case 'f_longdesc':
                value == '/' && value !== null ? img.longDesc === '' : img.longDesc = value;
                break
            }
        }
        if (param.f_thumb !== '' && param.f_thumb !== null) {
            editor.selectNodeContents(img);
            editor._doc.execCommand('createlink', false, param.f_thumb)
        }
        editor.updateToolbar();
        return true
    }, outparam)
};
XHTMLSuite.prototype._insertMedia = function (viewmode, movie) {
    var editor = this;
    var sel = this._getSelection();
    var range = this._createRange(sel);
    var objectHTML = '';
    var paramTags = '';
    var outparam = null;
    if (typeof movie == 'undefined') {
        movie = this.getParentElement();
        if (movie && (!(/^img$/i.test(movie.tagName)))) {
            movie = null
        }
    }
    if (movie) {
        if (!movie.className.match(XHTMLSuite.RE_XsMedia)) {
            return false
        }
        outparam = {
            f_xs_internal_id: movie.id,
            f_width: movie.width,
            f_height: movie.height,
            f_vert: movie.vspace,
            f_horiz: movie.hspace
        }
    } else {
        outparam = {
            f_movie: '',
            f_horiz: '',
            f_vert: '',
            f_height: '',
            f_width: '',
            f_quality: '',
            f_scale: '',
            f_wmode: '',
            f_play: '',
            f_loop: '',
            f_menu: ''
        }
    };
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=insert_media&listmode=media_imageslist&viewmode=' + editor.config.ImageManagerViewMode, function (param) {
        if (!param) {
            return false
        }
        var img = movie;
        if (img) {
            for (var field in param) {
                var value = param[field];
                switch (field) {
                case 'f_vert':
                    img.vspace = parseInt(value || '', 10);
                    break;
                case 'f_horiz':
                    img.hspace = parseInt(value || '', 10);
                    break;
                case 'f_width':
                    if (parseInt(value, 10) > 0) {
                        img.width = parseInt(value, 10)
                    }
                    break;
                case 'f_height':
                    if (parseInt(value, 10) > 0) {
                        img.height = parseInt(value, 10)
                    }
                    break
                }
            }
            img.className = 'XsFlashObject';
            img.id = movie.id
        } else {
            for (var field in param) {
                var value = param[field];
                switch (field) {
                case 'f_movie':
                    src = value;
                    break;
                case 'f_horiz':
                    hspc = parseInt(value || '', 10);
                    break;
                case 'f_vert':
                    vspc = parseInt(value || '', 10);
                    break;
                case 'f_height':
                    hght = value;
                    break;
                case 'f_width':
                    wdth = value;
                    break
                }
            }
            for (var field in param) {
                var value = param[field];
                var paramName = field.replace(/f_/gi, '');
                if (value === '' || paramName == 'xs_internal_id' || paramName == 'width' || paramName == 'height' || paramName == 'horiz' || paramName == 'vert') {
                    continue
                }
                paramTags += '<param name="' + paramName + '" value="' + value + '"' + (editor.config.outputHTML401 ? '></param>' : ' />\n')
            }
            objectHTML += '<object classid="' + editor.config.flashCLSID + '" codebase="' + editor.config.flashCodeBase + '" width="' + wdth + '" height="' + hght + '" hspace="' + hspc + '" vspace="' + vspc + '">\n';
            objectHTML += paramTags;
            objectHTML += '<embed type="application/x-shockwave-flash" pluginspage="' + editor.config.flashPluginsPage + '" src="' + src + '" width="' + wdth + '" height="' + hght + '" ' + (editor.config.outputHTML401 ? '></embed>' : ' />\n');
            objectHTML += '</object>\n';
            objectHTML = editor.HTMLParser(objectHTML);
            editor.insertHTML(objectHTML);
            editor.setHTML(editor.importHTML(editor.exportHTML(editor.getHTML())));
            editor.updateToolbar()
        }
        editor.updateToolbar();
        return true
    }, outparam)
};
XHTMLSuite.prototype._insertImageURL = function (activeElement, image, field) {
    var editor = this;
    var outparam = null;
    outparam = {
        f_url: ''
    };
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=insert_image&backgroundmode=active&viewmode=simple&listmode=' + this.config.ImageManagerListMode, function (param) {
        if (!param) {
            return false
        } else {
            activeElement.setAttribute('background', editor.stripBaseURL(param.f_url));
            field.value = editor.stripBaseURL(param.f_url)
        }
        return true
    }, outparam)
};
XHTMLSuite.prototype._insertFile = function () {
    var sel = this._getSelection();
    var range = this._createRange(sel);
    var editor = this;
    var outparam = null;
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=insert_file', function (param) {
        if (!param) {
            return false
        }
        var caption = document.createTextNode(param.f_caption);
        var space1 = document.createTextNode(' ');
        var space2 = document.createTextNode(' ');
        var medialink = document.createElement('a');
        if (param.f_addicon) {
            var icon = document.createElement('img');
            icon.src = (XHTMLSuite.is_opera || XHTMLSuite.is_safari) ? param.f_icon : editor.stripBaseURL(param.f_icon);
            icon.width = '16';
            icon.height = '16';
            icon.border = '0';
            icon.alt = param.f_caption;
            icon.title = param.f_caption
        }
        if (param.f_addsize) {
            var f_addsize = param.f_adddate ? document.createTextNode(param.f_size + ', ') : document.createTextNode(param.f_size)
        }
        if (param.f_adddate) {
            var f_adddate = document.createTextNode(param.f_date)
        }
        medialink.href = param.f_url;
        if (param.f_addtarget) {
            medialink.target = param.f_target
        }
        medialink.title = param.f_caption;
        if (param.f_addicon) {
            medialink.appendChild(icon);
            medialink.appendChild(space1)
        }
        medialink.appendChild(caption);
        medialink.appendChild(space2);
        if (param.f_addsize || param.f_adddate) {
            var openBracket = document.createTextNode('(');
            medialink.appendChild(openBracket)
        }
        if (param.f_addsize) {
            medialink.appendChild(f_addsize)
        }
        if (param.f_adddate) {
            medialink.appendChild(f_adddate)
        }
        if (param.f_addsize || param.f_adddate) {
            var closeBracket = document.createTextNode(')');
            medialink.appendChild(closeBracket)
        }
        editor.insertNodeAtSelection(medialink);
        editor.updateToolbar();
        return true
    }, outparam)
};
XHTMLSuite.prototype._setColor = function (cmdID) {
    var editor = this;
    var buttonID = cmdID;
    var anchorage, swatch = null;
    var direction = 'bottom, left';
    anchorage = XHTMLSuite.getElementById('div', this._textareaID + '_' + buttonID);
    switch (cmdID) {
    case 'hilitecolor':
    case 'backcolor':
        if (XHTMLSuite.is_ie || XHTMLSuite.is_safari) {
            cmdID = 'backcolor'
        }
        if (XHTMLSuite.is_gecko) {
            try {
                editor._doc.execCommand('styleWithCSS', false, true)
            } catch (ex) {}
        }
        if (XHTMLSuite.is_ie || XHTMLSuite.is_safari) {
            buttonID = 'hilitecolor'
        }
        editor.colorSwatch({
            callback: function (color) {
                if (XHTMLSuite.is_ie) {
                    var range = editor._createRange(editor._getSelection());
                    range.select()
                }
                if (color) {
                    if (color == 'none') {
                        editor._doc.execCommand(cmdID, false, '')
                    } else {
                        editor._doc.execCommand(cmdID, false, color)
                    }
                }
            }
        }, cmdID, anchorage, direction);
        break;
    case 'forecolor':
        editor.colorSwatch({
            callback: function (color) {
                if (XHTMLSuite.is_ie) {
                    var range = editor._createRange(editor._getSelection());
                    range.select()
                }
                if (color) {
                    if (color == 'none') {
                        editor._doc.execCommand(cmdID, false, '')
                    } else {
                        editor._doc.execCommand(cmdID, false, color)
                    }
                }
            }
        }, cmdID, anchorage, direction);
        break
    }
};
XHTMLSuite.prototype._createLink = function (link) {
    var editor = this;
    var outparam = null;
    var sel = this._getSelection();
    var range = this._createRange(sel);
    this.focusEditor();
    if (typeof link == 'undefined') {
        link = this.getParentElement();
        if (link) {
            while (link && !(/^a$/i.test(link.tagName))) {
                link = link.parentNode
            }
        }
    }
    if (!link) {
        var compare = 0;
        if (XHTMLSuite.is_ie) {
            if (!range == range.htmlText) {
                compare = range.compareEndPoints('StartToEnd', range)
            } else {
                compare = 1
            }
        } else {
            compare = range.compareBoundaryPoints(range.START_TO_END, range)
        }
        var el = this.getParentElement();
        if (el.tagName.toLowerCase() == 'img' && el.className.match(XHTMLSuite.RE_XsMedia)) {
            return
        }
        if (compare === 0 && !XHTMLSuite.is_opera) {
            alert(XHTMLSuite.I18N.msg['You need to select some text before creating a link']);
            return
        }
        outparam = {
            i_href: '',
            i_title: '',
            i_class: '',
            i_target: '',
            i_accesskey: '',
            i_tabindex: '',
            i_rel: '',
            i_rev: '',
            i_content: this.exportHTML(this.getHTML()),
            i_css: this._createCssArray(_xs_editing_css_url)
        }
    } else {
        outparam = {
            i_href: XHTMLSuite.is_ie ? editor.stripBaseURL(link.href) : editor.stripBaseURL(link.getAttribute('href')),
            i_title: link.title,
            i_class: link.className,
            i_target: link.target,
            i_accesskey: link.accessKey.toLowerCase(),
            i_tabindex: link.tabIndex > 0 ? link.tabIndex : '',
            i_rel: link.rel,
            i_rev: link.rev,
            i_content: this.exportHTML(this.getHTML()),
            i_css: this._createCssArray(_xs_editing_css_url)
        }
    };
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=createlink', function (param) {
        if (!param) {
            return false
        }
        var a = link;
        if (!a) {
            try {
                var tmp = XHTMLSuite.uniq('http://www.example.com/Link');
                editor._doc.execCommand('createlink', false, tmp);
                var anchors = editor._doc.getElementsByTagName('a');
                for (var i = 0; i < anchors.length; i++) {
                    var anchor = anchors[i];
                    if (anchor.href == tmp) {
                        if (!a) a = anchor;
                        anchor.href = param.f_href;
                        if (param.f_target) anchor.target = param.f_target;
                        if (param.f_title) anchor.title = param.f_title
                    }
                }
            } catch (ex) {}
        } else {
            var href = param.i_href.trim();
            editor.selectNodeContents(a);
            if (href === '') {
                editor._doc.execCommand('unlink', false, null);
                editor.updateToolbar();
                return false
            } else {
                a.href = href
            }
        }
        if (!(a && a.tagName.toLowerCase() == 'a')) {
            return false
        }
        a.href = param.i_href.trim();
        a.className = param.i_class.trim();
        a.target = param.i_target.trim();
        a.title = param.i_title.trim();
        a.accessKey = param.i_accesskey.trim().toLowerCase();
        if (param.i_tabindex !== '' && param.i_tabindex != -1) {
            a.tabIndex = parseInt(param.i_tabindex, 10)
        }
        a.rel = param.i_rel.trim();
        a.rev = param.i_rev.trim();
        editor.updateToolbar()
    }, outparam)
};
XHTMLSuite.prototype._insertDate = function () {
    var d = new Date();
    this.insertHTML(d.toLocaleDateString())
};
XHTMLSuite.prototype._insertTime = function () {
    var d = new Date();
    this.insertHTML(d.toLocaleTimeString())
};
XHTMLSuite.prototype._insertTemplate = function () {
    var editor = this;
    var sel = this._getSelection();
    var range = this._createRange(sel);
    this._popupDialog2('index2.php?option=com_xhtmlsuite&no_html=1&task=insert_template', function (param) {
        if (!param) {
            return false
        }
        var fileContent = param.i_filecontent;
        param.i_replaceall ? editor.setHTML(fileContent) : editor.insertHTML(fileContent)
    }, null)
};
XHTMLSuite.prototype._insertTable = function (callFromQuickTable) {
    var editor = this;
    var sel = this._getSelection();
    var range = this._createRange(sel);
    var doc = this._doc;
    var RE_blockElements = new RegExp(/(h[1-6]|pre|p|address|hr)/gi);
    var parent = this.getParentElement();
    var tag = parent.tagName.toLowerCase();
    if (this.config.showQuickTableDialog && !callFromQuickTable) {
        this._showQuickTableDialog('inserttable');
        return false
    }
    this._popupDialog('insert_table.php', function (param) {
        if (!param) {
            return false
        }
        var table = doc.createElement('table');
        for (var field in param) {
            var value = param[field];
            if (!value) {
                continue
            }
            switch (field) {
            case 'f_width':
                table.width = value + param.f_unit;
                break;
            case 'f_align':
                table.align = value;
                break;
            case 'f_border':
                table.border = parseInt(value, 10);
                break;
            case 'f_spacing':
                table.cellSpacing = parseInt(value, 10);
                break;
            case 'f_padding':
                table.cellPadding = parseInt(value, 10);
                break;
            case 'f_caption':
                var caption = doc.createElement('caption');
                var captionText = doc.createTextNode(value);
                caption.appendChild(captionText);
                table.appendChild(caption);
                break;
            case 'f_summary':
                table.summary = value;
                break
            }
        }
        var cellwidth = 0;
        if (table.border == '0') {
            XHTMLSuite._addClasses(table, 'xs_tbb')
        }
        if (param.f_fixed) {
            cellwidth = Math.floor(100 / parseInt(param.f_cols, 10))
        }
        if (param.f_headers) {
            var thead = doc.createElement('thead');
            table.appendChild(thead);
            var tr1 = doc.createElement('tr');
            thead.appendChild(tr1);
            for (var j = 0; j < param.f_cols; ++j) {
                var th = doc.createElement('th');
                for (var fields in param) {
                    var values = param[fields];
                    if (!values) {
                        continue
                    }
                    switch (fields) {
                    case 'f_halign':
                        th.align = values;
                        break;
                    case 'f_valign_top':
                        th.vAlign = 'top';
                        break
                    }
                }
                if (cellwidth) {
                    th.width = cellwidth + '%'
                }
                tr1.appendChild(th);
                th.appendChild(doc.createTextNode('\xa0'))
            }
        }
        var tbody = doc.createElement('tbody');
        table.appendChild(tbody);
        k = param.f_headers ? 1 : 0;
        for (var i = k; i < param.f_rows; ++i) {
            var tr2 = doc.createElement('tr');
            tbody.appendChild(tr2);
            for (var l = 0; l < param.f_cols; ++l) {
                var td = doc.createElement('td');
                for (var fields in param) {
                    var values = param[fields];
                    if (!values) {
                        continue
                    }
                    switch (fields) {
                    case 'f_halign':
                        td.align = values;
                        break;
                    case 'f_valign_top':
                        td.vAlign = 'top';
                        break
                    }
                }
                if (cellwidth) {
                    td.width = cellwidth + '%'
                }
                tr2.appendChild(td);
                td.appendChild(doc.createTextNode('\xa0'))
            }
        }
        if (tag.match(RE_blockElements)) {
            editor.removeParentTag(parent)
        }
        editor.focusEditor();
        editor.insertNodeAtSelection(table);
        return true
    }, null)
};
XHTMLSuite.prototype._toggleBorders = function () {
    var tables = this._doc.getElementsByTagName('TABLE');
    if (tables.length !== 0) {
        if (!this.borders) {
            name = 'bordered';
            this.borders = true
        } else {
            name = '';
            this.borders = false
        }
        for (var ix = 0; ix < tables.length; ix++) {
            if (this.borders) {
                XHTMLSuite._addClasses(tables[ix], 'xs_tbb')
            } else {
                XHTMLSuite._removeClass(tables[ix], 'xs_tbb')
            }
        }
    }
    return true
};
XHTMLSuite._postback = function (url, data, handler) {
    var req = null;
    if (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_7 && !XHTMLSuite.is_safari) {
        try {
            req = new ActiveXObject('Microsoft.XMLHTTP')
        } catch (ex) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    } else {
        try {
            req = new XMLHttpRequest()
        } catch (ex1) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    }
    var content = '';
    if (typeof data == 'string') {
        content = data
    } else if (typeof data == 'object') {
        for (var i in data) {
            content += (content.length ? '&' : '') + i + '=' + encodeURIComponent(data[i])
        }
    }
    function callBack() {
        if (req.readyState == 4) {
            try {
                if (typeof handler == 'function') {
                    handler(req.responseText, req)
                }
            } catch (ex2) {
                alert('An error has occurred: ' + req.statusText + '\nURL: ' + url)
            }
        }
    }
    try {
        req.onreadystatechange = callBack;
        req.open('POST', url, true);
        req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
        req.send(content)
    } catch (ex3) {
        alert(ex3)
    }
};
XHTMLSuite._getback = function (url, handler) {
    var req = null;
    if (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_7 && !XHTMLSuite.is_safari) {
        try {
            req = new ActiveXObject('Microsoft.XMLHTTP')
        } catch (ex) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    } else {
        try {
            req = new XMLHttpRequest()
        } catch (ex1) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    }
    function callBack() {
        if (req.readyState == 4) {
            try {
                if (req.status == 200) {
                    handler(req.responseText, req)
                } else {
                    alert('An error has occurred: ' + req.statusText + '\nURL: ' + url)
                }
            } catch (ex2) {}
        }
    }
    try {
        req.onreadystatechange = callBack;
        req.open('GET', url, true);
        req.send(null)
    } catch (ex3) {
        alert(ex3)
    }
};
XHTMLSuite._geturlcontent = function (url) {
    var req = null;
    if (XHTMLSuite.is_ie && !XHTMLSuite.is_ie_7 && !XHTMLSuite.is_safari) {
        try {
            req = new ActiveXObject('Microsoft.XMLHTTP')
        } catch (ex) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    } else {
        try {
            req = new XMLHttpRequest()
        } catch (ex1) {
            alert('XHTMLSuite ' + ex + ':\nFailed to establish XMLHTTP connection to server.\n\nPlease check security settings of your browser.\nActiveX (secure for scripting) must be enabled for this feature.\nAfter you have changed settings, please reload this page.')
        }
    }
    try {
        req.open('GET', url, false);
        req.send(null)
    } catch (ex2) {
        alert(ex2)
    }
    try {
        if (req.status == 200) {
            return req.responseText
        } else {
            return ''
        }
    } catch (ex3) {
        return ''
    }
};
XHTMLSuite._loadback = function (Url, callback) {
    var head = document.getElementsByTagName('head')[0];
    var evt = XHTMLSuite.is_ie ? 'onreadystatechange' : 'onload';
    var script = document.createElement('script');
    script.type = 'text/javascript';
    if (_editor_no_cache) {
        script.src = Url + '?ts=' + (new Date).getTime()
    } else {
        script.src = Url
    }
    script.charset = 'utf-8';
    script[evt] = function () {
        if ((XHTMLSuite.is_ie) && (!/loaded|complete/.test(window.event.srcElement.readyState))) {
            return
        }
        callback();
        script[evt] = null
    };
    head.appendChild(script)
};
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function (needle, fromIndex) {
        if (!fromIndex) {
            fromIndex = 0
        } else if (fromIndex < 0) {
            fromIndex = Math.max(0, this.length + fromIndex)
        }
        for (var i = fromIndex, ilen = this.length; i < ilen; i++) {
            if (this[i] === needle) {
                return i
            }
        }
        return -1
    }
}
if (!Array.prototype.append) {
    Array.prototype.append = function (a) {
        for (var i = 0; i < a.length; i++) {
            this.push(a[i])
        }
        return this
    }
}
if (!Array.prototype.contains) {
    Array.prototype.contains = function (needle) {
        return this.indexOf(needle) != -1
    }
}
XHTMLSuite.arrayContainsArray = function (a1, a2) {
    var all_found = true;
    for (var x = 0; x < a2.length; x++) {
        var found = false;
        for (var i = 0; i < a1.length; i++) {
            if (a1[i] == a2[x]) {
                found = true;
                break
            }
        }
        if (!found) {
            all_found = false;
            break
        }
    }
    return all_found
};
XHTMLSuite.arrayFilter = function (a1, filterfn) {
    var new_a = [];
    for (var x = 0; x < a1.length; x++) {
        if (filterfn(a1[x])) {
            new_a[new_a.length] = a1[x]
        }
    }
    return new_a
};
XHTMLSuite.collectionToArray = function (collection) {
    var array = [];
    for (var i = 0; i < collection.length; i++) {
        array.push(collection.item(i))
    }
    return array
};
XHTMLSuite.uniq_count = 0;
XHTMLSuite.uniq = function (prefix) {
    return prefix + XHTMLSuite.uniq_count++
};
XHTMLSuite.prototype.convertNode = function (el, newTagName) {
    var newel = this._doc.createElement(newTagName);
    while (el.firstChild) {
        newel.appendChild(el.firstChild)
    }
    return newel
};
XHTMLSuite.getEditorInstance = function (ref) {
    for (var i = __xhtmlsuites.length; i--;) {
        var editor = __xhtmlsuites[i];
        if (editor && (editor._textArea.id == ref || editor._textArea.name == ref || editor._textArea == ref)) {
            return editor
        }
    }
    return null
};
XHTMLSuite.prototype._comboSelected = function (el, txt) {
    this.focusEditor();
    var parent = this.getParentElement();
    var parentTag = parent.tagName.toLowerCase();
    var RE_formatBlockContent = new RegExp(/(p|h[1-6]|pre|address)/gi);
    var value = el.options[el.selectedIndex].value;
    switch (txt) {
    case 'fontname':
    case 'fontsize':
        var fontAttribs = txt.split('font');
        var toRemove = fontAttribs[1];
        if (toRemove == 'name') {
            toRemove = 'face'
        }
        if (value === '' && parentTag == 'font') {
            parent.removeAttribute(toRemove);
            if ((parent.getAttribute('size') === null && parent.getAttribute('face') === null && parent.getAttribute('color') === null) || (parent.getAttribute('size') === '' && parent.getAttribute('face') === '' && parent.getAttribute('color') === '')) {
                try {
                    this.removeParentTag(parent)
                } catch (ex) {}
                this.updateToolbar()
            }
        } else {
            this.execCommand(txt, false, value)
        }
        break;
    case 'formatblock':
        if (typeof parent != 'undefined' && value === '' && parentTag.match(RE_formatBlockContent) && parentTag != 'span') {
            try {
                this.removeParentTag(parent)
            } catch (ex1) {}
            this.updateToolbar()
        } else {
            if (XHTMLSuite.is_ie || XHTMLSuite.is_safari) {
                value = '<' + value + '>'
            }
            this.execCommand(txt, false, value)
        }
        break;
    default:
        var dropdown = this.config.customSelects[txt];
        if (typeof dropdown != 'undefined') {
            dropdown.action(this)
        }
        break
    }
};
XHTMLSuite.prototype._toggleTextCase = function (state) {
    var sel = this._getSelection();
    var range = this._createRange(sel);
    var current = null;
    if (XHTMLSuite.is_ie) {
        current = this.cloneContents();
        current = current.innerHTML
    } else {
        var clonedSelection = this.cloneContents();
        var div = this._doc.createElement('div');
        div.appendChild(clonedSelection);
        current = div.innerHTML;
        XHTMLSuite.removeFromParent(div)
    }
    if (current.indexOf('<td') > -1) {
        return
    }
    switch (state) {
    case 'uppercase':
        current = current.toUpperCase();
        break;
    case 'lowercase':
        current = current.toLowerCase();
        break
    }
    current = current.replace(/&NBSP;/gi, '&nbsp;');
    if (XHTMLSuite.is_ie) {
        range.select()
    } else {
        range.deleteContents()
    }
    this.insertHTML(current)
};
XHTMLSuite.prototype.execCommand = function (cmdID, UI, param) {
    this.focusEditor();
    cmdID = cmdID.toLowerCase();
    if (XHTMLSuite.is_gecko) {
        try {
            this._doc.execCommand('styleWithCSS', false, false)
        } catch (ex) {}
    }
    switch (cmdID) {
    case 'htmlmode':
        if (this.config.syntaxHighlighting) {
            this._setMarkupSelection()
        }
        this._currentlyActiveElement = '';
        this.toggleMode();
        break;
    case 'uppercasetext':
        this._toggleTextCase('uppercase');
        break;
    case 'lowercasetext':
        this._toggleTextCase('lowercase');
        break;
    case 'hilitecolor':
    case 'forecolor':
        this._setColor(cmdID);
        return false;
        break;
    case 'createlink':
        this._createLink();
        break;
    case 'fullscreenmode':
        _editor_fullscreen = true;
        this._fullScreen();
        break;
    case 'undo':
    case 'redo':
        this[cmdID]();
        break;
    case 'insertdate':
        this._insertDate();
        break;
    case 'inserttime':
        this._insertTime();
        break;
    case 'inserttable':
        this._insertTable();
        break;
    case 'inserttemplate':
        this._insertTemplate();
        break;
    case 'toggleborders':
        this._toggleBorders();
        break;
    case 'insertimage':
        this._insertImage();
        break;
    case 'insertmedia':
    case 'insertflash':
        this._insertMedia();
        break;
    case 'insertcharacter':
        this._insertCharacter();
        break;
    case 'insertfile':
        this._insertFile();
        break;
    case 'insertorderedlist':
    case 'insertunorderedlist':
        var parent = this.getParentElement();
        var tag = parent.tagName.toLowerCase();
        if (tag.match('div')) {
            if (!XHTMLSuite.is_safari) {
                this.removeParentTag(parent)
            }
        }
        this._doc.execCommand(cmdID, UI, param);
        break;
    case 'inserthorizontalrule':
        var RE_blockElements = new RegExp(/(h[1-6]|pre|p|address|hr)/gi);
        var parent = this.getParentElement();
        var tag = parent.tagName.toLowerCase();
        if (tag.match(RE_blockElements)) {
            this.removeParentTag(parent)
        }
        this._doc.execCommand(cmdID, UI, param);
        break;
    case 'removeformat':
        this._removeFormat();
        break;
    case 'preview':
        this._preview();
        break;
    case 'savedocument':
        if (typeof submitbutton == 'function') {
            submitbutton('save')
        } else {
            try {
                this._textArea.form.submit()
            } catch (ex1) {}
        }
        break;
    case 'accessibilitycheck':
        this._accessibilitycheck();
        break;
    case 'xsabbr':
        this._xsabbr();
        break;
    case 'xsacronym':
        this._xsacronym();
        break;
    case 'xsquote':
        this._xsquote();
        break;
    case 'tidycode':
        var html = this.getEditorContents();
        html = this._tidyCode(html);
        this.deactivateEditor();
        this.setHTML(this.importHTML(html));
        this.activateEditor();
        break;
    case 'about':
        this._popupDialog('about.html', null, this);
        break;
    case 'showhelp':
        this._helpDialog(null, this);
        break;
    case 'killword':
        this._wordClean();
        break;
    case 'cut':
    case 'copy':
    case 'paste':
        if (this._editMode == 'wysiwyg') {
            try {
                this._doc.execCommand(cmdID, UI, param);
                if (cmdID == 'paste') {
                    this.importHTML(this.getHTML())
                }
                if (this.config.killWordOnPaste) {
                    this._wordClean()
                }
            } catch (ex2) {
                if (XHTMLSuite.is_gecko && !XHTMLSuite.is_opera) {
                    if (confirm(XHTMLSuite.I18N.msg['Moz-Clipboard'])) {
                        var clipBoardHelper = window.open(this.config.clipBoardHelperUrl);
                        clipBoardHelper.focus()
                    }
                } else if (XHTMLSuite.is_opera) {
                    alert(XHTMLSuite.I18N.msg['Opera-Clipboard'])
                }
                return true
            }
        } else {
            if (this.config.syntaxHighlighting) {
                try {
                    this._sh_doc.execCommand(cmdID, UI, param)
                } catch (ex3) {
                    if (XHTMLSuite.is_gecko && !XHTMLSuite.is_opera) {
                        if (confirm(XHTMLSuite.I18N.msg['Moz-Clipboard'])) {
                            var clipBoardHelper = window.open(this.config.clipBoardHelperUrl);
                            clipBoardHelper.focus()
                        }
                    } else if (XHTMLSuite.is_opera) {
                        alert(XHTMLSuite.I18N.msg['Opera-Clipboard'])
                    }
                    return true
                }
            }
        }
        break;
    case 'lefttoright':
    case 'righttoleft':
        var dir = (cmdID == 'righttoleft') ? 'rtl' : 'ltr';
        var el = this.getParentElement();
        while (el && !XHTMLSuite.isBlockElement(el)) {
            el = el.parentNode
        }
        if (el) {
            if (el.style.direction == dir) {
                el.style.direction = ''
            } else {
                el.style.direction = dir
            }
        }
        break;
    case 'justifyleft':
    case 'justifyright':
        {
            var cmdIDMatch = new RegExp(/^justify(.*)$/);
            if (cmdID.match(cmdIDMatch)) {
                var activeElement = this._activeElement(this._getSelection());
                if (activeElement && (activeElement.tagName.toLowerCase() == 'img' || activeElement.tagName.toLowerCase() == 'td' || activeElement.tagName.toLowerCase() == 'tr' || activeElement.tagName.toLowerCase() == 'table')) {
                    activeElement.align = activeElement.align == RegExp.$1 ? '' : RegExp.$1
                } else {
                    this._doc.execCommand(cmdID, UI, param)
                }
            }
        }
        break;
    case 'syntaxhighlighting':
        this.SyntaxHighlighter();
        break;
    case 'togglewhitespace':
        this.toggleWhitespace();
        break;
    default:
        try {
            this._doc.execCommand(cmdID, UI, param)
        } catch (ex4) {}
        break
    }
    this.updateToolbar();
    return false
};
XHTMLSuite.prototype._editorEvent = function (ev) {
    var editor = this;
    var keyEvent = (XHTMLSuite.is_ie && ev.type == 'keydown') || (ev.type == 'keypress');
    if (typeof editor._textArea['on' + ev.type] == 'function') {
        editor._textArea['on' + ev.type](ev)
    }
    if (keyEvent) {
        for (var i in editor.extensions) {
            var extension = editor.extensions[i].instance;
            if (extension && typeof extension.onKeyPress == 'function') {
                if (extension.onKeyPress(ev)) {
                    return false
                }
            }
        }
    }
    if (keyEvent && ev.ctrlKey && !ev.altKey) {
        var sel = null;
        var range = null;
        var key = String.fromCharCode((XHTMLSuite.is_ie || XHTMLSuite.is_safari || XHTMLSuite.is_opera) ? ev.keyCode : ev.charCode).toLowerCase();
        var cmd = null;
        var value = null;
        switch (key) {
        case 'a':
            if (!XHTMLSuite.is_ie) {
                sel = this._getSelection();
                sel.removeAllRanges();
                range = this._createRange();
                range.selectNodeContents(this._doc.body);
                sel.addRange(range);
                XHTMLSuite._stopEvent(ev)
            }
            break;
        case 'b':
            cmd = 'bold';
            break;
        case 'i':
            cmd = 'italic';
            break;
        case 'u':
            cmd = 'underline';
            break;
        case 's':
            cmd = 'strikethrough';
            break;
        case 'l':
            cmd = 'justifyleft';
            break;
        case 'e':
            cmd = 'justifycenter';
            break;
        case 'r':
            cmd = 'justifyright';
            break;
        case 'j':
            cmd = 'justifyfull';
            break;
        case 'z':
            cmd = 'undo';
            break;
        case 'y':
            cmd = 'redo';
            break;
        case 'v':
            if (XHTMLSuite.is_ie) {
                cmd = 'paste'
            } else {
                if (this.config.killWordOnPaste) {
                    setTimeout(function () {
                        editor._wordClean()
                    }, 1)
                }
            }
            break;
        case '0':
            cmd = 'killword';
            break;
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
            cmd = 'formatblock';
            value = 'h' + key;
            if (XHTMLSuite.is_ie || XHTMLSuite.is_safari) {
                value = '<' + value + '>'
            }
            break
        }
        if (cmd) {
            this.execCommand(cmd, false, value);
            XHTMLSuite._stopEvent(ev)
        }
    } else if (keyEvent) {
        switch (ev.keyCode) {
        case 13:
            var selNode = editor.getParentElement();
            var dl = editor.getNearestParentOfType(selNode, 'dl');
            var parent = selNode.tagName.toLowerCase();
            var RE_make_DIV = /(html|body|dl|td|th|tr|thead|tbody|tfoot|p|pre|address)/gi;
            if (!dl) {
                if (XHTMLSuite.is_safari) {
                    if (this.config.useParagraph) {
                        if (ev.shiftKey === false) {
                            this.execCommand('formatblock', false, '<p>')
                        }
                    }
                }
                if (XHTMLSuite.is_ie) {
                    if (!this.config.useParagraph) {
                        if (parent.match(RE_make_DIV) && ev.shiftKey === false) {
                            this.execCommand('formatblock', false, '<div>')
                        }
                    }
                } else {
                    return
                }
            } else {
                if (typeof DefinitionList != 'undefined') {
                    DefinitionList.alias_buttonPress(editor, selNode);
                    XHTMLSuite._stopEvent(ev);
                    editor.updateToolbar()
                }
            }
            break;
        case 8:
        case 46:
            if (XHTMLSuite.is_gecko) {
                if (!ev.shiftKey && this.dom_checkBackspace()) {
                    XHTMLSuite._stopEvent(ev)
                }
            } else if (XHTMLSuite.is_ie) {
                if (this.ie_checkBackspace()) {
                    XHTMLSuite._stopEvent(ev);
                    return true
                }
            }
            break;
        case 9:
            editor.execCommand((ev.shiftKey ? 'outdent' : 'indent'), false, null);
            XHTMLSuite._stopEvent(ev);
            break;
        case 27:
            if (editor._isFullScreen) {
                editor.execCommand('fullscreenmode')
            }
            break;
        case 123:
            if (ev.shiftKey) {
                editor.execCommand('fullscreenmode')
            }
            break
        }
    }
    if (editor._timerToolbar) {
        clearTimeout(editor._timerToolbar)
    }
    editor._timerToolbar = setTimeout(function () {
        editor.updateToolbar();
        editor._timerToolbar = null
    }, 250);
    return true
};
XHTMLSuite.prototype.getNearestParentOfType = function (node, type) {
    type = type.toLowerCase();
    while (node) {
        if (node.nodeName.toLowerCase() == type) {
            return node
        }
        node = node.parentNode
    }
    return false
};
XHTMLSuite.checkSupportedBrowser = function (textareaID) {
    var supported = true;
    if (XHTMLSuite.is_gecko && !XHTMLSuite.is_safari && !XHTMLSuite.is_opera) {
        if (navigator.productSub < 20030210) {
            supported = false
        }
    }
    if (XHTMLSuite.is_safari && XHTMLSuite.safari_version < 522) {
        alert('Sorry, Safari prior version 3.0 is not supported by XHTMLSuite.');
        supported = false
    }
    if (XHTMLSuite.is_opera && XHTMLSuite.opera_version < 9.1) {
        alert('Sorry, Opera prior version 9.5 is not supported by XHTMLSuite.');
        supported = false
    }
    if (!supported) {
        try {
            var elt = document.getElementById('xs_dialog_container_' + textareaID);
            var elt2 = document.getElementById('xs_container_fulltext');
            if (typeof elt !== null && typeof elt != 'undefined') {
                elt.style.display = 'none'
            }
            if (typeof elt2 !== null && typeof elt2 != 'undefined') {
                elt2.style.display = ''
            }
        } catch (ex) {}
        return
    } else {
        return XHTMLSuite.is_ie || XHTMLSuite.is_designMode || XHTMLSuite.is_safari
    }
};
XHTMLSuite.prototype.notifyOf = function (ev, args) {
    if (this._notifyListeners[ev]) {
        for (var i = 0; i < this._notifyListeners[ev].length; i++) {
            this._notifyListeners[ev][i](ev, args)
        }
    }
};
XHTMLSuite.prototype.addEditorStylesheet = function (stylesheet, doc) {
    if (!doc) {
        doc = this._doc
    } else {
        doc = doc
    }
    var style = doc.createElement('link');
    style.rel = 'stylesheet';
    style.type = 'text/css';
    style.title = 'XHTMLSuiteInternalCSS';
    style.href = stylesheet;
    doc.getElementsByTagName('HEAD')[0].appendChild(style)
};
XHTMLSuite._removeClass = function (el, className) {
    if (!(el && el.className)) {
        return
    }
    var cls = el.className.split(' ');
    var ar = [];
    for (var i = cls.length; i > 0;) {
        if (cls[--i] != className) {
            ar[ar.length] = cls[i]
        }
    }
    el.className = ar.join(' ')
};
XHTMLSuite._addClass = function (el, className) {
    XHTMLSuite._removeClass(el, className);
    el.className += ' ' + className
};
XHTMLSuite._addClasses = function (el, classes) {
    if (el !== null) {
        var appliedClasses = el.className.trim().split(' ');
        var classesToApply = classes.split(' ');
        for (var x = 0; x < classesToApply.length; x++) {
            var exists = false;
            for (var i = 0; exists === false && i < appliedClasses.length; i++) {
                if (appliedClasses == classesToApply[x]) {
                    exists = true
                }
            }
            if (exists === false) {
                appliedClasses[appliedClasses.length] = classesToApply[x]
            }
        }
        el.className = appliedClasses.join(' ').trim()
    }
};
XHTMLSuite._blockTags = ' body p form textarea fieldset dl dt dd ul ol li legend div p hr h1 h2 h3 h4 h5 h6 quote pre table thead tbody tfoot colgroup rowgroup tr td th iframe address blockquote q cite object ';
XHTMLSuite.isBlockElement = function (el) {
    return el && el.nodeType == 1 && (XHTMLSuite._blockTags.indexOf(' ' + el.tagName.toLowerCase() + ' ') != -1)
};
XHTMLSuite.prototype._tidyCode = function (html) {
    if (XHTMLSuite.is_gecko) {
        html = html.replace(/((\s|\n|\r|\t)*)<br([\s]\/)?>((\s|\n|\r|\t)*)((&nbsp;|\s|\n|\r|\t)*)<\/(.*?)>/g, '</$8>')
    }
    html = html.replace(/\s(col|row)span="1"/g, '');
    html = html.replace(/\sclass=\"(xs_active_element|xs_active_element_RS|xs_active_element_RE)\"/g, '');
    html = html.replace(/> \n/g, '>\n');
    html = html.replace(/<(address|blockquote|h[1-6]|ol|pre|ul)([^>]*?)>((\s|\n|\r|\t)*)<\/(address|blockquote|h[1-6]|ol|pre|ul)>/g, '');
    html = html.replace(/<p([^>]*?)>((\s|\n|\r|\t)*)<\/p>/g, '<p>&nbsp;</p>');
    html = html.replace(/<(dd|dt)*>&nbsp;(.*?)/g, '<$1>$2');
    html = html.replace(/<(font|span)>((.|\n|\r|\t)*?)<\/(font|span)>/g, '$2');
    if (html.match(/<span class="xs_selection"><\/span>/gi)) {
        html = html.replace(/<(font|li|dt|dd)([^>]*?)><\/(font|li|dt|dd)>/g, '')
    } else {
        html = html.replace(/<(font|li|dt|dd)([^>]*?)><\/(font|li|dt|dd)>/g, '')
    }
    html = html.replace(/<(address|h[1-6]|p|pre)([^>]*?)>((&nbsp;|\s|\n|\r|\t)*)<table([^>]*?)>((.|\n|\r|\t)*?)<\/table>((&nbsp;|\s|\n|\r|\t)*)<\/(address|h[1-6]|p|pre)>/g, '<table$5>$6</table>\n<br />');
    html = html.replace(/<(address|h[1-6]|p|pre)([^>]*?)>((\n|\s|\r|\t)*)<hr([^>]*?)(\s)\/><\/(address|h[1-6]|p|pre)>/g, '<hr$4/>');
    return html
};
XHTMLSuite.prototype.getHTML = function () {
    var html = '';
    switch (this._editMode) {
    case 'wysiwyg':
        html = XHTMLSuite.getHTML(this._doc.body, this).trim();
        break;
    case 'textmode':
        if (!this.config.syntaxHighlighting) {
            html = this._textArea.value
        } else {
            html = XHTMLSuite.getHTML(this._sh_doc.body, this).trim()
        }
        break;
    default:
        alert('Mode <' + mode + '> not defined!');
        return false;
        break
    }
    return html
};
XHTMLSuite.prototype.setHTML = function (html) {
    if (this._doc !== null) {
        this._doc.body.innerHTML = html
    }
    this._textArea.value = html;
    if (this.config.syntaxHighlighting && this._sh_doc !== null) {
        if (XHTMLSuite.is_ie) {
            html = '<pre class="xs_IE_NoWrap">' + html + '</pre>'
        }
        this._sh_doc.body.innerHTML = html
    }
};
XHTMLSuite.prototype.getInnerHTML = function () {
    if (!this._doc.body) {
        return ''
    }
    var html = '';
    switch (this._editMode) {
    case 'wysiwyg':
        try {
            html = this._doc.body.innerHTML
        } catch (ex) {}
        break;
    case 'textmode':
        html = this._textArea.value;
        break;
    default:
        alert('Mode <' + this._editMode + '> not defined!');
        return false;
        break
    }
    return html
};
XHTMLSuite.prototype.importHTML = function (html) {
    if (this.config.removeScripts) {
        html = html.replace(/\n?<script(\s|[^\s])*?<\/script>\n?/gi, '')
    }
    html = html.replace(/<(\/?)noscript>/gi, '<$1xs_noscript>');
    html = html.replace(/(on(click|dblclick|blur|focus|mouseover|mouseout|mousemove|mousedown|mouseup|keypress|keydown|keyup|change|submit|reset|focus|select|unload)=\")/gi, 'xs_on$2="');
    html = this.importSR(html);
    html = html.replace(/<a name="(.*?)" ([^>]*)>/gi, '<a name="$1" id="$1" $2 class="xs_anchor">');
    html = html.replace(/<a title="(.*?)" name="(.*?)" ([^>]*)>/gi, '<a name="$1" id="$1" $2 class="xs_anchor">');
    html = html.replace(/<a href="(.*?)" name="(.*?)" ([^>]*)>/gi, '<a href="$1" name="$2" id="$2" $3 class="xs_anchor">');
    html = html.replace(/<a id="(.*?)" name="(.*?)">/gi, '<a id="$1" name="$1" class="xs_anchor">');
    html = html.replace(/<a id="(.*?)" name="(.*?)" title="(.*?)">/gi, '<a id="$1" name="$1" title="$3" class="xs_anchor">');
    html = html.replace(/<a id="(.*?)" title="(.*?)" name="(.*?)">/gi, '<a id="$1" name="$1" class="xs_anchor">');
    if (XHTMLSuite.is_ie) {
        html = html.replace(/(<script|<style|<!--)/gi, '&nbsp;$1')
    }
    if (XHTMLSuite.is_gecko) {
        html = html.replace(/<(\/?)strong(\s|>|\/)/gi, '<$1b$2');
        html = html.replace(/<(\/?)em(\s|>|\/)/gi, '<$1i$2')
    }
    html = html.replace(/(\s)-moz(.*?): -moz(.*?);/gi, '');
    html = html.replace(/ <\//g, '</');
    html = html.replace(/<span style="font-weight: bold;">((.|\n|\r|\t)*?)<\/span>/gi, '<strong>$1</strong>');
    html = html.replace(/<span style="font-style: italic;">((.|\n|\r|\t)*?)<\/span>/gi, '<em>$1</em>');
    html = html.replace(/<span style="text-decoration: underline;">((.|\n|\r|\t)*?)<\/span>/gi, '<ins>$1</ins>');
    html = html.replace(/<span style="background-color:(.*?)">((.|\n|\r|\t)*?)<\/span>/gi, '<font style="background-color:$1">$2</font>');
    html = html.replace(/type=\"text\/javascript/gi, 'type="text/xs_script');
    html = html.replace(/<t(d|h)([^>]*)><\/t(d|h)>/gi, '<t$1$2>&nbsp;</t$1>');
    html = html.replace(/<t(d|h)([^>]*)>(\s|<br([\s]\/)?>)<\/t(d|h)>/gi, '<t$1$2>&nbsp;</t$1>');
    html = html.replace(/<(\/?)ins(\s|>|\/)/gi, '<$1u$2');
    html = html.replace(/<(\/?)del(\s|>|\/)/gi, '<$1strike$2');
    html = this.fixPaths(html);
    html = this.importMediaHTML(html);
    return html
};
XHTMLSuite.prototype.importSR = function (html) {
    for (var i in this.config.specialReplacements) {
        var from = i;
        var to = this.config.specialReplacements[i];
        if (typeof from.replace != 'function' || typeof to.replace != 'function') {
            continue
        }
        var reg = new RegExp(from.replace(XHTMLSuite.RE_Specials, '\\$1'), 'g');
        html = html.replace(reg, to.replace(/\$/g, '$$$$'))
    }
    return html
};
XHTMLSuite.prototype.exportHTML = function (html) {
    if (this.config.removeScripts) {
        html = html.replace(/\n?<script(\s|[^\s])*?<\/script>\n?/gi, '')
    }
    if (XHTMLSuite.is_ie) {
        html = html.replace(/&nbsp;(\s*)(<script|<style|<!--)/gi, '$1$2');
        html = html.replace(/ dir=\"(ltr|rtl)\" style=\"margin-right: 0px\"/gi, '')
    }
    if (XHTMLSuite.is_gecko && !XHTMLSuite.is_opera) {
        html = html.replace(/<script[\s]*src[\s]*=[\s]*['"]chrome:\/\/.*?["']>[\s]*<\/script>/gi, '');
        html = html.replace(/<hr size="2" width="100%" \/>/gi, '<hr />')
    }
    if (XHTMLSuite.is_safari) {
        html = html.replace(/ class="(webkit-block-placeholder|webkit-indent-blockquote|Apple-style-span)"/gi, '');
        html = html.replace(/ style="-webkit-(.*?)"/gi, '');
        html = html.replace(/<br([\s]\/)?><\/p>/gi, '&nbsp;</p>')
    }
    html = html.replace(/<(\/?)xs_noscript>/gi, '<$1noscript>');
    html = html.replace(/(xs_on(click|dblclick|blur|focus|mouseover|mouseout|mousemove|mousedown|mouseup|keypress|keydown|keyup|change|submit|reset|focus|select|unload)=\")/gi, 'on$2="');
    html = html.replace(/<\/(script|style)>/gi, '</$1>\n');
    html = html.replace(/(\s)-moz(.*?): -moz(.*?);/gi, '');
    html = html.replace(/(class="xstbb"|class="xstbb xs_tbb")/gi, 'class="xs_tbb"');
    html = html.replace(/ class="xs_anchor"/gi, '');
    html = html.replace(/\n\n*/gi, '\n');
    html = html.replace(/xs_script/gi, 'javascript');
    html = html.replace(/<(\/?)b(\s|>|\/)/gi, '<$1strong$2');
    html = html.replace(/<(\/?)i(\s|>|\/)/gi, '<$1em$2');
    html = html.replace(/<(\/?)u(\s|>|\/)/gi, '<$1ins$2');
    html = html.replace(/<(\/?)strike(\s|>|\/)/gi, '<$1del$2');
    html = html.replace(/<p>[\s|\n|\r]*<br([\s]\/)?>&nbsp;<\/p>/gi, '<p>&nbsp;</p>');
    html = html.replace(/<\/li>[\s|\n|\r]*<(ol|ul?)([^>]*)>/gi, '\n   <$1$2>');
    html = html.replace(/<\/(ol|ul?)>[\s|\n|\r]*<li([^>]*)>/gi, '</$1></li><li$2>');
    html = this.exportSR(html);
    html = this.fixPaths(html);
    html = this.exportMediaHTML(html);
    if (this.config.sourceCodeFormatting) {
        html = this.codeFormatter(html)
    }
    if (this.config.numericalEntities) {
        html = html.replace(/[^ -~\r\n\t]/g, function (char) {
            return '&#' + char.charCodeAt(0) + ';'
        })
    }
    return html
};
XHTMLSuite.prototype.exportSR = function (html) {
    for (var i in this.config.specialReplacements) {
        var from = this.config.specialReplacements[i];
        var to = i;
        if (typeof from.replace != 'function' || typeof to.replace != 'function') {
            continue
        }
        var reg = new RegExp(from.replace(XHTMLSuite.RE_Specials, '\\$1'), 'g');
        html = html.replace(reg, to.replace(/\$/g, '$$$$'))
    }
    return html
};
XHTMLSuite.prototype.fixPaths = function (html) {
    if (html === null) {
        return ''
    }
    var src = html.match(/(src|href)="([^"]*)"/gi);
    var b = document.location.href;
    if (src) {
        var url, url_m, relPath, base_m, absPath;
        for (var i = 0; i < src.length; ++i) {
            url = src[i].match(/(src|href)="([^"]*)"/i);
            url_m = url[2].match(/\.\.\//g);
            if (url_m) {
                relPath = new RegExp("(.*?)(([^\/]*\/){" + url_m.length + "})[^\/]*$");
                base_m = b.match(relPath);
                absPath = url[2].replace(/(\.\.\/)*/, base_m[1]);
                html = html.replace(new RegExp(XHTMLSuite.escapeStringForRegExp(url[2])), absPath);
                if (this.config.stripBaseURL) {
                    html = this.stripBaseURL(html)
                }
            }
        }
    }
    if (typeof this.config.stripBaseHref != 'undefined' && this.config.stripBaseHref) {
        var baseRe = null;
        if (typeof this.config.baseHref != 'undefined' && this.config.baseHref !== null) {
            baseRe = new RegExp("((href|src|background|action)=\")(" + XHTMLSuite.escapeStringForRegExp(this.config.baseHref.replace(/([^\/]\/)(?=.+\.)[^\/]*$/, "$1")) + ")", 'g');
            html = html.replace(baseRe, '$1')
        }
        baseRe = new RegExp("((href|src|background|action)=\")(" + XHTMLSuite.escapeStringForRegExp(document.location.href.replace(/^(https?:\/\/[^\/]*)(.*)/, '$1')) + ")", 'g');
        html = html.replace(baseRe, '$1')
    }
    return html
};
XHTMLSuite.getHTML = function (root, editor) {
    var html = '';
    var c = XHTMLSuite.HTMLRegExpCache;
    if (root.nodeType == 11) {
        var div = document.createElement('div');
        var temp = root.insertBefore(div, root.firstChild);
        for (var j = temp.nextSibling; j; j = j.nextSibling) {
            temp.appendChild(j.cloneNode(true))
        }
        html += temp.innerHTML.replace(c[24], function (strn) {
            strn = strn.replace(c[23], function (tag) {
                if (/^<[!\?]/.test(tag)) {
                    return tag
                } else {
                    return editor.HTMLParser(tag)
                }
            });
            return strn
        })
    } else {
        var root_tag = (root.nodeType == 1) ? root.tagName.toLowerCase() : '';
        if (root_tag == 'html') {
            innerhtml = editor._doc.documentElement.innerHTML
        } else {
            innerhtml = root.innerHTML
        }
        if (editor.config.syntaxHighlighting && editor._editMode == 'textmode') {
            innerhtml = editor.getSyntaxHighlighterHTML(innerhtml)
        }
        html += innerhtml.replace(c[24], function (strn) {
            strn = strn.replace(c[23], function (tag) {
                if (/^<[!\?]/.test(tag)) {
                    return tag
                } else if (!(editor.config.htmlRemoveTags && editor.config.htmlRemoveTags.test(tag.replace(/<([^\s>\/]+)/, '$1')))) {
                    return editor.HTMLParser(tag)
                } else {
                    return ''
                }
            });
            return strn
        });
        html = html.replace(/<(li|dd|dt)( [^>]*)?>/g, '</$1><$1$2>').replace(/(<[uod]l[^>]*>[\s\S]*?)<\/(li|dd|dt)>/g, '$1').replace(/\s*<\/(li|dd|dt)>(\s*<\/(li|dd|dt)>)+/g, '</$1>').replace(/(<dt[\s>][\s\S]*?)(<\/d[dt]>)+/g, '$1</dt>');
        if (XHTMLSuite.is_gecko) {
            html = html.replace(/(<br>|<br \/>)\n$/, '').replace(/(.*)(<br>|<br \/>)$/, '$1')
        }
        if (editor.config.sourceCodeFormatting) {
            html = editor.codeFormatter(html)
        }
        html = editor._tidyCode(html);
        if (!editor.config.disableSpecialCharEncoding && !editor.config.numericalEntities) {
            html = editor.htmlEncode(html)
        }
    }
    html = html.replace(c[24], function (strn) {
        strn = strn.replace(/(^|>)(\s|[^\s])*?(<|$)/g, function (string) {
            string = string.replace(/"/g, '&quot;');
            return string
        });
        return strn
    });
    return html
};
XHTMLSuite.prototype.getEditorContents = function () {
    return this.exportHTML(this.getHTML())
};
XHTMLSuite.HTMLRegExpCache = [new RegExp(/<\s*\/?([^\s\/>]+)[\s*\/>]/gi), new RegExp(/(\s+)_moz[^=>]*=[^\s>]*/gi), new RegExp(/\s*=\s*(([^'"][^>\s]*)([>\s])|"([^"]+)"|'([^']+)')/g), new RegExp(/\/>/g), new RegExp(/<(br|hr|img|input|link|meta|param|embed|area|col)((\s*\S*="[^"]*")*)>/g), new RegExp(/(<\w+\s+(\w*="[^"]*"\s+)*)(checked|compact|declare|defer|disabled|ismap|multiple|no(href|resize|shade|wrap)|readonly|selected)([\s>])/gi), new RegExp(/(="[^']*)'([^'"]*")/), new RegExp(/&(?=(?!(#[0-9]{2,5};|[a-zA-Z0-9]{2,6};|#x[0-9a-fA-F]{2,4};))[^<]*>)/g), new RegExp(/<\s+/g), new RegExp(/\s+(\/)?>/g), new RegExp(/\s{2,}/g), new RegExp(/\s+([^=\s]+)((="[^"]+")|([\s>]))/gi), new RegExp(/\s+contenteditable(=[^>\s\/]*)?/gi), new RegExp(/((background|href|src|action)=")([^\s]*)"/g), new RegExp(/<\/?(div|p|h[1-6]|table|caption|form|fieldset|legend|select|option|input|textarea|button|thead|tbody|tfoot|colgroup|rowgroup|tr|td|th|col|dl|dt|ul|ol|li|blockquote|object|map|br|hr|embed|param|pre|script|html|head|body|meta|link|title|area)[^>]*>/g), new RegExp(/<\/(div|table|thead|tbody|tfoot|colgroup|rowgroup|tr|form|fieldset|select|ul|ol|dl|blockquote|object|map|html|head|body|script)( [^>]*)?>/g), new RegExp(/<(div|p|h[1-6]|form|fieldset|legend|select|option|textarea|table|caption|thead|tbody|tfoot|colgroup|rowgroup|tr|td|th|dl|dt|dd|ul|ol|li|blockquote|object|map|html|head|body|script)( [^>]*)?>/g), new RegExp(/<(br|hr|embed|param|pre|meta|link|title|area|input|col)[^>]*>/g), new RegExp(/(^|<\/(noscript|pre|script|textarea|style)>)(\s|[^\s])*?(<(noscript|pre|script|textarea|style)[^>]*>|$)/g), new RegExp(/(<pre[^>]*>)([\s\S])*?(<\/pre>)/g), new RegExp(/(^|<!--[\s\S]*?-->)([\s\S]*?)(?=<!--[\s\S]*?-->|$)/g), new RegExp(/\S*=""/g), new RegExp(/<\/(div|p|h[1-6]|caption|td|th|dt|legend|li|option|input|textarea|object|map)( [^>]*)?>/g), new RegExp(/<!--[\s\S]*?-->|<\?[\s\S]*?\?>|<\/?\w[^>]*>/g), new RegExp(/(^|<\/(noscript|script|style)>)[\s\S]*?(<(noscript|script|style)[^>]*>|$)/g), new RegExp(/((src)=")([^\s]*)"/g)];
if (!XHTMLSuite.is_opera && !XHTMLSuite.is_safari && typeof RegExp.prototype.compile == 'function') {
    for (var i = 0; i < XHTMLSuite.HTMLRegExpCache.length; i++) {
        XHTMLSuite.HTMLRegExpCache[i] = new RegExp().compile(XHTMLSuite.HTMLRegExpCache[i])
    }
}
XHTMLSuite.prototype.HTMLParser = function (html) {
    var c = XHTMLSuite.HTMLRegExpCache;
    if (html === '' || typeof html == 'undefined') {
        html = ''
    }
    html = html.replace(c[0], function (str) {
        return str.toLowerCase()
    }).replace(c[1], ' ').replace(c[12], ' ').replace(c[2], '="$2$4$5"$3').replace(c[21], ' ').replace(c[11], function (str, p1, p2) {
        if (XHTMLSuite.is_ie && p1 == 'style') {
            return ' ' + p1.toLowerCase() + p2.toLowerCase()
        } else {
            return ' ' + p1.toLowerCase() + p2
        }
    }).replace(c[3], '>').replace(c[9], XHTMLSuite.is_netscape ? '>' : '$1>').replace(c[6], '$1$2').replace(c[7], '&amp;').replace(c[8], '<').replace(c[10], ' ');
    if (this.config.outputHTML401) {
        html = html.replace(c[5], '$1$3$5').replace(c[4], '<$1$2>')
    } else {
        html = html.replace(c[5], '$1$3="$3"$5').replace(c[4], '<$1$2 />')
    }
    if (c[13].test(html)) {
        html = html.replace(c[13], '$1' + XHTMLSuite._escapeDollars(this.stripBaseURL(RegExp.$3)) + '"')
    }
    if (XHTMLSuite.is_ie && c[25].test(html)) {
        html = html.replace(c[25], '$1' + this.stripBaseURL(RegExp.$3) + '"')
    }
    if (this.config.make7BitPrintableURLs) {
        if (XHTMLSuite.is_ie) c[13].test(html);
        if (c[13].test(html)) {
            try {
                html = html.replace(c[13], '$1' + decodeURIComponent(RegExp.$3).replace(/([^!-~]+)/g, function (chr) {
                    return escape(chr)
                }) + '"')
            } catch (ex) {
                html = html.replace(c[13], XHTMLSuite._escapeDollars('$1' + RegExp.$3.replace(/([^!-~]+)/g, function (chr) {
                    return escape(chr)
                }) + '"'))
            }
        }
    }
    return html
};
XHTMLSuite._escapeDollars = function (str) {
    return str.replace(/\$/g, "$$$$")
};
XHTMLSuite.prototype.codeFormatter = function (s) {
    XHTMLSuite.__nindent = 0;
    XHTMLSuite.__sindent = '';
    XHTMLSuite.__sindentChar = (!this.config.indentChar || typeof this.config.indentChar == 'undefined' || this.config.indentChar === '') ? '   ' : this.config.indentChar;
    var c = XHTMLSuite.HTMLRegExpCache;
    s = s.replace(c[19], function (str) {
        return str.replace(/<br([\s]\/)?>/g, '\n')
    });
    s = s.replace(c[19], function (str) {
        return str.replace(/&nbsp;/g, ' ')
    });
    s = s.replace(c[18], function (strn) {
        strn = strn.replace(c[20], function (st, $1, $2) {
            string = $2.replace(/[\n\r]/gi, ' ').replace(/\s+/gi, ' ').replace(c[14], function (str) {
                if (str.match(c[16])) {
                    s = '\n' + XHTMLSuite.__sindent + str;
                    XHTMLSuite.__sindent += XHTMLSuite.__sindentChar;
                    ++XHTMLSuite.__nindent;
                    return s
                } else if (str.match(c[15])) {
                    --XHTMLSuite.__nindent;
                    XHTMLSuite.__sindent = '';
                    for (var i = XHTMLSuite.__nindent; i > 0; --i) {
                        XHTMLSuite.__sindent += XHTMLSuite.__sindentChar
                    }
                    return '\n' + XHTMLSuite.__sindent + str
                } else if (str.match(c[22])) {
                    --XHTMLSuite.__nindent;
                    XHTMLSuite.__sindent = '';
                    for (var j = XHTMLSuite.__nindent; j > 0; --j) {
                        XHTMLSuite.__sindent += XHTMLSuite.__sindentChar
                    }
                    return str
                } else if (str.match(c[17])) {
                    return '\n' + XHTMLSuite.__sindent + str
                }
                return str
            });
            return $1 + string
        });
        return strn
    });
    s = s.replace(/^\s*/, '').replace(/ +\n/g, '\n').replace(/[\r\n]+(\s+)<\/script>/gi, '$1</script>');
    return s
};
XHTMLSuite.prototype.stripBaseURL = function (string) {
    var baseUrl = null;
    if (_xs_site_in_subdir) {
        baseUrl = _xs_site_in_subdir
    } else {
        baseUrl = this.config.baseURL
    }
    var adminUrl = this.config.adminURL;
    if (this.config.stripBaseURL) {
        baseUrl = baseUrl.replace(/\x2f*$/, '');
        var slash;
        if (!_xs_root_relative_urls) {
            slash = '/'
        } else {
            slash = ''
        }
        baseUrl = baseUrl + slash;
        if (string.indexOf(adminUrl) > -1) {
            baseUrl = baseUrl + '/' + adminUrl + slash
        }
        string = string.replace(baseUrl, '')
    }
    return string
};
String.prototype.trim = function () {
    return this.replace(/^\s+/, '').replace(/\s+$/, '')
};
XHTMLSuite._makeColor = function (v) {
    if (typeof v != 'number') {
        return v
    }
    var r = v & 0xFF;
    var g = (v >> 8) & 0xFF;
    var b = (v >> 16) & 0xFF;
    return 'rgb(' + r + ',' + g + ',' + b + ')'
};
XHTMLSuite._colorToRgb = function (v) {
    if (!v || v == 'none') {
        return ''
    }
    var r, g, b;

    function fr(d) {
        return (d < 16) ? ('0' + d.toString(16)) : d.toString(16)
    };
    if (typeof v == 'number') {
        r = v & 0xFF;
        g = (v >> 8) & 0xFF;
        b = (v >> 16) & 0xFF;
        return '#' + fr(r) + fr(g) + fr(b)
    }
    if (v.substr(0, 3) == 'rgb') {
        var re = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/;
        if (v.match(re)) {
            r = parseInt(RegExp.$1, 10);
            g = parseInt(RegExp.$2, 10);
            b = parseInt(RegExp.$3, 10);
            return '#' + fr(r) + fr(g) + fr(b)
        }
        return null
    }
    if (v.substr(0, 1) == '#') {
        return v
    }
    return null
};
XHTMLSuite.prototype._popupDialog = function (url, action, init) {
    new Dialog(this.popupURL(url), action, init)
};
XHTMLSuite.prototype._popupDialog2 = function (url, action, init) {
    new Dialog(this.popupURL2(url), action, init)
};
XHTMLSuite.prototype._helpDialog = function (action, init) {
    new Dialog(this.helpURL(), action, init)
};
XHTMLSuite.prototype.imgURL = function (file, extension) {
    if (typeof extension == 'undefined') {
        return _xs_editor_url + file
    } else {
        return _xs_editor_url + 'extensions/' + extension + '/img/' + file
    }
};
XHTMLSuite.prototype.popupURL = function (file) {
    var url = '';
    if (file.match(/^extension:\/\/(.*?)\/(.*)/)) {
        var extension = RegExp.$1;
        var popup = RegExp.$2;
        if (!/\.(html?|php)$/.test(popup)) {
            popup += '.html'
        }
        url = _xs_editor_url + 'extensions/' + extension + '/dialogs/' + popup
    } else {
        url = _xs_editor_url + this.config.popupURL + file
    }
    return url
};
XHTMLSuite.prototype.popupURL2 = function (file) {
    var url = '';
    url = _xs_site_url + '/' + this.config.popupURL2 + file;
    return url
};
XHTMLSuite.prototype.helpURL = function () {
    return this.config.helpURL
};
XHTMLSuite.getElementById = function (tag, id, doc) {
    if (typeof doc == 'undefined' || doc === null) {
        doc = document
    }
    var el, i, objs = doc.getElementsByTagName(tag);
    for (i = objs.length; --i >= 0 && (el = objs[i]);) {
        if (el.id == id) {
            return el
        }
    }
    return null
};
XHTMLSuite.removeFromParent = function (el) {
    if (typeof el.tagName == 'undefined') {
        return
    }
    if (!el.parentNode || typeof el.parentNode == 'undefined') {
        return
    }
    var pN = el.parentNode;
    return pN.removeChild(el)
};
XHTMLSuite._comboSelectValue = function (c, val) {
    var ops = c.getElementsByTagName('option');
    for (var i = ops.length; --i >= 0;) {
        var op = ops[i];
        op.selected = (op.value == val)
    }
    c.value = val
};
XHTMLSuite.getElementTopLeft = function (element) {
    var curleft = curtop = 0;
    if (element.offsetParent) {
        curleft = element.offsetLeft;
        curtop = element.offsetTop;
        while (element = element.offsetParent) {
            curleft += element.offsetLeft;
            curtop += element.offsetTop
        }
    }
    return {
        top: curtop,
        left: curleft
    }
};
XHTMLSuite.findPosX = function (obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        return XHTMLSuite.getElementTopLeft(obj).left
    } else if (obj.x) {
        curleft += obj.x
    }
    return curleft
};
XHTMLSuite.findPosY = function (obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        return XHTMLSuite.getElementTopLeft(obj).top
    } else if (obj.y) {
        curtop += obj.y
    }
    return curtop
};
XHTMLSuite.prototype.setLoadingMessage = function (string) {
    RE_editor_url = new RegExp(_xs_editor_url, 'gi');
    string = string.replace(RE_editor_url, '');
    string = string.replace('includes/api/', '');
    string = string.replace('includes/specific/', '');
    if (typeof XHTMLSuite.I18N.loading[string] != 'undefined') {
        string = XHTMLSuite.I18N.loading[string]
    }
    var elt = XHTMLSuite.getElementById('div', 'xs_dialog_' + this._textareaID);
    if (!elt) {
        return
    }
    elt.innerHTML = '<div style="text-align: center;"><span class="xs_loading_msg"><em><strong>XHTML</strong>Suite</em></span><br />' + string + '</div>'
};
XHTMLSuite.prototype.removeLoadingMessage = function () {
    var elt = XHTMLSuite.getElementById('div', 'xs_dialog_container_' + this._textareaID);
    if (!elt) {
        return
    }
    elt.style.display = 'none'
};
if (document.addEventListener) {
    XHTMLSuite._addEvent = function (el, evname, func, capture) {
        if (typeof (capture) == 'undefined') {
            capture = false
        }
        el.addEventListener(evname, func, false, capture);
        XHTMLSuite._eventFlushers.push([el, evname, func])
    };
    XHTMLSuite._removeEvent = function (el, evname, func) {
        el.removeEventListener(evname, func, false)
    };
    XHTMLSuite._stopEvent = function (ev) {
        try {
            ev.preventDefault();
            ev.stopPropagation()
        } catch (ex) {}
    }
} else if (document.attachEvent) {
    XHTMLSuite._addEvent = function (el, evname, func, capture) {
        if (typeof (capture) == 'undefined') {
            capture = false
        }
        el.attachEvent('on' + evname, func, capture);
        XHTMLSuite._eventFlushers.push([el, evname, func])
    };
    XHTMLSuite._removeEvent = function (el, evname, func) {
        el.detachEvent('on' + evname, func)
    };
    XHTMLSuite._stopEvent = function (ev) {
        try {
            ev.cancelBubble = true;
            ev.returnValue = false
        } catch (ex) {
            window.event.cancelBubble = true;
            window.event.returnValue = false
        }
    }
} else {
    XHTMLSuite._addEvent = function (el, evname, func) {
        alert('_addEvent is not supported')
    };
    XHTMLSuite._removeEvent = function (el, evname, func) {
        alert('_removeEvent is not supported')
    };
    XHTMLSuite._stopEvent = function (ev) {
        alert('_stopEvent is not supported')
    }
}
XHTMLSuite._addEvents = function (el, evs, func, useCapture) {
    if (typeof (useCapture) == 'undefined') {
        useCapture = false
    }
    for (var i = evs.length; --i >= 0;) {
        XHTMLSuite._addEvent(el, evs[i], func, useCapture)
    }
};
XHTMLSuite._removeEvents = function (el, evs, func) {
    for (var i = evs.length; --i >= 0;) {
        XHTMLSuite._removeEvent(el, evs[i], func)
    }
};
XHTMLSuite.aD0E = function (el, ev, fn) {
    XHTMLSuite._prepFD0E(el, ev);
    el._xsd0Es[ev].unshift(fn)
};
XHTMLSuite.aD0Es = function (el, evs, fn) {
    for (var i = evs.length; --i >= 0;) {
        XHTMLSuite._prepFD0E(el, evs[i]);
        el._xsd0Es[evs[i]].unshift(fn)
    }
};
XHTMLSuite.pD0E = function (el, ev, fn) {
    XHTMLSuite._prepFD0E(el, ev);
    el._xsd0Es[ev].push(fn)
};
XHTMLSuite._prepFD0E = function (el, ev) {
    if (typeof el._xsd0Es == 'undefined' || el._xsd0Es === null) {
        el._xsd0Es = {};
        XHTMLSuite.fL(el, '_xsd0Es')
    }
    if (typeof el._xsd0Es[ev] == 'undefined') {
        el._xsd0Es[ev] = [];
        if (typeof el['on' + ev] == 'function') {
            el._xsd0Es[ev].push(el['on' + ev])
        }
        el['on' + ev] = function (event) {
            var a = el._xsd0Es[ev];
            var allOK = true;
            for (var i = a.length; --i >= 0;) {
                el._xstEH = a[i];
                if (el._xstEH(event) === false) {
                    el._xstEH = null;
                    allOK = false;
                    break
                }
                el._xstEH = null
            }
            return allOK
        };
        XHTMLSuite._eventFlushers.push([el, ev])
    }
};
XHTMLSuite.flushEvents = function (dispose) {
    var x = 0;
    if (!dispose) {
        var ev = XHTMLSuite._eventFlushers.pop();
        while (ev) {
            try {
                if (ev.length == 3) {
                    XHTMLSuite._removeEvent(ev[0], ev[1], ev[2]);
                    x++
                } else if (ev.length == 2) {
                    ev[0]['on' + ev[1]] = null;
                    ev[0]._xsd0Es[ev[1]] = null;
                    x++
                }
            } catch (ex) {}
            ev = XHTMLSuite._eventFlushers.pop()
        }
    }
};
XHTMLSuite.fL = function (obj, prop) {
    if (prop && typeof prop !== 'string' && prop.length && prop.length > 0) {
        for (var i = prop.length; i--;) {
            XHTMLSuite.toFree.push({
                o: obj,
                p: prop[i]
            })
        }
    } else {
        XHTMLSuite.toFree.push({
            o: obj,
            p: prop
        })
    }
};
XHTMLSuite.free = function (obj, prop) {
    if (obj && !prop) {
        for (var p in obj) {
            this.free(obj, p)
        }
    } else if (obj) {
        try {
            if (prop != 'innerHTML' && prop.indexOf('src') == -1) {
                if (obj[prop] && obj[prop].tagName && obj[prop].tagName.toLowerCase() == 'td') {
                    obj[prop].style.display = ''
                }
                obj[prop] = null
            }
        } catch (ex) {}
    }
};
XHTMLSuite.eventFlusher = function (dispose) {
    if (!XHTMLSuite.is_ie || XHTMLSuite.ie_version > 7) {
        return
    }
    XHTMLSuite.flushEvents(dispose);
    for (var x = 0; x < XHTMLSuite.toFree.length; x++) {
        if (!dispose && (XHTMLSuite.toFree[x].p != '_textArea' || XHTMLSuite.toFree[x].p != '_notifyListeners')) {
            this.free(XHTMLSuite.toFree[x].o, XHTMLSuite.toFree[x].p);
            XHTMLSuite.toFree[x].o = null
        }
    }
};

