$(function() {
	//make sure error messages are hidden
	$('.error').hide();
	
	//now, let's set logic for input feild styles
	$('.input_text').focus(function(){
		$(this).addClass("onfocus");
		$(this).removeClass("onfail");
	});
	$('.input_text').blur(function(){
		$(this).removeClass("onfocus");
	});
	
	$(".send_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();

		//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;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "http://www.di-pescara.com/wp-content/themes/dipescara/new_contact.php",
			data: dataString,
			success: function() {
				$('#contact_cont').html('<h2 class="blue">THANK YOU FOR YOUR INQUIRY.</h2><br/>One of our managers will get back to you shortly!').hide().fadeIn(1500, function() {
					$('#contact_cont');
				});
			}
		});
		return false;
		});
});
