function cleanField(id) { 
	$(id).value = $F(id).gsub(' ','');
	$(id).value = $F(id).replace(/[^a-zA-Z0-9-_]+/g,'');
}
function checkEmail(str) {
	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)) ? true : false;
}
function doRegister() {
	cleanField('username');
	var es = 'Oops, there are some issues!\n';
	if($F('username') == ''){es += '\n- Username missing'}else{cleanField('username');}
	if($F('password').length < 6 || $F('password') == ''){es += '\n- Password must be 6 or more characters'}
	if($F('password') == 'password' || $F('password') == $F('username')){es += '\n- Password cannot be username or \'password\''}
	if($F('password') != $F('password2')){es += '\n- Passwords do not match'}
	if($F('firstname') == ''){es += '\n- We need your name'}
	if(!checkEmail($F('emailaddress'))){es += '\n- Invalid email address'}
	if($F('dob') == ''){es += '\n- D.O.B missing (dd/mm/yyyy)'}
	if(!$('sex-male').checked && !$('sex-female').checked){es += '\n- Sex missing'}
	if(es == 'Oops, there are some issues!\n'){
		$('register').submit();
	} else {
		alert(es);
	}
}