function validateform()
{ 


var aform = document.APPLYNEW;
var radiov = "NONE";
var rep = true;
var repdone = false;
with (aform) {
  if (TITLE.value == "0") {
       alert("Please select Title");
       TITLE.focus();
       return;
    }
 if (FNAME.value == "") {
       alert("Please enter your first name");
       FNAME.focus();
       return;
    }
 if (LNAME.value == "") {
       alert("Please enter your Surname");
       LNAME.focus();
       return;
    }
	if (PHONE.value.length < 6 && EMPPHONE.value.length < 6) {
       rep = confirm("You have not provided your home or work telephone number, whilst this is not a compulsory requirement please be advised that this may cause the processing of your application to be Declined. To go back and enter the information please click Cancel or if you prefer not to click OK");
       repdone = rep;
	   if (rep == false) {
	           PHONE.focus();
               return;
	 }
	   }
   if (YOBDD.value == "DD") {
       alert("Please enter the day you were born 'DD' of your date of birth");
	   YOBDD.focus();
       return;
 
    }
	 if (YOBDD.value == "") {
       alert("Please enter the day you were born 'DD' of your date of birth");
	    YOBDD.focus();
       return;
 
     	 }
		  if (YOBDD.value.length<2){
        alert("Please enter the day you were born as two digits using zero if the day is between 1 to 9, e.g. 08");
		 YOBDD.focus();
        return;
    }
	
	if (YOBDD.value<1|| YOBDD.value >31){
   alert("Please check you have entered the day you were born correctly, MUST be a number between 01 and 31");
    YOBDD.focus();
   return;
}
   if (YOBMM.value == "MM") {
       alert("Please enter the month you were born 'MM' of your date of birth");
	    YOBMM.focus();
       return;
 
    }
	 if (YOBMM.value == "") {
       alert("Please enter the month you were born 'MM' of your date of birth");
	    YOBMM.focus();
       return;
	   
	   }
		  if (YOBMM.value.length<2){
        alert("Please enter the month you were born as two digits using zero if the month is between 1 to 9, e.g. 08");
		 YOBMM.focus();
        return;
         
    }
	
		if (YOBMM.value<1|| YOBMM.value >12){
   alert("Please check you have entered the month you were born correctly, MUST be a number between 01 and 12");
    YOBMM.focus();
   return;
}

   if (YOBYY.value == "YYYY") {
       alert("Please enter the year you were born ");
	    YOBYY.focus();
       return;
 
    }
	 if (YOBYY.value == "") {
       alert("Please enter the year you were born ");
	   YOBYY.focus();
       return;
 
    }
	 if (YOBYY.value.length<4){
        alert("Please enter the year you were born as four digits e.g. 1972");
		YOBYY.focus();
        return;
         
    }
	
	if (YOBYY.value<1900|| YOBYY.value >1995){
   alert("Please check you have entered the year you were born correctly, you MUST be at least 18 years old");
   YOBYY.focus();
   return;
}
	
	 if (PHONE.value.length < 6 && repdone == false) {
       rep = confirm("You have not provided your home telephone number, whilst this is not a compulsory requirement please be advised that this may cause the processing of your application to be declined. To go back and enter the information please click Cancel or if you prefer not to click OK. If you do not have a landline number please leave blank.");
       if (rep == false) {
	           PHONE.focus();
               return;
	   }
    }
   if (BANKTIME.value == "0") {
       alert("Please select Length of time bank account held");
       BANKTIME.focus();
       return;
    }
    if (MSTATUS.value == "0") {
       alert("Please select Marital Status");
       MSTATUS.focus();
       return;
    }
	radiov = GetaRadio("CHG");
	if (radiov == "NONE") {
	 alert("Please select Yes or No to: Cheque guarantee card held ");
       return;
	   }
	else {CHGV.value = radiov; }
	if (CHGV.value == "YES" && CLIMIT.value == "0") {
	 alert("Please select your Cheque guarantee card Limit");
       return;
	   }
	  if (OCCTYPE.value == "0") {
       alert("Please select Occupancy");
       OCCTYPE.focus();
       return;
    }

	  if (OCCTIME.value == "0") {
       alert("Please select Time at Address");
       OCCTIME.focus();
       return;
    }
     if (EMPNAME.value == "") {
       alert("Please enter your employers name");
       EMPNAME.focus();
       return;
    }
   if (EMPJOB.value.length < 3) {
       alert("Please enter your Job Title");
       EMPJOB.focus();
       return;
    }
	if (EMPPHONE.value.length < 6 && repdone == false) {
       rep = confirm("You have not provided your work telephone number, whilst this is not a compulsory requirement please be advised that this may cause the processing of your application to be declined. To go back and enter the information please click Cancel or if you prefer not to click OK");
       if (rep == false) {
	           PHONE.focus();
               return;
	   }
    }
	  if (EMPTIME.value == "0") {
       alert("Please select Time with employer");
       EMPTIME.focus();
       return;
    }
	  if (EMPEMAIL.value.length < 5 && EMAIL.value.length < 5) {
       alert("Please enter either your home or work email address");
       EMAIL.focus();
       return;
    }
	  if (EMPTAKEHOME.value == "") {
       alert("Please enter your monthly take home pay");
       EMPTAKEHOME.focus();
       return;
  
    }
	  if (FPDNEXT.value.length < 10 || validate_date(FPDNEXT.value)) {
       alert("Please enter or select from calendar your next pay date in the format dd/mm/yyyy");
       FPDNEXT.focus();
       return;
  
    }
	radiov = GetaRadio("PD");
	if (radiov == "NONE") {
	 alert("Please select Yes or No to: Are you paid directly into your bank account? ");
       return;
	   }
	if (radiov == "NO") {
	 alert("To apply you must be paid directly into your bank account. ");
       return;  
    }
	radiov = GetaRadio("SBANK");
	if (radiov == "NONE") {
	 alert("Please select Yes or No to: Do you have a debit card on the SAME bank account? ");
       return;
	   }
	if (radiov == "NO") {
	 alert("To apply you must have a debit card on the SAME bank account. ");
       return;  
    }
  if (AMOUNT.value == "0") {
       alert("Please select the Advance you want");
       AMOUNT.focus();
       return;
    }
	
  if (CONTACT.value == "0") {
       alert("Please select how you prefer to be contacted");
       CONTACT.focus();
       return;
    }
	
  if (FIND.value == "0") {
       alert("Please let us know how you found our site");
       FIND.focus();
       return;
	}
   if (CHECK1.checked == false) {
       alert("Please tick your agree to all declarations at end of form");
       return;
    }
	 
  aform.submit();
 }      
}
function GetaRadio(objname)
{
var i = 0;
var ireturn = "NONE";
aform = document.APPLYNEW;
for (i = 0; i < aform.length; i++) {
            if (aform.elements[i].name == objname) {
                   if (aform.elements[i].checked == true) { ireturn = aform.elements[i].value }
           }
         }
return ireturn;
}
function validate_date(indate)
{
var dateerror = 0;
var i;
var j;
var format = "224";
var da;
if (indate.indexOf('/') == -1) { dateerror = 1; }
if (dateerror == 0) {
      da = indate.split('/');
	  if (da.length != format.length) { dateerror = 1; }
      for (i = 0; i < da.length && dateerror == 0; i++) {
	          if (da[i].length != format.charAt(i)) { dateerror = 1; }
	  }
	 for (i = 0; i < da.length && dateerror == 0; i++) {
		     for (j = 0; j < da[i].length && dateerror == 0; j++) {
	              if (da[i].charAt(j) < '0' || da[i].charAt(j) > '9') { dateerror = 1; }
			 }
	  }	      	
 }
return dateerror;
}

