//Comment JS
jQuery('#comment_button').click(
    function () {
        if (jQuery('#recaptcha_box').css('display') == 'none') {
            jQuery('#recaptcha_box').css('display', 'block');
        } else {
            //Attempt to post comment, use EVENT json output (see base.php)
            var data = {
                'name' : jQuery('#comment_name').val(),
                'recaptcha_challenge_field' : jQuery('#recaptcha_challenge_field').val(),
                'recaptcha_response_field' : jQuery('#recaptcha_response_field').val(),
                'comments' : jQuery('#comment_text').val()
            };
            
            for (k in data) {
                if (data[k] == '') {
                    alert('Comment Error: ' + k + ' is a required field');
                    return false;
                }
            }
            
            jQuery.post('/event/' + EVENT.event_id + '/comment', data, function(response){
                if (response === '1') {
                    jQuery('#comment_form').css('display', 'none');
                    jQuery('#comment_message').css('display', 'block').html('Comment successfully posted!');
                } else 
                    jQuery('#comment_message').css('display', 'block').html(response);
            });
        }
    }
);
jQuery('#comment_form').submit(function() {jQuery('#comment_button').click();});

