/* ############################ VALIDATION FOR FORMS ############################ */ $(document).ready(function () { var mainform = $("#main-form"); var vinform = $("#vinform"); var modalform = $("#modal-form"); var activeXfinity = $("#activateform"); $.validator.setDefaults({ ignore: [], debug: false, success: "valid" }); /* enhance html validation method */ $.validator.methods.email = function( value, element ) { return this.optional( element ) || /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test( value ); } /* ############# Main Form ############# */ // Add US Phone Validation jQuery.validator.addMethod('phoneUS', function(phone_number, element) { phone_number = phone_number.replace(/\s+/g, ''); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/); }, 'Please enter a valid phone number.'); mainform.validate({ rules: { firstName: { required: true }, lastName: { required: true }, accountNumber: { required: true }, phoneNumber: { required: true }, mainformEmail: { required: true, email: true }, accountNumberConfirm: { equalTo : "#accountNumber" }, 'checkingsavings': { required: true }, agreeCheck: { required: true }, termsCheck: { required: true }, creditUnion: { required: true } }, messages: { firstName: { required: "Please provide your first name.", }, lastName: { required: "Please provide your last name.", }, accountNumber: { required: "Please provide your account number.", }, phoneNumber: { required: "Please enter a valid phone number.", }, mainformEmail: { required: "Please enter a valid email address.", email: "Please enter a valid email address.", }, accountNumberConfirm: { equalTo: "Please confirm your account number.", }, agreeCheck: { required: "Please confirm you are an active member.", }, termsCheck: { required: "Please agree to the Terms and Conditions.", }, creditUnion: { required: "Please select a credit union.", } } }); $("#activateform").submit(function(event) { //if (mainform.valid() == true) { //stop submit the form, we will post it manually. event.preventDefault(); // AJAX CALL TO VALIDATE 30 day active var myformCR = document.getElementById("activateform"); var fdCR = new FormData(myformCR); var aTag = $("a[name='claim']"); $.ajax({ url: "/templates/lmcur_xfinity/complete_check30.php", data: fdCR, cache: false, processData: false, contentType: false, type: 'POST', success: function (response) { //alert(response); if (response == 'GOOD') { // SUCCESSFUL VIN LOOKUP // HIDE MAIN FORM $("#activateform").hide(); // HIDE VIN FORM $("#vinform").hide(); $("#ClaimHeader").hide(); $("#ClaimHeaderOrangeBar").hide(); // $(".formSuccess").addClass("showMsg"); $("#main-form").show(); $('html,body').animate({scrollTop: aTag.offset().top}, 'cashreward'); } else if(response == 'USED'){ //alert('used'); // VIN ALREADY USED $("#activeEnter-error").html( 'Sorry this offer is only available on new connected Xfinity services.

Looking to add new Xfinity service? Shop Now' ); $("#activeEnter-error").show(); $('#txtData1').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); $("#RadioActiveAcc").hide(); $("#RadioActiveAccYes").hide(); $("#RadioActiveAccNo").hide(); $("#ActiveAccText").hide(); $("#SubmitActive_Action").hide(); // dataLayer.push({'event':'Comcast', 'eventCategory':'account_Lookup', 'eventAction':'Vin_Check', 'eventLabel':'Used', 'eventValue':''}); } else { // GENERAL ERROR $("#activeEnter-error").text('There was an error submitting whether you activated new Xfinity service in the past 30 days. Please try again.'); $("#activeEnter-error").show(); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); } } }); //} }); $("#main-form").submit(function(event) { if(mainform.valid() == true) { //stop submit the form, we will post it manually. event.preventDefault(); // AJAX CALL TO VALIDATE VIN var myformCR = document.getElementById("main-form"); var fdCR = new FormData(myformCR); var aTag = $("a[name='claim']"); $.ajax({ url: "/templates/lmcur_xfinity/complete_cashreward.php", data: fdCR, cache: false, processData: false, contentType: false, type: 'POST', success: function (response) { //alert(response); if(response == 'GOOD'){ // SUCCESSFUL VIN LOOKUP // HIDE MAIN FORM $("#main-form").hide(); // HIDE VIN FORM $("#vinform").hide(); $("#ClaimHeader").hide(); $("#ClaimHeaderOrangeBar").hide(); // $(".formSuccess").addClass("showMsg"); $("#formSuccess").show(); $('html,body').animate({scrollTop: aTag.offset().top},'cashreward'); }else{ // GENERAL ERROR $("#vinEnter-error").text( 'There was an error submitting your Xfinity Account. Please try again.' ); $("#vinEnter-error").show(); $('#vinEnter').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); } }}); // END AJAX CALL TO VALIDATE VIN // $("#main-form", "#vinform", "section.section-form>.container>h3", "section.section-form>.container>.orangeBar").addClass('hide'); //initiate submission steps here, disable return false return false; //disable submission } }); //$("#firstName, #lastName, #phoneNumber, #accountNumber, #accountNumberConfirm, #creditUnion, #mainformEmail, #inlineRadio1, #inlineRadio2, #agreeCheck, #termsCheck").on("change keyup", function() { // $(this).valid(); // // if(mainform.validate().checkForm() == true) { // $("#main-form button").prop('disabled', false); // } else { // $("#main-form button").prop('disabled', true); // } //}); $("input#termsCheck").click(function() { $("#firstName, #lastName, #phoneNumber, #accountNumber, #accountNumberConfirm, #creditUnion, #mainformEmail, #inlineRadio1, #inlineRadio2, #agreeCheck, #termsCheck").valid(); if(mainform.validate().checkForm() == true) { $("#main-form button").prop('disabled', false); } else { $("#main-form button").prop('disabled', false); // $("#termsCheck").prop('checked', false);//Added by ben } }) function phoneMask() { var num = $(this).val().replace(/\D/g,''); $(this).val('(' + num.substring(0,3) + ') ' + num.substring(3,6) + '-' + num.substring(6,10)); } $('#phoneNumber').keyup(phoneMask); $("#ClaimAnotherReward").click(function() { $("#vinform").show(); $(".formSuccess").removeClass("showMsg"); $("#ClaimHeader").show(); $("#ClaimHeaderOrangeBar").show(); $('#vinEnter').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); }); /* ############# VIN Form ############# */ vinform.validate({ rules: { txtData1: { required: true, alphanumeric: true, minlength: 8 } }, messages: { txtData1: { required: "Xfinity account must be the last eight digits", alphanumeric: "Xfinity account must be the last eight digits", minlength: "Xfinity account must be the last eight digits", } } }); $("#vinform").submit(function(event) { if(vinform.valid() == true) { // $("#vinEnter").prop('disabled', true); //stop submit the form, we will post it manually. event.preventDefault(); // AJAX CALL TO VALIDATE VIN var myform = document.getElementById("vinform"); var fd = new FormData(myform); //alert (JSON.stringify(fd)); //alert(fd); $.ajax({ url: "/templates/lmcur_xfinity/xfinity_account_lookup.php", data: fd, cache: false, processData: false, contentType: false, type: 'POST', success: function (response) { $("#vinEnter").prop('disabled', true); //alert(response); // SPLIT RESPONSE var theresponse = response.split("#"); //alert(theresponse[0]); if(theresponse[0] == 'GOOD'){ //alert('success'); // SUCCESSFUL VIN LOOKUP // PASS VIN $("#VIN_Value").text( $("#txtData1").val().toUpperCase() ); if(theresponse.length == 4) { $("#creditUnion").val(theresponse[1]); $("#CURnt").val(theresponse[2]); $("#CUCharterID").val(theresponse[3]); $('#ShowCUResults').html("Routing Number: " + theresponse[2] + ""); } // SHOW 30 day FORM $("#activateform").show(); // HIDE VIN FORM $("#vinform").hide(); $.getJSON('https://ipapi.co/json/', function(data) { $("#CUZipCode").val(data.postal); }); dataLayer.push({'event':'Comcast', 'eventCategory':'account_Lookup', 'eventAction':'Vin_Check', 'eventLabel':'Valid', 'eventValue':''}); }else if(theresponse[0] == 'BAD'){ //alert('bad'); // VIN NOT FOUND $("#vinEnter-error").text( 'The Xfinity Account could not be found. Please try again.' ); $("#vinEnter-error").show(); $('#txtData1').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); console.log('THIS IS FIRING'); window.dataLayer = window.dataLayer || []; window.dataLayer.push({'event':'Comcast', 'eventCategory':'account_Lookup', 'eventAction':'Vin_Check', 'eventLabel':'Not_Found', 'eventValue':''}); console.log('THIS IS FIRING 2'); }else if(theresponse[0] == 'USED'){ //alert('used'); // VIN ALREADY USED $("#vinEnter-error").text( 'The Xfinity account is already registered.' ); $("#vinEnter-error").show(); $('#txtData1').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); dataLayer.push({'event':'Comcast', 'eventCategory':'account_Lookup', 'eventAction':'Vin_Check', 'eventLabel':'Used', 'eventValue':''}); }else{ // GENERAL ERROR //alert('error'); $("#vinEnter-error").text( 'There was an error submitting your Xfinity Acocunt. Please try again.' ); $("#vinEnter-error").show(); $('#txtData1').val(""); $("#vinEnter").prop('disabled', false); $('#SubmitVin_Action').prop('disabled', true); $("#vinHelpBlock").hide(); dataLayer.push({'event':'Comcast', 'eventCategory':'account_Lookup', 'eventAction':'Vin_Check', 'eventLabel':'Gen_Error', 'eventValue':''}); } }}); // END AJAX CALL TO VALIDATE VIN //initiate submission steps here, disable return false return false; //disable submission } }); $("#txtData1").on("change keyup", function() { $('#txtData1').valid(); if(vinform.validate().checkForm() == true) { $("#vinform button").prop('disabled', false); $("#vinHelpBlock").show(); } else { $("#vinform button").prop('disabled', true); $("#vinHelpBlock").hide(); } }); // $("#vinEnter").on("focus", function() {$("#vinHelpBlock").show()}) /* ############# Modal Form ############# */ modalform.validate({ validClass: "valid", rules: { modalemail: { required: true, email: true }, modalzipCode: { required: true, digits: true, minlength: 5 } }, messages: { modalemail: { required: "Please provide your email.", email: "Please provide a valid email.", }, modalzipCode: { required: "Please provide your zip code.", digits: "Please provide a valid zip code.", minlength: "Please provide a valid zip code.", } } }); function close_modal() { $('.modal').fadeOut(500); $('.modal').removeClass('valid'); //$('.modal').removeClass('shown'); $("#modalemail").val(''); $("#modalzipCode").val(''); } $("#modal-form").submit(function(event) { event.preventDefault(); if(modalform.valid() == true) { // AJAX CALL TO MODAL FORM var mymodalform = document.getElementById("modal-form"); var fdmodal = new FormData(mymodalform); $.ajax({ url: "/templates/lmcur_carvana_2021/post_loan_lead.php", data: fdmodal, cache: false, processData: false, contentType: false, type: 'POST', success: function (response) { if(response == 'GOOD') { $(".modal").addClass('valid'); setTimeout(close_modal, 3000); $("#ohHeyConfirm").show(); $("#ohHey").hide(); }else{ //alert('ERROR'); } }}) //initiate submission steps here, disable return false return false; //disable submission } }); $("#modalemail, #modalzipCode").on("blur", function() { //$("#modalemail, #modalzipCode").on("change keyup", function() { $(this).valid(); if(modalform.validate().checkForm() == true) { $("#modal-form button").prop('disabled', false); } else { $("#modal-form button").prop('disabled', true); } }); $("#modalzipCode").on("change keyup", function() { //$("#modalemail, #modalzipCode").on("change keyup", function() { if($("#modalzipCode").val().length > 4) { $(this).valid(); if (modalform.validate().checkForm() == true) { $("#modal-form button").prop('disabled', false); } else { $("#modal-form button").prop('disabled', true); } } }); // CU Search $("#creditUnion").on("keyup", function() { //$("#modalemail, #modalzipCode").on("change keyup", function() { var search = $("#creditUnion").val(); if($("#creditUnion").val().length > 2) { // AJAX CALL // AJAX CALL TO VALIDATE VIN var myformCUF = document.getElementById("main-form"); var fdCUF = new FormData(myformCUF); $.ajax({ url: "/templates/lmcur_carvana_2021/finder_prod.php", data: fdCUF, cache: false, processData: false, contentType: false, type: 'POST', success: function (response) { $('#ShowCUResults').html(response); }}) }else{ $('#ShowCUResults').html(""); } }); }); function UpdateCUData(CUData){ var res = CUData.split("#"); $("#creditUnion").val(res[1]); $("#CURnt").val(res[0]); $("#CUCharterID").val(res[2]); $('#ShowCUResults').html("Routing Number: "+res[0]+""); }