$(document).ready(function(){
    // Fade out success divs:
    $(".success").fadeOut(4000, function(){
            $(".success + br").remove();
    });

    // Pretty up the title bar:
    $("#heading h1").prepend("<span></span>");
    
    // Light weight form validation:
    $("form").submit(function() {
        // Clean up any previous validations, if any:
        $('.required,.dropdown,#tfAnswer,#mcChoices,#mcAnswer,#wpAnswers,#wpSensitivity').removeClass('formError');

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

        // Check for invalid dropdowns:
        var dropdowns = $('#'+$(this).attr("id")+' .required.dropdown').filter(function() {
            return this.value == '#'
            });
        dropdowns.each(function() {
            $(this).addClass('formError');
            abort = true;
        });

        // Check for empty textboxes:
        var emptyTextBoxes = $('#'+$(this).attr("id")+' .required').filter(function() {
            return this.value.length == 0;
        });
        emptyTextBoxes.each(function() {
            $(this).addClass('formError');
            abort = true;
        });

        // Check for non numeric fields:
        var nonNumeric = $('#'+$(this).attr("id")+' .required.numeric').filter(function() {
            return isNaN(this.value);
        });
        nonNumeric.each(function() {
            $(this).addClass('formError');
            abort = true;
        });

        if (abort == true){
            alert("Some fields were not filled out correctly. Please go back and ensure that all red form fields are filled out. Check the Help Icon next to each form field for details.");
            return false;
        } else {
            return true;
        }

    });
});