﻿$(document).ready(function() {

    function hideAll() {
        $("#name-error").hide();
        $("#phone-error").hide();
        $("#email-error").hide();
        $("#message-error").hide();
    }

    // Validates the form.
    function validate() {
        var name = $("input[name='name']").val();
        var phone = $("input[name='phone']").val();
        var email = $("input[name='email']").val();
        var message = $("#message").val();

        // Validate the name
        if (name.length == 0) {
            $("#name-error").show();
            return false;
        }

        // Validate the phone
        if (phone.length <= 0) {
            $("#phone-error").show();
            return false;
        }

        // Validate the email
        if (email.length <= 0) {
            $("#email-error").show();
            return false;
        }

        // Validate the message
        if (message.length <= 0) {
            $("#message-error").show();
            return false;
        }

    }

    // Register the "submit" button click event.
    $("input[type='submit']").click(function() {
        hideAll();
        return validate();
    });


});