//var normal_color = '#FFFFA0'; var normal_color = '#FFFFFF'; var error_color = '#FFD7D7'; String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,""); } String.prototype.ltrim = function(){ return this.replace(/^\s+/,""); } String.prototype.rtrim = function(){ return this.replace(/\s+$/,""); } function $(id) { return document.getElementById(id); } function validate_form1() { $('error_more_less').innerHTML = ' '; $('err_div_tx').innerHTML = 'Please fix all the red fields!'; $('customer.loan.requested').style.background = normal_color; $('customer.gender').style.background = normal_color; $('customer.firstName').style.background = normal_color; $('customer.lastName').style.background = normal_color; $('customer.phone1.digits').style.background = normal_color; $('customer.phone3.digits').style.background = normal_color; $('customer.email').style.background = normal_color; $('customer.dob.date').style.background = normal_color; $('customer.employment.employerName').style.background = normal_color; err = 0; // amount requested if(IsEmptyField('customer.loan.requested')){ $('customer.loan.requested').style.background = error_color; err = 1; } else{ req = parseInt($('customer.loan.requested').value); if(req < 80){ $('error_more_less').innerHTML = "Loan Requested must be greater than 80 Pounds"; $('customer.loan.requested').style.background = error_color; err=1; } if(req > 1000){ $('error_more_less').innerHTML = "Loan Requested must be less than 1,000 Pounds"; $('customer.loan.requested').style.background = error_color; err=1; } } // title/gender if(IsEmptyField('customer.gender')){ $('customer.gender').style.background = error_color; err = 1; } // first name if(!validName($('customer.firstName').value)){ $('customer.firstName').style.background = error_color; err = 1; } // last name if(!validName($('customer.lastName').value)){ $('customer.lastName').style.background = error_color; err = 1; } // home phone homePhone = $('customer.phone1.digits').value; if(!validPhone(homePhone)){ $('customer.phone1.digits').style.background = error_color; err = 1; } // mobile phone cellPhone = $('customer.phone3.digits').value; if(!validCellPhone(cellPhone)){ $('customer.phone3.digits').style.background = error_color; err = 1; } // email if(!checkMail($('customer.email').value)){ $('customer.email').style.background = error_color; err = 1; } var dt1 = $('customer.dob.date').value; if(validateDate(dt1, 1900, 2000) == false){ $('customer.dob.date').style.background = error_color; err = 1; } else if(getAge(dt1) < 18){ $('err_div_tx').innerHTML = "You must be 18 or over."; $('customer.dob.date').style.background = error_color; err = 1; } var ename = $('customer.employment.employerName').value; if(IsEmptyField('customer.employment.employerName') || ename.length < 2){ $('customer.employment.employerName').style.background = error_color; err = 1; } if($("allow_mails").checked == false && err == 0) { alert('To submit, please check that you have read our privacy policy'); err = 1; } if (err == 1){ $('errdiv').style.display = 'block'; return false; } $('errdiv').style.display = 'none'; return true; } function clear_required_fields() { $('customer.firstName').style.background = '#FFFFFF'; $('customer.lastName').style.background = '#FFFFFF'; $('customer.streetNumber').style.background = '#FFFFFF'; $('customer.streetName').style.background = '#FFFFFF'; $('customer.state').style.background = '#FFFFFF'; $('customer.city').style.background = '#FFFFFF'; $('customer.zip').style.background = '#FFFFFF'; $('customer.email').style.background = '#FFFFFF'; $('customer.phone1.digits').style.background = '#FFFFFF'; $('customer.phone3.digits').style.background = '#FFFFFF'; $('customer.dob.date').style.background = '#FFFFFF'; $('customer.employment.employerName').style.background = '#FFFFFF'; $('customer.employment.incomeSource').style.background = '#FFFFFF'; $('customer.employment.netSalary').style.background = '#FFFFFF'; $('customer.bankAccount.directDeposit').style.background = '#FFFFFF'; $('customer.employment.howOftenPaid').style.background = '#FFFFFF'; $('customer.phone2.digits').style.background = '#FFFFFF'; $('customer.employment.payDate1').style.background = '#FFFFFF'; $('customer.employment.jobTimeMonths').style.background = '#FFFFFF'; $('customer.hasCC').style.background = '#FFFFFF'; $('customer.loan.requested').style.background = '#FFFFFF'; $('error_more_less').innerHTML=''; $('err_div_tx').innerHTML='Please fix all the red fields!'; $('customer.gender').style.background = '#FFFFFF'; $('customer.employment.payDate2').style.background = '#FFFFFF'; $('customer.employment.nin').style.background = '#FFFFFF'; $('cash_timeAtHome').style.background = '#FFFFFF'; } function check_fields() { var err=0; clear_required_fields(); if(IsEmptyField('customer.employment.payDate2')){$('customer.employment.payDate2').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.gender')){$('customer.gender').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.firstName')){$('customer.firstName').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.lastName')){$('customer.lastName').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.streetNumber')){$('customer.streetNumber').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.streetName')){$('customer.streetName').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.state')){$('customer.state').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.city')){$('customer.city').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.email')){$('customer.email').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.phone1.digits')){$('customer.phone1.digits').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.phone3.digits')){$('customer.phone3.digits').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.dob.date')){$('customer.dob.date').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.employment.employerName')){$('customer.employment.employerName').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.employment.incomeSource')){$('customer.employment.incomeSource').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.bankAccount.directDeposit')){$('customer.bankAccount.directDeposit').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.employment.howOftenPaid')){$('customer.employment.howOftenPaid').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.phone2.digits')){$('customer.phone2.digits').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.employment.payDate1')){$('customer.employment.payDate1').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.employment.jobTimeMonths')){$('customer.employment.jobTimeMonths').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.hasCC')){$('customer.hasCC').style.background = '#FFD7D7';err=1;} if(IsEmptyField('cash_timeAtHome')){$('cash_timeAtHome').style.background = '#FFD7D7';err=1;} if(IsEmptyField('customer.loan.requested')) { $('customer.loan.requested').style.background = '#FFD7D7'; err=1; } else { var req = parseInt($('customer.loan.requested').value); if(req < 80){ $('error_more_less').innerHTML = "Loan Requested must be greater than 80 Pounds"; $('customer.loan.requested').style.background = '#FFD7D7'; err=1; } if(req > 1000){ $('error_more_less').innerHTML = "Loan Requested must be less than 1,000 Pounds"; $('customer.loan.requested').style.background = '#FFD7D7'; err=1; } } if(IsEmptyField('customer.employment.netSalary') || !IsNumeric($('customer.employment.netSalary').value)) { $('customer.employment.netSalary').style.background = '#FFD7D7'; err=1; } else { var req = parseInt($('customer.employment.netSalary').value); if(req < 200){ $('err_div_tx').innerHTML = "Monthly Income must be greater than 200 Pounds"; $('customer.employment.netSalary').style.background = '#FFD7D7'; err=1; } } if(!checkMail($('customer.email').value)){$('customer.email').style.background = '#FFD7D7';err=1;} var zc = $('customer.zip').value; if(checkPostCode(zc)){ $('customer.zip').value = checkPostCode (zc) } else { $('customer.zip').style.background = '#FFD7D7'; err=1; } var firstname = $('customer.firstName').value; if(!validName(firstname)){ $('customer.firstName').style.background = '#FFD7D7'; err=1; } var lastname = $('customer.lastName').value; if(!validName(lastname)){ $('customer.lastName').style.background = '#FFD7D7'; err=1; } if($('customer.employment.employerName').value.length < 2){ $('customer.employment.employerName').style.background = '#FFD7D7'; err=1; } var phome = $('customer.phone1.digits').value; if(!validPhone(phome)){ $('customer.phone1.digits').style.background = '#FFD7D7';err=1;} var pwork = $('customer.phone2.digits').value; if(!validPhone(pwork)){ $('customer.phone2.digits').style.background = '#FFD7D7';err=1;} var pcell = $('customer.phone3.digits').value; if(!validCellPhone(pcell)){ $('customer.phone3.digits').style.background = '#FFD7D7';err=1;} if(pwork && phome && pwork == phome){ $('err_div_tx').innerHTML = "Home phone must be different than the work phone."; $('customer.phone1.digits').style.background = '#FFD7D7'; $('customer.phone2.digits').style.background = '#FFD7D7'; err=1; } var dt1 = $('customer.dob.date').value; if(!validateDate(dt1, 1900, 2000)){ $('customer.dob.date').style.background = '#FFD7D7'; err=1; } else if(getAge(dt1) < 18){ $('err_div_tx').innerHTML = "You must be 18 or over."; $('customer.dob.date').style.background = '#FFD7D7'; err=1; } var dt2 = $('customer.employment.payDate1').value; if(!validateDate(dt2, 2007, 2029)){ $('customer.employment.payDate1').style.background = '#FFD7D7'; err=1; } if($("allow_mails").checked == false && err==0) { alert('To submit, please check that you have read our privacy policy'); err = 1; } if(err!=1) { $('errdiv').style.display = 'none'; $('submitbutton').style.display = 'none'; $('processing').style.display = 'block'; var url = "/site/javascripts/v2/step2.php?" + allFormData(); http.abort(); http.open("GET", url, true); http.onreadystatechange = handleHttpResponse; http.send(null); } else { $('submitbutton').style.display = 'block'; $('processing').style.display = 'none'; $('errdiv').style.display = 'block'; } } // end func function handleHttpResponse() { if (http.readyState == 4) { if (http.responseText == 'err') { top.location="/thank-you/"; } else { top.location=http.responseText; } } } function getHTTPObject(){ var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E){ xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){ try{ xmlhttp = new XMLHttpRequest(); } catch (e){ xmlhttp = false; } } return xmlhttp; } var http = getHTTPObject(); // We create the HTTP Object function allFormData() { $('errdiv').style.display = 'none'; var dat = ""; dat = dat + "gender=" + escape($('customer.gender').value); dat = dat + "&firstname=" + escape($('customer.firstName').value); dat = dat + "&lastname=" + escape($('customer.lastName').value); dat = dat + "&address1=" + escape($('customer.streetNumber').value+' '+$('customer.streetName').value); dat = dat + "&streetnumber=" + escape($('customer.streetNumber').value); dat = dat + "&streetname=" + escape($('customer.streetName').value); dat = dat + "&state=" + escape($('customer.state').value); dat = dat + "&city=" + escape($('customer.city').value); dat = dat + "&zip=" + escape($('customer.zip').value); dat = dat + "&email=" + escape($('customer.email').value); dat = dat + "&phonenumber=" + escape($('customer.phone1.digits').value); dat = dat + "&phonecell=" + escape($('customer.phone3.digits').value); dat = dat + "&dob=" + escape($('customer.dob.date').value); dat = dat + "&employerName=" + escape($('customer.employment.employerName').value); dat = dat + "&IncomeSource=" + escape($('customer.employment.incomeSource').value); dat = dat + "&netSalary=" + escape($('customer.employment.netSalary').value); dat = dat + "&directDeposit=" + escape($('customer.bankAccount.directDeposit').value); dat = dat + "&howOftenPaid=" + escape($('customer.employment.howOftenPaid').value); dat = dat + "&phonework=" + escape($('customer.phone2.digits').value); dat = dat + "&payDate1=" + escape($('customer.employment.payDate1').value); dat = dat + "&jobTimeMonths=" + escape($('customer.employment.jobTimeMonths').value); dat = dat + "&creditCardType=" + escape($('customer.hasCC').value); dat = dat + "&amountRequested=" + escape($('customer.loan.requested').value); dat = dat + "&nin=" + escape($('customer.employment.nin').value); dat = dat + "&SortCode=" + escape($('customer.employment.sortcode').value); dat = dat + "&BankAccountNumber=" + escape($('customer.employment.bankaccount').value); dat = dat + "&payDate2=" + escape($('customer.employment.payDate2').value); dat = dat + "&allow_mails=" + escape($("allow_mails").value); dat = dat + "&SRLP=" + escape($("SRLP").value); dat = dat + "&cash_timeAtHome=" + escape($("cash_timeAtHome").value); // LID: optional (used on some partner sites) LID_elem = $('LID'); if(LID_elem){ dat = dat + "&LID=" + escape(LID_elem.value); } step_elem = $('suggest_step'); if(step_elem){ dat = dat + "&suggest_step=" + escape(step_elem.value); } return dat; } function isAlpha(str) { regex = /^\[a-zA-Z]+$/; return regex.test(str); } function isAlphaNum(str) { regex = /^\[0-9a-zA-Z]+$/; return regex.test(str); } function checkMail(mail) { var x = mail; var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (filter.test(x)) return true; else return false; } function validName(name) { name = name.trim(); regex = /^[a-zA-Z][a-zA-Z\s\'\.,\-]+$/ return regex.test(name); } function validPhone(phone) { if(!IsNumeric(phone)){ return false; } phone = phone.trim('0'); if(phone.length != 11 && phone.length != 10){ return false; } if(phone.charAt(0) != '0') { // || phone.charAt(1) == '7') { return false; } return true; } function validCellPhone(phone) { if(!IsNumeric(phone)){ return false; } phone = phone.trim('0'); if(phone.length != 11){ return false; } if(phone.substring(0, 2) != '07'){ return false; } return true; } function IsEmptyField(id) { value = $(id).value; return (value.trim() == ''); } function IsNumeric(sText) { var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function keyRestrict(e, validchars){ var key='', keychar=''; key = getKeyCode(e); if (key == null) return true; keychar = String.fromCharCode(key); keychar = keychar.toLowerCase(); validchars = validchars.toLowerCase(); if (validchars.indexOf(keychar) != -1) return true; if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 ) return true; return false; } function getKeyCode(e) { if (window.event) return window.event.keyCode; else if (e) return e.which; else return null; } function validateDate(fld, an1, an2){ var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/; if ((fld.match(RegExPattern)) && (fld!='')) { var mySplitResult = fld.split("/"); if((parseFloat(mySplitResult[2])>=an1) && (parseFloat(mySplitResult[2])<=an2)) { return true;} else{ return false;} } else { return false;} } function getAge(dobString) { dobParts = dobString.split('/'); dob = new Date(dobParts[2], dobParts[1] - 1, dobParts[0]); now = new Date(); return Math.floor((now.getTime() - dob.getTime()) / (365.25 * 24 * 60 * 60 * 1000)); } function checkPostCode (toCheck){ // Permitted letters depend upon their position in the postcode. var alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1 var alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2 var alpha3 = "[abcdefghjkstuw]"; // Character 3 var alpha4 = "[abehmnprvwxy]"; // Character 4 var alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5 // Array holds the regular expressions for the valid postcodes var pcexp = new Array (); // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Expression for postcodes: ANA NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Expression for postcodes: AANA NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Exception for the special postcode GIR 0AA pcexp.push (/^(GIR)(\s*)(0AA)$/i); // Standard BFPO numbers pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i); // c/o BFPO numbers pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i); // Overseas Territories pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i); // Load up the string to check var postCode = toCheck; // Assume we're not going to find a valid postcode var valid = false; // Check the string against the types of post codes for ( var i=0; i