").attr({id:i,role:"tooltip"}).addClass("ui-tooltip ui-widget ui-corner-all ui-widget-content "+(this.options.tooltipClass||""));return t("
").addClass("ui-tooltip-content").appendTo(n),n.appendTo(this.document[0].body),this.tooltips[i]=e,n},_find:function(e){var i=e.data("ui-tooltip-id");return i?t("#"+i):t()},_removeTooltip:function(t){t.remove(),delete this.tooltips[t.attr("id")]},_destroy:function(){var e=this;t.each(this.tooltips,function(i,s){var n=t.Event("blur");n.target=n.currentTarget=s[0],e.close(n,!0),t("#"+i).remove(),s.data("ui-tooltip-title")&&(s.attr("title",s.data("ui-tooltip-title")),s.removeData("ui-tooltip-title"))})}})}(jQuery);
$('body').addClass('js');
// http://www.braemoor.co.uk/software/postcodes.shtml
function checkPostCode (toCheck) {
// Permitted letters depend upon their position in the postcode.
var alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1
var alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2
var alpha3 = "[abcdefghjkpmnrstuvwxy]"; // Character 3
var alpha4 = "[abehmnprvwxy]"; // Character 4
var alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5
var BFPOa5 = "[abdefghjlnpqrst]"; // BFPO alpha5
var BFPOa6 = "[abdefghjlnpqrstuwzyz]"; // BFPO alpha6
// Array holds the regular expressions for the valid postcodes
var pcexp = new Array ();
// BFPO postcodes
pcexp.push (new RegExp ("^(bf1)(\\s*)([0-6]{1}" + BFPOa5 + "{1}" + BFPOa6 + "{1})$","i"));
// 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 + "{1}" + "?[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);
// Anguilla
pcexp.push (/^(ai-2640)$/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
' + ParsleyField.options.messages[ constraint ][ constraints[constraint].requirements ] + '';
}
else {
var $error = ' ' + ParsleyField.options.messages[ constraint ] + '';
}
$container.html($error);
$(elem).parents('.input').addClass('has-error');
break;
}
}
},
onFieldSuccess: function (elem, constraints, ParsleyField) {
var $container = $(elem).parents('.field').find('.message');
var $msg = '';
$container.html($msg);
$(elem).parents('.input').addClass('has-success');
}
}
});
*/
//set world pay post card triggers
if ($("#payment-redirect-form").length > 0) {
var errored = false
$('#cc_cards img').click(function(){
$('input[name="paymentType"]').val($(this).attr('data-card'));
$.ajax(
{
'url':Routing.generate('send_to_payment'),
'type':'post',
'data':$("#payment-redirect-form" ).serialize()
}
)
.success(function(a, b) {
var data = $.parseJSON(a.trim());
if (data.error !== undefined) {
alert(data.error);
} else if (data.token !== undefined) {
$('input[name="MC_api_return_url"]').val($('input[name="MC_api_return_url"]').val()+'?t='+data.token);
$("#payment-redirect-form").submit();
}
})
.error(function() {alert("There was a system problem, please try again.")});
});
}
// Scroll down to the first error or just to the top of the active step
if ($(".has-error:first").length > 0) {
$('html, body').animate({
scrollTop: $(".has-error:first").offset().top - 10
}, 500);
} else if ($('.form-step.active:first').not('.form-step-1').length > 0) {
$('html, body').animate({
scrollTop: $(".form-step.active").offset().top + 1
}, 500);
}
/* SLIDERS */
if ($(".quick-apply").length) {
var defaultSelectedSliderAmount = $("#default_selected_slider_amount").html();
var defaultSelectedSliderTerm = $("#default_selected_slider_term").html();
// Load Amount Slider
var selectAmount = $("#apply-borrow");
var sliderAmount = $("#apply-borrow-slider").slider({
range: "min",
min: 0,
max: valuesAmount.length - 1,
value: 0,
tooltip: "hide"
});
// Load Period Slider
var valuesPeriod = termMonths['amount' + minAmount]['months'];
var selectPeriod = $("#apply-period");
var sliderPeriod = $("#apply-period-slider").slider({
range: "min",
min: 0,
max: termMonths['amount' + minAmount]['months'].length - 1,
value: 0,
tooltip: "hide"
});
sliderAmount.on("slide", function (event) {
var value = valuesAmount[event.value];
selectAmount.val(value);
$("#apply-borrow-placeholder").html('£' + value);
sliderPeriod.data('slider').max = termMonths['amount' + value]['months'].length - 1;
valuesPeriod = termMonths['amount' + value]['months'];
if(undefined === event.forced || event.forced == false) {
sliderPeriod.slider('setValue', 0);
$('#apply-period-slider').val(0);
sliderPeriod.trigger({
type: 'slide',
value: 0
});
updateLoanCalculation();
}
});
sliderPeriod.on("slide", function (event) {
var value = valuesPeriod[event.value];
selectPeriod.val(value);
$("#apply-period-placeholder").html(value);
setTimeout(function () {
updateLoanCalculation();
}, 1000);
});
// Trigger the amount slider to initialise settings.
sliderAmount.trigger({
type: 'slide',
value: 0
});
setTimeout(function(){
targetAmount = $("option[value=" + defaultSelectedSliderAmount + "]", selectAmount);
sliderAmount.slider('setValue', targetAmount.index());
sliderAmount.trigger({type:'slide', value:targetAmount.index(), forced: true });
$('#apply-borrow-slider').val(targetAmount.index());
targetTerm = $("option[value=" + defaultSelectedSliderTerm + "]", selectPeriod);
sliderPeriod.trigger({type:'slide', value:targetTerm.index()});
sliderPeriod.slider('setValue', targetTerm.index());
$('#apply-period-slider').val(targetTerm.index());
setTimeout(function () {
updateLoanCalculation();
}, 300);
}, 1000);
}
if ($('#LoanApplicationStepOne_loan_application_loan_amount').length) {
var valuesPeriod = termMonths['amount' + minAmount]['months'];
// loan amount dropdowns
$("#LoanApplicationStepOne_loan_application_loan_amount").change(function () {
var loan_value = $("#LoanApplicationStepOne_loan_application_loan_amount option:selected").val();
var term_value = $("#LoanApplicationStepOne_loan_application_loan_term option:selected").val();
$("#LoanApplicationStepOne_loan_application_loan_term option").each(function () {
$(this).remove();
});
var options_html = '';
$.each(termMonths['amount' + loan_value]['months'], function () {
var value = this.toString();
options_html += '';
});
valuesPeriod = termMonths['amount' + loan_value]['months'];
$("#LoanApplicationStepOne_loan_application_loan_term").append(options_html);
setTimeout(function () {
updateLoanCalculation();
}, 500);
});
$("#LoanApplicationStepOne_loan_application_loan_term").change(function () {
setTimeout(function () {
updateLoanCalculation();
}, 500);
});
$("#LoanApplicationStepOne_loan_application_loan_amount").change();
}
function updateLoanCalculation() {
if ($('#apply-period-slider').length && $('#apply-borrow-slider').length) {
var period = $('#apply-period-slider').val();
var amount = $('#apply-borrow-slider').val();
if (amount == '') {
amount = 0;
}
if (period == '') {
period = 0;
}
period = valuesPeriod[period];
amount = valuesAmount[amount];
}
else {
var period = $("#LoanApplicationStepOne_loan_application_loan_term option:selected").val();
var amount = $("#LoanApplicationStepOne_loan_application_loan_amount option:selected").val();
}
var terms = termMonths['amount' + amount]['terms'][period];
if (terms.RepresentativeApr == undefined) {
return;
}
var exampleBorrow = $('#example-borrow'),
examplePeriod = $('#example-period'),
exampleRepayment = $('#example-repayment'),
exampleInterest = $('#example-interest'),
exampleTotal = $('#example-total'),
exampleApr = $('#example-apr'),
exampleRate = $('#example-rate'),
exampleFees = $('#example-fees'),
exampleInterestOnly = $('#example-interest-only');
exampleBorrow.html('£' + amount);
examplePeriod.html(period + ' months');
exampleApr.html(terms.RepresentativeApr);
monthlyrepayment = terms['MonthlyRepayment'];
exampleRepayment.html('£' + monthlyrepayment);
totalfees = terms['InterestFees'];
exampleInterest.html('£' + totalfees);
loantotal = terms['TotalRepayment'];
exampleTotal.html('£' + loantotal);
Fees = terms['DocumentFee'];
exampleFees.html('£' + Fees);
// Subtract fees and amount from total to get interest (round to 2 dp)
InterestOnly = Math.round((loantotal - Fees - amount) * 100) / 100;
exampleInterestOnly.html('£' + InterestOnly);
exampleRate.html(terms['InterestRate']);
}
// Visually hide some form elements
$('.js-hide').hide();
// Inject some classes on to yandm-fields widget
$('.dob-fields select').addClass('form-control input-lg');
// Housing status - mortgage/rent toggle
$('#LoanApplicationStepTwo_address_1_extra_housing_status').change(function() {
$('#LoanApplicationStepTwo_address_1_extra_rent_cost').parents('.field').find('.message').html(' ');
$('#LoanApplicationStepTwo_address_1_extra_rent_cost, #LoanApplicationStepTwo_address_1_extra_mortgage_cost').val('');
if ($(this).val() == '') {
$('#LoanApplicationStepTwo_address_1_extra_rent_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepTwo_address_1_extra_mortgage_cost:visible').parents('.field').slideUp();
}
else if ($(this).val() == 1) {
$('#LoanApplicationStepTwo_address_1_extra_rent_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepTwo_address_1_extra_mortgage_cost').parents('.field').slideDown();
}
else {
$('#LoanApplicationStepTwo_address_1_extra_mortgage_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepTwo_address_1_extra_rent_cost').parents('.field').slideDown();
}
if ($(this).val() == 7) {
$('#LoanApplicationStepTwo_address_1_extra_rent_cost').parents('.field').find('.message').html('For shared ownership only enter rental amount');
}
});
// $('#LoanApplicationStepTwo_address_1_extra_housing_status').change();
/////////////////////////////////////////////////////////
// SUPER USER PANEL STUFF ADDED BY VINI SEP 2014
/////////////////////////////////////////////////////////
function initChangeLoanAmount() {
// Let's return if we're not the correct admin user.
$("#change_loan_amount_button").on('click', function() {
// Hide this button
$(this).hide();
// Hide view table
$("#loan_summary_display").hide();
// Show edit form
$("#change_loan_amount_form").show();
});
$("#change_loan_amount_edit_control_cancel").on('click', function() {
resetLoanAmountForm();
// Show change button.
$("#change_loan_amount_button").show();
// Show view table
$("#loan_summary_display").show();
// Hide edit form
$("#change_loan_amount_form").hide();
});
// Loan amount setter
$("#loan_product_select").on('change', function() {
// Disable submit
$("#change_loan_amount_edit_control_submit").prop("disabled", true);
var product_code = $(this).val();
var options_html = '';
if (typeof loan_rates_master_data[product_code] != 'undefined') {
var all_amounts = loan_rates_master_data[product_code].termMonths;
// Reset term select
$("#loan_term_select").html(options_html).prop("disabled", true);
$.each(all_amounts, function(key,value) {
options_html += '';
});
$("#loan_range").html(' £' + loan_rates_master_data[product_code].minAmount +
' to £' + loan_rates_master_data[product_code].maxAmount);
$("#loan_range_row").show();
$("#loan_details_row").hide();
// Append options and enable
$("#loan_amount_select").html(options_html).prop("disabled", false);
} else {
// Append options and disable
$("#loan_amount_select").html(options_html).prop("disabled", true);
$("#loan_term_select").html(options_html).prop("disabled", true);
$("#loan_range").html('');
$("#loan_range_row").hide();
$("#loan_details_row").hide();
}
});
// Loan term setter
$("#loan_amount_select").on('change', function() {
// Disable submit
$("#change_loan_amount_edit_control_submit").prop("disabled", true);
var product_code = $("#loan_product_select").val();
var loan_amount = $(this).val();
var options_html = '';
if (typeof loan_rates_master_data[product_code] != 'undefined' &&
typeof loan_rates_master_data[product_code].termMonths[loan_amount] != 'undefined'
) {
var all_terms = loan_rates_master_data[product_code].termMonths[loan_amount];
$.each(all_terms, function(key,value) {
options_html += '';
});
// Append options and enable
$("#loan_term_select").html(options_html).prop("disabled", false);
$("#loan_details_row").hide();
} else {
// Append options and disable
$("#loan_term_select").html(options_html).prop("disabled", true);
$("#loan_details_row").hide();
}
});
// Loan details setter
$("#loan_term_select").on('change', function() {
// Disable submit
$("#change_loan_amount_edit_control_submit").prop("disabled", true);
var product_code = $("#loan_product_select").val();
var loan_amount = $("#loan_amount_select").val();
var loan_term = $(this).val();
if (typeof loan_rates_master_data[product_code] != 'undefined' &&
typeof loan_rates_master_data[product_code].termMonths[loan_amount] != 'undefined' &&
typeof loan_rates_master_data[product_code].termMonths[loan_amount][loan_term] != 'undefined'
) {
var loan_details = loan_rates_master_data[product_code].termMonths[loan_amount][loan_term];
$("#loan_details_row").show();
$("#interest_rate").html(' ' + loan_details.InterestRate);
$("#monthly_repayment").html(' ' + loan_details.MonthlyRepayment);
$("#rep_apr").html(' ' + loan_details.RepresentativeApr);
$("#total_repayment").html(' ' + loan_details.TotalRepayment);
$("#interest_fees").html(' ' + loan_details.InterestFees);
$("#document_fee").html(' ' + loan_details.DocumentFee);
// Enable submit
$("#change_loan_amount_edit_control_submit").prop("disabled", false);
} else {
$("#interest_rate").html('');
$("#monthly_repayment").html('');
$("#rep_apr").html('');
$("#total_repayment").html('');
$("#interest_fees").html('');
$("#document_fee").html('');
$("#loan_details_row").hide();
}
});
}
// Add the onclick handlers to the admin panel edit buttons
function initEditButtons() {
$(".edit-icon").each(function(index) {
var elemID = $(this).attr('id');
$(this).on('click', function() {
// Hide edit button
$('#' + elemID).hide();
// Show edit control buttons
$('#' + elemID + "_edit_control").show();
// Hide view table and show edit tables
$('#' + elemID + '_view_table').hide();
$('#' + elemID + '_address_view_table').hide();
$('#' + elemID + '_employment_view_table').hide();
$('#' + elemID + '_edit_table').show();
$('#' + elemID + '_address_edit_table').show();
$('#' + elemID + '_employment_edit_table').show();
// Password helptext
$('#' + elemID + '_password_helptext').show();
// Add event listener for edit cancel button
$('#' + elemID + "_edit_control_cancel").one('click', function() {
// Hide edit control buttons
$('#' + elemID + "_edit_control").hide();
// Show edit button
$('#' + elemID).show();
// Hide edit table and show view table
$('#' + elemID + '_edit_table').hide();
$('#' + elemID + '_address_edit_table').hide();
$('#' + elemID + '_employment_edit_table').hide();
$('#' + elemID + '_view_table').show();
$('#' + elemID + '_address_view_table').show();
$('#' + elemID + '_employment_view_table').show();
// Password helptext
$('#' + elemID + '_password_helptext').hide();
// Re-check housing fields.
checkHousingFields();
});
// Add event listener for edit submit button
$('#' + elemID + "_edit_control_submit").one('click', function() {
// Hide edit control buttons
$('#' + elemID + "_edit_control").hide();
// Show edit button
$('#' + elemID).show();
// Hide edit table and show view table
$('#' + elemID + '_edit_table').hide();
$('#' + elemID + '_view_table').show();
});
// Re-check housing fields.
checkHousingFields();
});
});
}
// Monitor address duration and enable or disable addition of addresses accordingly..
function checkResidencyDuration() {
var applicant_total_months_resided = 0;
var guarantor_total_months_resided = 0;
// Applicant
$("input[id*='applicant_lived_months']").each(function(index) {
var current_value = parseInt($(this).val());
applicant_total_months_resided += (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkResidencyDuration();
});
});
$("input[id*='applicant_lived_years']").each(function(index) {
var current_value = parseInt($(this).val());
applicant_total_months_resided += 12 * (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkResidencyDuration();
});
});
// Enable/disable add address button
if (applicant_total_months_resided < 36) {
$("#applicant_add_address_button").prop("disabled", false).show();
} else {
$("#applicant_add_address_button").prop("disabled", true).hide();
}
// Guarantor
$("input[id*='guarantor_lived_months']").each(function(index) {
var current_value = parseInt($(this).val());
guarantor_total_months_resided += (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkResidencyDuration();
});
});
$("input[id*='guarantor_lived_years']").each(function(index) {
var current_value = parseInt($(this).val());
guarantor_total_months_resided += 12 * (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkResidencyDuration();
});
});
// Enable/disable add address button
if (guarantor_total_months_resided < 36) {
$("#guarantor_add_address_button").prop("disabled", false).show();
} else {
$("#guarantor_add_address_button").prop("disabled", true).hide();
}
}
// Monitor address duration and enable or disable addition of addresses accordingly..
function checkEmploymentDuration() {
var applicant_total_months_employed = 0;
var guarantor_total_months_employed = 0;
// Applicant
$("input[id*='applicant_employed_months']").each(function(index) {
var current_value = parseInt($(this).val());
applicant_total_months_employed += (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkEmploymentDuration();
});
});
$("input[id*='applicant_employed_years']").each(function(index) {
var current_value = parseInt($(this).val());
applicant_total_months_employed += 12 * (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkEmploymentDuration();
});
});
// Enable/disable add address button
if (applicant_total_months_employed < 12) {
$("#applicant_add_employment_button").prop("disabled", false).show();
} else {
$("#applicant_add_employment_button").prop("disabled", true).hide();
}
// Guarantor
$("input[id*='guarantor_employed_months']").each(function(index) {
var current_value = parseInt($(this).val());
guarantor_total_months_employed += (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkEmploymentDuration();
});
});
$("input[id*='guarantor_employed_years']").each(function(index) {
var current_value = parseInt($(this).val());
guarantor_total_months_employed += 12 * (isNaN(current_value) ? 0 : current_value);
$(this).one('change', function() {
checkEmploymentDuration();
});
});
// Enable/disable add address button
if (guarantor_total_months_employed < 12) {
$("#guarantor_add_employment_button").prop("disabled", false).show();
} else {
$("#guarantor_add_employment_button").prop("disabled", true).hide();
}
}
function checkHousingFields() {
// Count number of address containers so we know if there is an address.
var applicant_address_count = $(".applicant_address_container:visible").length;
var guarantor_address_count = $(".guarantor_address_container:visible").length;
if (applicant_address_count > 0) {
$("#applicant_step_2_housing_status").prop("disabled", false);
$("#applicant_step_2_housing_cost").prop("disabled", false);
$("#applicant_address_required").hide();
} else {
$("#applicant_step_2_housing_status").prop("disabled", true);
$("#applicant_step_2_housing_cost").prop("disabled", true);
// Only show the info about address fields if the form is visible (edit mode).
if ($("#applicant_step_2_edit_table:visible").length > 0) {
$("#applicant_address_required").show();
} else {
$("#applicant_address_required").hide();
}
}
if (guarantor_address_count > 0) {
$("#guarantor_step_2_housing_status").prop("disabled", false);
$("#guarantor_step_2_housing_cost").prop("disabled", false);
$("#guarantor_address_required").hide();
} else {
$("#guarantor_step_2_housing_status").prop("disabled", true);
$("#guarantor_step_2_housing_cost").prop("disabled", true);
// Only show the info about address fields if the form is visible (edit mode).
if ($("#guarantor_step_2_edit_table:visible").length > 0) {
$("#guarantor_address_required").show();
} else {
$("#guarantor_address_required").hide();
}
}
}
// Add event handlers for new address buttons.
function initNewAddressButtons() {
$(".add_address_button").each(function(index) {
var elemID = $(this).attr('id');
var person_type = elemID.substring(0, 9);
$(this).on('click', function() {
// Count number of address containers so we know what index to start at.
var form_index = $("." + person_type + "_address_container:visible").length;
// Add new address form.
var formHTML =
'' +
'
Address
' +
'
' +
'
' +
'
';
$("#" + person_type + "_add_address_form_area").append(formHTML);
// Ensure the new fields have event handlers applied.
checkResidencyDuration();
checkEmploymentDuration();
checkHousingFields();
initRemoveFormButtons();
});
});
}
// Add event handlers for new employment buttons.
function initNewEmploymentButtons() {
$(".add_employment_button").each(function(index) {
var elemID = $(this).attr('id');
var person_type = elemID.substring(0, 9);
$(this).on('click', function() {
// Count number of employment containers so we know what index to start at.
var form_index = $("." + person_type + "_employment_container:visible").length;
// Add new address form.
var formHTML =
'' +
'
Employment
' +
'
' +
'
' +
'
';
$("#" + person_type + "_add_employment_form_area").append(formHTML);
// Ensure the new fields have event handlers applied.
checkResidencyDuration();
checkEmploymentDuration();
checkHousingFields();
initRemoveFormButtons();
});
});
}
// Add event handlers for remove address buttons.
function initRemoveFormButtons() {
$('button[name=remove_parent]').each(function(index) {
// Remove any existing click events
$(this).unbind("click");
// Add click event
$(this).one('click', function() {
$(this).parent().remove();
checkResidencyDuration();
checkEmploymentDuration();
checkHousingFields();
});
});
}
// Resets the loan amount form.
function resetLoanAmountForm() {
var options_html = '';
// Disable submit
$("#change_loan_amount_edit_control_submit").prop("disabled", true);
// Selectors
$("#loan_amount_select").html(options_html).prop("disabled", true);
$("#loan_term_select").html(options_html).prop("disabled", true);
// Loan range
$("#loan_range").html('');
$("#loan_range_row").hide();
// Loan details
$("#interest_rate").html('');
$("#monthly_repayment").html('');
$("#rep_apr").html('');
$("#total_repayment").html('');
$("#interest_fees").html('');
$("#document_fee").html('');
$("#loan_details_row").hide();
}
/////////////////////////////////////////////////////////
// END OF SUPER USER PANEL STUFF ADDED BY VINI SEP 2014
/////////////////////////////////////////////////////////
// Calculate total number of months from a pair of year and month fields
// Returns false if the either of the fields are unset
function calculateMonths(years, months) {
if ($.isNumeric(years.val()) && $.isNumeric(months.val())) {
var total_months = (years.val() * 12) + (months.val() * 1);
return total_months;
}
return false;
}
var gettingPostcode = false;
// Lookup a postcode
$('.postcode-lookup-wrapper .postcode-lookup-submit').on('click', function(event) {
event.preventDefault();
if (gettingPostcode) {
return;
}
gettingPostcode = true;
var $wrapper = $(this).parents('.postcode-lookup-wrapper');
var $pf = $wrapper.find('.postcode-lookup');
var $pv = $pf.val();
var $pve = encodeURIComponent($pv);
var $pm = $(this).parent().siblings('.message');
var $pmmob = $(this).parent().next().next();
var $pmmobspan = $pmmob.children('span');
var $ps = $wrapper.find('.postcode-lookup-select');
$pmmob[0].style.setProperty("display","none","important"); // hide the mobile error first
// Reset incase of previous activations
$pm.html(' ');
$ps.children().remove();
// Move postcode and lookup button back to top when using lookup (otherwise it is hidden)
$wrapper.find('.address-lookup-row').insertBefore($wrapper.find('.postcode-lookup-results'));
$wrapper.find('.address-manual:visible').slideUp();
$wrapper.find('.address-manual-link:hidden').slideDown();
$wrapper.find('.address-manual-link').css('display','block');
// Validate and process postcode
if (checkPostCode($pv)) {
$.ajax({
url: Routing.generate('find_address_by_postcode'),
type: "GET",
dataType: "json",
data: "postcode=" + $pve,
beforeSend: function() {
$pm.html('Please wait...');
}
}).done(function(msg) {
$pm.html(' ');
if (msg.status == 'failed') {
$pm.html('We couldn\'t locate that postcode. Please enter manually.');
$pmmobspan.html(" We couldn\'t locate that postcode. Please enter manually.");
$pmmob.show();
} else {
$ps.append('');
$.each(msg, function() {
$ps.append(
$("").text(this.Description).val(this.Id)
);
});
$wrapper.find('.postcode-lookup-results').slideDown();
}
gettingPostcode = false;
}).error(function() {
$pm.html('Sorry, there was a problem');
gettingPostcode = false;
});
}
else {
$pm.html('Please enter a valid postcode');
$pmmobspan.html(" Please enter a valid postcode");
$pmmob.show();
gettingPostcode = false; // reset this to false, otherwise it will not be able to check again.
}
});
// Lookup an address with it's index
$('.postcode-lookup-wrapper .postcode-lookup-select').change(function() {
var $wrapper = $(this).parents('.postcode-lookup-wrapper');
var $as = $(this);
var $index = encodeURIComponent($as.val());
var $pm = $wrapper.find('.message:first');
// Reset any previous manual address
$wrapper.find('.address-manual input[type=text]').val();
if ($as.val() !== '') {
$.ajax({
url: Routing.generate('find_address_by_index'),
type: "GET",
dataType: "json",
data: "address_index=" + $index,
beforeSend: function() {
$pm.html('Please wait...');
}
}).done(function(msg) {
$pm.html(' ');
$wrapper.find('.address-manual-link').slideUp();
$wrapper.find("input[name$='[select_address]']").val($as.val());
$wrapper.find("input[name$='[address_flat_number]']").val(msg.flat_number).trigger('blur');
$wrapper.find("input[name$='[address_building_number]']").val(msg.building_number).trigger('blur');
$wrapper.find("input[name$='[address_building_name]']").val(msg.building_name).trigger('blur');
$wrapper.find("input[name$='[address_thouroughfare]']").val(msg.thouroughfare).trigger('blur');
$wrapper.find("input[name$='[address_post_town]']").val(msg.town).trigger('blur');
$wrapper.find("input[name$='[address_county]']").val(msg.county).trigger('blur');
$wrapper.find("input[name$='[address_postcode]']").trigger('blur');
//$wrapper.find("input[name$='[address_locality]']").val(msg.a);
//$wrapper.find("input[name$='[address_dependent_locality]']").val(msg.address_line_2);
$wrapper.find('.postcode-lookup-results:visible').slideUp();
$wrapper.find('.address-manual:hidden').slideDown();
$wrapper.find('.postcode-lookup-results:visible').slideUp();
$wrapper.find('.address-manual:hidden').slideDown();
$wrapper.find('.address-manual-link').hide();
// Move postcode and lookup button to end of address when manually entering
$wrapper.find('.address-lookup-row').insertAfter($wrapper.find('.address-manual .row.field:last'));
}).error(function() {
$pm.html('Sorry, there was a problem');
});
}
});
// Toggle manual address
$('.postcode-lookup-wrapper .address-manual-link').click(function(event) {
event.preventDefault();
var $wrapper = $(this).parents('.postcode-lookup-wrapper');
$wrapper.find('.postcode-lookup-results:visible').slideUp();
$wrapper.find('.address-manual:hidden').slideDown();
$(this).hide();
// Move postcode and lookup button to end of address when manually entering
$wrapper.find('.address-lookup-row').insertAfter($wrapper.find('.address-manual .row.field:last'));
});
// Clear address index if the manual address is changed
$('.postcode-lookup-wrapper .address-manual input[type=text]').change(function() {
var $wrapper = $(this).parents('.postcode-lookup-wrapper');
$wrapper.find("input[name$='[select_address]']").val('');
});
function checkAddressHistoryValues() {
$a1y = $('#LoanApplicationStepTwo_address_1_address_lived_years');
$a1m = $('#LoanApplicationStepTwo_address_1_address_lived_months');
$a2y = $('#LoanApplicationStepTwo_address_2_address_lived_years');
$a2m = $('#LoanApplicationStepTwo_address_2_address_lived_months');
$a3y = $('#LoanApplicationStepTwo_address_3_address_lived_years');
$a3m = $('#LoanApplicationStepTwo_address_3_address_lived_months');
$a1total = calculateMonths($a1y, $a1m);
$a2total = calculateMonths($a2y, $a2m);
if ($a1total !== false && $a1total < 36) {
$('#address-2').slideDown();
if ($a2total !== false && ($a1total + $a2total) < 36) {
$('#address-3').slideDown();
}
else {
$('#address-3:visible').slideUp();
}
}
else {
$('#address-2:visible').slideUp();
$('#address-3:visible').slideUp();
}
}
// Handle the hiding and showing of employer details
function checkAddressHistory() {
$('.postcode-lookup-wrapper .yandm-fields select').change(function() {
checkAddressHistoryValues();
});
}
if ($('.form-step-2.active').length == 1) {
checkAddressHistory();
checkAddressHistoryValues();
}
//function checkEmploymentHistoryValues () {
// $e1y = $('#LoanApplicationStepThree_employment_1_employment_years');
// $e1m = $('#LoanApplicationStepThree_employment_1_employment_months');
// $e2y = $('#LoanApplicationStepThree_employment_2_employment_years');
// $e2m = $('#LoanApplicationStepThree_employment_2_employment_months');
// $e3y = $('#LoanApplicationStepThree_employment_3_employment_years');
// $e3m = $('#LoanApplicationStepThree_employment_3_employment_months');
//
// $e1total = calculateMonths($e1y, $e1m);
// $e2total = calculateMonths($e2y, $e2m);
//
// if ($e1total !== false && $e1total < 12) {
// $('#employer-2').slideDown();
// if ($e2total !== false && ($e1total + $e2total) < 12) {
// $('#employer-3').slideDown();
// }
// else {
// $('#employer-3:visible').slideUp();
// }
// }
// else {
// $('#employer-2:visible').slideUp();
// $('#employer-3:visible').slideUp();
// }
//}
// Handle the hiding and showing of employer details
//function checkEmploymentHistory() {
// $('.form-step-3 .yandm-fields select').change(function() {
// checkEmploymentHistoryValues();
// });
//}
//if ($('.form-step-3.active').length == 1) {
// checkEmploymentHistory();
// checkEmploymentHistoryValues();
//}
// Password Strength
$('.password-strength input[type=password]').keyup(function(e) {
var $output = $('.password-strength .message');
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$output.html('Password too short');
} else if (strongRegex.test($(this).val())) {
$output.html('Strong password');
} else if (mediumRegex.test($(this).val())) {
$output.html('Medium strength password');
} else {
$output.html('Weak password');
}
return true;
});
// Commented out by Vini Sep 2014 - Super User Panel Upgrade
// // Collapsing admin section panels
// var panels = $('.admin-section .panel-heading.collapser');
// panels.each(
// function (a, el) {
// var classname;
// el = $(el);
// if ($('span.label', el).length > 0) {
// return;
// }
// el.addClass('clearfix');
// el.append('');
// $('a', el).click(toggleCollapser);
// if (el.hasClass('collapser-closed')) {
// $('a', el).click();
// }
// }
// );
// $('.toggleAllCollapsers').click(function(){toggleAllCollapsers()});
if ($('#startBrokerTests')) {
$('#startBrokerTests').click(function(e){
$('#startBrokerTests').hide();
e.preventDefault();
$('#brokerTestResults').html("");
var testData = $.parseJSON($('#testDataJson').html());
var index;
for (index = 0; index < testData.length; ++index) {
runBrokerTest(index, testData)
}
$('#startBrokerTests').show();
});
}
function runBrokerTest (index, testData) {
var test = testData[index];
$.ajax({
url: test.url,
cache: false,
success:function(data, status) {
processBrokerTest(test, data, status);
},
failure:function(data, status) {
processBrokerTest(test, data, status);
}
});
}
function processBrokerTest (test, data, status) {
var originalData = data;
data = data.toLowerCase();
var strippedName = test.testname.replace(/[ ,.\-\/\\"\'\(\)]/g,'');
var jsonStart = data.indexOf('{"');
var jsonResponse = data.slice(jsonStart);
var jsonData = $.parseJSON(jsonResponse);
var failed = false;
var fail_reason = '';
var findStatus = test.expected.status.toLowerCase();
var n;
$('#brokerTestResults').append(
''+
''+test.testname+'
');
var target = $('#'+strippedName);
if(jsonData.status !== test.expected.status) {
// fail
failed = true;
fail_reason += 'Given status ['+jsonData.status+'] '+
'did not match expected ['+test.expected.status+'] ';
}
for (n = 0; n < test.expected.strings.length; n++) {
checkString = test.expected.strings[n];
if (jsonData.message.search(checkString.toLowerCase()) == -1) {
// fail
failed = true;
fail_reason += 'String not found "'+checkString+'" ';
}
}
if (failed) {
target.append('Failed: '+fail_reason+'');
} else {
target.append('Passed!');
}
target.append('Details:'+originalData+'
');
target.click(function(){$('#'+strippedName+'_details').toggle()});
}
//Check apr and set
if ($('.set_apr').length > 0)
{
$('.rep_borrow').html($('.set_apr').attr('data-rep_borrow'));
$('.rep_term').html($('.set_apr').attr('data-rep_term'));
$('.rep_repay').html($('.set_apr').attr('data-rep_repay'));
$('.rep_total_repay').html($('.set_apr').attr('data-rep_total_repay'));
$('.rep_interest').html($('.set_apr').attr('data-rep_interest'));
$('.rep_apr').html($('.set_apr').attr('data-rep_apr'));
}
// $('#confirm-terms').on( 'click', function() {
// $('#LoanApplicationStepSix_applicant_final_terms_conditions_accepted').trigger( 'click' );
// });
});
try {
onLoad();
} catch (e) {
// Function doesn't exist, that's fine
// Just a bypass for jquery not being loaded yet
}
$('#remove_duplicate_worldpay_app').on('click', function() {
var answer = confirm("Are you sure?");
return answer;
});
$('#remove_duplicate_worldpay_gt').on('click', function() {
var answer = confirm("Are you sure?");
return answer;
});
// Provided by datePicker
$('.datePicker').each(function(){
$.datepicker.setDefaults( $.datepicker.regional['']);
var id_input=this.id.split('_datepicker')[0];
var sfInput = $('#'+id_input)[0];
if(! (sfInput)){
console.error('An error has occurred while creating the datepicker');
}
$(this).datepicker({
'yearRange':$(this).data('yearrange'),
'changeMonth':$(this).data('changemonth'),
'changeYear':$(this).data('changeyear'),
'altField' : '#'+id_input,
'altFormat' : 'yy-mm-dd',
'minDate' : null,
'maxDate': null
});
$(this).keyup(function(e) {
if(e.keyCode == 8 || e.keyCode == 46) {
$.datepicker._clearDate(this);
$('#'+id_input)[0].value = '';
}
});
var dateSf = $.datepicker.parseDate('yy-mm-dd',sfInput.value);
$(this).datepicker('setDate',dateSf);
$(this).show();
$(sfInput).hide();
})
//url param
function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
//replace line breaks with BR
function nl2br (str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '
' : '
';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
function addPageLoader(){
$('body').addClass("loading_now");
setTimeout(function(){
removeLoader();
}, 30000);
}
function removePageLoader(){
$('body').removeClass("loading_now");
}
function addReferrerCookie() {
var cDomain = 'www.georgebanco.com'; // cDomain becomes hostname www.vitalonehealth.com
if (cDomain.indexOf(".") < cDomain.lastIndexOf(".")) { //Checks the number position of the domainname whcih is www. (4) vs the number position of .com which is 4. if it is less then…
var domainOffset = cDomain.indexOf(".") + 1 //add 1 to the index number total, so if its 3 then it puts it to 4
cDomain = cDomain.substr(domainOffset); // domain now extracts 4 letters out.
}
var expDays = 90;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
var refdate = new Date();
var expires = ";expires="+ exp.toUTCString() + ";path=/";
if (document.referrer.indexOf(cDomain) == -1 && document.referrer != "" && document.cookie.indexOf("referrer_url=") == -1) {
document.cookie = "referrer_url=" + escape(document.referrer) + expires;
document.cookie = "referrer_url_date=" + refdate.toUTCString() + expires;
document.cookie = "entry_url=" + escape(document.URL) + expires;
if(navigator.userAgent != ""){
document.cookie = "user_agent=" + escape(navigator.userAgent) + expires;
}
}
}
addReferrerCookie();
// Prevent duplicate form submissions
$('form.prevent-dupe-submit').submit(function(e) {
var form = $(this);
if (form.data('has-been-submitted') === true) {
e.preventDefault();
} else {
form.data('has-been-submitted', true);
}
});
function startAjaxRequest(btn)
{
if (btn.data('ajax_wait') === '1') {
return false;
} else {
btn.data('ajax_wait', '1');
return true;
}
}
function endAjaxRequest(btn)
{
btn.data('ajax_wait', '0');
}
/*!
* Bootstrap v3.1.1 (http://getbootstrap.com)
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
if("undefined"==typeof jQuery)throw new Error("Bootstrap's JavaScript requires jQuery");+function(a){"use strict";function b(){var a=document.createElement("bootstrap"),b={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var c in b)if(void 0!==a.style[c])return{end:b[c]};return!1}a.fn.emulateTransitionEnd=function(b){var c=!1,d=this;a(this).one(a.support.transition.end,function(){c=!0});var e=function(){c||a(d).trigger(a.support.transition.end)};return setTimeout(e,b),this},a(function(){a.support.transition=b()})}(jQuery),+function(a){"use strict";var b='[data-dismiss="alert"]',c=function(c){a(c).on("click",b,this.close)};c.prototype.close=function(b){function c(){f.trigger("closed.bs.alert").remove()}var d=a(this),e=d.attr("data-target");e||(e=d.attr("href"),e=e&&e.replace(/.*(?=#[^\s]*$)/,""));var f=a(e);b&&b.preventDefault(),f.length||(f=d.hasClass("alert")?d:d.parent()),f.trigger(b=a.Event("close.bs.alert")),b.isDefaultPrevented()||(f.removeClass("in"),a.support.transition&&f.hasClass("fade")?f.one(a.support.transition.end,c).emulateTransitionEnd(150):c())};var d=a.fn.alert;a.fn.alert=function(b){return this.each(function(){var d=a(this),e=d.data("bs.alert");e||d.data("bs.alert",e=new c(this)),"string"==typeof b&&e[b].call(d)})},a.fn.alert.Constructor=c,a.fn.alert.noConflict=function(){return a.fn.alert=d,this},a(document).on("click.bs.alert.data-api",b,c.prototype.close)}(jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.isLoading=!1};b.DEFAULTS={loadingText:"loading..."},b.prototype.setState=function(b){var c="disabled",d=this.$element,e=d.is("input")?"val":"html",f=d.data();b+="Text",f.resetText||d.data("resetText",d[e]()),d[e](f[b]||this.options[b]),setTimeout(a.proxy(function(){"loadingText"==b?(this.isLoading=!0,d.addClass(c).attr(c,c)):this.isLoading&&(this.isLoading=!1,d.removeClass(c).removeAttr(c))},this),0)},b.prototype.toggle=function(){var a=!0,b=this.$element.closest('[data-toggle="buttons"]');if(b.length){var c=this.$element.find("input");"radio"==c.prop("type")&&(c.prop("checked")&&this.$element.hasClass("active")?a=!1:b.find(".active").removeClass("active")),a&&c.prop("checked",!this.$element.hasClass("active")).trigger("change")}a&&this.$element.toggleClass("active")};var c=a.fn.button;a.fn.button=function(c){return this.each(function(){var d=a(this),e=d.data("bs.button"),f="object"==typeof c&&c;e||d.data("bs.button",e=new b(this,f)),"toggle"==c?e.toggle():c&&e.setState(c)})},a.fn.button.Constructor=b,a.fn.button.noConflict=function(){return a.fn.button=c,this},a(document).on("click.bs.button.data-api","[data-toggle^=button]",function(b){var c=a(b.target);c.hasClass("btn")||(c=c.closest(".btn")),c.button("toggle"),b.preventDefault()})}(jQuery),+function(a){"use strict";var b=function(b,c){this.$element=a(b),this.$indicators=this.$element.find(".carousel-indicators"),this.options=c,this.paused=this.sliding=this.interval=this.$active=this.$items=null,"hover"==this.options.pause&&this.$element.on("mouseenter",a.proxy(this.pause,this)).on("mouseleave",a.proxy(this.cycle,this))};b.DEFAULTS={interval:5e3,pause:"hover",wrap:!0},b.prototype.cycle=function(b){return b||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(a.proxy(this.next,this),this.options.interval)),this},b.prototype.getActiveIndex=function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},b.prototype.to=function(b){var c=this,d=this.getActiveIndex();return b>this.$items.length-1||0>b?void 0:this.sliding?this.$element.one("slid.bs.carousel",function(){c.to(b)}):d==b?this.pause().cycle():this.slide(b>d?"next":"prev",a(this.$items[b]))},b.prototype.pause=function(b){return b||(this.paused=!0),this.$element.find(".next, .prev").length&&a.support.transition&&(this.$element.trigger(a.support.transition.end),this.cycle(!0)),this.interval=clearInterval(this.interval),this},b.prototype.next=function(){return this.sliding?void 0:this.slide("next")},b.prototype.prev=function(){return this.sliding?void 0:this.slide("prev")},b.prototype.slide=function(b,c){var d=this.$element.find(".item.active"),e=c||d[b](),f=this.interval,g="next"==b?"left":"right",h="next"==b?"first":"last",i=this;if(!e.length){if(!this.options.wrap)return;e=this.$element.find(".item")[h]()}if(e.hasClass("active"))return this.sliding=!1;var j=a.Event("slide.bs.carousel",{relatedTarget:e[0],direction:g});return this.$element.trigger(j),j.isDefaultPrevented()?void 0:(this.sliding=!0,f&&this.pause(),this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid.bs.carousel",function(){var b=a(i.$indicators.children()[i.getActiveIndex()]);b&&b.addClass("active")})),a.support.transition&&this.$element.hasClass("slide")?(e.addClass(b),e[0].offsetWidth,d.addClass(g),e.addClass(g),d.one(a.support.transition.end,function(){e.removeClass([b,g].join(" ")).addClass("active"),d.removeClass(["active",g].join(" ")),i.sliding=!1,setTimeout(function(){i.$element.trigger("slid.bs.carousel")},0)}).emulateTransitionEnd(1e3*d.css("transition-duration").slice(0,-1))):(d.removeClass("active"),e.addClass("active"),this.sliding=!1,this.$element.trigger("slid.bs.carousel")),f&&this.cycle(),this)};var c=a.fn.carousel;a.fn.carousel=function(c){return this.each(function(){var d=a(this),e=d.data("bs.carousel"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c),g="string"==typeof c?c:f.slide;e||d.data("bs.carousel",e=new b(this,f)),"number"==typeof c?e.to(c):g?e[g]():f.interval&&e.pause().cycle()})},a.fn.carousel.Constructor=b,a.fn.carousel.noConflict=function(){return a.fn.carousel=c,this},a(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=a.extend({},e.data(),d.data()),g=d.attr("data-slide-to");g&&(f.interval=!1),e.carousel(f),(g=d.attr("data-slide-to"))&&e.data("bs.carousel").to(g),b.preventDefault()}),a(window).on("load",function(){a('[data-ride="carousel"]').each(function(){var b=a(this);b.carousel(b.data())})})}(jQuery),+function(a){"use strict";var b=function(c,d){this.$element=a(c),this.options=a.extend({},b.DEFAULTS,d),this.transitioning=null,this.options.parent&&(this.$parent=a(this.options.parent)),this.options.toggle&&this.toggle()};b.DEFAULTS={toggle:!0},b.prototype.dimension=function(){var a=this.$element.hasClass("width");return a?"width":"height"},b.prototype.show=function(){if(!this.transitioning&&!this.$element.hasClass("in")){var b=a.Event("show.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.$parent&&this.$parent.find("> .panel > .in");if(c&&c.length){var d=c.data("bs.collapse");if(d&&d.transitioning)return;c.collapse("hide"),d||c.data("bs.collapse",null)}var e=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[e](0),this.transitioning=1;var f=function(){this.$element.removeClass("collapsing").addClass("collapse in")[e]("auto"),this.transitioning=0,this.$element.trigger("shown.bs.collapse")};if(!a.support.transition)return f.call(this);var g=a.camelCase(["scroll",e].join("-"));this.$element.one(a.support.transition.end,a.proxy(f,this)).emulateTransitionEnd(350)[e](this.$element[0][g])}}},b.prototype.hide=function(){if(!this.transitioning&&this.$element.hasClass("in")){var b=a.Event("hide.bs.collapse");if(this.$element.trigger(b),!b.isDefaultPrevented()){var c=this.dimension();this.$element[c](this.$element[c]())[0].offsetHeight,this.$element.addClass("collapsing").removeClass("collapse").removeClass("in"),this.transitioning=1;var d=function(){this.transitioning=0,this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};return a.support.transition?void this.$element[c](0).one(a.support.transition.end,a.proxy(d,this)).emulateTransitionEnd(350):d.call(this)}}},b.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var c=a.fn.collapse;a.fn.collapse=function(c){return this.each(function(){var d=a(this),e=d.data("bs.collapse"),f=a.extend({},b.DEFAULTS,d.data(),"object"==typeof c&&c);!e&&f.toggle&&"show"==c&&(c=!c),e||d.data("bs.collapse",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.collapse.Constructor=b,a.fn.collapse.noConflict=function(){return a.fn.collapse=c,this},a(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(b){var c,d=a(this),e=d.attr("data-target")||b.preventDefault()||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,""),f=a(e),g=f.data("bs.collapse"),h=g?"toggle":d.data(),i=d.attr("data-parent"),j=i&&a(i);g&&g.transitioning||(j&&j.find('[data-toggle=collapse][data-parent="'+i+'"]').not(d).addClass("collapsed"),d[f.hasClass("in")?"addClass":"removeClass"]("collapsed")),f.collapse(h)})}(jQuery),+function(a){"use strict";function b(b){a(d).remove(),a(e).each(function(){var d=c(a(this)),e={relatedTarget:this};d.hasClass("open")&&(d.trigger(b=a.Event("hide.bs.dropdown",e)),b.isDefaultPrevented()||d.removeClass("open").trigger("hidden.bs.dropdown",e))})}function c(b){var c=b.attr("data-target");c||(c=b.attr("href"),c=c&&/#[A-Za-z]/.test(c)&&c.replace(/.*(?=#[^\s]*$)/,""));var d=c&&a(c);return d&&d.length?d:b.parent()}var d=".dropdown-backdrop",e="[data-toggle=dropdown]",f=function(b){a(b).on("click.bs.dropdown",this.toggle)};f.prototype.toggle=function(d){var e=a(this);if(!e.is(".disabled, :disabled")){var f=c(e),g=f.hasClass("open");if(b(),!g){"ontouchstart"in document.documentElement&&!f.closest(".navbar-nav").length&&a('').insertAfter(a(this)).on("click",b);var h={relatedTarget:this};if(f.trigger(d=a.Event("show.bs.dropdown",h)),d.isDefaultPrevented())return;f.toggleClass("open").trigger("shown.bs.dropdown",h),e.focus()}return!1}},f.prototype.keydown=function(b){if(/(38|40|27)/.test(b.keyCode)){var d=a(this);if(b.preventDefault(),b.stopPropagation(),!d.is(".disabled, :disabled")){var f=c(d),g=f.hasClass("open");if(!g||g&&27==b.keyCode)return 27==b.which&&f.find(e).focus(),d.click();var h=" li:not(.divider):visible a",i=f.find("[role=menu]"+h+", [role=listbox]"+h);if(i.length){var j=i.index(i.filter(":focus"));38==b.keyCode&&j>0&&j--,40==b.keyCode&&j').appendTo(document.body),this.$element.on("click.dismiss.bs.modal",a.proxy(function(a){a.target===a.currentTarget&&("static"==this.options.backdrop?this.$element[0].focus.call(this.$element[0]):this.hide.call(this))},this)),d&&this.$backdrop[0].offsetWidth,this.$backdrop.addClass("in"),!b)return;d?this.$backdrop.one(a.support.transition.end,b).emulateTransitionEnd(150):b()}else!this.isShown&&this.$backdrop?(this.$backdrop.removeClass("in"),a.support.transition&&this.$element.hasClass("fade")?this.$backdrop.one(a.support.transition.end,b).emulateTransitionEnd(150):b()):b&&b()};var c=a.fn.modal;a.fn.modal=function(c,d){return this.each(function(){var e=a(this),f=e.data("bs.modal"),g=a.extend({},b.DEFAULTS,e.data(),"object"==typeof c&&c);f||e.data("bs.modal",f=new b(this,g)),"string"==typeof c?f[c](d):g.show&&f.show(d)})},a.fn.modal.Constructor=b,a.fn.modal.noConflict=function(){return a.fn.modal=c,this},a(document).on("click.bs.modal.data-api",'[data-toggle="modal"]',function(b){var c=a(this),d=c.attr("href"),e=a(c.attr("data-target")||d&&d.replace(/.*(?=#[^\s]+$)/,"")),f=e.data("bs.modal")?"toggle":a.extend({remote:!/#/.test(d)&&d},e.data(),c.data());c.is("a")&&b.preventDefault(),e.modal(f,this).one("hide",function(){c.is(":visible")&&c.focus()})}),a(document).on("show.bs.modal",".modal",function(){a(document.body).addClass("modal-open")}).on("hidden.bs.modal",".modal",function(){a(document.body).removeClass("modal-open")})}(jQuery),+function(a){"use strict";var b=function(a,b){this.type=this.options=this.enabled=this.timeout=this.hoverState=this.$element=null,this.init("tooltip",a,b)};b.DEFAULTS={animation:!0,placement:"top",selector:!1,template:'',trigger:"hover focus",title:"",delay:0,html:!1,container:!1},b.prototype.init=function(b,c,d){this.enabled=!0,this.type=b,this.$element=a(c),this.options=this.getOptions(d);for(var e=this.options.trigger.split(" "),f=e.length;f--;){var g=e[f];if("click"==g)this.$element.on("click."+this.type,this.options.selector,a.proxy(this.toggle,this));else if("manual"!=g){var h="hover"==g?"mouseenter":"focusin",i="hover"==g?"mouseleave":"focusout";this.$element.on(h+"."+this.type,this.options.selector,a.proxy(this.enter,this)),this.$element.on(i+"."+this.type,this.options.selector,a.proxy(this.leave,this))}}this.options.selector?this._options=a.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()},b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.getOptions=function(b){return b=a.extend({},this.getDefaults(),this.$element.data(),b),b.delay&&"number"==typeof b.delay&&(b.delay={show:b.delay,hide:b.delay}),b},b.prototype.getDelegateOptions=function(){var b={},c=this.getDefaults();return this._options&&a.each(this._options,function(a,d){c[a]!=d&&(b[a]=d)}),b},b.prototype.enter=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);return clearTimeout(c.timeout),c.hoverState="in",c.options.delay&&c.options.delay.show?void(c.timeout=setTimeout(function(){"in"==c.hoverState&&c.show()},c.options.delay.show)):c.show()},b.prototype.leave=function(b){var c=b instanceof this.constructor?b:a(b.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);return clearTimeout(c.timeout),c.hoverState="out",c.options.delay&&c.options.delay.hide?void(c.timeout=setTimeout(function(){"out"==c.hoverState&&c.hide()},c.options.delay.hide)):c.hide()},b.prototype.show=function(){var b=a.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){if(this.$element.trigger(b),b.isDefaultPrevented())return;var c=this,d=this.tip();this.setContent(),this.options.animation&&d.addClass("fade");var e="function"==typeof this.options.placement?this.options.placement.call(this,d[0],this.$element[0]):this.options.placement,f=/\s?auto?\s?/i,g=f.test(e);g&&(e=e.replace(f,"")||"top"),d.detach().css({top:0,left:0,display:"block"}).addClass(e),this.options.container?d.appendTo(this.options.container):d.insertAfter(this.$element);var h=this.getPosition(),i=d[0].offsetWidth,j=d[0].offsetHeight;if(g){var k=this.$element.parent(),l=e,m=document.documentElement.scrollTop||document.body.scrollTop,n="body"==this.options.container?window.innerWidth:k.outerWidth(),o="body"==this.options.container?window.innerHeight:k.outerHeight(),p="body"==this.options.container?0:k.offset().left;e="bottom"==e&&h.top+h.height+j-m>o?"top":"top"==e&&h.top-m-j<0?"bottom":"right"==e&&h.right+i>n?"left":"left"==e&&h.left-i'}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"string"==typeof c?"html":"append":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;(e||"destroy"!=c)&&(e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]())})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(a(c).is("body")?window:c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);{var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#./.test(e)&&a(e);return f&&f.length&&f.is(":visible")&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})}},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);if(g&&b<=e[0])return g!=(a=f[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parentsUntil(this.options.target,".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate.bs.scrollspy")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.data("target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=this.pinnedOffset=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.getPinnedOffset=function(){if(this.pinnedOffset)return this.pinnedOffset;this.$element.removeClass(b.RESET).addClass("affix");var a=this.$window.scrollTop(),c=this.$element.offset();return this.pinnedOffset=c.top-a},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"top"==this.affixed&&(e.top+=d),"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top(this.$element)),"function"==typeof h&&(h=f.bottom(this.$element));var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;if(this.affixed!==i){this.unpin&&this.$element.css("top","");var j="affix"+(i?"-"+i:""),k=a.Event(j+".bs.affix");this.$element.trigger(k),k.isDefaultPrevented()||(this.affixed=i,this.unpin="bottom"==i?this.getPinnedOffset():null,this.$element.removeClass(b.RESET).addClass(j).trigger(a.Event(j.replace("affix","affixed"))),"bottom"==i&&this.$element.offset({top:c-h-this.$element.height()}))}}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(jQuery);
/* =========================================================
* bootstrap-slider.js v2.0.0
* http://www.eyecon.ro/bootstrap-slider
* =========================================================
* Copyright 2012 Stefan Petre
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================= */
!function( $ ) {
var Slider = function(element, options) {
this.element = $(element);
this.picker = $('
')
.insertBefore(this.element)
.append(this.element);
this.id = this.element.data('slider-id')||options.id;
if (this.id) {
this.picker[0].id = this.id;
}
if (typeof Modernizr !== 'undefined' && Modernizr.touch) {
this.touchCapable = true;
}
var tooltip = this.element.data('slider-tooltip')||options.tooltip;
this.tooltip = this.picker.find('.tooltip');
this.tooltipInner = this.tooltip.find('div.tooltip-inner');
this.orientation = this.element.data('slider-orientation')||options.orientation;
switch(this.orientation) {
case 'vertical':
this.picker.addClass('slider-vertical');
this.stylePos = 'top';
this.mousePos = 'pageY';
this.sizePos = 'offsetHeight';
this.tooltip.addClass('right')[0].style.left = '100%';
break;
default:
this.picker
.addClass('slider-horizontal')
.css('width', this.element.outerWidth());
this.orientation = 'horizontal';
this.stylePos = 'left';
this.mousePos = 'pageX';
this.sizePos = 'offsetWidth';
this.tooltip.addClass('top')[0].style.top = -this.tooltip.outerHeight() - 14 + 'px';
break;
}
this.min = this.element.data('slider-min')||options.min;
this.max = this.element.data('slider-max')||options.max;
this.step = this.element.data('slider-step')||options.step;
this.value = this.element.data('slider-value')||options.value;
if (this.value[1]) {
this.range = true;
}
this.selection = this.element.data('slider-selection')||options.selection;
this.selectionEl = this.picker.find('.slider-selection');
if (this.selection === 'none') {
this.selectionEl.addClass('hide');
}
this.selectionElStyle = this.selectionEl[0].style;
this.handle1 = this.picker.find('.slider-handle:first');
this.handle1Stype = this.handle1[0].style;
this.handle2 = this.picker.find('.slider-handle:last');
this.handle2Stype = this.handle2[0].style;
var handle = this.element.data('slider-handle')||options.handle;
switch(handle) {
case 'round':
this.handle1.addClass('round');
this.handle2.addClass('round');
break
case 'triangle':
this.handle1.addClass('triangle');
this.handle2.addClass('triangle');
break
}
if (this.range) {
this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
} else {
this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
this.handle2.addClass('hide');
if (this.selection == 'after') {
this.value[1] = this.max;
} else {
this.value[1] = this.min;
}
}
this.diff = this.max - this.min;
this.percentage = [
(this.value[0]-this.min)*100/this.diff,
(this.value[1]-this.min)*100/this.diff,
this.step*100/this.diff
];
this.offset = this.picker.offset();
this.size = this.picker[0][this.sizePos];
this.formater = options.formater;
this.layout();
if (this.touchCapable) {
// Touch: Bind touch events:
this.picker.on({
touchstart: $.proxy(this.mousedown, this)
});
} else {
this.picker.on({
mousedown: $.proxy(this.mousedown, this)
});
}
if (tooltip === 'show') {
this.picker.on({
mouseenter: $.proxy(this.showTooltip, this),
mouseleave: $.proxy(this.hideTooltip, this)
});
} else {
this.tooltip.addClass('hide');
}
};
Slider.prototype = {
constructor: Slider,
over: false,
inDrag: false,
showTooltip: function(){
this.tooltip.addClass('in');
//var left = Math.round(this.percent*this.width);
//this.tooltip.css('left', left - this.tooltip.outerWidth()/2);
this.over = true;
},
hideTooltip: function(){
if (this.inDrag === false) {
this.tooltip.removeClass('in');
}
this.over = false;
},
layout: function(){
this.handle1Stype[this.stylePos] = this.percentage[0]+'%';
this.handle2Stype[this.stylePos] = this.percentage[1]+'%';
if (this.orientation == 'vertical') {
this.selectionElStyle.top = Math.min(this.percentage[0], this.percentage[1]) +'%';
this.selectionElStyle.height = Math.abs(this.percentage[0] - this.percentage[1]) +'%';
} else {
this.selectionElStyle.left = Math.min(this.percentage[0], this.percentage[1]) +'%';
this.selectionElStyle.width = Math.abs(this.percentage[0] - this.percentage[1]) +'%';
}
if (this.range) {
this.tooltipInner.text(
this.formater(this.value[0]) +
' : ' +
this.formater(this.value[1])
);
this.tooltip[0].style[this.stylePos] = this.size * (this.percentage[0] + (this.percentage[1] - this.percentage[0])/2)/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
} else {
this.tooltipInner.text(
this.formater(this.value[0])
);
this.tooltip[0].style[this.stylePos] = this.size * this.percentage[0]/100 - (this.orientation === 'vertical' ? this.tooltip.outerHeight()/2 : this.tooltip.outerWidth()/2) +'px';
}
},
mousedown: function(ev) {
// Touch: Get the original event:
if (this.touchCapable && ev.type === 'touchstart') {
ev = ev.originalEvent;
}
this.offset = this.picker.offset();
this.size = this.picker[0][this.sizePos];
var percentage = this.getPercentage(ev);
if (this.range) {
var diff1 = Math.abs(this.percentage[0] - percentage);
var diff2 = Math.abs(this.percentage[1] - percentage);
this.dragged = (diff1 < diff2) ? 0 : 1;
} else {
this.dragged = 0;
}
this.percentage[this.dragged] = percentage;
this.layout();
if (this.touchCapable) {
// Touch: Bind touch events:
$(document).on({
touchmove: $.proxy(this.mousemove, this),
touchend: $.proxy(this.mouseup, this)
});
} else {
$(document).on({
mousemove: $.proxy(this.mousemove, this),
mouseup: $.proxy(this.mouseup, this)
});
}
this.inDrag = true;
var val = this.calculateValue();
this.element.trigger({
type: 'slideStart',
value: val
}).trigger({
type: 'slide',
value: val
});
return false;
},
mousemove: function(ev) {
// Touch: Get the original event:
if (this.touchCapable && ev.type === 'touchmove') {
ev = ev.originalEvent;
}
var percentage = this.getPercentage(ev);
if (this.range) {
if (this.dragged === 0 && this.percentage[1] < percentage) {
this.percentage[0] = this.percentage[1];
this.dragged = 1;
} else if (this.dragged === 1 && this.percentage[0] > percentage) {
this.percentage[1] = this.percentage[0];
this.dragged = 0;
}
}
this.percentage[this.dragged] = percentage;
this.layout();
var val = this.calculateValue();
this.element
.trigger({
type: 'slide',
value: val
})
.data('value', val)
.prop('value', val);
return false;
},
mouseup: function(ev) {
if (this.touchCapable) {
// Touch: Bind touch events:
$(document).off({
touchmove: this.mousemove,
touchend: this.mouseup
});
} else {
$(document).off({
mousemove: this.mousemove,
mouseup: this.mouseup
});
}
this.inDrag = false;
if (this.over == false) {
this.hideTooltip();
}
this.element;
var val = this.calculateValue();
this.element
.trigger({
type: 'slideStop',
value: val
})
.data('value', val)
.prop('value', val);
return false;
},
calculateValue: function() {
var val;
if (this.range) {
val = [
(this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step),
(this.min + Math.round((this.diff * this.percentage[1]/100)/this.step)*this.step)
];
this.value = val;
} else {
val = (this.min + Math.round((this.diff * this.percentage[0]/100)/this.step)*this.step);
this.value = [val, this.value[1]];
}
return val;
},
getPercentage: function(ev) {
if (this.touchCapable) {
ev = ev.touches[0];
}
var percentage = (ev[this.mousePos] - this.offset[this.stylePos])*100/this.size;
percentage = Math.round(percentage/this.percentage[2])*this.percentage[2];
return Math.max(0, Math.min(100, percentage));
},
getValue: function() {
if (this.range) {
return this.value;
}
return this.value[0];
},
setValue: function(val) {
this.value = val;
if (this.range) {
this.value[0] = Math.max(this.min, Math.min(this.max, this.value[0]));
this.value[1] = Math.max(this.min, Math.min(this.max, this.value[1]));
} else {
this.value = [ Math.max(this.min, Math.min(this.max, this.value))];
this.handle2.addClass('hide');
if (this.selection == 'after') {
this.value[1] = this.max;
} else {
this.value[1] = this.min;
}
}
this.diff = this.max - this.min;
this.percentage = [
(this.value[0]-this.min)*100/this.diff,
(this.value[1]-this.min)*100/this.diff,
this.step*100/this.diff
];
this.layout();
}
};
$.fn.slider = function ( option, val ) {
return this.each(function () {
var $this = $(this),
data = $this.data('slider'),
options = typeof option === 'object' && option;
if (!data) {
$this.data('slider', (data = new Slider(this, $.extend({}, $.fn.slider.defaults,options))));
}
if (typeof option == 'string') {
data[option](val);
}
})
};
$.fn.slider.defaults = {
min: 0,
max: 10,
step: 1,
orientation: 'horizontal',
value: 5,
selection: 'before',
tooltip: 'show',
handle: 'round',
formater: function(value) {
return value;
}
};
$.fn.slider.Constructor = Slider;
}( window.jQuery );
if( $('.new-form-guarantor').length > 0) {
function validateName(name) {
if (name) {
var expression = /^[A-Za-z-']{2,20}$/;
if (expression.test(name)) {
return true;
}
}
return false;
}
function getAJAXUrl() {
return Routing.generate('access_new_loan_application_ajax', {}, true);
//return '/v2/ajax-call';
//return '/app_dev.php' + '/v2/ajax-call';
}
var checkGuarantorAddressHistoryValues = function() {
var address2 = $('#address-2');
var address3 = $('#address-3');
var employmentDetail = $('#employment-detail');
var $a1y, $a1m, $a2y, $a2m, $a1total, $a2total;
$a1y = $('#GuarantorApplication_addresses_0_address_lived_years');
$a1m = $('#GuarantorApplication_addresses_0_address_lived_months');
$a2y = $('#GuarantorApplication_addresses_1_address_lived_years');
$a2m = $('#GuarantorApplication_addresses_1_address_lived_months');
if($.isNumeric($a1y.val()) && $.isNumeric($a1m.val())) {
//console.log('inside first if 34');
$a1total = parseInt( calculateMonths($a1y, $a1m) );
$a2total = parseInt( calculateMonths($a2y, $a2m) );
if ($a1total !== false && $a1total < 36) {
if (address2.not(":visible")) {
address2.show();
}
employmentDetail.hide();
//console.log('employmentDetail hide 43');
if(!isNaN($a2total) && $a2total > 0) {
if ($a2total !== false && ($a1total + $a2total) < 36) {
if (address3.not(':visible')) {
address3.show();
}
employmentDetail.hide();
//console.log('employmentDetail hide 51');
} else {
address3.hide();
employmentDetail.show();
}
}
} else {
//console.log('hit else 61');
address2.hide();
resetAddressFields(2);
address3.hide();
resetAddressFields(3);
employmentDetail.show(); // if no past addresses are required, then just make the employment section appear
}
}
};
$(document).ready( function() {
if($('#GuarantorApplication_mobile_number').val() != "") {
$('#validation-summary li#mobile').remove();
}
if($('#GuarantorApplication_email').val() != "") {
$('#validation-summary li#email').remove();
}
if($('#GuarantorApplication_first_name').val() != "") {
$('#validation-summary li#first_name').remove();
}
if($('#GuarantorApplication_surname').val() != "") {
$('#validation-summary li#last_name').remove();
}
if($('#GuarantorApplication_title').val() != "") {
$('#validation-summary li#title').remove();
}
if($('#GuarantorApplication_uk_resident').val() != "") {
$('#validation-summary li#uk_resident').remove();
}
if($('#GuarantorApplication_dob_day').val() != "" && $('#GuarantorApplication_dob_month').val() != "" && $('#GuarantorApplication_dob_year').val() != "") {
$('#validation-summary li#dob').remove();
}
function checkGuarantorUnemployedFields() {
//console.log('calling checkGuarantorUnemployedFields');
var failed;
var required_fields = {
1:'GuarantorApplication_unemployed_income_source',
2:'GuarantorApplication_unemployed_net_income',
3:'GuarantorApplication_unemployed_employment_pay_frequency'
};
$.each( required_fields, function( i, field ) {
if( $( "#" + field ).val() == "" ) {
failed = true;
}
});
if (failed) {
//console.log('return false');
return false;
} else {
//console.log('return true');
return true;
}
}
if( $('#GuarantorApplication_new_mobile').length > 0 && $('.your_number').length > 0 ) {
$('#GuarantorApplication_new_mobile').val($('#GuarantorApplication_mobile_number').val().replace('+44','0'));
$('.your_number').text($('#GuarantorApplication_mobile_number').val());
}
//$('#GuarantorApplication_addresses_0_address_lived_years').attr('disabled','disabled');
//$('#GuarantorApplication_addresses_0_address_lived_months').attr('disabled','disabled');
//$('#GuarantorApplication_addresses_1_address_lived_years').attr('disabled','disabled');
//$('#GuarantorApplication_addresses_1_address_lived_months').attr('disabled','disabled');
//$('#GuarantorApplication_addresses_2_address_lived_years').attr('disabled','disabled');
//$('#GuarantorApplication_addresses_2_address_lived_months').attr('disabled','disabled');
function checkGuarantorAddressFields(address_id) { // this function will check to see whether or not to enable the years/months lived boxes
var flat_no = $('#GuarantorApplication_addresses_'+address_id+'_address_flat_number').val();
var building_no = $('#GuarantorApplication_addresses_'+address_id+'_address_building_number').val();
var building_name = $('#GuarantorApplication_addresses_'+address_id+'_address_building_name').val();
var thouroughfare = $('#GuarantorApplication_addresses_'+address_id+'_address_thouroughfare').val();
var post_town = $('#GuarantorApplication_addresses_'+address_id+'_address_post_town').val();
var postcode = $('#GuarantorApplication_addresses_'+address_id+'_address_postcode').val();
if(( flat_no || building_no || building_name ) && thouroughfare && post_town && postcode) {
$('#GuarantorApplication_addresses_'+address_id+'_address_lived_years').removeAttr('disabled');
$('#GuarantorApplication_addresses_'+address_id+'_address_lived_months').removeAttr('disabled');
// add the shaking icon to indicate requirement
$('#GuarantorApplication_addresses_'+address_id+'_address_lived_years').parent().parent().prev()
.html('
Required field');
}
}
function checkGuarantorEmploymentFields(employment_id) { // this function will check to see whether or not to enable the years/months lived boxes
var employer_name = $('#GuarantorApplication_employments_'+employment_id+'_employer_name').val();
var employment_type = $('#GuarantorApplication_employments_'+employment_id+'_employment_type').val();
var employment_role = $('#GuarantorApplication_employments_'+employment_id+'_employment_role').val();
if (employment_id == 0) { // these fields are only required for current employment
var employer_phone = $('#GuarantorApplication_employments_'+employment_id+'_extra_employer_telephone').val();
var net_income = $('#GuarantorApplication_employments_'+employment_id+'_extra_net_income').val();
var pay_frequency = $('#GuarantorApplication_employments_'+employment_id+'_extra_employment_pay_frequency').val();
} else {
employer_phone = true; // auto set to true if it's any previous employment
net_income = true;
pay_frequency = true;
}
if (employer_name && employment_type && employment_role && employer_phone && net_income && pay_frequency) {
$('#GuarantorApplication_employments_'+employment_id+'_employment_years').removeAttr('disabled');
$('#GuarantorApplication_employments_'+employment_id+'_employment_months').removeAttr('disabled');
}
}
function checkGuarantorEmploymentFieldsMobile(employment_id) {
var employer_name = $('#GuarantorApplication_employments_'+employment_id+'_employer_name');
var employment_type = $('#GuarantorApplication_employments_'+employment_id+'_employment_type');
var employment_role = $('#GuarantorApplication_employments_'+employment_id+'_employment_role');
var net_income = $('#GuarantorApplication_employments_'+employment_id+'_extra_net_income');
var pay_frequency = $('#GuarantorApplication_employments_'+employment_id+'_extra_employment_pay_frequency');
var employer_telephone = $('#GuarantorApplication_employments_'+employment_id+'_extra_employer_telephone');
var scrolltopoint = false;
if(!employer_name.val()) {
$('#gt_employer_name_'+employment_id+'-error').show();
// scroll up to title.
scrolltopoint = employer_name;
}
if(!employment_type.val() ) {
$('#gt_employment_type_'+employment_id+'-error').show();
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = employment_type;
}
}
if(!employment_role.val() ) {
$('#gt_employment_role_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = employment_role;
}
}
if( employment_id == 0 ) {
if(!net_income.val() ) {
$('#gt_net_income_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = net_income;
}
}
if(!pay_frequency.val() ) {
$('#gt_pay_frequency_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = pay_frequency;
}
}
if(!employer_telephone.val() ) {
$('#gt_employer_telephone_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = employer_telephone;
}
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
$('.gt_employment-mobile-overlay_'+employment_id)[0].style.setProperty("display","none","important");
}
}
function checkGuarantorAddressFieldsMobile(address_id) {
console.log('checkGuarantorAddressFieldsMobile id: ' + address_id)
var flat_no = $('#GuarantorApplication_addresses_'+address_id+'_address_flat_number');
var building_no = $('#GuarantorApplication_addresses_'+address_id+'_address_building_number');
var building_name = $('#GuarantorApplication_addresses_'+address_id+'_address_building_name');
var thouroughfare = $('#GuarantorApplication_addresses_'+address_id+'_address_thouroughfare');
var post_town = $('#GuarantorApplication_addresses_'+address_id+'_address_post_town');
var postcode = $('#GuarantorApplication_addresses_'+address_id+'_address_postcode');
var scrolltopoint = false;
if(!flat_no.val() && !building_no.val() && !building_name.val()) {
$('#gt_flat_no_'+address_id+'-error').show();
$('#gt_building_no_'+address_id+'-error').show();
$('#gt_building_name_'+address_id+'-error').show();
// scroll up to title.
scrolltopoint = flat_no;
}
if(!thouroughfare.val() ) {
$('#gt_thouroughfare_'+address_id+'-error').show();
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = thouroughfare;
}
}
if(!post_town.val() ) {
$('#gt_post_town_'+address_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = post_town;
}
}
if(!postcode.val() ) {
$('#gt_postcode_'+address_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = postcode;
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
$('.gt_mobile-overlay_'+address_id)[0].style.setProperty("display","none","important");
}
}
function calculateMonths(years, months) {
if ($.isNumeric(years.val()) && $.isNumeric(months.val())) {
var years_as_months = parseInt(years.val()*12);
var existing_months = parseInt(months.val());
var result = parseInt( years_as_months + existing_months );
return result;
//29.09.14 - Made sure that the retured result is definitely a number by using parseInt and breaking it down (M.E.)
}
return false;
}
$('.gt_mobile-overlay_0').on( 'click', function(e) {
// check address values on mobile
checkGuarantorAddressFieldsMobile(0);
});
$('.gt_mobile-overlay_1').on( 'click', function(e) {
// check address values on mobile
checkGuarantorAddressFieldsMobile(1);
});
$('.gt_mobile-overlay_2').on( 'click', function(e) {
// check address values on mobile
checkGuarantorAddressFieldsMobile(2);
});
$('.gt_employment-mobile-overlay_0').on( 'click', function(e) {
// check address values on mobile
checkGuarantorEmploymentFieldsMobile(0);
});
$('.gt_employment-mobile-overlay_1').on( 'click', function(e) {
// check address values on mobile
checkGuarantorEmploymentFieldsMobile(1);
});
$('.gt_employment-mobile-overlay_2').on( 'click', function(e) {
// check address values on mobile
checkGuarantorEmploymentFieldsMobile(2);
});
// run the check on the address history values so the form knows whether to display the previous address block
checkGuarantorAddressHistoryValues();
checkGuarantorEmploymentFields(0);
checkGuarantorEmploymentFields(1);
checkGuarantorEmploymentFields(2);
checkGuarantorAddressFields(0);
checkGuarantorAddressFields(1);
checkGuarantorAddressFields(2);
$('#GuarantorApplication_first_name').on( 'blur', function() {
if( $(this).val() != "") {
$(this).val(capitaliseInput($(this).val()));
}
});
$('#GuarantorApplication_middle_name').on( 'blur', function() {
if( $(this).val() != "") {
$(this).val(capitaliseInput($(this).val()));
}
});
$('#GuarantorApplication_surname').on( 'blur', function() {
if( $(this).val() != "") {
$(this).val(capitaliseInput($(this).val()));
}
});
$('#GuarantorApplication_user_new_account_submit').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
$('#GuarantorApplication_password_new_password').on( 'keyup', function() {
checkRequiredFields();
});
$('#GuarantorApplication_password_new_password_confirm').on( 'keyup', function() {
var message_box = $(this).parent().prev();
var prev_message_box = $('#GuarantorApplication_password_new_password').parent().prev();
var mobile_message_box = $('#gt_password-error');
var chosenPassword = $('#GuarantorApplication_password_new_password').val();
if( chosenPassword != "" && chosenPassword == $(this).val() ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
prev_message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('password');
} else {
message_box.html('
Passwords do not match!');
message_box.next().addClass('has-error');
addToValidationSummary('password','Password','required');
}
checkRequiredFields();
});
$('#GuarantorApplication_user_security_question').on( 'change', function() {
if($(this).val() != "") {
$('#gt_security_question-error')[0].style.setProperty('display','none','important');
}
checkRequiredFields();
});
$('#GuarantorApplication_user_security_answer').on( 'keyup', function() {
if($(this).val() != "") {
$('#gt_security_answer-error')[0].style.setProperty('display','none','important');
}
checkRequiredFields();
});
function checkRequiredFields() {
var failed = false;
$('#GuarantorApplication_user_new_account_submit').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
var pwd = false;
var requiredFields = {
1:'GuarantorApplication_title',
2:'GuarantorApplication_first_name',
3:'GuarantorApplication_surname',
4:'GuarantorApplication_dob_day',
5:'GuarantorApplication_dob_month',
6:'GuarantorApplication_dob_year',
7:'GuarantorApplication_uk_resident',
8:'GuarantorApplication_mobile_number',
9:'GuarantorApplication_email',
10:'GuarantorApplication_password_new_password',
11:'GuarantorApplication_password_new_password_confirm',
12:'GuarantorApplication_user_security_question',
13:'GuarantorApplication_user_security_answer'
};
$.each( requiredFields, function( i, field ) {
if( $( "#" + field ).val() == "" ) {
failed = true;
}
// check for password match
if( i == 10 ) {
pwd = $('#'+field).val();
}
if( i == 11 && pwd != false ) {
if( pwd != $('#'+field).val() ) { // passwords did not match.
failed = true;
}
}
});
if(!failed) {
$('#GuarantorApplication_user_new_account_submit').removeAttr('disabled').addClass('btn-primary').removeClass('btn-disabled');
}
}
// the mobile version of email continue will work slightly differently.
$('.new_account_submit-mobile').on( 'click', function(e) {
// list all required fields for now, we will check them directly here
var title = $('#GuarantorApplication_title');
var first_name = $('#GuarantorApplication_first_name');
var surname = $('#GuarantorApplication_surname');
var dob_day = $('#GuarantorApplication_dob_day');
var dob_mon = $('#GuarantorApplication_dob_month');
var dob_year = $('#GuarantorApplication_dob_year');
var uk_resident = $('#GuarantorApplication_uk_resident');
var mobile = $('#GuarantorApplication_mobile_number');
var email = $('#GuarantorApplication_email');
var password = $('#GuarantorApplication_password_new_password');
var password_confirm = $('#GuarantorApplication_password_new_password_confirm');
var security_question = $('#GuarantorApplication_user_security_question');
var security_answer = $('#GuarantorApplication_user_security_answer');
var scrolltopoint = false;
if(!title.val() ) {
$('#gt_title-error').show();
title.parent().addClass('has-error');
// scroll up to title.
scrolltopoint = title;
}
if(!first_name.val() ) {
$('#gt_first_name-error').show();
first_name.parent().addClass('has-error');
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = first_name;
}
}
if(!surname.val() ) {
$('#gt_surname-error').show();
surname.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = surname;
}
}
if(!dob_day.val() || !dob_mon.val() || !dob_year.val()) {
$('#gt_dob-error').show();
dob_day.parent().parent().parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = dob_day;
}
}
if(!uk_resident.val() ) {
$('#gt_uk_resident-error').show();
uk_resident.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = uk_resident;
}
}
if(!mobile.val()) {
// a message needs to be added here
$('#mobile-error span').html(' This field is required!');
$('#mobile-error').show();
mobile.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = mobile;
}
}
if(!email.val()) {
// a message needs to be added here
$('#email-error span').html(' This field is required!');
// in case the warning sign icon is already in the box, remove it and add the chevron again
$('#email-error i').removeClass('fa-warning').addClass('fa-chevron-up');
$('#email-error').show();
email.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = email;
}
}
if(!password.val()) {
// a message needs to be added here
$('#gt_password-error span').html(' This field is required!');
$('#gt_password-error').show();
password.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = password;
}
}
if(!password_confirm.val()) {
$('#gt_password_confirm-error span').html(' This field is required!');
$('#gt_password_confirm-error').show();
password_confirm.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = password_confirm;
}
}
if(password.val() != password_confirm.val()) {
$('#gt_password-error span').html(' Passwords do not match!');
$('#gt_password-error').show();
$('#gt_password_confirm-error span').html(' Passwords do not match!');
$('#gt_password_confirm-error').show();
password.parent().addClass('has-error');
password_confirm.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = password;
}
}
if(!security_question.val()) {
// a message needs to be added here
$('#gt_security_question-error').show();
security_question.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = security_question;
}
}
if(!security_answer.val()) {
// a message needs to be added here
$('#gt_security_answer-error').show();
security_answer.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = security_answer;
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
if ($('#GuarantorApplication_email').val() != "") {
logGuarantorApplication();
}
}
e.preventDefault();
});
$('body').on('keypress', function(e) {
var keyCode = (e.keyCode ? e.keyCode : e.which);
if(keyCode == 13 && checkRequiredFields() && $('#GuarantorApplication_user_new_account_submit').is(":visible")) { // only action if all the required fields are filled
$('#GuarantorApplication_user_new_account_submit').trigger('click');
return false;
} else if( keyCode == 13 && $('#GuarantorApplication_save').is(":enabled")) {
$('#GuarantorApplication_save').trigger("click");
return false;
}
});
if( $('#guarantor-submit').length > 0 ) {
//check the input fields for values so the submit button can be active if everything valid
$('.required-field select, .required-field input').on( 'change', function() {
var fields = $('.required-field select, .required-field input').serializeArray();
var valueCount = 0;
$.each( fields, function( i, field ) {
// do not count irrelevant or non-required fields.
if(field.value != '') {
valueCount = (valueCount + 1);
}
});
if( valueCount < 12 ) { //needs at least 12 fields filled in, not including the non-required ones
return false;
} else {
$('#GuarantorApplication_user_new_account_submit').removeAttr('disabled').removeClass('btn-disabled').addClass('btn-primary');
}
return true;
});
}
/** GUARANTOR SAVE & UPDATE **/
$('.form-step-5 input, .form-step-5 select').on( 'change', function() {
var g_first_name = $('#GuarantorApplication_first_name').val();
var g_surname = $('#GuarantorApplication_surname').val();
var g_age = $('#GuarantorApplication_applicant_confirmed_age').val();
var g_mobile_number = $('#GuarantorApplication_mobile_number').val();
var g_email = $('#GuarantorApplication_email').val();
var g_relation = $('#GuarantorApplication_applicant_relation').val();
if(g_first_name && g_surname && g_age && g_mobile_number && g_email && g_relation) {
// before deciding whether to show the save button,
// make sure the email and mobile number are both valid
if( !validateEmail(g_email) ) {
return false;
}
if( !validateMobile(g_mobile_number) ) {
return false;
}
// as long as all required fields are filled out, allow the submit button to be clickable
$('#GuarantorApplication_user_new_account_submit').removeAttr('disabled').removeClass('btn-disabled').addClass('btn-primary');
}
return false;
});
// do quick check on dob fields. This is the only way to see if it is filled in or not.
// This only needs to be done on the applicant form so check the id exists.
if($('#GuarantorApplication_dob').length > 0) {
$.post(getAJAXUrl(),
{ action: 'check_guarantor_dob' }
).done( function(response) {
var message_box = $('#GuarantorApplication_dob').parent().parent().prev();
var mobile_message_box = $('#gt_dob-error');
var mobile_message_box_span = $('#gt_dob-error span');
if ( response == 'ok' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'empty') {
message_box.html('
You must be 21 or over to be a guarantor');
//mobile_message_box_span.html(' You must be 21 or over to be a guarantor');
//mobile_message_box.show();
} else if( response == 'newapp') { //a new application yet to be filled out
message_box.html('
You must be 21 or over to be a guarantor');
mobile_message_box_span.html(' You must be 21 or over to be a guarantor');
mobile_message_box.show();
} else {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
}
function logGuarantorApplication() {
// EDIT! Since every other value can be OK on the fly as
// the guarantor already exists in the db, the only thing that
// needs to be OK here is the password. It will overwrite the
// existing pre-created one and then log the person in again.
var message_box = $('#GuarantorApplication_user_new_account_submit').parent().prev();
var password = $('#GuarantorApplication_user_password_new_password').val();
var security_question = $('#GuarantorApplication_user_security_question').val();
var security_answer = $('#GuarantorApplication_user_security_answer').val();
$.post(getAJAXUrl(),
{ password: password, security_question: security_question, security_answer: security_answer, action: 'save_guarantor_security' }
).done( function(response) {
if (response == 1) {
//console.log('response was equal to 1');
// all good
$('#guarantor-new-mobile').val($('#GuarantorApplication_mobile_number').val());
resolveGuarantorMobilePhoneFields();
$('#password-details').slideUp();
$('#guarantor-submit').hide();
$('#rest-of-form').fadeIn();
$('#GuarantorApplication_uk_resident').attr('readonly','readonly'); // lock down the uk residency option
// Scroll to anchor to make sure user can still see form on mobile.
$('html,body').animate({scrollTop: $('#post_signup_anchor').offset().top},'slow');
} else {
//console.log('response was NOT equal to 1');
message_box.html('
Sorry, an error occurred.');
}
});
return false;
}
function resolveGuarantorMobilePhoneFields() {
$('.your_number').text($('#GuarantorApplication_mobile_number').val()); // update the SMS number for later display
$('#GuarantorApplication_SmsRequests_0_validation_code').val(''); // set the SMS validation code field entry to empty
}
// instead of putting all the code within a click event, run the above function
// so we can cater for mobile clicks too.
$('#GuarantorApplication_user_new_account_submit').on( 'click', logGuarantorApplication );
$('#GuarantorApplication_password_new_password').on('keyup', function() {
if($(this).val() != "") {
$('#gt_password-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
}
});
$('#GuarantorApplication_password_new_password_confirm').on('keyup', function() {
if($(this).val() != "") {
$('#gt_password_confirm-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
}
});
$('#GuarantorApplication_title').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_title-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_title' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('title');
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('
Required!');
addToValidationSummary('title','Title','required');
mobile_message_box.show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('title');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('title');
message_box.next().removeClass('has-error');
}
});
});
$('#GuarantorApplication_first_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_first_name-error');
var mobile_message_box_span = $('#gt_first_name-error span');
if( validateName(field_value) ) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_first_name', is_guarantor: 1 }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('first_name');
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('
Required!');
addToValidationSummary('first_name','First name','required');
mobile_message_box_span.html(" This field is required!");
mobile_message_box.show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('first_name');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('first_name');
message_box.next().removeClass('has-error');
}
});
} else {
message_box.html('
Invalid name!');
addToValidationSummary('first_name','First name','required');
mobile_message_box_span.html(" Invalid name!");
mobile_message_box.show();
message_box.next().addClass('has-error');
}
});
$('#GuarantorApplication_middle_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_middle_name-error');
var mobile_message_box_span = $('#gt_middle_name-error span');
// if no middle name has been entered, there's no need to do any checks.
if( field_value == "" ) {
return false;
}
if( validateName(field_value) ) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_middle_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
} else if( response == 'noval') {
message_box.html(' ');
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
}
});
} else {
message_box.html('
Invalid name!');
mobile_message_box_span.html(" Invalid name!");
mobile_message_box.show();
}
});
$('#GuarantorApplication_surname').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_surname-error');
var mobile_message_box_span = $('#gt_surname-error span');
if( validateName(field_value) ) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_surname', is_guarantor: 1 }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('last_name');
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('
Required!');
addToValidationSummary('last_name','Last name','required');
mobile_message_box_span(" This field is required!");
mobile_message_box.show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('last_name');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('last_name');
message_box.next().removeClass('has-error');
}
});
} else {
message_box.html('
Invalid name!');
addToValidationSummary('last_name','Last name','invalid');
mobile_message_box_span(" Invalid name!");
mobile_message_box.show();
message_box.next().addClass('has-error');
}
});
$('#GuarantorApplication_dob select').on( 'change', function(e) {
var dobday = false;
var dobmonth = false;
var dobyear = false;
var message_box = $(this).parent().parent().parent().prev();
var mobile_message_box = $('#gt_dob-error');
var mobile_message_box_span = $('#gt_dob-error span');
var mobile_info_box = $('#gt_dob-info');
var mobile_info_box_span = $('#gt_dob-info span');
//check to see if all values are filled before sending to database.
if($('#GuarantorApplication_dob_day').val() != "") {
dobday = $('#GuarantorApplication_dob_day').val();
}
if($('#GuarantorApplication_dob_month').val() != "") {
dobmonth = $('#GuarantorApplication_dob_month').val();
}
if($('#GuarantorApplication_dob_year').val() != "") {
dobyear = $('#GuarantorApplication_dob_year').val();
}
if(dobday && dobmonth && dobyear) { //all filled out
message_box.html(' ');
mobile_info_box[0].style.setProperty('display','none','important');
//format result.
var dob_value = dobyear+'-'+dobmonth+'-'+dobday;
$.post(getAJAXUrl(),
{ value: dob_value, field_name: 'dob', action: 'save_guarantor_dob' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
message_box.next().removeClass('has-error');
mobile_info_box[0].style.setProperty('display','none','important');
} else if( response == 'tooyoung') {
message_box.html('
Sorry! You must be between 25 and 75 to be a guarantor.');
addToValidationSummary('dob','Date of birth','invalid');
message_box.next().addClass('has-error');
mobile_message_box_span.html( "You must be between 25 and 75 to be a guarantor");
mobile_message_box.show();
mobile_info_box[0].style.setProperty('display','none','important');
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
message_box.next().removeClass('has-error');
mobile_info_box[0].style.setProperty('display','none','important'); // hide the info box, not needed anymore
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
message_box.next().removeClass('has-error');
mobile_info_box[0].style.setProperty('display','none','important');
}
});
} else {
message_box.html('
Please select full date of birth');
mobile_info_box_span.html( "Please select full date of birth");
mobile_info_box.show();
//message_box.next().addClass('has-error');
}
e.preventDefault();
});
$('#GuarantorApplication_uk_resident').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_uk_resident-error');
var mobile_message_box_span = $('#gt_uk_resident-error span');
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
if( field_value == "" ) {
message_box.next().addClass('has-error');
message_box.html('
You must be a UK resident to apply');
mobile_message_box_span.html(" You must be a UK resident to apply");
mobile_message_box.show();
}
$.post(getAJAXUrl(),
{ value: field_value, action: 'check_uk_residency' }
).done( function(response) {
if ( response == 'OK' ) {
// because the uk residency is not OK after hitting the button, it needs to be done on the fly now.
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_uk_residency' }
).done( function(response) {
if ( response == 'success' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('uk_resident');
message_box.next().removeClass('has-error');
} else {
message_box.html('
Something went wrong!');
message_box.next().addClass('has-error');
}
});
} else if( response == 'fail') {
message_box.html('
You must be a UK resident to apply');
addToValidationSummary('uk_resident','UK residency status','required');
mobile_message_box_span.html(" You must be a UK resident to apply");
mobile_message_box.show();
message_box.next().addClass('has-error');
} else {
message_box.html('
Something went wrong!');
message_box.next().addClass('has-error');
}
});
});
if($('#GuarantorApplication_uk_resident').length > 0) {
if($('#GuarantorApplication_uk_resident').val() == 1) {
$('#GuarantorApplication_uk_resident').attr('readonly','readonly'); //lock down the UK residency option if it's already set to Yes.
}
}
$('#GuarantorApplication_mobile_number').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var validation = validateMobile(message_box,field_value);
if ( validation ) {
message_box.html(' ');
// do a dedupe test first
$.post(getAJAXUrl(),
{ number: field_value, action: 'check_mobile_dupe'}
).done( function(response) {
if (response == 1) {
message_box.html('
It looks like this number could already be attached to an account. Please use an alternative or log in here if you have an account.');
return false;
} else {
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_guarantor_mobile_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
} else if( response == 'noval') {
message_box.html('
Required!');
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
}
});
}
});
}
});
$('#GuarantorApplication_addresses_0_mortgage_cost').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
// check for numeric entry
if (field_value.length > 0 && !$.isNumeric(field_value)) {
message_box.html('
Rent cost must be a number!');
$('#gt_mortgage_cost-error span').html(' Rent cost must be a number!');
$('#gt_mortgage_cost-error').show();
message_box.next().addClass('has-error');
return false;
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_mortgage_cost' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_mortgage_cost-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
}
});
});
$('#GuarantorApplication_addresses_0_rent_cost').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
// check for numeric entry
if (field_value.length > 0 && !$.isNumeric(field_value)) {
message_box.html('
Rent cost must be a number!');
$('#gt_rent_cost-error span').html(' Rent cost must be a number!');
$('#gt_rent_cost-error').show();
message_box.next().addClass('has-error');
return false;
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_rent_cost' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_rent_cost-error')[0].style.setProperty('display', 'none', 'important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_rent_cost-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_rent_cost-error')[0].style.setProperty('display', 'none', 'important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_rent_cost-error')[0].style.setProperty('display', 'none', 'important');
}
});
});
$('#GuarantorApplication_cost_other').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_cost_other' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_cost_other-error')[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_cost_other-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_cost_other-error')[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_cost_other-error')[0].style.setProperty('display','none','important');
}
});
});
// would likely need to validate this too.
$('#GuarantorApplication_landline_number').on( 'blur', function() {
var field_value = $(this).val();
var elem = $(this);
var message_box = $(this).parent().prev();
field_value = removeWhiteSpace(field_value);
$(this).val(field_value);
message_box.html(' ');
if( field_value.length > 0 ) {
if( validateLandline(elem,field_value) ) { // validated OK.
validated = true;
} else {
validated = false;
}
} else {
validated = true; //auto validated, blank value is OK.
}
// run the validation before saving.
if( validated ) { // validated OK.
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_landline_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
}
});
}
return false;
});
$('#GuarantorApplication_user_security_question').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if(field_value != "") {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('security_question');
} else {
message_box.html('
Required field!');
message_box.next().addClass('has-error');
addToValidationSummary('security_question','Security question','required');
}
});
$('#GuarantorApplication_user_security_answer').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if(field_value != "") {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('security_answer');
} else {
message_box.html('
Required field!');
message_box.next().addClass('has-error');
addToValidationSummary('security_answer','Security answer','required');
}
});
$('#GuarantorApplication_marital_status').on( 'change', function(e) {
if($(this).val().length > 0) {
$('#dependants').fadeIn();
} else {
if($('#dependants').is(':visible')) {
$('#dependants').fadeOut();
}
}
e.preventDefault();
});
$('#dependants input').on( 'keyup', function() {
if($(this).val().length > 0) {
$('#home-phone').fadeIn(); // because home phone is not required, make the housing status appear too
$('#housing-status').fadeIn();
} else {
if($('#housing-status').is(':visible')) {
$('#home-phone').fadeOut();
$('#housing-status').fadeOut();
}
}
});
$('#GuarantorApplication_addresses_0_mortgage_cost').on( 'keyup', function() {
if($(this).val().length > 0) {
$('#other-outgoings').fadeIn();
} else {
if($('#other-outgoings').is(':visible')) {
$('#other-outgoings').fadeOut();
}
}
});
$('#GuarantorApplication_addresses_0_rent_cost').on( 'keyup', function() {
if($(this).val().length > 0) {
$('#other-outgoings').fadeIn();
} else {
if($('#other-outgoings').is(':visible')) {
$('#other-outgoings').fadeOut();
}
}
});
$('#other-outgoings input').on( 'keyup', function() {
if($(this).val().length > 0) {
$('#home-phone').fadeIn();
} else {
if($('#home-phone').is(':visible')) {
$('#home-phone').fadeOut();
}
}
});
// Housing status - mortgage/rent toggle - THIS IS FOR THE NEW FORM.
//$('#GuarantorApplication_addresses_0_housing_status').on( 'click', function() {
$('#GuarantorApplication_addresses_0_housing_status').on( 'change', function() {
//$('#GuarantorApplication_addresses_0_rent_cost').parents('.field').find('.message').html(' ');
//$('#GuarantorApplication_addresses_0_rent_cost, #GuarantorApplication_addresses_0_mortgage_cost').val('');
if ($(this).val() == '') {
$('#GuarantorApplication_addresses_0_rent_cost:visible').parents('.field').slideUp();
$('#GuarantorApplication_addresses_0_mortgage_cost:visible').parents('.field').slideUp();
}
else if ($(this).val() == 1) {
$('#GuarantorApplication_addresses_0_rent_cost:visible').parents('.field').slideUp();
$('#GuarantorApplication_addresses_0_mortgage_cost').parents('.field').slideDown();
}
else {
$('#GuarantorApplication_addresses_0_mortgage_cost:visible').parents('.field').slideUp();
$('#GuarantorApplication_addresses_0_rent_cost').parents('.field').slideDown();
}
if ($(this).val() == 7) {
$('#GuarantorApplication_addresses_0_rent_cost').parents('.field').find('.message').html('
For shared ownership only enter rental amount');
}
});
//});
if($('#guarantor-form-step-1').length > 0) {
if( $('#housing-status').is(":visible") ) {
$('#GuarantorApplication_addresses_0_housing_status').trigger('change');
if($('#GuarantorApplication_addresses_0_rent_cost').is(":visible") && $('#GuarantorApplication_addresses_0_rent_cost').val() != "") {
$('#GuarantorApplication_addresses_0_rent_cost').trigger('keyup');
} else if ($('#GuarantorApplication_addresses_0_mortgage_cost').is(":visible") && $('#GuarantorApplication_addresses_0_mortgage_cost').val() != "") {
$('#GuarantorApplication_addresses_0_mortgage_cost').trigger('keyup');
}
}
}
/** ADDRESS DETAILS **/
$('#GuarantorApplication_addresses_0_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#GuarantorApplication_addresses_0_address_building_number').parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_0_address_building_name').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_flat_number' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#GuarantorApplication_addresses_0_address_building_number').val() && !$('#GuarantorApplication_addresses_0_address_building_name').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
building_name_msg_box.html('
At least one of these is required');
$('#gt_flat_no_1-error').show();
$('#gt_building_no_1-error').show();
$('#gt_building_name_1-error').show();
} else {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
building_num_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(1);
} else {
if( $('#GuarantorApplication_addresses_0_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_0_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_0_address_building_number').val() && !$('#GuarantorApplication_addresses_0_address_building_name').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
building_name_msg_box.html('
At least one of these is required');
$('#gt_flat_no_1-error').show();
$('#gt_building_no_1-error').show();
$('#gt_building_name_1-error').show();
} else {
message_box.html(' ');
building_num_msg_box.html(' ');
building_name_msg_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_0_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var flat_msg_box = $('#GuarantorApplication_addresses_0_address_flat_number').parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_0_address_building_name').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_building_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
});
flat_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(1);
} else {
if( $('#GuarantorApplication_addresses_0_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_0_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_0_address_flat_number').val() && !$('#GuarantorApplication_addresses_0_address_building_name').val()) {
message_box.html('
At least one of these is required');
flat_msg_box.html('
At least one of these is required');
building_name_msg_box.html('
At least one of these is required');
$('#gt_flat_no_1-error').show();
$('#gt_building_no_1-error').show();
$('#gt_building_name_1-error').show();
} else {
message_box.html(' ');
flat_msg_box.html(' ');
building_name_msg_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_0_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var flat_msg_box = $('#GuarantorApplication_addresses_0_address_flat_number').parent().prev();
var building_num_msg_box = $('#GuarantorApplication_addresses_0_address_building_number').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_building_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
});
// clear the warning messages out of the other fields
flat_msg_box.html(" ");
building_num_msg_box.html(" ");
checkGuarantorAddressFields(1);
} else {
if( $('#GuarantorApplication_addresses_0_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_0_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_0_address_building_number').val() && !$('#GuarantorApplication_addresses_0_address_flat_number').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
flat_msg_box.html('
At least one of these is required');
$('#gt_flat_no_1-error').show();
$('#gt_building_no_1-error').show();
$('#gt_building_name_1-error').show();
} else {
message_box.html(' ');
building_num_msg_box.html(' ');
flat_msg_box.html(' ');
$('#gt_flat_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_1-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_0_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_1-error')[0].style.setProperty('display','none','important');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_1-error')[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_1-error')[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_thouroughfare_1-error').show();
}
});
checkGuarantorAddressFields(1);
});
$('#GuarantorApplication_addresses_0_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_1-error')[0].style.setProperty('display','none','important');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_1-error')[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_1-error')[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_post_town_1-error').show();
}
});
checkGuarantorAddressFields(1);
});
$('#GuarantorApplication_addresses_0_address_county').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
});
checkGuarantorAddressFields(1);
}
});
$('#GuarantorApplication_addresses_0_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode' }
).done( function(response) {
if( response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('
Postcode is an invalid format!');
message_box.next().addClass('has-error');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_guarantor_postcode' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#GuarantorApplication_addresses_0_address_postcode').val(new_postcode);
}
});
checkGuarantorAddressFields(1);
});
$('#GuarantorApplication_addresses_0_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_0_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
if(field_value != "" && field_value_2 != "") {
checkGuarantorAddressHistoryValues(); // if the year value is zero, will most likely need to show previous address.
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, action: 'save_guarantor_address_lived_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress1();
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
if ($('#GuarantorApplication_addresses_1_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_1_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_1_address_lived_years').val() , value2: $('#GuarantorApplication_addresses_1_address_lived_months').val(), action: 'save_guarantor_address_lived_years', address_id: 2 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
if ($('#GuarantorApplication_addresses_2_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_2_address_lived_years').val() , value2: $('#GuarantorApplication_addresses_2_address_lived_months').val(), action: 'save_guarantor_address_lived_years', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
});
});
$('#GuarantorApplication_addresses_0_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_0_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
if (field_value != "" && field_value_2 != "") {
checkGuarantorAddressHistoryValues();
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, action: 'save_guarantor_address_lived_months' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress1();
ga('send','pageview','/v2/apply-guarantor/step-2');
ga('send','event','Application Form', 'Guarantor added address', 'Guarantor Application - Step 2');
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
if ($('#GuarantorApplication_addresses_1_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_1_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_1_address_lived_months').val() , value2: $('#GuarantorApplication_addresses_1_address_lived_years').val(), action: 'save_guarantor_address_lived_months', address_id: 2 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
if ($('#GuarantorApplication_addresses_2_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_2_address_lived_months').val() , value2: $('#GuarantorApplication_addresses_2_address_lived_years').val(), action: 'save_guarantor_address_lived_months', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
ga('send','pageview','/v2/apply-guarantor/step-2');
ga('send','event','Application Form', 'Guarantor added address', 'Guarantor Application - Step 2');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
});
});
/** ADDRESS 2 */
$('#GuarantorApplication_addresses_1_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#GuarantorApplication_addresses_1_address_building_number').parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_1_address_building_name').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_flat_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(" ");
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
});
building_num_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(2);
} else {
if( $('#GuarantorApplication_addresses_1_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_1_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_0_address_building_number').val() && !$('#GuarantorApplication_addresses_0_address_building_name').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
$('#gt_flat_no_2-error').show();
$('#gt_building_no_2-error').show();
$('#gt_building_name_2-error').show();
} else {
message_box.html(' ');
building_num_msg_box.html(' ');
building_num_msg_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_1_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var flat_num_msg_box = $('#GuarantorApplication_addresses_1_address_flat_number').parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_1_address_building_name').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_guarantor_building_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(" ");
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
});
flat_num_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(2);
} else {
if( $('#GuarantorApplication_addresses_1_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_1_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_1_address_flat_number').val() && !$('#GuarantorApplication_addresses_1_address_building_name').val()) {
message_box.html('
At least one of these is required');
flat_num_msg_box.html('
At least one of these is required');
building_name_msg_box.html('
At least one of these is required');
$('#gt_flat_no_2-error').show();
$('#gt_building_no_2-error').show();
$('#gt_building_name_2-error').show();
} else {
message_box.html(' ');
flat_num_msg_box.html(' ');
building_name_msg_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_1_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var flat_num_msg_box = $('#GuarantorApplication_addresses_1_address_flat_number').parent().prev();
var building_num_msg_box = $('#GuarantorApplication_addresses_1_address_building_number').parent().prev();
if( field_value.length > 0 ) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_guarantor_building_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(" ");
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
});
flat_num_msg_box.html(" ");
building_num_msg_box.html(" ");
checkGuarantorAddressFields(2);
} else {
if( $('#GuarantorApplication_addresses_1_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_1_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_1_address_building_number').val() && !$('#GuarantorApplication_addresses_1_address_flat_number').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
flat_num_msg_box.html('
At least one of these is required');
$('#gt_flat_no_2-error').show();
$('#gt_building_no_2-error').show();
$('#gt_building_name_2-error').show();
} else {
message_box.html(' ');
building_num_msg_box.html(' ');
flat_num_msg_box.html(' ');
$('#gt_flat_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_2-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_1_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_guarantor_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_thouroughfare_2-error').show();
}
});
checkGuarantorAddressFields(2);
});
$('#GuarantorApplication_addresses_1_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_guarantor_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
('#gt_post_town_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
('#gt_post_town_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
('#gt_post_town_2-error').show();
}
});
checkGuarantorAddressFields(2);
});
$('#GuarantorApplication_addresses_1_address_county').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, action: 'save_guarantor_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(" ");
}
});
checkGuarantorAddressFields(2);
}
});
$('#GuarantorApplication_addresses_1_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode', address_id:2}
).done( function(response) {
if( response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('
Postcode is an invalid format!');
message_box.next().addClass('has-error');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_guarantor_postcode', address_id:2}
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_postcode_2-error span').html(' This field is required!');
$('#gt_postcode_2-error').show();
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#GuarantorApplication_addresses_1_address_postcode').val(new_postcode);
}
});
checkGuarantorAddressFields(2);
});
$('#GuarantorApplication_addresses_1_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_1_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
if(field_value != "" && field_value_2 != "") {
checkGuarantorAddressHistoryValues();
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, address_id: 2, value2: field_value_2, action: 'save_guarantor_address_lived_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress2();
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
if ($('#GuarantorApplication_addresses_2_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_2_address_lived_years').val() , value2: $('#GuarantorApplication_addresses_2_address_lived_months').val(), action: 'save_guarantor_address_lived_years', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
});
});
$('#GuarantorApplication_addresses_1_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_1_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
if(field_value != "" && field_value_2 != "") {
checkGuarantorAddressHistoryValues();
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, address_id: 2, value2: field_value_2, action: 'save_guarantor_address_lived_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress2();
}
} else if (response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if (response == 'success') {
if (!field_value_2) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
if ($('#GuarantorApplication_addresses_2_address_lived_years').val() != "" && $('#GuarantorApplication_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#GuarantorApplication_addresses_2_address_lived_months').val() , value2: $('#GuarantorApplication_addresses_2_address_lived_years').val(), action: 'save_guarantor_address_lived_months', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if (response == 'nochange') {
if (!field_value_2) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
});
});
/** ADDRESS 3 **/
$('#GuarantorApplication_addresses_2_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_2_address_building_name').parent().prev();
var building_num_msg_box = $('#GuarantorApplication_addresses_2_address_building_number').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_flat_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
});
building_num_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(3);
} else {
if( $('#GuarantorApplication_addresses_2_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_2_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_2_address_building_number').val() && !$('#GuarantorApplication_addresses_2_address_building_name').val()) {
message_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
building_num_msg_box.html('
At least one of these is required');
$('#gt_flat_no_3-error').show();
$('#gt_building_no_3-error').show();
$('#gt_building_name_3-error').show();
} else {
message_box.html(' ');
building_num_msg_box.html(' ');
building_num_msg_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_2_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var building_name_msg_box = $('#GuarantorApplication_addresses_2_address_building_name').parent().prev();
var flat_num_msg_box = $('#GuarantorApplication_addresses_2_address_flat_number').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_building_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
});
flat_num_msg_box.html(" ");
building_name_msg_box.html(" ");
checkGuarantorAddressFields(3);
} else {
if( $('#GuarantorApplication_addresses_2_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_2_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_2_address_flat_number').val() && !$('#GuarantorApplication_addresses_2_address_building_name').val()) {
message_box.html('
At least one of these is required');
flat_num_msg_box.html('
At least one of these is required');
building_name_msg_box.html('
At least one of these is required');
$('#gt_flat_no_3-error').show();
$('#gt_building_no_3-error').show();
$('#gt_building_name_3-error').show();
} else {
message_box.html(' ');
flat_num_msg_box.html(' ');
building_name_msg_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_2_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var building_number_msg_box = $('#GuarantorApplication_addresses_2_address_building_number').parent().prev();
var flat_num_msg_box = $('#GuarantorApplication_addresses_2_address_flat_number').parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_building_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
} else {
message_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
});
flat_num_msg_box.html(" ");
building_number_msg_box.html(" ");
checkGuarantorAddressFields(3);
} else {
if( $('#GuarantorApplication_addresses_2_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
if( $('#GuarantorApplication_addresses_2_address_building_number').val() == "") {
building_number_msg_box.html(" ");
}
if (!$('#GuarantorApplication_addresses_2_address_flat_number').val() && !$('#GuarantorApplication_addresses_2_address_building_number').val()) {
message_box.html('
At least one of these is required');
flat_num_msg_box.html('
At least one of these is required');
building_number_msg_box.html('
At least one of these is required');
$('#gt_flat_no_3-error').show();
$('#gt_building_no_3-error').show();
$('#gt_building_name_3-error').show();
} else {
message_box.html(' ');
flat_num_msg_box.html(' ');
building_number_msg_box.html(' ');
$('#gt_flat_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_no_3-error')[0].style.setProperty("display","none","important");
$('#gt_building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
$('#GuarantorApplication_addresses_2_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_thouroughfare_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_thouroughfare_3-error').show();
}
});
checkGuarantorAddressFields(3);
});
$('#GuarantorApplication_addresses_2_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_post_town_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_post_town_3-error').show();
}
});
checkGuarantorAddressFields(3);
});
$('#GuarantorApplication_addresses_2_address_county').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, action: 'save_guarantor_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
});
checkGuarantorAddressFields(3);
}
});
$('#GuarantorApplication_addresses_2_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode', address_id:3 }
).done( function(response) {
if( response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('
Postcode is an invalid format!');
message_box.next().addClass('has-error');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_guarantor_postcode', address_id:3 }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_postcode_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_postcode_3-error').show();
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#GuarantorApplication_addresses_2_address_postcode').val(new_postcode);
}
});
checkGuarantorAddressFields(3);
});
$('#GuarantorApplication_addresses_2_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_2_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, address_id: 3, action: 'save_guarantor_address_lived_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress3();
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
});
});
$('#GuarantorApplication_addresses_2_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_addresses_2_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, address_id: 3, action: 'save_guarantor_address_lived_months' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
saveAddress3();
$('#employment-detail').show();
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment-detail').show();
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
$('#employment-detail').show();
}
}
});
});
if($('#address-1').is(":visible")) {
if($('#address-1-lived select').val() != "") {
$('#address-1-lived select').trigger('change');
}
}
if($('#address-2').is(":visible")) {
if($('#address-2-lived select').val() != "") {
$('#address-2-lived select').trigger('change');
}
}
if($('#address-3').is(":visible")) {
if($('#address-3-lived select').val() != "") {
$('#address-3-lived select').trigger('change');
}
}
/** EMPLOYMENT DETAILS **/
$('#GuarantorApplication_employments_0_employment_status').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var is_ok = false;
var show_unemployed = false;
var clear_down = true; // this determines whether or not to clear the existing values. Needed for triggering.
$('#GuarantorApplication_employments_3_employment_status').val(field_value); // unemployment value should match
message_box.html(' ');
// make sure the user has not chosen "unemployed". Throw a warning and don't show the employer details.
if( field_value == 4) {
message_box.html('
Sorry, you must have a regular income to be a guarantor');
message_box.next().addClass('has-error');
$('#gt_employment_status-error span').html(" You must have a regular income to apply for a loan");
$('#gt_employment_status-error i').removeClass('fa-chevron-up').addClass('fa-warning');
$('#gt_employment_status-error').show();
is_ok = false;
$('#employer-1').hide();
$('#employer-2').hide();
$('#employer-3').hide();
$('#employer-unemployed').hide();
// just in case they've decided to change their employment status after they filled everything in, hide everything subsequent sections
$('#bank-details').hide();
$('#guarantor-details').hide();
$('#terms-validation').hide();
} else {
// check the status chosen in order to determine which part of the form to show.
if( field_value >= 5 && field_value <= 8 ) { // these are what are referred to as "unemployed" statuses but acceptable
show_unemployed = true;
$('#employer-1').hide();
$('#employer-2').hide();
$('#employer-3').hide();
} else {
$('#employer-unemployed').hide();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_employment_status' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_employment_status-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
is_ok = true;
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
$('#gt_employment_status-error span').html(" This field is required!");
$('#gt_employment_status-error i').removeClass('fa-warning').addClass('fa-chevron-up');
$('#gt_employment_status-error').show();
is_ok = false;
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_employment_status-error')[0].style.setProperty("display","none","important");
is_ok = true;
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_employment_status-error')[0].style.setProperty("display","none","important");
is_ok = true;
clear_down = false;
}
if(is_ok) {
if( show_unemployed ) {
$('#employer-unemployed').slideDown();
} else {
$('#employer-1').slideDown();
}
} else {
if($('#employer-1').is(":visible")) {
$('#employer-1').hide();
}
if($('#employer-unemployed').is(":visible")) {
$('#employer-unemployed').hide();
}
}
if (clear_down == true) {
// clear down the fields so the trigger can work.
$('#GuarantorApplication_unemployed_income_source').val('');
$('#GuarantorApplication_unemployed_net_income').val('');
$('#GuarantorApplication_unemployed_employment_pay_frequency').val('');
// add the bouncing arrow to the now empty fields.
var message_box_1 = $('#GuarantorApplication_unemployed_income_source').parent().prev();
var message_box_2 = $('#GuarantorApplication_unemployed_net_income').parent().parent().prev();
var message_box_3 = $('#GuarantorApplication_unemployed_employment_pay_frequency').parent().prev();
message_box_1.html('
Required field');
message_box_2.html('
Required field');
message_box_3.html('
Required field');
// hide the bank details section until the new values have been filled.
$('#bank-details').hide();
}
if (!show_unemployed) { // If the user selects an "unemployed" status, no checks are necessary at this point.
checkEmployment(1);
}
});
}
});
/** DETAILS FOR 'UNEMPLOYED' STATUS CHOICES **/
$('#GuarantorApplication_unemployed_income_source').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var employment_status_val = $('#GuarantorApplication_employments_0_employment_status').val();
var mobile_message_box = $('#gt_income_source-error');
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{value: field_value, action: 'save_unemployed_income_source', person_type: 'guarantor'}
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('
Required!');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty("display","none","important");
}
});
//check if the previous fields are populated before showing the next section.
if (checkGuarantorUnemployedFields()) {
if($('#bank-details').not(":visible")) { // only slide it down if it's hidden
$('#bank-details').slideDown();
}
} else {
$('#bank-details').hide();
}
}
});
$('#GuarantorApplication_unemployed_net_income').on( 'keyup', function() {
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
var employment_status_val = $('#GuarantorApplication_employments_0_employment_status').val();
var mobile_message_box = $('#gt_monthly_income-error');
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{value: field_value, action: 'save_unemployed_net_income', person_type: 'guarantor'}
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
//check if the previous fields are populated before showing the next section.
if (checkGuarantorUnemployedFields()) {
if ($('#bank-details').not(":visible")) { // only slide it down if it's hidden
$('#bank-details').slideDown();
}
} else {
$('#bank-details').hide();
}
}
});
$('#GuarantorApplication_unemployed_employment_pay_frequency').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var employment_status_val = $('#GuarantorApplication_employments_0_employment_status').val();
var mobile_message_box = $('#gt_pay_frequency-error');
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{value: field_value, action: 'save_unemployed_pay_frequency', person_type: 'guarantor'}
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
//check if the previous fields are populated before showing the next section.
if (checkGuarantorUnemployedFields()) {
if ($('#bank-details').not(":visible")) { // only slide it down if it's hidden
$('#bank-details').slideDown();
}
} else {
$('#bank-details').hide();
}
}
});
/** INDIVIDUAL EMPLOYMENT FIELDS **/
$('#GuarantorApplication_employments_0_employer_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employer_name_1-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employer_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
mobile_message_box.show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employment_type').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_type_1-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employment_role').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_role_1-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employer_telephone').on( 'blur', function() {
var field_value = $(this).val();
var elem = $(this);
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employer_telephone_1-error');
field_value = removeWhiteSpace(field_value);
$(this).val(field_value);
message_box.html(' ');
if (validateLandline(elem,field_value)) { // validated OK.
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employer_telephone' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
}
});
$('#GuarantorApplication_employments_0_employer_telephone_ext').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employer_telephone_ext' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_net_income').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
var mobile_message_box = $('#gt_net_income_1-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_net_income' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employment_pay_frequency').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_pay_frequency_1-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', action: 'save_employment_pay_frequency' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_0_employment_months').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', action: 'save_employment_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
checkEmployment(1);
});
});
$('#GuarantorApplication_employments_0_employment_months').on( 'change', function() {
//console.log('changed GuarantorApplication_employments_0_employment_months');
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_0_employment_years').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', action: 'save_employment_months' }
).done( function(response) {
//console.log('response was ' + response);
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
ga('send','pageview','/v2/apply-guarantor/step-3');
ga('send','event','Application Form', 'Guarantor added employment details', 'Guarantor Application - Step 3');
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
ga('send','pageview','/v2/apply-guarantor/step-3');
ga('send','event','Application Form', 'Guarantor added employment details', 'Guarantor Application - Step 3');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
checkEmployment(1);
});
});
/** INDIVIDUAL EMPLOYMENT (2) FIELDS **/
$('#GuarantorApplication_employments_1_employer_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employer_name_2-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 2, action: 'save_employer_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(2);
});
});
$('#GuarantorApplication_employments_1_employment_type').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_type_2-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 2, action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(2);
});
});
$('#GuarantorApplication_employments_1_employment_role').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_role_2-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 2, action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(2);
});
});
$('#GuarantorApplication_employments_1_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_1_employment_months').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', employment_id: 2, action: 'save_employment_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
}
} else if( response == 'noval') {
message_box.next().addClass('has-error');
message_box.html('
Required!');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
checkEmployment(2);
});
});
$('#GuarantorApplication_employments_1_employment_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_1_employment_years').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', employment_id: 2, action: 'save_employment_months' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
}
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if( response == 'success') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if( response == 'nochange') {
if( !field_value_2 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
checkEmployment(2);
});
});
/** INDIVIDUAL EMPLOYMENT (3) FIELDS **/
$('#GuarantorApplication_employments_2_employer_name').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employer_name_3-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 3, action: 'save_employer_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(3);
});
});
$('#GuarantorApplication_employments_2_employment_type').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_type_3-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 3, action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(3);
});
});
$('#GuarantorApplication_employments_2_employment_role').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#gt_employment_role_3-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, person_type: 'guarantor', employment_id: 3, action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
}
checkEmployment(3);
});
});
$('#GuarantorApplication_employments_2_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_2_employment_months').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', employment_id: 3, action: 'save_employment_years' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
}
} else if (response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('
Please select months');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if (response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
checkEmployment(3);
});
});
$('#GuarantorApplication_employments_2_employment_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#GuarantorApplication_employments_2_employment_years').val();
var message_box = $(this).parent().parent().prev();
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, person_type: 'guarantor', employment_id: 3, action: 'save_employment_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
}
} else if (response == 'noval') {
message_box.html('
Required!');
message_box.next().addClass('has-error');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('
Please select years');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if (response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
checkEmployment(3);
});
});
if ($('#GuarantorApplication_employments_0_employment_status').length > 0 && $('#GuarantorApplication_employments_0_employment_status').prop("selectedIndex") != "") {
$('#employer-1').slideDown();
}
/** BANK DETAILS UPDATE SERVICES **/
$('.sort-code-fields input').on( 'blur', function() {
var first = $('#GuarantorApplication_bank_identifier').val();
var second = $('#GuarantorApplication_internal_identifier_first').val();
var third = $('#GuarantorApplication_internal_identifier_second').val();
var message_box = $('.sort-code-fields').parent().prev();
var first_len = (''+first).length;
var second_len = (''+second).length;
var third_len = (''+third).length;
if(first_len == 2 && second_len == 2 && third_len == 2 && $.isNumeric(first) && $.isNumeric(second) && $.isNumeric(third)) {
message_box.html(' ');
var field_value = first+second+third;
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_guarantor_sort_code' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_sortcode-error')[0].style.setProperty("display","none","important");
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_sortcode-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_sortcode-error')[0].style.setProperty("display","none","important");
}
});
} else {
if ((first_len > 0 && !$.isNumeric(first)) || (second_len > 0 && !$.isNumeric(second)) || (third_len > 0 && !$.isNumeric(third))) {
message_box.html('
Sort code must be numeric!');
message_box.next().addClass('has-error');
$('#gt_sortcode-error span').html(' Sort code must be numeric!');
$('#gt_sortcode-error').show();
} else {
message_box.html('
Sort code must be 6 digits');
message_box.next().addClass('has-error');
$('#gt_sortcode-error span').html(' Sort code must be 6 digits');
$('#gt_sortcode-error').show();
}
return false;
}
});
$('#GuarantorApplication_bank_account_number').on( 'keyup', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
// get sort code data
var sc_first = $('#GuarantorApplication_bank_identifier').val();
var sc_second = $('#GuarantorApplication_internal_identifier_first').val();
var sc_third = $('#GuarantorApplication_internal_identifier_second').val();
var sort_code = sc_first+sc_second+sc_third;
if(field_value.length > 0) { // only run these error checks if there's at least 1 digit here.
// has the user entered an alpha character?
if(!$.isNumeric(field_value)) {
message_box.html('
Account number must be numeric!');
$('#gt_bank_account-error span').html(' Account number must be numeric!');
$('#gt_bank_account-error').show();
message_box.next().addClass('has-error');
return false;
}
if (field_value.length == 8) { // 8 digits only
message_box.html(' ');
$.post(getAJAXUrl(),
{value: field_value, action: 'save_guarantor_account_number'}
).done(function (response) {
if (response == 'new') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_bank_account-error')[0].style.setProperty("display", "none", "important");
} else if (response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_bank_account-error')[0].style.setProperty("display", "none", "important");
} else if (response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#gt_bank_account-error')[0].style.setProperty("display", "none", "important");
}
if( checkBankSortCode(sort_code) ) {
$('#terms-validation').show();
}
});
} else {
message_box.html('
Account number needs to be 8 digits');
message_box.next().addClass('has-error');
$('#gt_bank_account-error span').html(' Account number needs to be 8 digits');
$('#gt_bank_account-error').show();
if ($('#terms-validation').is(":visible")) {
$('#terms-validation').hide();
}
}
}
return false;
});
$('#GuarantorApplication_bank_account_number').on('blur', function() {
var message_box = $(this).parent().prev();
var mobile_message_box_span = $('#gt_bank_account-error span');
var mobile_message_box = $('#gt_bank_account-error');
if($(this).val() == "") {
message_box.html('
This field is required!');
message_box.next().addClass('has-error');
mobile_message_box_span.html(' This field is required!');
mobile_message_box.show();
} else {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
/** TERMS & CONDITIONS SECTION **/
$('#GuarantorApplication_final_terms_conditions_accepted').on('change', function() {
resolveGuarantorMobilePhoneFields();
if($(this).val() == 1) {
$.post(getAJAXUrl(),
{ accepted: 1, action: 'save_guarantor_terms_conditions' }
).done( function(response) {
if(response == 'OK') {
// all agreed, so show verification section
if( $('#validation-section').not(":visible")) {
$('#validation-section').show();
}
}
}
);
$('#verify-message').html('
Required field');
} else {
// if, for some weird reason, the customer has unchecked the terms checkbox, make sure to nullify the entry.
$.post(getAJAXUrl(),
{ accepted: 0, action: 'save_guarantor_terms_conditions' }
).done( function(response) {
if(response == 'OK') {
// for some reason, decided not to accept? Close the validation section
if( $('#validation-section').is(":visible")) {
$('#validation-section').hide();
}
}
}
);
$('#verify-message').html(' ');
}
});
$('#GuarantorApplication_SmsRequests_0_validation_code').val('');
$('#GuarantorApplication_SmsRequests_0_validation_code').on('keyup', function() {
$('#validation-error').html('');
var code_length = $(this).val().length;
if( code_length == 4 ) { //the correct length for a validation code.
$('#GuarantorApplication_save').removeAttr('disabled').removeClass('btn-disabled').addClass('btn-primary');
$('#verify-message').html(' ');
} else {
$('#GuarantorApplication_save').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
$('#verify-message').html('
Must be 4 digits');
}
});
//$('#GuarantorApplication_SmsRequests_0_validation_code').attr('disabled','disabled');
$('#GuarantorApplication_save').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
//if($('#GuarantorApplication_final_terms_conditions_accepted').is(":checked")) {
// $('#GuarantorApplication_SmsRequests_0_validation_code').removeAttr('disabled');
//}
$('#GuarantorApplication_bank_account_number').trigger('keyup');
$('#GuarantorApplication_SmsRequests_0_validation_code').trigger('keyup'); // to check if sms code has been entered on reload
$('#GuarantorApplication_save').on( 'click', function(e) {
$(this).attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
var entered_code = $('#GuarantorApplication_SmsRequests_0_validation_code').val();
if( !entered_code ) { return false; } // this accounts for iPhones if the user does not click Done after entering the code
var error_box = $('#validation-error');
var message_box = $(this).next();
message_box.html('
Verifying mobile code...');
$.post(getAJAXUrl(),
{ code: entered_code, action: 'check_verification_code', person_type: 'guarantor' }
).done( function(response) {
if (response == "limit_reached") { // more than 5 SMS codes sent
error_box.html('
You have already reached your maximum verification code attempts. Please contact us.');
message_box.html('');
} else if(response == "incorrect") { // code does not match the db
error_box.html('
The verification code you entered is not valid. Please try again or request a new one.');
message_box.html('');
} else if(response == "OK") {
// add a loader to let the user know it's doing something!
message_box.html('
Redirecting to WorldPay, please wait a moment...');
$('#guarantor-form-step-1').submit(); // submit the form
}
});
e.preventDefault();
});
$('#GuarantorApplication_send_sms_verification_code_submit').on( 'click', function(e) {
var message_box = $('.new_mobile_error');
var mobile_num = $('#GuarantorApplication_new_mobile').val(); // this is now the mobile number to send the sms to
mobile_num = mobile_num.replace('+44','0'); // remove the +44 and replace with a zero. For some reason, sms will only send this way
// do some basic checks first.
var validation = validateMobile(message_box,mobile_num);
if( validation ) {
// do a dupe check as well
$.post(getAJAXUrl(),
{ number: mobile_num, action: 'check_mobile_dupe', person_type: 'guarantor'}
).done( function(response) {
message_box.css('margin','12px 0 10px 2px');
if (response == 1) {
message_box.html('
It looks like this mobile number may already be attached to an account. Please use an alternative or contact us');
return false;
} else if (response == 'invalid') {
message_box.html('
Invalid mobile number!');
} else {
$.post(getAJAXUrl(),
{ person_type: 'guarantor', mobile_number: mobile_num, action: 'resend_verification_code' }
).done( function(response) {
if(response == 'OK') {
message_box.html('
New verification code sent to '+mobile_num+'');
} else if( response == 'noval') {
message_box.html('
Please enter a mobile number!');
} else if( response == 'invalid') {
message_box.html('
This mobile number could not be validated. Please call us on 01225 941 941.');
} else {
message_box.html('
Sorry! An error occurred. Please call 01225 941 941 and we will try and resolve the issue.');
}
});
}
});
}
e.preventDefault();
});
});
}
function removeWhiteSpace(string) {
return string.replace(/\s+/g, '');
}
//if( window.location.pathname.indexOf('apply') >= 0 ) { // if we are on the new form, implement this js
if ($('.new-form-apply').length > 0 || $('.new-form-guarantor').length > 0) {
if($('.new-form-apply').length > 0) {
ga('send','pageview','/v2/apply');
ga('send','event','Application Form', 'started', 'LoanApplication');
} else {
ga('send','pageview','/v2/apply-guarantor');
ga('send','event','Application Form', 'started', 'GuarantorApplication');
}
/**
* Use FOSJsRouting bundle to get the right route
* @returns {string}
*/
function getAJAXUrl() {
return Routing.generate('access_new_loan_application_ajax', {}, true);
}
function capitaliseInput(value) {
return value.charAt(0).toUpperCase()+value.slice(1);
}
/** VALIDATION FUNCTIONS **/
function deparam(query) {
var pairs, i, keyValuePair, key, value, map = {};
if (query.slice(0, 1) === '?') {
query = query.slice(1);
}
if (query !== '') {
pairs = query.split('&');
for (i = 0; i < pairs.length; i += 1) {
keyValuePair = pairs[i].split('=');
key = decodeURIComponent(keyValuePair[0]);
key = key.replace('LoanApplicationStepOne[','');
value = (keyValuePair.length > 1) ? decodeURIComponent(keyValuePair[1]) : undefined;
map[key] = value;
}
}
return map;
}
function checkNumber(value) {
var reg = new RegExp('^\\d+$');
if (!value) {
return false;
}
return reg.test(value);
}
function validateEmail(email) {
// Basic regex (this is checked properly in php later)
regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
if (!regex.test(email)) {
return false;
} else {
return true;
}
}
function validateMobile(elem,num,type) {
type = typeof type !== 'undefined' ? type : 'applicant';
if (isNaN(num) || num.indexOf(" ") != -1) {
if( elem != null ) {
elem.html('
Must be a number with no spaces');
if( type == 'guarantor') {
$('#guarantor_mobile-error span').html(' Must be a valid number');
$('#guarantor_mobile-error').show();
} else if( type == 'new_guarantor') {
$('#new_gt_mobile_number-error span').html(' Must be a valid number');
$('#new_gt_mobile_number-error').show();
} else {
$('#mobile-error span').html(' Must be a valid number');
$('#mobile-error').show();
}
elem.next().addClass('has-error');
addToValidationSummary('mobile','Mobile number','invalid');
}
return false;
}
if (num.length > 14 || num.length < 10) {
if( elem != null ) {
elem.html('
Mobile number needs to be 11 or 12 digits');
// add the mobile error
if( type == 'guarantor') {
$('#guarantor_mobile-error span').html(' Mobile number needs to be 11 or 12 digits');
$('#guarantor_mobile-error').show();
} else if( type == 'new_guarantor') {
$('#new_gt_mobile_number-error span').html(' Mobile number needs to be 11 or 12 digits');
$('#new_gt_mobile_number-error').show();
} else {
$('#mobile-error span').html(' Mobile number needs to be 11 or 12 digits');
$('#mobile-error').show();
}
elem.next().addClass('has-error');
addToValidationSummary('mobile','Mobile number','invalid');
}
return false;
}
// if ((num.charAt(0) == '0' && num.charAt(1) == '7') || (num.charAt(0) == '4' && num.charAt(1) == '4') || num.charAt(0) == '+'){
// if( elem != null ) {
// elem.html(' ');
// }
// } else {
// if( elem != null ) {
// elem.html('
Mobile number needs to start with 07 or 44');
// }
// return false;
// }
// if it gets here, everything is OK.
return true;
}
function validateLandline(elem,num) {
var elemname = elem[0].id;
if( elemname == 'LoanApplicationStepOne_landline_number') {
var message_span = $('#home_phone-error span');
var message_box = $('#home_phone-error');
} else if( elemname == 'GuarantorApplication_landline_number') {
var message_span = $('#gt_home_phone-error span');
var message_box = $('#gt_home_phone-error');
} else if( elemname == 'LoanApplicationStepOne_employments_0_employer_telephone') {
var message_span = $('#employer_telephone_1-error span');
var message_box = $('#employer_telephone_1-error');
} else if( elemname == 'GuarantorApplication_employments_0_employer_telephone') {
var message_span = $('#gt_employer_telephone_1-error span');
var message_box = $('#gt_employer_telephone_1-error');
} else {
return true; // only the above boxes require landline validation, so if it's none of those, we shouldn't be here.
}
message_box.removeClass('hidden');
if (isNaN(num) || num.indexOf(" ")!= -1){
elem.parent().prev().html('
Must be a number with no spaces');
message_span.html(' Must be a valid number');
message_box.show();
elem.parent().addClass('has-error');
return false;
}
if (num.length > 12 || num.length < 10 ) {
elem.parent().prev().html('
Phone number should be between 10 and 12 digits');
message_span.html(' Phone number should be between 10 and 12 digits');
message_box.show();
elem.parent().addClass('has-error');
return false;
}
if ((num.charAt(0) == '0') || (num.charAt(0) == '4' && num.charAt(1) == '4')){
elem.parent().prev().html(' ');
} else {
elem.parent().prev().html('
Phone number needs to start with 0 or 44');
message_span.html(' Phone number needs to start with 0 or 44');
message_box.show();
elem.parent().addClass('has-error');
return false;
}
elem.parent().removeClass('has-error');
message_box.css('display', 'none !important');
message_box.addClass('hidden');
return true;
}
function checkBankSortCode(sortcode) {
if (sortcode) {
var sortcode_length = (''+sortcode).length;
if( sortcode_length === 6 && $.isNumeric(sortcode)) {
return true;
}
}
return false;
}
function checkBankAccountNumber(account_number) {
if (account_number) {
var account_number_length = (''+account_number).length;
if( account_number_length === 8 && $.isNumeric(account_number)) {
return true;
}
}
return false;
}
var checkApplicantAddressHistoryValues = function() {
//console.log('checkApplicantAddressHistoryValues called');
var address2 = $('#address-2');
var address3 = $('#address-3');
var employmentDetail = $('#employment-detail');
var prefix = 'LoanApplicationStepOne';
var $a1y, $a1m, $a2y, $a2m, $a3y, $a3m, $a1total, $a2total;
$a1y = $('#'+prefix+'_addresses_0_address_lived_years');
$a1m = $('#'+prefix+'_addresses_0_address_lived_months');
$a2y = $('#'+prefix+'_addresses_1_address_lived_years');
$a2m = $('#'+prefix+'_addresses_1_address_lived_months');
$a3y = $('#'+prefix+'_addresses_2_address_lived_years');
$a3m = $('#'+prefix+'_addresses_2_address_lived_months');
if ($a1y.val() > 0 || $a1m.val() > 0) {
//console.log('line 217 if triggered');
$a1total = parseInt(calculateMonths($a1y, $a1m));
$a2total = parseInt(calculateMonths($a2y, $a2m));
if ($a1total !== false && $a1total < 36) {
if (address2.not(':visible')) {
address2.show();
}
employmentDetail.hide();
if (!isNaN($a2total) && $a2total > 0) {
if ($a2total !== false && ($a1total + $a2total) < 36) {
if (address3.not(':visible')) {
address3.show();
}
// 3rd and final address history row - as long as it's filled in, show the employment section
if ($a3y.val() > 0 || $a3m.val() > 0) {
employmentDetail.show();
} else {
employmentDetail.hide();
}
} else {
address3.hide();
employmentDetail.show();
}
}
} else {
address2.hide();
resetAddressFields(1);
address3.hide();
resetAddressFields(2);
employmentDetail.show(); // if no past addresses are required, then just make the employment section appear
}
}
};
/** ADDRESS SAVE & UPDATE - ADDRESS 1 **/
function saveAddress1() {
var prefix, person_type;
if ($('#LoanApplicationStepOne_addresses_0_address_flat_number').length > 0) { // we are dealing with an applicant
prefix = 'LoanApplicationStepOne';
person_type = 'applicant';
} else {
prefix = 'GuarantorApplication';
person_type = 'guarantor';
}
var a_flat_number = $('#'+prefix+'_addresses_0_address_flat_number').val();
var a_building_number = $('#'+prefix+'_addresses_0_address_building_number').val();
var a_building_name = $('#'+prefix+'_addresses_0_address_building_name').val();
var a_thouroughfare = $('#'+prefix+'_addresses_0_address_thouroughfare').val();
var a_post_town = $('#'+prefix+'_addresses_0_address_post_town').val();
var a_county = $('#'+prefix+'_addresses_0_address_county').val();
var a_postcode = $('#'+prefix+'_addresses_0_address_postcode').val();
var a_lived_years = $('#'+prefix+'_addresses_0_address_lived_years').val();
var a_lived_months = $('#'+prefix+'_addresses_0_address_lived_months').val();
if ((a_flat_number || a_building_number || a_building_name) && a_thouroughfare && a_post_town && a_postcode && a_lived_years && a_lived_months) {
var address_details = {
'address_flat_number':a_flat_number,
'address_building_number':a_building_number,
'address_building_name':a_building_name,
'address_thouroughfare':a_thouroughfare,
'address_post_town':a_post_town,
'address_county':a_county,
'address_postcode':a_postcode,
'address_lived_years':a_lived_years,
'address_lived_months':a_lived_months
};
saveAddress(1,address_details,person_type); // can save the address if all details present
var total_months = ((a_lived_years*12) + a_lived_months);
if (total_months > 36) { // means no other addresses are necessary, so show employment section.
$('#employment-detail').show();
}
}
return false;
}
/** ADDRESS SAVE & UPDATE - ADDRESS 2 **/
function saveAddress2() {
var prefix, person_type;
if($('#LoanApplicationStepOne_addresses_1_address_flat_number').length > 0) { // we are dealing with an applicant
prefix = 'LoanApplicationStepOne';
person_type = 'applicant';
} else {
prefix = 'GuarantorApplication';
person_type = 'guarantor';
}
var a_flat_number = $('#'+prefix+'_addresses_1_address_flat_number').val();
var a_building_number = $('#'+prefix+'_addresses_1_address_building_number').val();
var a_building_name = $('#'+prefix+'_addresses_1_address_building_name').val();
var a_thouroughfare = $('#'+prefix+'_addresses_1_address_thouroughfare').val();
var a_post_town = $('#'+prefix+'_addresses_1_address_post_town').val();
var a_county = $('#'+prefix+'_addresses_1_address_county').val();
var a_postcode = $('#'+prefix+'_addresses_1_address_postcode').val();
var a_lived_years = $('#'+prefix+'_addresses_1_address_lived_years').val();
var a_lived_months = $('#'+prefix+'_addresses_1_address_lived_months').val();
if ((a_flat_number || a_building_number || a_building_name) && a_thouroughfare && a_post_town && a_postcode && a_lived_years && a_lived_months) {
var address_details = {
'address_flat_number':a_flat_number,
'address_building_number':a_building_number,
'address_building_name':a_building_name,
'address_thouroughfare':a_thouroughfare,
'address_post_town':a_post_town,
'address_county':a_county,
'address_postcode':a_postcode,
'address_lived_years':a_lived_years,
'address_lived_months':a_lived_months
};
saveAddress(2,address_details,person_type);
var total_months = ( (a_lived_years*12) + a_lived_months );
if( total_months > 36 ) { // means no other addresses are necessary, so show employment section.
$('#employment-detail').show();
}
}
return false;
}
/** ADDRESS SAVE & UPDATE - ADDRESS 3 **/
function saveAddress3() {
var prefix, person_type;
if ($('#LoanApplicationStepOne_addresses_2_address_flat_number').length > 0) { // we are dealing with an applicant
prefix = 'LoanApplicationStepOne';
person_type = 'applicant';
} else {
prefix = 'GuarantorApplication';
person_type = 'guarantor';
}
var a_flat_number = $('#'+prefix+'_addresses_2_address_flat_number').val();
var a_building_number = $('#'+prefix+'_addresses_2_address_building_number').val();
var a_building_name = $('#'+prefix+'_addresses_2_address_building_name').val();
var a_thouroughfare = $('#'+prefix+'_addresses_2_address_thouroughfare').val();
var a_post_town = $('#'+prefix+'_addresses_2_address_post_town').val();
var a_county = $('#'+prefix+'_addresses_2_address_county').val();
var a_postcode = $('#'+prefix+'_addresses_2_address_postcode').val();
var a_lived_years = $('#'+prefix+'_addresses_2_address_lived_years').val();
var a_lived_months = $('#'+prefix+'_addresses_2_address_lived_months').val();
if ((a_flat_number || a_building_number || a_building_name) && a_thouroughfare && a_post_town && a_postcode && a_lived_years && a_lived_months) {
var address_details = {
'address_flat_number':a_flat_number,
'address_building_number':a_building_number,
'address_building_name':a_building_name,
'address_thouroughfare':a_thouroughfare,
'address_post_town':a_post_town,
'address_county':a_county,
'address_postcode':a_postcode,
'address_lived_years':a_lived_years,
'address_lived_months':a_lived_months
};
saveAddress(3,address_details,person_type);
// no more previous addresses are required so just show next section.
$('#employment-detail').show();
}
return false;
}
function checkEmploymentFields(employment_id) {
employment_id = employment_id - 1;
//console.log('checkEmploymentFields : ' + employment_id);
var prefix;
var validations = [];
if ($('#guarantor-form-step-1').length > 0) {
prefix = 'GuarantorApplication';
} else {
prefix = 'LoanApplicationStepOne';
}
if (isNaN(employment_id)) {
//console.log('no employment id???');
return false;
}
var requiredFields = {
1:prefix+'_employments_'+employment_id+'_employer_name',
2:prefix+'_employments_'+employment_id+'_employment_type',
3:prefix+'_employments_'+employment_id+'_employment_role',
4:prefix+'_employments_'+employment_id+'_employment_years',
5:prefix+'_employments_'+employment_id+'_employment_months',
6:prefix+'_employments_'+employment_id+'_net_income',
7:prefix+'_employments_'+employment_id+'_employment_pay_frequency',
8:prefix+'_employments_'+employment_id+'_employer_telephone'
};
$.each(requiredFields, function(i, field) {
if (employment_id != 0 && i > 5) {
//console.log('i above 5 and employment zero, push true');
validations.push([employment_id][i] = true);
} else {
if (i == 8) {
if ($( "#" + field ).val() != "" && validateLandline($('#'+field).parent().prev(),($( "#" + field ).val()))) {
//console.log('i = 8 push true');
validations.push([employment_id][i] = true);
} else {
//console.log('i = 8 push false');
hideBankDetails();
}
} else if ($("#" + field).val() == "") {
//console.log("#" + field + ' was empty, so this is false');
validations.push([employment_id][i] = false);
} else {
//console.log("#" + field + ' push true');
validations.push([employment_id][i] = true);
}
}
});
validations = filterArray(validations);
if ( ! validations instanceof Array) {
//console.log('validations was not an array return false');
hideBankDetails();
return false;
}
//console.log('validations length = '+ validations.length);
for (var x = 0; x < validations.length; x++) {
if (validations[x] === false) {
//console.log('validations['+x+'] = false 464');
hideBankDetails();
return false;
}
}
//console.log('validator returning true 470');
return true;
}
function filterArray(array) {
if (array.length === 0) {
return false;
}
for (var x = 0; x < array.length; x++) {
if (typeof array[x] === 'undefined') {
array.splice(x, 1);
}
}
return array;
}
function checkApplicantEmploymentFieldsMobile(employment_id) {
var employer_name = $('#LoanApplicationStepOne_employments_'+employment_id+'_employer_name');
var employment_type = $('#LoanApplicationStepOne_employments_'+employment_id+'_employment_type');
var employment_role = $('#LoanApplicationStepOne_employments_'+employment_id+'_employment_role');
var net_income = $('#LoanApplicationStepOne_employments_'+employment_id+'_net_income');
var pay_frequency = $('#LoanApplicationStepOne_employments_'+employment_id+'_employment_pay_frequency');
var employer_telephone = $('#LoanApplicationStepOne_employments_'+employment_id+'_employer_telephone');
var scrolltopoint = false;
if(!employer_name.val()) {
$('#employer_name_'+employment_id+'-error').show();
// scroll up to title.
scrolltopoint = employer_name;
}
if(!employment_type.val() ) {
$('#employment_type_'+employment_id+'-error').show();
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = employment_type;
}
}
if(!employment_role.val() ) {
$('#employment_role_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = employment_role;
}
}
if( employment_id == 0 ) {
if(!net_income.val() ) {
$('#net_income_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = net_income;
}
}
if(!pay_frequency.val() ) {
$('#pay_frequency_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = pay_frequency;
}
}
if(!employer_telephone.val() ) {
$('#employer_telephone_'+employment_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = employer_telephone;
}
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
$('.employment-mobile-overlay_'+employment_id)[0].style.setProperty("display","none","important");
}
}
//M.E. - Had to rename this function. There's another function in script.js which was causing
// the second employer to slideup when called on guarantor form.
function checkEmploymentHistoryValuesNew() {
// This method shows or hides the employment forms as required
var prefix, $e1y, $e1m, $e2y, $e2m, $e1total, $e2total;
if ($('#guarantor-form-step-1').length > 0) {
prefix = 'GuarantorApplication';
} else {
prefix = 'LoanApplicationStepOne';
}
var emp_status = $('#'+prefix+'_employments_0_employment_status').val();
if (emp_status >= 4 && emp_status <=8) {
return false;
}
$e1y = $('#'+prefix+'_employments_0_employment_years');
$e1m = $('#'+prefix+'_employments_0_employment_months');
$e2y = $('#'+prefix+'_employments_1_employment_years');
$e2m = $('#'+prefix+'_employments_1_employment_months');
$e1total = calculateMonths($e1y, $e1m);
$e2total = calculateMonths($e2y, $e2m);
var employer2 = $('#employer-2');
var employer3 = $('#employer-3');
// Is the first employment duration sufficient?
if ($e1total !== false && !isNaN($e1total) && $e1total < 12) {
if (employer2.not(":visible")) {
// No we need more data:
employer2.show();
}
// Is the second employment duration sufficient?
if ($e2total !== false && !isNaN($e2total) && ($e1total + $e2total) < 12) {
if (employer3.not(":visible")) {
// No we need more
employer3.show();
}
} else {
// Yes 2nd employment duration is sufficient:
employer3.hide();
}
} else {
// Yes first employment duration is sufficient:
employer2.hide();
employer3.hide();
}
}
function checkEmployment(employment_id) {
//console.log('calling checkEmployment with id ' + employment_id);
employment_id = (typeof(employment_id) == 'undefined' ? null : employment_id);
if( employment_id < 3 ) { // don't need to check history values if this is the final employer
// What fields should be visible?
checkEmploymentHistoryValuesNew();
}
// Now we know we're displaying the correct fields, let's check the values of what's visible
// Note: if we have an employment ID passed let's just check this employment
if (employment_id) {
if (checkEmploymentFields(employment_id)) {
// if this is the final employment, show the next section.
if(employment_id == 3) {
//console.log('showing because employment id = 3');
showBankDetails();
}
//return true;
} else {
return false;
}
}
var employment_validity = [];
var employment_count = 1;
var all_employments_valid = false;
if ($('#employer-2').is(":visible")) {
employment_count++;
//console.log('employment2 was visible, employer count now = ' + employment_count);
}
if ($('#employer-3').is(":visible")) {
employment_count++;
//console.log('employment3 was visible, employer count now = ' + employment_count);
}
//console.log('before run, employer count now = ' + employment_count);
hideBankDetails();
// Check each set of fields.
for (var i=0; i
0) {
return 'GuarantorApplication';
}
return 'LoanApplicationStepOne';
}
/** SAVING DETAILS FUNCTIONS **/
function getEmploymentData(employment_id) {
var prefix;
employment_id = employment_id - 1; // to match up with the collection id
if ($('#guarantor-form-step-1').length > 0) {
prefix = 'GuarantorApplication';
} else {
prefix = 'LoanApplicationStepOne';
}
if (!employment_id ) {
employment_id = 1;
}
var e_employer_name = $('#'+prefix+'_employments_'+employment_id+'_employer_name').val();
var e_employer_type = $('#'+prefix+'_employments_'+employment_id+'_employment_type').val();
var e_employment_role = $('#'+prefix+'_employments_'+employment_id+'_employment_role').val();
var e_employer_telephone = $('#'+prefix+'_employments_'+employment_id+'_employer_telephone').val();
var e_employer_telephone_ext = $('#'+prefix+'_employments_'+employment_id+'_employer_telephone_ext').val();
var e_net_income = $('#'+prefix+'_employments_'+employment_id+'_net_income').val();
var e_pay_frequency = $('#'+prefix+'_employments_'+employment_id+'_employment_pay_frequency').val();
var e_employment_years = $('#'+prefix+'_employments_'+employment_id+'_employment_years').val();
var e_employment_months = $('#'+prefix+'_employments_'+employment_id+'_employment_months').val();
return {
'employer_name':e_employer_name,
'employer_type':e_employer_type,
'employment_role':e_employment_role,
'employer_telephone':e_employer_telephone,
'employer_telephone_ext':e_employer_telephone_ext,
'net_income':e_net_income,
'pay_frequency':e_pay_frequency,
'employment_years':e_employment_years,
'employment_months':e_employment_months
};
}
function saveEmployment(employment_id,data) {
//console.log('calling saveEmployment with id: ' + employment_id);
var person_type;
if ($('#guarantor-form-step-1').length > 0) {
person_type = 'guarantor';
} else {
person_type = 'applicant';
}
// Before saving any data, make sure all required fields are passed.
if (checkEmployment(employment_id)) {
//console.log('posting');
$.post(getAJAXUrl(),
{ data: data, employment_id: employment_id, action: 'save_employment_details', person_type: person_type }
).done( function(response) {
//if (response == 'OK') {
// console.log('saveEmployment was ok, showing bank details');
// showBankDetails();
//}
});
} else {
//console.log('not posting');
}
}
function calculateMonths(years, months) {
if ($.isNumeric(years.val()) && $.isNumeric(months.val())) {
var years_as_months = parseInt(years.val()*12);
var existing_months = parseInt(months.val());
return parseInt( years_as_months + existing_months );
//29.09.14 - Made sure that the retured result is definitely a number by using parseInt and breaking it down (M.E.)
}
return false;
}
var saveAddress = function(address_id,data,person_type) {
//console.log('calling saveAddress');
//console.log('address id: ' + address_id);
//console.log('data: ' + data);
//console.log('person_type: ' + person_type);
if( !window.load ) {
return false;
}
if(address_id && data) {
$.post(getAJAXUrl(),
{ data: data, address_id: address_id, person_type: person_type, action: 'save_address_details' }
).done( function(response) {
if (response == 'OK') {
// check if we need to show previous address
if (address_id < 3) { // only need to check for current and 1st previous address
checkApplicantAddressHistoryValues();
}
}
});
}
};
var resetAddressFields = function(address_id) {
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_flat_number').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_number').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_name').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_thouroughfare').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_county').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_post_town').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_postcode').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_years').val('');
$('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_months').val('');
};
function addToValidationSummary(id,nice_name,type) {
var summary_list = $('#validation-summary ul li ul');
if( id && nice_name ) {
// before attempting to add to the list, find out if it already is in the list.
if( $('#'+id).length > 0 ) {
return false;
}
if( $('#validation-title ul').find('li').length == 0) { // if the title has gone because there were no errors before, put it back in
$('#validation-title').html('The following fields have errors:');
summary_list = $('#validation-summary ul li ul');
}
if( type == "required") {
summary_list.append(''+nice_name+' is required!');
} else {
summary_list.append(''+nice_name+' is invalid!');
}
}
}
function removeFromValidationSummary(id) {
if( id ) {
$('#'+id).remove();
// if there are no more invalid fields, remove the validation header title
if($('#validation-summary ul li ul').children().length == 0) {
$('#validation-title').html('');
}
}
}
$(document).ready( function() {
//console.log('cookies');
//console.log(document.cookie);
window.load = true;
var is_broker_lead = $('#broker_lead').val();
var route = '';
//assign action to the form
if($('#applicant-form-step-1').length > 0) { //we are on applicant form
route = Routing.generate('access_v2_loan_application_apply_full', {}, true);
$('#applicant-form-step-1').attr('action', route);
//$('#applicant-form-step-1').attr('action','/v2/apply');
} else { //gt form
route = Routing.generate('access_new_loan_application_guarantor_apply_full', {}, true);
$('#guarantor-form-step-1').attr('action', route);
//$('#guarantor-form-step-1').attr('action','/v2/apply-guarantor');
}
// if this is a broker lead, then some fields will already be filled in. Therefore we need to remove these from the validation summary first
if (is_broker_lead) {
$('#validation-summary li#mobile').remove();
$('#validation-summary li#email').remove();
$('#validation-summary li#dob').remove();
$('#validation-summary li#first_name').remove();
$('#validation-summary li#last_name').remove();
// title may or may not be selected
if($('#LoanApplicationStepOne_title').val() != "") {
$('#validation-summary li#title').remove();
}
}
if( $('#terms-validation').is(":visible") && ( $('#LoanApplicationStepOne_final_terms_conditions_accepted').val() == 1 || $('#GuarantorApplication_final_terms_conditions_accepted').val() == 1) ) {
$('#validation-section').show();
} else {
$('#validation-section').hide();
}
$('#request-link a').on('click', function(e) {
if($('#resend-info').is(":visible")) {
$('#resend-info').slideUp();
} else {
$('#resend-info').slideDown();
}
e.preventDefault();
});
// $('#applicant-form-step-1').on( 'submit', function(e) { // this will prevent reload of the page if the Go button is clicked on a mobile keypad
// if( $('#terms-validation').is(":visible") && $('#LoanApplicationStepOne_save').is(':enabled') ) {
// $('#LoanApplicationStepOne_save').trigger('click');
// }
// e.preventDefault();
// return false;
// });
// for desktop
$('body').on('keypress', function(e) {
var keyCode = (e.keyCode ? e.keyCode : e.which);
if(keyCode == 13 && checkRequiredFields() && $('#LoanApplicationStepOne_user_new_account_submit').is(":visible")) { // only action if all the required fields are filled
$('#LoanApplicationStepOne_user_new_account_submit').trigger('click');
return false;
} else if( keyCode == 13 && $('#LoanApplicationStepOne_save').is(":enabled")) {
$('#LoanApplicationStepOne_save').trigger("click");
return false;
}
});
// $('body').on('keypress', function(e) {
// var keyCode = (e.keyCode ? e.keyCode : e.which);
// if (keyCode == 13) {
// if ( checkRequiredFields() && $('#LoanApplicationStepOne_user_new_account_submit').is(":enabled") && $('#new-user').is(":visible")) {// only action if all the required fields are filled, and the button is visible
// $('#LoanApplicationStepOne_user_new_account_submit').trigger('click');
// return false; // make sure this only gets submitted once or it will try to create multiple accounts!
// } else if( $('#GuarantorApplication_password_new_account_submit').is(":enabled")) {
// $('#GuarantorApplication_password_new_account_submit').trigger('click');
// return false;
// } else if ( $('#terms-validation').is(":visible") && $('#LoanApplicationStepOne_save').is(':enabled') ) {
// $('#LoanApplicationStepOne_save').trigger('click');
// return false;
// } else if ( $('#terms-validation').is(":visible") && $('#GuarantorApplication_save').is(":enabled")) {
// $('#GuarantorApplication_save').trigger('click');
// return false;
// }
// }
// });
if ($('#LoanApplicationStepOne_dob_day').val() != "" &&
$('#LoanApplicationStepOne_dob_month').val() != "" &&
$('#LoanApplicationStepOne_dob_year').val() != "")
{
dobday = $('#LoanApplicationStepOne_dob_day').val();
dobmonth = $('#LoanApplicationStepOne_dob_month').val();
dobyear = $('#LoanApplicationStepOne_dob_year').val();
if( validateDOB(dobday,dobmonth,dobyear) ) {
$('#LoanApplicationStepOne_dob').parent().parent().removeClass('has-error');
$('#dob-error')[0].style.setProperty( 'display', 'none', 'important' );
}
}
// Got an email in the field? Fair chance we need to do some validating:
if ($('#LoanApplicationStepOne_email').val()) {
// we only need to do this check if the page has been reloaded and the dob is missing.
// If the applicant comes from the home page form, don't perform this at this point
if( !$('#from_homepage').val() ) {
reValidateDob();
// before going ahead and running the checkStepOneFields check, make sure the email field is not readonly.
// This is because we don't want to bother running this method when the user has already passed this
// point as the "Please click continue" message will keep appearing when it's not needed.
if (!$('#LoanApplicationStepOne_email').prop('readonly')) {
checkStepOneFields();
}
}
}
//if the form is being loading from a pre-saved app, make sure the new mobile field is filled.
if( $('#LoanApplicationStepOne_new_mobile').length > 0 && $('.your_number').length > 0 ) {
$('#LoanApplicationStepOne_new_mobile').val($('#LoanApplicationStepOne_mobile_number').val().replace('+44','0'));
$('.your_number').text($('#LoanApplicationStepOne_mobile_number').val());
}
//also trigger a blur on the name.
if( $('#LoanApplicationStepOne_first_name').length > 0 && $('#LoanApplicationStepOne_first_name').val() != "") {
$('#LoanApplicationStepOne_first_name').val(capitaliseInput($('#LoanApplicationStepOne_first_name').val()));
}
if( $('#LoanApplicationStepOne_surname').length && $('#LoanApplicationStepOne_surname').val() != "") {
$('#LoanApplicationStepOne_surname').val(capitaliseInput($('#LoanApplicationStepOne_surname').val()));
}
$('#LoanApplicationStepOne_addresses_0_address_lived_years').attr('disabled','disabled');
$('#LoanApplicationStepOne_addresses_0_address_lived_months').attr('disabled','disabled');
$('#LoanApplicationStepOne_addresses_1_address_lived_years').attr('disabled','disabled');
$('#LoanApplicationStepOne_addresses_1_address_lived_months').attr('disabled','disabled');
$('#LoanApplicationStepOne_addresses_2_address_lived_years').attr('disabled','disabled');
$('#LoanApplicationStepOne_addresses_2_address_lived_months').attr('disabled','disabled');
/** FURTHER VALIDATION FUNCTIONS **/
function checkEmail(email,formdata,message_box) {
if ($('#broker_lead').val()) {
message_box.html(' ');
return true;
}
var new_data = deparam(formdata);
//M.E. - added email to arguments, as it had not been passed to the ajax file, therefore email checks were always failing.
// Also added icons / messages to aid the user's journey.
$.post(getAJAXUrl(),
{LoanApplicationStepOne: new_data, email: email, email_type: 'applicant', action: 'check_email'}
).done( function(response) {
if (response == 'duplicate') {
message_box.html(' ');
$('.email-continue').hide();
$('.email-continue-mobile')[0].style.setProperty( 'display', 'none', 'important' );
$('#new-user').hide();
$('#existing-user-password').show();
$('html, body').animate({
scrollTop: parseInt($('#existing-user-password').offset().top-50)
}, 500);
} else if (response == 'ok') {
message_box.html(' ');
$('.email-continue').hide();
$('.email-continue-mobile')[0].style.setProperty( 'display', 'none', 'important' );
$('#existing-user-password').hide();
$('#new-user').show();
$('html, body').animate({
scrollTop: parseInt($('#new-user').offset().top-50)
}, 500);
} else {
// Invalid
message_box.html('Sorry, this email appears invalid');
$('.email-continue').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
$('.email-continue').show();
$('.email-continue-mobile').show();
$('#existing-user-password').hide();
$('#new-user').hide();
}
});
$('.email-continue').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
}
function checkGuarantorEmail(email,formdata,message_box) {
var new_data = deparam(formdata);
$.post(getAJAXUrl(),
{LoanApplicationStepOne: new_data, email: email, email_type: 'guarantor', action: 'check_email'}
).done( function(response) {
if (response == 'duplicate') {
message_box.html('There was a problem with this email address. Please contact us or use an alternative.');
$('#guarantor_email-error span').html(" There was a problem with this email. Please contact us or use an alternative.");
$('#guarantor_email-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
} else if (response == 'ok') {
$.post(getAJAXUrl(),
{ value: email, field_name: 'LoanApplicationStepOne_loan_application_guarantors_0_email', action: 'save_guarantor_email' }
).done(function(response) {
if (response == 'new') {
message_box.html(' ');
$('#guarantor_email-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
if (checkGuarantorRequiredFields()) {
if ($('#terms-validation').not(":visible")) {
$('#terms-validation').show();
}
}
} else if (response == 'noval') {
message_box.html('Required!');
$('#guarantor_email-error span').html(" This is a required field!");
$('#guarantor_email-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
} else if (response == 'success') {
message_box.html(' ');
$('#guarantor_email-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
if (checkGuarantorRequiredFields() ) {
if ($('#terms-validation').not(":visible")) {
$('#terms-validation').show();
}
}
} else if (response == 'nochange') {
message_box.html(' ');
$('#guarantor_email-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
if (checkGuarantorRequiredFields() ) {
if ($('#terms-validation').not(":visible")) {
$('#terms-validation').show();
}
}
}
});
} else {
// Invalid
message_box.html('Sorry, this email appears invalid');
$('#guarantor_email-error span').html(" Sorry, this email appears to be invalid");
$('#guarantor_email-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
}
});
}
function checkApplicantAddressFields(address_id) { // this function will check to see whether or not to enable the years/months lived boxes
//console.log('calling checkApplicantAddressFields ' +address_id );
var flat_no = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_flat_number').val();
var building_no = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_number').val();
var building_name = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_name').val();
var thouroughfare = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_thouroughfare').val();
var post_town = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_post_town').val();
var postcode = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_postcode').val();
var livedYears = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_years');
var livedMonths = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_months');
if(( flat_no || building_no || building_name ) && thouroughfare && post_town && postcode) {
//console.log('checkApplicantAddressFields first if ');
livedYears.removeAttr('disabled');
livedMonths.removeAttr('disabled');
// add the shaking icon to indicate requirement
livedYears.parent().parent().prev()
.html(' Required field');
$('.mobile-overlay_'+address_id)[0].style.setProperty("display","none","important");
} else {
//console.log('checkApplicantAddressFields first else 1104');
$('.mobile-overlay_'+address_id).show();
$('#employment-detail').hide();
}
}
function checkApplicantAddressFieldsMobile(address_id) {
//console.log('calling checkApplicantAddressFieldsMobile ' +address_id );
var flat_no = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_flat_number');
var building_no = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_number');
var building_name = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_building_name');
var thouroughfare = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_thouroughfare');
var post_town = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_post_town');
var postcode = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_postcode');
var livedYears = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_years');
var livedMonths = $('#LoanApplicationStepOne_addresses_'+address_id+'_address_lived_months');
var scrolltopoint = false;
if(!flat_no.val() && !building_no.val() && !building_name.val()) {
$('#flat_no_'+address_id+'-error').show();
$('#building_no_'+address_id+'-error').show();
$('#building_name_'+address_id+'-error').show();
// scroll up to title.
scrolltopoint = flat_no;
}
if(!thouroughfare.val() ) {
$('#thouroughfare_'+address_id+'-error').show();
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = thouroughfare;
}
}
if(!post_town.val() ) {
$('#post_town_'+address_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = post_town;
}
}
if(!postcode.val() ) {
$('#postcode_'+address_id+'-error').show();
if( !scrolltopoint ) {
scrolltopoint = postcode;
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
$('.mobile-overlay_'+address_id)[0].style.setProperty("display","none","important");
}
}
$('.save-new-gt-mobile').on( 'click', checkNewGuarantorFieldsMobile);
function checkNewGuarantorFieldsMobile() {
var first_name = $('#Guarantor_first_name');
var surname = $('#Guarantor_surname');
var confirmed_age = $('#Guarantor_applicant_confirmed_age');
var email = $('#Guarantor_email');
var mobile_number = $('#Guarantor_mobile_number');
var relation = $('#Guarantor_applicant_relation');
var scrolltopoint = false;
if (!first_name.val()) {
$('#new_gt_first_name-error').show();
first_name.parent().addClass('has-error');
// scroll up to title.
scrolltopoint = first_name;
}
if (!surname.val()) {
$('#new_gt_surname-error').show();
surname.parent().addClass('has-error');
/// only assign scrolltopoint if not already.
if (!scrolltopoint) {
scrolltopoint = surname;
}
}
if (!confirmed_age.val() || confirmed_age.val() == '0') {
$('#new_gt_confirmed_age-error').show();
confirmed_age.parent().addClass('has-error');
if (!scrolltopoint) {
scrolltopoint = confirmed_age;
}
}
if (!email.val()) {
$('#new_gt_email-error').show();
email.parent().addClass('has-error');
if (!scrolltopoint) {
scrolltopoint = email;
}
}
if (!mobile_number.val()) {
$('#new_gt_mobile_number-error').show();
mobile_number.parent().addClass('has-error');
if (!scrolltopoint) {
scrolltopoint = mobile_number;
}
}
if (!relation.val()) {
$('#new_gt_relation-error').show();
relation.parent().addClass('has-error');
if (!scrolltopoint) {
scrolltopoint = relation;
}
}
if (scrolltopoint) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top - 100)
}, 500);
return false;
}
return true;
}
function saveGuarantor(data) {
if (data) {
$.post(getAJAXUrl(),
{ data: data, action: 'save_guarantor_details' }
).done( function(response) {
if (response == 'OK') {
//show the terms box and SMS validation
$('#terms-validation').show();
}
});
}
}
function checkUnemployedFields() {
var failed;
required_fields = {
1:'LoanApplicationStepOne_unemployed_income_source',
2:'LoanApplicationStepOne_unemployed_net_income',
3:'LoanApplicationStepOne_unemployed_employment_pay_frequency'
};
$.each( required_fields, function( i, field ) {
if( $( "#" + field ).val() == "" ) {
failed = true;
}
});
if (failed) {
return false;
} else {
return true;
}
}
//if( $('#LoanApplicationStepOne_email[readonly]').length == 0) {
$('#LoanApplicationStepOne_email').on( 'keyup', finalCheckEmail);
//}
// M.E. OK this needs to be here because if the user comes in from the home page apply form,
// then there will be no keyup on the email field since it's already populated with the
// email filled in. Therefore, the above trigger will never happen and subsequently
// the Continue button will essentially do nothing but reload the page.
$('.email-continue').on('click', function (e) {
var message_box = $('#LoanApplicationStepOne_email').parent().prev();
$(this).attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
// check email for duplicates here?
if ($('#LoanApplicationStepOne_email').val() != "") {
var data = $('#applicant-form-step-1').serialize();
// do check.
message_box.html('Authenticating...');
checkEmail($('#LoanApplicationStepOne_email').val(), data, message_box);
}
e.preventDefault();
});
// the mobile version of email continue will work slightly differently.
$('.email-continue-mobile').on( 'click', function(e) {
// list all required fields for now, we will check them directly here
var title = $('#LoanApplicationStepOne_title');
var first_name = $('#LoanApplicationStepOne_first_name');
var surname = $('#LoanApplicationStepOne_surname');
var dob_day = $('#LoanApplicationStepOne_dob_day');
var dob_mon = $('#LoanApplicationStepOne_dob_month');
var dob_year = $('#LoanApplicationStepOne_dob_year');
var uk_resident = $('#LoanApplicationStepOne_uk_resident');
var loan_reason = $('#LoanApplicationStepOne_loan_application_loan_reason');
var mobile = $('#LoanApplicationStepOne_mobile_number');
var email = $('#LoanApplicationStepOne_email');
var scrolltopoint = false;
if(!title.val() ) {
$('#title-error').show();
title.parent().addClass('has-error');
// scroll up to title.
scrolltopoint = title;
}
if(!first_name.val() ) {
$('#first_name-error').show();
first_name.parent().addClass('has-error');
/// only assign scrolltopoint if not already.
if( !scrolltopoint ) {
scrolltopoint = first_name;
}
}
if(!surname.val() ) {
$('#surname-error').show();
surname.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = surname;
}
}
if(!dob_day.val() || !dob_mon.val() || !dob_year.val()) {
$('#dob-error').show();
dob_day.parent().parent().parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = dob_day;
}
}
if(!uk_resident.val() ) {
$('#uk_resident-error').show();
uk_resident.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = uk_resident;
}
}
if(!loan_reason.val() ) {
$('#loan_reason-error').show();
loan_reason.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = loan_reason;
}
}
if(!mobile.val()) {
// a message needs to be added here
$('#mobile-error span').html(' This field is required!');
$('#mobile-error').show();
mobile.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = mobile;
}
}
if(!email.val()) {
// a message needs to be added here
$('#email-error span').html(' This field is required!');
// in case the warning sign icon is already in the box, remove it and add the chevron again
$('#email-error i').removeClass('fa-warning').addClass('fa-chevron-up');
$('#email-error').show();
email.parent().addClass('has-error');
if( !scrolltopoint ) {
scrolltopoint = email;
}
}
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
return false;
} else {
var message_box = $('#email-error');
if ($('#LoanApplicationStepOne_email').val() != "") {
var data = $('#applicant-form-step-1').serialize();
// do check.
message_box.html(' Authenticating...');
checkEmail($('#LoanApplicationStepOne_email').val(), data, message_box);
}
}
e.preventDefault();
});
// this handles the press of the Create Password button on mobile
//TODO: For some reason, this button ALWAYS submits regardless of the returns. Look into this.
$('#LoanApplicationStepOne_user_new_account_submit_mobile').on( 'click', function(e) {
// on final click, go through the fields one more time and show the user which are missing, if any
var failed = false;
var pwd = false;
var requiredFields = {
'title':'LoanApplicationStepOne_title',
'first_name':'LoanApplicationStepOne_first_name',
'surname':'LoanApplicationStepOne_surname',
'dobday':'LoanApplicationStepOne_dob_day',
'dobmonth':'LoanApplicationStepOne_dob_month',
'dobyear':'LoanApplicationStepOne_dob_year',
'uk_resident':'LoanApplicationStepOne_uk_resident',
'loan_reason':'LoanApplicationStepOne_loan_application_loan_reason',
'mobile_number':'LoanApplicationStepOne_mobile_number',
'email':'LoanApplicationStepOne_email',
'password':'LoanApplicationStepOne_user_password_new_password',
'password_confirm':'LoanApplicationStepOne_user_password_new_password_confirm',
'security_question':'LoanApplicationStepOne_user_security_question',
'security_answer':'LoanApplicationStepOne_user_security_answer'
};
var scrolltopoint = false;
$.each( requiredFields, function( i, field ) {
if ($( "#" + field ).val() == "") {
$('#'+i+'-error').show();
field.parent().addClass('has-error');
scrolltopoint = field;
failed = true;
}
// check for password match
if (i == 'password') {
pwd = $('#'+field).val();
if( !pwd ) {
$('#password-error').show();
field.parent().addClass('has-error');
scrolltopoint = field;
failed = true;
}
}
if (i == 'password_confirm' && pwd != false) {
if (pwd != $('#'+field).val()) { // passwords did not match.
$('#password_confirm-error').show();
field.parent().addClass('has-error');
scrolltopoint = field;
failed = true;
}
}
});
if( scrolltopoint ) {
$('html, body').animate({
scrollTop: parseInt(scrolltopoint.offset().top-100)
}, 500);
e.preventDefault();
return false;
} else {
e.preventDefault();
return false;
}
});
function isEmailFieldReadOnly() {
return $('#LoanApplicationStepOne_email').attr("readonly") === "readonly";
}
function finalCheckEmail() {
var emailAddr = $(this).val();
var message_box = $(this).parent().prev();
if ($('#broker_lead').val()) {
message_box.html(' ');
return true;
}
if (isEmailFieldReadOnly() == true) {
return true;
}
// if any changes are made to the email address, hide the password / sign up boxes if visible
if ($('#new-user').is(":visible")) {
$('#new-user').hide();
}
if ($('#existing-user-password').is(":visible")) {
$('#existing-user-password').hide();
}
if (emailAddr.length > 5) { // checks length before throwing a warning
if (validateEmail(emailAddr)) { // this checks valid format
// check that all other fields are populated first.
if (checkStepOneFields()) {
message_box.html('Please click continue!');
removeFromValidationSummary('email');
message_box.next().removeClass('has-error');
} else {
message_box.html('Please make sure all fields are filled and valid');
$('#email-error')[0].style.setProperty("display","none","important");
}
} else {
$('#existing-user-password').hide();
$('#new-user').hide();
message_box.html('Incorrect format');
$('#email-error span').html(" Incorrect format!");
$('#email-error').show();
addToValidationSummary('email','Email address','invalid');
message_box.next().addClass('has-error');
}
} else {
if (!emailAddr) {
message_box.html(' Required field');
addToValidationSummary('email','Email address','required');
message_box.next().addClass('has-error');
} else {
message_box.html('Too short');
$('#email-error span').html(" Too short!");
$('#email-error').show();
addToValidationSummary('email','Email address','invalid');
message_box.next().addClass('has-error');
}
}
}
/** END VALIDATION FUNCTIONS **/
/** This part is for the Add New Guarantor form. **/
$('#Guarantor_first_name').on( 'keyup', function() {
if($(this).val() != "") {
$('#new_gt_first_name-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
} else {
$('#new_gt_first_name-error').show();
$(this).parent().addClass('has-error');
}
});
$('#Guarantor_surname').on( 'keyup', function() {
if($(this).val() != "") {
$('#new_gt_surname-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
} else {
$('#new_gt_surname-error').show();
$(this).parent().addClass('has-error');
}
});
$('#Guarantor_applicant_confirmed_age').on( 'change', function() {
if($(this).val() != "" && $(this).val() != '0') {
$('#new_gt_confirmed_age-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
} else {
if($(this).val() == "") {
$('#new_gt_confirmed_age-error span').html(' This is a required field!');
} else {
$('#new_gt_confirmed_age-error span').html(' Guarantor must be over 25!');
}
$('#new_gt_confirmed_age-error').show();
$(this).parent().addClass('has-error');
}
});
$('#Guarantor_email').on( 'keyup', function() {
if($(this).val() != "") {
// validate the email on the fly
if( !validateEmail($(this).val()) ) {
$('#new_gt_email-error span').html(' Email address is an invalid format');
$('#new_gt_email-error').show();
} else {
$('#new_gt_email-error')[0].style.setProperty('display', 'none', 'important');
$(this).parent().removeClass('has-error');
}
} else {
$('#new_gt_email-error span').html(' This is a required field!');
$('#new_gt_email-error').show();
$(this).parent().addClass('has-error');
}
});
$('#Guarantor_mobile_number').on( 'change', function() {
if($(this).val() != "") {
$('#new_gt_mobile_number-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
} else {
$('#new_gt_mobile_number-error').show();
$(this).parent().addClass('has-error');
}
});
$('#Guarantor_applicant_relation').on( 'change', function() {
if($(this).val() != "") {
$('#new_gt_relation-error')[0].style.setProperty('display','none','important');
$(this).parent().removeClass('has-error');
} else {
$('#new_gt_relation-error').show();
$(this).parent().addClass('has-error');
}
});
/** FOR LOGIN SLIDE DOWN ON APPLICATION FORM **/
$('#login-now').on( 'click', function(e) {
if( $('#loginbox').is(":visible") ) {
$('#loginbox').slideUp();
$('#login-now').html('log in to your account');
$('#close-link').hide();
} else {
$('#loginbox').slideDown();
$('#login-now').html('log in to your account');
$('#close-link').show();
}
e.preventDefault();
});
$('#close-link').on( 'click', function(e) {
$('#loginbox').slideUp();
$('#close-link').hide();
e.preventDefault();
});
/** LOGIN BOX ACTION **/
$('#username').on( 'keyup', function() {
//remove any visible error messages for mobile
$('#login_username-error')[0].style.setProperty('display','none','important');
});
$('#login_form').on('submit', function(e) {
var username = $('#username').val();
var username_error = $('#username').parent().prev();
var password = $('#password').val();
var redirect = $('#redirect').val();
if (username && password) {
$.post(getAJAXUrl(),
{ email: username, password: password, action: 'app_login' }
).done( function(response) {
if (response == 'OK') {
//OK, reload the page
location.reload(redirect);
} else if (response == 'incorrect') {
username_error.html('Your credentials are incorrect!');
$('#login_username-error span').html(' Your credentials are incorrect!');
$('#login_username-error').show();
} else if (response == 'empty') {
username_error.html('Please enter your username and password!');
$('#login_username-error span').html(' Please enter your username and password!');
$('#login_username-error').show();
} else if(response == 'my_account') { //need to redirect to account page
window.location.href = '/my-account';
}
});
}
e.preventDefault();
});
/** LOGIN FROM APPLICATION FORM (IF EMAIL RECOGNISED) **/
$('#login-password').on( 'click', function(e) {
console.log('triggered');
var username = $('#LoanApplicationStepOne_email').val();
var password = $('#LoanApplicationStepOne_user_existing_password').val();
var redirect = $('#redirect').val();
var password_error = $('#LoanApplicationStepOne_user_existing_password').parent().prev();
console.log(username);
console.log(password);
if (username && password) {
console.log('all good?');
$.post(getAJAXUrl(),
{ email: username, password: password, action: 'app_login' }
).done( function(response) {
console.log(response);
if (response == 'OK') {
//OK, reload the page
location.reload(redirect);
} else if (response == 'incorrect') {
password_error.html('Your credentials are incorrect!');
} else if (response == 'empty') {
password_error.html('Please enter your username and password!');
} else if(response == 'my_account') { //need to redirect to account page
window.location.href = '/my-account';
}
});
}
e.preventDefault();
});
// Also do same with address
checkApplicantAddressHistoryValues();
checkApplicantAddressFields(0);
checkApplicantAddressFields(1);
checkApplicantAddressFields(2);
$('#LoanApplicationStepOne_user_password_new_password').on( 'keyup', function() {
checkRequiredFields();
});
$('#LoanApplicationStepOne_user_password_new_password_confirm').on( 'keyup', function() {
var message_box = $(this).parent().prev();
var chosenPassword = $('#LoanApplicationStepOne_user_password_new_password').val();
if( chosenPassword != "" && chosenPassword == $(this).val() ) {
message_box.html(' ');
$('#password_confirm-error')[0].style.setProperty( 'display', 'none', 'important' );
} else {
message_box.html('Passwords do not match!');
}
checkRequiredFields();
});
// on mobile, check the password confirm on blur instead
$('#LoanApplicationStepOne_user_password_new_password_confirm').on( 'blur', function() {
var chosenPassword = $('#LoanApplicationStepOne_user_password_new_password').val();
if( chosenPassword != "" && chosenPassword == $(this).val() ) {
$('#password_confirm-error')[0].style.setProperty( 'display', 'none', 'important' );
$(this).prev().removeClass('has-error');
} else {
// show the error on mobile
$('#password_confirm-error').show();
$(this).parent().addClass('has-error');
}
checkRequiredFields();
});
$('#LoanApplicationStepOne_user_security_question').on( 'change', function() {
checkRequiredFields();
});
$('#LoanApplicationStepOne_user_security_answer').on( 'keyup', function() {
checkRequiredFields();
});
// if coming in from a broker lead, we will need to make sure all required fields are filled before
// enabling the submit button
function checkRequiredFields() {
if ($('#show_login').val() === null) {
$('#address-detail').fadeIn();
$('#marital').show();
$('#rest-of-form').fadeIn();
}
$('#LoanApplicationStepOne_user_new_account_submit').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
var failed = false;
var pwd = false;
var requiredFields = {
1:'LoanApplicationStepOne_title',
2:'LoanApplicationStepOne_first_name',
3:'LoanApplicationStepOne_surname',
4:'LoanApplicationStepOne_dob_day',
5:'LoanApplicationStepOne_dob_month',
6:'LoanApplicationStepOne_dob_year',
7:'LoanApplicationStepOne_uk_resident',
8:'LoanApplicationStepOne_loan_application_loan_reason',
9:'LoanApplicationStepOne_mobile_number',
10:'LoanApplicationStepOne_email',
11:'LoanApplicationStepOne_user_password_new_password',
12:'LoanApplicationStepOne_user_password_new_password_confirm',
13:'LoanApplicationStepOne_user_security_question',
14:'LoanApplicationStepOne_user_security_answer'
};
$.each( requiredFields, function( i, field ) {
if ($( "#" + field ).val() == "") {
failed = true;
}
// check for password match
if (i == 11) {
pwd = $('#'+field).val();
}
if (i == 12 && pwd != false) {
if (pwd != $('#'+field).val()) { // passwords did not match.
failed = true;
}
}
});
if (!failed) {
$('#LoanApplicationStepOne_user_new_account_submit').removeAttr('disabled').addClass('btn-primary').removeClass('btn-disabled');
return true;
}
return false;
}
function checkGuarantorRequiredFields() {
var is_ok = true;
var requiredFields = {
1:'LoanApplicationStepOne_loan_application_guarantors_0_first_name',
2:'LoanApplicationStepOne_loan_application_guarantors_0_surname',
3:'LoanApplicationStepOne_loan_application_guarantors_0_applicant_confirmed_age',
4:'LoanApplicationStepOne_loan_application_guarantors_0_mobile_number',
5:'LoanApplicationStepOne_loan_application_guarantors_0_email',
6:'LoanApplicationStepOne_loan_application_guarantors_0_applicant_relation'
};
$.each(requiredFields, function(i, field) {
if ($("#" + field).val() == "") {
is_ok = false;
}
// check for valid email and mobile also.
if (i == 4) {
if (!validateMobile(null, $('#'+field).val())) {
is_ok = false;
}
}
if (i == 5) {
if (!validateEmail($('#'+field).val())) {
is_ok = false;
}
}
});
var termsValidationField = $('#terms-validation');
if (is_ok) {
// we need to do a dupe check as well before continuing
if ($('#LoanApplicationStepOne_loan_application_guarantors_0_mobile_number').val() != "") { // only do the call if the mobile number is there
$.post(getAJAXUrl(),
{
number: $('#LoanApplicationStepOne_loan_application_guarantors_0_mobile_number').val(),
mobile_type: 'guarantor',
action: 'check_mobile_dupe'
}
).done(function (response) {
if (response == 'invalid' || response == 1 || response == 'own_number') {
is_ok = false;
termsValidationField.hide();
return is_ok;
} else {
if (termsValidationField.not(":visible")) {
termsValidationField.show();
}
return is_ok;
}
});
}
} else {
return false;
}
}
var visitor_mobile_number = null;
function hasMobileNumberChanged(mobile_number) {
if (!mobile_number) {
return false;
}
if (visitor_mobile_number != mobile_number ) {
visitor_mobile_number = mobile_number;
return true;
}
return false;
}
function checkStepOneFields() {
var is_broker_lead = $('#broker_lead').val(); // check if this is a broker lead. Things needs to happen differently if so.
var submit_button = $('#LoanApplicationStepOne_user_new_account_submit');
var current_mobile_number_field_value = $('#LoanApplicationStepOne_mobile_number').val();
var hasMobileChanged = hasMobileNumberChanged(current_mobile_number_field_value);
var failed = false;
var test = false;
var newUserField = $('#new-user');
var existingUserField = $('#existing-user-password');
if (is_broker_lead) {
// disable the submit button until we can clarify everything is valid.
submit_button.attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
var result = checkRequiredFields(); // run the check required fields function instead.
return result;
} else {
if (newUserField.is(":visible")) {
newUserField.hide();
}
if (existingUserField.is(":visible")) {
existingUserField.hide();
}
}
// when disabling the continue button, use first-child so as not to affect the mobile version button
$('.email-continue').show();
$('#email-go span button:first-child').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
// all these fields need to be populated before the application can continue past email
var requiredFields = {
1:'LoanApplicationStepOne_title',
2:'LoanApplicationStepOne_first_name',
3:'LoanApplicationStepOne_surname',
4:'LoanApplicationStepOne_dob_day',
5:'LoanApplicationStepOne_dob_month',
6:'LoanApplicationStepOne_dob_year',
7:'LoanApplicationStepOne_uk_resident',
8:'LoanApplicationStepOne_loan_application_loan_reason',
9:'LoanApplicationStepOne_mobile_number',
10:'LoanApplicationStepOne_email'
};
var dobday = 0;
var dobmonth = 0;
var dobyear = 0;
$.each(requiredFields, function(i, field) {
if ($( "#" + field).val() == "") {
failed = true;
}
if (i==2 || i==3) {
if (!validateName($( "#" + field ).val())) {
failed = true;
}
}
if (i==4) {
dobday = $( "#" + field).val();
}
if (i==5) {
dobmonth = $( "#" + field).val();
}
if (i==6) {
dobyear = $( "#" + field).val();
// before attempting validation, make sure that at least one option is chosen
if( dobyear && dobmonth && dobday ) {
if (!validateDOB(dobday, dobmonth, dobyear)) {
failed = true;
}
} else {
failed = true; // still failed, if no values passed, but just won't highlight it.
}
}
// check for valid email and mobile also.
if (i == 9) {
test = true;
if (!validateMobile(null, $('#'+field).val())) {
failed = true;
}
if (hasMobileChanged) {
// if it passed validation, do a quick dupe check again just in case.
if( $('#'+field).val() != "" ) { // only do the call if the mobile number is there
$.post(getAJAXUrl(),
{ number: $('#'+field).val(), email_token: $('#email_token').val(), action: 'check_mobile_dupe'}
).done( function(response) {
if( response == 'invalid' || response == 1 ) {
failed = true;
}
});
}
}
}
// check for valid email and mobile also.
if (i == 10) {
if (!validateEmail($('#'+field).val())) {
failed = true;
} else {
removeFromValidationSummary('email');
$('#LoanApplicationStepOne_email').parent().removeClass('has-error');
}
}
});
if( test == false ) {
if (!failed) {
$('#LoanApplicationStepOne_email').parent().prev().html('Please click continue!');
$("#email-error")[0].style.setProperty( 'display', 'none', 'important' );
$('#email-go span button:first-child').removeAttr('disabled').addClass('btn-primary').removeClass('btn-disabled').addClass('email-continue');
// Broker lead? Show create user form.
if ($('#broker_lead').val() && !$('#user_logged_in').val() && !$('#show_login').val()) {
$('#new-user').show();
}
return true;
} else {
$('#LoanApplicationStepOne_email').parent().prev().html('Please make sure all fields are filled and valid');
$('#email-go span button:first-child').attr('disabled','disabled').removeClass('btn-primary').addClass('btn-disabled');
}
}
if (failed) {
$('#LoanApplicationStepOne_email').parent().prev().html('Please make sure all fields are filled and valid');
$('#email-go span button:first-child').attr('disabled','disabled').removeClass('btn-primary').addClass('btn-disabled');
return false;
}
if (isEmailFieldReadOnly() == true) {
$('#LoanApplicationStepOne_email').parent().prev().html(' ');
} else {
$('#LoanApplicationStepOne_email').parent().prev().html('Please click continue!');
$('#email-go span button').removeAttr('disabled').addClass('btn-primary').removeClass('btn-disabled').addClass('email-continue');
}
// Broker lead? Show create user form.
if ($('#broker_lead').val() && !$('#user_logged_in').val() && !$('#show_login').val()) {
if ($('#new-user').not(':visible')) {
$('#new-user').show();
}
submit_button.removeAttr('disabled').addClass('btn-primary').removeClass('btn-disabled');
}
//if everything OK, remove the email error message on mobiles
$("#email-error")[0].style.setProperty( 'display', 'none', 'important' );
return true;
}
function validateName(name) {
if( name ) {
var expression = /^[A-Za-z-']{2,20}$/;
if( expression.test(name) ) {
return true;
}
}
return false;
}
/** INITIAL SAVING OF APPLICATION (AFTER CREATING ACCOUNT) **/
$('#LoanApplicationStepOne_user_new_account_submit').on( 'click', function(e) {
$(this).attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
// at this point we need to log it in the database and continue
var message_box = $(this).parent().prev();
if ($('#applicant-form-step-1').length > 0) {
var formData = $('#applicant-form-step-1').serialize();
var formType = 'applicant';
} else {
var formData = $('#guarantor-form-step-1').serialize();
var formType = 'guarantor';
}
var is_broker_lead = $('#broker_lead').val();
var email_token = $('#email_token').val();
$.post(getAJAXUrl(),
{ form_data: formData, form_type: formType, broker_lead: is_broker_lead, email_token: email_token, action: 'log_application' }
).done( function(response) {
if (response == 1 ) {
if (formType == 'applicant') { // only need to readonly the email if applicant, guarantor already is readonly.
$('#LoanApplicationStepOne_email').attr('readonly','readonly'); //disable further changes to email address at this point
$('#LoanApplicationStepOne_mobile_number').attr('readonly','readonly'); //disable further changes to mobile
$('#LoanApplicationStepOne_uk_resident').attr('readonly','readonly'); //disable further changes to uk residency
//populate the field by the verify section with the existing mobile so it can be changed later
$('#LoanApplicationStepOne_new_mobile').val($('#LoanApplicationStepOne_mobile_number').val());
$('.your_number').text($('#LoanApplicationStepOne_mobile_number').val());
// TODO: Maybe completely disable the first part of the form after creating password to prevent additional changes?
//ga('send', 'event', 'applicant_apply', 'click', 'applicant_account_created');
ga('send','pageview', {
'page': '/v2/apply',
'title': 'Applicant account created'
});
}
} else {
//console.log(response);
message_box.html('Sorry, an error occurred.');
return false;
}
});
$('#new-user').hide();
$('#address-detail').fadeIn();
$('#marital').show();
$('#rest-of-form').fadeIn();
e.preventDefault();
// Scroll to anchor to make sure user can still see form on mobile.
$('html,body').animate({scrollTop: $('#post_signup_anchor').offset().top},'slow');
setTimeout(
function () {
// Double check that these fields weren't prefilled (if they were then validate them as if
// the user had filled it in now)
$('#housing-status select').trigger('change');
$('#marital select').trigger('change');
// Invalid phone format will silentl stop us progressing
$('#LoanApplicationStepOne_employments_0_employer_telephone').trigger('blur');
if ($('#LoanApplicationStepOne_employments_1_employer_telephone').is(':visible')) {
$('#LoanApplicationStepOne_employments_1_employer_telephone').trigger('blur');
}
if ($('#LoanApplicationStepOne_employments_2_employer_telephone').is(':visible')) {
$('#LoanApplicationStepOne_employments_2_employer_telephone').trigger('blur');
}
if ($('#LoanApplicationStepOne_addresses_0_mortgage_cost').is(':visible')) {
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').trigger('blur')
}
if ($('#LoanApplicationStepOne_addresses_0_rent_cost').is(':visible')) {
$('#LoanApplicationStepOne_addresses_0_rent_cost').trigger('keyup')
}
if ($('#LoanApplicationStepOne_applicant_bank_account_number').is(':visible')) {
$('#LoanApplicationStepOne_applicant_bank_account_number').trigger('keyup');
}
if ($('#LoanApplicationStepOne_addresses_0_address_lived_years').is(':visible')) {
$('#LoanApplicationStepOne_addresses_0_address_lived_years').trigger('change');
}
if ($('#LoanApplicationStepOne_addresses_0_address_lived_months').is(':visible')) {
$('#LoanApplicationStepOne_addresses_0_address_lived_months').trigger('change');
}
$('#LoanApplicationStepOne_applicant_cost_other').trigger('keyup');
$('#LoanApplicationStepOne_dependants').trigger('blur');
},
300
);
});
/** INDIVIDUAL AJAX CALLS FOR EACH FORM FIELD **/
$('#LoanApplicationStepOne_title').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
// remove the mobile warning message, if present
$("#title-error")[0].style.setProperty( 'display', 'none', 'important' );
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_title' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('title');
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
addToValidationSummary('title','Title','required');
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('title');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('title');
}
});
checkStepOneFields();
});
/** CAPITALISE FIRST LETTER OF ALL NAMES FOR MORE PROFESSIONAL LOOK **/
$('#LoanApplicationStepOne_first_name').on( 'blur', function() {
$(this).val(capitaliseInput($(this).val()));
});
$('#LoanApplicationStepOne_middle_name').on( 'blur', function() {
$(this).val(capitaliseInput($(this).val()));
});
$('#LoanApplicationStepOne_surname').on( 'blur', function() {
$(this).val(capitaliseInput($(this).val()));
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_first_name').on( 'blur', function() {
$(this).val(capitaliseInput($(this).val()));
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_surname').on( 'blur', function() {
$(this).val(capitaliseInput($(this).val()));
});
$('#LoanApplicationStepOne_first_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
var message_box = $(this).parent().prev();
var input_wrapper = $(this).parent();
if (validateName(field_value)) {
// remove the mobile warning message, if present
$('#first_name-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_first_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('first_name');
} else if( response == 'noval') {
message_box.html('Required!');
input_wrapper.addClass('has-error');
addToValidationSummary('first_name','First name', 'required');
} else if( response == 'success') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('first_name');
} else if( response == 'nochange') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('first_name');
}
});
} else {
if( field_value == "" ) { // show the Required message
message_box.html('Required!');
removeFromValidationSummary('first_name'); // remove first in case it's already there
addToValidationSummary('first_name','First name', 'required');
} else {
message_box.html('Invalid name!');
removeFromValidationSummary('first_name'); // remove the required warning, if present - then add the invalid warning.
addToValidationSummary('first_name','First name', 'invalid');
// add the error message for mobiles
$('#first_name-error span').html(' Please enter a valid name!');
$('#first_name-error').show();
}
input_wrapper.addClass('has-error');
}
checkStepOneFields();
});
$('#LoanApplicationStepOne_surname').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
var message_box = $(this).parent().prev();
var input_wrapper = $(this).parent();
if (validateName(field_value)) {
$('#surname-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_surname' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('last_name');
} else if( response == 'noval') {
message_box.html('Required!');
input_wrapper.addClass('has-error');
addToValidationSummary('last_name','Last name','required');
} else if( response == 'success') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('last_name');
} else if( response == 'nochange') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
removeFromValidationSummary('last_name');
}
});
} else {
if( field_value == "" ) { // show the Reqiured message
message_box.html('Required!');
removeFromValidationSummary('last_name');
addToValidationSummary('last_name','Last name','required');
} else {
message_box.html('Invalid name!');
removeFromValidationSummary('last_name');
addToValidationSummary('last_name','Last name','invalid');
// add the error message for mobiles
$('#surname-error span').html(' Please enter a valid name!');
$('#surname-error').show();
}
input_wrapper.addClass('has-error');
}
checkStepOneFields();
});
$('#LoanApplicationStepOne_middle_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
var message_box = $(this).parent().prev();
// if no middle name has been entered, there's no need to do any checks.
if( field_value == "" ) {
return false;
}
if( validateName(field_value) ) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_middle_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
} else if( response == 'noval') {
message_box.html(' ');
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
}
});
} else {
message_box.html('Invalid name!');
}
checkStepOneFields();
});
$('#LoanApplicationStepOne_loan_application_loan_reason').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_","");
var message_box = $(this).parent().prev();
$('#loan_reason-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_loan_reason' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('loan_reason');
} else if (response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
addToValidationSummary('loan_reason','Loan reason','required');
} else if (response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('loan_reason');
} else if (response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('loan_reason');
}
});
checkStepOneFields();
});
$('#LoanApplicationStepOne_loan_application_loan_amount').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_","");
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_loan_amount' },
function(response) {
if ( response ) {
// saved ok.
}
}, "json");
checkStepOneFields();
});
$('#LoanApplicationStepOne_loan_application_loan_term').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_","");
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_loan_term' }
).done( function(response) {
//ok
});
checkStepOneFields();
});
$('#LoanApplicationStepOne_mobile_number').on( 'change', runMobileNumberCheck);
function runMobileNumberCheck() {
var mobile_number_field = $('#LoanApplicationStepOne_mobile_number');
var field_value = mobile_number_field.val();
var message_box = mobile_number_field.parent().prev();
var email_message_box = $('#LoanApplicationStepOne_email').parent().prev();
field_value = removeWhiteSpace(field_value);
mobile_number_field.val(field_value);
var validation = validateMobile(message_box,field_value);
var email_token = $('#email_token').val();
if (validation) {
$('#mobile-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
message_box.html(' ');
// do a dedupe test first
$.post(getAJAXUrl(),
{ number: field_value, email_token: email_token, action: 'check_mobile_dupe'}
).done( function(response) {
if (response == 1) {
message_box.html('It looks like this mobile number may already be attached to an account. Please use an alternative or login here if you have an account.');
$('#mobile-error span').html(' This mobile number already has an account. Please log in.');
message_box.next().addClass('has-error');
$('#mobile-error').show();
email_message_box.html('Please make sure all fields are filled and valid');
$('#email-error span').html(' Please correct all errors before continuing.');
$('#email-error i').removeClass('fa-chevron-up').addClass('fa-warning');
$('#email-error').show();
return false;
} else if (response == 'invalid') {
message_box.html('Invalid mobile number!');
message_box.next().addClass('has-error');
$('#mobile-error span').html(' Invalid mobile number!');
$('#mobile-error').show();
email_message_box.html('Please make sure all fields are filled and valid');
$('#email-error span').html(' Please correct all errors before continuing.');
$('#email-error i').removeClass('fa-chevron-up').addClass('fa-warning');
$('#email-error').show();
} else if (response == 'opted_out') {
message_box.html('This mobile number is in the opt-out list.');
message_box.next().addClass('has-error');
$('#mobile-error span').html(' Mobile number is opted out.');
$('#mobile-error').show();
email_message_box.html('Please make sure all fields are filled and valid');
$('#email-error span').html(' Please correct all errors before continuing.');
$('#email-error i').removeClass('fa-chevron-up').addClass('fa-warning');
$('#email-error').show();
return false;
} else {
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_mobile_number' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('mobile');
$('#mobile-error')[0].style.setProperty( 'display', 'none', 'important' );
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
addToValidationSummary('mobile','Mobile number','required');
$('#mobile-error span').html(' This is a required field!');
$('#mobile-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('mobile');
$('#mobile-error')[0].style.setProperty( 'display', 'none', 'important' );
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('mobile');
$('#mobile-error')[0].style.setProperty( 'display', 'none', 'important' );
}
});
checkStepOneFields();
}
});
}
}
$('#marital select').on( 'change', function() {
// is this the applicant or guarantor form?
if($(this).attr('id') == 'GuarantorApplication_marital_status') {
var action = "save_guarantor_marital_status";
} else {
var action = "save_marital_status";
}
var field_value = $(this).val();
var field_id = $(this).attr('id');
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: action }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
if($('#gt_marital_status-error').length > 0) {
$('#gt_marital_status-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#marital_status-error')[0].style.setProperty( 'display', 'none', 'important' );
}
} else if( response == 'noval') {
message_box.html('Required!');
if($('#gt_marital_status-error').length > 0) {
$('#gt_marital_status-error').show();
} else {
$('#marital_status-error').show();
}
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
if($('#gt_marital_status-error').length > 0) {
$('#gt_marital_status-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#marital_status-error')[0].style.setProperty( 'display', 'none', 'important' );
}
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
if($('#gt_marital_status-error').length > 0) {
$('#gt_marital_status-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#marital_status-error')[0].style.setProperty( 'display', 'none', 'important' );
}
}
});
});
$('#LoanApplicationStepOne_dob select').on( 'change', saveDOB);
function validateDOB(dobday, dobmonth, dobyear) {
var message_box = $('#LoanApplicationStepOne_dob select').parent().parent().parent().prev();
message_box.html(' ');
if (!dobday || !dobmonth || !dobyear) {
message_box.html(' Required!');
message_box.next().addClass('has-error');
return false;
}
var dob = new Date(dobyear + '/' + dobmonth + '/' + dobday); // M.E. delimiter needs to be a slash in order for calculation to work correctly.
var today = new Date();
var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
if (age >= 18) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#dob-error')[0].style.setProperty( 'display', 'none', 'important' );
return true;
} else {
message_box.html('Sorry! You must be over 18 to apply.');
message_box.next().addClass('has-error');
$('#dob-error span').html(' Sorry, you must be over 18 to apply');
$('#dob-error').show();
return false;
}
}
function reValidateDob() {
validateDOB(
$('#LoanApplicationStepOne_dob_day').val(),
$('#LoanApplicationStepOne_dob_month').val(),
$('#LoanApplicationStepOne_dob_year').val()
);
}
function saveDOB() {
var dobday = false;
var dobmonth = false;
var dobyear = false;
var message_box = $('#LoanApplicationStepOne_dob select').parent().parent().parent().prev();
var input_wrapper = $('#LoanApplicationStepOne_dob').parent().parent();
var mobile_message_box = $('#dob-error');
var mobile_message_span = $('#dob-error span');
message_box.html(' ');
//check to see if all values are filled before sending to database.
if ($('#LoanApplicationStepOne_dob_day').val() != "") {
dobday = $('#LoanApplicationStepOne_dob_day').val();
}
if ($('#LoanApplicationStepOne_dob_month').val() != "") {
dobmonth = $('#LoanApplicationStepOne_dob_month').val();
}
if ($('#LoanApplicationStepOne_dob_year').val() != "") {
dobyear = $('#LoanApplicationStepOne_dob_year').val();
}
// at this point, the user may have only chosen day or just day and month, so validating
// here will throw an error which isn't particularly user friendly. So, another method
// needs to be implemented to fix this
if(dobday != false && dobmonth != false && dobyear != false) {
if (validateDOB(dobday, dobmonth, dobyear)) { //all filled out
//format result.
var dob_value = dobyear + '-' + dobmonth + '-' + dobday;
$.post(getAJAXUrl(),
{value: dob_value, field_name: 'dob', action: 'save_dob'}
).done(function (response) {
if (response == 'new') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
} else if (response == 'tooyoung') {
message_box.html('Sorry! You must be over 18 to apply.');
input_wrapper.addClass('has-error');
addToValidationSummary('dob', 'Date of birth', 'required');
} else if (response == 'success') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
} else if (response == 'nochange') {
message_box.html(' ');
input_wrapper.removeClass('has-error');
mobile_message_box[0].style.setProperty('display','none','important');
removeFromValidationSummary('dob');
}
});
}
} else {
message_box.html('Please select full date of birth');
mobile_message_span.html(" Please select full date of birth");
mobile_message_box.show();
}
checkStepOneFields();
}
$('#dependants input').on( 'blur', function() {
if($(this).attr('id') == "GuarantorApplication_dependants") {
var action = 'save_guarantor_dependants';
} else {
var action = 'save_dependants';
}
var field_value = $(this).val();
var message_box = $(this).parent().prev();
if(field_value.length > 0 && checkNumber(field_value) === false) {
message_box.next().addClass('has-error');
message_box.html('Dependants must be a number!');
if($('#gt_dependants-error').length > 0) {
$('#gt_dependants-error span').html(' Dependants must be a number!');
$('#gt_dependants-error').show();
} else {
$('#dependants-error span').html(' Dependants must be a number!');
$('#dependants-error').show();
}
return false;
}
$.post(getAJAXUrl(),
{ value: field_value, action: action }
).done( function(response) {
if ( response == 'noval' ) {
message_box.html('Required!');
if($('#gt_dependants-error').length > 0) {
$('#gt_dependants-error').show();
} else {
$('#dependants-error').show();
}
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
if($('#gt_dependants-error').length > 0) {
$('#gt_dependants-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#dependants-error')[0].style.setProperty( 'display', 'none', 'important' );
}
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
if($('#gt_dependants-error').length > 0) {
$('#gt_dependants-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#dependants-error')[0].style.setProperty( 'display', 'none', 'important' );
}
message_box.next().removeClass('has-error');
}
});
});
$('#LoanApplicationStepOne_uk_resident').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
$('#uk_resident-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'check_uk_residency' }
).done(function(response) {
if ( response == 'OK' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
removeFromValidationSummary('uk_resident');
} else if( response == 'fail') {
message_box.html('You must be a UK resident to apply');
message_box.next().addClass('has-error');
addToValidationSummary('uk_resident', 'UK residency status','required');
} else {
message_box.html('Something went wrong!');
message_box.next().addClass('has-error');
addToValidationSummary('uk_resident', 'UK residency','required');
}
});
checkStepOneFields();
});
// For housing status, only do the save if the user has manually clicked the box, as we need to trigger
// a change action on load in order to be able to show the correct cost box underneath.
// FIXME: Click event seems to cause multiple calls - take a look into it
//$('#LoanApplicationStepOne_addresses_0_housing_status').on('click', function() {
$('#housing-status select').on( 'change', function() {
//console.log('#housing-status on change');
if($(this).attr('id') == 'GuarantorApplication_addresses_0_housing_status') {
var action = 'save_guarantor_housing_status';
} else {
var action = 'save_housing_status';
}
//console.log('action' + action);
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: action }
).done( function(response) {
//console.log('response');
//console.log(response);
if ( response == 'new' ) {
message_box.html(' ');
if($('#gt_housing_status-error').length > 0) {
$('#gt_housing_status-error')[0].style.setProperty( 'display', 'none', 'important' );
} else {
$('#housing_status-error')[0].style.setProperty('display', 'none', 'important');
}
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
if($('#gt_housing_status-error').length > 0) {
$('#gt_housing_status-error').show();
} else {
$('#housing_status-error').show();
}
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
if($('#gt_housing_status-error').length > 0) {
$('#gt_housing_status-error')[0].style.setProperty( 'display', 'none', 'important' );
} else {
$('#housing_status-error')[0].style.setProperty('display', 'none', 'important');
}
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
if($('#gt_housing_status-error').length > 0) {
$('#gt_housing_status-error')[0].style.setProperty( 'display', 'none', 'important' );
} else {
$('#housing_status-error')[0].style.setProperty('display', 'none', 'important');
}
message_box.next().removeClass('has-error');
}
});
});
//});
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().parent().prev();
// check for numeric entry
if (field_value.length > 0 && checkNumber(field_value) === false) {
message_box.html('Mortgage cost must be a number!');
$('#mortgage_cost-error span').html(' Mortgage cost must be a number!');
$('#mortgage_cost-error').show();
message_box.next().addClass('has-error');
return false;
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_mortgage_cost' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#mortgage_cost-error').show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#mortgage_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
}
});
});
$('#LoanApplicationStepOne_addresses_0_rent_cost').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().parent().prev();
// check for numeric entry
if (field_value.length > 0 && checkNumber(field_value) === false) {
message_box.html('Rent cost must be a number!');
$('#rent_cost-error span').html(' Rent cost must be a number!');
$('#rent_cost-error').show();
message_box.next().addClass('has-error');
return false;
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_rent_cost' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#rent_cost-error')[0].style.setProperty( 'display', 'none', 'important' );
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#rent_cost-error span').html(' This is a required field!');
$('#rent_cost-error').show();
message_box.next().addClass('has-error');
return false;
} else if( response == 'success') {
message_box.html(' ');
$('#rent_cost-error')[0].style.setProperty('display', 'none', 'important');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#rent_cost-error')[0].style.setProperty('display', 'none', 'important');
} else if( response == 'invalid' ) {
message_box.html('Rent cost must be a number!');
$('#rent_cost-error span').html(' Rent cost must be a number!');
$('#rent_cost-error').show();
message_box.next().addClass('has-error');
return false;
}
});
});
$('#LoanApplicationStepOne_cost_other').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
var message_box = $(this).parent().parent().prev();
// check for numeric entry
if (field_value.length > 0 && checkNumber(field_value) === false) {
message_box.html('Monthly outgoings must be a number!');
$('#cost_other-error span').html(' Monthly outgoings must be a number!');
$('#cost_other-error').show();
return false;
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_cost_other' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#cost_other-error')[0].style.setProperty('display','none','important');
} else if (response == 'noval') {
message_box.html('Required!');
$('#cost_other-error span').html(' This is a required field!');
$('#cost_other-error').show();
message_box.next().addClass('has-error');
return false;
} else if (response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#cost_other-error')[0].style.setProperty('display','none','important');
} else if (response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#cost_other-error')[0].style.setProperty('display','none','important');
} else if (response == 'invalid') {
message_box.html('Monthly outgoings must be a number!');
$('#cost_other-error span').html(' Monthly outgoings must be a number!');
$('#cost_other-error').show();
message_box.next().addClass('has-error');
return false;
}
});
});
// would likely need to validate this too.
$('#LoanApplicationStepOne_landline_number').on( 'blur', function() {
//console.log('LoanApplicationStepOne_landline_number called');
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
var elem = $(this);
var message_box = $(this).parent().prev();
var validated = false;
field_value = removeWhiteSpace(field_value);
$(this).val(field_value);
message_box.html(' ');
// run the validation before saving.
// only attempt validation if a value is passed. If value is blank, it's still OK as it's an optional field
if( field_value.length > 0 ) {
if( validateLandline(elem,field_value) ) { // validated OK.
validated = true;
} else {
validated = false;
}
} else {
validated = true; //auto validated, blank value is OK.
}
if( validated ) {
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_landline_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
});
}
return false;
});
function isInteger(n) {
return n === +n && n === (n|0);
}
$('#address-1-manual').on('change', function() {
checkApplicantAddressHistoryValues();
});
$('#LoanApplicationStepOne_addresses_0_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_0_address_building_number').parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_0_address_building_name').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_flat_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_0_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_name').val()) {
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
} else {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(0);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_0_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if($('#LoanApplicationStepOne_addresses_0_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_0_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_name').val()) {
building_num_msg_box.html('At least one of these is required');
building_name_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_0_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_0_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_0_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
var flat_msg_box = $('#LoanApplicationStepOne_addresses_0_address_flat_number').parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_0_address_building_name').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_building_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_0_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_name').val()) {
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
} else {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(0);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_0_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_0_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_0_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_name').val()) {
flat_msg_box.html('At least one of these is required');
building_name_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_0_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_0_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_0_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
var flat_msg_box = $('#LoanApplicationStepOne_addresses_0_address_flat_number').parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_0_address_building_number').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_building_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_0_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_number').val()) {
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
} else {
message_box.html(' ');
$('#flat_no_1-error')[0].style.setProperty("display","none","important");
$('#building_no_1-error')[0].style.setProperty("display","none","important");
$('#building_name_1-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(0);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_0_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_0_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_0_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_0_address_building_number').val()) {
flat_msg_box.html('At least one of these is required');
building_num_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_1-error').show();
$('#building_no_1-error').show();
$('#building_name_1-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_0_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_0_address_lived_months').attr('disabled', true);
} else {
message_box.html(' ');
}
}
});
$('#LoanApplicationStepOne_addresses_0_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#thouroughfare_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#thouroughfare_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#thouroughfare_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#thouroughfare_1-error').show();
message_box.next().addClass('has-error');
}
});
checkApplicantAddressFields(0);
});
$('#LoanApplicationStepOne_addresses_0_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#post_town_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#post_town_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#post_town_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
$('#post_town_1-error').show();
}
});
checkApplicantAddressFields(0);
});
$('#LoanApplicationStepOne_addresses_0_address_county').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_0_","");
var message_box = $(this).parent().prev();
if ( field_value.length > 0 ) { // only attempt a save if there's a value
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
});
checkApplicantAddressFields(0);
}
});
$('#LoanApplicationStepOne_addresses_0_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode', address_id:1 }
).done( function(response) {
if( response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('Postcode is an invalid format!');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_postcode', address_id:1 }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#postcode_1-error')[0].style.setProperty("display","none","important");
saveAddress1();
} else if( response == 'success') {
message_box.html(' ');
$('#postcode_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#postcode_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
$('#postcode_1-error span').html(" This field is required!");
$('#postcode_1-error').show();
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#LoanApplicationStepOne_addresses_0_address_postcode').val(new_postcode);
}
});
checkApplicantAddressFields(0);
});
$('#manual-address-1, #manual-address-2, #manual-address-3').on('click', function() {
if($('#gt_postcode_1-error').length > 0) { // we are on GT form
$('#gt_postcode_1-error')[0].style.setProperty('display', 'none', 'important');
$('#gt_postcode_2-error')[0].style.setProperty('display', 'none', 'important');
$('#gt_postcode_3-error')[0].style.setProperty('display', 'none', 'important');
} else {
$('#postcode_1-error')[0].style.setProperty('display', 'none', 'important');
$('#postcode_2-error')[0].style.setProperty('display', 'none', 'important');
$('#postcode_3-error')[0].style.setProperty('display', 'none', 'important');
}
});
$('.mobile-overlay_1').on( 'click', function(e) {
//console.log('.mobile-overlay_1 click');
// check address values on mobile
checkApplicantAddressFieldsMobile(0);
});
$('.mobile-overlay_2').on( 'click', function(e) {
//console.log('.mobile-overlay_2 click');
// check address values on mobile
checkApplicantAddressFieldsMobile(1);
});
$('.mobile-overlay_3').on( 'click', function(e) {
//console.log('.mobile-overlay_3 click');
// check address values on mobile
checkApplicantAddressFieldsMobile(2);
});
$('.employment-mobile-overlay_0').on( 'click', function(e) {
//console.log('.employment-mobile-overlay_0 click');
// check address values on mobile
checkApplicantEmploymentFieldsMobile(0);
});
$('.employment-mobile-overlay_1').on( 'click', function(e) {
//console.log('.employment-mobile-overlay_1 click');
// check address values on mobile
checkApplicantEmploymentFieldsMobile(1);
});
$('.employment-mobile-overlay_2').on( 'click', function(e) {
//console.log('.employment-mobile-overlay_2 click');
// check address values on mobile
checkApplicantEmploymentFieldsMobile(2);
});
$('#LoanApplicationStepOne_addresses_0_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_0_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
if( field_value != "" && field_value_2 != "" ) {
checkApplicantAddressHistoryValues(); // if the year value is zero, will most likely need to show previous address.
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, action: 'save_address_lived_years' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
saveAddress1();
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
// we may need to adjust the move in date on previous addresses, if this is being changed.
if ($('#LoanApplicationStepOne_addresses_1_address_lived_years').val() != "" && $('#LoanApplicationStepOne_addresses_1_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_1_address_lived_years').val() , value2: $('#LoanApplicationStepOne_addresses_1_address_lived_months').val(), action: 'save_address_lived_years', address_id: 2 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
// check for 3rd address too
if ($('#LoanApplicationStepOne_addresses_2_address_lived_years').val() != "" && $('#LoanApplicationStepOne_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_2_address_lived_years').val() , value2: $('#LoanApplicationStepOne_addresses_2_address_lived_months').val(), action: 'save_address_lived_years', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
}
});
});
$('#LoanApplicationStepOne_addresses_0_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_0_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
if (field_value != "" && field_value_2 != "") {
checkApplicantAddressHistoryValues();
}
// if this is first time it has been changed, remove the blank option at the top so the user cannot try and cheat it
// test 1. Is the first option blank?
if( $(this).find("option").eq(0).val() == "" ) { // yes, so remove it. Otherwise, nothing will be removed
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, action: 'save_address_lived_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
saveAddress1();
}
ga('send','pageview','/v2/apply/step-2');
ga('send','event','Application Form', 'Added address details', 'Loan Application - Step 2');
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
// we may need to adjust the move in date on previous addresses, if this is being changed.
if ($('#LoanApplicationStepOne_addresses_1_address_lived_years').val() != "" && $('#LoanApplicationStepOne_addresses_1_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_1_address_lived_months').val() , value2: $('#LoanApplicationStepOne_addresses_1_address_lived_years').val(), action: 'save_address_lived_months', address_id: 2 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
// check for 3rd address too.
var address2LivedYears = $('#LoanApplicationStepOne_addresses_2_address_lived_years').val();
var address2LivedMonths = $('#LoanApplicationStepOne_addresses_2_address_lived_months').val();
if (address2LivedYears != "" && typeof address2LivedYears !== 'undefined' && address2LivedMonths != "" && typeof address2LivedMonths !== 'undefined') {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_2_address_lived_months').val() , value2: $('#LoanApplicationStepOne_addresses_2_address_lived_years').val(), action: 'save_address_lived_months', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
ga('send','pageview','/v2/apply/step-2');
ga('send','event','Application Form', 'Edited address details', 'Loan Application - Step 2');
} else if( response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
}
});
});
/** ADDRESS 2 */
$('#LoanApplicationStepOne_addresses_1_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_1_address_building_name').parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_1_address_building_number').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_flat_number' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_1_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_name').val()) {
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
} else {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(1);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_1_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_1_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_1_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_name').val()) {
building_num_msg_box.html('At least one of these is required');
building_name_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_1_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_1_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_1_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_1_address_building_name').parent().prev();
var flat_msg_box = $('#LoanApplicationStepOne_addresses_1_address_flat_number').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_building_number' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_1_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_name').val()) {
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
} else {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(1);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_1_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_1_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_1_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_name').val()) {
flat_msg_box.html('At least one of these is required');
building_name_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_1_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_1_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_1_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_1_address_building_number').parent().prev();
var flat_msg_box = $('#LoanApplicationStepOne_addresses_1_address_flat_number').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_building_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_1_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_number').val()) {
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
} else {
message_box.html(' ');
$('#flat_no_2-error')[0].style.setProperty("display","none","important");
$('#building_no_2-error')[0].style.setProperty("display","none","important");
$('#building_name_2-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(1);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_1_address_flat_number').val() == "") {
flat_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_1_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_1_address_flat_number').val() && !$('#LoanApplicationStepOne_addresses_1_address_building_number').val()) {
flat_msg_box.html('At least one of these is required');
building_num_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_2-error').show();
$('#building_no_2-error').show();
$('#building_name_2-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_1_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_1_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_1_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#thouroughfare_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#thouroughfare_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#thouroughfare_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
$('#thouroughfare_2-error').show();
}
});
checkApplicantAddressFields(1);
});
$('#LoanApplicationStepOne_addresses_1_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#post_town_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#post_town_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#post_town_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
$('#post_town_2-error').show();
}
});
checkApplicantAddressFields(1);
});
$('#LoanApplicationStepOne_addresses_1_address_county').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 2, field_name: field_name, action: 'save_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(" ");
}
});
checkApplicantAddressFields(1);
});
$('#LoanApplicationStepOne_addresses_1_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode', address_id:2 }
).done( function(response) {
if( response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('Postcode is an invalid format!');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_postcode', address_id:2 }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#postcode_2-error')[0].style.setProperty("display","none","important");
saveAddress2();
} else if( response == 'success') {
message_box.html(' ');
$('#postcode_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#postcode_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
$('#postcode_2-error span').html(" This field is required!");
$('#postcode_2-error').show();
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#LoanApplicationStepOne_addresses_1_address_postcode').val(new_postcode);
}
});
checkApplicantAddressFields(1);
});
$('#LoanApplicationStepOne_addresses_1_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_1_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
if (field_value != "" && field_value_2 != "") {
checkApplicantAddressHistoryValues();
}
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, address_id: 2, value2: field_value_2, action: 'save_address_lived_years' }
).done(function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
saveAddress2();
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
// check for 3rd address
if ($('#LoanApplicationStepOne_addresses_2_address_lived_years').val() != "" && $('#LoanApplicationStepOne_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_2_address_lived_years').val() , value2: $('#LoanApplicationStepOne_addresses_2_address_lived_months').val(), action: 'save_address_lived_years', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
}
});
});
$('#LoanApplicationStepOne_addresses_1_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_1_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
if (field_value != "" && field_value_2 != "") {
checkApplicantAddressHistoryValues();
}
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
message_box.html(' ');
$.post(getAJAXUrl(),
{ value1: field_value, address_id: 2, value2: field_value_2, action: 'save_address_lived_months' }
).done(function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
saveAddress2();
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
// check for 3rd address
if ($('#LoanApplicationStepOne_addresses_2_address_lived_years').val() != "" && $('#LoanApplicationStepOne_addresses_2_address_lived_months').val() != "") {
$.post(getAJAXUrl(),
{ value1: $('#LoanApplicationStepOne_addresses_2_address_lived_months').val() , value2: $('#LoanApplicationStepOne_addresses_2_address_lived_years').val(), action: 'save_address_lived_months', address_id: 3 }
).done( function(response) {
// no response needed, all we're doing is adjusting the move in date.
});
}
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
}
});
});
/** ADDRESS 3 **/
$('#LoanApplicationStepOne_addresses_2_address_flat_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_2_address_building_number').parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_2_address_building_name').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_flat_number' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_2_address_building_name').val() && !$('#LoanApplicationStepOne_addresses_2_address_building_number').val()) {
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
} else {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(2);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_2_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_2_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_2_address_building_name').val() && !$('#LoanApplicationStepOne_addresses_2_address_building_number').val()) {
building_name_msg_box.html('At least one of these is required');
building_num_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_2_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_2_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_2_address_building_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
var flat_num_msg_box = $('#LoanApplicationStepOne_addresses_2_address_flat_number').parent().prev();
var building_name_msg_box = $('#LoanApplicationStepOne_addresses_2_address_building_name').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_building_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_2_address_building_name').val() && !$('#LoanApplicationStepOne_addresses_2_address_flat_number').val()) {
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
} else {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(2);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_2_address_building_name').val() == "") {
building_name_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_2_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_2_address_building_name').val() && !$('#LoanApplicationStepOne_addresses_2_address_flat_number').val()) {
building_name_msg_box.html('At least one of these is required');
flat_num_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_2_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_2_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_2_address_building_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
var building_num_msg_box = $('#LoanApplicationStepOne_addresses_2_address_building_number').parent().prev();
var flat_num_msg_box = $('#LoanApplicationStepOne_addresses_2_address_flat_number').parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_building_name' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
} else {
if (!$('#LoanApplicationStepOne_addresses_2_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_2_address_flat_number').val()) {
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
} else {
message_box.html(' ');
$('#flat_no_3-error')[0].style.setProperty("display","none","important");
$('#building_no_3-error')[0].style.setProperty("display","none","important");
$('#building_name_3-error')[0].style.setProperty("display","none","important");
}
}
});
checkApplicantAddressFields(2);
if(field_value.length > 0) {
if( $('#LoanApplicationStepOne_addresses_2_address_building_number').val() == "") {
building_num_msg_box.html(" ");
}
if( $('#LoanApplicationStepOne_addresses_2_address_flat_number').val() == "") {
flat_num_msg_box.html(" ");
}
} else { // this field is empty, so do a check to see if the others are too
if (!$('#LoanApplicationStepOne_addresses_2_address_building_number').val() && !$('#LoanApplicationStepOne_addresses_2_address_flat_number').val()) {
building_num_msg_box.html('At least one of these is required');
flat_num_msg_box.html('At least one of these is required');
message_box.html('At least one of these is required');
$('#flat_no_3-error').show();
$('#building_no_3-error').show();
$('#building_name_3-error').show();
// if all fields are blank, we need to re-disable the drop down
$('#LoanApplicationStepOne_addresses_2_address_lived_years').attr('disabled', true);
$('#LoanApplicationStepOne_addresses_2_address_lived_months').attr('disabled', true);
}
}
});
$('#LoanApplicationStepOne_addresses_2_address_thouroughfare').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_thouroughfare' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else if( response == 'noval') {
message_box.html('Required!');
}
});
checkApplicantAddressFields(2);
});
$('#LoanApplicationStepOne_addresses_2_address_post_town').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_post_town' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else if( response == 'noval') {
message_box.html('Required!');
}
});
checkApplicantAddressFields(2);
});
$('#LoanApplicationStepOne_addresses_2_address_county').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, address_id: 3, field_name: field_name, action: 'save_county' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
saveAddress3();
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
});
checkApplicantAddressFields(2);
});
$('#LoanApplicationStepOne_addresses_2_address_postcode').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_addresses_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
// check for validity, and if OK, re-format.
$.post(getAJAXUrl(),
{ postcode: field_value, action: 'format_postcode', address_id:3 }
).done( function(response) {
if (response == "Invalid") { // if it's invalid make sure to tell the user and stop from saving.
message_box.html('Postcode is an invalid format!');
$('#address-1-lived select').attr('disabled','disabled'); //disable the residency so the user cannot continue.
return false;
} else {
new_postcode = response; // if not invalid, the response will be the newly formatted postcode.
$.post(getAJAXUrl(),
{ value: new_postcode, action: 'save_postcode', address_id:3 }
).done(function(response) {
if (response == 'new') {
message_box.html(' ');
$('#postcode_3-error')[0].style.setProperty("display","none","important");
saveAddress3();
} else if (response == 'success') {
message_box.html(' ');
$('#postcode_3-error')[0].style.setProperty("display","none","important");
} else if (response == 'nochange') {
message_box.html(' ');
$('#postcode_3-error')[0].style.setProperty("display","none","important");
} else if (response == 'noval') {
message_box.html('Required!');
$('#postcode_3-error span').html(" This field is required!");
$('#postcode_3-error').show();
}
});
// since we have the correct format, re-populate the field with the nice one.
$('#LoanApplicationStepOne_addresses_2_address_postcode').val(new_postcode);
}
});
checkApplicantAddressFields(2);
});
$('#LoanApplicationStepOne_addresses_2_address_lived_years').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_2_address_lived_months').val();
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, address_id: 3, action: 'save_address_lived_years' }
).done( function(response) {
if ( response == 'new' ) {
if( !field_value_2 && field_value_2 !== 0 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
saveAddress3();
}
} else if( response == 'noval') {
message_box.html('Required!');
} else if( response == 'success') {
if( !field_value_2 && field_value_2 !== 0 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
} else if( response == 'nochange') {
if( !field_value_2 && field_value_2 !== 0 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
}
});
});
$('#LoanApplicationStepOne_addresses_2_address_lived_months').on( 'change', function() {
var field_value = $(this).val();
var field_value_2 = $('#LoanApplicationStepOne_addresses_2_address_lived_years').val();
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, address_id: 3, action: 'save_address_lived_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
saveAddress3();
message_box.html(' ');
$('#employment-detail').show();
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
$('#employment-detail').show();
}
} else if( response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
}
});
});
/** EMPLOYMENT FIELDS **/
$('#LoanApplicationStepOne_employments_0_employment_status').on( 'change', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var is_ok = false;
var show_unemployed = false;
var clear_down = true; // this determines whether or not to clear the existing values. Needed for triggering.
$('#LoanApplicationStepOne_employments_3_employment_status').val(field_value); // unemployment value should match
message_box.html(' ');
// make sure the user has not chosen "unemployed". Throw a warning and don't show the employer details.
if( field_value == 4) {
message_box.html('Sorry, you must have a regular income to apply for a loan');
message_box.next().addClass('has-error');
$('#employment_status-error span').html(" You must have a regular income to apply for a loan");
$('#employment_status-error i').removeClass('fa-chevron-up').addClass('fa-warning');
$('#employment_status-error').show();
is_ok = false;
$('#employer-1').hide();
$('#employer-2').hide();
$('#employer-3').hide();
$('#employer-unemployed').hide();
// just in case they've decided to change their employment status after they filled everything in, hide everything subsequent sections
hideBankDetails();
$('#guarantor-details').hide();
hideTermsAndConditions();
} else {
// check the status chosen in order to determine which part of the form to show.
if (field_value >= 5 && field_value <= 8 ) { // these are what are referred to as "unemployed" statuses but acceptable
show_unemployed = true;
$('#employer-1').hide();
$('#employer-2').hide();
$('#employer-3').hide();
} else {
$('#employer-unemployed').hide();
}
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_employment_status' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_status-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(0);
saveEmployment(1,employmentData);
is_ok = true;
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
$('#employment_status-error span').html(" This field is required!");
$('#employment_status-error i').removeClass('fa-warning').addClass('fa-chevron-up');
$('#employment_status-error').show();
is_ok = false;
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_status-error')[0].style.setProperty("display","none","important");
is_ok = true;
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_status-error')[0].style.setProperty("display","none","important");
is_ok = true;
clear_down = false;
}
if(is_ok) {
if( show_unemployed ) {
$('#employer-unemployed').show();
} else {
$('#employer-1').show();
}
} else {
if($('#employer-1').is(":visible")) {
$('#employer-1').hide();
}
if($('#employer-unemployed').is(":visible")) {
$('#employer-unemployed').hide();
}
}
if (clear_down == true) {
//console.log('clear down 4426');
// clear down the fields so the trigger can work.
$('#LoanApplicationStepOne_unemployed_income_source').val('');
$('#LoanApplicationStepOne_unemployed_net_income').val('');
$('#LoanApplicationStepOne_unemployed_employment_pay_frequency').val('');
// add the bouncing arrow to the now empty fields.
var message_box_1 = $('#LoanApplicationStepOne_unemployed_income_source').parent().prev();
var message_box_2 = $('#LoanApplicationStepOne_unemployed_net_income').parent().parent().prev();
var message_box_3 = $('#LoanApplicationStepOne_unemployed_employment_pay_frequency').parent().prev();
message_box_1.html(' Required field');
message_box_2.html(' Required field');
message_box_3.html(' Required field');
// hide the bank details section until the new values have been filled.
hideBankDetails();
}
});
}
});
/** DETAILS FOR 'UNEMPLOYED' STATUS CHOICES **/
$('#LoanApplicationStepOne_unemployed_income_source').on( 'change', function() {
//console.log('LoanApplicationStepOne_unemployed_income_source onChange');
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var employment_status_val = $('#LoanApplicationStepOne_employments_0_employment_status').val();
var mobile_message_box = $('#income_source-error');
//console.log('employment_status_val: ' + employment_status_val);
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_unemployed_income_source' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty("display","none","important");
} else if( response == 'noval') {
message_box.html('Required!');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty("display","none","important");
}
});
//check if the previous fields are populated before showing the next section.
if (checkUnemployedFields()) {
if($('#bank-details').not(":visible")) { // only slide it down if it's hidden
//console.log('showing because check unemployed fields');
showBankDetails();
}
} else {
hideBankDetails();
}
}
});
$('#LoanApplicationStepOne_unemployed_net_income').on( 'keyup', function() {
//console.log('LoanApplicationStepOne_unemployed_net_income onChange');
var field_value = $(this).val();
var message_box = $(this).parent().parent().prev();
var mobile_message_box = $('#monthly_income-error');
var employment_status_val = $('#LoanApplicationStepOne_employments_0_employment_status').val();
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_unemployed_net_income' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('Required!');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
//check if the previous fields are populated before showing the next section.
if( checkUnemployedFields() ) {
if($('#bank-details').not(":visible")) { // only slide it down if it's hidden
//console.log('showing because net income unemployed');
showBankDetails();
}
} else {
hideBankDetails();
}
}
});
// remove the 99 item that needs to be in for Symfony to validate, but shouldn't be shown to end user
$('#LoanApplicationStepOne_employments_0_employment_status option').each(function() {
if ( $(this).val() == 99 ) {
$(this).remove();
}
});
$('#GuarantorApplication_employments_0_employment_status option').each(function() {
if ( $(this).val() == 99 ) {
$(this).remove();
}
});
$('#LoanApplicationStepOne_unemployed_employment_pay_frequency').on( 'change', function() {
//console.log('LoanApplicationStepOne_unemployed_employment_pay_frequency onChange');
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var mobile_message_box = $('#pay_frequency-error');
var employment_status_val = $('#LoanApplicationStepOne_employments_0_employment_status').val();
if (employment_status_val > 4 && employment_status_val < 9) {
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_unemployed_pay_frequency' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'noval') {
message_box.html('Required!');
mobile_message_box.show();
} else if( response == 'success') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
} else if( response == 'nochange') {
message_box.html(' ');
mobile_message_box[0].style.setProperty('display','none','important');
}
});
//check if the previous fields are populated before showing the next section.
if (checkUnemployedFields()) {
if ($('#bank-details').not(":visible")) { // only slide it down if it's hidden
//console.log('unemployed pay freq');
showBankDetails();
}
} else {
hideBankDetails();
}
}
});
$('#LoanApplicationStepOne_employments_0_employer_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_employer_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employer_name_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
$('#employer_name_1-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employer_name_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employer_name_1-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_0_employer_name is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employment_type').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_type_1-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
$('#employment_type_1-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_type_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_type_1-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_0_employment_type is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employment_role').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_role_1-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
$('#employment_role_1-error').show();
} else if( response == 'success') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_role_1-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
message_box.next().removeClass('has-error');
$('#employment_role_1-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_0_employment_role is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employer_telephone').on( 'blur', function() {
//console.log('LoanApplicationStepOne_employments_0_employer_telephone validate');
var field_value = $(this).val();
var elem = $(this);
var message_box = $(this).parent().prev();
field_value = removeWhiteSpace(field_value);
$(this).val(field_value);
message_box.html(' ');
if( field_value == "") {
message_box.html('Required!');
$('#employer_telephone_1-error').show();
message_box.next().addClass('has-error');
return false;
}
if (validateLandline(elem,field_value)) { // validated OK.
$.post(getAJAXUrl(),
{ value: field_value, action: 'save_employer_telephone' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employer_telephone_1-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#employer_telephone_1-error').show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#employer_telephone_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#employer_telephone_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
//console.log('LoanApplicationStepOne_employments_0_employer_telephone is calling...');
checkEmployment(1);
});
} else {
return false;
}
});
$('#LoanApplicationStepOne_employments_0_employer_telephone_ext').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_employer_telephone_ext' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
} else if( response == 'success') {
message_box.html(' ');
} else if( response == 'nochange') {
message_box.html(' ');
} else {
message_box.html(' ');
}
//console.log('LoanApplicationStepOne_employments_0_employer_telephone_ext is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_net_income').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_net_income' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#net_income_1-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#net_income_1-error').show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#net_income_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#net_income_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
//console.log('LoanApplicationStepOne_employments_0_net_income is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employment_pay_frequency').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_employment_pay_frequency' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#pay_frequency_1-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#pay_frequency_1-error').show();
message_box.next().addClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#pay_frequency_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#pay_frequency_1-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
//console.log('LoanApplicationStepOne_employments_0_employment_pay_frequency is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_0_employment_months').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, action: 'save_employment_years' }
).done(function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
}
} else if (response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
//console.log('LoanApplicationStepOne_employments_0_employment_years is calling...');
checkEmployment(1);
});
});
$('#LoanApplicationStepOne_employments_0_employment_months').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_0_employment_years').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_0_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
$(this).find("option").eq(0).remove();
}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, action: 'save_employment_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(1);
saveEmployment(1,employmentData);
message_box.next().removeClass('has-error');
ga('send','pageview','/v2/apply/step-3');
ga('send','event','Application Form', 'Added income and employment details', 'Loan Application - Step 3');
}
} else if( response == 'noval') {
message_box.html('Required!');
message_box.next().addClass('has-error');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
ga('send','pageview','/v2/apply/step-3');
ga('send','event','Application Form', 'Added income and employment details', 'Loan Application - Step 3');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
message_box.next().addClass('has-error');
} else {
message_box.html(' ');
message_box.next().removeClass('has-error');
}
}
//console.log('LoanApplicationStepOne_employments_0_employment_months is calling...');
checkEmployment(1);
});
});
/** EMPLOYMENT 2 INDIVIDUAL FIELDS **/
$('#LoanApplicationStepOne_employments_1_employer_name').on( 'blur', function() {
//console.log('changed LoanApplicationStepOne_employments_1_employer_name');
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 2, action: 'save_employer_name' }
).done( function(response) {
if (response == 'new') {
message_box.html(' ');
$('#employer_name_2-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(2);
//console.log(employmentData);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employer_name_2-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employer_name_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employer_name_2-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_1_employer_name is calling...');
checkEmployment(2);
});
});
$('#LoanApplicationStepOne_employments_1_employment_type').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 2, action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_type_2-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employment_type_2-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employment_type_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employment_type_2-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_1_employment_type is calling...');
checkEmployment(2);
});
});
$('#LoanApplicationStepOne_employments_1_employment_role').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_1_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 2, action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_role_2-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employment_role_2-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employment_role_2-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employment_role_2-error')[0].style.setProperty("display","none","important");
}
//console.log('LoanApplicationStepOne_employments_1_employment_role is calling...');
checkEmployment(2);
});
});
$('#LoanApplicationStepOne_employments_1_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_1_employment_months').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_1_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
//if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
// $(this).find("option").eq(0).remove();
//}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, employment_id: 2, action: 'save_employment_years' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0 ) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
}
//console.log('LoanApplicationStepOne_employments_1_employment_years is calling...');
checkEmployment(2);
});
});
$('#LoanApplicationStepOne_employments_1_employment_months').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_1_employment_years').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_1_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
//if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
// $(this).find("option").eq(0).remove();
//}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, employment_id: 2, action: 'save_employment_months' }
).done( function(response) {
if (response == 'new') { // if it's new, at this point we need to save all details.
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(2);
saveEmployment(2,employmentData);
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0 ) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
}
//console.log('LoanApplicationStepOne_employments_1_employment_months is calling...');
checkEmployment(2);
});
});
/** EMPLOYMENT 3 INDIVIDUAL FIELDS **/
$('#LoanApplicationStepOne_employments_2_employer_name').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 3, action: 'save_employer_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employer_name_3-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employer_name_3-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employer_name_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employer_name_3-error')[0].style.setProperty("display","none","important");
}
});
checkEmployment(3);
});
$('#LoanApplicationStepOne_employments_2_employment_type').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 3, action: 'save_employment_type' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_type_3-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employment_type_3-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employment_type_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employment_type_3-error')[0].style.setProperty("display","none","important");
}
checkEmployment(3);
});
});
$('#LoanApplicationStepOne_employments_2_employment_role').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_employments_2_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, employment_id: 3, action: 'save_employment_role' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#employment_role_3-error')[0].style.setProperty("display","none","important");
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
} else if( response == 'noval') {
message_box.html('Required!');
$('#employment_role_3-error').show();
} else if( response == 'success') {
message_box.html(' ');
$('#employment_role_3-error')[0].style.setProperty("display","none","important");
} else if( response == 'nochange') {
message_box.html(' ');
$('#employment_role_3-error')[0].style.setProperty("display","none","important");
}
checkEmployment(3);
});
});
$('#LoanApplicationStepOne_employments_2_employment_years').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_2_employment_months').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_2_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
//if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
// $(this).find("option").eq(0).remove();
//}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, employment_id: 3, action: 'save_employment_years' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, months is still blank, show a friendly notice
message_box.html('Please select months');
} else {
message_box.html(' ');
}
}
checkEmployment(3);
});
});
$('#LoanApplicationStepOne_employments_2_employment_months').on('change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_value_2 = $('#LoanApplicationStepOne_employments_2_employment_years').val();
var field_name = field_id.replace("LoanApplicationStepOne_employments_2_","");
var message_box = $(this).parent().parent().prev();
message_box.html(' ');
//if( $(this).find("option").eq(0).val() == "" ) { // if the first option is still the default, remove it so it cannot be selected again
// $(this).find("option").eq(0).remove();
//}
$.post(getAJAXUrl(),
{ value1: field_value, value2: field_value_2, field_name: field_name, employment_id: 3, action: 'save_employment_months' }
).done( function(response) {
if (response == 'new') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
var employmentData = getEmploymentData(3);
saveEmployment(3,employmentData);
}
} else if (response == 'noval') {
message_box.html('Required!');
} else if (response == 'success') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
} else if (response == 'nochange') {
if (!field_value_2 && field_value_2 !== 0) { // if at this point, years is still blank, show a friendly notice
message_box.html('Please select years');
} else {
message_box.html(' ');
}
}
checkEmployment(3);
});
});
/** BANK DETAILS UPDATE SERVICES **/
$('.sort-code-fields input').on( 'blur', function() {
var first = $('#LoanApplicationStepOne_bank_identifier').val();
var second = $('#LoanApplicationStepOne_internal_identifier_first').val();
var third = $('#LoanApplicationStepOne_internal_identifier_second').val();
var message_box = $('.sort-code-fields').parent().prev();
var formData = $('#applicant-form-step-1').serialize(); // this is for the guarantor checks further down.
var account_number = $('#LoanApplicationStepOne_bank_account_number').val();
var first_len = (''+first).length;
var second_len = (''+second).length;
var third_len = (''+third).length;
// only attempt to save if all boxes are correct length and are numerals.
if(first_len == 2 && second_len == 2 && third_len == 2 && $.isNumeric(first) && $.isNumeric(second) && $.isNumeric(third)) {
message_box.html(' ');
var field_value = first+second+third;
var field_name = 'bank_account_sortcode';
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_sort_code' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#sortcode-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#sortcode-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#sortcode-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'invalid') {
message_box.html('Sortcode is invalid!');
message_box.next().addClass('has-error');
$('#sortcode-error').show();
$('#guarantor-details').hide(); //in case it's showing from a previous successful validation.
return false;
}
// before showing guarantor details, make sure the account number is filled in AND valid.
if( checkBankAccountNumber(account_number) ) {
// do all the guarantor checks.
$.post(getAJAXUrl(),
{ form_data: formData, action: 'check_guarantor_status' }
).done( function(response) {
if(response == 'OK') {
//ToDo: dont show GT stage, but show next
if ( $('#guarantor-details').attr('data-unsecured') != '1'){
$('#guarantor-details').show();
}
else{
$('#terms-validation').show();
}
}
}
);
} else {
//console.log('hide t and c');
hideTermsAndConditions();
return false;
}
});
} else {
//console.log('hide t and c');
hideTermsAndConditions();
// check to see if the user has entered any alpha characters.
if( (first_len > 0 && !$.isNumeric(first)) || (second_len > 0 && !$.isNumeric(second)) || (third_len > 0 && !$.isNumeric(third)) ) {
message_box.html('Sort code must be numeric!');
message_box.next().addClass('has-error');
$('#sortcode-error span').html(' Sort code must be numeric!');
$('#sortcode-error').show();
} else {
message_box.html('Sort code must be 6 digits');
$('#sortcode-error span').html(' Sort code must be 6 digits');
$('#sortcode-error').show();
message_box.next().addClass('has-error');
$('#guarantor-details').hide(); //in case it's showing from a previous successful validation.
}
return false; // don't go any further if it fails.
}
// do a check here, as they might have already filled their account number in.
if($('#LoanApplicationStepOne_bank_account_number').val() != "" ) {
$.post(getAJAXUrl(),
{ form_data: formData, action: 'check_guarantor_status' }
).done( function(response) {
if(response == 'OK') {
if(response == 'OK') {
//ToDo: dont show GT stage, but show next
if ( $('#guarantor-details').attr('data-unsecured') != '1'){
$('#guarantor-details').show();
}
else{
$('#terms-validation').show();
}
}
}
}
);
} else {
if($('#guarantor-details').is(":visible")) {
$('#guarantor-details').hide();
}
}
return false;
});
$('#LoanApplicationStepOne_bank_account_number').on( 'keyup', function() {
var field_value = $(this).val();
var message_box = $(this).parent().prev();
var formData = $('#applicant-form-step-1').serialize(); // this is for the guarantor checks further down.
// get sort code data
var sc_first = $('#LoanApplicationStepOne_bank_identifier').val();
var sc_second = $('#LoanApplicationStepOne_internal_identifier_first').val();
var sc_third = $('#LoanApplicationStepOne_internal_identifier_second').val();
var sort_code = sc_first+sc_second+sc_third;
// has the user entered an alpha character?
if(field_value.length > 0 && !$.isNumeric(field_value)) { // only check it if there are characters entered or it will throw this error when blank.
message_box.html('Account number must be numeric!');
$('#bank_account-error span').html(' Account number must be numeric!');
$('#bank_account-error').show();
message_box.next().addClass('has-error');
return false;
}
if(field_value.length == 8) { // 8 digits only
message_box.html(' ');
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_","");
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_account_number' }
).done( function(response) {
if( response == 'new' ) {
message_box.html(' ');
$('#bank_account-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'success') {
message_box.html(' ');
$('#bank_account-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#bank_account-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'invalid') {
message_box.html('Account number needs to be 8 digits!');
$('#bank_account-error span').html(' Account number needs to be 8 digits!');
$('#bank_account-error').show();
message_box.next().addClass('has-error');
hideTermsAndConditions();
} else if( response == 'noval') {
message_box.html('Account number is required!');
$('#bank_account-error span').html(' Account number is required!');
$('#bank_account-error').show();
message_box.next().addClass('has-error');
hideTermsAndConditions();
}
// before showing guarantor details, make sure the sort code is filled in AND valid.
if( checkBankSortCode(sort_code) ) {
// do all the guarantor checks.
$.post(getAJAXUrl(),
{ form_data: formData, action: 'check_guarantor_status' }
).done( function(response) {
if(response == 'OK') {
//ToDo: dont show GT stage, but show next
if ( $('#guarantor-details').attr('data-unsecured') != '1'){
$('#guarantor-details').show();
}
else{
$('#terms-validation').show();
}
} else {
hideTermsAndConditions();
}
}
);
} else {
hideTermsAndConditions();
}
});
} else {
message_box.html('Account number needs to be 8 digits');
message_box.next().addClass('has-error');
$('#bank_account-error span').html(' Account number needs to be 8 digits!');
$('#bank_account-error').show();
if($('#guarantor-details').is(":visible")) {
$('#guarantor-details').hide();
}
hideTermsAndConditions();
}
return false;
});
/** GUARANTOR SAVE & UPDATE **/
//console.log('#LoanApplicationStepOne_guarantor_edit.val() = ' + $('#LoanApplicationStepOne_guarantor_edit').val());
if ($('#LoanApplicationStepOne_guarantor_edit').val() == 0) {
//console.log('LoanApplicationStepOne_guarantor_edit is called');
$('.form-step-5 input, .form-step-5 select').on( 'change', function() {
var g_first_name = $('#LoanApplicationStepOne_loan_application_guarantors_0_first_name').val();
var g_surname = $('#LoanApplicationStepOne_loan_application_guarantors_0_surname').val();
var g_age = $('#LoanApplicationStepOne_loan_application_guarantors_0_applicant_confirmed_age').val();
var g_mobile_number = $('#LoanApplicationStepOne_loan_application_guarantors_0_mobile_number').val();
var g_email = $('#LoanApplicationStepOne_loan_application_guarantors_0_email').val();
var g_relation = $('#LoanApplicationStepOne_loan_application_guarantors_0_applicant_relation').val();
var guarantor_details = {
'first_name':g_first_name,
'surname':g_surname,
'applicant_confirmed_age':g_age,
'mobile_number':g_mobile_number,
'email':g_email,
'applicant_relation':g_relation
};
if (g_first_name && g_surname && g_age && g_mobile_number && g_email && g_relation) {
saveGuarantor(guarantor_details);
}
return false;
});
}
// once the guarantor details are completed, allow user to edit if necessary.
$('#LoanApplicationStepOne_loan_application_guarantors_0_first_name').on( 'blur', function() {
//console.log('#LoanApplicationStepOne_loan_application_guarantors_0_first_name on blur');
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_guarantors_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_guarantor_first_name' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#guarantor_first_name-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#guarantor_first_name-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
} else if( response == 'success') {
message_box.html(' ');
$('#guarantor_first_name-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#guarantor_first_name-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
});
checkGuarantorRequiredFields();
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_surname').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_guarantors_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_guarantor_surname' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#guarantor_surname-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#guarantor_surname-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
} else if( response == 'success') {
message_box.html(' ');
$('#guarantor_surname-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#guarantor_surname-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
});
checkGuarantorRequiredFields();
});
// as long as the guarantor email field is filled on page load, trigger a keyup in order to
// be able to run a check on the email entered
if($('#LoanApplicationStepOne_loan_application_guarantors_0_email').val() != "") {
var message_box = $($('#LoanApplicationStepOne_loan_application_guarantors_0_email')).parent().prev();
var field_value = $('#LoanApplicationStepOne_loan_application_guarantors_0_email').val();
var form_data = $('#applicant-form-step-1').serialize();
checkGuarantorEmail(field_value, form_data, message_box);
}
$('#LoanApplicationStepOne_loan_application_guarantors_0_email').on( 'keyup', function(e) {
var field_value = $(this).val();
var form_data = $('#applicant-form-step-1').serialize();
var message_box = $(this).parent().prev();
if (field_value.length > 5) {
if (validateEmail(field_value)) { // this checks valid format
// do check.
message_box.html('Authenticating...');
message_box.next().removeClass('has-error');
$('#guarantor_email-error')[0].style.setProperty('display','none','important');
checkGuarantorEmail(field_value, form_data, message_box);
e.preventDefault();
} else {
message_box.html('Incorrect format');
$('#guarantor_email-error span').html(" Incorrect format");
$('#guarantor_email-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
}
} else {
if (!field_value) {
message_box.html(' Required field');
message_box.next().addClass('has-error');
$('#guarantor_email-error span').html(" This is a required field!");
$('#guarantor_email-error').show();
} else {
message_box.html('Too short');
$('#guarantor_email-error span').html(" Too short!");
$('#guarantor_email-error').show();
message_box.next().addClass('has-error');
}
}
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_mobile_number').on( 'blur', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_guarantors_0_","");
var message_box = $(this).parent().prev();
field_value = removeWhiteSpace(field_value);
$(this).val(field_value);
var validation = validateMobile(message_box,field_value,'guarantor');
if (validation) {
message_box.html(' ');
// do a dedupe test first
$.post(getAJAXUrl(),
{ number: field_value, mobile_type: 'guarantor', action: 'check_mobile_dupe'}
).done( function(response) {
if (response == 1) {
message_box.html('There was a problem using this mobile number. Please use an alternative or contact us');
$('#guarantor_mobile-error span').html(" There was a problem using this mobile number. Please use an alternative or contact us");
$('#guarantor_mobile-error').show();
$('#terms-validation').hide();
message_box.next().addClass('has-error');
return false;
} else if (response == 'invalid') {
message_box.html('Invalid number!');
$('#guarantor_mobile-error span').html(" Number is invalid!");
$('#guarantor_mobile-error').show();
$('#terms-validation').hide();
message_box.next().addClass('has-error');
return false;
} else if (response == 'own_number') {
message_box.html('Cannot use the same mobile number for guarantor.');
$('#guarantor_mobile-error span').html(" Cannot use the same mobile number for guarantor");
$('#guarantor_mobile-error').show();
$('#terms-validation').hide();
message_box.next().addClass('has-error');
return false;
} else {
$.post(getAJAXUrl(),
{ value: field_value, field: field_name, action: 'save_guarantor_mobile_number' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#guarantor_mobile-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#guarantor_mobile-error span').html(" This field is required!");
$('#guarantor_mobile-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
} else if( response == 'success') {
message_box.html(' ');
$('#guarantor_mobile-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#guarantor_mobile-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else {
message_box.html('Sorry! This mobile number could not be validated');
$('#guarantor_mobile-error span').html(" Sorry! This mobile number could not be validated");
$('#guarantor_mobile-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
}
});
checkGuarantorRequiredFields();
}
});
} else {
$('#terms-validation').hide(); // hide the terms section if the number is invalid.
}
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_applicant_confirmed_age').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_guarantors_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_guarantor_confirmed_age' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$('#confirmed_age-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$('#confirmed_age-error span').html(" This field is required!");
$('#confirmed_age-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
} else if( response == 'success') {
message_box.html(' ');
$('#confirmed_age-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$('#confirmed_age-error')[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'tooyoung') {
message_box.html('Guarantor must be over 21!');
$('#confirmed_age-error span').html(" Guarantor must be over 21!");
$('#confirmed_age-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
}
});
checkGuarantorRequiredFields();
});
$('#LoanApplicationStepOne_loan_application_guarantors_0_applicant_relation').on( 'change', function() {
var field_value = $(this).val();
var field_id = $(this).attr('id');
var field_name = field_id.replace("LoanApplicationStepOne_loan_application_guarantors_0_","");
var message_box = $(this).parent().prev();
message_box.html(' ');
$.post(getAJAXUrl(),
{ value: field_value, field_name: field_name, action: 'save_guarantor_relation' }
).done( function(response) {
if ( response == 'new' ) {
message_box.html(' ');
$("#guarantor_relation-error")[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'noval') {
message_box.html('Required!');
$("#guarantor_relation-error span").html(" This field is required!");
$('#guarantor_relation-error').show();
message_box.next().addClass('has-error');
$('#terms-validation').hide();
return false;
} else if( response == 'success') {
message_box.html(' ');
$("#guarantor_relation-error")[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
} else if( response == 'nochange') {
message_box.html(' ');
$("#guarantor_relation-error")[0].style.setProperty("display","none","important");
message_box.next().removeClass('has-error');
}
checkGuarantorRequiredFields();
});
});
/** TERMS & CONDITIONS SECTION **/
$('#LoanApplicationStepOne_final_terms_conditions_accepted').on('change', function() {
var validationCodeInput = $('#LoanApplicationStepOne_SmsRequests_0_validation_code');
var validationSection = $('#validation-section');
validationCodeInput.val(''); // ensure the sms code field is always emptied
if($(this).val() == 1) {
$.post(getAJAXUrl(),
{ accepted: 1, action: 'save_terms_conditions' }
).done( function(response) {
if(response == 'OK') {
// all agreed, so show verification section
if(validationSection.not(":visible")) {
validationSection.show();
}
} else if ((/^\d{4}$/).test(response)) {
// We already have a code, so populate it.
validationCodeInput.val(response);
validationSection.show();
validationCodeInput.trigger('keyup');
}
});
$('#verify-message').html(' Required field');
} else {
// if, for some weird reason, the customer has unchecked the terms checkbox, make sure to nullify the entry.
$.post(getAJAXUrl(),
{ accepted: 0, action: 'save_terms_conditions' }
).done( function(response) {
if(response == 'OK') {
// for some reason, decided not to accept? Close the validation section
if( validationSection.is(":visible")) {
validationSection.hide();
}
}
}
);
$('#verify-message').html(' ');
}
});
$('#LoanApplicationStepOne_SmsRequests_0_validation_code').on('keyup', function() {
$('#validation-error').html('');
var code_length = $(this).val().length;
if (code_length == 4) { //the correct length for a validation code.
$('#LoanApplicationStepOne_save').removeAttr('disabled').removeClass('btn-disabled').addClass('btn-primary');
$('#verify-message').html(' ');
} else {
$('#LoanApplicationStepOne_save').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
$('#verify-message').html('Must be 4 digits');
}
});
/** FOR DYNAMICALLY APPEARING FORM FIELDS **/
$('#LoanApplicationStepOne_save').on( 'click', function(e) {
$('#existing-user-password').hide();
$('#address-detail').show();
$('#marital').show(); //show the marital status box to begin with.
e.preventDefault();
});
$('#LoanApplicationStepOne_marital_status').on( 'change', function(e) {
if($(this).val().length > 0) {
$('#dependants').show();
} else {
if($('#dependants').is(':visible')) {
$('#dependants').hide();
}
}
e.preventDefault();
});
$('#dependants input').on( 'keyup', function() {
if($(this).val().length > 0 && checkNumber($(this).val())) {
$('#home-phone').show(); // because home phone is not required, make the housing status appear too
$('#housing-status').show();
} else {
if($('#home-phone').is(':visible')) {
$('#home-phone').hide();
$('#housing-status').hide();
}
}
});
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').on( 'keyup', function() {
if($(this).val().length > 0 && $.isNumeric($(this).val())) {
$('#other-outgoings').show();
} else {
if($('#other-outgoings').is(':visible')) {
$('#other-outgoings').hide();
}
}
});
$('#LoanApplicationStepOne_addresses_0_rent_cost').on( 'keyup', function() {
if($(this).val().length > 0 && $.isNumeric($(this).val()) ) {
$('#other-outgoings').show();
} else {
if($('#other-outgoings').is(':visible')) {
$('#other-outgoings').hide();
}
}
});
$('#other-outgoings input').on( 'keyup', function() {
if($(this).val().length > 0 && $.isNumeric($(this).val())) {
$('#address-1').show();
} else {
if($('#address-1').is(':visible')) {
$('#address-1').hide();
}
}
});
/** SHOW RELEVANT BOX FOR RENT/MORTGAGE DEPENDING ON CHOSEN HOUSING STATUS **/
// Housing status - mortgage/rent toggle - THIS IS FOR THE NEW FORM.
//$('#LoanApplicationStepOne_addresses_0_housing_status').on( 'click', function() {
$('#LoanApplicationStepOne_addresses_0_housing_status').on( 'change', function() {
//$('#LoanApplicationStepOne_addresses_0_rent_cost').parents('.field').find('.message').html(' ');
//$('#LoanApplicationStepOne_addresses_0_rent_cost, #LoanApplicationStepOne_addresses_0_mortgage_cost').val('');
if ($(this).val() == '') {
$('#LoanApplicationStepOne_addresses_0_rent_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepOne_addresses_0_mortgage_cost:visible').parents('.field').slideUp();
clearMortgageInputBox();
clearRentInputBox();
}
else if ($(this).val() == 1) {
$('#LoanApplicationStepOne_addresses_0_rent_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').parents('.field').slideDown();
clearRentInputBox();
}
else {
$('#LoanApplicationStepOne_addresses_0_mortgage_cost:visible').parents('.field').slideUp();
$('#LoanApplicationStepOne_addresses_0_rent_cost').parents('.field').slideDown();
clearMortgageInputBox();
}
if ($(this).val() == 7) {
$('#LoanApplicationStepOne_addresses_0_rent_cost').parents('.field').find('.message').html('For shared ownership only enter rental amount');
clearMortgageInputBox();
}
});
//});
function clearMortgageInputBox() {
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').val("");
}
function clearRentInputBox() {
$('#LoanApplicationStepOne_addresses_0_rent_cost').val("");
}
if ($('#applicant-form-step-1').length > 0) {
if( $('#housing-status').is(":visible") ) {
$('#LoanApplicationStepOne_addresses_0_housing_status').trigger('change');
if($('#LoanApplicationStepOne_addresses_0_rent_cost').is(":visible") && $('#LoanApplicationStepOne_addresses_0_rent_cost').val() != "") {
$('#LoanApplicationStepOne_addresses_0_rent_cost').trigger('keyup');
} else if ($('#LoanApplicationStepOne_addresses_0_mortgage_cost').is(":visible") && $('#LoanApplicationStepOne_addresses_0_mortgage_cost').val() != "") {
$('#LoanApplicationStepOne_addresses_0_mortgage_cost').trigger('keyup');
}
}
}
/** BY DEFAULT, SHOW ADDRESS DETAIL BLOCK **/
$('#address-detail').show();
/** SETS UP FORM WHEN LOGGED IN, TO DETERMINE WHAT FIELD WAS ENTERED LAST TIME - NOT RELEVANT AT THE MOMENT **/
// set up array of ids relating to form inputs
var inputBoxIds = {
1:'marital|select',
2:'dependants|input',
3:'housing-status|select',
4:'v2-rent-cost|input',
5:'v2-mortgage-cost|input',
6:'other-outgoings|input',
7:'home-phone|input',
8:'address-1-lived|select',
9:'address-2-lived|select',
10:'address-3-lived|select',
11:'employment-status|select',
12:'employment-1-length|select',
13:'employment-2-length|select',
14:'employment-3-length|select',
15:'account-number|input',
16:'guarantor-relation|select',
17:'unemployment-pay-frequency|select',
18:'guarantor-employment-1-length|select',
19:'guarantor-employment-2-length|select',
20:'guarantor-employment-3-length|select'
};
var boxCount = Object.keys(inputBoxIds).length;
$('#marital').show(); // this needs to be visible just in case it's not populated, as there is no trigger if the page reloads
$('#dependants').hide();
$('#housing-status').hide();
$('#other-outgoings').hide();
$('#home-phone').hide();
$('#address-1').hide();
$('#employment-detail').hide();
hideBankDetails();
$('#guarantor-details').hide();
hideTermsAndConditions();
$('#employer-1').hide();
$('#employer-unemployed').hide();
//$('#LoanApplicationStepOne_SmsRequests_0_validation_code').attr('disabled','disabled');
$('#LoanApplicationStepOne_save').attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
// if($('#LoanApplicationStepOne_final_terms_conditions_accepted').is(":checked")) {
// $('#LoanApplicationStepOne_SmsRequests_0_validation_code').removeAttr('disabled');
// }
if ($('#guarantor-form-step-1').length > 0) {
checkGuarantorAddressHistoryValues();
} else {
checkApplicantAddressHistoryValues();
}
$('#LoanApplicationStepOne_SmsRequests_0_validation_code').trigger('keyup'); // to check if sms code has been entered on reload
for (var i=1;i<=boxCount;i++) {
var inputArr = inputBoxIds[i].split('|');
if( $('#'+inputArr[0]+' '+inputArr[1]).val() != "" ) {
$('#'+inputArr[0]).show();
if (inputArr[1] == "input") {
if($('#'+inputArr[0]+' input').val() != "") {
$('#'+inputArr[0]+' input').trigger('keyup');
}
} else if (inputArr[1] == "select") {
if ($('#'+inputArr[0]+' select').val() != "") {
$('#'+inputArr[0]+' select').trigger('change');
}
}
} else {
// carry on
}
}
$('#LoanApplicationStepOne_save').on( 'click', function(e) {
$(this).attr('disabled','disabled').addClass('btn-disabled').removeClass('btn-primary');
var entered_code = $('#LoanApplicationStepOne_SmsRequests_0_validation_code').val();
if( !entered_code ) { return false; } // this accounts for iPhones if the user does not click Done after entering the code
var error_box = $('#validation-error');
var message_box = $(this).next();
message_box.html('Verifying mobile code...');
$.post(getAJAXUrl(),
{ code: entered_code, action: 'check_verification_code' }
).done( function(response) {
if (response == "limit_reached") { // more than 5 SMS codes sent
error_box.html('You have already reached your maximum verification code attempts. Please contact us.');
message_box.html('');
} else if(response == "incorrect") { // code does not match the db
error_box.html('The verification code you entered is not valid. Please try again or request a new one.');
message_box.html('');
} else if(response == "OK") {
// add a loader to let the user know it's doing something!
message_box.html('Redirecting to WorldPay, please wait a moment...');
$('#applicant-form-step-1').submit(); // submit the form
}
});
e.preventDefault();
});
$('#LoanApplicationStepOne_send_sms_verification_code_submit').on( 'click', function(e) {
var message_box = $('.new_mobile_error');
var mobile_num = $('#LoanApplicationStepOne_new_mobile').val(); // this is now the mobile number to send the sms to
//mobile_num = mobile_num.replace('+44','0'); // remove the +44 and replace with a zero. For some reason, sms will only send this way
// do some basic checks first.
var validation = validateMobile(message_box,mobile_num);
if( validation ) {
// do a dupe check as well.
$.post(getAJAXUrl(),
{ number: mobile_num, action: 'check_mobile_dupe',person_type: 'applicant'}
).done( function(response) {
message_box.css('margin','12px 0 10px 2px');
if (response == 1) {
message_box.html(' It looks like this mobile number may already be attached to an account. Please use an alternative or contact us');
return false;
} else if (response == 'invalid') {
message_box.html(' Invalid mobile number!');
} else {
$.post(getAJAXUrl(),
{ person_type: 'applicant', mobile_number: mobile_num, action: 'resend_verification_code' }
).done( function(response) {
if(response == 'OK') {
message_box.html(' New verification code sent to '+mobile_num+'');
} else if( response == 'noval') {
message_box.html(' Please enter a mobile number!');
} else if( response == 'invalid') {
message_box.html(' This mobile number could not be validated. Please call us on 01225 941 941.');
} else {
message_box.html(' Sorry! An error occurred. Please call 01225 941 941 and we will try and resolve the issue.');
}
});
}
});
}
e.preventDefault();
});
$('#LoanApplicationStepOne_SmsRequests_0_validation_code').val('');
// remove employments 0 - 2 if applicant has select none standard employment
// this gets rid of mashed up address 0 and address 3 - should the applicant have changed their mind when
// filling in the form
$('#applicant-form-step-1').submit(function(event) {
var selected_employment_status = $('#LoanApplicationStepOne_employments_0_employment_status').val();
selected_employment_status = parseInt(selected_employment_status);
var none_standard_employment_statuses = [5,6,7,8];
if ($.inArray(selected_employment_status, none_standard_employment_statuses) == -1) {
return; // ignore, this was a standard employment type
}
// remove the standard employments so as not to skew the input
$('#employer-1').remove();
$('#employer-2').remove();
$('#employer-3').remove();
});
// remove employments 0 - 2 if applicant has select none standard employment
// this gets rid of mashed up address 0 and address 3 - should the applicant have changed their mind when
// filling in the form
$('#guarantor-form-step-1').submit(function(event) {
var selected_employment_status = $('#GuarantorApplication_employments_0_employment_status').val();
selected_employment_status = parseInt(selected_employment_status);
var none_standard_employment_statuses = [5,6,7,8];
if ($.inArray(selected_employment_status, none_standard_employment_statuses) == -1) {
return; // ignore, this was a standard emmployment type
}
// remove the standard employments so as not to skew the input
$('#employer-1').remove();
$('#employer-2').remove();
$('#employer-3').remove();
});
});
}
/*!
* jQuery Validation Plugin v1.14.0
*
* http://jqueryvalidation.org/
*
* Copyright (c) 2015 Jörn Zaefferer
* Released under the MIT license
*/
(function( factory ) {
if ( typeof define === "function" && define.amd ) {
define( ["jquery"], factory );
} else {
factory( jQuery );
}
}(function( $ ) {
$.extend($.fn, {
// http://jqueryvalidation.org/validate/
validate: function( options ) {
// if nothing is selected, return nothing; can't chain anyway
if ( !this.length ) {
if ( options && options.debug && window.console ) {
console.warn( "Nothing selected, can't validate, returning nothing." );
}
return;
}
// check if a validator for this form was already created
var validator = $.data( this[ 0 ], "validator" );
if ( validator ) {
return validator;
}
// Add novalidate tag if HTML5.
this.attr( "novalidate", "novalidate" );
validator = new $.validator( options, this[ 0 ] );
$.data( this[ 0 ], "validator", validator );
if ( validator.settings.onsubmit ) {
this.on( "click.validate", ":submit", function( event ) {
if ( validator.settings.submitHandler ) {
validator.submitButton = event.target;
}
// allow suppressing validation by adding a cancel class to the submit button
if ( $( this ).hasClass( "cancel" ) ) {
validator.cancelSubmit = true;
}
// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if ( $( this ).attr( "formnovalidate" ) !== undefined ) {
validator.cancelSubmit = true;
}
});
// validate the form on submit
this.on( "submit.validate", function( event ) {
if ( validator.settings.debug ) {
// prevent form submit to be able to see console output
event.preventDefault();
}
function handle() {
var hidden, result;
if ( validator.settings.submitHandler ) {
if ( validator.submitButton ) {
// insert a hidden input as a replacement for the missing submit button
hidden = $( "" )
.attr( "name", validator.submitButton.name )
.val( $( validator.submitButton ).val() )
.appendTo( validator.currentForm );
}
result = validator.settings.submitHandler.call( validator, validator.currentForm, event );
if ( validator.submitButton ) {
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden.remove();
}
if ( result !== undefined ) {
return result;
}
return false;
}
return true;
}
// prevent submit for invalid forms or custom submit handlers
if ( validator.cancelSubmit ) {
validator.cancelSubmit = false;
return handle();
}
if ( validator.form() ) {
if ( validator.pendingRequest ) {
validator.formSubmitted = true;
return false;
}
return handle();
} else {
validator.focusInvalid();
return false;
}
});
}
return validator;
},
// http://jqueryvalidation.org/valid/
valid: function() {
var valid, validator, errorList;
if ( $( this[ 0 ] ).is( "form" ) ) {
valid = this.validate().form();
} else {
errorList = [];
valid = true;
validator = $( this[ 0 ].form ).validate();
this.each( function() {
valid = validator.element( this ) && valid;
errorList = errorList.concat( validator.errorList );
});
validator.errorList = errorList;
}
return valid;
},
// http://jqueryvalidation.org/rules/
rules: function( command, argument ) {
var element = this[ 0 ],
settings, staticRules, existingRules, data, param, filtered;
if ( command ) {
settings = $.data( element.form, "validator" ).settings;
staticRules = settings.rules;
existingRules = $.validator.staticRules( element );
switch ( command ) {
case "add":
$.extend( existingRules, $.validator.normalizeRule( argument ) );
// remove messages from rules, but allow them to be set separately
delete existingRules.messages;
staticRules[ element.name ] = existingRules;
if ( argument.messages ) {
settings.messages[ element.name ] = $.extend( settings.messages[ element.name ], argument.messages );
}
break;
case "remove":
if ( !argument ) {
delete staticRules[ element.name ];
return existingRules;
}
filtered = {};
$.each( argument.split( /\s/ ), function( index, method ) {
filtered[ method ] = existingRules[ method ];
delete existingRules[ method ];
if ( method === "required" ) {
$( element ).removeAttr( "aria-required" );
}
});
return filtered;
}
}
data = $.validator.normalizeRules(
$.extend(
{},
$.validator.classRules( element ),
$.validator.attributeRules( element ),
$.validator.dataRules( element ),
$.validator.staticRules( element )
), element );
// make sure required is at front
if ( data.required ) {
param = data.required;
delete data.required;
data = $.extend( { required: param }, data );
$( element ).attr( "aria-required", "true" );
}
// make sure remote is at back
if ( data.remote ) {
param = data.remote;
delete data.remote;
data = $.extend( data, { remote: param });
}
return data;
}
});
// Custom selectors
$.extend( $.expr[ ":" ], {
// http://jqueryvalidation.org/blank-selector/
blank: function( a ) {
return !$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/filled-selector/
filled: function( a ) {
return !!$.trim( "" + $( a ).val() );
},
// http://jqueryvalidation.org/unchecked-selector/
unchecked: function( a ) {
return !$( a ).prop( "checked" );
}
});
// constructor for validator
$.validator = function( options, form ) {
this.settings = $.extend( true, {}, $.validator.defaults, options );
this.currentForm = form;
this.init();
};
// http://jqueryvalidation.org/jQuery.validator.format/
$.validator.format = function( source, params ) {
if ( arguments.length === 1 ) {
return function() {
var args = $.makeArray( arguments );
args.unshift( source );
return $.validator.format.apply( this, args );
};
}
if ( arguments.length > 2 && params.constructor !== Array ) {
params = $.makeArray( arguments ).slice( 1 );
}
if ( params.constructor !== Array ) {
params = [ params ];
}
$.each( params, function( i, n ) {
source = source.replace( new RegExp( "\\{" + i + "\\}", "g" ), function() {
return n;
});
});
return source;
};
$.extend( $.validator, {
defaults: {
messages: {},
groups: {},
rules: {},
errorClass: "error",
validClass: "valid",
errorElement: "label",
focusCleanup: false,
focusInvalid: true,
errorContainer: $( [] ),
errorLabelContainer: $( [] ),
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
onfocusin: function( element ) {
this.lastActive = element;
// Hide error label and remove error class on focus if enabled
if ( this.settings.focusCleanup ) {
if ( this.settings.unhighlight ) {
this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
}
this.hideThese( this.errorsFor( element ) );
}
},
onfocusout: function( element ) {
if ( !this.checkable( element ) && ( element.name in this.submitted || !this.optional( element ) ) ) {
this.element( element );
}
},
onkeyup: function( element, event ) {
// Avoid revalidate the field when pressing one of the following keys
// Shift => 16
// Ctrl => 17
// Alt => 18
// Caps lock => 20
// End => 35
// Home => 36
// Left arrow => 37
// Up arrow => 38
// Right arrow => 39
// Down arrow => 40
// Insert => 45
// Num lock => 144
// AltGr key => 225
var excludedKeys = [
16, 17, 18, 20, 35, 36, 37,
38, 39, 40, 45, 144, 225
];
if ( event.which === 9 && this.elementValue( element ) === "" || $.inArray( event.keyCode, excludedKeys ) !== -1 ) {
return;
} else if ( element.name in this.submitted || element === this.lastElement ) {
this.element( element );
}
},
onclick: function( element ) {
// click on selects, radiobuttons and checkboxes
if ( element.name in this.submitted ) {
this.element( element );
// or option elements, check parent select in that case
} else if ( element.parentNode.name in this.submitted ) {
this.element( element.parentNode );
}
},
highlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).addClass( errorClass ).removeClass( validClass );
} else {
$( element ).addClass( errorClass ).removeClass( validClass );
}
},
unhighlight: function( element, errorClass, validClass ) {
if ( element.type === "radio" ) {
this.findByName( element.name ).removeClass( errorClass ).addClass( validClass );
} else {
$( element ).removeClass( errorClass ).addClass( validClass );
}
}
},
// http://jqueryvalidation.org/jQuery.validator.setDefaults/
setDefaults: function( settings ) {
$.extend( $.validator.defaults, settings );
},
messages: {
required: "This field is required.",
remote: "Please fix this field.",
email: "Please enter a valid email address.",
url: "Please enter a valid URL.",
date: "Please enter a valid date.",
dateISO: "Please enter a valid date ( ISO ).",
number: "Please enter a valid number.",
digits: "Please enter only digits.",
creditcard: "Please enter a valid credit card number.",
equalTo: "Please enter the same value again.",
maxlength: $.validator.format( "Please enter no more than {0} characters." ),
minlength: $.validator.format( "Please enter at least {0} characters." ),
rangelength: $.validator.format( "Please enter a value between {0} and {1} characters long." ),
range: $.validator.format( "Please enter a value between {0} and {1}." ),
max: $.validator.format( "Please enter a value less than or equal to {0}." ),
min: $.validator.format( "Please enter a value greater than or equal to {0}." )
},
autoCreateRanges: false,
prototype: {
init: function() {
this.labelContainer = $( this.settings.errorLabelContainer );
this.errorContext = this.labelContainer.length && this.labelContainer || $( this.currentForm );
this.containers = $( this.settings.errorContainer ).add( this.settings.errorLabelContainer );
this.submitted = {};
this.valueCache = {};
this.pendingRequest = 0;
this.pending = {};
this.invalid = {};
this.reset();
var groups = ( this.groups = {} ),
rules;
$.each( this.settings.groups, function( key, value ) {
if ( typeof value === "string" ) {
value = value.split( /\s/ );
}
$.each( value, function( index, name ) {
groups[ name ] = key;
});
});
rules = this.settings.rules;
$.each( rules, function( key, value ) {
rules[ key ] = $.validator.normalizeRule( value );
});
function delegate( event ) {
var validator = $.data( this.form, "validator" ),
eventType = "on" + event.type.replace( /^validate/, "" ),
settings = validator.settings;
if ( settings[ eventType ] && !$( this ).is( settings.ignore ) ) {
settings[ eventType ].call( validator, this, event );
}
}
$( this.currentForm )
.on( "focusin.validate focusout.validate keyup.validate",
":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'], " +
"[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], " +
"[type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'], " +
"[type='radio'], [type='checkbox']", delegate)
// Support: Chrome, oldIE
// "select" is provided as event.target when clicking a option
.on("click.validate", "select, option, [type='radio'], [type='checkbox']", delegate);
if ( this.settings.invalidHandler ) {
$( this.currentForm ).on( "invalid-form.validate", this.settings.invalidHandler );
}
// Add aria-required to any Static/Data/Class required fields before first validation
// Screen readers require this attribute to be present before the initial submission http://www.w3.org/TR/WCAG-TECHS/ARIA2.html
$( this.currentForm ).find( "[required], [data-rule-required], .required" ).attr( "aria-required", "true" );
},
// http://jqueryvalidation.org/Validator.form/
form: function() {
this.checkForm();
$.extend( this.submitted, this.errorMap );
this.invalid = $.extend({}, this.errorMap );
if ( !this.valid() ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
}
this.showErrors();
return this.valid();
},
checkForm: function() {
this.prepareForm();
for ( var i = 0, elements = ( this.currentElements = this.elements() ); elements[ i ]; i++ ) {
this.check( elements[ i ] );
}
return this.valid();
},
// http://jqueryvalidation.org/Validator.element/
element: function( element ) {
var cleanElement = this.clean( element ),
checkElement = this.validationTargetFor( cleanElement ),
result = true;
this.lastElement = checkElement;
if ( checkElement === undefined ) {
delete this.invalid[ cleanElement.name ];
} else {
this.prepareElement( checkElement );
this.currentElements = $( checkElement );
result = this.check( checkElement ) !== false;
if ( result ) {
delete this.invalid[ checkElement.name ];
} else {
this.invalid[ checkElement.name ] = true;
}
}
// Add aria-invalid status for screen readers
$( element ).attr( "aria-invalid", !result );
if ( !this.numberOfInvalids() ) {
// Hide error containers on last error
this.toHide = this.toHide.add( this.containers );
}
this.showErrors();
return result;
},
// http://jqueryvalidation.org/Validator.showErrors/
showErrors: function( errors ) {
if ( errors ) {
// add items to error list and map
$.extend( this.errorMap, errors );
this.errorList = [];
for ( var name in errors ) {
this.errorList.push({
message: errors[ name ],
element: this.findByName( name )[ 0 ]
});
}
// remove items from success list
this.successList = $.grep( this.successList, function( element ) {
return !( element.name in errors );
});
}
if ( this.settings.showErrors ) {
this.settings.showErrors.call( this, this.errorMap, this.errorList );
} else {
this.defaultShowErrors();
}
},
// http://jqueryvalidation.org/Validator.resetForm/
resetForm: function() {
if ( $.fn.resetForm ) {
$( this.currentForm ).resetForm();
}
this.submitted = {};
this.lastElement = null;
this.prepareForm();
this.hideErrors();
var i, elements = this.elements()
.removeData( "previousValue" )
.removeAttr( "aria-invalid" );
if ( this.settings.unhighlight ) {
for ( i = 0; elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ],
this.settings.errorClass, "" );
}
} else {
elements.removeClass( this.settings.errorClass );
}
},
numberOfInvalids: function() {
return this.objectLength( this.invalid );
},
objectLength: function( obj ) {
/* jshint unused: false */
var count = 0,
i;
for ( i in obj ) {
count++;
}
return count;
},
hideErrors: function() {
this.hideThese( this.toHide );
},
hideThese: function( errors ) {
errors.not( this.containers ).text( "" );
this.addWrapper( errors ).hide();
},
valid: function() {
return this.size() === 0;
},
size: function() {
return this.errorList.length;
},
focusInvalid: function() {
if ( this.settings.focusInvalid ) {
try {
$( this.findLastActive() || this.errorList.length && this.errorList[ 0 ].element || [])
.filter( ":visible" )
.focus()
// manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
.trigger( "focusin" );
} catch ( e ) {
// ignore IE throwing errors when focusing hidden elements
}
}
},
findLastActive: function() {
var lastActive = this.lastActive;
return lastActive && $.grep( this.errorList, function( n ) {
return n.element.name === lastActive.name;
}).length === 1 && lastActive;
},
elements: function() {
var validator = this,
rulesCache = {};
// select all valid inputs inside the form (no submit or reset buttons)
return $( this.currentForm )
.find( "input, select, textarea" )
.not( ":submit, :reset, :image, :disabled" )
.not( this.settings.ignore )
.filter( function() {
if ( !this.name && validator.settings.debug && window.console ) {
console.error( "%o has no name assigned", this );
}
// select only the first element for each name, and only those with rules specified
if ( this.name in rulesCache || !validator.objectLength( $( this ).rules() ) ) {
return false;
}
rulesCache[ this.name ] = true;
return true;
});
},
clean: function( selector ) {
return $( selector )[ 0 ];
},
errors: function() {
var errorClass = this.settings.errorClass.split( " " ).join( "." );
return $( this.settings.errorElement + "." + errorClass, this.errorContext );
},
reset: function() {
this.successList = [];
this.errorList = [];
this.errorMap = {};
this.toShow = $( [] );
this.toHide = $( [] );
this.currentElements = $( [] );
},
prepareForm: function() {
this.reset();
this.toHide = this.errors().add( this.containers );
},
prepareElement: function( element ) {
this.reset();
this.toHide = this.errorsFor( element );
},
elementValue: function( element ) {
var val,
$element = $( element ),
type = element.type;
if ( type === "radio" || type === "checkbox" ) {
return this.findByName( element.name ).filter(":checked").val();
} else if ( type === "number" && typeof element.validity !== "undefined" ) {
return element.validity.badInput ? false : $element.val();
}
val = $element.val();
if ( typeof val === "string" ) {
return val.replace(/\r/g, "" );
}
return val;
},
check: function( element ) {
element = this.validationTargetFor( this.clean( element ) );
var rules = $( element ).rules(),
rulesCount = $.map( rules, function( n, i ) {
return i;
}).length,
dependencyMismatch = false,
val = this.elementValue( element ),
result, method, rule;
for ( method in rules ) {
rule = { method: method, parameters: rules[ method ] };
try {
result = $.validator.methods[ method ].call( this, val, element, rule.parameters );
// if a method indicates that the field is optional and therefore valid,
// don't mark it as valid when there are no other rules
if ( result === "dependency-mismatch" && rulesCount === 1 ) {
dependencyMismatch = true;
continue;
}
dependencyMismatch = false;
if ( result === "pending" ) {
this.toHide = this.toHide.not( this.errorsFor( element ) );
return;
}
if ( !result ) {
this.formatAndAdd( element, rule );
return false;
}
} catch ( e ) {
if ( this.settings.debug && window.console ) {
console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
}
if ( e instanceof TypeError ) {
e.message += ". Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.";
}
throw e;
}
}
if ( dependencyMismatch ) {
return;
}
if ( this.objectLength( rules ) ) {
this.successList.push( element );
}
return true;
},
// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
// return the generic message if present and no method specific message is present
customDataMessage: function( element, method ) {
return $( element ).data( "msg" + method.charAt( 0 ).toUpperCase() +
method.substring( 1 ).toLowerCase() ) || $( element ).data( "msg" );
},
// return the custom message for the given element name and validation method
customMessage: function( name, method ) {
var m = this.settings.messages[ name ];
return m && ( m.constructor === String ? m : m[ method ]);
},
// return the first defined argument, allowing empty strings
findDefined: function() {
for ( var i = 0; i < arguments.length; i++) {
if ( arguments[ i ] !== undefined ) {
return arguments[ i ];
}
}
return undefined;
},
defaultMessage: function( element, method ) {
return this.findDefined(
this.customMessage( element.name, method ),
this.customDataMessage( element, method ),
// title is never undefined, so handle empty string as undefined
!this.settings.ignoreTitle && element.title || undefined,
$.validator.messages[ method ],
"Warning: No message defined for " + element.name + ""
);
},
formatAndAdd: function( element, rule ) {
var message = this.defaultMessage( element, rule.method ),
theregex = /\$?\{(\d+)\}/g;
if ( typeof message === "function" ) {
message = message.call( this, rule.parameters, element );
} else if ( theregex.test( message ) ) {
message = $.validator.format( message.replace( theregex, "{$1}" ), rule.parameters );
}
this.errorList.push({
message: message,
element: element,
method: rule.method
});
this.errorMap[ element.name ] = message;
this.submitted[ element.name ] = message;
},
addWrapper: function( toToggle ) {
if ( this.settings.wrapper ) {
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
}
return toToggle;
},
defaultShowErrors: function() {
var i, elements, error;
for ( i = 0; this.errorList[ i ]; i++ ) {
error = this.errorList[ i ];
if ( this.settings.highlight ) {
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
}
this.showLabel( error.element, error.message );
}
if ( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if ( this.settings.success ) {
for ( i = 0; this.successList[ i ]; i++ ) {
this.showLabel( this.successList[ i ] );
}
}
if ( this.settings.unhighlight ) {
for ( i = 0, elements = this.validElements(); elements[ i ]; i++ ) {
this.settings.unhighlight.call( this, elements[ i ], this.settings.errorClass, this.settings.validClass );
}
}
this.toHide = this.toHide.not( this.toShow );
this.hideErrors();
this.addWrapper( this.toShow ).show();
},
validElements: function() {
return this.currentElements.not( this.invalidElements() );
},
invalidElements: function() {
return $( this.errorList ).map(function() {
return this.element;
});
},
showLabel: function( element, message ) {
var place, group, errorID,
error = this.errorsFor( element ),
elementID = this.idOrName( element ),
describedBy = $( element ).attr( "aria-describedby" );
if ( error.length ) {
// refresh error/success class
error.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
// replace message on existing label
error.html( message );
} else {
// create error element
error = $( "<" + this.settings.errorElement + ">" )
.attr( "id", elementID + "-error" )
.addClass( this.settings.errorClass )
.html( message || "" );
// Maintain reference to the element to be placed into the DOM
place = error;
if ( this.settings.wrapper ) {
// make sure the element is visible, even in IE
// actually showing the wrapped element is handled elsewhere
place = error.hide().show().wrap( "<" + this.settings.wrapper + "/>" ).parent();
}
if ( this.labelContainer.length ) {
this.labelContainer.append( place );
} else if ( this.settings.errorPlacement ) {
this.settings.errorPlacement( place, $( element ) );
} else {
place.insertAfter( element );
}
// Link error back to the element
if ( error.is( "label" ) ) {
// If the error is a label, then associate using 'for'
error.attr( "for", elementID );
} else if ( error.parents( "label[for='" + elementID + "']" ).length === 0 ) {
// If the element is not a child of an associated label, then it's necessary
// to explicitly apply aria-describedby
errorID = error.attr( "id" ).replace( /(:|\.|\[|\]|\$)/g, "\\$1");
// Respect existing non-error aria-describedby
if ( !describedBy ) {
describedBy = errorID;
} else if ( !describedBy.match( new RegExp( "\\b" + errorID + "\\b" ) ) ) {
// Add to end of list if not already present
describedBy += " " + errorID;
}
$( element ).attr( "aria-describedby", describedBy );
// If this element is grouped, then assign to all elements in the same group
group = this.groups[ element.name ];
if ( group ) {
$.each( this.groups, function( name, testgroup ) {
if ( testgroup === group ) {
$( "[name='" + name + "']", this.currentForm )
.attr( "aria-describedby", error.attr( "id" ) );
}
});
}
}
}
if ( !message && this.settings.success ) {
error.text( "" );
if ( typeof this.settings.success === "string" ) {
error.addClass( this.settings.success );
} else {
this.settings.success( error, element );
}
}
this.toShow = this.toShow.add( error );
},
errorsFor: function( element ) {
var name = this.idOrName( element ),
describer = $( element ).attr( "aria-describedby" ),
selector = "label[for='" + name + "'], label[for='" + name + "'] *";
// aria-describedby should directly reference the error element
if ( describer ) {
selector = selector + ", #" + describer.replace( /\s+/g, ", #" );
}
return this
.errors()
.filter( selector );
},
idOrName: function( element ) {
return this.groups[ element.name ] || ( this.checkable( element ) ? element.name : element.id || element.name );
},
validationTargetFor: function( element ) {
// If radio/checkbox, validate first element in group instead
if ( this.checkable( element ) ) {
element = this.findByName( element.name );
}
// Always apply ignore filter
return $( element ).not( this.settings.ignore )[ 0 ];
},
checkable: function( element ) {
return ( /radio|checkbox/i ).test( element.type );
},
findByName: function( name ) {
return $( this.currentForm ).find( "[name='" + name + "']" );
},
getLength: function( value, element ) {
switch ( element.nodeName.toLowerCase() ) {
case "select":
return $( "option:selected", element ).length;
case "input":
if ( this.checkable( element ) ) {
return this.findByName( element.name ).filter( ":checked" ).length;
}
}
return value.length;
},
depend: function( param, element ) {
return this.dependTypes[typeof param] ? this.dependTypes[typeof param]( param, element ) : true;
},
dependTypes: {
"boolean": function( param ) {
return param;
},
"string": function( param, element ) {
return !!$( param, element.form ).length;
},
"function": function( param, element ) {
return param( element );
}
},
optional: function( element ) {
var val = this.elementValue( element );
return !$.validator.methods.required.call( this, val, element ) && "dependency-mismatch";
},
startRequest: function( element ) {
if ( !this.pending[ element.name ] ) {
this.pendingRequest++;
this.pending[ element.name ] = true;
}
},
stopRequest: function( element, valid ) {
this.pendingRequest--;
// sometimes synchronization fails, make sure pendingRequest is never < 0
if ( this.pendingRequest < 0 ) {
this.pendingRequest = 0;
}
delete this.pending[ element.name ];
if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
$( this.currentForm ).submit();
this.formSubmitted = false;
} else if (!valid && this.pendingRequest === 0 && this.formSubmitted ) {
$( this.currentForm ).triggerHandler( "invalid-form", [ this ]);
this.formSubmitted = false;
}
},
previousValue: function( element ) {
return $.data( element, "previousValue" ) || $.data( element, "previousValue", {
old: null,
valid: true,
message: this.defaultMessage( element, "remote" )
});
},
// cleans up all forms and elements, removes validator-specific events
destroy: function() {
this.resetForm();
$( this.currentForm )
.off( ".validate" )
.removeData( "validator" );
}
},
classRuleSettings: {
required: { required: true },
email: { email: true },
url: { url: true },
date: { date: true },
dateISO: { dateISO: true },
number: { number: true },
digits: { digits: true },
creditcard: { creditcard: true }
},
addClassRules: function( className, rules ) {
if ( className.constructor === String ) {
this.classRuleSettings[ className ] = rules;
} else {
$.extend( this.classRuleSettings, className );
}
},
classRules: function( element ) {
var rules = {},
classes = $( element ).attr( "class" );
if ( classes ) {
$.each( classes.split( " " ), function() {
if ( this in $.validator.classRuleSettings ) {
$.extend( rules, $.validator.classRuleSettings[ this ]);
}
});
}
return rules;
},
normalizeAttributeRule: function( rules, type, method, value ) {
// convert the value to a number for number inputs, and for text for backwards compability
// allows type="date" and others to be compared as strings
if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
value = Number( value );
// Support Opera Mini, which returns NaN for undefined minlength
if ( isNaN( value ) ) {
value = undefined;
}
}
if ( value || value === 0 ) {
rules[ method ] = value;
} else if ( type === method && type !== "range" ) {
// exception: the jquery validate 'range' method
// does not test for the html5 'range' type
rules[ method ] = true;
}
},
attributeRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
// support for in both html5 and older browsers
if ( method === "required" ) {
value = element.getAttribute( method );
// Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup
if ( value === "" ) {
value = true;
}
// force non-HTML5 browsers to return bool
value = !!value;
} else {
value = $element.attr( method );
}
this.normalizeAttributeRule( rules, type, method, value );
}
// maxlength may be returned as -1, 2147483647 ( IE ) and 524288 ( safari ) for text inputs
if ( rules.maxlength && /-1|2147483647|524288/.test( rules.maxlength ) ) {
delete rules.maxlength;
}
return rules;
},
dataRules: function( element ) {
var rules = {},
$element = $( element ),
type = element.getAttribute( "type" ),
method, value;
for ( method in $.validator.methods ) {
value = $element.data( "rule" + method.charAt( 0 ).toUpperCase() + method.substring( 1 ).toLowerCase() );
this.normalizeAttributeRule( rules, type, method, value );
}
return rules;
},
staticRules: function( element ) {
var rules = {},
validator = $.data( element.form, "validator" );
if ( validator.settings.rules ) {
rules = $.validator.normalizeRule( validator.settings.rules[ element.name ] ) || {};
}
return rules;
},
normalizeRules: function( rules, element ) {
// handle dependency check
$.each( rules, function( prop, val ) {
// ignore rule when param is explicitly false, eg. required:false
if ( val === false ) {
delete rules[ prop ];
return;
}
if ( val.param || val.depends ) {
var keepRule = true;
switch ( typeof val.depends ) {
case "string":
keepRule = !!$( val.depends, element.form ).length;
break;
case "function":
keepRule = val.depends.call( element, element );
break;
}
if ( keepRule ) {
rules[ prop ] = val.param !== undefined ? val.param : true;
} else {
delete rules[ prop ];
}
}
});
// evaluate parameters
$.each( rules, function( rule, parameter ) {
rules[ rule ] = $.isFunction( parameter ) ? parameter( element ) : parameter;
});
// clean number parameters
$.each([ "minlength", "maxlength" ], function() {
if ( rules[ this ] ) {
rules[ this ] = Number( rules[ this ] );
}
});
$.each([ "rangelength", "range" ], function() {
var parts;
if ( rules[ this ] ) {
if ( $.isArray( rules[ this ] ) ) {
rules[ this ] = [ Number( rules[ this ][ 0 ]), Number( rules[ this ][ 1 ] ) ];
} else if ( typeof rules[ this ] === "string" ) {
parts = rules[ this ].replace(/[\[\]]/g, "" ).split( /[\s,]+/ );
rules[ this ] = [ Number( parts[ 0 ]), Number( parts[ 1 ] ) ];
}
}
});
if ( $.validator.autoCreateRanges ) {
// auto-create ranges
if ( rules.min != null && rules.max != null ) {
rules.range = [ rules.min, rules.max ];
delete rules.min;
delete rules.max;
}
if ( rules.minlength != null && rules.maxlength != null ) {
rules.rangelength = [ rules.minlength, rules.maxlength ];
delete rules.minlength;
delete rules.maxlength;
}
}
return rules;
},
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule: function( data ) {
if ( typeof data === "string" ) {
var transformed = {};
$.each( data.split( /\s/ ), function() {
transformed[ this ] = true;
});
data = transformed;
}
return data;
},
// http://jqueryvalidation.org/jQuery.validator.addMethod/
addMethod: function( name, method, message ) {
$.validator.methods[ name ] = method;
$.validator.messages[ name ] = message !== undefined ? message : $.validator.messages[ name ];
if ( method.length < 3 ) {
$.validator.addClassRules( name, $.validator.normalizeRule( name ) );
}
},
methods: {
// http://jqueryvalidation.org/required-method/
required: function( value, element, param ) {
// check if dependency is met
if ( !this.depend( param, element ) ) {
return "dependency-mismatch";
}
if ( element.nodeName.toLowerCase() === "select" ) {
// could be an array for select-multiple or a string, both are fine this way
var val = $( element ).val();
return val && val.length > 0;
}
if ( this.checkable( element ) ) {
return this.getLength( value, element ) > 0;
}
return value.length > 0;
},
// http://jqueryvalidation.org/email-method/
email: function( value, element ) {
// From https://html.spec.whatwg.org/multipage/forms.html#valid-e-mail-address
// Retrieved 2014-01-14
// If you have a problem with this implementation, report a bug against the above spec
// Or use custom methods to implement your own email validation
return this.optional( element ) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test( value );
},
// http://jqueryvalidation.org/url-method/
url: function( value, element ) {
// Copyright (c) 2010-2013 Diego Perini, MIT licensed
// https://gist.github.com/dperini/729294
// see also https://mathiasbynens.be/demo/url-regex
// modified to allow protocol-relative URLs
return this.optional( element ) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test( value );
},
// http://jqueryvalidation.org/date-method/
date: function( value, element ) {
return this.optional( element ) || !/Invalid|NaN/.test( new Date( value ).toString() );
},
// http://jqueryvalidation.org/dateISO-method/
dateISO: function( value, element ) {
return this.optional( element ) || /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test( value );
},
// http://jqueryvalidation.org/number-method/
number: function( value, element ) {
return this.optional( element ) || /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test( value );
},
// http://jqueryvalidation.org/digits-method/
digits: function( value, element ) {
return this.optional( element ) || /^\d+$/.test( value );
},
// http://jqueryvalidation.org/creditcard-method/
// based on http://en.wikipedia.org/wiki/Luhn_algorithm
creditcard: function( value, element ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
// accept only spaces, digits and dashes
if ( /[^0-9 \-]+/.test( value ) ) {
return false;
}
var nCheck = 0,
nDigit = 0,
bEven = false,
n, cDigit;
value = value.replace( /\D/g, "" );
// Basing min and max length on
// http://developer.ean.com/general_info/Valid_Credit_Card_Types
if ( value.length < 13 || value.length > 19 ) {
return false;
}
for ( n = value.length - 1; n >= 0; n--) {
cDigit = value.charAt( n );
nDigit = parseInt( cDigit, 10 );
if ( bEven ) {
if ( ( nDigit *= 2 ) > 9 ) {
nDigit -= 9;
}
}
nCheck += nDigit;
bEven = !bEven;
}
return ( nCheck % 10 ) === 0;
},
// http://jqueryvalidation.org/minlength-method/
minlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length >= param;
},
// http://jqueryvalidation.org/maxlength-method/
maxlength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || length <= param;
},
// http://jqueryvalidation.org/rangelength-method/
rangelength: function( value, element, param ) {
var length = $.isArray( value ) ? value.length : this.getLength( value, element );
return this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
},
// http://jqueryvalidation.org/min-method/
min: function( value, element, param ) {
return this.optional( element ) || value >= param;
},
// http://jqueryvalidation.org/max-method/
max: function( value, element, param ) {
return this.optional( element ) || value <= param;
},
// http://jqueryvalidation.org/range-method/
range: function( value, element, param ) {
return this.optional( element ) || ( value >= param[ 0 ] && value <= param[ 1 ] );
},
// http://jqueryvalidation.org/equalTo-method/
equalTo: function( value, element, param ) {
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var target = $( param );
if ( this.settings.onfocusout ) {
target.off( ".validate-equalTo" ).on( "blur.validate-equalTo", function() {
$( element ).valid();
});
}
return value === target.val();
},
// http://jqueryvalidation.org/remote-method/
remote: function( value, element, param ) {
if ( this.optional( element ) ) {
return "dependency-mismatch";
}
var previous = this.previousValue( element ),
validator, data;
if (!this.settings.messages[ element.name ] ) {
this.settings.messages[ element.name ] = {};
}
previous.originalMessage = this.settings.messages[ element.name ].remote;
this.settings.messages[ element.name ].remote = previous.message;
param = typeof param === "string" && { url: param } || param;
if ( previous.old === value ) {
return previous.valid;
}
previous.old = value;
validator = this;
this.startRequest( element );
data = {};
data[ element.name ] = value;
$.ajax( $.extend( true, {
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
context: validator.currentForm,
success: function( response ) {
var valid = response === true || response === "true",
errors, message, submitted;
validator.settings.messages[ element.name ].remote = previous.originalMessage;
if ( valid ) {
submitted = validator.formSubmitted;
validator.prepareElement( element );
validator.formSubmitted = submitted;
validator.successList.push( element );
delete validator.invalid[ element.name ];
validator.showErrors();
} else {
errors = {};
message = response || validator.defaultMessage( element, "remote" );
errors[ element.name ] = previous.message = $.isFunction( message ) ? message( value ) : message;
validator.invalid[ element.name ] = true;
validator.showErrors( errors );
}
previous.valid = valid;
validator.stopRequest( element, valid );
}
}, param ) );
return "pending";
}
}
});
// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
var pendingRequests = {},
ajax;
// Use a prefilter if available (1.5+)
if ( $.ajaxPrefilter ) {
$.ajaxPrefilter(function( settings, _, xhr ) {
var port = settings.port;
if ( settings.mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = xhr;
}
});
} else {
// Proxy ajax
ajax = $.ajax;
$.ajax = function( settings ) {
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
if ( mode === "abort" ) {
if ( pendingRequests[port] ) {
pendingRequests[port].abort();
}
pendingRequests[port] = ajax.apply(this, arguments);
return pendingRequests[port];
}
return ajax.apply(this, arguments);
};
}
}));
/*!
* JavaScript Cookie v2.1.0
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
var _OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = _OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function init (converter) {
function api (key, value, attributes) {
var result;
// Write
if (arguments.length > 1) {
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
var expires = new Date();
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
attributes.expires = expires;
}
try {
result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {}
if (!converter.write) {
value = encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
} else {
value = converter.write(value, key);
}
key = encodeURIComponent(String(key));
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);
return (document.cookie = [
key, '=', value,
attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
attributes.path && '; path=' + attributes.path,
attributes.domain && '; domain=' + attributes.domain,
attributes.secure ? '; secure' : ''
].join(''));
}
// Read
if (!key) {
result = {};
}
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split('; ') : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var name = parts[0].replace(rdecode, decodeURIComponent);
var cookie = parts.slice(1).join('=');
if (cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
cookie = converter.read ?
converter.read(cookie, name) : converter(cookie, name) ||
cookie.replace(rdecode, decodeURIComponent);
if (this.json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
if (key === name) {
result = cookie;
break;
}
if (!key) {
result[name] = cookie;
}
} catch (e) {}
}
return result;
}
api.get = api.set = api;
api.getJSON = function () {
return api.apply({
json: true
}, [].slice.call(arguments));
};
api.defaults = {};
api.remove = function (key, attributes) {
api(key, '', extend(attributes, {
expires: -1
}));
};
api.withConverter = init;
return api;
}
return init(function () {});
}));