////////////////////////////////////////////////////////////////////////
//
//                            CHEditor 4.1-p3
//
//       Author: Na Chang-Ho
//       EMail:  chna@chcode.com
//       Homepage: http://www.chcode.com, http://www.chsoft.co.kr
//
//       Copyright (C) 1997-2007, CHSoft. All rights reserved.
//
////////////////////////////////////////////////////////////////////////
var chutil = new CH_UTILITIES();
var GB = {
    colors : [
    "#FF0000", "#FFFF00", "#00FF00", "#00FFFF", "#0000FF", "#FF00FF", "#FFFFFF", "#F5F5F5", "#DCDCDC", "#FFFAFA",
    "#D3D3D3", "#C0C0C0", "#A9A9A9", "#808080", "#696969", "#000000", "#2F4F4F", "#708090", "#778899", "#4682B4",
    "#4169E1", "#6495ED", "#B0C4DE", "#7B68EE", "#6A5ACD", "#483D8B", "#191970", "#000080", "#00008B", "#0000CD",
    "#1E90FF", "#00BFFF", "#87CEFA", "#87CEEB", "#ADD8E6", "#B0E0E6", "#F0FFFF", "#E0FFFF", "#AFEEEE", "#00CED1",
    "#5F9EA0", "#48D1CC", "#00FFFF", "#40E0D0", "#20B2AA", "#008B8B", "#008080", "#7FFFD4", "#66CDAA", "#8FBC8F",
    "#3CB371", "#2E8B57", "#006400", "#008000", "#228B22", "#32CD32", "#00FF00", "#7FFF00", "#7CFC00", "#ADFF2F",
    "#98FB98", "#90EE90", "#00FF7F", "#00FA9A", "#556B2F", "#6B8E23", "#808000", "#BDB76B", "#B8860B", "#DAA520",
    "#FFD700", "#F0E68C", "#EEE8AA", "#FFEBCD", "#FFE4B5", "#F5DEB3", "#FFDEAD", "#DEB887", "#D2B48C", "#BC8F8F",
    "#A0522D", "#8B4513", "#D2691E", "#CD853F", "#F4A460", "#8B0000", "#800000", "#A52A2A", "#B22222", "#CD5C5C",
    "#F08080", "#FA8072", "#E9967A", "#FFA07A", "#FF7F50", "#FF6347", "#FF8C00", "#FFA500", "#FF4500", "#DC143C",
    "#FF0000", "#FF1493", "#FF00FF", "#FF69B4", "#FFB6C1", "#FFC0CB", "#DB7093", "#C71585", "#800080", "#8B008B",
    "#9370DB", "#8A2BE2", "#4B0082", "#9400D3", "#9932CC", "#BA55D3", "#DA70D6", "#EE82EE", "#DDA0DD", "#D8BFD8",
    "#E6E6FA", "#F8F8FF", "#F0F8FF", "#F5FFFA", "#F0FFF0", "#FAFAD2", "#FFFACD", "#FFF8DC", "#FFFFE0", "#FFFFF0",
    "#FFFAF0", "#FAF0E6", "#FDF5E6", "#FAEBD7", "#FFE4C4", "#FFDAB9", "#FFEFD5", "#FFF5EE", "#FFF0F5", "#FFE4E1"
    ],
    htmlKey : [
    "!DOCTYPE", "A", "ABBR", "ACRONYM", "ADDRESS", "APPLET", "AREA", "B", "BASE", "BASEFONT", "BGSOUND", "BDO",
    "BIG", "BLINK", "DL", "BODY", "BR", "BUTTON", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP",
    "COMMENT", "DD", "DEL", "DFN", "DIR", "DIV", "FONT", "DT", "EM", "EMBED", "FIELDSET", "BLOCKQUOTE",
    "FORM", "FRAME", "FRAMESET", "H", "H1", "H2", "H3", "H4", "H5", "H6", "HEAD", "HR",
    "HTML", "I", "IFRAME", "IMG", "INPUT", "INS", "ISINDEX", "KBD", "LABEL", "LEGEND", "LI", "LINK",
    "LISTING", "MAP", "MARQUEE", "MENU", "META", "MULTICOL", "NEXTID", "NOBR", "NOFRAMES", "NOSCRIPT", "OBJECT", "OL",
    "OPTGROUP", "OPTION", "P", "PARAM", "PLAINTEXT","PRE", "Q", "S", "SAMP", "SCRIPT", "SELECT", "SERVER",
    "SMALL", "SOUND", "SPACER", "SPAN", "STRIKE", "STRONG", "STYLE", "SUB", "SUP", "TABLE", "TBODY", "TD",
    "TEXTAREA", "TITLE", "TFOOT", "TH", "THEAD", "TEXTFLOW", "TR", "TT", "U", "UL", "VAR", "WBR", "XMP" ],

    MSIE    : navigator.userAgent.toLowerCase().indexOf("msie")  != -1,
    GECKO   : navigator.userAgent.toLowerCase().indexOf('gecko') != -1,
    OPERA   : navigator.userAgent.toLowerCase().indexOf('opera') != -1,

    editorMode          : 'rich',
    popupIFrame         : ['fontType', 'fontSize', 'paragraph', 'zoom', 'foreColor', 'backColor', 'BGColor'],
    popupID             : null,
    imageBorder         : '#ccc solid',
    currentRS           : new Object(),
    autoHeight          : false,
    frameFocus          : (navigator.userAgent.toLowerCase().indexOf("msie")  != -1) ? 'onfocus' : 'onload'
}

function CH_UTILITIES()
{
    this.oname;
}

function cheditor(oname)
{
    if (typeof(document.execCommand) == 'undefined')
        return;

    if (GB.MSIE) {
       if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 5.5) {
            this.run = function() {
                document.write("<textarea name=\"message\" id=\"message\" style=\"width:100%;height:200px\"></textarea>");
            };
            return;
        }
    }

    if (GB.GECKO) {
        if (navigator.productSub < 20030210) {
            this.run = function() {
                document.write("<textarea name=\"message\" id=\"message\" style=\"width:100%;height:200px\"></textarea>");
            };
            return;
        }
    }

    this.config = {
        editorWidth     : '680px',
        editorHeight    : '100%',
        editorFontSize  : '9pt',
        editorFontFace  : 'gulim',
        editorBorder    : '1px solid #ccc',
        tabIndex        : 0,
        lineHeight      : 16,
        editorBgcolor   : '#fff',
        editorToolbar   : '',
        editorPath      : '.',
        popupAutoKill   : true,
        fullHTMLSource  : true,
        hrefTarget        : '_blank',
        showTagPath     : true,
        toolBarSplit    : true,
        useBR           : true,
        useImageBR      : true,
        imgMaxWidth     : 650,
        imgMaxHeight    : 8000,
        imgReSize       : true,
        imgBorder       : '#999 solid',
        useSource       : true,
        usePreview      : true,
        usePrint        : true,
        useUndo         : true,
        useRedo         : true,
        useCopy         : true,
        useCut          : true,
        usePaste        : true,
        usePasteFromWord: true,
        useSelectAll    : true,
        useBold         : true,
        useUnderline    : true,
        useStrike       : true,
        useItalic       : true,
        useSuperscript  : true,
        useSubscript    : true,
        useJustifyLeft  : true,
        useJustifyCenter: true,
        useJustifyRight : true,
        useJustifyFull  : true,
        useOrderedList  : true,
        useUnOrderedList: true,
        useOutdent      : true,
        useIndent       : true,
        useFontType     : true,
        useParagraph    : true,
        useFontSize     : true,
        useZoom         : true,
        useBackColor    : true,
        useForeColor    : true,
        useBGColor      : true,
        useSChar        : true,
        useHyperLink    : true,
        useUnLink       : true,
        useFlash        : true,
        useMedia        : true,
        useUploadImage  : true,
        useBGImage      : true,
        useEmontion     : true,
        useHR           : true,
        autoHeight      : false,
        useTable        : true
    };
    this.selectedColor      = '#ffc985';
    this.editorPopupBgcolor = '#e3efff';
    this.oname              = oname;
    this.editArea           = null;
    this.editAreaWapper     = null;
    this.inputForm          = null;
    this.selection          = null;
    this.selectionType      = null;
    this.displayMode        = 'RICH';
    this.szTmp              = '';
    this.undoSteps          = 20;
    this.undoTimeout        = 500;
    this.undoQueue          = new Array(this.undoSteps);
    this.undoPos            = -1;
    this.customUndo         = true;
    this.timerUndo          = null;
}

