// JavaScript Document

function validate() {
	with(document.competition) {
		if(realname.value=='') alertUser(realname);
		else if(sent_from.value=='') alertUser(sent_from);
		else if(checkEmail(sent_from) == false) {
			alert('Sorry, your e-mail address is invalid. Please re-enter.');
			sent_from.focus();
		}
		else if(phone.value=='') alertUser(phone);
		else if(postcode.value=='') alertUser(postcode);
		else submit();	
	}
}

function alertUser(thisElement) {
	alert('Please make sure you have filled out each of the fields.');
	thisElement.focus();
}

function checkEmail(emailAddr) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailAddr.value)){
		return (true)
	}
	return (false)
}

function changUrl(url) {
	window.location=url;
}
