$(function() {
	//make sure error messages are hidden
	$('.error').hide();
	
	//now, let's set logic for input feild styles
	$('.text').focus(function(){
		$(this).addClass("onfocus");
		$(this).removeClass("onfail");
	});
	$('.text').blur(function(){
		$(this).removeClass("onfocus");
	});
	
	$(".btn_submit_contact").click(function() {
		// validate and process the form
		// first hide any error messages
		$('.error').hide();
		
		//next, let's set our required feild variables
		var name = $("input#name").val();
		var email = $("input#email").val();
		var comments = $("textarea#comments").val();
		var contact = $("#contact_email").val();
		var location = $("#loc").val();
		
		//we need some extra variables for email validation
		var at = "@";
		var dot = ".";
		
		if (name == "") {
			$("input#name").addClass("onfail");
		}
		if (email == "" || email.indexOf(at)==-1 || email.indexOf(dot)==-1) {
			$("input#email").addClass("onfail");
		}
		if (comments == "") {
			$("textarea#comments").addClass("onfail");
		}
		//if something is missing, don't process the form
		if (name == "" || email == "" || email.indexOf(at)==-1 || email.indexOf(dot)==-1 || comments == "") {
			return false;
		}
		
		//if all is good, then create a datastring with the values
		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments + '&contact=' + contact + '&location=' + location;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "http://shawscrabhouse.com/wp-content/themes/shaws/new_contact.php",
			data: dataString,
			success: function() {
				$('#contact-form').html('<p style="padding: 10px;">THANK YOU!<br/>One of our managers will be getting back to you shortly.</p>').hide().fadeIn(1500, function() {
					$('#contact-form');
				});
			}
		});
		$('#contact-form').html('<p style="padding: 10px;">THANK YOU!<br/>One of our managers will be getting back to you shortly.</p>').hide().fadeIn(1500, function() {
					$('#contact-form');
				});
		return false;
		});
});
