$(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");
	});
	
	$(".send_parties").click(function() {
		// validate and process the form
		// first hide any error messages
		$('.error').hide();
		
		//next, let's set our required feild variables
		var firstname = $("input#firstname").val();
		var lastname = $("input#lastname").val();
		var email = $("input#email02").val();
		var phone = $("input#phone02").val();
		var guests = $("input#PartySize02").val();
		var date = $("input#datepicker02").val();
		var time = $("input#ResHour02").val();
		var type = $("input#PartyType02").val();
		
		//we need some extra variables for email validation
		var at = "@";
		var dot = ".";
		
		if (firstname == "") {
			$("input#firstname").addClass("onfail");
		}
		if (lastname == "") {
			$("input#lastname").addClass("onfail");
		}
		if (email == "" || email.indexOf(at)==-1 || email.indexOf(dot)==-1) {
			$("input#email02").addClass("onfail");
		}
		if (phone.length < 10 || isNaN(parseInt(phone))) {
			$("input#phone02").addClass("onfail");
		}
		if (guests == "") {
			$("input#PartySize02").addClass("onfail");
		}
		
		
		//if something is missing, don't process the form
		if (firstname == "" || lastname == "" || email == "" || email.indexOf(at)==-1 || email.indexOf(dot)==-1 || phone.length < 10 || isNaN(parseInt(phone)) || guests == "") {
			return false;
		}
		
		//if all is good, then create a datastring with the values
		var dataString = '&firstname=' + firstname + '&lastname=' + lastname + '&email=' + email + '&phone=' + phone + '&date=' + date + '&type=' + type + '&guests=' + guests + '&time=' + time;
		//alert (dataString);return false;
		
		$.ajax({
			type: "POST",
			url: "http://www.di-pescara.com/wp-content/themes/dipescara/new_request.php",
			data: dataString,
			success: function() {
				$('#parties_cont').html('<p class="txt_big_light" style="margin-top: 24px;">THANK YOU FOR YOUR INQUIRY.<br/>Our Parties Manager will be getting back to you shortly.</p>').hide().fadeIn(1500, function() {
					$('#parties_cont');
				});
			}
		});
		return false;
		});
});
