// コメントにカスタマイズ絵文字入力機能：画像設定
function getCommentEmojiList() {
    var list = new Array();
    // 画像名、画像URLの設定
    list[list.length] = new Array('01w', 'http://kumanta.net/cgi/sb/balloon/balloon_01w.gif');
    list[list.length] = new Array('02w', 'http://kumanta.net/cgi/sb/balloon/balloon_02w.gif');
    list[list.length] = new Array('03w', 'http://kumanta.net/cgi/sb/balloon/balloon_03w.gif');
    list[list.length] = new Array('04w', 'http://kumanta.net/cgi/sb/balloon/balloon_04w.gif');
    list[list.length] = new Array('05w', 'http://kumanta.net/cgi/sb/balloon/balloon_05w.gif');
    list[list.length] = new Array('06w', 'http://kumanta.net/cgi/sb/balloon/balloon_06w.gif');
    list[list.length] = new Array('07w', 'http://kumanta.net/cgi/sb/balloon/balloon_07w.gif');
    list[list.length] = new Array('08w', 'http://kumanta.net/cgi/sb/balloon/balloon_08w.gif');
    list[list.length] = new Array('09w', 'http://kumanta.net/cgi/sb/balloon/balloon_09w.gif');
    list[list.length] = new Array('10w', 'http://kumanta.net/cgi/sb/balloon/balloon_10w.gif');
    list[list.length] = new Array('11w', 'http://kumanta.net/cgi/sb/balloon/balloon_11w.gif');
    list[list.length] = new Array('12w', 'http://kumanta.net/cgi/sb/balloon/balloon_12w.gif');
    list[list.length] = new Array('13w', 'http://kumanta.net/cgi/sb/balloon/balloon_13w.gif');
    list[list.length] = new Array('15w', 'http://kumanta.net/cgi/sb/balloon/balloon_15w.gif');
    list[list.length] = new Array('16w', 'http://kumanta.net/cgi/sb/balloon/balloon_16w.gif');
    list[list.length] = new Array('17w', 'http://kumanta.net/cgi/sb/balloon/balloon_17w.gif');
    list[list.length] = new Array('18w', 'http://kumanta.net/cgi/sb/balloon/balloon_18w.gif');
    list[list.length] = new Array('19w', 'http://kumanta.net/cgi/sb/balloon/balloon_19w.gif');
    list[list.length] = new Array('20w', 'http://kumanta.net/cgi/sb/balloon/balloon_20w.gif');
    list[list.length] = new Array('21w', 'http://kumanta.net/cgi/sb/balloon/balloon_21w.gif');
    list[list.length] = new Array('22w', 'http://kumanta.net/cgi/sb/balloon/balloon_22w.gif');
    list[list.length] = new Array('23w', 'http://kumanta.net/cgi/sb/balloon/balloon_23w.gif');
    list[list.length] = new Array('24w', 'http://kumanta.net/cgi/sb/balloon/balloon_24w.gif');
    list[list.length] = new Array('25w', 'http://kumanta.net/cgi/sb/balloon/balloon_25w.gif');
    list[list.length] = new Array('26w', 'http://kumanta.net/cgi/sb/balloon/balloon_26w.gif');
    list[list.length] = new Array('53w', 'http://kumanta.net/cgi/sb/balloon/balloon_53w.gif');
    list[list.length] = new Array('54w', 'http://kumanta.net/cgi/sb/balloon/balloon_54w.gif');
    list[list.length] = new Array('56w', 'http://kumanta.net/cgi/sb/balloon/balloon_56w.gif');
    list[list.length] = new Array('58w', 'http://kumanta.net/cgi/sb/balloon/balloon_58w.gif');
    list[list.length] = new Array('60w', 'http://kumanta.net/cgi/sb/balloon/balloon_60w.gif');
    list[list.length] = new Array('62w', 'http://kumanta.net/cgi/sb/balloon/balloon_62w.gif');
    list[list.length] = new Array('64w', 'http://kumanta.net/cgi/sb/balloon/balloon_64w.gif');
    list[list.length] = new Array('66w', 'http://kumanta.net/cgi/sb/balloon/balloon_66w.gif');
    list[list.length] = new Array('68w', 'http://kumanta.net/cgi/sb/balloon/balloon_68w.gif');
    list[list.length] = new Array('70w', 'http://kumanta.net/cgi/sb/balloon/balloon_70w.gif');
    list[list.length] = new Array('72w', 'http://kumanta.net/cgi/sb/balloon/balloon_72w.gif');
    list[list.length] = new Array('74w', 'http://kumanta.net/cgi/sb/balloon/balloon_74w.gif');
    list[list.length] = new Array('76w', 'http://kumanta.net/cgi/sb/balloon/balloon_76w.gif');
    list[list.length] = new Array('78w', 'http://kumanta.net/cgi/sb/balloon/balloon_78w.gif');
    list[list.length] = new Array('80w', 'http://kumanta.net/cgi/sb/balloon/balloon_80w.gif');
    list[list.length] = new Array('82w', 'http://kumanta.net/cgi/sb/balloon/balloon_82w.gif');
    list[list.length] = new Array('84w', 'http://kumanta.net/cgi/sb/balloon/balloon_84w.gif');
    list[list.length] = new Array('86w', 'http://kumanta.net/cgi/sb/balloon/balloon_86w.gif');
    list[list.length] = new Array('88w', 'http://kumanta.net/cgi/sb/balloon/balloon_88w.gif');
    list[list.length] = new Array('90w', 'http://kumanta.net/cgi/sb/balloon/balloon_90w.gif');
    list[list.length] = new Array('92w', 'http://kumanta.net/cgi/sb/balloon/balloon_92w.gif');
    list[list.length] = new Array('94w', 'http://kumanta.net/cgi/sb/balloon/balloon_94w.gif');
    list[list.length] = new Array('96w', 'http://kumanta.net/cgi/sb/balloon/balloon_96w.gif');
    list[list.length] = new Array('98w', 'http://kumanta.net/cgi/sb/balloon/balloon_98w.gif');
    list[list.length] = new Array('100w', 'http://kumanta.net/cgi/sb/balloon/balloon_100w.gif');
    list[list.length] = new Array('102w', 'http://kumanta.net/cgi/sb/balloon/balloon_102w.gif');
    list[list.length] = new Array('104w', 'http://kumanta.net/cgi/sb/balloon/balloon_104w.gif');
    list[list.length] = new Array('106w', 'http://kumanta.net/cgi/sb/balloon/balloon_106w.gif');
    list[list.length] = new Array('108w', 'http://kumanta.net/cgi/sb/balloon/balloon_108w.gif');
    list[list.length] = new Array('110w', 'http://kumanta.net/cgi/sb/balloon/balloon_110w.gif');
    list[list.length] = new Array('112w', 'http://kumanta.net/cgi/sb/balloon/balloon_112w.gif');
    list[list.length] = new Array('114w', 'http://kumanta.net/cgi/sb/balloon/balloon_114w.gif');
    list[list.length] = new Array('116w', 'http://kumanta.net/cgi/sb/balloon/balloon_116w.gif');
    list[list.length] = new Array('118w', 'http://kumanta.net/cgi/sb/balloon/balloon_118w.gif');
    list[list.length] = new Array('120w', 'http://kumanta.net/cgi/sb/balloon/balloon_120w.gif');
    list[list.length] = new Array('122w', 'http://kumanta.net/cgi/sb/balloon/balloon_122w.gif');
    list[list.length] = new Array('124w', 'http://kumanta.net/cgi/sb/balloon/balloon_124w.gif');
    list[list.length] = new Array('126w', 'http://kumanta.net/cgi/sb/balloon/balloon_126w.gif');
    list[list.length] = new Array('128w', 'http://kumanta.net/cgi/sb/balloon/balloon_128w.gif');
    list[list.length] = new Array('130w', 'http://kumanta.net/cgi/sb/balloon/balloon_130w.gif');
    list[list.length] = new Array('132w', 'http://kumanta.net/cgi/sb/balloon/balloon_132w.gif');
    list[list.length] = new Array('134w', 'http://kumanta.net/cgi/sb/balloon/balloon_134w.gif');
    list[list.length] = new Array('136w', 'http://kumanta.net/cgi/sb/balloon/balloon_136w.gif');
    list[list.length] = new Array('138w', 'http://kumanta.net/cgi/sb/balloon/balloon_138w.gif');
    list[list.length] = new Array('140w', 'http://kumanta.net/cgi/sb/balloon/balloon_140w.gif');
    list[list.length] = new Array('142w', 'http://kumanta.net/cgi/sb/balloon/balloon_142w.gif');
    list[list.length] = new Array('144w', 'http://kumanta.net/cgi/sb/balloon/balloon_144w.gif');
    list[list.length] = new Array('146w', 'http://kumanta.net/cgi/sb/balloon/balloon_146w.gif');
    list[list.length] = new Array('148w', 'http://kumanta.net/cgi/sb/balloon/balloon_148w.gif');
    list[list.length] = new Array('150w', 'http://kumanta.net/cgi/sb/balloon/balloon_150w.gif');
    list[list.length] = new Array('152w', 'http://kumanta.net/cgi/sb/balloon/balloon_152w.gif');
    return list;
}

