// setup form submission through an iframe
$(document).ready(function(){

	// create the js submissino iframe.
	theFrame = $('body').append('<iframe name="submitFrame" src="about:blank" id="submitFrame"></iframe>');
	
	$('#cm-stitu-stitu').click(function() {
		if(this.value == 'type your email') this.value = '';
	});

	$('#email-form').submit(function(e){
	
		var obj = $(this);
	
		e.preventDefault();

		// on submit, check the email to see if it's valid. If so, show a "thank you" message and submit the form.		
		if (checkEmail($('#cm-stitu-stitu').val())) {
			obj.attr('target', 'submitFrame');
			obj.hide();
			$('#submitThanks').show();
			this.submit();
		} else {
			//email is invalid, show a notification.
			if(!obj.hasClass('error')) obj.prepend('<div class="email-error">Please provide a valid email address</div>').addClass('error');
		}
		
	}); // end onSubmit code.

}); // end document.ready

// do basic email validation
function checkEmail(email) {
	var filter = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*/;
	if (!filter.test(email)) {
		return false;
	} else {
		return true;
	}
}
