function checkFormComment(){
	var fullname = document.getElementById('fullname');
	var email = document.getElementById('email');

	var aa = document.getElementById('city');
	var dd = document.getElementById('star');
	var ee = document.getElementById('comment');
	var cc = document.getElementById('room');


	if(!isEmpty(fullname, "Please fill in the name section.")){

	if (!isEmpty(aa, "Please fill out all sections.")) {
	if (!isEmpty(ee, "Please fill out all sections.")) {
	if (!isEmpty(cc, "Please fill out all sections.")) {
	if (!isEmpty(dd, "Please fill out all sections.")) {

	if(emailValidator(email, "Invalid email address!")){ return true; }
						
	}}}}}
	return false;	
}


function checkForm(){
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var ac = document.getElementById('accesscode');
	var pin = document.getElementById('pin');

	if(checkAlpha(firstname, "Please complete both names.")){
	if(checkAlpha(lastname, "Please complete both names.")){

			if(checkAC(ac, "AccessCode (found on aluminum ruler) must be in format: AAAAA-######")){
				if(checkAlphaNum(pin, "Login ID may consist of only letters and numbers.")){
					if(lengthRestriction(pin, 4, 10)){
							if(emailValidator(email, "Invalid email address!")){ return true; }
						
					}
				}	
		}
	}}
	return false;	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); 
		return true;
	}
	return false;
}

function checkNum(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function checkAlpha(elem, helperMsg){
	var alphaExp = /^[a-zA-Z \s]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function checkAlphaNum(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z_-]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("PIN must be between " +min+ " and " +max+ " characters.");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		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 checkAC(elem, helperMsg){

	var acExp = /^[a-zA-Z]{5}\-[0-9]{6}$/;
	if(elem.value.match(acExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}

}

function checkPhone(elem, helperMsg){

	var phoneExp = /^[0123456789\-\(\)\s]+$/;
	if(elem.value.match(phoneExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}

}
