$(function() {
 	$("#submit").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	var name = $("input#name").val();
	
	var email = $("input#email").val();
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

	if (email == "") {
    	$("div#enter_email").show();
    	$("input#email").focus();
    	return false;
    } else if(!emailReg.test(email)) {
    	$("div#email_error").show();
    	$("input#email").focus();
    	return false;
	}
    
    var company = $("input#company").val();
    
    var messagebox = $("textarea#messagebox").val();
		if (messagebox == "") {
    	$("div#messagebox_error").show();
    	$("textarea#messagebox").focus();
    	return false;
    }
	
	var dataString = 'name='+ name + '&email=' + email + '&company=' + company + '&messagebox=' + messagebox;
	$.ajax({
    	type: "POST",
    	url: "/PHPMailer_v5.0.2/process.php",
    	data: dataString,
    	success: function() {
        	$('#emailform').html("<div id='message'></div>");
        	$('#message').html("<h4>Request sent</h4>")
        	.append("<p>You will receive an email shortly.</p>")
        	.hide()
        	.fadeIn(1500);
      	}
    });
    return false;
	});
});
