$(document).ready(function(){

// For Free Airfare form
	$("#showform").submit(function() {
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var allowedChars = /^[A-Za-z\ \-\'\.]*$/;
		var allowedCharsNumbers = /^[0-9A-Za-z\ \-\'\.]*$/;

		// first name
		if($("#firstname").val() == '') {
			$("#firstname").before('<span class="error">Please enter your first name.</span>');
			$(this).focus();
			hasError = true;
		}
		else if(!allowedChars.test($('#firstname').val())) {
			$('#firstname').before('<span class="error">Only letters, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		// last name
		if($("#lastname").val() == '') {
			$("#lastname").before('<span class="error">Please enter your last name.</span>');
			hasError = true;
		}
		else if(!allowedChars.test($('#lastname').val())) {
			$('#lastname').before('<span class="error">Only letters, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}		
		
		//replyto
		if($("#replyto").val() == '') {
			$("#replyto").before('<span class="error">Please enter your email address.</span>');
			hasError = true;
		}
		else if(!emailReg.test($('#replyto').val())) {
			$('#replyto').before('<span class="error">Please enter a valid email.</span>');
			hasError = true;
		}

		// title
		if(!allowedCharsNumbers.test($('#title').val())) {
			$('#title').before('<span class="error">Only letters, numbers, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		// company
		if(!allowedCharsNumbers.test($('#company').val())) {
			$('#company').before('<span class="error">Only letters, numbers, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		// business
		if(!allowedCharsNumbers.test($('#business').val())) {
			$('#business').before('<span class="error">Only letters, numbers, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		// city
		if(!allowedChars.test($('#city').val())) {
			$('#city').before('<span class="error">Only letters, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		// question
		if(!allowedCharsNumbers.test($('#question').val())) {
			$('#question').before('<span class="error">Only letters, numbers, dashes, periods, spaces, and apostrophes are allowed.</span>');
			hasError = true;
		}
		
		if(hasError) {
			return false;
		} else {
			return true;
		}
	});
// END For Free Airfare form
});