
function reloadCaptcha() {
    $('image-captcha').set('src', '/captcha/view.php?rand=' + String(Math.random()));
}

function setErrorCaptcha() {
    $('error-captcha').set('text', 'Please enter the characters\nabove to file your report');
}

function removeErrorCaptcha() {
    $('error-captcha').set('text','');
}

function checkComment() {
    var ret = true;
    if ($('user').get('value').length < 3) {
        $('error-user').set('text', 'Sorry, but at least 3 characters are required in the user name');
        ret = false;
    } else if ($('user').get('value').length > 32) {
        $('error-user').set('text', 'Sorry, but maximum 32 characters are allowed in the user name');
        ret = false;
    } else {
       $('error-user').set('text', ''); 
    }
    
    if ($('comment').get('value').length < 20) {
        $('error-content').set('text', 'Sorry, but at least 20 characters are required in the comment box');
        ret = false;
    } else {
       $('error-content').set('text', ''); 
    }
    
    return ret;
}
function addComment() {
    $('form-comment').submit();
}

function checkCaptcha() {
    var myRequest = new Request({method: 'get', url: '/ajax/checkcaptcha.php'});
    var captcha = $('captcha').value;
    myRequest.onSuccess = function (text, xml) {if (text == 1) { 
                                                    removeErrorCaptcha();
                                                    if (checkComment()) {
                                                        addComment(); 
                                                    }
                                                } else { 
                                                     reloadCaptcha();
                                                     setErrorCaptcha();
                                                     checkComment();
                                                } 
                                    };
    
    myRequest.send('captcha=' + captcha);

}

function showSpam(id) {
    $("spam_" + id).dispose();
    $("comment_" + id).set('class', 'comment');
}
