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);
};

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}


$(document).ready(function(){
	// Snippet info
	$('.venuedesc').hide();

	// Subscribe
	$('.subscribe').click(function(e){
		e.preventDefault();
	
		var email = $('#register').attr('value');
		var category = $('#categoryid').attr('value');

		// Validate email
		if(isValidEmailAddress(email)){
			// Generate url depending on category id presence
			if(isNumeric(category)){
				var url = "emailcheck.html?email="+email+"&category="+category;
			} else {
				var url = "emailcheck.html?email="+email;
			}
			// Call submission page
			$.ajax({
				url: url,
				context: document.body,
				success: function(data){
					if(data == 'fail'){
						$('.error').html("This is not a valid email address");					
					} else {
						$('.error').html('');
						$('.subscribe_box').html(data);
					}
				}
			});
		} else {
			// Send back error
			$('.error').html("This is not a valid email address");
		}
	});

	$('.subscribe_large').click(function(e){
		e.preventDefault();
	
		var email = $('#register_large').attr('value');
		var category = $('#categoryid_large').attr('value');

		// Validate email
		if(isValidEmailAddress(email)){
			// Generate url depending on category id presence
			if(isNumeric(category)){
				var url = "emailcheck.html?email="+email+"&category="+category;
			} else {
				var url = "emailcheck.html?email="+email;
			}
			// Call submission page
			$.ajax({
				url: url,
				context: document.body,
				success: function(data){
					if(data == 'fail'){
						$('.error_large').html("Invalid email address");					
					} else {
						$('.error_large').html('');
						$('.subscribe_box_large').html(data);
					}
				}
			});
		} else {
			// Send back error
			$('.error_large').html("Invalid email address");					
		}
	});

	
 });

