$(document).ready(function() {

		$('.default-value').each(function() {
    		var default_value = this.value;
   		    $(this).css('color', '#AFAFAF'); // this could be in the style sheet instead
   			$(this).focus(function() {
        		if(this.value == default_value) {
          		  this.value = '';
           		 $(this).css('color', '#333');
        		}
   			});
  			$(this).blur(function() {
        		if(this.value == '') {
           			$(this).css('color', '#AFAFAF');
            		this.value = default_value;
        		}
    		});
		});
	
		$("#subForm input:submit").click(function() {	
			
			// First, disable the form from submitting
			$('form#subForm').submit(function() { return false; });
			
			// Grab form action
			formAction = $("form#subForm").attr("action");
			
			// Hacking together id for email field
			// Replace the xxxxx below:
			// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
			emailId = "hjjrly";
			emailId = emailId.replace("/", "");
			emailId = emailId + "-" + emailId;
			
			// Validate email address with regex
			if (!checkEmail(emailId)) 
			{
				$('input#hjjrly-hjjrly.default-value').css('color', '#ff0000'); // JB: Prints some HTML
				return;
			}
        		if($("#name").value == 1) {
          		  $("#name").value = '';
        		}		
			
			$("#subForm input:submit").attr("disabled", "true");
		
			// Serialize form values to be submitted with POST
			var str = $("form#subForm").serialize();

			
			// Add form action to end of serialized data
			final = str + "&action=" + formAction;
			
			
			// Submit the form via ajax
			$.ajax({
				url: "http://www.stuartholmeshairholiday.co.uk/js/proxy.php",
				type: "POST",
				data: final,
				success: function(html){
					$("#theForm").hide(); // If successfully submitted hides the form
					$("#confirm").fadeIn("slow");  // Shows "Thanks for subscribing" div
				}
			});
		});
	});
	function checkEmail(email)
	{	
		var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	}