cheditor.prototype = {
plainMode : function () {
    this.editAreaWapper.style.display = 'none';
    document.getElementById('idToolbar'+this.oname).style.display = 'none';
    document.getElementById('checkBox'+this.oname).style.display = 'none';
    document.getElementById('plain_id'+this.oname).style.display = '';
    document.getElementById('plain_id'+this.oname).focus();
    if (this.config.showTagPath)
        document.getElementById('statusBlock'+this.oname).style.display = 'none';
    this.resetData();
},

htmlMode : function () {
    document.getElementById('plain_id'+this.oname).style.display = 'none';
    this.editAreaWapper.style.display = '';
    document.getElementById('idToolbar'+this.oname).style.display = '';
    document.getElementById('checkBox'+this.oname).style.display = '';
    if (this.config.showTagPath)
        document.getElementById('statusBlock'+this.oname).style.display = '';
    this.resetData();
    this.editArea.focus();
},

createTextarea : function () {
    var wrapper = document.getElementById('wrapper_'+this.oname);
    var textarea = document.createElement("textarea");
    textarea.style.width = this.config.editorWidth;
    textarea.style.height = this.config.editorHeight;
    textarea.style.border = this.config.editorBorder;
    textarea.id = "plain_id"+this.oname;
    textarea.style.display = 'none';
    textarea.style.fontSize = '9pt';
    textarea.style.position = 'relative';
    if (this.config.tabIndex) textarea.tabIndex = this.config.tabIndex;
    wrapper.appendChild(textarea);
},

useBR : function (el) {
    this.editArea.focus();
},

resetData : function () {
    if (GB.editorMode == 'rich') {
        document.getElementById('plain_id'+this.oname).value = this.outputBodyText();
        GB.editorMode = 'plain';
    }
    else {
        var szPlain = document.getElementById('plain_id'+this.oname).value;
        szPlain = szPlain.replace(/\n/g,'<br>');
        this.resetEditArea(szPlain);
        this.setEditorOpt();
        GB.editorMode = 'rich';
    }
},

undoSnapshot : function () {
    ++this.undoPos;
    if (this.undoPos >= this.undoSteps) {
        this.undoQueue.shift();
        --this.undoPos;
    }
    var take = true;
    var txt = this.getContents();

    if (this.undoPos > 0) take = (this.undoQueue[this.undoPos - 1] != txt);
    take ? this.undoQueue[this.undoPos] = txt : this.undoPos--;
},

updateUndoQueue : function () {
    if (this.customUndo && !this.timerUndo) {
        this.undoSnapshot();
        var editor = this;
        this.timerUndo = setTimeout(function() { editor.timerUndo = null;}, this.undoTimeout);
    }
},

resetEditArea : function (loadContents) {
    var oEditor = document.getElementById('id'+this.oname).contentWindow;
    oEditor.document.designMode = "on";
    if (!GB.MSIE) oEditor.document.execCommand('useCSS', false, false);
    oEditor.document.open("text/html", "replace");
    oEditor.document.write("<html><head></head>");
    oEditor.document.write("<body style=\"margin:5px;background-color:"+this.config.editorBgcolor+"\">"+loadContents+"</body></html>");
    oEditor.document.close();
    oEditor.document.body.style.fontSize   = this.config.editorFontSize;
    oEditor.document.body.style.fontFamily = this.config.editorFontFace;
    return oEditor;
},

startDrag : function (event, el) {
    GB.currentRS.elNode = this.editAreaWapper;
    var y = GB.MSIE ? window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop :
        event.clientY + window.scrollY;
    GB.currentRS.cursorStartY = y;
    GB.currentRS.elStartTop   = parseInt(GB.currentRS.elNode.style.height);
    if (isNaN(GB.currentRS.elStartTop))  GB.currentRS.elStartTop  = 0;
    if (GB.MSIE) {
        document.attachEvent("onmousemove", eval(chutil.oname).dragGo);
        document.attachEvent("onmouseup",   eval(chutil.oname).dragStop);
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
    else {
        document.addEventListener("mousemove", eval(chutil.oname).dragGo,   true);
        document.addEventListener("mouseup",   eval(chutil.oname).dragStop, true);
        event.preventDefault();
    }
},

dragGo : function (event) {
    var y = (GB.MSIE) ? window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop :
        event.clientY + window.scrollY;
    GB.currentRS.elNode.style.height  = (GB.currentRS.elStartTop  + y - GB.currentRS.cursorStartY) + "px";
    if (GB.MSIE) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
    else
        event.preventDefault();
},

dragStop : function () {
    GB.currentRS.elNode.style.border = eval(chutil.oname).config.editorBorder;
    if (GB.MSIE) {
        document.detachEvent("onmousemove", eval(chutil.oname).dragGo);
        document.detachEvent("onmouseup",   eval(chutil.oname).dragStop);
    }
    else {
        document.removeEventListener("mousemove", eval(chutil.oname).dragGo,   true);
        document.removeEventListener("mouseup",   eval(chutil.oname).dragStop, true);
    }
},

run : function () {
    document.write('<div style="width:'+this.config.editorWidth+';height:auto" id="wrapper_'+this.oname+'">');
    this.drawToolbar();
    document.write('<div style="position:relative;height:'+this.config.editorHeight+';border:'+this.config.editorBorder+'" id="editArea_'+this.oname+'">');
    document.write('<iframe frameborder="0" border="0" style="width:100%;height:100%;overflow:auto"'+' id="id'+this.oname+'" name="id'+this.oname+'"');
    if (this.config.tabIndex) document.write(' tabindex="'+this.config.tabIndex+'"');
    document.write(' '+GB.frameFocus+'="chutil.oname=\''+this.oname+'\'"></iframe>');
    document.write('</div>');
    document.write('<div id="CHModifyBlock'+this.oname+'" style="display:none;border-right:'+this.config.editorBorder+';border-left:'+this.config.editorBorder+';border-bottom:'+this.config.editorBorder+';padding:2px;background-color:#eee;font-size:7pt;font-family:verdana;text-align:left">&#160;</div>');

    if (this.config.showTagPath) {
        document.write('<div id="statusBlock'+this.oname+'" style="background-color:#eee;float:left;border-right:'+this.config.editorBorder+';border-left:'+this.config.editorBorder+';border-bottom:'+this.config.editorBorder+';">');
        document.write('<div id="CHstatusBar'+this.oname+'" style="float:left;padding:2px;font-size:7pt;font-family:verdana;text-align:left">&lt;HTML&gt; &lt;BODY&gt;</div>');
        document.write('<div onmousedown="'+this.oname+'.startDrag(event,this)" id="reSize'+this.oname+'" style="background:#eee;left:0px;top:0px;float:right;width:11px;cursor:move"><img src="'+this.config.editorPath+'/icons/statusbar_resize.gif"></div>');
        document.write('</div><div style="clear:both"></div>');
    }
    document.write('<div id="checkBox'+this.oname+'" style="text-align:left;font-size:9pt">');
    if (this.config.useSource)
        document.write('<input type="checkbox" onclick="'+this.oname+'.setDisplayMode()" id="chkDisplayMode">HTML¼Ò½º&#160;');
    if (this.config.usePreview)
        document.write('<input type="checkbox" onclick="'+this.oname+'.previewMode()" id="chkPreviewMode">¹Ì¸®º¸±â&#160;');
    document.write('</div>');
    document.write('</div>');

    var loadContents = '';
    if (this.inputForm && document.getElementById(this.inputForm))
        loadContents = document.getElementById(this.inputForm).value;

    this.editArea = this.resetEditArea(loadContents);
    this.editAreaWapper = document.getElementById("editArea_"+this.oname);

    document.write('<iframe name="idtmp'+this.oname+'" contentEditable="true" id="idtmp'+this.oname+'" style="visibility:hidden;width:0px;height:0px;overflow:auto;" noborder onfocus="'+this.oname+'.boxHide()"></iframe>');
    var tmpeditor = eval("idtmp"+this.oname);
    tmpeditor.document.designMode = "on";
    tmpeditor.document.open("text/html","replace");
    tmpeditor.document.write("<html><head></head><body></body></html>");
    tmpeditor.document.close();

    if (!document.getElementById("foreColor")) {
        htmlOutput = this.createWindow(200, this.setColorTable('fore'));
        document.write('<iframe frameborder="0" id="foreColor" name="foreColor" style="position:absolute;visibility:hidden;z-index:-1;width:1px;height:1px;"></iframe>');
        foreColor.document.open("text/html", "replace");
        foreColor.document.write(htmlOutput);
        foreColor.document.close();
    }
    if (!document.getElementById("backColor")) {
        htmlOutput = this.createWindow(200, this.setColorTable('back'));
        document.write('<iframe frameborder="0" id="backColor" name="backColor" style="position:absolute;visibility:hidden;z-index:-1;width:1px;height:1px;"></iframe>');
        backColor.document.open("text/html", "replace");
        backColor.document.write(htmlOutput);
        backColor.document.close();
    }
    if (!document.getElementById("BGColor")) {
        htmlOutput = this.createWindow(200, this.setColorTable('bgColor'));
        document.write('<iframe frameborder="0" id="BGColor" name="BGColor" style="position:absolute;visibility:hidden;z-index:-1;width:1px;height:1px;"></iframe>');
        BGColor.document.open("text/html", "replace");
        BGColor.document.write(htmlOutput);
        BGColor.document.close();
    }
    if (!document.getElementById("fontType")){
        htmlOutput = '<div style="background-color:'+this.editorPopupBgcolor+'">' +
            "<div style='padding:4px 0px 0px 2px;color:#0E2C5D;background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);float:left;font-size:9pt'>±Û²Ã ¸ð¾ç</div>"+
            "<div style='background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);text-align:right;padding:3px;font-size:9pt'>&#160;<img src="+this.config.editorPath+"/icons/close.gif width=13 height=13 onclick='parent."+this.oname+".boxHide();' style='vertical-align:top' /></div>" +
            "<div style='clear:both;border-top:1px solid #8db3e5'></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('gulim')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:gulim;font-size:9pt;margin:1px'>°¡³ª´Ù¶ó¸¶¹Ù»ç (±¼¸²)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('batang')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:batang;font-size:9pt;margin:1px'>°¡³ª´Ù¶ó¸¶¹Ù»ç (¹ÙÅÁ)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('dotum')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:dotum;font-size:9pt;margin:1px'>°¡³ª´Ù¶ó¸¶¹Ù»ç (µ¸¿ò)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('gungsuh')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:gungsuh;font-size:9pt;margin:1px'>°¡³ª´Ù¶ó¸¶¹Ù»ç (±Ã¼­)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Arial')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Arial;font-size:9pt;margin:1px'>ABCDEFGHIJK (Arial)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Arial Black')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Arial Black;font-size:9pt;margin:1px'>ABCDEFGHIJK (Arial Black)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Arial Narrow')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Arial Narrow;font-size:9pt;margin:1px'>ABCDEFGHIJK (Arial Narrow)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Comic Sans MS')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Comic Sans MS;font-size:9pt;margin:1px'>ABCDEFGHIJK (Comic Sans MS)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Courier New')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Courier New;font-size:9pt;margin:1px'>ABCDEFGHIJK (Courier New)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Tahoma')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Tahoma;font-size:9pt;margin:1px'>ABCDEFGHIJK (Tahoma)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Times New Roman')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Times New Roman;font-size:9pt;margin:1px'>ABCDEFGHIJK (Times New Roman)</div>" +
            "<div onclick=\"parent."+this.oname+".changeFontType('Verdana')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;font-family:Verdana;font-size:9pt;margin:1px'>ABCDEFGHIJK (Verdana)</div>" +
            "</div>";

        htmlOutput = this.createWindow(220, htmlOutput);
        document.write("<iframe frameborder=0 id=fontType name=fontType style='position: absolute; visibility: hidden; z-index: -1;width:1px;height:1px;'></iframe>");
        fontType.document.open("text/html","replace");
        fontType.document.write(htmlOutput);
        fontType.document.close();
    }
    if (!document.getElementById("paragraph")) {
        htmlOutput = '<div style="background-color:'+this.editorPopupBgcolor+'">' +
            "<div style='padding:4px 0px 0px 2px;color:#0E2C5D;background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);float:left;font-size:9pt'>Á¦¸ñ ¼±ÅÃ</div>"+
            "<div style='background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);text-align:right;padding:3px;font-size:9pt'>&#160;<img src="+this.config.editorPath+"/icons/close.gif width=13 height=13 onclick='parent."+this.oname+".boxHide();' style='vertical-align:top' /></div>" +
            "<div style='clear:both;border-top:1px solid #8db3e5'></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H1>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h1 style='margin:0'>Á¦¸ñ 1</h1></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H2>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h2 style='margin:0'>Á¦¸ñ 2</h2></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H3>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h3 style='margin:0'>Á¦¸ñ 3</h3></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H4>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h4 style='margin:0'>Á¦¸ñ 4</h4></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H5>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h5 style='margin:0'>Á¦¸ñ 5</h5></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<H6>')\"  align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><h6 style='margin:0'>Á¦¸ñ 6</h6></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<PRE>')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><pre style='margin:0'>Preformatted</pre></div>" +
            "<div onclick=\"parent."+this.oname+".applyParagraph('<P>')\"   align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;margin:1px'><p style='margin:0'>º¸Åë</p></div>" +
            "</div>";

        htmlOutput = this.createWindow(200, htmlOutput);
        document.write("<iframe frameborder=0 id=paragraph name=paragraph style='position: absolute; visibility: hidden; z-index: 1;width:1px;height:1px;'></iframe>");
        paragraph.document.open("text/html", "replace");
        paragraph.document.write(htmlOutput);
        paragraph.document.close();
    }
    if (!document.getElementById("fontSize")) {
        htmlOutput =  '<div style="background-color:'+this.editorPopupBgcolor+'">' +
            "<div style='padding:4px 0px 0px 2px;color:#0E2C5D;background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);float:left;font-size:9pt'>±Û²Ã Å©±â</div>"+
            "<div style='background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);text-align:right;padding:3px;font-size:9pt'>&#160;<img src="+this.config.editorPath+"/icons/close.gif width=13 height=13 onclick='parent."+this.oname+".boxHide();' style='vertical-align:top' /></div>" +
            "<div style='clear:both;border-top:1px solid #8db3e5'></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(1)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='1'>°¡³ª´Ù¶ó¸¶¹Ù (1)</font></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(2)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='2'>°¡³ª´Ù¶ó¸¶¹Ù (2)</font></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(3)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='3'>°¡³ª´Ù¶ó¸¶¹Ù (3)</font></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(4)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='4'>°¡³ª´Ù¶ó¸¶¹Ù (4)</font></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(5)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='5'>°¡³ª´Ù¶ó¸¶¹Ù (5)</font></div>" +
            "<div onclick=\"parent."+this.oname+".changeFontSize(6)\" onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:2px;margin:1px;'><font size='6'>°¡³ª´Ù¶ó¸¶¹Ù (6)</font></div>" +
            "</div>";

        htmlOutput = this.createWindow(260, htmlOutput);
        document.write("<iframe frameborder=0 id=fontSize name=fontSize style='position: absolute; visibility: hidden; z-index: -1;width:1px;height:1px;'></iframe>");
        fontSize.document.open("text/html","replace");
        fontSize.document.write(htmlOutput);
        fontSize.document.close();
    }
    if (GB.MSIE && !document.getElementById("zoom")){
        htmlOutput =  '<div style="background-color:'+this.editorPopupBgcolor+'">' +
            "<div style='padding:4px 0px 0px 2px;color:#0E2C5D;background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);float:left;font-size:9pt'>º»¹® È®´ë</div>"+
            "<div style='background:#6b90c0 url("+this.config.editorPath+"/icons/title_bar_bg.gif);text-align:right;padding:3px;font-size:9pt'>&#160;<img src="+this.config.editorPath+"/icons/close.gif width=13 height=13 onclick='parent."+this.oname+".boxHide();' style='vertical-align:top' /></div>" +
            "<div style='clear:both;border-top:1px solid #8db3e5'></div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('500%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>500%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('250%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>250%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('200%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>200%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('150%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>150%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('120%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>120%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('100%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>100%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('75%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>75%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('50%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>50%</div>" +
            "<div onclick=\"parent."+this.oname+".viewZoom('25%')\" align=center onmouseover='parent."+this.oname+".mouseOver(this)' onmouseout='parent."+this.oname+".mouseOut(this)' class=dropdown style='padding:3px;font-size:9pt;margin:1px'>25%</div>" +
            "</div>";

        htmlOutput = this.createWindow(100, htmlOutput);
        document.write("<iframe frameborder=0 id=zoom name=zoom style='position:absolute; visibility:hidden;z-index:-1;width:1px;height:1px;'></iframe>");
        zoom.document.open("text/html","replace");
        zoom.document.write(htmlOutput);
        zoom.document.close();
    }

    document.write('<div id="dwindow" style="border:1px solid #8db3e5;visibility:hidden;position:absolute;background-color:#ebe9ed;left:0px;top:0px;" onSelectStart="return false">');
    document.write('<div align="right" style="height:21px;background:#6b90c0 url('+this.config.editorPath+'/icons/title_bar_bg.gif);">'+
        '<div style="margin:4px 0px 0px 5px;float:left;font-size:9pt;color:#0E2C5D;" id="popupTitle"></div><div><img src="'+this.config.editorPath+'/icons/close.gif" onClick="'+this.oname+'.popupWinClose()" style="margin:3px 2px 0px 0px;cursor:pointer"></div></div>');
    document.write('<div id="cframe">');
    document.write('</div></div>');

    GB.popupID = document.getElementById('dwindow');
    GB.autoHeight = this.config.autoHeight;
    this.editArea.focus();
    this.createTextarea();
    this.setEditorOpt();
},

setEditorOpt : function () {
    if (GB.MSIE) this.editArea.document.onkeydown = this.doOnKeyPress;
    this.addEvent(this.editArea.document, "mouseup");
},

addEvent : function (doc, ev) {
    this.updateUndoQueue();
    var func = function () { cheditor.setEditorEvent(chutil.oname) };
    GB.MSIE ? doc.attachEvent("on"+ev, func) : doc.addEventListener(ev, func, false);
},

toolbarButtonOut : function (elemButton) {
    var nTop = elemButton.style.top.substring(0, elemButton.style.top.length - 2);
    elemButton.style.top = nTop * 1 + 22 + 'px';
},

toolbarButtonOver : function (elemButton) {
    var nTop = elemButton.style.top.substring(0, elemButton.style.top.length - 2);
    elemButton.style.top = nTop - 22 + 'px';
},

drawToolbar : function () {
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_1.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_2.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_3.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_4.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_5.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_6.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_7.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_8.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_9.gif' width=1 height=1 style='display:none'>");
    document.write("<img src='"+this.config.editorPath+"'/icons/toolbar_icon_10.gif' width=1 height=1 style='display:none'>");
    document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%" id="idToolbar'+this.oname+'">');
    document.write('<tr><td align="left">');
    if (this.config.usePrint)
        this.drawToolbarIcon(1,0,22,"btnPrint"+this.oname, "ÀÎ¼â", this.oname + ".doCmd('Print',false)");
    if (this.config.useUndo)
        this.drawToolbarIcon(1,44,22,"btnUndo"+this.oname, "½ÇÇà Ãë¼Ò", this.oname + ".undo()");
    if (this.config.useRedo)
        this.drawToolbarIcon(1,88,22,"btnRedo"+this.oname, "µÇµ¹¸®±â", this.oname + ".redo()");
    if (this.config.useCopy)
        this.drawToolbarIcon(1,132,22,"btnCopy"+this.oname, "º¹»ç", this.oname + ".doCmd('Copy',false)");
    if (this.config.useCut)
        this.drawToolbarIcon(2,0,22,"btnCut"+this.oname, "Àß¶ó³»±â", this.oname + ".doCmd('Cut',false)");
    if (this.config.usePaste)
        this.drawToolbarIcon(2,44,22,"btnPaste"+this.oname, "ºÙÀÌ±â", this.oname + ".doCmd('Paste',false)");
    if (this.config.usePasteFromWord)
        this.drawToolbarIcon(10,88,22,"btnPaste"+this.oname, "MS¿öµå ºÙÀÌ±â", this.oname + ".doCmd('PasteFromWord',false)");
    if (this.config.useSelectAll)
        this.drawToolbarIcon(2,88,22,"btnSelectAll"+this.oname, "ÀüÃ¼ ¼±ÅÃ", this.oname + ".doCmd('SelectAll',false)");
    if (this.config.useBold)
        this.drawToolbarIcon(2,132,22,"btnBold"+this.oname, "ÁøÇÏ°Ô", this.oname + ".doCmd('Bold',false)");
    if (this.config.useUnderline)
        this.drawToolbarIcon(3,0,22,"btnUnderline"+this.oname, "¹ØÁÙ", this.oname + ".doCmd('Underline',false)");
    if (this.config.useStrike)
        this.drawToolbarIcon(3,44,22,"btnStrikethrough"+this.oname, "Ãë¼Ò¼±", this.oname + ".doCmd('Strikethrough',false)");
    if (this.config.useItalic)
        this.drawToolbarIcon(3,88,22,"btnItalic"+this.oname, "±â¿ïÀÓ", this.oname + ".doCmd('Italic',false)");
    if (this.config.useSuperscript)
        this.drawToolbarIcon(3,132,22,"btnSuperscript"+this.oname, "À§Ã·ÀÚ", this.oname + ".doCmd('Superscript',false)");
    if (this.config.useSubscript)
        this.drawToolbarIcon(4,0,22,"btnSubscript"+this.oname, "¾Æ·¡ Ã·ÀÚ", this.oname + ".doCmd('Subscript',false)");
    if (this.config.useJustifyLeft)
        this.drawToolbarIcon(4,44,22,"btnJustifyLeft"+this.oname, "¿ÞÂÊ Á¤·Ä", this.oname + ".doCmd('JustifyLeft',false)");
    if (this.config.useJustifyCenter)
        this.drawToolbarIcon(4,88,22,"btnJustifyCenter"+this.oname, "°¡¿îµ¥ Á¤·Ä", this.oname + ".doCmd('JustifyCenter',false)");
    if (this.config.useJustifyRight)
        this.drawToolbarIcon(4,132,22,"btnJustifyRight"+this.oname, "¿À¸¥ÂÊ Á¤·Ä", this.oname + ".doCmd('JustifyRight',false)");
    if (this.config.useJustifyFull)
        this.drawToolbarIcon(5,0,22,"btnJustifyFull"+this.oname, "¾çÂÊ Á¤·Ä", this.oname + ".doCmd('JustifyFull',false)");
    if (this.config.useOrderedList)
        this.drawToolbarIcon(5,44,22,"btnOrderedList"+this.oname, "¹®´Ü ¹øÈ£", this.oname + ".doCmd('InsertOrderedList',false)");
    if (this.config.useUnOrderedList)
        this.drawToolbarIcon(5,88,22,"btnUnorderedList"+this.oname, "±Û ¸Ó¸®Ç¥",    this.oname + ".doCmd('InsertUnorderedList',false)");
    if (this.config.useOutdent)
        this.drawToolbarIcon(5,132,22,"btnOutdent"+this.oname, "¿ÞÂÊ¿©¹é ÁÙÀÌ±â", this.oname + ".doCmd('Outdent',false)");
    if (this.config.useIndent)
        this.drawToolbarIcon(6,0,22,"btnIndent"+this.oname, "¿ÞÂÊ¿©¹é ´Ã¸®±â", this.oname + ".doCmd('Indent',false)");
    if (this.config.toolBarSplit) document.write('</td></tr><tr><td>');
    if (this.config.useFontType)
        this.drawToolbarIcon(8,0,29,"btnFontType"+this.oname, "±Û²Ã", this.oname + ".displayWindow('fontType');"+this.oname+".windowPos(this,'fontType')");
    if (this.config.useParagraph)
        this.drawToolbarIcon(8,44,29,"btnParaGraph"+this.oname, "Á¦¸ñ", this.oname + ".displayWindow('paragraph');"+this.oname+".windowPos(this,'paragraph')");
    if (this.config.useFontSize)
        this.drawToolbarIcon(8,88,29,"btnFontSize"+this.oname, "±Û²ÃÅ©±â", this.oname + ".displayWindow('fontSize');"+this.oname+".windowPos(this,'fontSize')");
    if (GB.MSIE && this.config.useZoom)
        this.drawToolbarIcon(8,132,29,  "btnZoom"+this.oname, "º»¹®È®´ë", this.oname + ".displayWindow('zoom');"+this.oname+".windowPos(this,'zoom')");
    if (this.config.useBackColor)
        this.drawToolbarIcon(9,88,22,"btnBackColor"+this.oname, "Çü±¤Ææ", this.oname + ".displayWindow('backColor');"+this.oname+".windowPos(this,'backColor')");
    if (this.config.useForeColor)
        this.drawToolbarIcon(9,132,22,"btnForeColor"+this.oname, "±ÛÀÚ»ö", this.oname + ".displayWindow('foreColor');"+this.oname+".windowPos(this,'foreColor')");
    if (this.config.useBGColor)
        this.drawToolbarIcon(9,44,22,"btnBGColor"+this.oname, "¹ÙÅÁ»ö", this.oname + ".displayWindow('BGColor');"+this.oname+".windowPos(this,'BGColor')");
    if (this.config.useSChar)
        this.drawToolbarIcon(7,132,22,"btnSChar"+this.oname, "Æ¯¼ö¹®ÀÚ", this.oname + ".windowOpen('schar')");
    if (this.config.useHyperLink)
        this.drawToolbarIcon(6,44,22,"btnhyperLink"+this.oname, "ÇÏÀÌÆÛ¸µÅ©", this.oname + ".windowOpen('hyperLink')");
    if (this.config.useUnLink)
        this.drawToolbarIcon(6,88,22,"btnUnLink"+this.oname, "ÇÏÀÌÆÛ¸µÅ© ÇØÁ¦", this.oname + ".doCmd('UnLink',false)");
    if (this.config.useFlash)
        this.drawToolbarIcon(9,0,22,"btnFlash"+this.oname, "ÇÃ·¡½¬ ¹«ºñ", this.oname + ".windowOpen('flash')");
    if (this.config.useMedia)
        this.drawToolbarIcon(6,132,22,"btnMedia"+this.oname, "¹Ìµð¾î", this.oname + ".windowOpen('media')");
    if (this.config.useUploadImage)
        this.drawToolbarIcon(7,0,22,"btnImage"+this.oname, "±×¸²³Ö±â", this.oname + ".windowOpen('image')");
    if (this.config.useBGImage)
        this.drawToolbarIcon(7,44,22,"btnBgImage"+this.oname, "¹è°æ±×¸²", this.oname + ".windowOpen('bgimage')");
    if (this.config.useEmontion)
        this.drawToolbarIcon(7,88,22,"btnEm"+this.oname, "Ç¥Á¤ ¾ÆÀÌÄÜ", this.oname + ".windowOpen('emotion')");
    if (this.config.useHR)
        this.drawToolbarIcon(10,0,22,"btnHorizontalRule"+this.oname, "°¡·Î¼±", this.oname + ".doCmd('InsertHorizontalRule')");
    if (this.config.useTable)
        this.drawToolbarIcon(10,44,22,"btnTable"+this.oname, "Å×ÀÌºí", this.oname + ".windowOpen('table')");

    if (GB.MSIE) {
        document.write('<div style="float:left"><input type="checkbox" id="chkUseBR'+this.oname+'" checked="checked" onclick="'+this.oname+'.useBR(this)"><span style="font-size:8pt;font-family:verdana">BR</span></div>');
    }
    document.write('</td></tr></table>');
},

changeFontType : function (val) {
    eval(fontType.document.getElementById("CHEditor").value).doCmdPopup("fontName",val);
},

setColor : function (color, _which) {
    if (_which == 'back')
        eval(backColor.document.getElementById("CHEditor").value).doCmdPopup(GB.MSIE ? 'BackColor' : 'HiliteColor', color);
    else
        eval(foreColor.document.getElementById("CHEditor").value).doCmdPopup('ForeColor', color);
},

setBgColor : function (color) {
    if (GB.MSIE)
        eval(BGColor.document.getElementById("CHEditor").value).doBgColor(color);
    else
        eval(BGColor.document.getElementById("CHEditor").value).doCmdPopup("BackColor",color);
},

doBgColor : function (color) {
    this.editArea.document.body.style.backgroundColor = color;
    this.selection.select();
    this.boxHide();
    this.editArea.focus();
},

applyParagraph : function (val) {
    eval(paragraph.document.getElementById("CHEditor").value).doCmdPopup("FormatBlock",val);
},

changeFontSize : function (val) {
    eval(fontSize.document.getElementById("CHEditor").value).doCmdPopup("fontSize",val);
},

getElement : function (elm, tag) {
    while (elm != null && elm.tagName != tag) {
        if (elm.id == 'id'+this.oname) return null;
        elm = elm.parentElement;
    }
    return elm;
},

hyperLink: function (szURL, szTarget, szTitle) {
    var selection = this.selection;
    var selectionType = this.selectionType;
    var range, el;

    if (GB.MSIE) {
        selection.select();
        selection = this.fixSelection(selection);
        selectionType = this.fixSelectionType(selection, selectionType);
        var target = (selectionType == "None" ? document.getElementById('id'+this.oname).document : selection);
        target.execCommand("UnLink", false);
        target.execCommand("CreateLink", false, szURL);
        el = selection.parentElement ? selection.parentElement() : this.getElement(selection.item(0),"A");
    }
    else {
        selection = this._getSelection();
        if (typeof selection != "undefined") range = selection.getRangeAt(0);
        document.getElementById("id"+this.oname).contentDocument.execCommand("CreateLink", false, szURL);
        el = range.startContainer.previousSibling;
    }

    if (el) {
        if (szTarget) el.target = szTarget;
        if (szTitle) el.title = szTitle;
    }
},

viewZoom: function (val) {
    if (!GB.MSIE) return;
    this.editArea.focus();
    this.selection.select();
    eval(zoom.document.getElementById("CHEditor").value).editArea.document.body.style.zoom = val;
    eval(zoom.document.getElementById("CHEditor").value).editArea.focus();
    this.boxHide();
},

insertBgImage: function (img) {
    this.editArea.focus();
    if (img) {
        img = this.config.editorPath + '/' + img;
        this.editArea.document.body.style.backgroundImage = "url("+img+")";
    }
    else {
        var s = this.editArea.document.body.style;
        GB.MSIE ? s.removeAttribute("backgroundImage") : s.backgroundImage = "none";
    }
},

insertTable: function (insertNode) {
    if (GB.MSIE) {
        this.selection.select();
        this.selection.pasteHTML(insertNode.outerHTML);
        return;
    }

    var sel = this._getSelection();
    var range = sel.getRangeAt(0);

    sel.removeAllRanges();
    range.deleteContents();

    var container = range.startContainer;
    var pos = range.startOffset;

    range = document.createRange();

    if (container.nodeType==3 && insertNode.nodeType==3) {
        container.insertData(pos, insertNode.nodeValue);

        range.setEnd(container, pos+insertNode.length);
        range.setStart(container, pos+insertNode.length);
    }
    else {
        var afterNode;
        if (container.nodeType == 3) {
            var textNode = container;
            container = textNode.parentNode;
            var text = textNode.nodeValue;
            var textBefore = text.substr(0,pos);
            var textAfter = text.substr(pos);
            var beforeNode = document.createTextNode(textBefore);
            var afterNode = document.createTextNode(textAfter);

            container.insertBefore(afterNode, textNode);
            container.insertBefore(insertNode, afterNode);
            container.insertBefore(beforeNode, insertNode);
            container.removeChild(textNode);
        }
        else {
            afterNode = container.childNodes[pos];
            container.insertBefore(insertNode, afterNode);
        }

        range.setEnd(afterNode, 0);
        range.setStart(afterNode, 0);
    }
    sel.addRange(range);
},

doInsertImage : function (img) {
    var oSelection = this.selection;
    var selectionType = this.selectionType;
    var szRandom = Math.random();
    var imgId = 'chimg_'+szRandom;
    var thumb = 'thumb_'+szRandom;
    var linebreak = false;
    var maxSize = false;
    var szHTML = '<img src="'+img.src+'"';

    if (this.config.imgReSize) maxSize = this.resizeImageComplete(img);
    szHTML += ' style="width:'+img.width+'px;height:'+img.height+'px" border="0"';

    if (img.hspace) szHTML += ' hspace='+parseInt(img.hspace);
    if (img.vspace) szHTML += ' vspace='+parseInt(img.vspace);
    if (img.alt == 'break') linebreak = true;
    if (img.align)  szHTML += ' align='+ img.align;

    imgId = imgId.replace(/\./,'');
    thumb = thumb.replace(/\./,'');

    if (maxSize) {
        szHTML += ' id="'+imgId+'">';
        szHTML = '<a id="'+thumb+'" href="'+img.src+'" class="imageUtil" onclick="return hs.run(this)">'+szHTML+'</a>';
    }
    else szHTML += '>';

    if (linebreak) szHTML = '<div>'+szHTML+'</div>';
    this.doCmdPaste(szHTML);
},

resizeImageComplete : function (img) {
    var resizeW;
    var resizeH;
    var w = this.config.imgMaxWidth;
    var h = this.config.imgMaxHeight;

    if (img.width > w || img.height > h) {
        if (img.width > img.height) {
            resizeW = img.width > w ? w : img.width;
            resizeH = Math.round((img.height * resizeW) / img.width);
        }
        else {
            resizeH = img.height > h ? h : img.height;
            resizeW = Math.round((img.width * resizeH) / img.height);
        }
    }
    else
        return false;

    img.width  = resizeW;
    img.height = resizeH;
    return true;
},

showTagSelector : function (on) {
    if (!this.config.showTagPath) return;
    var el = document.getElementById("CHstatusBar"+this.oname);
    el.style.display = on ? '' : 'none';
},

setDisplayMode: function () {
    this.selection = null;
    this.popupWinClose();
    var oEditor = this.editArea;
    if (this.config.usePreview) {
        if (document.getElementById("chkPreviewMode").checked) {
            document.getElementById("chkPreviewMode").checked = false;
            this.displayMode = 'RICH';
        }
    }

    if (this.displayMode=='RICH') {
        document.getElementById("CHModifyBlock"+this.oname).style.display = 'none';
        this.showTagSelector(false);
        var content = '';
        var tmpBody = this.getContents(true);

        if (!this.config.fullHTMLSource) {
            var spl = GB.MSIE ? "BODY" : "body";
            tmpBody= tmpBody.substr(tmpBody.indexOf("<"+spl) + 1);
            tmpBody = tmpBody.substr(tmpBody.indexOf(">") + 1);
            var tmp = tmpBody.split("</"+spl+">");
            tmpBody = tmp[0];
            this.szTmp = oEditor.document.body.style.cssText;
        }

        if (!GB.MSIE)
            tmpBody = tmpBody.replace(/</g,'&lt;').replace(/>/g,'&gt;');

        var key = GB.htmlKey.join ("|");
        var reg = new RegExp ("(&lt;\/?)(" + key + ")(&gt;)", "ig");
        var reg2 = new RegExp ("(&lt;)(" + key + ") (.+?)(&gt;)", "ig");

        if (GB.MSIE) {
            oEditor.document.body.innerText = tmpBody;
            content = oEditor.document.body.innerHTML;
        }
        else
            content = oEditor.document.body.innerText = tmpBody;

        content = content.replace (/&lt;META(.+?)name=generator&gt;/ig, "");
        content = content.replace (/&lt;link href=(.*?)&gt;/ig, '');
        content = content.replace (/(&lt;br&gt;)/ig, '$1<br>');
        content = content.replace (/\n/g, '<br>');
        content = content.replace (reg, "<font color=#0000ff>$1$2$3</font>");
        content = content.replace (reg2, "<font color=#0000ff>$1$2</font> $3<font color=#0000ff>$4</font>");

        oEditor.document.body.innerHTML = content;
        oEditor.document.body.clearAttributes;
        oEditor.document.body.style.fontFamily = 'Courier New';
        oEditor.document.body.style.fontSize = '9pt';
        oEditor.document.body.style.color = '#000';
        oEditor.document.body.style.background = '#fff';
        oEditor.document.body.contentEditable = true;
        oEditor.document.body.focus;
        this.displayMode = 'HTML';

        var tmpHeight = this.editAreaWapper.offsetHeight +
            document.getElementById("idToolbar"+this.oname).offsetHeight;

        if (!GB.MSIE) tmpHeight -= parseInt(this.editAreaWapper.style.borderTopWidth) * 2;
        document.getElementById("idToolbar"+this.oname).style.display = "none";
        this.editAreaWapper.style.height =  tmpHeight+'px';
    }
    else {
        if (GB.MSIE) this.putContents(oEditor.document.body.innerText);
        else this.putContents(oEditor.document.body.innerText);

        this.displayMode = 'RICH';

        if (!this.config.fullHTMLSource) oEditor.document.body.style.cssText = this.szTmp;
        if (!GB.MSIE) oEditor.document.designMode = "on";

        document.getElementById("idToolbar"+this.oname).style.display = "block";
        this.editAreaWapper.style.height = this.config.editorHeight;

        this.editArea.focus();
        this.showTagSelector(true);
        this.setEditorOpt();
    }
},

previewMode : function () {
    this.selection = null;
    this.popupWinClose();

    if (this.config.useSource) {
        if (document.getElementById("chkDisplayMode").checked) {
            this.putContents(this.editArea.document.body.innerText);
            this.displayMode = 'RICH';

            document.getElementById("idToolbar"+this.oname).style.display = "none";
            this.editArea.document.body.focus;
            document.getElementById("chkDisplayMode").checked = false;
        }
    }

    if (this.displayMode=='RICH') {
        document.getElementById("CHModifyBlock"+this.oname).style.display = 'none';
        this.showTagSelector(false);
        var content = this.editArea.document.body.innerHTML;
        this.editArea.document.body.innerHTML = content;
        this.editArea.document.body.contentEditable = false;
        if (!GB.MSIE) this.editArea.document.designMode = "off";
        this.editArea.document.body.focus;
        this.displayMode = 'HTML';
        var tmpHeight = this.editAreaWapper.offsetHeight +
            document.getElementById("idToolbar"+this.oname).offsetHeight;
        if (!GB.MSIE) tmpHeight -= parseInt(this.editAreaWapper.style.borderTopWidth) * 2;
        document.getElementById("idToolbar"+this.oname).style.display = "none";
        this.editAreaWapper.style.height =  tmpHeight+'px';
    }
    else {
        var tmp = this.getContents(false);
        this.editArea.document.body.innerText = tmp;
        this.putContents(this.editArea.document.body.innerText);
        this.displayMode = 'RICH';
        if (!GB.MSIE) this.editArea.document.designMode = "on";
        document.getElementById("idToolbar"+this.oname).style.display = "block";
        this.editAreaWapper.style.height = this.config.editorHeight;
        this.editArea.focus();
        this.showTagSelector(true);
        this.setEditorOpt();
    }
},

putContents : function (sContent) {
    var editorTmp = document.getElementById("idtmp"+this.oname).contentWindow;
    var doc = editorTmp.document.open("text/html", "replace");
    doc.write(sContent);
    doc.close();
    doc = this.editArea.document.open("text/html", "replace");

    if (GB.MSIE) {
        doc.write(editorTmp.document.documentElement.outerHTML);
    }
    else {
        var szTmp = editorTmp.document.documentElement.innerHTML;
        doc.write(szTmp.replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
    }
    doc.close();

    this.editArea.document.body.style.border = "";
    this.editArea.document.body.contentEditable = true;

    if (GB.MSIE) {
        this.editArea.document.execCommand("2D-Position", true, true);
        this.editArea.document.execCommand("MultipleSelection", true, true);
        this.editArea.document.execCommand("LiveResize", true, true);
    }
},

getContents : function (op) {
    if (this.config.hrefTarget != '' || this.config.hrefTarget != null) {
        for (var i=0; i < this.editArea.document.links.length; i++) {
            if (!this.editArea.document.links[i].target) {
                this.editArea.document.links[i].target = this.config.hrefTarget;
            }
        }
    }

    this.editArea.document.body.style.border = "";
    this.editArea.document.body.removeAttribute("contentEditable", 0);

    if (op == true) {
        var img = this.editArea.document.body.getElementsByTagName('img');
        for (i=0; i<img.length; i++) {
            if (img[i].src) {
                if (img[i].getAttribute("onload")) {
                    img[i].onload = 'javascript:addCaption(this)';
                }
            }
            else {
                img[i].removeAttribute("onload", "", 0);
            }
        }
    }

    var el = this.bodyOnly ? this.editArea.document.body : this.editArea.document.documentElement;
    var mydoc = GB.MSIE ? el.outerHTML : el.innerHTML;
    mydoc = mydoc.replace("BORDER-RIGHT: medium none; ", "");
    mydoc = mydoc.replace("BORDER-TOP: medium none; ", "");
    mydoc = mydoc.replace("BORDER-BOTTOM: medium none; ", "");
    mydoc = mydoc.replace("BORDER-LEFT: medium none; ", "");
    mydoc = mydoc.replace("BORDER-RIGHT: medium none", "");
    mydoc = mydoc.replace("BORDER-TOP: medium none", "");
    mydoc = mydoc.replace("BORDER-BOTTOM: medium none", "");
    mydoc = mydoc.replace("BORDER-LEFT: medium none", "");
    mydoc = mydoc.replace(" style=\"\"", "");
    return mydoc;
},

returnContents : function (mydoc) {
    this.editArea.document.body.contentEditable = true;
    if (this.inputForm && document.getElementById(this.inputForm))
        document.getElementById(this.inputForm).value = mydoc;
    return mydoc;
},

outputPlainText : function () {
    var mydoc = document.getElementById('plain_id'+this.oname).value;
    mydoc = mydoc.replace(/\n/g, '<br />');
    return this.returnContents(mydoc);
},

outputHTML : function () {
    if (GB.editorMode != 'rich') return this.outputPlainText();
    this.resetViewHTML();
    var mydoc = this.getContents(true);
    mydoc = mydoc.replace (/<META(.+?)name=generator>/ig, "");
    mydoc = mydoc.replace (/<link href=(.*?)>/ig, '');
    return this.returnContents(mydoc);
},

outputBodyHTML : function () {
    if (GB.editorMode != 'rich') return this.outputPlainText();
    var str = this.outputHTML();
    var spl = GB.MSIE ? "BODY" : "body";
    str = str.substr(str.indexOf("<"+spl) + 1);
    str = str.substr(str.indexOf(">") + 1);
    var tmp = str.split("</"+spl+">");
    str = tmp[0];
    return this.returnContents(str);
},

outputBodyText : function () {
    return (GB.MSIE) ? this.editArea.document.body.innerText :
        this.outputBodyHTML().replace(/<br>/ig, "\n").replace(/<[^>]+>/g, "");
},

resetViewHTML : function () {
    var chkViewHtml = document.getElementById("chkDisplayMode");
    if (chkViewHtml != null && chkViewHtml.checked) {
        chkViewHtml.checked = false;
        this.setDisplayMode();
    }
},

returnFalse : function () {
    this.resetViewHTML();
    this.editArea.focus();
    var img = this.editArea.document.body.getElementsByTagName('img');
    for (i=0; i<img.length; i++) {
        if (img[i].src) {
            if (img[i].getAttribute("onload")) {
                img[i].onload = 'true';
            }
        }
        else {
            img[i].removeAttribute("onload", "", 0);
            img[i].removeAttribute("className", "", 0);
        }
    }
    this.setEditorOpt();
    return false;
},

trimSpace : function (str) {
    str = str.replace (/^\s+/g, '');
    str = str.replace (/\s+$/g, '');
    str = str.replace (/\r\n/g, '');
    str = str.replace (/\n/g, '');
    return str;
},

strLength : function (str) {
    var len = str.length;
    var mbytes = 0;
    var i = 0;

    for (; i<len; i++) {
        var c = str.charCodeAt(i);
        if (c > 128) mbytes++;
    }

    return (len-mbytes) + (mbytes*2);
},

contentsLengthAll : function () {
    this.resetViewHTML();
    return this.outputHTML().length;
},

contentsLength : function () {
    this.resetViewHTML();
    var content = this.outputBodyHTML();
    content = this.trimSpace(content);

    if (!content || content == "")
        return 0;

    return this.strLength(content);
},

inputLength : function () {
    this.resetViewHTML();
    var content = this.trimSpace(this.outputBodyText());

    if (!content || content == "")
        return 0;

    return this.strLength(content);
},

setSelection : function () {
    this.selection = this._getSelection();
    this.selectionType = this._getSelectionType(this.selection);
},

dimension : function (boxName) {
    var tblPopup = eval(boxName).document.getElementById('tblPopup');
    document.getElementById(boxName).style.width = tblPopup.offsetWidth + 'px';
    document.getElementById(boxName).style.height = tblPopup.offsetHeight + 'px';
},

displayWindow : function (boxName) {
    this.boxHide();
    this.setSelection();
    eval(boxName).document.getElementById("CHEditor").value = this.oname;
    this.dimension(boxName);
    this.boxPosition(boxName);
    document.getElementById(boxName).style.zIndex = 2;
    document.getElementById(boxName).style.visibility = "visible";
    document.getElementById(boxName).focus();

    if (!GB.MSIE)
        document.getElementById(boxName).style.display = 'block';
    else
        document.getElementById(boxName).focus();

    if (this.config.popupAutoKill)
        document.getElementById(boxName).onmouseout = this.boxHide;

    this.popupWinClose();
},

boxPosition : function (boxName) {
    var tblPopup = eval(boxName).document.getElementById("tblPopup");
    var myTop = 0, myLeft = 0;

    if (this.editAreaWapper.offsetParent) {
        var tmpEl = this.editAreaWapper;
        while (tmpEl && tmpEl.tagName.toLowerCase() != "body") {
            myTop   += tmpEl.offsetTop;
            myLeft  += tmpEl.offsetLeft;
            tmpEl   = tmpEl.offsetParent;
        }
    }

    if (this.editAreaWapper.offsetHeight-tblPopup.offsetHeight > 0)
        document.getElementById(boxName).style.pixelTop=(myTop + (this.editAreaWapper.offsetHeight-tblPopup.offsetHeight)/2);
    else
        document.getElementById(boxName).style.pixelTop=(myTop + (this.editAreaWapper.offsetHeight-tblPopup.offsetHeight)/2);

    if (this.editAreaWapper.offsetWidth-tblPopup.offsetWidth > 0)
        document.getElementById(boxName).style.pixelLeft=(myLeft + (this.editAreaWapper.offsetWidth-tblPopup.offsetWidth)/2);
    else
        document.getElementById(boxName).style.pixelLeft=myLeft;
},

mouseOver : function (el) {
    el.style.background = this.selectedColor;
},

mouseOut : function (el) {
    el.style.background = this.editorPopupBgcolor;
},

windowPos : function (idImg, boxName) {
    var myLeft = 0;
    var myTop = 0;
    if (idImg.offsetParent) {
        while (idImg && idImg.tagName.toLowerCase() != "body") {
            myLeft += idImg.offsetLeft;
            myTop = idImg.offsetTop;
            idImg = idImg.offsetParent;
        }
    }
    myTop = myTop + 24;
    document.getElementById(boxName).style.left = myLeft + 'px';
    document.getElementById(boxName).style.top = myTop + 'px';
},

boxHide : function() {
    for (i=0; i < GB.popupIFrame.length; i++)
        if (document.getElementById(GB.popupIFrame[i]))
            document.getElementById(GB.popupIFrame[i]).style.visibility = 'hidden';
},

createWindow : function (width, content) {
    var str = '<style>'
        + 'body {margin:0px;padding:0px;border:0px;background-color:'+this.editorPopupBgcolor+';font-family:'+this.config.editorFontFace+'}'
        + '.dropdown {cursor:pointer}'
        + '</style>'
        + '<body onselectstart="return event.srcElement.tagName==\'INPUT\'" oncontextmenu="return false">'
        + '<table width="'+width+'" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;border:#8db3e5 1px solid;" id="tblPopup">'
        + '  <tr><td>'
        + content
        + '  </td></tr>'
        + '</table>'
        + '<input type="text" style="display:none" id="CHEditor" contentEditable="true">'
        + '</body>';

    return str;
},

setColorTable : function (_which) {
    var title = (_which == 'back') ? 'Çü±¤Ææ' : (_which == 'bgColor' ? '¹ÙÅÁ»ö' : '±ÛÀÚ»ö');
    var strCap =
        '<table cellpadding="0" cellspacing="0" width="100%" border="0">' +
        ' <tr style="height:20px;background:#8db3e5 url('+this.config.editorPath+'/icons/title_bar_bg.gif);">' +
        '   <td style="border-bottom:1px solid #8db3e5;padding:2px 0px 0px 2px;"><div style="font-size:9pt;color:#0E2C5D">'+title+'</div>'+
        '   </td>'+
        '   <td style="padding:2px 0px 0px 2px;text-align:right;border-bottom:1px solid #8db3e5;">' +
        '     <img src="'+this.config.editorPath+'/icons/close.gif" width="13" height="13" onclick="parent.'+this.oname+'.boxHide();" />&#160;'+
        '   </td>' +
        ' </tr>' +
        ' <tr>' +
        '   <td colspan="2">' +
        '     <table cellpadding="1" cellspacing="5" style="cursor: '+
        '         pointer;font-family:Verdana;font-size:7px;border:0px'+
        '         " bgcolor="#e3efff">'+
        '       <tr>'+
        '         <td colspan="10" id="cellColor" style="border:1px solid #000;height:20px;font-family:verdana;font-size:12px;text-align:center">¾øÀ½'+
        '         </td>'+
        '       </tr>';
    var colorRows = [strCap];
    var k = 0;
    var w = 14;
    var h = 10;
    var eCellColor = "document.getElementById('cellColor').style.backgroundColor";
    var cmd = (_which == 'back') ? ".setColor("+eCellColor+",'back')" :
        (_which == 'fore' ? ".setColor("+eCellColor+",'fore')" : ".setBgColor("+eCellColor+")");

    colorRows[colorRows.length] = '<div style="padding:1px">';

    for (var i = 0; i < w; i++) {
        colorRows[colorRows.length] = "<tr>";
        for (var j = 0; j < h; j++) {
            colorRows[colorRows.length] = '<td onmouseover="parent.'+this.oname+'.showColor(document.getElementById(\'cellColor\'),this)" '+
                'onclick="parent.'+this.oname+cmd+';" bgcolor="'+GB.colors[k]+'" style="border:1px solid #aaa;width:12px;">&#160;</td>';
            k++;
        }
        colorRows[colorRows.length] = "</tr>";
    }

    colorRows[colorRows.length] =
        '<tr>'+
        '  <td colspan="10" style="border:1px solid #000;height:15px;font-size:9pt;text-align:center; " '+
        '    onmouseover="parent.'+this.oname+'.showColor(document.getElementById(\'cellColor\'),this)" onclick="parent.'+this.oname+cmd+'">»ö»ó ¾øÀ½'+
        '  </td>'+
        '</tr>'+
        '</table>'+
        '</td></tr></table>';

    return colorRows.join("\n");
},

showColor : function (val, obj) {
    if (obj.bgColor)
        val.innerHTML = val.style.backgroundColor = obj.bgColor;
    else {
        val.innerHTML = '¾øÀ½';
        GB.MSIE ? val.style.removeAttribute('backgroundColor') : val.style.backgroundColor = "";
    }
},

doOnKeyPress : function () {
    var oEditor     = document.getElementById("id"+chutil.oname).contentWindow;
    var editArea    = document.getElementById("editArea_"+chutil.oname);
    var areaHeight  = parseInt(editArea.style.height);
    var key = oEditor.event.keyCode;
    if (key) {
        if (key == 13) {
            if (GB.autoHeight && oEditor.document.body.scrollHeight+40 > areaHeight)
                editArea.style.height = oEditor.document.body.scrollHeight+40+'px';
            if (document.getElementById('chkUseBR'+chutil.oname).checked == true && oEditor.event.shiftKey == false) {
                var sel = oEditor.document.selection.createRange();
                oEditor.event.returnValue = false;
                oEditor.event.cancelBubble = true;
                sel.pasteHTML('<br />');
                sel.select();
                sel.moveEnd("character", 1);
                sel.moveStart("character", 1);
                sel.collapse(false);
                return false;
            }
            else
                return oEditor.event.keyCode = 13;
        }
        if (GB.autoHeight && (key == 8 || key == 46) && oEditor.document.body.scrollHeight+30 < areaHeight)
            editArea.style.height = oEditor.document.body.scrollHeight+30+'px';
    }
},

drawToolbarIcon : function (iconBlock, top, iconWidth, id, toolTip, cmd) {
    document.write("<div style=\"text-align:left;float:left;margin:0px 2px 0px 0px;width:"+iconWidth+"px;height:24px;\">");
    document.write("<span unselectable=\"on\" style=\"cursor:pointer;position:absolute;clip:rect(0px "+iconWidth+"px 22px 0px);\">");

    switch (iconBlock) {
        case 1:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_1.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 2:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_2.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 3:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_3.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 4:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_4.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 5:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_5.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 6:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_6.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 7:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_7.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 8:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_8.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 9:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_9.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        case 10:
            document.write("<img id=\""+id+"\" title=\""+toolTip+"\" src=\""+this.config.editorPath+"/icons/toolbar_icon_10.gif\" style=\"position:absolute;top:-"+top+"px;width:"+iconWidth+"px;\" onmouseover=\""+this.oname+".toolbarButtonOver(this)\" onmouseout=\""+this.oname+".toolbarButtonOut(this)\" onmouseup=\""+cmd+"\">");
            break;
        default: break;
    }
    document.write("</span></div>");
},

popupWinLoad : function (url, popupWidth, popupHeight, szTitle) {
    var oTitle = document.getElementById('popupTitle');
    var container = this.editAreaWapper;
    var posLeft = container.offsetWidth;
    var posTop = (container.offsetHeight-popupHeight) > 0 ? container.offsetTop + (container.offsetHeight-popupHeight)/2 - 12:
        container.offsetTop;
    var offLeft = (container.offsetWidth-popupWidth) > 0 ? container.offsetLeft + (container.offsetWidth-popupWidth)/2 :
        container.offsetLeft;
    var dwindow = GB.popupID;

    dwindow.style.width = popupWidth+"px";
    dwindow.style.height = popupHeight+23+"px";
    dwindow.style.left = offLeft + 'px';
    dwindow.style.top = posTop + 'px';
    dwindow.style.zIndex = 100;

    var cframe = document.getElementById("cframe");
    var iframe = document.createElement("iframe");
    iframe.style.width = "100%";
    iframe.style.height = popupHeight+'px';
    iframe.style.border = "0px";
    iframe.frameBorder = 0;
    iframe.src = url;
    cframe.innerHTML = '';
    cframe.appendChild(iframe);
    dwindow.style.visibility = "visible";
    oTitle.innerHTML = szTitle;

    if (GB.MSIE) iframe.focus();
},

popupWinClose : function () {
    if (GB.popupID == null) return;
    GB.popupID.style.visibility = "hidden";
    document.getElementById("cframe").src = "";
    GB.popupID.style.zIndex = -1;
    this.editArea.focus();
    if (GB.MSIE && this.selection != null) this.selection.select();
},

windowOpen : function (_which) {
    var tmpl, w, h;
    var popupTitle = '';
    this.editArea.focus();
    this.boxHide();

    if (GB.MSIE) this.setSelection();

    switch (_which) {
    case "image" :
        tmpl = "insert_image.html";
        h = 390;
        w = 354;
        popupTitle = '±×¸² ³Ö±â';
        break;
    case "media" :
        tmpl = "insert_media.html";
        h = 480;
        w = 430;
        popupTitle = '¹Ìµð¾î';
        break;
    case "bgimage" :
        tmpl = "insert_bgimage.html";
        h = 190;
        w = 430;
        popupTitle = '¹è°æ ÀÌ¹ÌÁö';
        break;
    case "table" :
        tmpl = "insert_table.html";
        h = 460;
        w = 430;
        popupTitle = 'Å×ÀÌºí ¸¸µé±â';
        break;
    case "hyperLink" :
        tmpl = "insert_hlink.html";
        h = 145;
        w = 420;
        popupTitle = 'ÇÏÀÌÆÛ¸µÅ©';
        break;
    case "emotion" :
        tmpl = "insert_emicon.html";
        h = 210;
        w = 400;
        popupTitle = 'Ç¥Á¤ ¾ÆÀÌÄÜ';
        break;
    case "schar" :
        tmpl = "insert_schar.html";
        h = 180;
        w = 500;
        popupTitle = 'Æ¯¼ö ¹®ÀÚ';
        break;
    case "flash" :
        tmpl = "insert_flash.html";
        h = 295;
        w = 500;
        popupTitle = 'ÇÃ·¡½¬ ¹«ºñ';
        break;
    default:
        return;
    }

    tmpl = this.config.editorPath + '/' + tmpl;
    this.popupWinLoad(tmpl, w, h, popupTitle);
},

_getSelection : function() {
    return GB.MSIE ? this.editArea.document.selection.createRange() :
        this.editArea.getSelection();
},

_getSelectionType : function(selection) {
    return GB.MSIE ? this.editArea.document.selection.type :
        selection.getRangeAt(0).startContainer.nodeType;
},

undo : function () {
    this.editArea.focus();
    this.updateUndoQueue();
    if (this.undoPos > 0) {
        var txt = this.undoQueue[--this.undoPos];
        if (txt) {
            this.editAreaWapper.style.visibility = 'hidden';
            this.putContents(txt);
            this.editAreaWapper.style.visibility = 'visible';
        }
        else ++this.undoPos;
    }
    this.selection = null;
    this.setEditorOpt();
    if (this.config.showTagPath) cheditor.setEditorEvent(this.oname);
},

redo : function () {
    this.editArea.focus();
    if (this.undoPos < this.undoQueue.length - 1) {
        var txt = this.undoQueue[++this.undoPos];
        if (txt) {
            this.editAreaWapper.style.visibility = 'hidden';
            this.putContents(txt);
            this.editAreaWapper.style.visibility = 'visible';
        }
        else --this.undoPos;
    }
    this.setEditorOpt();
    if (this.config.showTagPath) cheditor.setEditorEvent(this.oname);
},

doCmd : function(cmd, opt) {
    this.popupWinClose();
    this.updateUndoQueue();
    this.selection = null;

    var oTarget;
    var selection = this._getSelection();
    var selectionType = this._getSelectionType(selection);

    if (GB.MSIE) {
        selection = this.fixSelection(selection);
        selectionType = this.fixSelectionType(selection, selectionType);
        oTarget = (selectionType == 'None') ? this.editArea.document : selection;
        selection.select();
    }
    else {
        var range;
        if (typeof selection != "undefined") {
            range = selection.getRangeAt(0);
        }
        else {
            range = this.editArea.document.createRange();
        }
        oTarget = this.editArea.document;
    }

    if (cmd.toLowerCase() == 'print') {
        this.editArea.print();
        return;
    }
    var pasteFromWord = false;
    if (cmd == 'PasteFromWord') {
        cmd = 'Paste';
        pasteFromWord = true;
    }

    if (!GB.MSIE && ((cmd == 'Cut') || (cmd == 'Copy') || (cmd == 'Paste'))) {
        try {
            oTarget.execCommand(cmd, false, opt);
        }
        catch (e) {
            var keyboard = '';
            var command = '';
            switch (cmd) {
                case 'Cut'  : keyboard = 'x'; command = 'ÀÚ¸£±â'; break;
                case 'Copy' : keyboard = 'c'; command = 'º¹»ç'; break;
                case 'Paste': keyboard = 'v'; command = 'ºÙÀÌ±â'; break;
            }
            alert('»ç¿ëÇÏ°í °è½Å ºê¶ó¿ìÀú¿¡¼­´Â \'' + command + '\' ¸í·ÉÀ» »ç¿ëÇÏ½Ç ¼ö ¾ø½À´Ï´Ù. \n' +
            'Å°º¸µå ´ÜÃàÅ°¸¦ ÀÌ¿ëÇÏ¿© ÁÖ¼¼¿ä. \(À©µµ »ç¿ëÀÚ: Ctrl + ' + keyboard + ', ¸ÆÅ²Åä½Ã »ç¿ëÀÚ: Apple + ' + keyboard + '\)')
        }
        this.editArea.focus();
        return;
    }

    try {
        if (pasteFromWord == true) {
            var editorTmp = eval("idtmp"+this.oname);
            editorTmp.document.execCommand("SelectAll");
            editorTmp.document.execCommand("Paste");
            selection.pasteHTML(this.cleanFromWord());
            selection.select();
        }
        else {
            oTarget.execCommand(cmd, false, opt);
        }
    }
    catch (e) {
        alert(cmd + ": Áö¿øµÇÁö ¾Ê´Â ¸í·ÉÀÔ´Ï´Ù.");
    }
    if (this.config.showTagPath) cheditor.setEditorEvent(this.oname);
},

cleanFromWord : function () {
    var editorTmp = eval("idtmp"+this.oname);
    for (var i=0; i < editorTmp.document.body.all.length; i++) {
        editorTmp.document.body.all[i].removeAttribute("className", "", 0);
        editorTmp.document.body.all[i].removeAttribute("style", "", 0);
    }
    var sHTML = editorTmp.document.body.innerHTML;
    var str = sHTML;
    var arrTmp = str.split('<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />');
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("<o:p>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("</o:p>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("<o:p>&nbsp;");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("<P>&nbsp;</P>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("<P>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("</P>");
    if (arrTmp.length > 1) str = arrTmp.join("<br>");
    var arrTmp = str.split("<STRONG>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    var arrTmp = str.split("</STRONG>");
    if (arrTmp.length > 1) str = arrTmp.join("");
    str = str.replace(/<\/?span(.*?)>/ig, '');
    str = str.replace(/<\/?font(.*?)>/ig, '');
    str = str.replace(/&nbsp;<br>/ig, "<br>");

    return str;
},

doCmdPaste : function(str) {
    if (GB.MSIE) {
        this.selection.select();
        if (this.selectionType == "Control") return;
        this.selection.pasteHTML(str);
    }
    else
        this.doCmd('insertHTML', str);
},

doCmdPopup : function(cmd, opt) {
    var target;
    var selection = this.selection;
    var selectionType = this.selectionType;

    if (GB.MSIE) {
        target = (selectionType == 'None') ? this.editArea.document : selection;
        selection.select();
    }
    else {
        var range =(typeof selection != "undefined") ? selection.getRangeAt(0) :
            this.editArea.document.createRange();
        target = this.editArea.document;
    }

    this.editArea.focus();

    try {
        target.execCommand(cmd, false, opt);
    }
    catch(e) {
        alert(cmd + ": Áö¿øµÇÁö ¾Ê´Â ¸í·ÉÀÔ´Ï´Ù.");
    }
    if (this.config.showTagPath) cheditor.setEditorEvent(this.oname);
    this.boxHide();
},

insideEditor : function(el) {
    while (el != null) {
        if (el.tagName.toLowerCase() == "body" && el.contentEditable == "true")
            return true;
        el = el.parentElement;
    }

    return false;
},

fixSelection : function(selection) {
    if (GB.MSIE) {
        if(selection.parentElement != null) {
            if(!this.insideEditor(selection.parentElement())) {
                this.editArea.focus();
                selection = this._getSelection();
            }
        }
        else {
            if(!this.insideEditor(selection.item(0))) {
                this.editArea.focus();
                selection = this._getSelection();
            }
        }
    }

    return selection;
},

fixSelectionType : function(selection, selectionType) {
    if (GB.MSIE) {
        if (selection.parentElement != null) {
            if (!this.insideEditor(selection.parentElement())) {
                this.editArea.focus();
                return this._getSelectionType();
            }
        }
        else {
            if (!this.insideEditor(selection.item(0))) {
                this.editArea.focus();
                return this._getSelectionType();
            }
        }
    }
}
};

cheditor.modifyImage = function (img, editBlock) {
    var a_align = new Array("baseline","top","middle","bottom","texttop","absmiddle","absbottom","left","right");
    var a_text = new Array("±âÁØ¼±","À§ÂÊ","°¡¿îµ¥","¾Æ·¡ÂÊ","¹®ÀÚ¿­ À§ÂÊ","¼±ÅÃ ¿µ¿ªÀÇ °¡¿îµ¥","¼±ÅÃ ¿µ¿ªÀÇ ¾Æ·¡ÂÊ","¿ÞÂÊ","¿À¸¥ÂÊ");
    if (img.hspace < 0) img.hspace = 0;
    if (img.vspace < 0) img.vspace = 0;
    if (img.border < 0 || img.border == '') img.border = 0;
    var htmlOutput = '<table cellpadding="0" cellspacing="0" border="0"><tr>' +
        '<td width="110"><font style="font-size:9pt">°¡·Î ÇÈ¼¿: <input type="text" size="3" style="font-size:9pt" value="'+img.width+'" id=n_width>&nbsp;</font>\n</td>' +
        '<td width="110"><font style="font-size:9pt">°¡·Î ¿©¹é: <input type="text" size="3" style="font-size:9pt" value="'+img.hspace+'" id=n_hspace>&nbsp;</font>\n</td>' +
        '<td width="200"><font style="font-size:9pt">Á¤·Ä: <select id="n_alignment" name="n_alignment" style="font-size:9pt">' +
        '<option value="">¾øÀ½</option>';
        for (var i=0; i<a_align.length; i++) {
            htmlOutput += '<option value='+a_align[i];
            if (img.align == a_align[i].toLowerCase()) htmlOutput += ' selected';
            htmlOutput += '>'+a_text[i]+'</option>';
        }

     htmlOutput += '</select><select id="n_alignment_caption" name="n_alignment_caption" style="display:none;font-size:9pt">'+
        '<option value="left">¿ÞÂÊ</option><option value="right">¿À¸¥ÂÊ</option></select></font></td>' +
        '<td>&nbsp;<font style="font-size:9pt">±¥¼± µÎ²²: <input type="text" size="1" style="font-size:9pt" value="'+img.border+'" id="n_border">&nbsp;</font>\n</td></tr>' +
        '<tr><td><font style="font-size:9pt">¼¼·Î ÇÈ¼¿: <input type="text" size="3" style="font-size:9pt" value="'+img.height+'" id="n_height">&nbsp;</font>\n</td>' +
        '<td><font style="font-size:9pt">¼¼·Î ¿©¹é: <input type="text" size="3" style="font-size:9pt" value="'+img.vspace+'" id="n_vspace">&nbsp;</font>\n</td>' +
        '<td colspan="2"><font style="font-size:9pt">¼³¸í: <input type="text" size="25" id="n_alt" style="font-size:9pt" value="'+img.alt+'">' +
        '&nbsp;<button style="height:21px;font-size:9pt;padding-top:2px" id="editimg">¼öÁ¤</button>' +
        '&nbsp;<input type="checkbox" id="isCaption" style="background-color:#a3d260">Ä¸¼Ç</font>\n</td></tr></table>';

    editBlock.innerHTML = htmlOutput;

    document.getElementById("isCaption").onclick = function() {
        if (document.getElementById("isCaption").checked) {
            document.getElementById("n_alignment_caption").style.display = '';
            document.getElementById("n_alignment").style.display = 'none';
        }
        else {
            document.getElementById("n_alignment_caption").style.display = 'none';
            document.getElementById("n_alignment").style.display = '';
        }
    };
    document.getElementById("editimg").onclick = function() {
        var n_width  = document.getElementById("n_width");
        var n_height = document.getElementById("n_height");
        var n_hspace = document.getElementById("n_hspace");
        var n_vspace = document.getElementById("n_vspace");
        var n_border = document.getElementById("n_border");
        var n_alt    = document.getElementById("n_alt");

        if (n_width.value == '' || n_width.value == null || n_width.value < 1) {
            alert("°¡·Î ÇÈ¼¿ Å©±â¸¦ ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À");
            return;
        }
        else if (n_height.value == '' || n_height.value == null || n_height.value < 1) {
            alert("¼¼·Î ÇÈ¼¿ Å©±â¸¦ ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿À");
            return;
        }
        else {
            var n_align  = '';
            if (document.getElementById("n_alignment").style.display != 'none') {
                n_align = document.getElementById("n_alignment");
            }
            else {
                n_align = document.getElementById("n_alignment_caption");
            }

            img.style.width  = parseInt(n_width.value);
            img.style.height = parseInt(n_height.value);

            if (parseInt(n_hspace.value) > 0) img.hspace = parseInt(n_hspace.value);
            else img.removeAttribute("hspace", "", 0);
            if (parseInt(n_vspace.value) > 0) img.vspace = parseInt(n_vspace.value);
            else img.removeAttribute("vspace", "", 0);
            if (n_border.value != '') {
                img.style.border = n_border.value+'px ' + GB.imageBorder;
                img.removeAttribute("border", "", 0);
            }
            else img.removeAttribute("border", "", 0);
            if (n_align.value != '')  img.align  = n_align.value ;
            else img.removeAttribute("align", "", 0);
            if (n_alt.value != '') img.alt = n_alt.value;
            else img.removeAttribute("alt", "", 0);

            if (document.getElementById("isCaption").checked) {
                var id = img.getAttribute("id");
                if (id) {
                    id = id.replace(/chimg/, 'thumb');
                    var lb = eval("id"+chutil.oname).document.getElementById(id);
                    if (lb) lb.onclick = 'return hs.run(this,\''+img.alt.replace(/\'/,'')+'\')';
                }
                img.className = 'chimg_photo';
                img.onload = 'true';
                alert('Ä¸¼ÇÀº ¿¡µðÅÍ ¾È¿¡¼­´Â º¸ÀÌÁö ¾Ê½À´Ï´Ù.\n±Û ÀÛ¼º ¿Ï·á ÈÄ HTML ÆäÀÌÁö »ó¿¡¼­ º¸ÀÔ´Ï´Ù.');
            }
            else {
                img.removeAttribute("className", "", 0);
                img.removeAttribute("onload", "", 0);
            }
        }
    };
};

cheditor.modifyCell = function (cell, statusbar) {
    while (cell != null && cell.tagName.toLowerCase() != "td") cell = cell.parentNode;

    var tbl = cell;
    var row = tbl;
    var editorPath = eval(chutil.oname).config.editorPath;

    while (tbl != null && tbl.tagName.toLowerCase() != "table") tbl = tbl.parentNode;
    while (row != null && row.tagName.toLowerCase() != "tr") row = row.parentNode;

    var t_width  = tbl.style.width  ? tbl.style.width  : tbl.width;
    var t_height = tbl.style.height ? tbl.style.height : tbl.getAttribute("height");
    var t_cellpadding = tbl.cellPadding;
    var t_cellspacing = tbl.cellSpacing;
    var t_bgcolor = tbl.getAttribute("bgcolor") ? tbl.bgColor : '';
    var t_bordercolor = tbl.getAttribute("bordercolor") ? tbl.getAttribute("bordercolor") : '';
    var t_border = tbl.getAttribute("border") ? tbl.border : '';
    var c_width = cell.getAttribute("width") ? cell.getAttribute("width") : '';
    var c_height = cell.getAttribute("height") ? cell.getAttribute("height") : '';
    var c_align = cell.getAttribute("align") ? cell.align : '';
    var c_bgcolor = cell.getAttribute("bgcolor") ? cell.bgColor : '';
    var is_ie = navigator.userAgent.toLowerCase().indexOf("msie") != -1;

    if (t_height == null) t_height = '';
    t_width = t_width.replace(/px/ig, '');
    t_height = t_height.replace(/px/ig, '');

    var html_output =   '<table cellpadding=0 cellspacing=0 style="margin-top:5px;">' +
                        '<tr><td><span style=font-size:9pt;>°¡·Î Æø: <input type=text size=4 value="'+t_width+'" id=n_width>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>¼¿ ÆÐµù: <input type=text size=1 value="'+t_cellpadding+'" id=n_cellpadding></span>\n</td>' +
                        '<td align="right"><span style=font-size:9pt;>Å×ÀÌºí ¹è°æ »ö: <input type=text size=6 value="'+t_bgcolor+'" id=n_bgcolor>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>Å×ÀÌºí Á¤·Ä: <select id=alignment style=font-size:9pt>' +
                        '<option value="">¾øÀ½' +
                        '<option value=left>¿ÞÂÊ' +
                        '<option value=center>°¡¿îµ¥' +
                        '<option value=right>¿À¸¥ÂÊ' +
                        '</select></span></td>' +
                        '</tr><tr>' +
                        '<td><span style=font-size:9pt;>¼¼·Î Æø: <input type=text size=4 value="'+t_height+'" id=n_height>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>¼¿ °£°Ý: <input type=text size=1 value="'+t_cellspacing+'" id=n_cellspacing></span>\n</td>' +
                        '<td align="right"><span style=font-size:9pt;>Å×ÀÌºí Å×µÎ¸® »ö: <input type=text size=6 value="'+t_bordercolor+'" id=n_bordercolor>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>Å×µÎ¸® µÎ²²: <input type=text size=1 value="'+t_border+'" id=n_border></span>\n</td>' +
                        '</tr><tr>' +
                        '<td><span style=font-size:9pt;>¼¿ °¡·Î: <input type=text size=4 value="'+c_width+'" id=c_width>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>°¡·Î Á¤·Ä: <select id=c_alignment style=font-size:9pt>' +
                        '<option value="">¾øÀ½' +
                        '<option value=left>¿ÞÂÊ' +
                        '<option value=center>°¡¿îµ¥' +
                        '<option value=right>¿À¸¥ÂÊ' +
                        '<option value=justify>¾çÂÊ' +
                        '</select></span></td>' +
                        '<td align="right"><span style=font-size:9pt;>¼¿ ¹è°æ »ö: <input type=text size=6 value="'+c_bgcolor+'" id=c_bgcolor>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>No Wrap:<input type=checkbox value="'+t_bgcolor+'" id=nowrap>&nbsp;</span>\n' +
                        '<button style="width:54px;height:21px;font-size:9pt;padding-top:2px" id="editcell">¼öÁ¤</button></td>' +
                        '</tr><tr>' +
                        '<td><span style=font-size:9pt;>¼¿ ¼¼·Î: <input type=text size=4 value="'+c_height+'" id=c_height>&nbsp;</span>\n</td>' +
                        '<td>&#160;<span style=font-size:9pt;>¼¼·Î Á¤·Ä: <select id=c_valignment style=font-size:9pt>' +
                        '<option value="">¾øÀ½' +
                        '<option value=top>À§ÂÊ' +
                        '<option value=middle>°¡¿îµ¥' +
                        '<option value=bottom>¾Æ·¡' +
                        '<option value=baseline>±âÁØ¼±' +
                        '</select></span></td>' +
                        '<td style=padding-left:12px colspan=2>' +
                        '<img align=absmiddle src='+editorPath+'/icons/increasecolspan.gif width=20 height=20 id=increasecolspan style=cursor:pointer title="ColSpan Áõ°¡">' +
                        '<img align=absmiddle src='+editorPath+'/icons/decreasecolspan.gif width=20 height=20 id=decreasecolspan style=cursor:pointer title="ColSpan °¨¼Ò ">' +
                        '<img align=absmiddle src='+editorPath+'/icons/increaserowspan.gif width=20 height=20 id=increaserowspan style=cursor:pointer title="RowSpan Áõ°¡">' +
                        '<img align=absmiddle src='+editorPath+'/icons/decreaserowspan.gif width=20 height=20 id=decreaserowspan style=cursor:pointer title="RowSpan °¨¼Ò ">&#160;&#160;&#160;&#160;' +
                        '<img align=absmiddle src='+editorPath+'/icons/addcol.gif width=20 height=20 id=addcol style=cursor:pointer title="Çà »ðÀÔ">&nbsp;' +
                        '<img align=absmiddle src='+editorPath+'/icons/addcols.gif width=20 height=20 id=addcols style=cursor:pointer title="¼¿ »ðÀÔ">&nbsp;' +
                        '<img align=absmiddle src='+editorPath+'/icons/removecol.gif width=20 height=20 id=removecol style=cursor:pointer title="Çà »èÁ¦">&nbsp;' +
                        '<img align=absmiddle src='+editorPath+'/icons/removecols.gif width=20 height=20 id=removecols style=cursor:pointer title="¼¿ »èÁ¦">&nbsp;' +
                        '<img align=absmiddle src='+editorPath+'/icons/addrow.gif width=20 height=20 id=addrows style=cursor:pointer title="¿­ »ðÀÔ">&nbsp;' +
                        '<img align=absmiddle src='+editorPath+'/icons/removerow.gif width=20 height=20 id=removerow style=cursor:pointer title="¿­ »èÁ¦">' +
                        '</td></tr></table>';

    statusbar.innerHTML = html_output;
    document.getElementById("nowrap").checked = cell.getAttribute("nowrap") ? true : false;

    if (tbl.getAttribute("align")) { document.getElementById("alignment").value = tbl.getAttribute("align"); }
    if (cell.getAttribute("align")) { document.getElementById("c_alignment").value  = cell.getAttribute("align"); }
    if (cell.getAttribute("valign")) { document.getElementById("c_valignment").value    = cell.getAttribute("valign"); }

    document.getElementById("editcell").onclick = function() {
        var n_width = document.getElementById("n_width");
        var n_height = document.getElementById("n_height");
        var n_align = document.getElementById("alignment");
        var n_cellpadding = document.getElementById("n_cellpadding");
        var n_cellspacing = document.getElementById("n_cellspacing");
        var n_bgcolor = document.getElementById("n_bgcolor");
        var n_border = document.getElementById("n_border");
        var n_bordercolor = document.getElementById("n_bordercolor");
        var c_width = document.getElementById("c_width");
        var c_height = document.getElementById("c_height");
        var c_bgcolor = document.getElementById("c_bgcolor");
        var c_align = document.getElementById("c_alignment");
        var c_valign = document.getElementById("c_valignment");

        tbl.border = parseInt(n_border.value);
        tbl.removeAttribute("width", 0);
        tbl.removeAttribute("height", 0);

        if (n_width.value) tbl.style.width = n_width.value;
        if (n_height.value > 0) tbl.style.height = n_height.value;

        tbl.cellPadding = n_cellpadding.value;
        tbl.cellSpacing = n_cellspacing.value;

        if (n_align.value != "") tbl.align = n_align.value;
        else if (tbl.getAttribute("align")) tbl.removeAttribute("align", 0);

        if (n_bgcolor.value) tbl.bgColor = n_bgcolor.value;
        else tbl.removeAttribute("bgcolor", 0);

        if (n_bordercolor.value) tbl.setAttribute("bordercolor", n_bordercolor.value);
        else tbl.removeAttribute("bordercolor", 0);

        if (c_width.value > 0) cell.width = c_width.value;
        if (c_height.value > 0) cell.height = c_height.value;

        cell.noWrap = document.getElementById("nowrap").checked ? true : false;

        if (c_align.value != "") cell.align = c_align.value;
        else cell.removeAttribute("align", 0);

        if (c_valign.value != "") cell.vAlign = c_valign.value;
        else cell.removeAttribute("valign", 0);

        if (c_bgcolor.value) cell.bgColor = c_bgcolor.value;
        else cell.removeAttribute("bgcolor", 0);
    }

    document.getElementById("increasecolspan").onclick = function() { cell.colSpan++; }
    document.getElementById("decreasecolspan").onclick = function() {
        if (cell.colSpan == 1) cell.removeAttribute("colspan", 0);
        else cell.colSpan = cell.colSpan - 1;
    }
    document.getElementById("increaserowspan").onclick = function() { cell.rowSpan++; }
    document.getElementById("decreaserowspan").onclick = function() {
        if (cell.rowSpan == 1) cell.removeAttribute("rowspan", 0);
        else cell.rowSpan = cell.rowSpan - 1;
    }
    document.getElementById("addcol").onclick = function() {
        for (var i=0; i<tbl.rows.length; i++) {
            var trow = tbl.rows.item(i);
            var col = trow.insertCell(cell.cellIndex);
            if (!GB.MSIE) {
                var br = document.createElement("");
                col.appendChild(br);
            }
        }
    }
    document.getElementById("addcols").onclick = function() {
        var col = row.insertCell(cell.cellIndex);
        if (!GB.MSIE) {
            var br = document.createElement("");
            col.appendChild(br);
        }
    }
    document.getElementById("removecol").onclick = function() {
        for (var i=0; i<tbl.rows.length; i++) {
            var trow = tbl.rows.item(i);
            trow.deleteCell(cell.cellIndex);
        }
    }
    document.getElementById("removecols").onclick = function() { row.deleteCell(cell.cellIndex); }
    document.getElementById("addrows").onclick = function() {
        var nrow = tbl.insertRow(row.rowIndex);
        var len = row.cells.length;
        for (var i=0; i<len; i++) {
            var td = nrow.insertCell(i);
            if (!GB.MSIE) {
                var br = document.createElement("");
                td.appendChild(br);
            }
        }
    }
    document.getElementById("removerow").onclick = function() { tbl.deleteRow(row.rowIndex); }
};

cheditor.setEditorEvent = function (oname) {
    var statusBar = document.getElementById("CHstatusBar"+oname);
    var modifyBlock = document.getElementById("CHModifyBlock"+oname);
    var oEditor = document.getElementById("id"+oname).contentWindow;
    var cmd, el, sel, rng, _parent, ancestors = [];

    if (GB.MSIE) {
        sel = oEditor.document.selection;
    }
    else {
        sel = oEditor.getSelection();
        if (typeof sel != "undefined") {
            try {
                rng = sel.getRangeAt(0);
            }
            catch(e) {
                rng = oEditor.document.createRange();
            }
        }
        else {
            rng = oEditor.document.createRange();
        }
    }

    if (GB.MSIE) {
        rng = sel.createRange();

        if (sel.type == "Text" || sel.type == "None") {
            _parent = rng.parentElement();
        }
        else if (sel.type == "Control") {
            _parent = rng.item(0);
        }
        else {
            _parent = oEditor.document.body;
        }
    }
    else try {
        _parent = rng.commonAncestorContainer;
        if (!rng.collapsed && rng.startContainer == rng.endContainer &&
            rng.startOffset - rng.endOffset < 2 && rng.startContainer.hasChildNodes())
        {
            _parent = rng.startContainer.childNodes[rng.startOffset];
        }

        while (_parent.nodeType == 3) {
            _parent = _parent.parentNode;
        }
    }
    catch (e) {
        _parent= null;
    }

    while (_parent && (_parent.nodeType == 1) && (_parent.tagName.toLowerCase() != 'body')) {
        ancestors.push(_parent);
        _parent = _parent.parentNode;
    }

    ancestors.push(oEditor.document.body);

    for (var i = ancestors.length; --i >= 0;) {
        el = ancestors[i];
        if (!el) countine;

        switch (el.tagName.toLowerCase()) {
            case "img" : cmd = "img"; break;
            case "td" : cmd = "td"; break;
            default : continue;
        }
    }

    switch (cmd) {
    case "img" :
        modifyBlock.style.display = "block";
        cheditor.modifyImage(el, modifyBlock);
        break;
    case "td" :
        modifyBlock.style.display = "block";
        cheditor.modifyCell(el, modifyBlock);
        break;
    default :
        modifyBlock.style.display = "none";
        modifyBlock.innerHTML = '';
    }

    if (statusBar) {
        var found = false, a;
        statusBar.innerHTML = '&lt;HTML&gt; &lt;BODY&gt; ';

        for (var i = ancestors.length; --i >= 0;) {
            el = ancestors[i];
            if (!el || el.tagName.toUpperCase() == 'HTML' || el.tagName.toUpperCase() == 'BODY')
                continue;
            var tag = el.tagName.toUpperCase();
            a = document.createElement("a");
            a.href = "#";
            a.el = el;
            a.style.color = 'blue';
            a.title = el.style.cssText;
            a.onmouseover = function () { this.style.textDecoration = 'none'; }
            a.onmouseout = function () { this.style.textDecoration = 'underline'; }
            a.onclick = function () {
                this.blur();
                cheditor.tagSelector(oEditor,this.el);
                document.getElementById("removeSelected").style.display = '';
                return false;
            };

            a.appendChild(document.createTextNode(tag));
            statusBar.appendChild(document.createTextNode('<'));
            statusBar.appendChild(a);
            statusBar.appendChild(document.createTextNode('> '));
            found = true;
        }

        if (found) {
            a = document.createElement("a");
            a.href = "#";
            a.style.color = 'red';
            a.id = "removeSelected";
            a.style.display = "none";
            a.onclick = function () {
                this.blur();
                oEditor.document.execCommand("Delete", false, false);
                oEditor.focus();
                cheditor.setEditorEvent(oname);
                return false;
            };

            a.appendChild(document.createTextNode('REMOVE'));
            statusBar.appendChild(a);
        }
    }
};

cheditor.tagSelector = function (oEditor, node) {
    var range;
    oEditor.focus();

    if (GB.MSIE) {
        range = oEditor.document.body.createTextRange();
        range.moveToElementText(node);
        range.select();
    }
    else {
        var selection = oEditor.getSelection();
        if (typeof selection != "undefined") {
            try {
                range = selection.getRangeAt(0);
            }
            catch(e) { range = oEditor.document.createRange(); }
        }
        else
            range = oEditor.document.createRange();

        range.selectNodeContents(node);
        selection.removeAllRanges();
        selection.addRange(range);
    }
};

