/**
 * Checks if form fields are empty
 */
function emptyCheck(field) {		
	if(field == "") {					
		return false;
	} else {		
		return true;
	}
}

/** 
 * function to check a string is a valid email address
 */
function isValidEmail(strEmail) {
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) 
	{		
		return false;
	} 
	return true; 
}

/**
 * Checks if the form fields are empty and to check a string is a valid email address
 * Shows alert box if they are false
 */
function checkForm()
{	
	var message = '';	
	var checkSource = emptyCheck(document.getElementById('source').value);
	var resultofEmailCheck = isValidEmail(document.getElementById('email').value);
	
	if(checkSource == true){
		return true;
	} else {
						
		if(checkSource == false) {
			message = 'Please tell us how you heard about us?\n\n';
		}
		
		if(resultofEmailCheck == false) {
			message = message + 'Please enter a valid email address';
		}
		
		alert(message);

		return false;		
	}
}
