$('.login-content').hide();

$(document).ready(function() {
	$("#ijsdi-ijsdi").focus(function() {
		$(this).css("color","#00ADEF");
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		$(this).css("color","#CCC");
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	$(".interest-form input:submit").click(function() {         
		// First, disable the form from submitting
		$('.interest-form').submit(function() { return false; });
		
		// Grab form action
		formAction = $(".interest-form").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 = "ijsdi";
		emailId = emailId.replace("/", "");
		emailId = emailId + "-" + emailId;
		
		// Validate email address with regex
		if (!checkEmail(emailId)) {
			$('.error').slideDown("show", function() {
				$('.error').addClass('hasError');
			});
			return;
		} else {
			$('.hasError').slideUp("slow");
		}
		
		// Serialize form values to be submitted with POST
		var str = $(".interest-form").serialize();
		
		// Add form action to end of serialized data
		final = str + "&action=" + formAction;
		
		// show spinner
		$("#loading").fadeIn("slow");
		
		// Submit the form via ajax
		$.ajax({
			url: "proxy.php",
			type: "POST",
			data: final,
			success: function(html){
				//$(".interest-form").hide(); // If successfully submitted hides the form
				$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
				$("#loading").fadeOut("slow");
				$("#ijsdi-ijsdi").val('Your email address');
			}
		});
	});
	
	$('.client-login-button a').click(function() {
		$('.login-content').slideToggle(300);
		return false;
	});
});
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);
}
