var captcha = {};

captcha.removeErrors = function(event) {
    if ($(this).hasClass("error-captcha")) {
        $(this).removeClass("error-captcha");
        $(this).val("");
    }
}

captcha.redisplayCaptcha = function(capidn, caplink) {
    if (!utils.cookies_enabled()) {
        caplink = "#";
    }
    $(capidn).attr('src', caplink + "?stamp=" + new Date().getTime());
}


captcha.displayError = function(capidn, error) {
    $(capidn).val(error);
    $(capidn).addClass("error-captcha");
}


captcha.cleanup = function(capidn) {
    $(capidn).val("");
    $(capidn).removeClass("error-captcha");
}


$(document).ready(function() {
    $("#captcha-subscription").focus(captcha.removeErrors);
    $("#id_captcha").focus(captcha.removeErrors);
    $("#captcha").focus(captcha.removeErrors);
    if (!utils.cookies_enabled()) {
        captcha.redisplayCaptcha('#captcha-image', '#');
        captcha.displayError('#id_captcha', 'ERROR');
        captcha.displayError('#captcha-subscription', 'ERROR');
    }
});
