1// Finance app optional blocks completed--- 2 3let config_elements = [], 4config_forms = [], 5form_type_bt = false; 6 7function insertForm(nest_id, formname, vid, formCallback) { 8 9 let config_form = {}, 10 contactFormWrap = $(contactFormSrc).clone(), 11 contactForm = contactFormWrap[1], 12 div_open = 0, 13 datetime_ids = [], 14 date_ids = [], 15 active_vehicle = [], 16 temp_containers = [], 17 calling_function = arguments.callee.caller.name; 18 19 form_type_bt = nest_id.match(/_bt$/) ? true : false; 20 21 let p = new Promise((resolve, reject) => { 22 23 $.ajax({ 24 url: '/isapi_xml.php?module=form_popup&formname='+ formname +'&action=get_config', 25 method: "GET", 26 success: function(data) { 27 resolve(data); 28 } 29 }); 30 }); 31 32 p.then((result) => { 33 config_forms[formname] = result; 34 config_form = result; 35 config_elements[formname] = config_form.elements; 36 37 $('#'+ nest_id).empty().append(contactFormWrap).ready(() => { 38 $(contactForm).attr('name', formname); 39 }); 40 41 }).then((result) => { 42 return getVehicleInfo(formname, vid); 43 44 }).then((active_vehicle) => { 45 $(contactFormWrap[0]).text(config_form.display_name); 46//--Custom ---- 47 if (formname == 'newsletter_unsubscribe') { 48 49 if (typeof(form_data[formname][0]) == 'undefined' 50 || typeof(form_data[formname][0]['email']) == 'undefined') { 51 52 let new_el = $('#h2_wrap').clone(); 53 let new_input = $(new_el).find('h2') 54 .text( 'Subscriber Not found'); 55 $(contactForm).find('.form_body') 56 .append(new_input); 57 58 return false; 59 } 60 let new_el = $('#h2_wrap').clone(); 61 let new_input = $(new_el).find('h2') 62 .text( 'Subscriber: '+ form_data[formname][0]['email']); 63 $(contactForm).find('.form_body') 64 .append(new_input); 65 66 $(contactForm).find('.form_body') 67 .append('<input type="hidden" name="email" value="'+ form_data[formname][0]['email'] +'" />'); 68 } else if (typeof(vid) == 'string' && vid.length > 0) { 69 $(contactForm).find('.form_body') 70 .append('<input type="hidden" name="vid" value="'+ vid +'" />'); 71 } 72//------------ 73 Object.keys(config_form.elements).map(function(v, k) { 74 75 let config_element = config_elements[formname][v] 76 readonly = false, 77 el_group = config_element.type 78 .replace(/^date(.*)/, 'date') 79 .replace(/^makes_(.*)/, 'select') 80 .replace(/^models_(.*)/, 'select') 81 .replace(/^stocks_(.*)/, 'select') 82 .replace(/^years_(.*)/, 'select'), 83 new_el = config_element.type == 'html' 84 ? '' 85 : $('#'+ el_group +'_wrap').clone(); 86 87 //----User's info if no user only--- 88 if (typeof(user.email) == 'string' && user.email.length > 5 89 && typeof(user[v]) != 'undefined' && user[v].length > 0) 90 readonly = true; 91 92 $(new_el).attr('id', ''); 93 94 if (v.replace(/(.*)state/, 'state') == 'state') { 95 let new_input = $(new_el).find('select') 96 .attr('id', v) 97 .attr('name', v) 98 .append('<option value="">State</option>'); 99 states.map((s) => { 100 $(new_input).append('<option value="' + s.key + '">' + s.value + '</option>') 101 }) 102 if (config_element.required) { 103 $(new_el).find('#' + v + ' option:first').append('*'); 104 } 105 } else if (config_element.type == 'years_all') { 106 let new_input = $(new_el).find('select') 107 .attr('id', v) 108 .attr('name', v) 109 .append('<option value="">'+ config_element.display_name +'</option>'); 110 let d = new Date; 111 112 for (let y = d.getFullYear(); y > 1970; y--) { 113 $(new_input).append('<option value="'+ y +'">'+ y +'</option>'); 114 }; 115 if (config_element.required) { 116 $(new_el).find('#'+ v +' option:first').append('*'); 117 } 118 } else if (config_element.type == 'makes_all') { 119 let new_input = $(new_el).find('select') 120 .attr('id', v) 121 .attr('name', v) 122 .append('<option value="">Make</option>'); 123 124 vehicle_makes.map((m) => { 125 $(new_input).append('<option value="'+ m +'"'+ (typeof(active_vehicle['make']) == 'string' && active_vehicle['make'] == m ? ' selected' : '') +'>'+ m +'</option>') 126 }) 127 if (config_element.required) { 128 $(new_el).find('select option:first').append('*'); 129 } 130 } else if (config_element.type == 'makes_av') { 131 let new_input = $(new_el).find('select') 132 .attr('id', v) 133 .attr('name', v) 134 .change(function() { setModels(this.value) }) 135 .append('<option value="">Make</option>'); 136 Object.keys(available_makes_models['makes']).map((m) => { 137 $(new_input).append('<option value="'+ m +'"'+ (typeof(active_vehicle['make']) == 'string' && active_vehicle['make'] == m ? ' selected' : '') +'>'+ m +'</option>') 138 }) 139 if (config_element.required) { 140 $(new_el).find('select option:first').append('*'); 141 } 142 } else if (config_element.type == 'models_av') { 143 let new_input = $(new_el).find('select') 144 .attr('id', v) 145 .attr('name', v) 146 .change(function() { setStock(this.value) }) 147 .append('<option value="">Model</option>'); 148 if (typeof(active_vehicle['model']) == 'string' && active_vehicle['model'].length > 0) 149 new_input.append('<option value="'+ (typeof(active_vehicle['model']) == 'string' && active_vehicle['model'] +'" selected>'+ active_vehicle['model']) +'</option>'); 150 if (config_element.required) { 151 $(new_el).find('select option:first').append('*'); 152 } 153 } else if (config_element.type == 'stocks_av') { 154 let new_input = $(new_el).find('select') 155 .attr('id', v) 156 .attr('name', v) 157 .change(function() { setMakeModel(this.value) }) 158 .append('<option value="">Stock #</option>'); 159 Object.keys(available_makes_models['stocks']).map(function(v, k) { 160 available_makes_models['stocks'][v].map(function(v1, k1) { 161 new_input.append('<option value="'+ v1 +'"'+ (typeof(active_vehicle['stockno']) == 'string' && active_vehicle['stockno'] == v1 ? ' selected' : '') +'>'+ v1 +'</option>'); 162 }); 163 }); 164 if (config_element.required) { 165 $(new_el).find('select option:first').append('*'); 166 } 167 } else if (config_element.type == 'makes') { 168 let new_input = $(new_el).find('select') 169 .attr('id', v) 170 .attr('name', v) 171 .append('<option value="">Make</option>');; 172 vehicle_makes.map((m) => { 173 $(new_input).append('<option value="'+ m +'">'+ m +'</option>') 174 }) 175 if (config_element.required) { 176 $(new_el).find('select option:first').append('*'); 177 } 178 } else if (config_element.type == 'h1') { 179 let new_input = $(new_el).find('h1') 180 .text(config_element.display_name); 181 182 183 } else if (config_element.type == 'h2') { 184 let new_input = $(new_el).find('h2') 185 .text(config_element.display_name); 186 187 } else if (config_element.type == 'break') { 188 189 } else if (config_element.type == 'html') { 190 new_el = config_element.display_name 191 192 } else if (config_element.type == 'code') { 193 if (typeof(config_element.message_default) != 'undefined') 194 new_el = config_element.message_default 195 196 } else if (config_element.type == 'select') { 197 let new_input = $(new_el).find('select') 198 .attr('id', v) 199 .attr('name', v) 200 .attr('aria-label', config_element.display_name) 201 .append('<option value="">'+ config_element.display_name +'</option>'); 202 Object.keys(config_element.options).map((i) => { 203 $(new_input).append('<option value="'+ i +'">'+ config_element.options[i] +'</option>') 204 }); 205 if (config_element.required) { 206 $(new_el).find('select option:first').append('*'); 207 } 208 209 } else if (config_element.type == 'checkbox') { 210 $(new_el).find('input') 211 .attr('name', v) 212 .val('1'); 213 $(new_el).find('label') 214 .html(config_element.display_name); 215 216 } else if (config_element.type == 'datetime') { 217 datetime_ids.push(v); 218 $(new_el).find('input') 219 .attr('id', v) 220 .attr('name', v) 221 .attr('placeholder', config_element.display_name 222 + (config_element.required ? '*' : '')); 223 224 } else if (config_element.type == 'date') { 225 date_ids.push(v); 226 $(new_el).find('input') 227 .attr('id', v) 228 .attr('name', v) 229 .attr('placeholder', config_element.display_name 230 + (config_element.required ? '*' : '')) 231 232 } else if (config_element.type == 'date_exp') { 233 $(new_el).find('input') 234 .attr('id', v) 235 .attr('name', v) 236 .attr('placeholder', config_element.display_name 237 + (config_element.required ? '*' : '')) 238 .datepicker({ 239 changeMonth: true, 240 changeYear: true, 241 dateFormat: 'MM/yyyyy' 242 }) 243 244 } else if (config_element.type == 'file') { 245 $(new_el).find(':first-child') 246 .attr('id', v) 247 .attr('name', v) 248 .attr('placeholder', config_element.display_name 249 + (config_element.required ? '*' : '')) 250 251 } else if (config_element.type == 'textarea') { 252 $(new_el).find(':first-child') 253 .attr('id', v) 254 .attr('name', v) 255 .attr('aria-label', config_element.display_name) 256 .attr('placeholder', config_element.display_name 257 + (config_element.required ? '*' : '')); 258 259 if (typeof(config_element.message_default) != 'undefined' 260 && Object.keys(active_vehicle).length > 0) 261 262 $(new_el).find(':first-child').val( 263 config_element.message_default 264 .replace('$year', typeof(active_vehicle['year']) != 'undefined' ? active_vehicle['year'] : '') 265 .replace('$make', typeof(active_vehicle['make']) != 'undefined' ? active_vehicle['make'] : '') 266 .replace('$model', typeof(active_vehicle['model']) != 'undefined' ? active_vehicle['model'] : '') 267 .replace('$stock', typeof(active_vehicle['stockno']) != 'undefined' ? active_vehicle['stockno'] : '') 268 .replace('\\n', "\n") 269 ); 270 271 } else { 272 $(new_el).find(':first-child') 273 .attr('id', v) 274 .attr('name', v) 275 .attr('aria-label', config_element.display_name) 276 .attr('placeholder', config_element.display_name 277 + (config_element.required ? '*' : '')); 278 279 if (typeof(user[v]) != 'undefined') 280 $(new_el).find(':first-child').val(user[v]); 281 282 else if (typeof(form_data[formname]) != 'undefined' 283 && typeof(form_data[formname][0]) != 'undefined' 284 && typeof(form_data[formname][0][v]) != 'undefined' 285 ) 286 $(new_el).find(':first-child').val(form_data[formname][0][v]); 287 288 } 289 290 if (v.indexOf('html') < 0) 291 $(new_el).find('input').attr('readonly', readonly); 292 293 if (div_open > 0 || (typeof(new_el) == 'string' && new_el.match(/^div_/))) { 294 if (typeof(new_el) == 'string' && new_el.match(/^div_open/)) { 295 div_open ++; 296 let par = config_element.display_name.split('&'), 297 temp_div = document.createElement('div'); 298 299 if (typeof(par) == 'object') { 300 for (let i = 0; i < par.length; i++) { 301 if (par[i].split('=')[0] == 'id') 302 temp_div.id = par[i].split('=')[1]; 303 else if (par[i].split('=')[0] == 'style') 304 temp_div.style[par[i].split('=')[1].split(':')[0]] = par[i].split('=')[1].split(':')[1]; 305 } 306 } 307 if (div_open == 1) temp_container = temp_div; 308 else temp_container.appendChild(temp_div ); 309 } else if (typeof(new_el) == 'string' && new_el == 'div_close') { 310 if (div_open == 1) { 311 $(contactForm).find('.form_body').append(temp_container); 312 temp_container = null; 313 div_open = 0; 314 } else 315 div_open --; 316 } else { 317 if (div_open == 1) 318 temp_container.appendChild(new_el.addClass(config_element.width)[0]); 319 else 320 temp_container.lastChild.appendChild(new_el.addClass(config_element.width)[0]); 321 } 322 } else 323 $(new_el).addClass(config_element.width) 324 .appendTo($(contactForm).find('.form_body')); 325 326 }); 327 if (config_form.use_captcha) { 328 let captcha = $(recaptcha_plaseholder).clone(); 329 $(captcha).find(':first-child') 330 .attr('id', 're-captcha_'+ formname); 331 $(captcha).attr('id', 'captcha_'+ formname).appendTo($(contactForm).find('.form_body')) 332 } 333 let btnBox = $('#btnBox_wrap').clone(); 334 335 $(btnBox).find('button').attr('id', 'btnSubmit_'+ formname); 336 337 $(btnBox).find('span.text') 338 .text(typeof(config_form.button_text) != 'undefined' 339 && config_form.button_text.length 340 ? config_form.button_text 341 : 'Send' 342 ); 343 $(btnBox).appendTo($(contactForm).find('.form_body')) 344 345 if (formname.match(/^newsletter/) && formname != 'newsletter_subscribe_mini') { 346 setNewslTopics(formname); 347 } 348 349 }).then(function(result) { 350 if (config_form.use_captcha) { 351 352 setTimeout(function() { 353 grecaptcha.render('re-captcha_'+ formname, { 354 sitekey: data_sitekey, 355 callback: function() { 356 validateForm(contactForm, false); 357 } 358 }); 359 }, 1000); 360 } 361 362 //custom model pre-fill 363 let url = window.location.href; 364 url = new URL(url); 365 let model = url.searchParams.get("model"); 366 if(model){ 367 document.getElementById("message").value = `Hi, I would like more information about ${model}.` 368 } 369/* 370 var datePickerTime = function(currentDateTime) { 371 var day = currentDateTime.getDay(); 372 if (day === 6) { 373 this.setOptions({ 374 minTime: '10:00:00', 375 maxTime: '17:15:00', 376 }); 377 } else if (day === 1 || day === 2){ 378 this.setOptions({ 379 minTime: '09:00:00', 380 maxTime: '19:45:00', 381 }); 382 383 } else { 384 this.setOptions({ 385 minTime: '09:00:00', 386 maxTime: '17:45:00', 387 }); 388 } 389 }; 390 $('#appointment_day').datetimepicker({ 391 minDate: new Date(), 392 dayOfWeekStart : 0, 393 lang:'en', 394 step: 15, 395 format: 'm/d/Y g:i A', 396 formatTime: 'g:i A', 397 disabledWeekDays:[0], 398 onChangeDateTime: datePickerTime 399 400 }) 401 */ 402 for (let i = 0; i < datetime_ids.length; i++) { 403 $('#'+ datetime_ids[i]).datetimepicker({ 404 minDate: new Date(), 405 dayOfWeekStart : 0, 406 lang:'en', 407 step: 15, 408 format: 'm/d/Y g:i A', 409 formatTime: 'g:i A', 410 minTime: '09:15:00', 411 maxTime: '17:45:00', 412 disabledWeekDays:[0], 413 414 }).on('change', function(e){ 415 validateForm(contactForm, false); 416 }); 417 } 418 419 for (let i = 0; i < date_ids.length; i++) { 420 $('#'+ date_ids[i]).datepicker({ 421 minDate: new Date(), 422 }) 423 } 424 $($(contactForm).find(':file')).on('change', function() { 425 uploadFiles(this.files, $(contactForm).attr('name')); 426 }); 427 428 $($(contactForm).find('input')).bind('input', function() { 429 validateForm(contactForm, false); 430 }); 431 432 $($(contactForm).find('textarea')).bind('input', function() { 433 validateForm(contactForm, false); 434 }); 435 $($(contactForm).find('select')).on('change', function() { 436 validateForm(contactForm, false); 437 }); 438 439 if (formname == 'finance_app') 440 ff_init(config_elements['finance_app']); 441 442 if (calling_function == 'createPopup') { 443 $('#quickContent').prepend('<div id="closeContacts" onclick="closeContacts()"><span class="glyphicon glyphicon-remove">X</span></div>'); 444 $('#quickContacts').show(); 445 } 446 if (formname == 'register') 447 $('.mygarage-auth-section form input').attr("readonly", false); 448 449 if (typeof formCallback == 'function') 450 formCallback(); 451 }); 452} 453 454function createPopup(div, formname, veh_id, callback) { 455 $('body').prepend( 456 '<div id="quickContacts" style="z-index: 999999;">\ 457 <div id="quickContent" ></div>\ 458 </div>
458'); 459 insertForm(div, formname, veh_id, callback); 460} 461 462function closeContacts() { 463 $('#quickContacts').remove(); 464} 465 466function validateForm(form, submitted) { 467 468 let form_valid = true; 469 let form_arr = []; 470 471 for (let i = 0; form.elements[i]; i++) { 472 473 let element = form.elements[i]; 474 475 if ((typeof config_elements[form.name][element.name] != 'undefined' 476 && (config_elements[$(form).attr('name')][element.name].required)) 477 || element.name == 'g-recaptcha-response') { 478 479 if (element.name.match(/phone/)) { 480 $(element).attr("autocomplete", "off"); 481 let phone = element.value.replace(/[^\d]/g, "").replace(/^1/, ""); 482 phone = phone.substring(0, 10); 483 484 if (phone.length == 10) 485 element.value = phone.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3"); 486 else 487 element.value = phone; 488 } 489 490 let valid = element.name.match(/^email/) 491 ? validateEmail(element.value) 492 : element.value.length > 0; 493 494 valid = element.name.match(/phone/) 495 ? element.value.match(/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/) 496 : valid; 497 498 valid = element.type == 'checkbox' 499 ? element.checked 500 : valid; 501 502 503 if (valid) { 504 if (!submitted 505 && form.name.match(/^newsletter/) 506 && element.name == 'email') { 507 508 $.ajax({ 509 url: '/isapi_xml.php?module=form_popup&formname='+ form.name + '&action=subscriber_exists&email='+ element.value, 510 method: "GET", 511 success: function(data) { 512 if (data == 'Y') { 513 alert('Subscriber with the same email address already exists in our system!'); 514 element.style.outline = invalid_style; 515 $('#btnSubmit').prop('disabled', true); 516 } 517 } 518 }); 519 } 520 if (element.name == 'g-recaptcha-response') 521 $('#re-captcha_'+ form.name).css('outline', valid_style); 522 else 523 element.style.outline = valid_style; 524 525 } else if (element.name == 'g-recaptcha-response') { 526 $('#re-captcha_'+ form.name).css('outline', invalid_style); 527 form_valid = false; 528 } else { 529 element.style.outline = invalid_style; 530 form_valid = false; 531 } 532 } 533 534 if (element.type != 'checkbox' || element.checked) 535 form_arr.push({ 536 [element.name]: element.value 537 }); 538 }; 539 540 if (form_valid) $('#btnSubmit_'+ form.name).prop('disabled', false); 541 else $('#btnSubmit_'+ form.name).prop('disabled', true); 542 543 if (submitted && form_valid) { 544 545 $('#btnSubmit_'+ form.name).text('Processing...').prop('disabled', true); 546 547 let veh_id = $('[name="vid"]').val(), 548 vid_for_url = typeof veh_id != 'undefined' && veh_id.length > 0 ? '&vid='+ form[0].value : '', 549 form_type = form_type_bt ? '&_bt' : '', 550 uid = typeof(user.user_id) == 'string' ? '&uid='+ user.user_id : ''; 551 552 $.ajax({ 553 url: '/isapi_xml.php?module=form_popup'+ form_type + uid +'&formname='+ $(form).attr('name') + vid_for_url, 554 type: "POST", 555 dataType: 'json', 556 data: JSON.stringify(form_arr), 557 contentType: 'application/json;charset=UTF-8', 558 complete: function(data) { 559 let response = ''; 560 if (data.responseText.length > 12) 561 response = JSON.parse(data.responseText); 562 563 if(typeof(response) == 'object' && typeof(response.user_id) != 'undefined') { 564 user = response; 565 $('#fname_hi').text(user.fname); 566 $('#user_hi').show(); 567 data.responseText = 'OK'; 568 569 if ($(form).attr('name').match(/_bt?/) && typeof(nextStep) == 'function') 570 nextStep($(form).attr('name'), data.responseText); 571 else 572 $(form).html(getThankYouMessage(form.name)); 573 574 } else if (data.responseText == 'OK') { 575 if (form.name == 'login' || form.name == 'register') 576 location.href = ''; 577 else 578 $(form).html(getThankYouMessage(form.name)); 579 580 } else if (data.responseText == 'NR') { 581 registerPopup(); 582 583 } else if(response = JSON.parse(data.responseText) 584 && typeof(response) == 'object' 585 && typeof(response.user_id) != 'undefined') { 586 user = responce; 587 588 } else alert('Error!'); 589 } 590 }); 591 } 592} 593 594function getVehicleInfo(formname, vid) { 595 return new Promise((resolve, reject) => { 596 597 if (typeof(vid) == 'string' && vid.match(/^\d+/)) { 598 $.ajax({ 599 url: '/isapi_xml.php?module=form_popup&formname='+ formname +'&action=vehicle_info&vid='+ vid, 600 method: "GET", 601 success: function(data) { 602 resolve(data); 603 } 604 }); 605 } else 606 resolve([]); 607 }); 608} 609 610function setNewslTopics(formname) { 611 612 $.ajax({ 613 url: '/isapi_xml.php?module=form_popup&formname=newsletter_subscribe&action=get_newsl_topics', 614 method: "GET", 615 success: function(data) { 616 newsletter_topics = data; 617 let new_elements = []; 618 for (let i = 0; i < newsletter_topics.length; i++) { 619 let el = $('[name="nl_topics"]').parent().clone(); 620 $(el).find('input').attr('name', 'nl_topics_'+ i).val(newsletter_topics[i].topic_id); 621 622 if (typeof(form_data[formname]) != 'undefined' 623 && typeof(form_data[formname][1]) != 'undefined' 624 && form_data[formname][1].indexOf(newsletter_topics[i].topic_id) > -1) 625 $(el).find('input').attr('checked', 'checked'); 626 else if(i == 0) 627 $(el).find('input').attr('checked', 'checked'); 628 $(el).find('label').text(newsletter_topics[i].topic); 629 630 new_elements.push(el); 631 } 632 $('[name="nl_topics"]').parent().replaceWith(new_elements); 633
634 $('form[name="'+ formname +'"]').find('input:checkbox').bind('change', function() { 635 validateForm($('form[name="'+ formname +'"]')[0], false); 636 }); 637 } 638 }); 639} 640 641function uploadFiles(files, formname) { 642 643 let error = ''; 644 let form_data = new FormData(); 645 646 for (let count = 0; count<files.length; count++) { 647 let name = files[count].name; 648 let extension = name.split('.').pop().toLowerCase(); 649 650 if(jQuery.inArray(extension, ['gif','png','jpg','jpeg']) == -1) { 651 error += "Invalid " + count + " Image File" 652 } else { 653 form_data.append("files[]", files[count]); 654 } 655 } 656 657 if(error == '') { 658 $.ajax({ 659 url: '/isapi_xml.php?module=form_popup&formname='+ formname + '&action=upload', 660 method: "POST", 661 data: form_data, 662 contentType: false, 663 cache: false, 664 processData: false, 665 beforeSend:function() { 666 $(document.forms[formname]) 667 .find('#uploader_text') 668 .empty() 669 .text('Uploading...'); 670 }, 671 success:function(data) { 672 if (data == 'OK') { 673 $(document.forms[formname]) 674 .find('#uploader_text') 675 .empty() 676 .text(files.length +' files attached.'); 677 $(files).val(''); 678 } else alert(data); 679 } 680 }) 681 682 } else { 683 alert('Error!'); 684 } 685} 686 687function setModels(make) { 688 689 $('#model').empty(); 690 if (make == '') 691 setStock(false); 692 else { 693 let i = 0; 694 available_makes_models['makes'][make].map(function(v) { 695 $('#model').append('<option value="'+ v +'">'+ v +'</option>'); 696 }); 697 698 if (available_makes_models['makes'][make].length == 1) 699 setStock(available_makes_models['makes'][make]); 700 } 701} 702 703function setStock(model) { 704 $('#stockno').empty(); 705 if (typeof(model) == 'string') { 706 available_makes_models['stocks'][model].map(function(v) { 707 $('#stockno').append('<option value="'+ v +'">'+ v +'</option>'); 708 }); 709 } else { 710 711 Object.keys(available_makes_models['stocks']).map(function(v, k) { 712 available_makes_models['stocks'][v].map(function(v1, k1) { 713 $('#stockno').append('<option value="'+ v1 +'">'+ v1 +'</option>'); 714 }); 715 }); 716 } 717} 718 719function setMakeModel(stock) { 720 let make = '', model = ''; 721 Object.keys(available_makes_models['stocks']).map((v, k) => { 722 if (available_makes_models['stocks'][v].includes(stock)) { 723 model = v; 724 return; 725 } 726 }); 727 Object.keys(available_makes_models['makes']).map((v, k) => { 728 if (available_makes_models['makes'][v].includes(model)) { 729 make = v; 730 return; 731 } 732 }); 733 $('#make option').prop('selected', false); 734 $('#make option[value="'+ make +'"]').prop('selected', true); 735 736 setModels(make); 737} 738 739function validateEmail(email) { 740 if (email.length < 5) return false; 741 let emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 742 743 return emailReg.test(email); 744} 745 746function onContactsSubmit(obj) { 747 if (submit_block) { 748 imagesLimitAlert(); 749 return false; 750 } else { 751 validateForm(obj, true); 752 return false; 753 } 754} 755 756function setBlockReqired(name) { 757 $ ('#'+ name).find('input, select, textarea').each(function(i, obj) { 758 let el_id = $(obj).attr('id'); 759 if (typeof(config_forms['finance_app'].elements[el_id]) == 'object') { 760 config_elements['finance_app'][el_id].required = config_forms['finance_app'].elements[el_id].required; 761 } 762 }); 763} 764 765function unsetBlockReqired(name) { 766 $ ('#'+ name).find('input, select, textarea').each(function(i, obj) { 767 let el_id = $(obj).attr('id'); 768 if (typeof(config_forms['finance_app'].elements[el_id]) == 'object') { 769 config_elements['finance_app'][el_id].required = false; 770 } 771 }); 772} 773 774//--- Custom - Finance form --- 775 776let ff_init = (config) => { 777 778 unsetBlockReqired('co_applicant_block'); 779 unsetBlockReqired('prev_employer'); 780 unsetBlockReqired('prev_applicant_residence_block'); 781 782 $('[name=work_y]').on('change', function(){ 783 if($(this).val() < 2){ 784 setBlockReqired('prev_employer'); 785 $('#prev_employer').show('slow'); 786 } else { 787 unsetBlockReqired('prev_employer'); 788 $('#prev_employer').hide('slow'); 789 } 790 }); 791 792 $('[name=addr_y]').on('change', function(){ 793 if($(this).val() < 2) { 794 setBlockReqired('prev_applicant_residence_block'); 795 $('#prev_applicant_residence_block').show('slow'); 796 } else { 797 unsetBlockReqired('prev_applicant_residence_block'); 798 $('#prev_applicant_residence_block').hide('slow'); 799 } 800 }); 801 802 $('[name=co_work_y]').on('change', function(){ 803 if($(this).val() <= 2){ 804 setBlockReqired('co_prev_employer'); 805 $('#co_prev_employer').show('slow'); 806 } else { 807 unsetBlockReqired('co_prev_employer'); 808 $('#co_prev_employer').hide('slow'); 809 } 810 }); 811 812 $('[name=co_addr_y]').on('change', function(){ 813 if($(this).val() < 2) { 814 setBlockReqired('co_prev_applicant_residence_block'); 815 $('#co_prev_applicant_residence_block').show('slow'); 816 } else { 817 unsetBlockReqired('co_prev_applicant_residence_block'); 818 $('#co_prev_applicant_residence_block').hide('slow'); 819 } 820 }); 821 822 $('[name=co_applicant_active]').click(function(){ 823 if(this.checked) { 824 $('#co_applicant_block').show('slow'); 825 setBlockReqired('co_applicant_block'); 826 unsetBlockReqired('co_prev_applicant_residence_block'); 827 unsetBlockReqired('co_prev_employer'); 828 } else{ 829 $('#co_applicant_block').hide('slow'); 830 unsetBlockReqired('co_applicant_block'); 831 } 832 }); 833 834 $('[name=co_same_address]').click(function(){ 835 836 if($('[name=addr_y]').val() < 2) 837 $('#co_prev_applicant_residence_block').show('slow'); 838 else 839 $('#co_prev_applicant_residence_block').hide('slow'); 840 841 if(this.checked){ 842 $('#applicant_residence_block :input').map(function() { 843 $('[name=co_'+ $(this).prop("name") +']').val($(this).val()); 844 }); 845 $('#prev_applicant_residence_block :input').map(function() { 846 $('[name=co_'+ $(this).prop("name") +']').val($(this).val()); 847 }); 848 } else { 849 $('#co_applicant_residence_block :input').map(function() { 850 $(this).val(''); 851 }); 852 $('#prev_applicant_residence_block :input').map(function() { 853 $(this).val(''); 854 }); 855 } 856 }); 857};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.