var mt_icon_base = "http://画像のアップロード先のディレクトリ/";
var mt_icons = Array(
    Array("ファイル名", "説明", 幅, 高さ),
    Array("ファイル名", "説明", 幅, 高さ)
);

var i_file = 0;
var i_alt = 1;
var i_width = 2;
var i_height = 3;

function insertToTextArea (e, v) {
    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();
}

function insertIconTag(e, 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] + '" />';
    insertToTextArea(e, i_html);
}

function insertIconMacro(e, i)
{
    var i_html;

    i_html = ':' + mt_icons[i][0] + ':';
    insertToTextArea(e, i_html);
}

function listIcons(e, mode)
{
    var i;

    for (i = 0; i < mt_icons.length; i++) {
        if (mode == 'tag') {
            document.write('<a href="#" onclick="insertIconTag(' + e + ',' + i + ');" title="' + mt_icons[i][i_alt] + '">');
        }
        else if (mode == 'macro') {
            document.write('<a href="#" onclick="insertIconMacro(' + e + ',' + i + ');" title="' + mt_icons[i][i_alt] + '">');
        }
        document.write('<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] + '" /></a>');
    }
}