function contactForm() {
$('form#contact_form').submit(function() {
$('form#contact_form .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if(jQuery.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('You forgot to enter your '+labelText+'.');
hasError = true;
}
else if($(this).hasClass('email')) {
var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;
if(!emailReg.test(jQuery.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('You entered an invalid '+labelText+'.');
hasError = true;
}
}
});
if(!hasError) {
$('form#contact_form li.buttons button').fadeOut('normal', function() {
$(this).parent().append('
');
});
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contact_form').slideUp("fast", function() {
$(this).before('
Thanks! Your email was successfully sent. We should be in touch with you soon.
'); }); }); } return false; }); }