



<!-- FORM VALIDATION FIRST ADDED: KDD 26.01.09 -->
<!-- This one is for the contact us form -->
<!-- The quick response seems to throw a wobbly if we use it for both -->
<!-- Because the fields are different -->
<!-- Additional validation for telephone numbers -->
<!-- Added KDD 11.03.09 -->
<!-- Non numeric characters will not type into the input -->
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==""||value=="Your Name"||value=="Contact Telephone")
  {alert(alerttxt);return false;}
else {return true}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (chkExistingCustomer.checked == true)
    {
    if (validate_required(dmaid,"Please enter your DMA ID.")==false)
        {dmaid.focus();return false;}
    }
if (validate_required(name,"Please enter your name.")==false)
  {name.focus();return false;}
if (validate_required(phone,"Please enter your phone number.")==false)
  {phone.focus();return false;}
if (validate_required(postcode,"Please enter your postcode.")==false)
  {postcode.focus();return false;}
if (validate_required(email,"Please enter your email address.")==false)
  {email.focus();return false;}
if (validate_email(email,"Please enter a valid email address")==false)
  {email.focus();return false;}
if (privacy.checked == false )
	{
		alert ( "Please check the Privacy Policy." );
		privacy.focus();return false;
	}
}
}

      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

// QUICK RESPONSE
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==""||value=="Your Name"||value=="Contact Telephone")
  {alert(alerttxt);return false;}
else {return true}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}

function validate_form2(thisform)
{
with (thisform)
{
if (validate_required(name,"Please enter your name.")==false)
  {name.focus();return false;}
if (validate_required(phone,"Please enter your phone number.")==false)
  {phone.focus();return false;}
if (validate_required(email,"Please enter your email address.")==false)
  {email.focus();return false;}
if (validate_email(email,"Please enter a valid email address")==false)
  {email.focus();return false;}
if (privacy.checked == false )
	{
		alert ( "Please check the Privacy Policy." );
		privacy.focus();return false;
	}
}
}

