function lengthRestriction(elem, min){
	var uInput = elem.value;
	if(uInput.length >= min){
		return true;
	}else{
		alert("Please enter more than 2 characters");
		elem.focus();
		return false;
	}
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function formValidator(){
	// Make quick references to our fields
	var name = document.getElementById('name');
	var email = document.getElementById('email');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(name, "Please enter your name")){
			if(lengthRestriction(name, 2)){
				if(emailValidator(email, "Please enter a valid email address")){
					alert("You will soon receive an email with our Workshop dates. See you there!")
					return true;
			}
		}
	}
	return false;
}