function getCustmizeEmojiAttribute() {
    // 画像タグに含める属性値（alt属性以外）
    var att = 'border="0" style="vertical-align:middle"';

    // ***************** 設定ここまで *****************
    att = (att != '') ? (' ' + att) : '';
    return att;
}

function writeCustmizeEmojiTagList(textarea) {

    // ***************** 設定ここまで *****************
    var list = getCommentEmojiList();
    var att = getCustmizeEmojiAttribute();
    for (var i = 0; i < list.length; i++) {
        window.document.write('<a href="javascript:;" onClick="addCustmizeEmoji(' + textarea + ', \'' + list[i][0] + '\');"><img src="' + list[i][1] + '"' + att + ' alt="' + list[i][0] + '" /></a>');
    }
}

// reference from jugem.jp (c)
function addCustmizeEmoji(obj, tag) {
    var item = '[' + tag + ']';
    if (document.selection) {
        obj.focus();
        sel = document.selection.createRange();
        sel.text = item;
    } else if (obj.selectionStart || obj.selectionStart == '0') {
        var startPos = obj.selectionStart;
        var endPos = obj.selectionEnd;
        obj.value = obj.value.substring(0, startPos) + item + obj.value.substring(endPos, obj.value.length);
    } else {
        obj.value += item;
    }
}
// コメントにカスタマイズ絵文字入力機能：画像変換
function changeCustmizeEmojiTag(commentAreaIdName, commentAreaTag, commentBodyClassName) {

    // ***************** 設定ここまで *****************
    var list = getCommentEmojiList();
    var att = getCustmizeEmojiAttribute();
    var objComArea;
    var classComArea;
    var objComBody = new Array();
    if (commentAreaIdName != '') {
        objComArea = document.getElementById(commentAreaIdName);
        if (!objComArea || !objComArea.innerHTML) return;
        classComArea = objComArea.getElementsByTagName(commentAreaTag);
    } else {
        classComArea = document.getElementsByTagName('*');
    }
    for (var i = 0; i < classComArea.length; i++) {
        if (classComArea[i].className == commentBodyClassName) objComBody[objComBody.length] = classComArea[i];
    }
    for (var i = 0; i < objComBody.length; i++) {
        objComBody[i].innerHTML = getStringCustmizeEmojiTag(list, objComBody[i].innerHTML, att);
    }
}

function getStringCustmizeEmojiTag(list, s, att) {
    for (var i = 0; i < list.length; i++) {
        s = s.split('[' + list[i][0] + ']').join('<img src="' + list[i][1] + '"' + att + ' alt="' + list[i][0] + '" class="emoji" />');
    }
    return s;
}