// BANK SWITCHING
	function trim(stringToTrim) {
	  return stringToTrim.replace(/^\s+|\s+$/g,"");
	}

	String.prototype.ltrim = function() {
	  a = this.replace(/^\s+/, '');
	  return a;
	};


    function valid8 ()
    {
      with (document.stb) {

        if (trim(fname.value).length < 2) {
          alert ("You must enter a forename");
          fname.focus ();
          return false;
        }

        if (trim(mname.value).length > 0 && trim(mname.value).length < 2) {
          alert ("Minimum length for a middle name is 2 characters");
          lname.focus ();
          return false;
        }

        if (trim(lname.value).length < 2) {
          alert ("You must enter a surname");
          lname.focus ();
          return false;
        }
			
		if (dob_dd.selectedIndex == 0 || dob_mm.selectedIndex == 0 || dob_yy.selectedIndex == 0){
          alert ("You must enter a valid date of birth date");
          dob_dd.focus ();
          return false;
        }

		if (dob_dd.selectedIndex != conf_dob_dd.selectedIndex 
			|| dob_mm.selectedIndex != conf_dob_mm.selectedIndex 
			|| dob_yy.selectedIndex != conf_dob_yy.selectedIndex){
          alert ("The Date of Birth and the Date of Birth(confirmed) must match");
          dob_dd.focus ();
          return false;
        }
		
		dob.value=dob_yy.value + "-" + dob_mm.value + "-" + dob_dd.value;
				
		if (trim(hsnum.value).length == 0 && trim(hsname.value).length == 0){
          alert ("You must enter either a house name or a house number");
          hsnum.focus ();
          return false;
        }

 		if (trim(hsnum.value).length != 0 && trim(hsname.value).length != 0){ 
          alert ("You must enter either a house name or a house number\n(You cannot enter both)");
          hsnum.focus ();
          return false;
        }

 		if (trim(hsname.value).length != 0 && trim(hsname.value).length < 2){
          alert ("Minimum length for a house name is 2 characters");
          lname.focus ();
          return false;
		}

        if (trim(roadname.value).length < 2) {
          alert ("You must enter a road name");
          roadname.focus ();
          return false;
        }
		
        if (trim(city.value).length < 2) {
          alert ("You must enter a city name");
          city.focus ();
          return false;
        }

        if (trim(pc.value).length < 5) {
          alert ("You must enter a valid postcode (at least 5 characters long)");
          pc.focus ();
          return false;
        }

        if (hometel.value.length < 9 || hometel.value.substring(0,1) != '0') {
          alert ("You must enter a valid home telephone number \n(at least 9 characters beginning with '0')");
          hometel.focus ();
          return false;
        }

        if (trim(worktel.value).length != 0 && (trim(worktel.value).length < 9 || worktel.value.substring(0,1) != '0')) {
          alert ("If you enter a work telephone number, it must be at least 9 characters long and begin with '0'");
          worktel.focus ();
          return false;
        }

        if (trim(mobiletel.value).length != 0 && (trim(mobiletel.value).length < 9 || mobiletel.value.substring(0,1) != '0')) {
          alert ("If you enter a mobile number, it must be at least 9 characters long and begin with '0'");
          mobiletel.focus ();
          return false;
        }

		var atSym   = email.value.indexOf('@');
      	var period  = email.value.lastIndexOf('.');
      	var space   = email.value.indexOf(' ');
      	var len     = email.value.length - 1;

      	if (email.value == "" || ((atSym < 1) || (period <= atSym+1) || (period == len ) || (space  != -1))) {
		  alert ("You must enter a valid email address - please check");
          email.focus ();
          return false;
        }

        if (trim(password.value).length < 8) {
          alert ("Your must enter a valid password (at least 8 characters long)");
          password.focus ();
          return false;
        }
        	
        if (trim(password.value) != trim(password2.value)) {
          alert ("Your passwords dont match - please enter both passwords");
		  password.value = "";
		  password2.value ="";
          password.focus ();
          return false;
        }
        	
        if (trim(occupation.value).length < 2) {
          alert ("You must enter an occupation");
          occupation.focus ();
          return false;
        }

        if (isNaN(salary.value) || salary.value < 100){
          alert ("You must enter the salary for the load period (greater than 99)");
          salary.focus ();
          return false;
        }

        if (isNaN(loadvalue.value) || loadvalue.value < 100){
          alert ("You must enter the load value for each load period (greater than 99)");
          loadvalue.focus ();
          return false;
        }
		
		/*****************************
        if (loadvalue.value > (salary.value - dpvalue.value)){
          alert ("The load amount must be less than the salary minus the debt plan value");
          loadvalue.focus ();
          return false;
        }
		****************************/

		if (load_dd.selectedIndex == 0 || load_mm.selectedIndex == 0 || load_yy.selectedIndex == 0){
          alert ("You must enter a valid first load date");
          load_dd.focus ();
          return false;
        }

		var loadDate = new Date(load_yy.value, load_mm.value -1, load_dd.value) //Month is 0-11 in JavaScript
		today = new Date();
		//Set 1 day in milliseconds
		var one_day=1000*60*60*24
	
		difference = Math.ceil((loadDate.getTime()-today.getTime())/(one_day));

		if (difference < 3){
          alert ("The date must be at least 3 days in advance");
          load_dd.focus ();
          return false;
		}
		  		
		loaddate.value=load_yy.value + "-" + load_mm.value + "-" + load_dd.value;
		/********
        if (dma.value!= "" && (dpvalue.value == "" || isNaN(dpvalue.value) || dpvalue.value < 0)) {
          alert ("If you enter a DMA, you must also enter a value for the debt plan per load period greater than 0");
          dpvalue.focus ();
          return false;
        }

		if (dpvalue.value == "")
			dpvalue.value=0;

		********/
        if (trim(secquestion.value).length < 3) {
          alert ("You must enter a securtiy question");
          secquestion.focus ();
          return false;
        }

        if (trim(secanswer.value).length < 3) {
          alert ("You must enter an answer to the security question");
          secanswer.focus ();
          return false;
        }
      }
    }