<!-- Hide from JavaScript-Impaired Browsers
//Validation script for contract phones page

function existingNumber(value){
	if(value == "no"){
		document.mainform.existingMobileNetwork.disabled = true;
		document.mainform.existingMobileNetwork.style.background = "#E8E8E8";
		document.mainform.existingMobileNumber.disabled = true;
		document.mainform.existingMobileNumber.style.background = "#E8E8E8";
		
		document.mainform.existingMobileNumber.value = "";
		document.mainform.existingMobileNetwork.options[0].selected = true;
		
		
		hideBlock1.style.color = "#C9C9C9";
		hideBlock2.style.color = "#C9C9C9";
	} else {
		document.mainform.existingMobileNetwork.disabled = false;
		document.mainform.existingMobileNetwork.style.background = "#FFFFFF";
		document.mainform.existingMobileNumber.disabled = false;
		document.mainform.existingMobileNumber.style.background = "#FFFFFF";
		
		hideBlock1.style.color = "#000000";
		hideBlock2.style.color = "#000000";
	}
}
function prevAddress(value){
	if(value <3){
		document.mainform.personalDetailsPrevAddress.disabled = false;
		document.mainform.personalDetailsPrevAddress.style.background = "#FFFFFF";
		document.mainform.personalDetailsPrevTown.disabled = false;
		document.mainform.personalDetailsPrevTown.style.background = "#FFFFFF";
		document.mainform.personalDetailsPrevPostcode.disabled = false;
		document.mainform.personalDetailsPrevPostcode.style.background = "#FFFFFF";
		document.mainform.personalDetailsPrevResYear.disabled = false;
		document.mainform.personalDetailsPrevResYear.style.background = "#FFFFFF";
		document.mainform.personalDetailsPrevResMonth.disabled = false;
		document.mainform.personalDetailsPrevResMonth.style.background = "#FFFFFF";
		
		hideBlock3.style.color = "#000000";
		hideBlock4.style.color = "#000000";
		hideBlock5.style.color = "#000000";
		hideBlock6.style.color = "#000000";
		hideBlock7.style.color = "#000000";
	} else {
		document.mainform.personalDetailsPrevAddress.disabled = true;
		document.mainform.personalDetailsPrevAddress.style.background = "#E8E8E8";
		document.mainform.personalDetailsPrevTown.disabled = true;
		document.mainform.personalDetailsPrevTown.style.background = "#E8E8E8";
		document.mainform.personalDetailsPrevPostcode.disabled = true;
		document.mainform.personalDetailsPrevPostcode.style.background = "#E8E8E8";
		document.mainform.personalDetailsPrevResYear.disabled = true;
		document.mainform.personalDetailsPrevResYear.style.background = "#E8E8E8";
		document.mainform.personalDetailsPrevResMonth.disabled = true;
		document.mainform.personalDetailsPrevResMonth.style.background = "#E8E8E8";
		
		hideBlock3.style.color = "#C9C9C9";
		hideBlock4.style.color = "#C9C9C9";
		hideBlock5.style.color = "#C9C9C9";
		hideBlock6.style.color = "#C9C9C9";
		hideBlock7.style.color = "#C9C9C9";
	}
}

