function validateForm(FormDetails) {

	var reason = "";		
	reason += validateEmail(FormDetails.EmailAddress);
	reason += validateEmpty(FormDetails.FirstName);
	reason += validateEmpty(FormDetails.LastName);
	reason += validateEmpty(FormDetails.Address1);
	reason += validateEmpty(FormDetails.Address3);
	reason += validateEmpty(FormDetails.PostCode);
	reason += validateEmpty(FormDetails.Country);
	
	reason += validateOptIn(FormDetails.optin);

	if (reason != "") {
		if(reason === "You must accept the terms and conditions\n"){				
			alert("You must accept the terms and conditions.");
		}
		return false;
	}		

	return true;
}

function validateOptIn(){
	var error = "";		
	var checkbox = document.getElementById('optin');

	if (checkbox.checked != 1)
		error = "You must accept the terms and conditions\n";
		return error;
}

function validateEmpty(fld) {
	var error = "";

	if (fld.value.length == 0) {
		//fld.style.background = 'Yellow'; 
		error = ""
		document.getElementById(fld.id+'err').innerHTML = 'Required';
	} else {
		fld.style.background = 'White';
	}
	return error;  
}
function trim(s){
	return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
	var error="";
	var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if (fld.value == "") {
		//fld.style.background = 'Yellow';
		error = "Email required";
	} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		//fld.style.background = 'Yellow';
		error = "Enter a valid email";
	} else if (fld.value.match(illegalChars)) {
		//fld.style.background = 'Yellow';
		error = "Enter a valid email";
	} else {
		fld.style.background = 'White';
	}
	document.getElementById(fld.id+'err').innerHTML = error;
	return error;
}