var outputDivId = 'captcha_posted';
var outputProgress = 'progress';

// 認証リクエスト処理
function ajax_captcha(formId, divId, divProgress)
{
    outputDivId = divId;
    outputProgress = divProgress;

    // Ajaxローダーを表示します
    document.getElementById(outputProgress).style.display = '';
    var url    = 'http://magsl.net/ajaxcaptcha/captcha.php';
    var pars   = formId.txtCaptcha.name + "=" + encodeURIComponent(formId.txtCaptcha.value);
    var myAjax = new Ajax.Request(url, {
                                        method: 'post',
                                        parameters: pars,
                                        onComplete: ajax_captcha_complete
                                        }); 
    return false;
}

// リクエスト結果処理
function ajax_captcha_complete(RequestText)
{
    // Ajaxローダーを非表示します
    document.getElementById(outputProgress).style.display = 'none';
    // 認証結果を表示します
    document.getElementById(outputDivId).innerHTML = RequestText.responseText;
    if ( RequestText.responseText == "OK" )
    {

        // 認証チェックOKの場合の処理
        ajax_comment_post(outputDivId, outputProgress);
    }
    else
    {

        // 認証チェックNGの場合の処理

        // ここに認証エラーの場合に表示するメッセージを記述します
       document.getElementById(outputDivId).innerHTML = '<font color="#FF0000">認証コードが不正です。正しいコードを入力してください。</font>';

        // 認証エラーしたので、新しいCAPTCHA認証イメージを作成／表示します
        img = document.getElementById('imgCaptcha'); 
        img.src = 'http://magsl.net/ajaxcaptcha/create_image.php?' + Math.random();
    }
}