function proofsIdentity(value) {
	if(value == "drivingLicence"){
		document.mainform.ProofIdentityDrivingLicence.disabled = false;
		document.mainform.ProofIdentityDrivingLicence.style.background = "#FFFFFF";
		
		
		document.mainform.ProofAddressDrivingLicence.style.background = "#E8E8E8";
		document.mainform.ProofAddressDrivingLicence.disabled = true;
		document.mainform.ProofAddress[0].disabled = true;
		document.mainform.ProofAddress[1].checked = true;
		document.mainform.ProofAddressStatementACCNum.disabled = false;
		document.mainform.ProofAddressStatementACCNum.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementName.disabled = false;
		document.mainform.ProofAddressStatementName.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementSort.disabled = false;
		document.mainform.ProofAddressStatementSort.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateDay.disabled = false;
		document.mainform.ProofAddressStatementDateDay.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateMonth.disabled = false;
		document.mainform.ProofAddressStatementDateMonth.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateYear.disabled = false;
		document.mainform.ProofAddressStatementDateYear.style.background = "#FFFFFF";
		
		document.mainform.ProofIdentityPassport.disabled = true;
		document.mainform.ProofIdentityPassport.style.background = "#E8E8E8";
		document.mainform.ProofIdentityDebitCard.disabled = true;
		document.mainform.ProofIdentityDebitCard.style.background = "#E8E8E8";
		document.mainform.ProofIdentityDebitCardSort.disabled = true;
		document.mainform.ProofIdentityDebitCardSort.style.background = "#E8E8E8";
	} else if(value == "passport") {
		document.mainform.ProofAddress[0].disabled = false;
		
		document.mainform.ProofIdentityDrivingLicence.disabled = true;
		document.mainform.ProofIdentityDrivingLicence.style.background = "#E8E8E8";
		document.mainform.ProofIdentityPassport.disabled = false;
		document.mainform.ProofIdentityPassport.style.background = "#FFFFFF";
		document.mainform.ProofIdentityDebitCard.disabled = true;
		document.mainform.ProofIdentityDebitCard.style.background = "#E8E8E8";
		document.mainform.ProofIdentityDebitCardSort.disabled = true;
		document.mainform.ProofIdentityDebitCardSort.style.background = "#E8E8E8";
	} else if(value == "debitCard") {
		document.mainform.ProofAddress[0].disabled = false;
		
		document.mainform.ProofIdentityDrivingLicence.disabled = true;
		document.mainform.ProofIdentityDrivingLicence.style.background = "#E8E8E8";
		document.mainform.ProofIdentityPassport.disabled = true;
		document.mainform.ProofIdentityPassport.style.background = "#E8E8E8";
		document.mainform.ProofIdentityDebitCard.disabled = false;
		document.mainform.ProofIdentityDebitCard.style.background = "#FFFFFF";
		document.mainform.ProofIdentityDebitCardSort.disabled = false;
		document.mainform.ProofIdentityDebitCardSort.style.background = "#FFFFFF";
	}
}

function proofsAddress(value) {
	if(value == "drivingLicence"){
		
		document.mainform.ProofIdentityDrivingLicence.disabled = true;
		document.mainform.ProofIdentityDrivingLicence.style.background = "#E8E8E8";
		
		document.mainform.ProofAddressDrivingLicence.disabled = false;
		document.mainform.ProofAddressDrivingLicence.style.background = "#FFFFFF";
		
		document.mainform.ProofAddressStatementACCNum.disabled = true;
		document.mainform.ProofAddressStatementACCNum.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementName.disabled = true;
		document.mainform.ProofAddressStatementName.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementSort.disabled = true;
		document.mainform.ProofAddressStatementSort.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateDay.disabled = true;
		document.mainform.ProofAddressStatementDateDay.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateMonth.disabled = true;
		document.mainform.ProofAddressStatementDateMonth.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateYear.disabled = true;
		document.mainform.ProofAddressStatementDateYear.style.background = "#E8E8E8";
		
		document.mainform.ProofAddressUtilitiesType.disabled = true;
		document.mainform.ProofAddressUtilitiesType.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesRefNum.disabled = true;
		document.mainform.ProofAddressUtilitiesRefNum.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateDay.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateDay.disabled = true;
		document.mainform.ProofAddressUtilitiesDateMonth.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateMonth.disabled = true;
		document.mainform.ProofAddressUtilitiesDateYear.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateYear.disabled = true;
		document.mainform.ProofAddressUtilitiesType.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesType.disabled = true;
		
	} else if(value == "statement") {
		
		document.mainform.ProofIdentityDrivingLicence.disabled = false;
		
		document.mainform.ProofAddressDrivingLicence.disabled = true;
		document.mainform.ProofAddressDrivingLicence.style.background = "#E8E8E8";
		
		document.mainform.ProofAddressStatementACCNum.disabled = false;
		document.mainform.ProofAddressStatementACCNum.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementName.disabled = false;
		document.mainform.ProofAddressStatementName.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementSort.disabled = false;
		document.mainform.ProofAddressStatementSort.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateDay.disabled = false;
		document.mainform.ProofAddressStatementDateDay.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateMonth.disabled = false;
		document.mainform.ProofAddressStatementDateMonth.style.background = "#FFFFFF";
		document.mainform.ProofAddressStatementDateYear.disabled = false;
		document.mainform.ProofAddressStatementDateYear.style.background = "#FFFFFF";
		
		document.mainform.ProofAddressUtilitiesType.disabled = true;
		document.mainform.ProofAddressUtilitiesType.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesRefNum.disabled = true;
		document.mainform.ProofAddressUtilitiesRefNum.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateDay.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateDay.disabled = true;
		document.mainform.ProofAddressUtilitiesDateMonth.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateMonth.disabled = true;
		document.mainform.ProofAddressUtilitiesDateYear.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesDateYear.disabled = true;
		document.mainform.ProofAddressUtilitiesType.style.background = "#E8E8E8";
		document.mainform.ProofAddressUtilitiesType.disabled = true;
	
	} else if(value == "utilitiesNumber") {
	
		document.mainform.ProofIdentityDrivingLicence.disabled = false;
		
		document.mainform.ProofAddressDrivingLicence.disabled = true;
		document.mainform.ProofAddressDrivingLicence.style.background = "#E8E8E8";
		
		document.mainform.ProofAddressStatementACCNum.disabled = true;
		document.mainform.ProofAddressStatementACCNum.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementName.disabled = true;
		document.mainform.ProofAddressStatementName.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementSort.disabled = true;
		document.mainform.ProofAddressStatementSort.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateDay.disabled = true;
		document.mainform.ProofAddressStatementDateDay.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateMonth.disabled = true;
		document.mainform.ProofAddressStatementDateMonth.style.background = "#E8E8E8";
		document.mainform.ProofAddressStatementDateYear.disabled = true;
		document.mainform.ProofAddressStatementDateYear.style.background = "#E8E8E8";
			
		document.mainform.ProofAddressUtilitiesType.disabled = false;
		document.mainform.ProofAddressUtilitiesType.style.background = "#FFFFFF";
		document.mainform.ProofAddressUtilitiesRefNum.disabled = false;
		document.mainform.ProofAddressUtilitiesRefNum.style.background = "#FFFFFF";
		document.mainform.ProofAddressUtilitiesDateDay.style.background = "#FFFFFF";
		document.mainform.ProofAddressUtilitiesDateDay.disabled = false;
		document.mainform.ProofAddressUtilitiesDateMonth.style.background = "#FFFFFF";
		document.mainform.ProofAddressUtilitiesDateMonth.disabled = false;
		document.mainform.ProofAddressUtilitiesDateYear.style.background = "#FFFFFF";
		document.mainform.ProofAddressUtilitiesDateYear.disabled = false;
		
		
	}
}

