function hideSubmit(formData, jqForm, options) {
    var entry = $('#CompetitionEntry', jqForm).attr('value');

    if (!entry || entry == '') {
        alert('You must type your entry into the space provided. Please try again.');
        return false;
    }

    var agree = $('#CompetitionAgree', jqForm).attr('checked');

    if (!agree || agree != true) {
        alert('You must agree to the terms and conditions to enter.');
        return false;
    }

    $(".competitionsubmit").hide('slow');
}

function submitCompetition(competitionID) {
    $("form[competitionID='" + competitionID + "']").submit();
}

$(document).ready(function() {

    var textAreas = $('textarea.competitionentry');

    textAreas.css({
        "height": "50px",
        "min-height": "50px",
        "max-height": "200px",
        "line-height": "18px"
    });

    if (!$.browser.msie) {
        textAreas.autogrow({
            maxHeight: 200,
            minHeight: 50,
            lineHeight: 18
        });
    }

    $("form.competitionform").each(function() {

        var form = $(this);
        var competitionId = form.attr('competitionID');
        var counter = $('.competitioncounter', form);
        var options = {
            url: '/aspnet_client/microgroove/r/c.aspx',
            type: 'post',
            target: form,
            beforeSubmit: hideSubmit
        };

        form.ajaxForm(options);
        $('textarea.competitionentry', form).textlimit(counter, 256);
    });

});
