blankre = /^\s*$/;
wordre = /\.doc$|\.docx$/;

function isblank(s)
{
  return blankre.test(s);
}

function isword(s)
{
	return wordre.test(s);
}

function validate() {
	document.apply_form.submit_form.disbaled = false;
	if (!document.apply_form.gender[0].checked && !document.apply_form.gender[1].checked) {
		alert("Please select a Gender");
		document.apply_form.gender[0].focus();
		return false;
	}
	if (isblank(document.apply_form.family_name.value)) {
		alert("You must enter a Family Name");
		document.apply_form.family_name.focus();
		return false;
	}
	if (isblank(document.apply_form.first_name.value)) {
		alert("You must enter a First Name");
		document.apply_form.first_name.focus();
		return false;
	}
	if (isblank(document.apply_form.country[document.apply_form.country.selectedIndex].value)) {
		alert("You must enter a Country");
		document.apply_form.country.focus();
		return false;
	}
	if (isblank(document.apply_form.email.value)) {
		alert("You must enter an E-mail Address");
		document.apply_form.email.focus();
		return false;
	}
	if (isblank(document.apply_form.type_of_grant[document.apply_form.type_of_grant.selectedIndex].value)) {
		alert("You must select the type of grant you are applying for");
		document.apply_form.type_of_grant.focus();
		return false;
	}
	if (isblank(document.apply_form.related_jrp[document.apply_form.related_jrp.selectedIndex].value)) {
		alert("You must select which JRP this application applies to");
		document.apply_form.related_jrp.focus();
		return false;
	}
	if (!document.apply_form.applied_before[0].checked && !document.apply_form.applied_before[1].checked) {
		alert("Please confirm whether you have applied for any other EMRP Research Grants in this call.");
		document.apply_form.applied_before[0].focus();
		return false;
	}
	if (document.apply_form.applied_before[0].checked && isblank(document.apply_form.further_details.value)) {
		alert("Please give details of the other EMRP Research Grants you have applied for");
		document.apply_form.further_details.focus();
		return false;
	}
	if (isblank(document.apply_form.file_upload.value)) {
		alert("Please attach your application form for upload");
		document.apply_form.file_upload.focus();
		return false;
	}
	if (!isword(document.apply_form.file_upload.value)) {
		alert("Please upload a Microsoft WORD Document");
		document.apply_form.file_upload.focus();
		return false;
	}
	return true;
}
