function FJInsertIcon(mt_icon_base) {
    var mt_icons = [
        [ "balloon_28.gif", "ハート", 16, 14 ],
        [ "balloon_29.gif", "ハート割れ", 16, 14 ],
        [ "balloon_30.gif", "ＯＫ", 16, 14 ],
        [ "balloon_31.gif", "ＮＧ", 16, 14 ],
        [ "balloon_32.gif", "まる", 16, 14 ],
        [ "balloon_33.gif", "バツ", 16, 14 ],
        [ "balloon_34.gif", "おんぷ", 16, 14 ],
        [ "balloon_35.gif", "おんぷ２", 16, 14 ],
        [ "balloon_36.gif", "ピカーン", 16, 14 ],
        [ "balloon_37.gif", "！", 16, 14 ],
        [ "balloon_38.gif", "？", 16, 14 ],
        [ "balloon_39.gif", "", 16, 14 ],
        [ "balloon_41.gif", "", 16, 14 ],
        [ "balloon_42.gif", "", 16, 14 ],
        [ "balloon_43.gif", "", 16, 14 ],
        [ "balloon_44.gif", "", 16, 14 ],
        [ "balloon_45.gif", "", 16, 14 ],
        [ "balloon_46.gif", "", 16, 14 ],
        [ "balloon_47.gif", "", 16, 14 ],
        [ "balloon_48.gif", "", 16, 14 ],
        [ "balloon_49.gif", "", 16, 14 ],
        [ "balloon_50.gif", "", 16, 14 ],
        [ "balloon_52.gif", "", 16, 14 ],
        [ "balloon_55.gif", "", 16, 14 ],
        [ "balloon_57.gif", "", 16, 14 ],
        [ "balloon_59.gif", "", 16, 14 ],
        [ "balloon_61.gif", "", 16, 14 ],
        [ "balloon_63.gif", "", 16, 14 ],
        [ "balloon_65.gif", "", 16, 14 ],
        [ "balloon_67.gif", "", 16, 14 ],
        [ "balloon_69.gif", "", 16, 14 ],
        [ "balloon_71.gif", "", 16, 14 ],
        [ "balloon_73.gif", "", 16, 14 ],
        [ "balloon_75.gif", "", 16, 14 ],
        [ "balloon_77.gif", "", 16, 14 ],
        [ "balloon_79.gif", "", 16, 14 ],
        [ "balloon_81.gif", "", 16, 14 ],
        [ "balloon_83.gif", "", 16, 14 ],
        [ "balloon_85.gif", "", 16, 14 ],
        [ "balloon_87.gif", "", 16, 14 ],
        [ "balloon_89.gif", "", 16, 14 ],
        [ "balloon_91.gif", "", 16, 14 ],
        [ "balloon_93.gif", "", 16, 14 ],
        [ "balloon_95.gif", "", 16, 14 ],
        [ "balloon_97.gif", "", 16, 14 ],
        [ "balloon_99.gif", "", 16, 14 ],
        [ "balloon_101.gif", "", 16, 14 ],
        [ "balloon_103.gif", "", 16, 14 ],
        [ "balloon_105.gif", "", 16, 14 ],
        [ "balloon_107.gif", "", 16, 14 ],
        [ "balloon_109.gif", "", 16, 14 ],
        [ "balloon_111.gif", "", 16, 14 ],
        [ "balloon_113.gif", "", 16, 14 ],
        [ "balloon_115.gif", "", 16, 14 ],
        [ "balloon_117.gif", "", 16, 14 ],
        [ "balloon_119.gif", "", 16, 14 ],
        [ "balloon_121.gif", "", 16, 14 ],
        [ "balloon_123.gif", "", 16, 14 ],
        [ "balloon_125.gif", "", 16, 14 ],
        [ "balloon_127.gif", "", 16, 14 ],
        [ "balloon_129.gif", "", 16, 14 ],
        [ "balloon_131.gif", "", 16, 14 ],
        [ "balloon_133.gif", "", 16, 14 ],
        [ "balloon_135.gif", "", 16, 14 ],
        [ "balloon_137.gif", "", 16, 14 ],
        [ "balloon_139.gif", "", 16, 14 ],
        [ "balloon_141.gif", "", 16, 14 ],
        [ "balloon_143.gif", "", 16, 14 ],
        [ "balloon_145.gif", "", 16, 14 ],
        [ "balloon_147.gif", "", 16, 14 ],
        [ "balloon_149.gif", "", 16, 14 ],
        [ "balloon_151.gif", "", 16, 14 ],
        [ "balloon_153.gif", "", 16, 14 ],
        [ "balloon_154.gif", "", 16, 14 ],
        [ "balloon_40.gif", "カミナリ", 16, 14 ],
        [ "emoji1.gif", "", 18, 10 ],
        [ "emoji2.gif", "", 9, 8 ],
        [ "emoji3.gif", "", 8, 8 ],
        [ "emoji36.gif", "", 8, 8 ],
        [ "emoji37.gif", "", 8, 8 ],
        [ "emoji42.gif", "", 8, 8 ],
        [ "emoji43.gif", "", 6, 8 ],
        [ "emoji41.gif", "", 6, 13 ],
        [ "emoji28.gif", "涙", 9, 15 ],
        [ "emoji4.gif", "サッカー", 12, 12 ],
        [ "emoji5.gif", "野球", 12, 12 ],
        [ "emoji32.gif", "プレゼント", 13, 14 ],
        [ "emoji30.gif", "きらきら", 11, 10 ],
        [ "emoji6.gif", "ビール", 15, 15 ],
        [ "emoji57.gif", "", 16, 13 ],
        [ "emoji49.gif", "", 26, 14 ],
        [ "emoji34.gif", "", 15, 15 ],
        [ "emoji35.gif", "", 12, 17 ],
        [ "emoji14.gif", "ニャンコ", 14, 13 ],
        [ "emoji15.gif", "雲", 20, 12 ],
        [ "emoji7.gif", "ハチ", 31, 13 ],
        [ "emoji27.gif", "ドア", 11, 17 ],
        [ "emoji8.gif", "自転車", 13, 9 ],
        [ "emoji50.gif", "", 23, 16 ],
        [ "emoji54.gif", "", 15, 16 ],
        [ "emoji55.gif", "", 17, 17 ],
        [ "emoji56.gif", "", 27, 17 ],
        [ "emoji51.gif", "", 20, 20 ],
        [ "emoji12.gif", "", 21, 19 ],
        [ "emoji13.gif", "", 20, 19 ]
/*
        [ "ファイル名", "説明", 幅, 高さ ],
        [ "ファイル名", "説明", 幅, 高さ ]
*/
    ];
    var i_file = 0;
    var i_alt = 1;
    var i_width = 2;
    var i_height = 3;

    this.insertToTextArea = function(v) {
        var e = document.getElementById('comment-text');
        if (document.selection) {
            e.focus();
            var range = document.selection.createRange();
            range.text = v;
        } else {
            var length = e.textLength;
            var start = e.selectionStart;
            var end = e.selectionEnd;
            if (end == 1 || end == 2) end = length;
            e.value = e.value.substring(0, start) + v + e.value.substr(end, length);
            e.selectionStart = start + v.length;
            e.selectionEnd = start + v.length;
        }
        e.focus();
    };

    this.insertIconEditor = function(i) {
        var i_html;

        if (app.editor.mode == 'iframe') {
            var id = "temp_id_for_retrieving_inserted_element_" + Unique.id();
            i_html = '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" id="' + id + '" />';
            var inserted = _insertHTML(i_html, false, id, true);
            if (inserted) {
                inserted.src = mt_icon_base + mt_icons[i][i_file];
            }
        }
        else {
            i_html = '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" />';
            app.editor.actual.setSelection(i_html);
        }
    };

    this.insertIconTag = function(i) {
        var i_html;

        i_html = '<img src="' + mt_icon_base + mt_icons[i][0] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" />';
        this.insertToTextArea(i_html);
    };

    this.insertIconMacro = function(i) {
        var i_html;

        i_html = ':' + mt_icons[i][0] + ':';
        this.insertToTextArea(i_html);
    };

    this.listIconsEditor = function() {
        var i;

        var editor = document.getElementById('editor-content-enclosure');
        var editorParent = editor.parentNode;
        var iconDiv = document.createElement('div');
        iconDiv.id = 'editor-content-iconbar';
        iconDiv.style.padding = '3px 10px';
        iconDiv.style.border = '1px solid #cccccc';
        iconDiv.style.borderTop = 'none';
        iconDiv.style.backgroundColor = '#f3f3f3';
        editorParent.insertBefore(iconDiv, editor);
        var spanElement = document.createElement('span');
        spanElement.id = 'editor_insert_icons';
        var html = '';
        for (i = 0; i < mt_icons.length; i++) {
            html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconEditor(' + i + ');" style="cursor : pointer;" />';
        }
        spanElement.innerHTML = html;
        iconDiv.appendChild(spanElement);
    };

    this.listIconsCommentForm = function(mode) {
        var i;
        var html = '';

        for (i = 0; i < mt_icons.length; i++) {
            if (mode == 'tag') {
                html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconTag(' + i + ');" style="cursor : pointer;" />';
            }
            else if (mode == 'macro') {
                html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconMacro(' + i + ');" style="cursor : pointer;" />';
            }
        }
        document.write(html);
    };

    _insertHTML = function(html, select, id, isTempId) {
        var editor = app.editor.actual;
        var selection = editor.getSelection();
        var inserted = null;
        if (selection.createRange) { // Internet Explorer (IE)
            var range = selection.createRange();
            if (selection.type == "None" || selection.type == "Text") {
                try {
                    range.pasteHTML(html);
                } catch (err) {
                    log("Error pasting html on selection of type 'Text' or 'None': " + err);                
                }
                if (defined(id)) {
                    inserted = editor.document.getElementById(id);
                    if(select) 
                        range.moveToElementText(inserted);
                } else {
                    if(range.moveStart) {
                        range.moveStart("character", ((html.length) * (-1)));
                        inserted = range.parentElement();
                    }
                }
                if (select) 
                    range.select();
            }
            else { // IE 'Control' selection    
                range.item(0).outerHTML = html;
                inserted = range.item(0); 
            }
        }
 
        // mozilla
        else if (selection.getRangeAt) {
            var range;
            if (selection.rangeCount)
                range = selection.getRangeAt(0);
            else {
                range = editor.document.createRange();
                range.setStart(editor.document.body, 0);
                range.setEnd(editor.document.body, 0);
                selection.addRange(range);
            }
            var anchor = range.startContainer;

            if (selection && range && editor.isCaretAtEnd(selection, range)) { 
                var paragraph = editor.document.createElement(editor.FORMAT_BLOCK_TAG);
                paragraph.insertBefore(editor.document.createElement("br"), null);
                editor.document.getElementsByTagName("body")[0].insertBefore(paragraph, null);
            } 

            if (select && anchor.nodeType == Node.TEXT_NODE && !html.match( /<[a-z][a-z]*\s/i)) {
                range.setStart(anchor, selection.anchorOffset);
                var insertNode = editor.document.createTextNode(html);
                range.insertNode(insertNode);
                var inserted = insertNode;
            }
            else {
                var pS = anchor.previousSibling;
                var nS = anchor.nextSibling;
                editor.document.execCommand("insertHTML", false, html);
                if(pS !== anchor.previousSibling)
                    inserted = anchor.previousSibling;
                else if(nS !== anchor.nextSibling)
                    inserted = anchor.nextSibling;
                else 
                    inserted = anchor.firstChild;
            }

            if (defined(id))
                inserted = editor.document.getElementById(id);
            if (inserted && inserted.tagName && inserted.tagName.toLowerCase() == "a")
                editor.tagJustInserted = true;
            if (select) {
                range.selectNode(inserted);
                editor.monitorSelection(); // Required for Mozilla for proper arrow keys on highlighted link.
            }
            selection.addRange(range);        
        }

        if(isTempId && inserted) {
            inserted.id = undefined;
            inserted.removeAttribute("id");
        }
        return inserted;
    };
}

