$.oSettings = {}; function setAriaInvalid(){ $('input, select, textarea').attr('aria-invalid','false'); $('.form-control.is-invalid, .was-validated .form-control:invalid').attr('aria-invalid','true'); } (function() { 'use strict'; window.addEventListener('load', function() { var forms = document.getElementsByClassName('needs-validation'); var validation = Array.prototype.filter.call(forms, function(form) { form.addEventListener('submit', function(event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); form.classList.add('was-validated'); setAriaInvalid(); $('input, textarea').on('focusout, blur, keyup', function(){ setAriaInvalid(); }); $("select").change(function(){ setAriaInvalid(); }); $('input[aria-invalid=true], select[aria-invalid=true], textarea[aria-invalid=true]').filter(':first').focus(); } }, false); }); }, false); })(); $(document).ready(function(){ function checkMinYrs(type,minyears,joint) { if (type == 'residence') { if (joint) { fieldsetID = "joint_previous_residence"; years = 'jointyearsatresidence'; months = 'jointmonthsatresidence'; } else { fieldsetID = "previous_residence"; years = 'yearsatresidence'; months = 'monthsatresidence'; } } else if (type == 'employer') { if (joint) { fieldsetID = "joint_previous_employer_information"; years = 'jointemployeryears'; months = 'jointemployermonths'; } else { fieldsetID = "previous_employer_information"; years = 'employeryears'; months = 'employermonths'; } } $('[name=' + years + '],' + '[name=' + months + ']').unbind("change").bind("change", function(event) { checkMinYrs(type,minyears,joint); }); if (fieldsetID) { var currentyears = ($('[name=' + years + ']').val()+'').replace(/\D/g,''); var currentmonths = ($('[name=' + months + ']').val()+'').replace(/\D/g,''); if (!currentyears || isNaN(currentyears)) currentyears = 0; if (!currentmonths || isNaN(currentmonths)) currentmonths = 0; var selector = '#' + fieldsetID + ' input, #' + fieldsetID + ' select, #' + fieldsetID + ' textarea'; $(selector).removeAttr("required").parent("div").siblings("label").removeClass("asterisk"); if (currentyears < minyears) { $(selector).each(function() { if ($(this).is(':visible')) { $(this).prop("required",true).parent("div").siblings("label").addClass("asterisk"); } }); } } } function spouseinfo(){ $("#spousename, #spouseincome").removeAttr("required").parent("div").siblings("label").removeClass("asterisk"); $('#field-spousename,#field-spouseincome').hide(); } spouseinfo(); $.oSettings.Category = {}; $.oSettings.dealershipurl = "https://www.ebypa.com/"; $("#previous_employer_information, #joint_previous_employer_information").prop("disabled", true).hide(); $.oSettings.SelectVehTypeOpt = $('#category').not('.customoptions').html(); $.oSettings.SelectMakeOpt = $('#make').not('.customoptions').html(); $.oSettings.SelectModelOpt = $('#model').not('.customoptions').html(); // Populate Vehicle Types $.oSettings.vehtypeOptions = ""; var vTypesArray = new Array(); $.oSettings.Category.vehTypes.sort(); $.each($.oSettings.Category.vehTypes, function(key, vehtype){ if(vehtype != '' && $.inArray(vehtype, vTypesArray) == -1){ $.oSettings.vehtypeOptions += ''; vTypesArray.push(vehtype); } }); $.each($.oSettings.Category.categoryData, function(vehtype,value){ $.oSettings.Category.categoryData[vehtype] = null; $.oSettings.Category.categoryData[vehtype.toLowerCase()] = value; }); if($.oSettings.vehtypeOptions) $('#category').not('.customoptions').html($.oSettings.SelectVehTypeOpt+$.oSettings.vehtypeOptions); switchIndividualJoint($('#applicationtype').val()); $('select.select-applicationtype').change(function(){ switchIndividualJoint($(this).val()); }); function switchIndividualJoint(this_val){ if(this_val != 'Joint'){ this_val = 'Individual'; } $('select.select-applicationtype').val(this_val); if($('#applicationtype').val() == 'Joint'){ $('.joint-app-element').not('#joint_previous_employer_information').show(); $('.joint-app-element input, .joint-app-element select, .joint-app-element textarea').prop('disabled', false); }else{ $('.joint-app-element').hide(); $('.joint-app-element input, .joint-app-element select, .joint-app-element textarea').prop('disabled', true); } } $('#switch-make-field').click(function(){ switchSelectText('make'); }); $('#switch-model-field').click(function(){ switchSelectText('model'); }); $('#category,#makeyear,#make').change(function(){ loadMakesModels(); }); function switchSelectText(fieldname){ $('#model,#modeltxt').val(''); if(fieldname == 'make') $('#make,#maketxt').val(''); var field = $('#field-' + fieldname); if(field.hasClass('display-select')){ field.removeClass('display-select'); if(fieldname == 'make') $('#field-model').removeClass('display-select'); }else if($('#' + fieldname).find('option').length > 1){ field.addClass('display-select'); } switchSelectTextDisable(); } function switchSelectTextDisable(){ $('#make:not([readonly]),#maketxt:not([readonly]),#model:not([readonly]),#modeltxt:not([readonly])').prop('disabled', false); if($('#field-make').hasClass('display-select')){ $('#maketxt:not([readonly])').prop('disabled', true); $('label#makelabel').attr('for','make'); }else{ $('#make:not([readonly])').prop('disabled', true); $('label#makelabel').attr('for','maketxt'); } if($('#field-model').hasClass('display-select')){ $('#modeltxt:not([readonly])').prop('disabled', true); $('label#modellabel').attr('for','model'); }else{ $('#model:not([readonly])').prop('disabled', true); $('label#modellabel').attr('for','modeltxt'); } } function cleankey(str){ var output = ((str === undefined || str === null || str == '') ? '' : str) + ""; output = output.toLowerCase(); output = $("
").html(output).text(); output = output.replace(/\W+/g,""); return output; } function loadMakesModels(){ $.oSettings.selectedYear = $('#makeyear').val(); $.oSettings.selectedMake = $('#make:visible').val() || ''; $.oSettings.selectedModel = $('#model:visible').val() || ''; $("#make").not('.customoptions').html($.oSettings.SelectMakeOpt); $("#model").not('.customoptions').html($.oSettings.SelectModelOpt); $.oSettings.selectedVehType = ($('#category').val() + '').toLowerCase(); // Populate Makes if($("select#make.customoptions").length <= 0){ $.oSettings.makeOptions = ''; $('#field-make').removeClass('display-select'); if($.oSettings.Category.categoryData[$.oSettings.selectedVehType] && $.oSettings.Category.categoryData[$.oSettings.selectedVehType][$.oSettings.selectedYear]){ if(($.oSettings.selectedVehType.length > 0) && ($.oSettings.selectedYear.length > 0)){ $.each($.oSettings.Category.categoryData[$.oSettings.selectedVehType][$.oSettings.selectedYear],function(key,make){ if(make) $.oSettings.makeOptions += ''; }); } }else{ $('#field-make, #field-model').removeClass('display-select'); } if($.oSettings.makeOptions){ $("#make").not('.customoptions').html($.oSettings.SelectMakeOpt + $.oSettings.makeOptions); $('#field-make').addClass('display-select'); }else{ $('#field-make').removeClass('display-select'); } } // Populate Models if($("select#model.customoptions").length <= 0){ $('#field-model').removeClass('display-select'); $.getJSON("incfiles/GetMakesModels.php",{ "dealershipurl":$.oSettings.dealershipurl ,"type":($('#category').val() ? encodeURIComponent($('#category').val()) : "") ,"year":($('#makeyear').val() ? encodeURIComponent($('#makeyear').val()) : "") ,"make":($('#make').val() ? encodeURIComponent($('#make').val()) : "") },function(j){ $.oSettings.modelOptions = ''; if (j && j.length > 0){ for (var i = 0; i < j.length; i++) { var model = j[i].modeltrim.replace(/ Base$/,""); $.oSettings.modelOptions += ''; } } if($.oSettings.modelOptions){ $('#model').not('.customoptions').html($.oSettings.SelectModelOpt + $.oSettings.modelOptions); $('#field-model').addClass('display-select'); }else{ $('#field-model').removeClass('display-select'); } switchSelectTextDisable(); }); } switchSelectTextDisable(); } loadMakesModels(); });