
// Module version: 3.18.91



 var gDELIM      = "_";



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function ResolveCardNo( s ) {
 
 for ( var i=0,t='',allowable='0123456789 ';i<s.length;i++ ) {

  if ( allowable.indexOf( s.charAt( i ) ) != -1 ) {
    t += s.charAt( i );
  }
   // Bad chars found. Let user resolve them..
   else { return ''; }

 }

 // Return pure set of numbers
 return t;
}


function spliceDoubleStringVal( fullVal ) {

 var myStr2 = new String( "" );
 var i = -1;  

 if ( fullVal.length > 0 ) {
  i = fullVal.indexOf( gDELIM ) + 1;
  if ( i >= 0 ) {
   myStr2 = fullVal.slice( ( i ), fullVal.length );
   return myStr2;
  }
 }
  else { return ''; }

 return '';

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkMainAddressFields( add0, add1, add2, add3, postcode, allMustNotBeBlank, postcodecannotbeBlank ) {

 var retval = true;

 // All fields must have something in them (postcode can be missed)..
 if ( allMustNotBeBlank >= 1 ) {

  if ( ( add0.length <= 0 ) || ( add1.length <= 0 ) || ( add2.length <= 0 ) || ( add3.length <= 0 ) ) {
   retval = false;
  }
   else { retVal = true; }

 }


 if ( postcodecannotbeBlank >= 1 ) {
  // Postcode must be supplied
  if ( postcode.length <= 0 ) {
   retval = false;
  }
   else { retVal = true; }
 }

 return retval;

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkPostcode(postCode, canBeBlank, maxLength, ffName) {

 // Can the postcode be blank?
 if( canBeBlank != 1 ) {


  // Is it required but blank?
  if ( postCode.length <= 0 ) {
   return false;   
  }

  // Has a check on the max length been requested?
  if ( maxLength != -1 ) {
   if ( postCode.length > maxLength ) {
    return false;   
   }
  }
   

 }
  
 
 return true;

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function checkForUpTo2PhoneNosSupplied( telNo1, telNo2, telNo3, telNo4 ) {

var count = 0;
var a = telNo1.length;
var b = telNo2.length;
var c = telNo3.length;
var d = telNo4.length;

  if ( a > 0 ) { count++; }
  if ( b > 0 ) { count++; }
  if ( c > 0 ) { count++; }
  if ( d > 0 ) { count++; }

  if ( count >= 2 ) { 
   return true;
  }
   else { return false; }
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function checkMonthIsInFuture( monthVal, pastOrFuture ) {

 // Separate "IsANumber" check on the Month is assumed to have taken place by the time a call to this 
 // function occurs..

 var month2      = 0;
 var monthDigits = 0;
 
 currMonth       = new Date();
 monthDigits 	 = currMonth.getMonth();


 if ( pastOrFuture >= 1 ) {

  // Check month is in future...
  if ( monthVal > monthDigits ) {
   return true;
  }

 }
  else {

   // Check month is in past...
   if ( monthVal < monthDigits ) {
    return true;
   }

  }

 return false;

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function checkYearIsInFuture( yearVal ) {

 // Separate "IsANumber" check on the Year is assumed to have taken place by the time a call to this 
 // function occurs..

 var year2      = 0;
 var yearDigits = 0;
 
 currYear       = new Date();
 yearDigits 	= currYear.getFullYear();



// if ( yearVal.length = 2 ) { 
  // Convert to 4 digit year
//  year2 = yearDigits.substring( 0, 2 ) + yearVal;
// }


  // Check year is in future...
  if ( yearVal > yearDigits ) {
   return true;
  }
  else {
    return false;
  }


}



function checkMonthIsCurrent( monthVal ) {

 // Separate "IsANumber" check on the Month is assumed to have taken place by the time a call to this 
 // function occurs..

 var monthDigits = 0;
 var fMonth = new String("");
    

 currMonth       = new Date();
 monthDigits 	 = currMonth.getMonth();
 monthDigits++;

 if ( monthDigits < 10 ) { 
  fMonth = '0' + monthDigits.toString(); 
 }
  else { fMonth = monthDigits.toString(); }
 

  // Check month is same...
  if ( monthVal == fMonth ) {
   return true;
  }

 return false;

}




function checkMonthInThisYearHasNotExpired( monthVal ) {

 // Separate "IsANumber" check on the Month, year is assumed to have taken place by the time a call to this 
 // function occurs..

 var monthDigits = 0;
 
 currMonth       = new Date();
 monthDigits 	 = currMonth.getMonth();
 monthDigits++;


  // Check month for expiry
  if ( monthVal > monthDigits ) {
   return true;
  }

 return false;

}



function checkMonthInThisYearHasPassed( monthVal ) {

 // Separate "IsANumber" check on the Month, year is assumed to have taken place by the time a call to this 
 // function occurs..

 var monthDigits = 0;
 
 currMonth       = new Date();
 monthDigits 	 = currMonth.getMonth();
 monthDigits++;


  // Check month for expiry
  if ( monthVal < monthDigits ) {
   return true;
  } 
   else { return false; }

}




function checkYearIsCurrent( yearVal ) {

 // Separate "IsANumber" check on the Year is assumed to have taken place by the time a call to this 
 // function occurs..

 var year2      = 0;
 var yearDigits = 0;
 
 currYear       = new Date();
 yearDigits 	= currYear.getFullYear();



// if ( yearVal.length = 2 ) { 
  // Convert to 4 digit year
//  year2 = yearDigits.substring( 0, 2 ) + yearVal;
// }


  // Check year is in future...
  if ( yearVal == yearDigits ) {
   return true;
  }
   else {
    return false;
   }

}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}



function checkNotBlank( val ) {

 var valCk = new String( val );


 // Prevent "    " sneaks! :-)
 valCk = trim( valCk );


 if ( valCk.length <= 0 ) { 
  return false;
 } else { return true; }


}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function IsANumber( val ) {

 var myTestNo = val;

 if ( isNaN( myTestNo ) == true ) { 
  return false;
 }
  else { return true; }

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function IsEmailValid(checkThisEmail) {
var myEMailIsValid = true
var myAtSymbolAt = checkThisEmail.indexOf('@')
var myLastDotAt = checkThisEmail.lastIndexOf('.')
var mySpaceAt = checkThisEmail.indexOf(' ')
var myLength = checkThisEmail.length


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
{myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
{myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
{myEMailIsValid = false}


// no empt<y space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

 if (mySpaceAt != -1) 
 {myEMailIsValid = false}

 

 return myEMailIsValid
}




////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// The wrapper calls to the above that validate entire form sections..
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function checkYourDetails() {

 var s = new String( "" );
 var t = new String( "" );

 // Forname and Surname
 if ( ! checkNotBlank( document.frm.tfFORENAME_CLI_GE_0001.value ) ) {
  s = spliceDoubleStringVal( "tfFORENAME_CLI_GE_0001" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter your Forename. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfFORENAME_CLI_GE_0001.focus(); 
  return false;
 }

 if ( ! checkNotBlank( document.frm.tfSURNAME_CLI_GE_0001.value ) ) {
  s = spliceDoubleStringVal( "tfSURNAME_CLI_GE_0001" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter your Surname. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfSURNAME_CLI_GE_0001.focus(); 
  return false;
 }


 // EMAIL
 if ( ! checkNotBlank( document.frm.tfEMAIL_CLI_GE_0008.value ) ) {
  s = spliceDoubleStringVal( "tfEMAIL_CLI_GE_0008" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must supply your E-Mail address. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfEMAIL_CLI_GE_0008.focus(); 
  return false;
 }


 if ( ! IsEmailValid( document.frm.tfEMAIL_CLI_GE_0008.value ) ) {
  s = spliceDoubleStringVal( "_X_GE_0001" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must supply a valid E-Mail address. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfEMAIL_CLI_GE_0008.focus(); 
  return false;
 }


 // Home Tel
 if ( ! checkNotBlank( document.frm.tfHOMETELEPHONE_CLI_GE_0006.value ) ) {
  s = spliceDoubleStringVal( "tfHOMETELEPHONE_CLI_GE_0006" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter your Home Telephone Number. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfHOMETELEPHONE_CLI_GE_0006.focus(); 
  return false;
 }

 // At least 2 nos supplied
 if ( ! checkForUpTo2PhoneNosSupplied(  document.frm.tfHOMETELEPHONE_CLI_GE_0006.value, 
					document.frm.tfWORKTELEPHONE_CLI_GE_0006.value, 
					document.frm.tfMOBILENO_CLI_GE_0006.value, 
					document.frm.tfCONTACTTELEPHONE_CLI_GE_0006.value ) ) {
  s = spliceDoubleStringVal( "_CLI_GE_0007" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter your at least 2 contact Telephone Numbers. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfHOMETELEPHONE_CLI_GE_0006.focus(); 
  return false;
 }



/*  -- Business / Individual Selection Disabled by request.

 if (      ( document.frm.cbxINDIVORBUSINESS_X_GE_0000.options[document.frm.cbxINDIVORBUSINESS_X_GE_0000.selectedIndex].text != "Individual" ) 
        && ( ! checkNotBlank( document.frm.tfCOMPANYNAME_CLI_GE_0010.value )   )  )  {

  s = spliceDoubleStringVal( "tfCOMPANYNAME_CLI_GE_0010" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter your Company Name if you are not submitting this form as an Individual. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfCOMPANYNAME_CLI_GE_0010.focus(); 
  return false;
 }


 if (      ( document.frm.cbxINDIVORBUSINESS_X_GE_0000.options[document.frm.cbxINDIVORBUSINESS_X_GE_0000.selectedIndex].text == "Partnership"  ) 
        && ( ! checkNotBlank( document.frm.tfBUSPARTNERNAME_CLI_GE_0009.value )  )  )  {

  s = spliceDoubleStringVal( "tfBUSPARTNERNAME_CLI_GE_0009" );
  t = spliceDoubleStringVal( s );
  showError( 'Error. You must enter the name of your Business Partner if you are submitting this form as a member of a Partnership. ' + ' - The exact Error Code given was ' + t );
  document.frm.tfBUSPARTNERNAME_CLI_GE_0009.focus(); 
  return false;
 }

*/


 
return true;

}








function checkYourHomeAddress() {

 var s = new String( "" );
 var t = new String( "" );


 if ( ! checkMainAddressFields( document.frm.tfADDRESS0_CLI_GE_0004.value,
			        document.frm.tfADDRESS1_CLI_GE_0004.value,
			        document.frm.tfADDRESS2_CLI_GE_0004.value,
           		        document.frm.tfADDRESS3_CLI_GE_0004.value,
				document.frm.tfPOSTCODE_CLI_GE_0004.value, 1, 0 ) ) {

  s = spliceDoubleStringVal( "_CLI_GE_0004" );
  t = spliceDoubleStringVal( s );
  showError( 'Home Address check failed. All address lines must be completed (postcode can be blank). ' + ' - The exact Error Code given was ' + t );
  document.frm.tfADDRESS0_CLI_GE_0004.focus(); 
  return false;

 }





 return true;

}



function checkTermsRead() {

/* var s = new String( "" );
 var t = new String( "" );

  s = spliceDoubleStringVal( "cbTERMSREAD_X_TERMS_TE_0001" );
  t = spliceDoubleStringVal( s );
*/

 if ( document.frmOrder.cbTERMSREAD_X_TERMS_TE_0001.checked == false ) {
  showError( 'You must agree to the Terms and Conditions and signify your agreement by ticking the Terms Agreement box.' );
  document.frmOrder.cbTERMSREAD_X_TERMS_TE_0001.focus(); 
  return false;
 }
 


return true;


}




function ResolveCardNo( s ) {
 
 for ( var i=0,t='',allowable='0123456789 ';i<s.length;i++ ) {

  if ( allowable.indexOf( s.charAt( i ) ) != -1 ) {
    t += s.charAt( i );
  }
   // Bad chars found. Let user resolve them..
   else { return ''; }

 }

 // Return pure set of numbers
 return t;
}


function ResolveCardNo_NoSPACES( s ) {
 
 for ( var i=0,t='',allowable='0123456789';i<s.length;i++ ) {

  if ( allowable.indexOf( s.charAt( i ) ) != -1 ) {
    t += s.charAt( i );
  }
   // Bad chars found. Let user resolve them..
   else { return ''; }

 }

 // Return pure set of numbers
 return t;
}




function luhnCheck(cardNbr) {

    var result     = true;
	
    var ndx        = cardNbr.length - 1;
    var checkDigit = cardNbr.substr(ndx,1);
    var multiplier = 2;
    var accum      = 0;
	
    while(ndx)
    {
        var cardCh = cardNbr.substr(ndx - 1,1);
        if(cardCh >= 0 && cardCh <= 9)
        {
            var thisValue  = cardCh * multiplier;
            while(thisValue > 0)
            {
                accum += Math.floor(thisValue % 10);
                thisValue = Math.floor(thisValue / 10);
            }

            multiplier = (multiplier == 2 ? 1 : 2);
        }

        ndx--;
    }
	
    cc_checksum = ((10 - (accum % 10)) % 10);
    if(cc_checksum != checkDigit)
        result = false;

    return(result);

}



function checkPrefixAndLength(cardType, cardNbr)
{
    var result    = false;
	
    var amexRules			= new Array("37,37,15","34,34,15");
    var discRules			= new Array("6011,6011,16");
    var dinersRules		= new Array("36,36,14","38,38,14","300,305,14");
    var enrouteRules		= new Array("2014,2014,15","2149,2149,15");
    var jcbRules				= new Array("3,3,16","2131,2131,15","1800,1800,15");
    var mcRules				= new Array("51,55,16");
    var visaRules			= new Array("4,4,13","4,4,16");
    var switchRules		= new Array("490302,490309,18,1","490335,490339,18,1","491101,491102,16,1",
							                                  "491174,491182,18,1","493600,493699,19,1","564182,564182,16,2",
							                                  "633300,633300,16,0","633301,633301,19,1","633302,633349,16,0",
							                                  "675900,675900,16,0","675901,675901,19,1","675902,675904,16,0",
							                                  "675905,675905,19,1","675906,675917,16,0","675918,675918,19,1",
							                                  "675919,675937,16,0","675938,675940,18,1","675941,675949,16,0",
							                                  "675950,675962,19,1","675963,675997,16,0","675998,675998,19,1",
							                                  "675999,675999,16,0");
    var soloRules			= new Array("633450,633453,16,0","633454,633457,16,0","633458,633460,16,0",
			  	 										      "633461,633461,18,1","633462,633472,16,0","633473,633473,18,1",
							                                  "633474,633475,16,0","633476,633476,19,1","633477,633477,16,0",
														      "633478,633478,18,1","633479,633480,16,0","633481,633481,19,1",
							                                  "633482,633489,16,0","633490,633493,16,1","633494,633494,18,1",
							                                  "633495,633497,16,2","633498,633498,19,1","633499,633499,18,1",
							                                  "676700,676700,16,0","676701,676701,19,1","676702,676702,16,0",
							                                  "676703,676703,18,1","676704,676704,16,0","676705,676705,19,1",
							                                  "676706,676707,16,2","676708,676711,16,0","676712,676715,16,0",
							                                  "676716,676717,16,0","676718,676718,19,1","676719,676739,16,0",
							                                  "676740,676740,18,1","676741,676749,16,0","676750,676762,19,1",
							                                  "676763,676769,16,0","676770,676770,19,1","676771,676773,16,0",
							                                  "676774,676774,18,1","676775,676778,16,0","676779,676779,18,1",
							                                  "676780,676781,16,0","676782,676782,18,1","676783,676794,16,0",
							                                  "676795,676795,18,1","676796,676797,16,0","676798,676798,19,1",
							                                  "676799,676799,16,0");
    var thisRules;
	

    switch(cardType)
    {
        case "Amex" : thisRules = amexRules;
                   break;
        case "American Express" : thisRules = amexRules;
                   break;
        case "Discover" : thisRules = discRules;
                   break;
        case "Diners Club": thisRules = dinersRules;
                   break;

		// Treat Electron in same way as VISA
		case "Electron" : thisRules = visaRules;
                   break;

        case "Enroute" : thisRules = enrouteRules;
                   break;
        case "JCB" : thisRules = jcbRules;
                   break;
        case "MasterCard" : thisRules = mcRules;
                   break;

		// Switch and Maestro have merged - cater for possible old forms and new
		case "Maestro" : thisRules = switchRules;
                   break;
        case "Switch" : thisRules = switchRules;
                   break;
		case "Switch Maestro" : thisRules = switchRules;
                   break;
        case "Switch/Maestro" : thisRules = switchRules;
                   break;
        case "Switch / Maestro" : thisRules = switchRules;
                   break;
        case "Maestro / Switch" : thisRules = switchRules;
                   break;
        case "Maestro/Switch" : thisRules = switchRules;
                   break;


        case "Solo": thisRules = soloRules;
                   break;
        case "VISA" : thisRules = visaRules;
                   break;
		case "VISA Delta" : thisRules = visaRules;
                   break;

        default  : thisRules = new Array();
                   break;
    }
	
    var ndx;
    var ruleDetails;
    var done = false; 
    for(ndx = 0 ; ndx < thisRules.length && !done ; ++ndx)
    {
        thisRule    = thisRules[ndx];
        ruleDetails = thisRule.split(",");
        
        var hiPrefix        = ruleDetails[0];
        var loPrefix        = ruleDetails[1];
        var valLength       = ruleDetails[2];
        var issueLength     = ruleDetails[3];
        var startDateLength = ruleDetails[4];
        
        var cardPrefix = cardNbr.substr(0,hiPrefix.length);
        if(cardPrefix >= hiPrefix && cardPrefix <= loPrefix)
        {
            if(cardNbr.length == valLength)
            {
                result = true;
       				
                cc_switch_startDateLength = startDateLength;
                cc_switch_issueLength     = issueLength;
                done   = true;
            }
        }
    }
  	
    return(result);
}






function checkCreditDebitDetails(ccorder_mand, paymentMethod) {


 var ccnoTest = new String( "" );


// Must /is be a cc / dc order (type id 1)?
if ( ( ccorder_mand > 0 )  || ( paymentMethod == 1 ) ) {

	 if ( 
	      ( ! checkNotBlank( document.frmOrder.tfCC_CardHolder.value )  ) 
	        || 
		( ! checkNotBlank( document.frmOrder.tfCC_No.value ) ) 

	    ) {

	    showError( 'You have opted to pay by credit / debit card but the credit / debit card details are incomplete. Please review the details before attempting to submit your order again.' );
	    document.frmOrder.tfCC_No.focus(); 
	    return false;

	 }




	 // Card holder not blank?
	 if ( ! checkNotBlank( document.frmOrder.tfCC_CardHolder.value )  ) {
	    showError( 'The Card Holder Name on the Debit / Credit card must be entered with your card details.' );
	    document.frmOrder.tfCC_CardHolder.focus(); 
	    return false;
	 }


	// Minimum of 13 chars. for CC Number (a VISA card does have this number!). No single card has less!

	if (    ( document.frmOrder.tfCC_No.value.length < 13 )
	     || ( ! checkNotBlank( document.frmOrder.tfCC_No.value ) ) 
	//     || ( ! IsANumber(     document.frmOrder.tfCC_No.value ) )
	   ) {
	    showError( 'Please supply the the card number on the credit / debit card. The number is (typically) a minimum of 13 digits.' );
	    document.frmOrder.tfCC_No.focus(); 
	    return false;
	 }


	// Run a check on the number to ensure it contains only numbers and NO spaces. Return is (hopefully) 
	// a number only, without spaces and other non-integer chars. It is that value we check isNAN=false
	// The back-end does the REAL work of validating the card.

	ccnoTest = ResolveCardNo_NoSPACES( document.frmOrder.tfCC_No.value );

	if ( ! checkNotBlank( ccnoTest ) ) {
		 // Return was blank, meaning a bad char. was found..
	    showError( 'Please supply the Card Number on the credit / debit card. Please enter only a pure number, do not include any spaces.' );
	    document.frmOrder.tfCC_No.focus(); 
	    return false;
	}

	if ( ! luhnCheck(ccnoTest) ) {
		 // LUHN failure
	    showError( 'The Card Number supplied failed a checksum validation. Check the number you entered is exactly as it appears on your card, without spaces.' );
	    document.frmOrder.tfCC_No.focus(); 
	    return false;
	}

	if (! checkPrefixAndLength(document.frmOrder.cbxCC_Type.options[document.frmOrder.cbxCC_Type.selectedIndex].text, ccnoTest) ) {
		 // PREFIX Failure
	    showError( 'The prefix of the Card Number supplied for the selected Card Type did not tally. Check you have entered the correct Card Number and selected the appropriate Card Type.' );
	    document.frmOrder.tfCC_No.focus(); 
	    return false;
	}


	if ( ( checkMonthIsCurrent( document.frmOrder.cbxCCValidFromMM.options[document.frmOrder.cbxCCValidFromMM.selectedIndex].text ) == true ) && ( checkYearIsCurrent( document.frmOrder.cbxCCValidFromYYYY.options[document.frmOrder.cbxCCValidFromYYYY.selectedIndex].text ) == true ) ) 
	{ 
	 // Same month and year are a valid card valid from 
	}
	 else {

		 // Check Combined valid from date (MM/YYYY) is valid (combined month and year must be in the past)
		 if ( ( checkMonthInThisYearHasNotExpired( document.frmOrder.cbxCCValidFromMM.options[document.frmOrder.cbxCCValidFromMM.selectedIndex].text ) == true ) && ( checkYearIsCurrent( document.frmOrder.cbxCCValidFromYYYY.options[document.frmOrder.cbxCCValidFromYYYY.selectedIndex].text ) == true ) )
		 {
		    showError( 'You have selected an invalid Valid From Month in the credit / debit card details. The combined Valid From Month and Year date is in the future.' );
		    document.frmOrder.tfCC_CardHolder.focus(); 
		    return false;
        }

	 }





	if ( ( checkMonthIsCurrent( document.frmOrder.cbxCCValidFromMM.options[document.frmOrder.cbxCCValidFromMM.selectedIndex].text ) == true ) && ( checkYearIsCurrent( document.frmOrder.cbxCCValidFromYYYY.options[document.frmOrder.cbxCCValidFromYYYY.selectedIndex].text ) == true ) ) 
	{ 
	 // Same month and year are a valid card valid from 
	 
	}
	 else {
	
		 // Check Combined valid from date (MM/YYYY) is valid (combined month and year must be in the past)
		 if ( ( checkMonthInThisYearHasNotExpired( document.frmOrder.cbxCCValidFromMM.options[document.frmOrder.cbxCCValidFromMM.selectedIndex].text ) == true ) && ( checkYearIsCurrent( document.frmOrder.cbxCCValidFromYYYY.options[document.frmOrder.cbxCCValidFromYYYY.selectedIndex].text ) == true ) )
		 {
		    showError( 'You have selected an invalid Valid From Month in the credit / debit card details. The combined Valid From Month and Year date is in the future.' );
		    document.frmOrder.tfCC_CardHolder.focus(); 
		    return false;
	         }
	}
	




	// Check Combined Expiry date (MM/YYYY) is valid (combined month and year must be in the future or expire in the current month)
	 if ( ( checkMonthInThisYearHasPassed( document.frmOrder.cbxCCExpiryMM.options[document.frmOrder.cbxCCExpiryMM.selectedIndex].text ) == true ) && ( checkYearIsCurrent( document.frmOrder.cbxCCExpiryYYYY.options[document.frmOrder.cbxCCExpiryYYYY.selectedIndex].text ) == true ) )  
	 {
	   showError( 'You have selected an invalid Expiry Month in the credit / debit card details. The combined Expiry Month and Year date is in the past.' );
	   document.frmOrder.tfCC_CardHolder.focus(); 
	   return false;
	 }




	// Switch requires Issue No. and the number can be different
	 if ( document.frmOrder.cbxCC_Type.options[document.frmOrder.cbxCC_Type.selectedIndex].text == "Switch" ) {

	   if ( ! checkNotBlank( document.frmOrder.tfCC_IssueNo.value ) ) {
	    showError( 'You must enter a Switch Card Issue Number when selecting Switch as the Credit Card Type.' );
	    document.frmOrder.tfCC_IssueNo.focus(); 
	    return false;
	   }


	   if ( ! IsANumber( document.frmOrder.tfCC_IssueNo.value ) ) {
	    showError( 'You must enter a valid number for the Switch Card Issue Number when selecting Switch as the Credit Card Type.' );
	    document.frmOrder.tfCC_IssueNo.focus(); 
	    return false;
	   }

	 }



       // Check the CV2 number (if supplied)
  	 if ( checkNotBlank( document.frmOrder.tfCC_V2No.value ) ) {
	   if ( ! IsANumber( document.frmOrder.tfCC_V2No.value ) ) {
		showError( 'You must enter a valid number for the AV/CV2 Check Number. The information entered should be a pure number, without spaces. The AV/CV2 number is the last 3 digits on the back of your card.' );
	    document.frmOrder.tfCC_V2No.focus(); 
	    return false;
	   }
	 }
	 else {
		showError( 'You must enter a valid number for the AV/CV2 Check Number. The information entered should be a pure number, without spaces. The AV/CV2 number is the last 3 digits on the back of your card.' );
	    document.frmOrder.tfCC_V2No.focus(); 
	    return false;
	 }



}


return true;


}




function checkDDebitDetails( DDIsMandatory, NetName ) {

 var s = new String( "" );
 var t = new String( "" );

// && ( document.frm.cbPayMonthlyBillByDD_TED_DDME_0001.value = "0" ) ) {

// If network MUST have a DD, check the details..


if ( DDIsMandatory >= 1 ) {

 if ( 
      (  ! checkNotBlank( document.frm.tfBANKNAME_TED_DDME_00006.value )  )  
      ||
      (  ! checkNotBlank( document.frm.tfBANKADD0_TED_DDME_0005.value )   )
      ||
      (  ! checkNotBlank( document.frm.tfBANKADD1_TED_DDME_0005.value )   )
      ||
      (  ! checkNotBlank( document.frm.tfBANKADD2_TED_DDME_0005.value )   )
      ||
      (  ! checkNotBlank( document.frm.tfBANKADD3_TED_DDME_0005.value )   )
      ||
      (  ! checkNotBlank( document.frm.tfBANKPCODE_TED_DDME_0005.value )  )
      ||
      (  ! checkNotBlank( document.frm.tfACCHOLDER1_TED_DDME_0004.value ) )
      ||
      (  ! checkNotBlank( document.frm.tfBANKSORT_TED_DDME_0003.value )   ) 
      ||
      (  ! checkNotBlank( document.frm.tfBANKACC_TED_DDME_0002.value )    ) 
      || 
      (  ! IsANumber( document.frm.tfBANKACC_TED_DDME_0002.value )        )
      || 
      (  ! IsANumber( document.frm.tfBANKSORT_TED_DDME_0003.value )       ) 
      
   ) {
 

     s = spliceDoubleStringVal( "tfBANKNAME_TED_DDME_00006" );
     t = spliceDoubleStringVal( s );

     if ( ! NetName == "" ) {
      showError( 'You must submit your all of your Bank Details in the Direct Debit section of the form as ' + NetName + ' must setup a Direct Debit with your account. Please also ensure the Sort Code and Account number are numbers, not letters.' + ' - The exact Error Code given was ' + t );
     }
      else { showError( 'You must submit all of your Bank Details in the Direct Debit section of the form. ' + ' - The exact Error Code given was ' + t ); }

     document.frm.tfBANKNAME_TED_DDME_00006.focus(); 
     return false;

 }

}

 return true;

}







function checkCartQuantityUpdate(qty) {

// Check Quantity Entry..
if ( qty != null ) {
	
	if ( ! checkNotBlank( qty ) ) {
		alert( 'You must enter a Quantity in the Quantity entry box. (You appear to have left it blank).' );
		return false;
	}
	else {
		if ( ! IsANumber( qty ) ) {
			alert( 'You must enter a valid Quantity Value in the Quantity entry box.\n\n- You have not entered a genuine number.' );
			return false;
		}
	}

} 

	 
 return true;


}





function checkCartAdditionUpdate(fObj) {

// Check Colour CBX if needed
if ( document.forms[fObj].cbxColours != null ) {

	if ( document.forms[fObj].cbxColours.options[document.forms[fObj].cbxColours.selectedIndex].value == '-1' ) { 
		document.forms[fObj].cbxColours.focus();
		alert( 'You must select a Colour from the drop-down list.' );
		return false;
	}

} 


// Check Size CBX if needed
if ( document.forms[fObj].cbxSizes != null ) {

	if ( document.forms[fObj].cbxSizes.options[document.forms[fObj].cbxSizes.selectedIndex].value == '-1' ) { 
		document.forms[fObj].cbxSizes.focus();
		alert( 'You must select a Size from the drop-down list.' );
		return false;
	}

} 


// Check Quantity Entry..
if ( document.forms[fObj].tfQty != null ) {
	
	if ( ! checkNotBlank( document.forms[fObj].tfQty.value ) ) {
		document.forms[fObj].tfQty.focus();
		alert( 'You must enter a Quantity in the Quantity entry box. (You appear to have left it blank).' );
		return false;
	}
	else {
		if ( ! IsANumber( document.forms[fObj].tfQty.value ) ) {
			document.forms[fObj].tfQty.focus();
			alert( 'You must enter a valid Quantity Value in the Quantity entry box. (You have not entered a genuine number).' );
			return false;
		}
	}

} 

	 
 return true;


}









function checkSearchCriteria(criteria) {


if ( criteria != null ) {
	
	if ( ! checkNotBlank( criteria ) ) {
		alert( 'You must type in something to search for in the Search entry box.' );
		return false;
	}

} 

	 
 return true;


}




function checkOrderForm( ccorder_mand, paymentMethod ) {


	/* paymentMethod:

			0 - Credit Card (i.e. PDQ)
			1 - 3rd Party Gateway
			2 - Account Based Order / Login

	*/


	// Core Name etc.
	if ( paymentMethod > 1 )
	{

		// Account Login based orders use a single field for the Name / Company Name
		if ( ! checkNotBlank( document.frmOrder.tfCliFullName.value ) ) {
			alert( 'You must supply your Full Name. The box for your Name appears to be blank.' );
			document.frmOrder.tfCliFullName.focus();
			return false;
		}

	}

	if ( paymentMethod < 2 )
	{

		// https / SSL orders use separate fields for the Fore / Surnames
		if ( ! checkNotBlank( document.frmOrder.tfCliForeNames.value ) ) {
			alert( 'You must supply your Forename(s). The box for your Forename(s) appears to be blank.' );
			document.frmOrder.tfCliForeNames.focus();
			return false;
		}

		if ( ! checkNotBlank( document.frmOrder.tfCliSurname.value ) ) {
			alert( 'You must supply your Surname. The box for your Surname appears to be blank.' );
			document.frmOrder.tfCliSurname.focus();
			return false;
		}


	}


/* Stand-alone check if email address WAS entered
	if ( checkNotBlank( document.frmOrder.tfCliEMail.value ) ) {
		if ( ! IsEmailValid( document.frmOrder.tfCliEMail.value ) ) {
			alert( 'Please supply a valid E-Mail Address. Ensure this includes the "@" symbol.' );
			document.frmOrder.tfCliEMail.focus();
			return false;
		}
	}
*/

	// E-Mail Address
	if ( ! checkNotBlank( document.frmOrder.tfCliEMail.value ) ) {
		alert( 'You must supply your E-Mail Address. The e-mail entry box appears to be blank.' );
		document.frmOrder.tfCliEMail.focus();
		return false;
	}

	if ( ! IsEmailValid( document.frmOrder.tfCliEMail.value ) ) {
		alert( 'You must supply a valid E-Mail Address. Ensure this includes the "@" symbol.' );
		document.frmOrder.tfCliEMail.focus();
		return false;
	}


	// Main Tel No.
	if ( ! checkNotBlank( document.frmOrder.tfCliTelNo.value ) ) {
		alert( 'You must supply your Telephone Contact Number. The box for this appears to be blank.' );
		document.frmOrder.tfCliTelNo.focus();
		return false;
	}


	


	// Home Address
	if ( ! checkNotBlank( document.frmOrder.tfCliAdd1.value ) ) {
		alert( 'You must supply the first line of your Address. The box for this appears to be blank.' );
		document.frmOrder.tfCliAdd1.focus();
		return false;
	}


	if ( ! checkNotBlank( document.frmOrder.tfCliAdd2.value ) ) {
		alert( 'You must supply the second line of your Address. The box for this appears to be blank.' );
		document.frmOrder.tfCliAdd2.focus();
		return false;
	}

	if ( ! checkNotBlank( document.frmOrder.tfCliAdd3.value ) ) {
		alert( 'You must supply the third line of your Address. The box for this appears to be blank.' );
		document.frmOrder.tfCliAdd3.focus();
		return false;
	}


	if ( ! checkNotBlank( document.frmOrder.tfCliPostcode.value ) ) {
		alert( 'You must supply the Postcode of your main address. The box for this appears to be blank.' );
		document.frmOrder.tfCliPostcode.focus();
		return false;
	}


    if ( paymentMethod > 1 )
    {
		if ( ! checkNotBlank( document.frmOrder.tfCliPONumber.value ) ) {
			alert( 'You must supply a valid Purchase Order Number for the Payment Method you have chosen. The box for this number appears to be blank.' );
			document.frmOrder.tfCliPONumber.focus();
			return false;
		}
		
    }



	// Disabled - PayPal systems are used instead..
	if ( paymentMethod == 0 )
	{
		// Force 1, 1 (card mandatory, payment we set to 1 even though we are using method 0)
		if ( ! checkCreditDebitDetails(1, 1) )	{
			return false;
		}
	}
	


	if ( ! checkTermsRead() )
	{
		return false;
	}



 return true;


}







function checkMailingListForm(fObj) {


	// Core Name etc.
	if ( ! checkNotBlank( document.forms[fObj].tfCliFirstNames.value ) ) {
		alert( 'You must supply your First Name(s). The box for your First Name(s) appears to be blank.' );
		document.forms[fObj].tfCliFirstNames.focus();
		return false;
	}

	if ( ! checkNotBlank( document.forms[fObj].tfCliSurname.value ) ) {
		alert( 'You must supply your Surname. The box for this appears to be blank.' );
		document.forms[fObj].tfCliSurname.focus();
		return false;
	}




	// E-Mail Address
	if ( ! checkNotBlank( document.forms[fObj].tfCliEMail.value ) ) {
		alert( 'You must supply your E-Mail Address. The e-mail entry box appears to be blank.' );
		document.forms[fObj].tfCliEMail.focus();
		return false;
	}

	if ( ! IsEmailValid( document.forms[fObj].tfCliEMail.value ) ) {
		alert( 'You must supply a valid E-Mail Address. Ensure this includes the "@" symbol.' );
		document.forms[fObj].tfCliEMail.focus();
		return false;
	}


	// Confirmation of email address:
	if ( document.forms[fObj].tfCliEMail.value != document.forms[fObj].tfCliEMailConf.value ) {
		alert( 'You must confirm your e-mail address by entering it twice on the boxes provided. The two addresses must exactly match.' );
		document.forms[fObj].tfCliEMailConf.focus();
		return false;		
	}



	// Home Address
	if ( ! checkNotBlank( document.forms[fObj].tfCliAdd1.value ) ) {
		alert( 'You must supply the first line of your main address. The box for this appears to be blank.' );
		document.forms[fObj].tfCliAdd1.focus();
		return false;
	}

	if ( ! checkNotBlank( document.forms[fObj].tfCliPostcode.value ) ) {
		alert( 'You must supply the Postcode of your main address. The box for this appears to be blank.' );
		document.forms[fObj].tfCliPostcode.focus();
		return false;
	}


	if	( 
											  document.forms[fObj].cbxBirthDateDD.options[document.forms[fObj].cbxBirthDateDD.selectedIndex].value == '01'
		&&								  document.forms[fObj].cbxBirthDateMM.options[document.forms[fObj].cbxBirthDateMM.selectedIndex].value == '01'
		&&								  document.forms[fObj].tfBirthDateYYYY.value.length <= 0
		)
	{
		// Date of Birth is defaulting (no need to process / validate it)	
	}
	else {

		// Date of Birth is not set at defaults - validate the selections..
		if ( ! checkNotBlank( document.forms[fObj].tfBirthDateYYYY.value ) ) {
			alert( 'You must enter a Year value for the Date of Birth. (You appear to have left it blank).' );
			document.forms[fObj].tfBirthDateYYYY.focus();
			return false;
		}
		
		if ( ! IsANumber( document.forms[fObj].tfBirthDateYYYY.value ) ) {
				alert( 'You must enter a valid Year in the entry box.\n\n- You have not entered a genuine number.' );
				document.forms[fObj].tfBirthDateYYYY.focus();
				return false;
		}

		if ( checkYearIsInFuture( document.forms[fObj].tfBirthDateYYYY.value ) == true ) {
				alert( 'You have entered an invalid Year in the Date of Birth section of the form. The Birth Year is in the future.' );
				document.forms[fObj].tfBirthDateYYYY.focus();
				return false;
		}
	
	}




 return true;



}






function checkPostcode()
{

	// Requires a FULL code WITH A SPACE

	if ( ! checkNotBlank( document.frmPickPostcode.tfPostcode.value ) ) {
		alert( 'You must supply the Postcode of your Delivery Address. The box for this appears to be blank.' );
		document.frmPickPostcode.tfPostcode.focus();
		return false;
	}

    // Must include a space after prefix
	var mySpaceAt = document.frmPickPostcode.tfPostcode.value.indexOf(' ');

	if ( mySpaceAt <= -1 ) {
		alert( 'You must supply the FULL Postcode of your Delivery Address.\n\nPlease INCLUDE the space between the 2 parts of your postcode.\n\nExample: PR2 2YL' );
		document.frmPickPostcode.tfPostcode.focus();
		return false;
    }


	
	return true;

}




 function checkPriceRange()
 {
			
 	if ( ! IsANumber( document.FrmSubSearchByPrice.tfPriceFrom.value ) )
	{
		showError( 'Please supply a valid decimal amount for the Price From value.' );
		document.FrmSubSearchByPrice.tfPriceFrom.focus(); 
		return false;
	}
				
	if ( ! IsANumber( document.FrmSubSearchByPrice.tfPriceTo.value ) )
	{
		showError( 'Please supply a valid decimal amount for the Price To value.' );
		document.FrmSubSearchByPrice.tfPriceTo.focus(); 
		return false;
	}
			
		
 	if ( double.Parse( document.FrmSubSearchByPrice.tfPriceTo.value ) < double.Parse( document.FrmSubSearchByPrice.tfPriceFrom.value ) )
	{
		showError( 'Please amend your price range values so that the From value is LESS than the To value.' );
		document.FrmSubSearchByPrice.tfPriceFrom.focus(); 
		return false;
	}
			
			
	return true;
							
}
			
			 
			 
function confirmBackOrder() {
	if ( confirm('Are you sure you wish to back order this item, it is currently out of stock?\n\nN O T E:\n\nWe will not process your credit card until the goods have been secured.\n\nDepending on the time of day, you may wish to click the Real-Time Stock Check link to get an up-to-the-minute stock level status for the product you are attempting to buy (note this link is not available for all products).\n\nProceed?') ) {
		return true;
	}
	else { return false; }
}