function validEmail(email)
{
	invalidChars = " /:;!#";
	
	if(email == ""){ return false; }
	for(i=0; i<invalidChars.length; i++){
		badChar = invalidChars.charAt(i);
		if(email.indexOf(badChar,0) > -1){ return false; }
	} // end for loop
	
	atPos = email.indexOf("@",1);
	if(atPos == -1){ return false; }
	if(email.indexOf("@",atPos+1) != -1){ return false; }
	
	periodPos = email.indexOf(".",atPos);
	if(periodPos == -1){ return false; }
	if(periodPos+3 > email.length){ return false; }
	
	return true;
}

function validate(x)
{
	// validate full name
	if(x.fullname.value == ""){
		alert("Please enter your full name");
		x.fullname.focus();
		return false;
	}
	
	// validate gender
	if(x.gender.value == ""){
		alert("Please select gender");
		x.gender.focus();
		return false;
	}
	
	// validate day of birth
	if(x.dobd.value == ""){
		alert("Please select day of birth");
		x.dobd.focus();
		return false;
	}
	
	// validate month of birth
	if(x.dobm.value == ""){
		alert("Please select month of birth");
		x.dobm.focus();
		return false;
	}
	
	
	// validate year of birth
	if(x.doby.value == ""){
		alert("Please select year of birth");
		x.doby.focus();
		return false;
	}
	
	// validate email address
	if(!validEmail(x.email.value)){
		alert("Invalid email address");
		x.email.focus();
		x.email.select();
		return false;
	}
	
	// validate contact number
	if(x.tel.value == ""){
		alert("Please enter a valid contact number");
		x.tel.focus();
		return false;
	}
	
	// validate type
	if(x.type.value == ""){
		alert("Please select type");
		x.type.focus();
		return false;
	}
	
	// validate centre
	if(x.ctrid.value == ""){
		alert("Please select preferred registration centre");
		x.ctrid.focus();
		return false;
	}
	
	// validate water state
	if(x.waterstate.value == ""){
		alert("Please fill in the security question");
		x.waterstate.focus();
		return false;
	}
}