https://www.cartakeback.com/wp-content/themes/cartakeback/assets/getQuotes.js?v=1739273472&ver=7.1.2
1$(document).ready(function(){ 2 3var getUrlParameter = function getUrlParameter(sParam) { 4 var sPageURL = window.location.search.substring(1), 5 sURLVariables = sPageURL.split('&'), 6 sParameterName, 7 i; 8 9 for (i = 0; i < sURLVariables.length; i++) { 10 sParameterName = sURLVariables[i].split('='); 11 12 if (sParameterName[0] === sParam) { 13 return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); 14 } 15 } 16 return false; 17}; 18 19var $loading = $('#loadingDiv'); 20var $loadingStandard = $('#loadingStandard'); 21var $loadingAccept = $('#loadingAccept'); 22var $loadingDriveIn = $('#loadingAccept'); 23var $loadingAccount = $('#loadingAccount'); 24 25$( "#postcode" ).on('blur input change paste', function() { 26 $('.findpostcode').removeClass('show'); 27}); 28 29// Cookie setting functions. 30var collectID; 31var collectID = $("#collectID").val(); 32 33function setCookie(name, value) { 34 var today = new Date(); 35 var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); // plus 30 days 36 document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString(); 37} 38 39var regexpress = /^(0[0-9, ]{9,13}|(N|n)(A|a))$/ig; 40var regEmail = /^(([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]))(((\s|;|,)\s?)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9]))*)$/g; 41var regPostcode = /^([Gg][Ii][Rr](\s?)0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))(\s?)[0-9][A-Za-z]{2})$/; 42 43$(".resetQuotation").click(function () { 44 // function storeValues() {
45 // setCookie("drive_quote_ref", '0'); 46 // setCookie("atf_id", ''); 47 // return true; 48 // } 49 // storeValues(); 50}); 51 52$(".accept-button").click(function () { 53 function storeValues() { 54 setCookie("drive_quote_ref", '0'); 55 setCookie("atf_id", ''); 56 return true; 57 } 58 storeValues(); 59}); 60 61//// Change function to fire on accept button to set drive_quote_ref and atf_id 62$("#backToCollect").click(function() { 63 function storeValues() { 64 setCookie("drive_quote_ref", '0'); 65 setCookie("atf_id", ''); 66 return true; 67 } 68 69 storeValues(); 70}); 71 72// Get Quotes Function Main Form 73$( "#getQuotes" ).click(function() { 74 var str = $("form#quote_form").serializeArray(); 75 var formData = {}; 76 77 $(str).each(function(i, field){ 78 formData[field.name] = field.value; 79 }); 80 81 var vehicleReg = formData["vrm"].length ? $.trim(formData["vrm"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#vrm").val().replace(/\s+/g, '').toUpperCase()); 82 var postCode = formData["postcode"].length ? $.trim(formData["postcode"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#postcode").val().replace(/\s+/g, '').toUpperCase()); 83 84 var newUrl = window.location.origin + '/instant-scrap-car-quotation'; 85 86 function storeValues() { 87 setCookie("postcode", postCode); 88 setCookie("vrm", vehicleReg); 89 setCookie("drive_quote_ref", '0'); 90 91 if (!vehicleReg.length) { 92 $(["select_car", "select_model", "select_fuel", "select_year"]).each(function(i, field){ 93 if (formData[field] && formData[field].length) { 94 setCookie(field, formData[field]); 95 } 96 }); 97 } 98 99 // setCookie("collectID", collectID); 100 return true; 101 } 102 103 // Form validation 104 let postcodeIsValid = regPostcode.test(postCode); 105 106 $("#vrm").attr("placeholder", "Enter Reg").css("border","none").removeClass("redplace"); 107 $("#select_model").attr("placeholder", "Model").css("border","none").removeClass("redplace"); 108 $("#postcode").attr("placeholder", "Enter Postcode").css("border","none").removeClass("redplace"); 109 110 // VRM 111 if ( !vehicleReg.length && ! $('#select_car').val() ) { 112 // No VRM and no Make 113 $("#vrm").attr("placeholder", "Registration is required").css("border","1px solid #ba1133").addClass("redplace"); 114 } else if ( !vehicleReg.length && ( $('#select_car').val() && ! $("#select_model").val() ) ) { 115 // No VRM, but a Make and no Model 116 $("#select_model").attr("placeholder", "Model is required").css("border","1px solid #ba1133").addClass("redplace"); 117 } else if ( !postCode.length ) { 118 $("#postcode").attr("placeholder", "Postcode is required").css("border","1px solid #ba1133").addClass("redplace"); 119 } else if ( ! postcodeIsValid ) { 120 $("#postcode").val('').attr("placeholder", "Postcode is invalid").css("border","1px solid #ba1133").addClass("redplace"); 121 } else { 122 var isAccountHolder = (parseInt(variables.isAccountHolder, 10) === 1); 123 var shouldReloadFlow = (!isAccountHolder); 124 125 if (shouldReloadFlow) { 126 $loading.removeClass('d-none'); 127 storeValues(); 128 129 setTimeout(function(){ 130 if (window.location.href == newUrl) { 131 location.reload(); 132 } else { 133 window.location.href = newUrl; 134 } 135 }, 500); 136 137 } else { 138 $.ajax({ 139 url: variables.wp_ajax_url, 140 beforeSend: function(){ 141 $loading.removeClass('d-none'); 142 }, 143 complete: function(){ 144 storeValues(); 145 146 setTimeout(function(){ 147 if(window.location.href == newUrl) { 148 location.reload(); 149 } else { 150 window.location.href = newUrl; 151 } 152 }, 500); 153 }, 154 type: 'POST', 155 data: { 156 'action': 'get_quotes', 157 'formvalues': formData, 158 }, 159 success: function(response){ 160 if ( response.data.IsRetrieval === false && response.data.CollectID !== false ) { 161 let gData = { 162 'transactionID': response.data.CollectID, 163 'event': 'SubmissionStageLoadOptions' 164 }; 165 166 if (response.data.Email !== false && response.data.Email.length) { 167 gData.userData = { 'email': response.data.Email }; 168 } 169 170 dataLayer.push(gData); 171 } 172 }, 173 error: function(response){ 174 //console.log(response); 175 } 176 }); 177 } 178 } 179}); 180 181var hash = $(location).attr('hash'); 182 183if ( hash == '#unknownReg' || hash == '#unknownPostcode' ) { 184 $(hash).collapse(); 185} 186 187// Get Quotes Quick Form 188$( "#getQuotesQuick" ).click(function() { 189 var str = $("form#quote_form").serializeArray(); 190 var formData = {}; 191 192 $(str).each(function(i, field){ 193 formData[field.name] = field.value; 194 }); 195 196 var vehicleReg = formData["vrm"].length ? $.trim(formData["vrm"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#vrm").val().replace(/\s+/g, '').toUpperCase()); 197 var postCode = formData["postcode"].length ? $.trim(formData["postcode"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#postcode").val().replace(/\s+/g, '').toUpperCase()); 198 199 var newUrl = window.location.origin + '/instant-scrap-car-quotation'; 200 201 function storeValues() {
202 setCookie("postcode", postCode); 203 setCookie("vrm", vehicleReg); 204 setCookie("drive_quote_ref", '0'); 205 return true; 206 } 207 208 // Form validation 209 let postcodeIsValid = regPostcode.test(postCode); 210 211 // VRM 212 if ( !vehicleReg.length ) { 213 $("#vrm").attr("placeholder", "Registration is required").css("border", "1px solid #ba1133").addClass("redplace"); 214 $('#quote_form #vrm + a').addClass('shown').attr('tabindex', '0'); 215 216 if ( str[1].value.length != "" ) { 217 $("#postcode").attr("placeholder", "Enter Postcode").css("border", "none").removeClass("redplace"); 218 $('#quote_form #postcode + a').removeClass('shown').attr('tabindex', '-1'); 219 return false; 220 } 221 } else { 222 $("#vrm").attr("placeholder", "Enter Reg").css("border", "none").removeClass("redplace"); 223 $('#quote_form #vrm + a').removeClass('shown').attr('tabindex', '-1'); 224 } 225 226 // Postcode 227 if ( !postCode.length ) { 228 $("#postcode").attr("placeholder", "Postcode is required").css("border","1px solid #ba1133").addClass("redplace"); 229 $('#quote_form #postcode + a').addClass('shown').attr('tabindex', '0'); 230 } else if ( ! postcodeIsValid ) { 231 $("#postcode").val('').attr("placeholder", "Postcode is invalid").css("border","1px solid #ba1133").addClass("redplace"); 232 $('#quote_form #postcode + a').addClass('shown').attr('tabindex', '0'); 233 } else { 234 var isAccountHolder = (parseInt(variables.isAccountHolder, 10) === 1); 235 var shouldReloadFlow = (!isAccountHolder); 236 237 if (shouldReloadFlow) { 238 $loading.removeClass('d-none'); 239 storeValues(); 240 241 setTimeout(function(){ 242 if (window.location.href == newUrl) { 243 location.reload(); 244 } else { 245 window.location.href = newUrl; 246 } 247 }, 500); 248 249 } else { 250 $("#postcode").attr("placeholder", "Enter Postcode").css("border", "none").removeClass("redplace"); 251 $('#quote_form #postcode + a').removeClass('shown').attr('tabindex', '-1'); 252 253 $.ajax({ 254 url: variables.wp_ajax_url, 255 beforeSend: function(){ 256 $loading.removeClass('d-none'); 257 }, 258 complete: function(){ 259 storeValues(); 260 261 setTimeout(function(){ 262 if (window.location.href == newUrl) { 263 location.reload(); 264 } else { 265 window.location.href = newUrl; 266 } 267 }, 500); 268 }, 269 type: 'POST', 270 data: { 271 'action': 'get_quotes_quick_form', 272 'formvalues': formData, 273 }, 274 success: function(response){ 275 if ( response.data.IsRetrieval === false && response.data.CollectID !== false ) { 276 let gData = { 277 'transactionID': response.data.CollectID, 278 'event': 'SubmissionStageLoadOptions' 279 }; 280 281 if (response.data.Email !== false && response.data.Email.length) { 282 gData.userData = { 'email': response.data.Email }; 283 } 284 285 dataLayer.push(gData); 286 } 287 }, 288 error: function(response){ 289 // console.log(response); 290 } 291 }); 292 } 293 } 294}); 295 296 297// Get Quotes Quick Form 298$( "#getQuotesPop" ).click(function() { 299 var str = $("form#quote_form_pop").serializeArray(); 300 var formData = {}; 301 302 $(str).each(function(i, field){ 303 formData[field.name] = field.value; 304 }); 305 306 var vehicleReg = formData["vrm"].length ? $.trim(formData["vrm"].replace(/\s+/g, '').toUpperCase()) : $.trim($(".vrm-pop").val().replace(/\s+/g, '').toUpperCase()); 307 var postCode = formData["postcode"].length ? $.trim(formData["postcode"].replace(/\s+/g, '').toUpperCase()) : $.trim($(".postcode-pop").val().replace(/\s+/g, '').toUpperCase()); 308 309 var newUrl = window.location.origin + '/instant-scrap-car-quotation'; 310 311 function storeValues() {
312 setCookie("postcode", postCode); 313 setCookie("vrm", vehicleReg); 314 setCookie("drive_quote_ref", '0'); 315 // setCookie("collectID", collectID); 316 return true; 317 } 318 319 // Form validation 320 let postcodeIsValid = regPostcode.test(postCode); 321 322 // VRM 323 if ( !vehicleReg.length ) { 324 if ( ! $('#select_car').val() ) { 325 $(".vrm-pop").attr("placeholder", "Registration is required").css("border","1px solid #ba1133").addClass("redplace"); 326 } 327 } 328 329 // Postcode 330 if ( !postCode.length ) { 331 $(".postcode-pop").attr("placeholder", "Postcode is required").css("border","1px solid #ba1133").addClass("redplace"); 332 } else if ( ! postcodeIsValid ) { 333 $(".postcode-pop").val('').attr("placeholder", "Postcode is invalid").css("border","1px solid #ba1133").addClass("redplace"); 334 } else { 335 var isAccountHolder = (parseInt(variables.isAccountHolder, 10) === 1); 336 var shouldReloadFlow = (!isAccountHolder); 337 338 if (shouldReloadFlow) { 339 $loading.removeClass('d-none'); 340 storeValues(); 341 342 setTimeout(function(){ 343 if (window.location.href == newUrl) { 344 location.reload(); 345 } else { 346 window.location.href = newUrl; 347 } 348 }, 500); 349 350 } else { 351 $.ajax({ 352 url: variables.wp_ajax_url, 353 beforeSend: function(){ 354 $loading.removeClass('d-none'); 355 }, 356 complete: function(){ 357 storeValues(); 358 359 setTimeout(function() { 360 if (window.location.href == newUrl) { 361 location.reload(); 362 } else { 363 window.location.href = newUrl; 364 } 365 }, 500); 366 }, 367 type: 'POST', 368 data: { 369 'action': 'get_quotes_quick_form', 370 'formvalues': formData, 371 }, 372 success: function(response){ 373 if ( response.data.IsRetrieval === false && response.data.CollectID !== false ) { 374 let gData = { 375 'transactionID': response.data.CollectID, 376 'event': 'SubmissionStageLoadOptions' 377 }; 378 379 if (response.data.Email !== false && response.data.Email.length) { 380 gData.userData = { 'email': response.data.Email }; 381 } 382 383 dataLayer.push(gData); 384 } 385 }, 386 error: function(response){ 387 // console.log(response); 388 } 389 }); 390 } 391 } 392}); 393 394$( "#getQuotesBlock" ).click(function() { 395 var str = $("form#quote_form_block").serializeArray(); 396 var formData = {}; 397 398 $(str).each(function(i, field){ 399 formData[field.name] = field.value; 400 }); 401 402 var vehicleReg = formData["vrm"].length ? $.trim(formData["vrm"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#vrm_quote_block").val().replace(/\s+/g, '').toUpperCase()); 403 var postCode = formData["postcode"].length ? $.trim(formData["postcode"].replace(/\s+/g, '').toUpperCase()) : $.trim($("#postcode_quote_block").val().replace(/\s+/g, '').toUpperCase()); 404 405 var newUrl = window.location.origin + '/instant-scrap-car-quotation'; 406 407 function storeValues() { 408 setCookie("postcode", postCode); 409 setCookie("vrm", vehicleReg); 410 setCookie("drive_quote_ref", '0'); 411 // setCookie("collectID", collectID); 412 return true; 413 } 414 415 // Form validation 416 let postcodeIsValid = regPostcode.test(postCode); 417 418 // VRM 419 if ( !vehicleReg.length ) { 420 if ( ! $('#select_car').val() ) { 421 $("#vrm_quote_block").attr("placeholder", "Registration is required").css("border","1px solid #ba1133").addClass("redplace"); 422 } 423 } 424 425 // Postcode 426 if ( !postCode.length ) { 427 $("#postcode_quote_block").attr("placeholder", "Postcode is required").css("border","1px solid #ba1133").addClass("redplace"); 428 } else if ( ! postcodeIsValid ) { 429 $("#postcode_quote_block").val('').attr("placeholder", "Postc
429ode is invalid").css("border","1px solid #ba1133").addClass("redplace"); 430 } else { 431 var isAccountHolder = (parseInt(variables.isAccountHolder, 10) === 1); 432 var shouldReloadFlow = (!isAccountHolder); 433 434 if (shouldReloadFlow) { 435 $loading.removeClass('d-none'); 436 storeValues(); 437 438 setTimeout(function(){ 439 if (window.location.href == newUrl) { 440 location.reload(); 441 } else { 442 window.location.href = newUrl; 443 } 444 }, 500); 445 446 } else { 447 $.ajax({ 448 url: variables.wp_ajax_url, 449 beforeSend: function(){ 450 $loading.removeClass('d-none'); 451 }, 452 complete: function(){ 453 storeValues(); 454 455 setTimeout(function() { 456 if (window.location.href == newUrl) { 457 location.reload(); 458 } else { 459 window.location.href = newUrl; 460 } 461 }, 500); 462 }, 463 type: 'POST', 464 data: { 465 'action': 'get_quotes_quick_form', 466 'formvalues': formData, 467 }, 468 success: function(response){ 469 if ( response.data.IsRetrieval === false && response.data.CollectID !== false ) { 470 let gData = { 471 'transactionID': response.data.CollectID, 472 'event': 'SubmissionStageLoadOptions' 473 }; 474 475 if (response.data.Email !== false && response.data.Email.length) { 476 gData.userData = { 'email': response.data.Email }; 477 } 478 479 dataLayer.push(gData); 480 } 481 }, 482 error: function(response){ 483 // console.log(response); 484 } 485 }); 486 } 487 } 488}); 489 490$.validator.addMethod('regexpress', function (value, element) { 491 //console.log( 'Phone: ' + value.match(regexpress) ); 492 return value.match(regexpress); 493}, ''); 494$.validator.addMethod('regEmail', function (value, element) { 495 //console.log( 'Email: ' + value.match(regEmail) ); 496 return value.match(regEmail); 497}, ''); 498$.validator.addMethod('regPostcode', function (value, element) { 499 //console.log( 'Email: ' + value.match(regEmail) ); 500 return value.match(regPostcode); 501}, ''); 502 503$("button#acceptQuote").click(function(){ 504 if ( ! $.cookie( 'collectID' ) ) { 505 var collectID = $('form#acceptance_form input[id="collectID"]').val(); 506 setCookie("collectID", collectID); 507 } 508}); 509 510$("#acceptance_form").validate({ 511 errorContainer: "#messageBox1", 512 errorLabelContainer: "#messageBox1 ul", 513 wrapper: "li", 514 debug: false, 515 focusCleanup: false, 516 errorClass: "invalid", 517 validClass: "success", 518 519 rules: { 520 firstname: "required", 521 yoursurname: "required", 522 523 // compound rule 524 email: { 525 required: true, 526 // email: true, 527 regEmail: true 528 }, 529 YourPhone: { 530 required: true, 531 regexpress: true 532 }, 533 YourStreet: { 534 required: true 535 }, 536 YourTown: { 537 required: true 538 }, 539 PostCode: { 540 required: true 541 } 542 543 }, 544 545 messages: { 546 firstname: "Please enter your first name", 547 yoursurname: "Please enter your surname", 548 email: "Please provide a valid email address", 549 YourPhone: "Please provide a valid phone number", 550 YourStreet: "Please enter your street", 551 YourTown: "Please enter your town", 552 PostCode: "Please enter a valid UK postcode", 553 }, 554 555 submitHandler: function(){ 556 function storeValues(){ 557 return true; 558 } 559 560 var str = $("#acceptance_form").serializeArray(); 561 562 if ( str[16].value == '1' ) { 563 var ajax_action = 'accept_offer_quote'; 564 } else { 565 var ajax_action = 'accept_instant_quote'; 566 } 567 568 $.ajax({ 569 url: variables.wp_ajax_url, 570 type: 'POST', 571 data: { 572 'action': ajax_action, 573 'formvalues': str, 574 }, 575 beforeSend: function(){ 576 $loadingAccept.removeClass('d-none'); 577 }, 578 complete: function(){ 579 580 }, 581 success: function(response){ 582 var data = response.data ? response.data : false;
583 var redirectURL = ''; 584 585 if ( data.CollectID && data.VRM && data.Postcode ) { 586 storeValues(); 587 588 redirectURL = window.location.origin + "/instant-scrap-car-quotation/?CollectID=" + data.CollectID + "&VRM=" + data.VRM + "&Postcode=" + data.Postcode; 589 } else { 590 redirectURL = window.location.origin + "/instant-scrap-car-quotation/"; 591 } 592 593 setTimeout(function(){ 594 window.location.href = redirectURL; 595 }, 500); 596 }, 597 error: function(response){ 598 //console.log('Error Response:' + response); 599 } 600 }); 601 } 602}); 603 604$("#drive_acceptance_form").validate({ 605 errorContainer: "#messageBox1", 606 errorLabelContainer: "#messageBox1 ul", 607 wrapper: "li", 608 debug:false, 609 focusCleanup: false, 610 errorClass: "invalid", 611 validClass: "success", 612 613 rules: { 614 firstname: "required", 615 yoursurname: "required", 616 // compound rule 617 email: { 618 required: true, 619 // email: true, 620 regEmail: true 621 }, 622 YourPhone: { 623 required: true, 624 regexpress: true 625 }, 626 YourStreet: { 627 required: true 628 }, 629 YourTown: { 630 required: true 631 }, 632 PostCode: { 633 required: true 634 } 635 636 }, 637 messages: { 638 firstname: "Please enter your first name", 639 yoursurname: "Please enter your surname", 640 email: "Please provide a valid email address", 641 YourPhone: "Please provide a valid phone number", 642 YourStreet: "Please enter your street", 643 YourTown: "Please enter your town", 644 PostCode: "Please enter a valid UK postcode", 645 }, 646 647 submitHandler: function(){ 648 function storeValues(){ 649 return true; 650 } 651 652 var str = $("#drive_acceptance_form").serializeArray(); 653 //console.log(str[16].value); 654 655 if ( str[16].value == '1' ) { 656 var ajax_action = 'accept_offer_quote'; 657 } else { 658 var ajax_action = 'accept_instant_quote'; 659 } 660 661 $.ajax({ 662 url: variables.wp_ajax_url, 663 type: 'POST', 664 data: { 665 'action': ajax_action, 666 'formvalues': str, 667 }, 668 beforeSend: function(){ 669 $loadingDriveIn.removeClass('d-none'); 670 }, 671 complete: function(){ 672 673 }, 674 success: function(response){ 675 var data = response.data ? response.data : false; 676 var redirectURL = ''; 677 678 if ( data.CollectID && data.VRM && data.Postcode ) { 679 storeValues(); 680 681 redirectURL = window.location.origin + "/instant-scrap-car-quotation/?CollectID=" + data.CollectID + "&VRM=" + data.VRM + "&Postcode=" + data.Postcode; 682 } else { 683 redirectURL = window.location.origin + "/instant-scrap-car-quotation/"; 684 } 685 686 setTimeout(function(){ 687 window.location.href = redirectURL; 688 }, 500); 689 }, 690 error: function(response){ 691 // console.log('Error Response:' + response); 692 } 693 }); 694 695 } 696}); 697 698// Accept Offer Quote 699$(".acceptOfferQuote").click(function() { 700 701 var collectID = $.cookie("collectID"); 702 var vehicleReg = $.cookie("vrm"); 703 var postCode = $.cookie("postcode"); 704 705 function storeValues() { 706 //setCookie("collectID", collectID); 707 setCookie("drive_quote_ref", '0'); 708 setCookie("atf_id", null); 709 return true; 710 } 711 712 var str = $("#acceptance_form").serializeArray(); 713 714 $.ajax({ 715 url: variables.wp_ajax_url, 716 type: 'POST', 717 data: { 718 'action': 'accept_offer_quote', 719 'formvalues': str, 720 }, 721 beforeSend: function(){ 722 $loadingStandard.removeClass('d-none'); 723 }, 724 complete: function(){ 725 storeValues(); 726 727 setTimeout(function() { 728 window.location.href += "?CollectID=" + collectID + "&VRM=" + vehicleReg + "&Postcode=" + postCode; 729 }, 500); 730 }, 731 success: function (response) { 732 // console.log('Success Response: ' + response); 733 }, 734 error: function (response) { 735 // console.log('Error Response:' + response); 736 } 737 }); 738}); 739 740$(".acceptDriveQuote").click(function () { 741 var driveQuoteRef = $(this).closest('.branch_location').attr('data-drive_quote_id'); 742 var atfID = $(this).closest('.branch_location').attr('data-atf_id'); 743 var hex = atfID.toString(16); 744 // var quotedPrice = ($this).closest('.quoted_price').text(); 745 // $(".updateprice").empty(); 746 // $(".updateprice").append(quotedPrice); 747 var newUrl = window.location.origin + '/drop-off-quote-acceptance/?atf=ctb' + hex; 748 749 var is_offer = $(this).closest('.branch_location').attr('data-is_offer'); 750 751 function storeValues() { 752 if ( ! $.cookie( 'collectID' ) ) { 753 var collectID = $('form#acceptance_form input[id="collectID"]').val();
754 setCookie("collectID", collectID); 755 } 756 setCookie("drive_quote_ref", driveQuoteRef); 757 setCookie("atf_id", atfID); 758 return true; 759 } 760 761 storeValues(); 762 763 setTimeout(function() { 764 window.location.href = newUrl; 765 }, 1000); 766}); 767 768// Accept Offer Quote 769/* 770$( ".updateaddressform" ).click(function () { 771 772 var str = $("#accept_update_form").serializeArray(); 773 774 $.ajax({ 775 url: variables.wp_ajax_url, 776 type: 'POST', 777 data: { 778 'action': 'update_customer', 779 780 'updatedformvalues': str, 781 }, 782 beforeSend: function(){ 783 $loadingStandard.removeClass('d-none'); 784 }, 785 complete: function(){ 786 setTimeout(function() { 787 $loadingStandard.addClass('d-none'); 788 }, 2500); 789 }, 790 success: function (response) { 791 // console.log(str); 792 setTimeout(function() { 793 location.reload(); 794 }, 1500); 795 }, 796 error: function (response) { 797 // console.log('Error Response:' + response); 798 } 799 }); 800}); 801*/ 802 803$("#accept_update_form").on('submit', function(e){ 804 e.preventDefault(); 805}).validate({ 806 errorContainer: "#messageBox1", 807 errorLabelContainer: "#messageBox1 ul", 808 wrapper: "li", 809 debug: false, 810 onkeyup: false, 811 onfocusout: false, 812 focusCleanup: false, 813 errorClass: "invalid", 814 validClass: "success", 815 rules: { 816 firstname: "required", 817 yoursurname: "required", 818 email: { 819 required: true, 820 validateEmail: true 821 }, 822 YourPhone: { 823 required: true, 824 validateTelephone: true 825 }, 826 YourStreet: { 827 required: true 828 }, 829 YourTown: { 830 required: true 831 }, 832 postCode: { 833 required: true 834 } 835 }, 836 messages: { 837 firstname: 'Please provide your forename', 838 yoursurname: 'Please provide your surname', 839 email: 'Please provide a valid email address', 840 YourPhone: 'Please provide a valid telephone number', 841 YourStreet: 'Please enter your street', 842 YourTown: 'Please enter your town', 843 postCode: 'Please enter a valid Postcode', 844 }, 845 submitHandler: function(){ 846 847 var str = $("#accept_update_form").serializeArray(); 848 849 $.ajax({ 850 url: variables.wp_ajax_url, 851 type: 'POST', 852 data: { 853 'action': 'update_customer', 854 'updatedformvalues': str, 855 }, 856 beforeSend: function(){ 857 $loadingStandard.removeClass('d-none'); 858 }, 859 complete: function(){ 860 setTimeout(function() { 861 $loadingStandard.addClass('d-none'); 862 }, 2500); 863 }, 864 success: function (response) { 865 // console.log(str); 866 setTimeout(function() { 867 location.reload(); 868 }, 1500); 869 }, 870 error: function (response) { 871 // console.log('Error Response:' + response); 872 } 873 }); 874 875 } 876}); 877 878$.validator.addMethod('validateEmail', function(value, element, params){ 879 return (this.optional(element) == true) || (this.optional( element ) === 'dependency-mismatch') || (value.match(regEmail)); 880}); 881 882$.validator.addMethod('validateTelephone', function(value, element, params){ 883 return (this.optional(element) == true) || (this.optional( element ) === 'dependency-mismatch') || (value.match(regexpress)); 884}); 885 886// Use Account Address 887$("#use_address").click(function() { 888 889 $.ajax({ 890 url: variables.wp_ajax_url, 891 type: 'POST', 892 data: { 893 'action': 'get_address', 894 }, 895 beforeSend: function(){ 896 $loading.removeClass('d-none'); 897 }, 898 complete: function(){ 899 $loading.addClass('d-none'); 900 }, 901 success: function (response) { 902 var returnedData = JSON.parse(response); 903 // console.log(returnedData); 904 905 $('#txtOrganisation').val(returnedData.val1); 906 // $('#txtBuilding').val(returnedData.val2); 907 $('#txtStreet').val(returnedData.val2); 908 // $('#txtLocality').val(returnedData.val4); 909 $('#txtTown').val(returnedData.val3); 910 $('#txtCounty').val(returnedData.val4); 911 $('#postcode').val(returnedData.val5); 912 913 }, 914 error: function (response) { 915 console.log('Error Response:' + response); 916 } 917 }); 918}); 919
920// Use My Details function 921$("#use_my_details").click(function(){ 922 $.ajax({ 923 url: variables.wp_ajax_url, 924 type: 'POST', 925 data: { 926 'action': 'get_user_details', 927 }, 928 beforeSend: function(){ 929 $loadingStandard.removeClass('d-none'); 930 }, 931 complete: function(){ 932 $loadingStandard.addClass('d-none'); 933 }, 934 success: function(response){ 935 var userDetails = JSON.parse( response ); 936 937 $('#acceptance_form #forename').val( userDetails.Forename ); 938 $('#acceptance_form #surname').val( userDetails.Surname ); 939 $('#acceptance_form #emailaddress').val( userDetails.Email ); 940 $('#acceptance_form #telday').val( userDetails.TelephoneDay ); 941 }, 942 error: function(response){ 943 console.log('Error Response:' + response); 944 } 945 }); 946}); 947 948$("#use_postcode").click(function() { 949 950 $.ajax({ 951 url: variables.wp_ajax_url, 952 type: 'POST', 953 data: { 954 'action': 'get_address', 955 }, 956 beforeSend: function(){ 957 $loadingStandard.removeClass('d-none'); 958 }, 959 complete: function(){ 960 $loadingStandard.addClass('d-none'); 961 }, 962 success: function (response) { 963 var returnedData = JSON.parse(response); 964 // console.log(returnedData); 965 $('#postcode').val(returnedData.val5); 966 967 }, 968 error: function (response) { 969 console.log('Error Response:' + response); 970 } 971 }); 972}); 973 974// Change Postcode on quote 975$( "#change" ).click(function(){ 976 977 var newpostVal = $("#changepostcode").val(); 978 var newpost = $.trim(newpostVal.replace(/\s+/g, '')); 979 980 let pattern = /^([Gg][Ii][Rr](\s?)0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))(\s?)[0-9][A-Za-z]{2})$/; 981 982 let isValid = pattern.test(newpost); 983 984 if ( ! isValid ) { 985 $('#postcode_error').removeClass('d-none').find('span').html('Please enter a valid UK postcode'); 986 return; 987 } else { 988 $('#postcode_error').addClass('d-none').find('span').html(''); 989 } 990 991 var str = $("#change_location").serializeArray(); 992 993 $.ajax({ 994 url: variables.wp_ajax_url, 995 type: 'POST', 996 beforeSend: function(){ 997 $loading.removeClass('d-none'); 998 }, 999 data: { 1000 'action': 'change_location', 1001 'formvalues': str, 1002 }, 1003 success: function (response) { 1004 console.log(response); 1005 if ( response.success === true ) { 1006 $('#postcode_error').addClass('d-none').html(''); 1007 setTimeout(function() { 1008 location.reload(); 1009 }, 500); 1010 } else { 1011 $loading.addClass('d-none'); 1012 $('#postcode_error').removeClass('d-none').find('span').html( response.data ); 1013 } 1014 }, 1015 error: function (response) { 1016 // console.log('Error Response:' + response); 1017 } 1018 }); 1019}); 1020 1021// User Login Function 1022$( "#userLogin" ).click(function () { 1023 1024 var uid = $("#userLoginForm").serializeArray(); 1025 1026 // console.log(); 1027 var user = uid[0].value; 1028 var pass = uid[1].value; 1029 1030 $("#userLoginForm #username").attr("placeholder", "User ID").css("border", "none").removeClass("redplace"); 1031 $("#userLoginForm #password").attr("placeholder", "Password").css("border", "none").removeClass("redplace"); 1032 1033 // VRM 1034 if ( user.length == "" ) { 1035 $('#userLoginForm #username').attr("placeholder", "Your user ID is required").css("border", "1px solid #ba1133").addClass("redplace"); 1036 } 1037 1038 if ( pass.length == "" ) { 1039 $('#userLoginForm #password').attr("placeholder", "Your password is required").css("border", "1px solid #ba1133").addClass("redplace"); 1040 } 1041 1042 if ( user.length == "" || pass.length == "" ) { 1043 return false; 1044 } else { 1045 // Fire ajax if form is complete 1046 $.ajax({ 1047 url: variables.wp_ajax_url, 1048 type: 'POST', 1049 data: { 1050 'action': 'user_login', 1051 'formvalues': uid, 1052 }, 1053 beforeSend: function(){ 1054 $loadingAccount.removeClass('d-none'); 1055 }, 1056 success: function (response) { 1057 if ( response == "" ) { 1058 dataLayer.push({ 'event': 'AccountHolderLogin' }); 1059 1060 setTimeout(function(){ 1061 $('#loginModal').modal('hide'); // Redundant? 1062 window.location = '/user-account'; 1063 }, 500); 1064 } else { 1065 if ($('#user_check').is(':empty')) { 1066 $("#user_check").append('<p class="red strong">' + response + '</p>'); 1067 } else { 1068 $("#user_check").empty(); 1069 $("#user_check").append('<p class="red strong">' + response + '</p>'); 1070 } 1071 1072 $loadingAccount.addClass('d-none'); 1073 } 1074 }, 1075 error: function (response) { 1076 console.log('Error Response:' + response); 1077 } 1078 }); 1079 } 1080}); 1081 1082$('#userLogout').click(function() { 1083 1084 $.ajax({ 1085 url: variables.wp_ajax_url, 1086 type: 'POST', 1087 data: { 1088 'action': 'user_log_out', 1089 }, 1090 complete: function(){ 1091 setTimeout(function() { 1092 window.location = '/user-account'; 1093 }, 500); 1094 }, 1095 success: function (response) { 1096 // console.log(response); 1097 }, 1098 error: function (response) { 1099 // console.log('Error Response:' + response); 1100 } 1101 }); 1102}); 1103 1104// User Change Password 1105$('#changePass').click(function() { 1106 1107 var str = $("#changePassword").serializeArray(); 1108 console.log(str); 1109 1110 $.ajax({ 1111 url: variables.wp_ajax_url, 1112 type: 'POST', 1113 data: { 1114 'action': 'change_password', 1115 'formvalues': str, 1116 }, 1117 1118 success: function (response) { 1119 // console.log(response.Message); 1120 // alert(response); 1121 // var values = jQuery.parseJSON(response); 1122 // console.log(values); 1123 if ($('#user-alert').is(':empty')) { 1124 $("#user-alert").append(response); 1125 } else { 1126 $("#user-alert").empty(); 1127 $("#user-alert").append(response); 1128 } 1129 }, 1130 error: function (response) { 1131 alert('Error Response:' + response); - 1132 $("#user-alert").append('Error! Please try again.'); 1133 } 1134 }); 1135}); 1136 1137$('#clearQuote').click(function() { 1138 $.ajax({ 1139 url: variables.wp_ajax_url, 1140 type: 'POST', 1141 data: { 1142 'action': 'clear_quote', 1143 }, 1144 complete: function() { 1145 setTimeout(function() { 1146 window.location = '/instant-scrap-car-quotation'; 1147 }, 1000); 1148 }, 1149 success: function (response) { 1150 // console.log(response); 1151 }, 1152 error: function (response) { 1153 // console.log('Error Response:' + response); 1154 } 1155 }); 1156}); 1157 1158$('#startRefresh').click(function() { 1159 1160 var currentPrice = $('#main-quote h3.your-quote--offer span.h1.x-large').text(); 1161 1162 setCookie( 'unrefreshedPrice', currentPrice.replace(/\D/g, '') ); 1163 1164 $('.first-quote').hide(); 1165 $('.questions-form').removeClass('d-none'); 1166 1167 $('#branchDropOff, #collapseExample').each(function(){ 1168 $( '#' + $(this).attr('id') ).collapse('hide'); 1169 }); 1170}); 1171 1172$('.accept-button').click(function() { 1173 $('.acceptance').removeClass('d-none'); 1174 $('.acceptance').show(); 1175}); 1176 1177$('#closeRefresh' ).click(function() { 1178 $.ajax({ 1179 url: window.location.href, 1180 headers: { 1181 "Pragma": "no-cache", 1182 "Expires": -1, 1183 "Cache-Control": "no-cache" 1184 } 1185 }).done(function () { 1186 window.location.reload(true); 1187 }); 1188}); 1189 1190// Contact Details 1191$('#quote-contact-details form').on('submit', function(e){ 1192 e.preventDefault(); 1193}).validate({ 1194 debug: false, 1195 onkeyup: false, 1196 onfocusout: false, 1197 focusCleanup: false, 1198 rules: { 1199 email: { 1200 required: true, 1201 validateEmail: true 1202 } 1203 }, 1204 messages: { 1205 email: variables.errorEmail 1206 }, 1207 submitHandler: function(form){ 1208 var formData = {}; 1209 1210 $($(form).serializeArray()).each(function(i, field){ 1211 formData[field.name] = field.value; 1212 }); 1213 1214 if(formData["email"].length){
1215 setCookie("email", formData["email"]); 1216 } 1217 1218 $.ajax({ 1219 url: variables.wp_ajax_url, 1220 beforeSend: function(){ 1221 $loading.removeClass('d-none'); 1222 }, 1223 complete: function(){ 1224 var newUrl = window.location.origin + '/instant-scrap-car-quotation'; 1225 1226 setTimeout(function(){ 1227 if(window.location.href == newUrl) { 1228 location.reload(); 1229 } else { 1230 window.location.href = newUrl; 1231 } 1232 }, 500); 1233 }, 1234 type: 'POST', 1235 data: { 1236 'action': 'get_quotes', 1237 'formvalues': formData, 1238 }, 1239 success: function(response){ 1240 if ( response.data.IsRetrieval === false && response.data.CollectID !== false ) { 1241 let gData = { 1242 'transactionID': response.data.CollectID, 1243 'event': 'SubmissionStageLoadOptions' 1244 }; 1245 1246 if (response.data.Email !== false && response.data.Email.length) { 1247 gData.userData = { 'email': response.data.Email }; 1248 } 1249 1250 dataLayer.push(gData); 1251 } 1252 }, 1253 error: function(response){ 1254 location.reload(); 1255 } 1256 }); 1257 } 1258}); 1259// END Contact Details 1260 1261$('form#questions').on('submit', function(e){ 1262 e.preventDefault(); 1263}).validate({ 1264 debug: false, 1265 onfocusout: false, 1266 focusCleanup: false, 1267 ignore: '', 1268 rules: { 1269 question1: { 1270 required: true 1271 }, 1272 question2: { 1273 required: true 1274 }, 1275 question4: { 1276 required: true 1277 }, 1278 }, 1279 messages: { 1280 question1: 'Please tell us whether the car starts and drives', 1281 question2: 'Please tell us whether the car has ever been written off', 1282 question4: 'Please tell us whether the car has more than 3 months MOT left', 1283 }, 1284 errorPlacement: function(error, element){ 1285 if ( element.is(':radio') ) { 1286 error.appendTo( element.closest('.col-12') ); 1287 } else { 1288 error.insertAfter( element ); 1289 } 1290 }, 1291 submitHandler: function(form){ 1292 $('#refreshQuote').hide(); 1293 $('.drop-off').hide(); 1294 $('.acceptance').removeClass('show'); 1295 $('#loadingRefresh').removeClass('d-none'); 1296 1297 var data = {}; 1298 1299 // Set Variables for Quote Refresh function 1300 var decimal = parseInt(collectID); 1301 var hex = decimal.toString(16); 1302 1303 var startsDrives = $('input[name=question1]:checked').val(); 1304 var writtenOff = $('input[name=question2]:checked').val(); 1305 var actualMileage = $('input[name=question3]').val(); 1306 var MOT = $('input[name=question4]:checked').val(); 1307 1308 var answers = { 1309 'WriteOff': writtenOff, 1310 'StartsAndDrives': startsDrives, 1311 }; 1312 1313 if ( typeof actualMileage !== "undefined" ) { 1314 answers['ActualMileage'] = actualMileage; 1315 } 1316 1317 if ( typeof MOT !== "undefined" ) { 1318 answers['MOTHas3Months'] = MOT; 1319 } 1320 1321 data['collectid'] = hex; 1322 data['answers'] = answers; 1323 1324 $.ajax({ 1325 url: variables.apiURL + '/api/enquiry/submitanswersandgetquote', 1326 type: 'POST', 1327 headers: { 1328 'X-API-KEY': variables.apiKey, 1329 'X-API-USER': variables.apiUser, 1330 'Content-Type': 'application/json', 1331 }, 1332 beforeSend: function(){ 1333 $loading.removeClass('d-none'); 1334 //console.log(JSON.stringify(data)); 1335 //return false; 1336 }, 1337 complete: function(){ 1338 location.reload(); 1339 }, 1340 data: JSON.stringify(data), 1341 success: function(response) { 1342 var newprice = response.CollectPrice; 1343 var price = newprice.toLocaleString('en-UK').replace(',', ''); 1344 1345 setCookie('refreshedprice', price); 1346 1347 return true; 1348 }, 1349 error: function(response) { 1350 1351 } 1352 }); 1353 } 1354}); 1355 1356$.validator.addMethod( 'pastDate', function( value, element ) { 1357 if ( $('form.questions input[name="question4"]:checked').val() != 2 ) { 1358 $(element).prop('value', ''); 1359 return true; 1360 } 1361 1362 var currentDate = new Date().setHours( 0, 0, 0, 0 ); 1363 var selectedDate = new Date(value); 1364 1365 return ( ( this.optional(element) == true ) || ( this.optional( element ) === 'dependency-mismatch' ) || ( currentDate <= selectedDate ) ); 1366}); 1367 1368$.validator.addMethod( 'futureDate', function( value, element ) { 1369 if ( $('form.questions input[name="question4"]:checked').val() != 2 ) { 1370 $(element).prop('value', ''); 1371 return true; 1372 } 1373 1374 var currentDate = new Date(); 1375 var selectedDate = new Date(value); 1376 var maximumDate = currentDate.setMonth( currentDate.getMonth() + 3 ); 1377 1378 return ( ( this.optional(element) == true ) || ( this.optional( element ) === 'dependency-mismatch' ) || ( selectedDate <= maximumDate ) ); 1379}); 1380 1381function monthDifference( dateFrom, dateTo ) { 1382 return dateTo.getMonth() - dateFrom.getMonth() + ( 12 * ( dateTo.getFullYear() - dateFrom.getFullYear() ) ); 1383} 1384 1385function formatMileageSlider( mileage, maximum, stepSize ) { 1386 var output = mileage; 1387 1388 if ( mileage == maximum ) { 1389 output = 'Over ' + new Intl.NumberFormat('en-GB').format( ( maximum - stepSize ) ); 1390 } else { 1391 output = 'Up to ' + new Intl.NumberFormat('en-GB').format( mileage ); 1392 } 1393 1394 return output; 1395} 1396 1397function actualMileage() { 1398 var val = $('#question3 .form-range').val(); 1399 var max = $('#question3 .form-range').prop('max'); 1400 var step = $('#question3 .form-range').prop('step'); 1401 1402 $('#question3 label.form-label').html( formatMileageSlider( val, max, step ) ); 1403} 1404 1405function hideShowMOTDue( answer ) { 1406 if ( answer == 2 ) { 1407 $('#question5').removeClass('d-none').addClass('d-block'); 1408 } else { 1409 $('#question5').removeClass('d-block').addClass('d-none'); 1410 } 1411} 1412 1413// Disallow default datepicker 1414$('.questions-form form.questions input[type="date"]').on('click', function(){ 1415 return false;
1416}); 1417 1418// Show ActualMileage if ApproxMileage == 2 (No) 1419actualMileage(); 1420/* 1421$('.questions-form form.questions .question3').on('click', function () { 1422 hideShowActualMileage( this.value ); 1423}); 1424*/ 1425 1426// Update slider label 1427$('#question3 .form-range').on('input', function() { 1428 var val = this.value; 1429 var max = $(this).prop('max'); 1430 var step = $(this).prop('step'); 1431 1432 $('#question3 label.form-label').html( formatMileageSlider( val, max, step ) ); 1433}); 1434 1435// Show MOTDue if MOTHas3Months == 2 (No) 1436hideShowMOTDue( $('.questions-form form.questions .question4:checked').val() ); 1437$('.questions-form form.questions .question4').on('click', function () { 1438 hideShowMOTDue( this.value ); 1439}); 1440 1441// Clear values from refreshed quote if radio buttons are actioned again. 1442$('#group1, #group2, #group3, #group4, #group5').on('click', function () { 1443 $("#refreshQuote").show(); 1444 $("#refreshed_quote").empty(); 1445}); 1446 1447$( '#sendDetails' ).click(function () { 1448 1449 var emailAdd = $('input[name=cxemail]').val(); 1450 var mobileTel = $('input[name=cxmobile]').val(); 1451 1452 var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 1453 var phoneRegex = /^\s?((07|\+447)( ?[0-9]){9}\s?)$/; 1454 1455 var isValidPhone = phoneRegex.test(mobileTel); 1456 var isValidEmail = emailRegex.test(emailAdd); 1457 1458 var settings = { 1459 url: variables.apiURL + "/api/enquiry/customercontact", 1460 method: 'POST', 1461 timeout: 0, 1462 headers: { 1463 'X-API-KEY': variables.apiKey, 1464 'X-API-USER': variables.apiUser, 1465 'Content-Type': 'application/json', 1466 }, 1467 data: JSON.stringify({ 1468 'collectid': collectID, 1469 'email': emailAdd, 1470 'mobilenumber': mobileTel 1471 }) 1472 }; 1473 1474 if (isValidPhone || isValidEmail) { 1475 $.ajax(settings).done(function (response) { 1476 $('#sendQuoteModal').modal('hide'); 1477 }); 1478 } else { 1479 if ($('#errordiv').is(':empty')) { 1480 $('#errordiv').append('<p class="strong mt-3 text-center red">Please enter a valid UK phone number or email address.</p>'); 1481 } else { 1482 $('#errordiv').empty(); 1483 $('#errordiv').append('<p class="strong mt-3 text-center red">Please enter a valid UK phone number or email address.</p>'); 1484 } 1485 } 1486}); 1487 1488$('#select_car').on('change', function() { 1489 var selected = this.value; 1490 var select = $('#select_model'); 1491 1492 var settings = { 1493 url: variables.apiURL + '/api/enquiry/getallmodelsformake', 1494 method: 'POST', 1495 timeout: 0, 1496 headers: { 1497 'X-API-KEY': variables.apiKey, 1498 'X-API-USER': variables.apiUser, 1499 'Content-Type': "text/plain", 1500 }, 1501 data: JSON.stringify({ 1502 'make': selected, 1503 }) 1504 }; 1505 1506 $.ajax(settings).done(function(response) { 1507 var availableTags = response; 1508 1509 $( '#select_model' ).autocomplete({ 1510 source: availableTags 1511 }); 1512 }); 1513 1514 }); 1515 1516 $( '.start_quote' ).on( 'click', function() { 1517 var accountReference = $(this).attr('value'); 1518 var codRef = $(this).attr('codref'); 1519 var codKey = $(this).attr('codkey'); 1520 function storeValues() { 1521 setCookie('account_reference', accountReference, 1); 1522 setCookie('cod_ref', codRef, 1); 1523 setCookie('cod_key', codKey, 1); 1524 return true; 1525 } 1526 storeValues(); 1527 setTimeout(function() { 1528 window.location = '/instant-scrap-car-quotation'; 1529 }, 1500); 1530 }); 1531 1532$('#preference_form').on('submit', function(e){ 1533 e.preventDefault(); 1534 1535 var collectid = $('[name="collect_id"]', this).val(); 1536 var vrm = $('[name="vrm"]', this).val(); 1537 var sharedEmailPreference = $('[name="shared_email_preference"]', this).val() === '1'; 1538 var sharedPhonePreference = $('[name="shared_phone_preference"]', this).val() === '1'; 1539 1540 1541 var pref = { 1542 collectID: collectid, 1543 vrm: vrm, 1544 answers: {} 1545 }; 1546 1547 if ( $('#customerEmail', this).length ) { 1548 pref.answers.customerEmail = $('#customerEmail', this).is(":checked") ? false : true; 1549 1550 if ( sharedEmailPreference ) { 1551 pref.answers.locationEmail = pref.answers.customerEmail; 1552 } 1553 } 1554 1555 if ( $('#customerTel', this).length ) { 1556 pref.answers.customerPhone = $('#customerTel', this).is(":checked") ? false : true; 1557 1558 if ( sharedPhonePreference ) { 1559 pref.answers.locationPhone = pref.answers.customerPhone; 1560 } 1561 } 1562 1563 if ( $('#locationEmail', this).length ) { 1564 pref.answers.locationEmail = $('#locationEmail', this).is(":checked") ? false : true; 1565 } 1566 1567 if ( $('#locationTel', this).length ) { 1568 pref.answers.locationPhone = $('#locationTel', this).is(":checked") ? false : true; 1569 } 1570 1571 $.ajax({ 1572 url: variables.wp_ajax_url, 1573 type: 'POST', 1574 data: { 1575 'action': 'save_contact_preferences', 1576 'formValues': pref, 1577 }, 1578 success: function (response) { 1579 $("#pref_response").empty(); 1580 $("#pref_response").append('<p class="strong">Preferences saved.</p>'); 1581 // console.log(response); 1582 }, 1583 error: function (response) { 1584 // console.log('Error Response:' + response); 1585 } 1586 }); 1587}); 1588 1589$("#restartQuote").click(function() { 1590 $.ajax({ 1591 url: variables.wp_ajax_url, 1592 type: 'POST', 1593 data: { 1594 'action': 'restart_quote' 1595 }, 1596 beforeSend: function(){ 1597 $loadingStandard.removeClass('d-none'); 1598 }, 1599 complete: function(){ 1600 window.location.href = window.location.origin + '/instant-scrap-car-quotation'; 1601 }, 1602 success: function (response) { 1603 1604 }, 1605 error: function (response) { 1606 // console.log('Error Response:' + response); 1607 } 1608 }); 1609}); 1610 1611}); 1612 1613function scrollToElement( elementID ) { 1614 var elmnt = document.getElementById( elementID.substr(1) ); 1615 elmnt.scrollIntoView({behavior:'smooth', block:'start'}); 1616} 1617 1618$('a[data-bs-target="#changeLocation"]').click(function(){ 1619 $('#branchDropOff, #collapseExample').each(function(){ 1620 $( '#' + $(this).attr('id') ).collapse('hide'); 1621 }); 1622}); 1623 1624$('.scroll-to-element').click(function(){ 1625 var $href = $(this).attr('href'); 1626 var $bsTarget = $(this).data('bs-target'); 1627 1628 $('#branchDropOff, #collapseExample, #changeLocation').each(function(){ 1629 if ( '#' + $(this).attr('id') != $bsTarget ) { 1630 $( '#' + $(this).attr('id') ).collapse('hide'); 1631 } 1632 }); 1633 1634 $( $bsTarget ).on('shown.bs.collapse', function(){ 1635 if ( $bsTarget != '#collapseExample' ) { 1636 $('.accept-button').show(400, function(){ 1637 scrollToElement( $href ); 1638 }); 1639 } else { 1640 $('.accept-button').hide(400, function(){ 1641 scrollToElement( $href ); 1642 }); 1643 } 1644 }); 1645});
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.