function DCH_validateForm()
{
// defaults for the script
   var errors = '';
   var dateerror = '';
   var oMyForm = document.appform;
// regular expression patterns
   var validemail     = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   var validname      = /^([a-zA-Z\-'])+ *([a-zA-Z\- '])*$/;
   var validdate      = /^\d{1,2}\D+\d{1,2}\D+\d{2,4}$/;
   var validphone     = /^[\d ]{10,}$/;
   var validpc1       = /^[a-zA-Z0-9 ]{2,}$/;
   var validpc2       = /^[a-zA-Z0-9 ]{3,}$/;
   var validcurrency  = /^[0-9]{4,}$/;
   var valid3digit    = /^[0-9]{3}$/;
   var valid4digit    = /^[0-9]{4}$/;
   var validnumber    = /^[0-9]{1,}$/;
// test for basic mandatory form field values
   if(oMyForm.c1_ttl.value =='')
   {errors+='Select your title from the list.\n';}
   if(!validname.test(oMyForm.c1_fn.value))
   {errors+='Provide your first name.\n';}
   if(!validname.test(oMyForm.c1_sn.value))
   {errors+='Provide your last name.\n';}
   if((!validphone.test(oMyForm.c1_th.value)) && (!validphone.test(oMyForm.c1_tm.value)))
   {errors+='Provide at least one contact telephone number.\n';}
   if(oMyForm.calltime.value =='')
   {errors+='Tell us the best time to call you.\n';}
// DATE OF BIRTH CHECK
   if(oMyForm.c1_day.value != '' && oMyForm.c1_mnth.value != '' && oMyForm.c1_yr.value != '')
   {
      if(!valid4digit.test(oMyForm.c1_yr.value))
      { dateerror++; }
      if((oMyForm.c1_day.value == 31) && (oMyForm.c1_mnth.value == 4 || oMyForm.c1_mnth.value == 6 || oMyForm.c1_mnth.value == 9 || oMyForm.c1_mnth.value == 11))
      { dateerror++; }
      if((oMyForm.c1_day.value > 29) && (oMyForm.c1_mnth.value == 2)) 
      { dateerror++; }
   }
   else 
   { dateerror++; }
   if(dateerror) 
   { errors+='Invalid date for date of birth.\n'; }
// END OF DATE OF BIRTH CHECK
   if(!validemail.test(oMyForm.c1_em.value))
   {errors+='Provide a valid email address.\n';}
   if((oMyForm.c1_ad1.value =='') && (oMyForm.c1_ad2.value =='') && (oMyForm.c1_cty.value ==''))
   {errors+='Provide your postal address.\n';}
   if(!validpc1.test(oMyForm.c1_pc1.value) || !validpc2.test(oMyForm.c1_pc2.value))
   {errors+='Please provide a valid post code.\n';}
   if((oMyForm.ff_igr1.value !='') && (!validcurrency.test(oMyForm.ff_igr1.value)))
   {errors+='Annual income field is invalid.\n';}
   if(oMyForm.calltime.value =='')
   {errors+='What is the best time to call you?\n';}
   if(oMyForm.livingstatus.value =='')
   {errors+='Select your living status from the list.\n';}
   if(oMyForm.ff_et1.value =='')
   {errors+='Select your employment status from the list.\n';}
   if(oMyForm.c1_mar.value =='')
   {errors+='Select your marital status from the list.\n';}
   if(!validcurrency.test(oMyForm.ff_igr1.value))
   {errors+='Gross Annual Income field is invalid.\n';}
   if(oMyForm.c1_occ.value =='')
   {errors+='What is your occupation?\n';}
   if(oMyForm.c1_oct.value =='')
   {errors+='How long have you been in your current employment.\n';}
   
// credit history checks			
   if(oMyForm.ff_cr1.value == '')
   {errors+='Provide credit rating\n';}

// loan requirement checks
   if(oMyForm.loantype.value =='')
   {errors+='Select the required loan or mortgage type from the list.\n';}
   if((!validcurrency.test(oMyForm.ff_mr.value) ) || (oMyForm.ff_mr.value) < 5000 )
   {errors+='State required loan amount (at least £5000).\n';}
   if(isNaN(oMyForm.ff_mty.value) || (oMyForm.ff_mty.value <3))
   {errors+='Please state required repayment period in months.\n';}

//home owner questions
if(oMyForm.livingstatus.value =='Home Owner')
{
   if(!validcurrency.test(oMyForm.ff_hv.value))
   {errors+='Please state the approx value of your home\n';}
   if(!validcurrency.test(oMyForm.mortgagebalance.value))
   {errors+='Please state the approx balance of your mortgage\n';}
   if(!validcurrency.test(oMyForm.ff_pp.value))
   {errors+='Please state the approx purchase price of your home\n';}
   if(oMyForm.ff_pt.value =='')
   {errors+='Select your property type from the list.\n';}
   if(!validname.test(oMyForm.ff_ml.value))
   {errors+='Provide the name of your mortgage lender.\n';}
   if(oMyForm.ff_pd.value =='')
   {errors+='When did you buy your property.\n';}
   if(!validnumber.test(oMyForm.ff_mp.value))
   {errors+='What is your monthly mortgage payment?\n';}
}

// check to see if agreement has been checked
   if(oMyForm.dataprotection.checked == false)
   {errors+='Please tick the box to accept our data protection information.\n';}

// show errors or submit form
   if (errors){alert('We cannot accept your application until the following fields are completed\n-----------------------------------------------------------------------------\n'+errors);}
   else{oMyForm.submit();}
}

function checkPurpose()
{
   var errors = '';
   var oMyForm = document.appform;
   if(oMyForm.livingstatus.value =='')
   {errors+='Select your "Living Status" from the list before selecting loan type.\n';}
									
   switch(oMyForm.loantype.value)
   {
      case 'Home Improvements':
         if(oMyForm.livingstatus.value !='Home Owner' )
         {errors+='Tenants cannot have Home Improvement Loans.\n';}
         break;
   }
// show errors or continue
   if (errors)
   {
      alert('INVALID LOAN TYPE\n-----------------------------\n'+errors+'\nPlease check your entry under "Living Status" is appropriate to the type of loan or mortgage you require.');
      oMyForm.loantype.selectedIndex = 0;
      oMyForm.livingstatus.focus();
   }
}
