$(document).ready(function(){
    var requiredText = '&nbsp;<span style="font-weight:bold; color: red;">*</span>';

    $('.required').prev('label').append(requiredText);
    $('select[class!="noValidate"]:visible').prev('label').append(requiredText);

    $("form").submit(function(event) {

        // Clean up any previous validations, if any:
        $(this).find('.required,select,input').removeClass('formError');

        // Flag to submit the page or not:
        abort = false;

        // Check for invalid dropdowns:
        var dropdowns = $(this).find('select[class!="noValidate"]:visible').filter(function() {
            return this.value == '#'
        });

        // Then mark those dropdowns:
        dropdowns.each(function() {
            // Add the form error to the dropdown:
            $(this).addClass('formError');

            // What is the name of this item?
            var item = $(this).attr('name');

            // And raise the abort flag!
            abort = true;
        });

        // Check for empty textboxes:
        var emptyTextBoxes = $(this).find('.required').filter(function() {
            return this.value.length == 0;
        });

        emptyTextBoxes.each(function() {
            $(this).addClass('formError');
            abort = true;
        });

        // Don't proceed if we have to abort:
        if (abort == true){
            alert ('Please ensure you have filled out or made a selection for each form field marked with a red border, and try again.');
            return false;
        } else {
            return true;
        }
    });
});
