function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);return false
		}
		else { return true }
	}
}

function emailValid(sWhichField) {
	
	var re = new RegExp(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/);
	if (sWhichField.value.match(re)) {
		return true;
	} else {
		return false;
	}
}


function validate_form(thisform) {
	with (thisform) {

		if (validate_required(txtName,"Name must be filled out!")==false) {	txtName.focus();return false	}
		if (validate_required(txtEmail,"Email must be filled out!")==false) { txtEmail.focus();return false	}
		if (!emailValid(txtEmail)) { alert('You must enter a valid Email address');txtEmail.focus();return false }
				
		if(!chkPermanent.checked && !chkContract.checked) { 
			alert("You must select at least one work type");
			return false;
		}
		
		
		if (validate_required(txtPhone,"Phone number must be filled out!")==false) { txtPhone.focus();return false	}
		if (validate_required(fileCV,"CV must be attached!")==false) { fileCV.focus();return false	}
		
		var iExtPos = fileCV.value.length - 4;

		if ((!(fileCV.value.toUpperCase().substr(iExtPos,4) == ".DOC")) && (!(fileCV.value.toUpperCase().substr((iExtPos-1),5) == ".DOCX")) && (!(fileCV.value.toUpperCase().substr(iExtPos,4) == ".PDF")) && (!(fileCV.value.toUpperCase().substr(iExtPos,4) == ".RTF"))) {
			alert("Please only upload a CV in Microsoft Word, RTF or PDF format.");
			return false;
		}
		
	}
	
}


function validate_marketeye(thisform){
	with (thisform) {
		if (validate_required(txtName,"Name must be filled out!")==false) {	txtName.focus();return false	}
		if (validate_required(txtEmail,"Email must be filled out!")==false) { txtEmail.focus();return false	}
		if (!emailValid(txtEmail)) { alert('You must enter a valid Email address');txtEmail.focus();return false }
	}
}

function validate_contact(thisform){
	with (thisform) {
		if (validate_required(txtName,"Name must be filled out!")==false) {	txtName.focus();return false	}
		if (validate_required(txtNumber,"Number must be filled out!")==false) { txtNumber.focus();return false	}
		if (validate_required(txtEmail,"Email must be filled out!")==false) { txtEmail.focus();return false	}
		if (!emailValid(txtEmail)) { alert('You must enter a valid Email address');txtEmail.focus();return false }
	}
}


function validate_uploadvacancy(thisform) {
	with (thisform) {
		if (validate_required(txtName,"Name must be filled out!")==false) {	txtName.focus();return false	}
		if (validate_required(txtPhone,"Phone number must be filled out!")==false) { txtPhone.focus();return false	}
		if (validate_required(txtEmail,"Email must be filled out!")==false) { txtEmail.focus();return false	}
		if (!emailValid(txtEmail)) { alert('You must enter a valid Email address');txtEmail.focus();return false }

		if (validate_required(txtOrgan,"Organisation must be filled out!")==false) { txtOrgan.focus();return false	}
		if (validate_required(txtJobTitle,"Job Title must be filled out!")==false) { txtJobTitle.focus();return false	}

		if (sltJobType.selectedIndex == 0) { alert('Job Type must be selected');sltJobType.focus();return false }

		if (validate_required(txtLocation,"Location must be filled out!")==false) { txtLocation.focus();return false	}
		if (validate_required(txtJobDesc,"Description must be filled out!")==false) { txtJobDesc.focus();return false	}
		if (validate_required(txtKeySkills,"Key Skills must be filled out!")==false) { txtKeySkills.focus();return false	}
		if (validate_required(txtMoney,"Remuneration must be filled out!")==false) { txtMoney.focus();return false	}


	}
	
}

