$(document).ready(function(){
	$('.error').hide();
	$('#eventFormSubmit').click(function() {
		$('.error').hide();
		// set form field values as variables
		var eventType = $("select#eventType option:selected").val();
		var eventLocation = $("select#eventLocation option:selected").val();
		var eventDate = $("input#eventDate").val();
		var eventTime = $("input#eventTime").val();
		var contact = $("input#contact").val();
		var address1 = $("input#address1").val();
		var address2 = $("input#address2").val();
		var city = $("input#city").val();
		var state = $("select#state option:selected").val();
		var zip = $("input#zip").val();
		var country = $("input#country").val();
		var phone = $("input#phone").val();
		var fax = $("input#fax").val();
		var email = $("input#email").val();
		var numGuests = $("input#numGuests").val();
		var contactMethod = $("select#contactMethod option:selected").val();
		var comments = $("textarea#comments").val();
		// form validation
		if (eventType == "") {$("#eventType-error").show(); $("input#eventType").focus(); return false;}
		if (eventLocation == "") {$("#eventLocation-error").show(); $("input#eventLocation").focus(); return false;}
		if (eventDate == "") {$("#eventDate-error").show(); $("input#eventDate").focus(); return false;}
		if (contact == "") {$("#contact-error").show(); $("input#contact").focus(); return false;}
		if (city == "") {$("#city-error").show(); $("input#city").focus(); return false;}
		if (state == "") {$("#state-error").show(); $("input#state").focus(); return false;}
		if (zip == "") {$("#zip-error").show(); $("input#zip").focus(); return false;}
		if (phone == "") {$("#phone-error").show(); $("input#phone").focus(); return false;}
		if (email == "") {$("#email-error1").show(); $("input#email").focus(); return false;}
		if (!isValidEmailAddress(email)) {$("#email-error2").show(); $("input#email").focus(); return false;}
		if (contactMethod == "") {$("#contactMethod-error").show(); $("input#contactMethod").focus(); return false;}
		// begin ajax form submission
		var dataString = '';
		dataString += 'eventType='+eventType;
		dataString += '&eventLocation='+eventLocation;
		dataString += '&eventDate='+eventDate;
		dataString += '&eventTime='+eventTime;
		dataString += '&contact='+contact;
		dataString += '&address1='+address1;
		dataString += '&address2='+address2;
		dataString += '&city='+city;
		dataString += '&state='+state;
		dataString += '&zip='+zip;
		dataString += '&country='+country;
		dataString += '&phone='+phone;
		dataString += '&fax='+fax;
		dataString += '&email='+email;
		dataString += '&numGuests='+numGuests;
		dataString += '&contactMethod='+contactMethod;
		dataString += '&comments='+comments;
		// alert (dataString); return false;
		$.ajax({
			type: "POST",
			url: "includes/event-request-process.asp",
			data: dataString,
			dataType: "text",
			async: false,
			cache: false,
			error: function () {alert('AJAX Connectivity Error');}, 
			success: function(msg) {$('#eventForm').html(msg);}
		});
		return false;
		// end ajax form submission
	});
});

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
};