function businessDetails(value){
	if(value == 'no'){
		hideBlock6.style.color = "#C9C9C9";
		hideBlock7.style.color = "#C9C9C9";
		hideBlock8.style.color = "#C9C9C9";
		hideBlock9.style.color = "#C9C9C9";
		hideBlock10.style.color = "#C9C9C9";
		hideBlock11.style.color = "#C9C9C9";
		hideBlock12.style.color = "#C9C9C9";
		hideBlock13.style.color = "#C9C9C9";
		hideBlock14.style.color = "#C9C9C9";
		hideBlock15.style.color = "#C9C9C9";
		hideBlock16.style.color = "#C9C9C9";
		hideBlock17.style.color = "#C9C9C9";
		hideBlock18.style.color = "#C9C9C9";
		hideBlock19.style.color = "#C9C9C9";
		hideBlock20.style.color = "#C9C9C9";
		
		document.mainform.businessDetailsNumEmployees[0].disabled = true;
		document.mainform.businessDetailsNumEmployees[1].disabled = true;
		document.mainform.businessDetailsNumEmployees[2].disabled = true;
		document.mainform.businessDetailsNumEmployees[3].disabled = true;
		document.mainform.businessDetailsNumEmployees[4].disabled = true;
		
		document.mainform.businessDetailsName.disabled = true;
		document.mainform.businessDetailsName.style.background = "#E8E8E8";
		document.mainform.businessDetailsAddress.disabled = true;
		document.mainform.businessDetailsAddress.style.background = "#E8E8E8";
		document.mainform.businessDetailsTown.disabled = true;
		document.mainform.businessDetailsTown.style.background = "#E8E8E8";
		document.mainform.businessDetailsPostcode.disabled = true;
		document.mainform.businessDetailsPostcode.style.background = "#E8E8E8";
		document.mainform.businessDetailsRegNumber.disabled = true;
		document.mainform.businessDetailsRegNumber.style.background = "#E8E8E8";
		document.mainform.businessDetailsVATNumber.disabled = true;
		document.mainform.businessDetailsVATNumber.style.background = "#E8E8E8";
		document.mainform.businessDetailsTelephone.disabled = true;
		document.mainform.businessDetailsTelephone.style.background = "#E8E8E8";		
		document.mainform.businessDetailsFax.disabled = true;
		document.mainform.businessDetailsFax.style.background = "#E8E8E8";	
		document.mainform.businessDetailsTitle.disabled = true;
		document.mainform.businessDetailsTitle.style.background = "#E8E8E8";	
		document.mainform.businessDetailsFName.disabled = true;
		document.mainform.businessDetailsFName.style.background = "#E8E8E8";	
		document.mainform.businessDetailsInitial.disabled = true;
		document.mainform.businessDetailsInitial.style.background = "#E8E8E8";	
		document.mainform.businessDetailsLName.disabled = true;
		document.mainform.businessDetailsLName.style.background = "#E8E8E8";	
	} else {
		hideBlock6.style.color = "#000000";
		hideBlock7.style.color = "#000000";
		hideBlock8.style.color = "#000000";
		hideBlock9.style.color = "#000000";
		hideBlock10.style.color = "#000000";
		hideBlock11.style.color = "#000000";
		hideBlock12.style.color = "#000000";
		hideBlock13.style.color = "#000000";
		hideBlock14.style.color = "#000000";
		hideBlock15.style.color = "#000000";
		hideBlock16.style.color = "#000000";
		hideBlock17.style.color = "#000000";
		hideBlock18.style.color = "#000000";
		hideBlock19.style.color = "#000000";
		hideBlock20.style.color = "#000000";
		
		document.mainform.businessDetailsNumEmployees[0].disabled = false;
		document.mainform.businessDetailsNumEmployees[1].disabled = false;
		document.mainform.businessDetailsNumEmployees[2].disabled = false;
		document.mainform.businessDetailsNumEmployees[3].disabled = false;
		document.mainform.businessDetailsNumEmployees[4].disabled = false;
		
		document.mainform.businessDetailsName.disabled = false;
		document.mainform.businessDetailsName.style.background = "#FFFFFF";
		document.mainform.businessDetailsAddress.disabled = false;
		document.mainform.businessDetailsAddress.style.background = "#FFFFFF";
		document.mainform.businessDetailsTown.disabled = false;
		document.mainform.businessDetailsTown.style.background = "#FFFFFF";
		document.mainform.businessDetailsPostcode.disabled = false;
		document.mainform.businessDetailsPostcode.style.background = "#FFFFFF";
		document.mainform.businessDetailsRegNumber.disabled = false;
		document.mainform.businessDetailsRegNumber.style.background = "#FFFFFF";
		document.mainform.businessDetailsVATNumber.disabled = false;
		document.mainform.businessDetailsVATNumber.style.background = "#FFFFFF";
		document.mainform.businessDetailsTelephone.disabled = false;
		document.mainform.businessDetailsTelephone.style.background = "#FFFFFF";		
		document.mainform.businessDetailsFax.disabled = false;
		document.mainform.businessDetailsFax.style.background = "#FFFFFF";	
		document.mainform.businessDetailsTitle.disabled = false;
		document.mainform.businessDetailsTitle.style.background = "#FFFFFF";	
		document.mainform.businessDetailsFName.disabled = false;
		document.mainform.businessDetailsFName.style.background = "#FFFFFF";	
		document.mainform.businessDetailsInitial.disabled = false;
		document.mainform.businessDetailsInitial.style.background = "#FFFFFF";	
		document.mainform.businessDetailsLName.disabled = false;
		document.mainform.businessDetailsLName.style.background = "#FFFFFF";	
	}
}

