function FJInsertIcon(mt_icon_base, position) {
    var mt_icons = [
        [ "m022.gif", "中くらいハート", 11, 11 ],
        [ "m025.gif", "小さいハート", 11, 11 ],
        [ "m020.gif", "大きいハート", 11, 11 ],
        [ "m023.gif", "影つき小さいハート", 11, 11 ],
        [ "m024.gif", "小さいハート２", 11, 11 ],
        [ "m031.gif", "ブローケンハート", 11, 11 ],
        [ "m027.gif", "赤い音符", 11, 11 ],
        [ "m028.gif", "青い音符", 11, 11 ],
        [ "m029.gif", "緑の音符", 11, 11 ],
        [ "m030.gif", "黒い音符", 11, 11 ],
        [ "m001.gif", "ハート", 11, 11 ],
        [ "m002.gif", "タラ～", 11, 11 ],
        [ "m003.gif", "急げ", 11, 11 ],
        [ "m004.gif", "アセアセ", 11, 11 ],
        [ "m032.gif", "温泉", 11, 11 ],
        [ "m033.gif", "キラキラ", 11, 11 ],
        [ "m034.gif", "キラキラ２", 11, 11 ],
        [ "m035.gif", "おやすみ", 11, 11 ],
        [ "m036.gif", "チューリップ", 11, 11 ],
        [ "m037.gif", "桜", 11, 11 ],
        [ "m038.gif", "キスマーク", 11, 11 ],
        [ "m039.gif", "グー", 11, 11 ],
        [ "m041.gif", "パー", 11, 11 ],
        [ "m043.gif", "チョキ", 11, 11 ],
        [ "m045.gif", "PC", 11, 11 ],
        [ "m046.gif", "お手紙", 11, 11 ],
        [ "m047.gif", "電話", 11, 11 ],
        [ "m048.gif", "携帯", 11, 11 ],
        [ "m049.gif", "！", 11, 11 ],
        [ "m050.gif", "！？", 11, 11 ],
        [ "m051.gif", "!!", 11, 11 ],
        [ "m052.gif", "?", 11, 11 ],
        [ "m056.gif", "お茶", 11, 11 ],
        [ "m060.gif", "エンピツ", 11, 11 ],
        [ "m061.gif", "本", 11, 11 ],
        [ "m062.gif", "書類", 11, 11 ],
        [ "m063.gif", "ふきだしのハート", 11, 11 ],
        [ "m064.gif", "ふきだしのアセ", 11, 11 ],
        [ "m066.gif", "ふきだしの!", 11, 11 ],
        [ "m067.gif", "Yes", 11, 11 ],
        [ "m068.gif", "No", 11, 11 ],
        [ "m069.gif", "ふきだし音符", 11, 11 ],
        [ "m065.gif", "ふきだし双葉", 11, 11 ],
        [ "m070.gif", "う○ち", 11, 11 ],
        [ "m072.gif", "黄色い花", 11, 11 ],
        [ "m073.gif", "はさみ", 11, 11 ],
        [ "m075.gif", "足跡", 11, 11 ],
        [ "m078.gif", "おにぎり", 11, 11 ],
        [ "m079.gif", "カクテル", 11, 11 ],
        [ "m080.gif", "ビール", 11, 11 ],
        [ "m081.gif", "お願い", 11, 11 ],
        [ "m082.gif", "心よりお願い", 11, 11 ],
        [ "m083.gif", "急げ", 11, 11 ],
        [ "m092.gif", "マウス", 11, 11 ],
        [ "m093.gif", "日本酒", 11, 11 ],
        [ "m094.gif", "日本茶", 11, 11 ],
        [ "m095.gif", "さくらんぼ", 11, 11 ],
        [ "m096.gif", "アップ", 11, 11 ],
        [ "m097.gif", "ダウン", 11, 11 ],
        [ "m101.gif", "ニコニコ", 11, 11 ],
        [ "m102.gif", "ニコ", 11, 11 ],
        [ "m103.gif", "エヘ", 11, 11 ],
        [ "m104.gif", "あらま", 11, 11 ],
        [ "m105.gif", "二ヒヒ", 11, 11 ],
        [ "m106.gif", "目がハート", 11, 11 ],
        [ "m107.gif", "ダメ～", 11, 11 ],
        [ "m108.gif", "タラ～", 11, 11 ],
        [ "m109.gif", "アセッ", 11, 11 ],
        [ "m110.gif", "う～ん", 11, 11 ],
        [ "m111.gif", "ちょっと悲しい", 11, 11 ],
        [ "m112.gif", "涙～", 11, 11 ],
        [ "m141.gif", "りんご", 11, 11 ],
        [ "m142.gif", "イチゴ", 11, 11 ],
        [ "m146.gif", "双葉", 11, 11 ],
        [ "m148.gif", "ヒヨコ", 11, 11 ],
        [ "m169.gif", "ブドウ", 11, 11 ],
        [ "m171.gif", "ハンバーガー", 11, 11 ],
        [ "m172.gif", "ネコ", 11, 11 ],
        [ "m173.gif", "ピンクのバニー", 11, 11 ],
        [ "m174.gif", "ラップトップ", 11, 11 ],
        [ "m175.gif", "カメラ", 11, 11 ],
        [ "m176.gif", "プレゼント", 11, 11 ],
        [ "m178.gif", "芽が出た", 11, 11 ],
        [ "m179.gif", "カード・しおり", 11, 11 ],
        [ "m180.gif", "お魚", 11, 11 ],
        [ "m183.gif", "ピル", 11, 11 ],
        [ "m184.gif", "フィルム", 11, 11 ],
        [ "m201.gif", "きのこ", 11, 11 ],
        [ "m203.gif", "飴", 11, 11 ],
        [ "m204.gif", "クリスマスリース", 11, 11 ],
        [ "m207.gif", "クリスマスツリー", 11, 11 ],
        [ "m208.gif", "☆", 11, 11 ],
        [ "m209.gif", "ドクロ", 11, 11 ],
        [ "m448.gif", "病院", 11, 11 ],
        [ "m211.gif", "車", 11, 11 ],
        [ "m212.gif", "ケーキ", 11, 11 ],
        [ "m213.gif", "ベル", 11, 11 ],
        [ "m214.gif", "王冠", 11, 11 ],
        [ "m447.gif", "初心者マーク", 11, 11 ],
        [ "m215.gif", "雪の結晶", 11, 11 ],
        [ "m216.gif", "雨", 11, 11 ],
        [ "m217.gif", "頭にきた！？", 11, 11 ],
        [ "m218.gif", "曇り", 11, 11 ],
        [ "m445.gif", "晴れ", 11, 11 ],
        [ "m446.gif", "かみなり", 11, 11 ],
        [ "m219.gif", "雪", 11, 11 ],
        [ "m220.gif", "十字架", 11, 11 ],
        [ "m221.gif", "食事", 11, 11 ],
        [ "m222.gif", "みかん", 11, 11 ],
        [ "m223.jpg", "おばけ", 11, 11 ],
        [ "m225.gif", "コマ", 11, 11 ],
        [ "m228.gif", "鏡餅", 11, 11 ],
        [ "m232.gif", "にわとり", 11, 11 ],
        [ "m240.gif", "爆弾", 11, 11 ],
        [ "m241.gif", "ご飯", 11, 11 ],
        [ "m242.gif", "鍵", 11, 11 ],
        [ "m244.gif", "電球", 11, 11 ],
        [ "m245.gif", "ゴミ箱", 11, 11 ],
        [ "m246.gif", "おだんご", 11, 11 ],
        [ "m249.gif", "目覚まし時計", 11, 11 ],
        [ "m251.gif", "歯", 11, 11 ],
        [ "m260.gif", "ムービー", 11, 11 ],
        [ "m262.gif", "指輪", 11, 11 ],
        [ "m271.gif", "目玉焼き", 11, 11 ],
        [ "m274.gif", "パイナップル", 11, 11 ],
        [ "m288.gif", "カート", 11, 11 ],
        [ "m010.gif", "霧", 11, 11 ],
        [ "m011.gif", "ぐるぐる", 11, 11 ],
        [ "m012.gif", "傘", 11, 11 ],
        [ "m013.gif", "家", 11, 11 ],
        [ "m018.gif", "夕方", 11, 11 ],
        [ "m019.gif", "朝", 11, 11 ],
        [ "m076.gif", "右左", 11, 11 ],
        [ "m077.gif", "上下", 11, 11 ],
        [ "m144.gif", "クリップ", 11, 11 ],
        [ "m159.gif", "注意", 11, 11 ],
        [ "m300.gif", "おしまい", 11, 11 ]

/*
        [ "ファイル名", "説明", 幅, 高さ ],
        [ "ファイル名", "説明", 幅, 高さ ]
*/
    ];
    var i_file = 0;
    var i_alt = 1;
    var i_width = 2;
    var i_height = 3;
    var toolbarPosition = position;

    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';
        if (toolbarPosition == 1) {
            editorParent.insertBefore(iconDiv, editor);
        }
        else if (toolbarPosition == 2) {
            editorParent.appendChild(iconDiv);
        }
        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;
    };
}

