function checkrequired(which) {

	error = 0;
	errorMsg = "";

	which.requiredTitle.style.backgroundColor ='';
	which.requiredFirstName.style.backgroundColor ='';
	which.requiredLastName.style.backgroundColor ='';
	which.requiredAddress.style.backgroundColor ='';
	which.requiredPostcode.style.backgroundColor ='';
	which.requiredDateofBirth.style.backgroundColor ='';
	which.requiredNationality.style.backgroundColor ='';
	which.requiredHeight.style.backgroundColor ='';
	which.requiredWeight.style.backgroundColor ='';
	which.requiredStartWorkDate.style.backgroundColor ='';
	which.requiredLastEmployer.style.backgroundColor ='';
	which.requiredLastEmployerAddress.style.backgroundColor ='';
	which.requiredLastEmployerPostCode.style.backgroundColor ='';
	which.requiredLastEmployerTelephone.style.backgroundColor ='';
	which.requiredLastEmployerPositionHeld.style.backgroundColor ='';
	which.requiredLastEmployerStartDate.style.backgroundColor ='';
	which.requiredLastEmployerFinishDate.style.backgroundColor ='';
	which.requiredWorkRefName.style.backgroundColor ='';
	which.requiredWorkRefOrganisation.style.backgroundColor ='';
	which.requiredWorkRefAddress.style.backgroundColor ='';
	which.requiredWorkRefPostCode.style.backgroundColor ='';
	which.requiredWorkRefTelephone.style.backgroundColor ='';
	which.requiredCharacterRefName.style.backgroundColor ='';
	which.requiredCharacterRefAddress.style.backgroundColor ='';
	which.requiredCharacterRefPostCode.style.backgroundColor ='';
	which.requiredCharacterRefTelephone.style.backgroundColor ='';
	// which.requiredNINumber.style.backgroundColor ='';
	which.requiredTodaysDate.style.backgroundColor ='';
	which.Email.style.backgroundColor ='';
	which.Email_confirm.style.backgroundColor ='';
	which.WorkRefFax.style.backgroundColor ='';
	which.CharacterRefFax.style.backgroundColor ='';
	which.AdditionalInformation.style.backgroundColor ='';

	which.requiredPermit_validity_dates.style.backgroundColor ='';
	which.AllergyDetails.style.backgroundColor ='';
	which.IllnessDetails.style.backgroundColor ='';

	if (which.requiredTitle.value == "") {
		which.requiredTitle.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Title \n"
	}

	if (which.requiredFirstName.value == "") {
		which.requiredFirstName.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "First Name \n"
	}

	if (which.requiredLastName.value == "") {
		which.requiredLastName.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Name \n"
	}

	if (which.requiredAddress.value == "") {
		which.requiredAddress.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Address \n"
	}

	if (which.requiredPostcode.value == "") {
		which.requiredPostcode.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Post Code \n"
	}

	var email1 = which.Email.value;
	var email2 = which.Email_confirm.value;
	if (email1 == email2)
	{
		if(checkEmail(email1) == false)
		{
			which.Email.style.backgroundColor ='#BED3E9';
			which.Email_confirm.style.backgroundColor ='#BED3E9';
			error = 1;
			errorMsg = errorMsg + "Invalid Email Address\n"
		}
	}
	else
	{
		if (email1 != "" && email1 != email2)
		{
			which.Email.style.backgroundColor ='#BED3E9';
			which.Email_confirm.style.backgroundColor ='#BED3E9';
			error = 1;
			errorMsg = errorMsg + "Email Address's do not match \n"
		}
	}



	if (which.requiredDateofBirth.value == "") {
		which.requiredDateofBirth.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Date Of Birth \n"
		}

	if (which.requiredNationality.value == "") {
		which.requiredNationality.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Nationality \n"
		}

	if (which.BritishNat[0].checked == false && which.BritishNat[1].checked == false) {
		which.BritishNat[0].style.backgroundColor ='#BED3E9';
		which.BritishNat[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "British citizen/EU\n"
		}

	if (which.BritishNat[1].checked && which.BritishPermit[0].checked == false && which.BritishPermit[1].checked == false) {
		which.BritishPermit[0].style.backgroundColor ='#BED3E9';
		which.BritishPermit[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Visa/Permit\n"
		}

	if (which.BritishPermit[0].checked == true && which.requiredPermit_validity_dates.value == "") {
		which.requiredPermit_validity_dates.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Visa/Permit validity dates\n"
		}

	if (which.MaritalStatus[0].checked == false && which.MaritalStatus[1].checked == false && which.MaritalStatus[2].checked == false && which.MaritalStatus[3].checked == false) {
		error = 1;
		errorMsg = errorMsg + "Marital Status \n"
		}

	if (which.Sex[0].checked == false && which.Sex[1].checked == false) {
		error = 1;
		errorMsg = errorMsg + "Sex \n"
		}

	if (which.requiredHeight.value == "") {
		which.requiredHeight.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Height \n"
		}

	if (which.requiredWeight.value == "") {
		which.requiredWeight.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Weight \n"
		}
		
{
		if (which.DrivingLicence.checked) {
			return true;
		}
		else
		{
			alert("Please confirm that you have a current driving licence and is it either valid in the UK/EU or is an International Permit. (Please Tick) \n\n")
			return false;
		}
	}		

	if (!which.commitmenttoorigin[0].checked && !which.commitmenttoorigin[1].checked) {
		which.commitmenttoorigin[0].style.backgroundColor ='#BED3E9';
		which.commitmenttoorigin[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "4 Month Commitment to ORIGIN\n"
		}

	if (which.requiredEnglish_Language_Level.value == "") {
		which.requiredWeight.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "English Language Level\n"
		}

	if (!which.DomesticDuties[0].checked && !which.DomesticDuties[1].checked) {
		which.DomesticDuties[0].style.backgroundColor ='#BED3E9';
		which.DomesticDuties[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Willingness to carry out domestic duties\n"
		}

	if (!which.PersonalCare[0].checked && !which.PersonalCare[1].checked) {
		which.PersonalCare[0].style.backgroundColor ='#BED3E9';
		which.PersonalCare[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Willingness to carry out personal care\n"
		}

	if (!which.LiveIn[0].checked && !which.LiveIn[1].checked) {
		which.LiveIn[0].style.backgroundColor ='#BED3E9';
		which.LiveIn[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Willingness to perform live in care\n"
		}

	if (!which.WorkAway[0].checked && !which.WorkAway[1].checked) {
		which.WorkAway[0].style.backgroundColor ='#BED3E9';
		which.WorkAway[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Willingness to travel & work away\n"
		}

	if (!which.Allergies[0].checked && !which.Allergies[1].checked) {
		which.Allergies[0].style.backgroundColor ='#BED3E9';
		which.Allergies[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Do you have any allergies?\n"
	}
	else
	{
		if (which.Allergies[0].checked && which.AllergyDetails.value == "") {
			which.AllergyDetails.style.backgroundColor ='#BED3E9';
			error = 1;
			errorMsg = errorMsg + "Allergy details\n"
		}
	}

	if (!which.Smoker[0].checked && !which.Smoker[1].checked) {
		which.Smoker[0].style.backgroundColor ='#BED3E9';
		which.Smoker[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Do you smoke?\n"
		}

	if (!which.Disabiliy[0].checked && !which.Disabiliy[1].checked) {
		which.Disabiliy[0].style.backgroundColor ='#BED3E9';
		which.Disabiliy[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Do you have any disabilities, that would affect your ability to perform this role?\n"
		}

	if (!which.MajorIllness[0].checked && !which.MajorIllness[1].checked) {
		which.MajorIllness[0].style.backgroundColor ='#BED3E9';
		which.MajorIllness[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Have you suffered from any significant illness or medical conditions?\n"
	}

	if (which.MajorIllness[0].checked && which.IllnessDetails.value == "" || which.Disabiliy[0].checked && which.IllnessDetails.value == "") {
		which.IllnessDetails.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Suggestions of how any illness dificulties can be overcome\n"
	}


	if (which.requiredStartWorkDate.value == "") {
		which.requiredStartWorkDate.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Start Date \n"
		}

	if (which.requiredLastEmployer.value == "") {
		which.requiredLastEmployer.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Employer \n"
	}

	if (which.requiredLastEmployerAddress.value == "") {
		which.requiredLastEmployerAddress.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Employer Address \n"
	}

	if (which.requiredLastEmployerPostCode.value == "") {
		which.requiredLastEmployerPostCode.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Employer Postcode \n"
	}

	if (which.requiredLastEmployerTelephone.value == "") {
		which.requiredLastEmployerTelephone.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Employer Telephone \n"
	}

	if (which.requiredLastEmployerPositionHeld.value == "") {
		which.requiredLastEmployerPositionHeld.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Position Held \n"
	}

	if (which.requiredLastEmployerStartDate.value == "") {
		which.requiredLastEmployerStartDate.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Start Date \n"
	}

	if (which.requiredLastEmployerFinishDate.value == "") {
		which.requiredLastEmployerFinishDate.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Last Finish Date \n"
	}

	if (which.requiredWorkRefName.value == "") {
		which.requiredWorkRefName.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Reference Name \n"
	}

	if (which.requiredWorkRefOrganisation.value == "") {
		which.requiredWorkRefOrganisation.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Reference Organisation \n"
	}

	if (which.requiredWorkRefAddress.value == "") {
		which.requiredWorkRefAddress.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Reference Address \n"
	}

	if (which.requiredWorkRefPostCode.value == "") {
		which.requiredWorkRefPostCode.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Reference Postcode \n"
	}

	if (which.requiredWorkRefTelephone.value == "") {
		which.requiredWorkRefTelephone.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Work Reference Tel \n"
	}

	if (which.requiredCharacterRefName.value == "") {
		which.requiredCharacterRefName.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Character Reference Name \n"
	}

	if (which.requiredCharacterRefAddress.value == "") {
		which.requiredCharacterRefAddress.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Character Reference Address \n"
	}

	if (which.requiredCharacterRefPostCode.value == "") {
		which.requiredCharacterRefPostCode.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Character Reference Postcode \n"
	}

	if (which.requiredCharacterRefTelephone.value == "") {
		which.requiredCharacterRefTelephone.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Character Reference Telephone \n"
	}

	if (!which.CriminalOffence[0].checked && !which.CriminalOffence[1].checked ) {
		which.CriminalOffence[0].style.backgroundColor ='#BED3E9';
		which.CriminalOffence[1].style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Have you ever been convicted of a criminal offence?\n"
	}

	if (which.KeyStrengths.value == "") {
		which.KeyStrengths.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Key Strengths\n"
	}

	if (which.requiredHereAboutOrigin.value == "") {
		which.requiredHereAboutOrigin.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "How you heard about Origincare\n"
	}

	//if (which.requiredNINumber.value == "") {
	//	which.requiredNINumber.style.backgroundColor ='#BED3E9';
	//	error = 1;
	//	errorMsg = errorMsg + "National Insurance Number\n"
	//}

	if (which.requiredTodaysDate.value == "") {
		which.requiredTodaysDate.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "Todays Date \n"
	}

	if (!which.DrivingLicence.checked) {
		which.DrivingLicence.style.backgroundColor ='#BED3E9';
		error = 1;
		errorMsg = errorMsg + "\nIf you are to work for Origin, You must have a valid driving licence.\nPlease ensure that if you have a valid driving licence that the tick box is ticked.\n"
	}
	else
	{
		if (which.DrivingLicence.checked && which.LicenseType.value=="") {
			which.LicenseType.style.backgroundColor ='#BED3E9';
			error = 1;
			errorMsg = errorMsg + "\nWhat type of driving licence do you hold?\n"
		}
	}

	if (error == 1) {
		alert("Please ensure you have entered all the required fields (see below). Thank You. \n\n" + errorMsg );
		return false;
	}
	else
	{
		if (which.Confirmation.checked) {
			return true;
		}
		else
		{
			alert("Please confirm that the information you have given is true & correct. (Please Tick) \n\n")
			return false;
		}
	}
}

function checkEmail(strEmail) {

	var strAt="@"
	var strDot="."
	var lenAt = strEmail.indexOf(strAt)
	var lenStr = strEmail.length
	var lenDot = strEmail.indexOf(strDot)

	if (strEmail.indexOf(strAt)==-1)
	{
	   return false;
	}

	if (strEmail.indexOf(strAt)==-1 || strEmail.indexOf(strAt)==0 || strEmail.indexOf(strAt)==lenStr)
	{
	   return false;
	}

	if (strEmail.indexOf(strDot)==-1 || strEmail.indexOf(strDot)==0 || strEmail.indexOf(strDot)==lenStr)
	{
	    return false;
	}

	if (strEmail.indexOf(strAt,(lenAt+1)) != -1)
	{
	    return false;
	}

	if (strEmail.substring(lenAt-1,lenAt)==strDot || strEmail.substring(lenAt+1,lenAt+2)==strDot)
	{
	    return false;
	}

	if (strEmail.indexOf(strDot,(lenAt+2))==-1)
	{
	    return false;
	}

	if (strEmail.indexOf(" ")!=-1)
	{
	    return false;
	}

	return true
}