function ajax_comment(mode)
{
    if (mode == 'preview') {
        add_param = 'preview=Preview';
    }
    else {
        add_param = 'post=Post';
    }
    $("comment_result").innerHTML = '<p>感想を処理しています...　<img src="http://zou6.net/nendozou/img/ajax-loader.gif" width="16" height="16" alt="処理中" /></p>';
    $("comment_result").style.display = 'block';
    document.getElementById('comment-post').disabled = true;
    document.getElementById('comment-preview').disabled = true;
    var ajax_obj = new Ajax.Request('/cgi/mt33/mt-comments.cgi',
                                    { method : 'post',
                                      parameters : Form.serialize('comments_form') + '&' + add_param,
                                      onSuccess : comment_success,
                                      onFailure : comment_failure });
   return false;
}

function comment_success(obj)
{
    var text = obj.responseText;
    var regex = new RegExp("<!-- Posted -->", "");
    var loc_regex = new RegExp("post=(¥¥d*)", "");
    var link, num;

    if (document.comments_form.bakecookie.checked) {
        rememberMe(document.comments_form);
    }
    if (text.match(regex)) {
        link = location.protocol + "//" + location.host + location.pathname;
        if (location.search.match(loc_regex)) {
            num = parseInt(RegExp.$1) + 1;
            repl = "post=" + num;
            link += location.search.replace(loc_regex, repl);
        }
        else {
            link += location.search ? location.search + '&post=1' : '?post=1';
        }
        link += location.hash;
        location.href = link;
    }
    else {
        $("comment_result").innerHTML = obj.responseText;
    document.getElementById('comment-post').disabled = false;
    document.getElementById('comment-preview').disabled = false;
   }
}

function comment_failure(obj)
{
    $("comment_result").innerHTML = '投稿に失敗しました';
}

