function update_data() {
    var Data = "First Name: " + $('#first_name').val()
               + "<br />Last Name: " + $('#last_name').val()
               + "<br />Email: " + $('#email').val()
               + "<br />Phone: " + $('#phone').val()
               + "<br />Description: " + $('#description').val();
    $('#email_message').val( Data );
}

$(document).ready(function() { 
    $('#emailer-form').ajaxForm({
        beforeSubmit: function(data, obj, opt) {
            // Start by disabling the send button.
            $('#send').attr("disabled", "disabled");
            $('#contact-status').css('display', 'block');
            var responseText='';
            
            // Do the validation.
            if ( !$('#first_name').val() ) {
                responseText += '<p>Please fill out the First Name field.</p>';
            }
            if ( !$('#last_name').val() ) {
                responseText += '<p>Please fill out the Last Name field.</p>';
            }
            if ( !$('#email').val() ) {
                responseText += '<p>Please enter a valid Email address.</p>';
            }
            if ( !$('#phone').val() ) {
                responseText += '<p>Please fill out the Phone field.</p>';
            }
            
            // Enable the buttons on the form again.
            $('#send').removeAttr("disabled","");

            // Copy the email address to the hidden field, for emailing.
            $('#email_from').val( $("#email").val() );

            // Copy contact details to the hidden field, for emailing.
            update_data();

            if (responseText) {
                $('#contact-status').html(responseText);
                return false;
            }
        },
        success: function(responseText, statusText) {
            if ( responseText.match(/Your email was successfully sent/) ) {
                // At this point, the form should have been successfully
                // sent to the recipient with the Emailer plugin.
                // So now, just send to Salesforce!
                $('#contact-form').submit();
            }
            else {
                // Still errors in the submission process--display them to the visitor.
                $('#contact-status').css('display', 'block');
                $('#contact-status').html(responseText);
            }
        }
    }); 
}); 
