// JavaScript Document

function valid_email(email) {
	if(!(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(email))){
		return false;
	}	
}
function check_form() {
	var comm = "";
	var fname = document.getElementById('camp[fname]').value;
	var sname = document.getElementById('camp[sname]').value;

	var email = document.getElementById('camp[email]').value;
	var friend1 = document.getElementById('friend1').value;
	var friend2 = document.getElementById('friend2').value;
	var friend3 = document.getElementById('friend3').value;
	var friend4 = document.getElementById('friend4').value;
	
	if (fname.length == 0) {
		comm += '\nPlease enter your first name\n';
	}
	if (sname.length == 0) {
		comm += '\nPlease enter your surname\n';
	}
	if (valid_email(email) == false) {
		comm += 'Please enter your email address\n\n';
	}
	if((friend1.length > 0) && valid_email(friend1) == false) {
		comm += 'Friend1 email is incorrect\n';	
	}
	if((friend2.length > 0) && valid_email(friend2) == false) {
		comm += 'Friend2 email is incorrect\n';	
	}
	if((friend3.length > 0) && valid_email(friend3) == false) {
		comm += 'Friend3 email is incorrect\n';	
	}
	if((friend4.length > 0) && valid_email(friend4) == false) {
		comm += 'Friend4 email is incorrect\n';	
	}
	
	if (comm.length == 0) {
		//document.form1.submit();
		return true;
	} 
	else {
		alert('The following errors occured:\n' + comm);
		
	}
	return false;
}