jQuery(document).ready(function($) {
	$('#commentform').submit(function() {
		var hasError = false;
		var comment = $('#comment').val();
		var author = $('#author').val();
		var email = $('#email').val();
		var emailReg = /^(([\w-\.]+)@([\w-]+\.)+[\w-]{2,4})?$/;
		var message = '';
		if (comment == '') {
			$('#commentInfo').text('If you have nothing to say, why are you trying to say it?');
			hasError = true;
		}
		else {
			$('#commentInfo').text('');
		}

		if ( $('.logged-in-as').length == 0 ) {
			if (author == '') {
				$('#author').val('anonymous');
			}

			if (email == '') {
				$('#emailInfo').text('An email address is required. Don\'t worry, we won\'t share it!');
				hasError = true;
			}
			else if(!emailReg.test(email)) {
				$('#emailInfo').text('Please enter a valid email address.');
				hasError = true;
			}
			else if (email.length > 254) {
				$('#emailInfo').text('That\'s a little long to be a valid email address.');
			}
			else {
				$('#emailInfo').text('');
			}
		}

		if (hasError) {
			return false;
		}
	});
});

