window.onload = initStuff;

function initStuff() {

	if (document.getElementById) {
		
		// Attach email regex check to form
		var emailform = document.getElementById('emailform');
		emailform.onsubmit = function() {
			return checkEmail()
		};
		
		// Remove text from input field on focus
		var email = document.getElementById('email');
		email.onfocus = function() {
			email.value = '';
		}
		email.onblur = function() {
			if (email.value == '') {email.value = 'Want to receive an eggMail?';}	
		}
		
	}

}

function checkEmail() {
	
	var email = document.getElementById('email');
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) {
		alert('Oops! You didn\'t supply a valid email address!');
		email.focus;
		return false;
	}
	
}