//This is the function which does all of the form validation
function checkForm(){
	
	errorTest = false;
	
	//Check exisiting mobile number if customer is an existing customer.
	//if(document.mainform.existingCustomer[1].checked == true){
		
		//Check that if the user is an existing customer they have chosen a network.
		//if(!document.mainform.existingMobileNetwork.value){
		//	errorTest = true;
		//	alert('You must select the network you are currently on');
		//	document.mainform.existingMobileNetwork.focus();
		//}
		
		//Check Existing Mobile Phone Number
		//if(!errorTest || !document.mainform.existingMobileNumber.value || document.mainform.existingMobileNumber.style.color == "red"){
		//	document.mainform.existingMobileNumber.style.color = "red";
		//	document.mainform.existingMobileNumber.value = "Mobile phone number error";
		//	
		//	errorTest = true;

		//} else {
		//	var x = CheckPhoneNumber(document.mainform.existingMobileNumber.value);
		//	if(!x){
		//		document.mainform.existingMobileNumber.style.color = "red";
		//		document.mainform.existingMobileNumber.value = "Mobile phone number error";
		//		errorTest = true;
		//	}
		//}
	//}
	
	//Check customers first name
	if(!document.mainform.personalDetailsFName.value || !document.mainform.personalDetailsFName.style.color == "red"){
		document.mainform.personalDetailsFName.style.color = "red";
		document.mainform.personalDetailsFName.value = "Please enter your first name";
		errorTest = true;
	}
		
	//Check customers last name
	if(!document.mainform.personalDetailsLName.value || !document.mainform.personalDetailsLName.style.color == "red"){
		document.mainform.personalDetailsLName.style.color = "red";
		document.mainform.personalDetailsLName.value = "Please enter your last name";
		errorTest = true;
	}
	
	//Check date of customers date of birth
	var filter  = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!filter.test(document.mainform.personalDetailsDOB.value)) {
		document.mainform.personalDetailsDOB.style.color = "red";
		document.mainform.personalDetailsDOB.value = "DOB error";
		errorTest = true;
	}
	
	//Check customers Address
	if(!document.mainform.personalDetailsAddress.value || !document.mainform.personalDetailsAddress.style.color == "red"){
		document.mainform.personalDetailsAddress.style.color = "red";
		document.mainform.personalDetailsAddress.value = "Please enter your address";
		errorTest = true;
	}
	
	//Check customers postcode
	if(!document.mainform.personalDetailsPostcode.value || !document.mainform.personalDetailsPostcode.style.color == "red"){
		document.mainform.personalDetailsPostcode.style.color = "red";
		document.mainform.personalDetailsPostcode.value = "Postcode error";
		errorTest = true;
	}
	
	//Check customers town
	if(!document.mainform.personalDetailsTown.value || !document.mainform.personalDetailsTown.style.color == "red"){
		document.mainform.personalDetailsTown.style.color = "red";
		document.mainform.personalDetailsTown.value = "Town error";
		errorTest = true;
	}
	
	//Check length of time at current address
	if(document.mainform.personalDetailsResYear.value){
		var test1 = document.mainform.personalDetailsResYear.value;
	} else {
		var test1 = 0;
	}
	
	if(document.mainform.personalDetailsResMonth.value){
		var test2 = document.mainform.personalDetailsResMonth.value;
	} else {
		var test2 = 0;
	}
	
	if(test1 + test2 <= 0){
		document.mainform.personalDetailsResYear.style.color = "red";
		document.mainform.personalDetailsResYear.value = "*";

		document.mainform.personalDetailsResMonth.style.color = "red";
		document.mainform.personalDetailsResMonth.value = "*";
		errorTest = true;
	}
	
	
	
	//If the customer is required to enter their previous address
	if(test1 < 3 || document.mainform.personalDetailsResYear.value < 3){
		//Check customers previous Address
		if(!document.mainform.personalDetailsPrevAddress.value || !document.mainform.personalDetailsPrevAddress.style.color == "red"){
			document.mainform.personalDetailsPrevAddress.style.color = "red";
			document.mainform.personalDetailsPrevAddress.value = "Please enter your previous address";
			errorTest = true;
		}
		
		//Check customers previous postcode
		if(!document.mainform.personalDetailsPrevPostcode.value || !document.mainform.personalDetailsPrevPostcode.style.color == "red"){
			document.mainform.personalDetailsPrevPostcode.style.color = "red";
			document.mainform.personalDetailsPrevPostcode.value = "Postcode error";
			errorTest = true;
		}
		
		//Check customers previous town
		if(!document.mainform.personalDetailsPrevTown.value || !document.mainform.personalDetailsPrevTown.style.color == "red"){
			document.mainform.personalDetailsPrevTown.style.color = "red";
			document.mainform.personalDetailsPrevTown.value = "Previous  town error";
			errorTest = true;
		}
	}	
	
	//Check customers home telephone number
	var x = CheckPhoneNumber(document.mainform.personalDetailsHomeTel.value);
	if(!x){
		document.mainform.personalDetailsHomeTel.style.color = "red";
		document.mainform.personalDetailsHomeTel.value = "Phone number error";
		errorTest = true;
	}
	
	//Check customers daytime telephone number
	var x = CheckPhoneNumber(document.mainform.personalDetailsDayTel.value);
	if(!x){
		document.mainform.personalDetailsDayTel.style.color = "red";
		document.mainform.personalDetailsDayTel.value = "Phone number error";
		errorTest = true;
	}
	
	//Check Email address
	var x = checkMail(document.mainform.personalDetailsEmail.value);
	if(!x || !document.mainform.personalDetailsEmail.value || document.mainform.personalDetailsEmail.style.color == "red"){
		document.mainform.personalDetailsEmail.style.color = "red";
		document.mainform.personalDetailsEmail.value = "Email error";
		errorTest = true;
	}
	
	//Check customers bank / building society name
	if(!document.mainform.personalDetailsBankName.value){
		document.mainform.personalDetailsBankName.style.color = "red";
		document.mainform.personalDetailsBankName.value = "Bank name error";
		errorTest = true;
	}
	
	
	//Check length of time at bank
	if(document.mainform.personalDetailsBankYear.value){
		var test1 = document.mainform.personalDetailsBankYear.value;
	} else {
		var test1 = 0;
	}
	
	if(document.mainform.personalDetailsBankMonth.value){
		var test2 = document.mainform.personalDetailsBankMonth.value;
	} else {
		var test2 = 0;
	}
	
	if(test1 + test2 <= 0){
		document.mainform.personalDetailsBankYear.style.color = "red";
		document.mainform.personalDetailsBankYear.value = "*";

		document.mainform.personalDetailsBankMonth.style.color = "red";
		document.mainform.personalDetailsBankMonth.value = "*";
		errorTest = true;
	}
	
	//Check length of time in employment
	if(document.mainform.personalDetailsEmploymentYear.value){
		var test1 = document.mainform.personalDetailsEmploymentYear.value;
	} else {
		var test1 = 0;
	}
	
	if(document.mainform.personalDetailsEmploymentMonth.value){
		var test2 = document.mainform.personalDetailsEmploymentMonth.value;
	} else {
		var test2 = 0;
	}
	
	if(test1 + test2 <= 0){
		document.mainform.personalDetailsEmploymentYear.style.color = "red";
		document.mainform.personalDetailsEmploymentYear.value = "*";

		document.mainform.personalDetailsEmploymentMonth.style.color = "red";
		document.mainform.personalDetailsEmploymentMonth.value = "*";
		errorTest = true;
	}
	
	//If the user is required to fill out their business details
	if(!document.mainform.applicationType[0].checked){
		//Check buisness name
		if(!document.mainform.businessDetailsName.value){
			document.mainform.businessDetailsName.style.color = "red";
			document.mainform.businessDetailsName.value = "Buisness name error";
			errorTest = true;
		}
		
		//Check buisness address
		if(!document.mainform.businessDetailsAddress.value){
			document.mainform.businessDetailsAddress.style.color = "red";
			document.mainform.businessDetailsAddress.value = "Buisness address error";
			errorTest = true;
		}
				
		//Check buisness town
		if(!document.mainform.businessDetailsTown.value){
			document.mainform.businessDetailsTown.style.color = "red";
			document.mainform.businessDetailsTown.value = "Buisness town error";
			errorTest = true;
		}
		
		//Check buisness postcode
		if(!document.mainform.businessDetailsPostcode.value){
			document.mainform.businessDetailsPostcode.style.color = "red";
			document.mainform.businessDetailsPostcode.value = "Buisness postcode error";
			errorTest = true;
		}
		
		//Check buisness registration number
		if(!document.mainform.businessDetailsRegNumber.value){
			document.mainform.businessDetailsRegNumber.style.color = "red";
			document.mainform.businessDetailsRegNumber.value = "REG. number error";
			errorTest = true;
		}
		
		//Check buisness VAT number
		if(!document.mainform.businessDetailsVATNumber.value){
			document.mainform.businessDetailsVATNumber.style.color = "red";
			document.mainform.businessDetailsVATNumber.value = "VAT. number error";
			errorTest = true;
		}
		
		//Check customers business telephone number
		var x = CheckPhoneNumber(document.mainform.businessDetailsTelephone.value);
		if(!x){
			document.mainform.businessDetailsTelephone.style.color = "red";
			document.mainform.businessDetailsTelephone.value = "Phone number error";
			errorTest = true;
		}
		
		//Check buisness contact persons first name
		if(!document.mainform.businessDetailsFName.value){
			document.mainform.businessDetailsFName.style.color = "red";
			document.mainform.businessDetailsFName.value = "First name error";
			errorTest = true;
		}
		
		//Check business contact persons last name
		if(!document.mainform.businessDetailsLName.value){
			document.mainform.businessDetailsLName.style.color = "red";
			document.mainform.businessDetailsLName.value = "Last name error";
			errorTest = true;
		}
		
	}
	
	//Check account holders name
	if(!document.mainform.DirectDebitDetailsName.value){
		document.mainform.DirectDebitDetailsName.style.color = "red";
		document.mainform.DirectDebitDetailsName.value = "Account holder name error";
		errorTest = true;
	}
	
	//Check Account Number
	accountspc = document.mainform.DirectDebitDetailsAcountNum.value.replace(/\s+/g, "");
	accounttest = /^[0-9]{8}$/.test(accountspc);
	if(!accounttest || !document.mainform.DirectDebitDetailsAcountNum.value || document.mainform.DirectDebitDetailsAcountNum.style.color == "red"){
		document.mainform.DirectDebitDetailsAcountNum.style.color = "red";
		document.mainform.DirectDebitDetailsAcountNum.value = "Error";
		errorTest = true;
	}
	
	//Check Sort Code
	sortcodespc = document.mainform.DirectDebitDetailsSortCode.value.replace(/\s+/g, "");
	sortcodetest = /^[0-9]{6}$/.test(sortcodespc);
	if(!sortcodetest || !document.mainform.DirectDebitDetailsSortCode.value || document.mainform.DirectDebitDetailsSortCode.style.color == "red"){
		document.mainform.DirectDebitDetailsSortCode.style.color = "red";
		document.mainform.DirectDebitDetailsSortCode.value = "Error";
		errorTest = true;
	}
	
	//Check card holders name
	if(!document.mainform.creditCardDetailsName.value || document.mainform.creditCardDetailsName.style.color == "red"){
		document.mainform.creditCardDetailsName.style.color = "red";
		document.mainform.creditCardDetailsName.value = "Card holder name error";
		errorTest = true;
	}
	
	//Check credit card number
	ccnumspc = document.mainform.creditCardDetailsNum.value.replace(/\s+/g, "");
	ccnumtest = /^[0-9]{0,30}$/.test(ccnumspc);
	if(!ccnumtest || !document.mainform.creditCardDetailsNum.value || document.mainform.creditCardDetailsNum.style.color == "red"){
		document.mainform.creditCardDetailsNum.style.color = "red";
		document.mainform.creditCardDetailsNum.value = "Error";
		errorTest = true;
	}
	
	//Check that either a start date or and issue number has been set by the user
	if(document.mainform.creditCardDetailsStartMonth.value && !document.mainform.creditCardDetailsStartYear.value && !document.mainform.creditCardDetailsIssueNum.value){
		errorTest = true;
	} else if(!document.mainform.creditCardDetailsStartMonth.value && document.mainform.creditCardDetailsStartYear.value && !document.mainform.creditCardDetailsIssueNum.value){
		errorTest = true;
	} else if(!document.mainform.creditCardDetailsStartMonth.value && !document.mainform.creditCardDetailsStartYear.value && !document.mainform.creditCardDetailsIssueNum.value){
		errorTest = true;
	}

	if(!document.mainform.creditCardDetailsBankName.value){
		document.mainform.creditCardDetailsBankName.style.color = "red";
		document.mainform.creditCardDetailsBankName.value = "Error";
		errorTest = true;
	}
	
	//Check credit card security number
	ccnumspc = document.mainform.creditCardDetailsSecurityNum.value.replace(/\s+/g, "");
	ccnumtest = /^[0-9]{3}$/.test(ccnumspc);
	if(!ccnumtest || !document.mainform.creditCardDetailsSecurityNum.value || document.mainform.creditCardDetailsSecurityNum.style.color == "red"){
		document.mainform.creditCardDetailsSecurityNum.style.color = "red";
		document.mainform.creditCardDetailsSecurityNum.value = "*";
		errorTest = true;
	}
	
	//Check credit card type
	if(!document.mainform.creditCardDetailsCardType.value){
		errorTest = true;
	}
	//Check expiry
	if(!document.mainform.creditCardDetailsExpMonth.value || !document.mainform.creditCardDetailsExpYear.value){
		errorTest = true;
	}
	//Check proofs
	//Check proof of ID
	if(document.mainform.ProofIdentity[0].checked){ //User has submitted their passport number as proof of identity
		
		if(!document.mainform.ProofIdentityPassport.value || document.mainform.ProofIdentityPassport.style.color == "red"){
			document.mainform.ProofIdentityPassport.style.color = "red";
			document.mainform.ProofIdentityPassport.value = "Passport number error";
			errorTest = true;
		}
		
	} else if(document.mainform.ProofIdentity[1].checked) { //User has submitted their drivers licence as proof of identity
		
		if(!document.mainform.ProofIdentityDrivingLicence.value || document.mainform.ProofIdentityDrivingLicence.style.color == "red"){
			document.mainform.ProofIdentityDrivingLicence.style.color = "red";
			document.mainform.ProofIdentityDrivingLicence.value = "Drivers Licence error";
			errorTest = true;
		}
		
	} else if(document.mainform.ProofIdentity[2].checked) { //User has submitted their debit card as proof of identity
		
		if(!document.mainform.ProofIdentityDebitCard.value || document.mainform.ProofIdentityDebitCard.style.color == "red"){
			document.mainform.ProofIdentityDebitCard.style.color = "red";
			document.mainform.ProofIdentityDebitCard.value = "Debit Card error";
			errorTest = true;
		}
		
		if(!document.mainform.ProofIdentityDebitCardSort.value || document.mainform.ProofIdentityDebitCardSort.style.color == "red"){
			document.mainform.ProofIdentityDebitCardSort.style.color = "red";
			document.mainform.ProofIdentityDebitCardSort.value = "Sort code error";
			errorTest = true;
		}
		
	}
	//Check proof of Address
	if(document.mainform.ProofAddress[0].checked){ //User has submitted their drivers licence number as proof of address
		
		if(!document.mainform.ProofAddressDrivingLicence.value || document.mainform.ProofAddressDrivingLicence.style.color == "red"){
			document.mainform.ProofAddressDrivingLicence.style.color = "red";
			document.mainform.ProofAddressDrivingLicence.value = "Drivers Licence error";
			errorTest = true;
		}
		
	} else if(document.mainform.ProofAddress[1].checked) { //User has submitted their bank statement as proof of address
		if(!document.mainform.ProofAddressStatementACCNum.value || document.mainform.ProofAddressStatementACCNum.style.color == "red"){
			document.mainform.ProofAddressStatementACCNum.style.color = "red";
			document.mainform.ProofAddressStatementACCNum.value = "Statement Number error";
			errorTest = true;
		}
		if(!document.mainform.ProofAddressStatementName.value || document.mainform.ProofAddressStatementName.style.color == "red"){
			document.mainform.ProofAddressStatementName.style.color = "red";
			document.mainform.ProofAddressStatementName.value = "Account name error";
			errorTest = true;
		}
		if(!document.mainform.ProofAddressStatementSort.value || document.mainform.ProofAddressStatementSort.style.color == "red"){
			document.mainform.ProofAddressStatementSort.style.color = "red";
			document.mainform.ProofAddressStatementSort.value = "Sort code error";
			errorTest = true;
		}
		if(!document.mainform.ProofAddressStatementDateDay.value || !document.mainform.ProofAddressStatementDateMonth.value || !document.mainform.ProofAddressStatementDateYear.value){
			errorTest = true;
		}
	
	} else if(document.mainform.ProofAddress[2].checked) { //User has submitted their utilities bill as proof of address
		if(!document.mainform.ProofAddressUtilitiesType.value){
			errorTest = true;
		}
		if(!document.mainform.ProofAddressUtilitiesRefNum.value || document.mainform.ProofAddressUtilitiesRefNum.style.color == "red"){
			document.mainform.ProofAddressUtilitiesRefNum.style.color = "red";
			document.mainform.ProofAddressUtilitiesRefNum.value = "Reference Number error";
			errorTest = true;
		}
		if(!document.mainform.ProofAddressUtilitiesDateDay.value || !document.mainform.ProofAddressUtilitiesDateMonth.value || !document.mainform.ProofAddressUtilitiesDateYear.value){
			errorTest = true;
		}
	}
	
	
	//If there are no errors found, submit the form
	if(errorTest){
		alert("There were errors with your form, please revise and try again");
	} else {
		if(document.mainform.termsandconditions1.checked && document.mainform.termsandconditions2.checked){
			document.mainform.submit();
		} else {
			alert("You must agree to all the purchase terms and conditions");
			document.mainform.termsandconditions1.focus();
		}
	}
}

//This function is designed to enter the slashes into the text box as the user enters it
function formatBirthdate(){
	
	if(document.mainform.personalDetailsDOB.value.length == '2' && event.keyCode != 47){
		
		document.mainform.personalDetailsDOB.value = document.mainform.personalDetailsDOB.value + "/";
	}
	if(document.mainform.personalDetailsDOB.value.length == '5' && event.keyCode != 47){
		document.mainform.personalDetailsDOB.value = document.mainform.personalDetailsDOB.value + "/";
	}
}

//This function is used to limit field that only require numbers
function onlyNum (){
	if (event.keyCode<47||event.keyCode>57)
	return false
}

//This function is used to limit field that only require numbers and spaces
function onlyNumSpc (){
	if (event.keyCode != 32 && event.keyCode<47||event.keyCode>57)
	return false
}

//returns the code of a keypress
function keyPress (){
	alert(event.keyCode);
}
// End Hiding -->
