PageSourceSearch

https://www.freeadvice.com/wp-content/plugins/leads-master/assets/newtab.js?ver=1.1.3

js freeadvice.com collected 2026-09-24 18:38:23 UTC 19,840 bytes, 551 lines download raw bytes

1function generateRequestId() {
2   return Math.random().toString(36).substr(2, 9) + Math.random().toString(36).substr(2, 9);
3}
4
5jQuery(document).ready(function($) {
6  var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
7
8  $('body').on('click', '.mda-submit', function(e) {
9    var form = $(this).closest('form');
10    form.attr('btnClicked', true);
11    form.submit();
12  });
13
14  $('body').on('focus', '[name=zipcode]', function(e) {
15    quote_hide_tooltips();
16  });
17
18  $('body').on('keydown', '[name=zipcode]', function(e) {
19    quote_hide_tooltips();
20  });
21
22  $('body').on('blur', 'form', function(e) {
23    quote_hide_tooltips();
24  });
25
26  $(window).on('resize', function(e) {
27    quote_hide_tooltips();
28  });
29
30  function quote_hide_tooltips() {
31    $('.field-holder').each(function(i,z) {
32      tlite.hide(z);
33    })
34  }
35
36  $('body').on('submit', 'form', function(e) {
37    var form = $(this);
38    var zip = $(this).find("[name=zipcode]");
39    var typeSelect = $(this).find("select[name=type]");
40    var fieldType = form.find('[name="type"]').prop('tagName');
41    var isMultiVertical = fieldType === 'SELECT' ? true : false;
42    var popper = null;
43    var request = form.find("[name=requestId]");
44    var is_quote_life_rates_page = form.find('[name="is_quote_life_rates_page"]').val() === '1';
45
46    /*
47     Preventing the form from being submitted for life insurance modal only when enabled.
48     See insurance-quotes.php, phoenix_config method
49    */
50    if (window.phoenix.config.lifeModalFormEnabled === 'true' && // life modal enabled in quote settings
51        form[0].id !== 'life' && // making sure its not when the modal is submitted
52        getInsuranceType(form) === 'Life' && // Only when you click on the life drop down or type === 'Life'
53        !isMultiVertical && // Only opening modal if its not a multi-vertical
54        zip.is(':hidden') === true
55    ) {
56      openLifeModal(false)
57      e.preventDefault();
58      return false;
59    }
60
61    /**
62     * If Life rates page is enabled validate the age and income fields
63     */
64    if (
65      window.phoenix.config.quoteLifeRatesPageEnabled === "true" &&
66      is_quote_life_rates_page
67    ) {
68      var age = form.find('[name="age"]');
69      var income = form.find('[name="income"]');
70      var ageHasValue = age.is(":checked");
71      var incomeHasValue = income.is(":checked");
72
73      if (!ageHasValue) {
74        e.preventDefault();
75        setTimeout(function () {
76          var ageTooltipTarget = age.first().closest(".field-holder")[0];
77          if (ageTooltipTarget) {
78            tlite.show(ageTooltipTarget, { grav: "s" });
79          }
80        }, 100);
81        return false;
82      }
83      if (!incomeHasValue) {
84        e.preventDefault();
85        setTimeout(function () {
86          var incomeTooltipTarget = income.first().closest(".field-holder")[0];
87          if (incomeTooltipTarget) {
88            tlite.show(incomeTooltipTarget, { grav: "s" });
89          }
90        }, 100);
91        return false;
92      }
93    }
94
95    if (getVisitorId()) {
96      request.val(getVisitorId() + "|" + generateSubmitId());
97    }
98
99    if (zip.length > 0) {
100      if (zip.is(":hidden")) {
101        submitForm(form, e);
102        return true;
103      }
104
105      if (typeSelect.length > 0 && !typeSelect.val()) {
106        e.preventDefault();
107        setTimeout(function() {
108          tlite.show(typeSelect.closest('.field-holder')[0], { grav: 's' })
109        }, 100);
110        return false;
111      }
112      if(!zip.val() || zip.val().length < 1) {
113        e.preventDefault();
114        setTimeout(function() {
115          tlite.show(zip.closest('.field-holder')[0], { grav: 's' })
116        }, 100);
117        return false;
118      } else if( !(/^[0-9]{5}$/.test(zip.val())) ){
119        e.preventDefault();
120        setTimeout(function() {
121          zip_error = zip.closest('.field-holder');
122          zip_error.attr("title","Please enter a valid Zip Code!");
123          tlite.show(zip_error[0], { grav: 's' });
124          //reset filed holder value
125          zip_error.attr("title","ZIP Code must be filled out!");
126        }, 100);
127        return false;
128      } else {
129        if (!iOS || form.attr('btnClicked')) {
130            if (window.phoenix.config.lifeModalFormEnabled === 'true' && // life modal enabled in quote settings
131                form[0].id !== 'life' && // making sure its not when the modal is submitted
132                getInsuranceType(form) === 'Life' && // Only when you click on the life drop down or type === 'Life'
133                zip.is(':hidden') === true // Only when zipcode is hidden in the MDA
134            ) {
135                openLifeModal(true, zip.val());
136                e.preventDefault();
137                return false;
138            } else {
139                submitForm(form, e);
140            }
141        } else {
142          e.preventDefault();
143          var button = form.find('.mda-submit').closest('.field-holder')[0];
144          zip.blur();
145          tlite.show(button, { grav: 's' })
146          form.find('.mda-submit').addClass('needs-submit');
147          setTimeout(function() {
148            form.find('.mda-submit').removeClass('needs-submit');
149          }, 1000);
150          return false;
151        }
152      }
153    } else if (zip.is(":hidden")) {
154      submitForm(form, e);
155    }
156  });
157
158  function openLifeModal(prepop = false, zip = '') {
159    //Hidding MDA background to prevent double black backgrounds
160    jQuery('.mda-background').fadeOut(200);
161      jQuery('#lifeModal').modal();
162      if (prepop) { /* Prepopping zip field from previous input */
163          var lifeForm = $('form.life');
164          var lifeFormZip = $(lifeForm).find("[name=zipcode]");
165          lifeFormZip.val(zip);
166      }
167  }
168
169  function submitForm(form, e) {
170    if (form.has('[name="zipcode"],[name="zip"]').length) {
171        var type = getInsuranceType(form);
172        var is_quote_life_rates_page = form.find('[name="is_quote_life_rates_page"]').val() === '1';
173
174        var _showQuoteLifeRatesPage =
175          type === "Life" &&
176          window.phoenix.config.quoteLifeRatesPageEnabled === "true" &&
177          !is_quote_life_rates_page;
178
179        var _showPopup = showPopup(form) && !_showQuoteLifeRatesPage;
180        var _showNative = showNative(form) || _showQuoteLifeRatesPage;
181
182        if(_showQuoteLifeRatesPage){
183          form.attr('action', window.phoenix.config.quoteLifeRatesPageUrl || "/quote-life-rates");
184        }
185
186      if (_showPopup) {
187        /* Trigger GA tracking if only a newtab */
188        if (!_showNative) {
189          window.dataLayer = window.dataLayer || [];
190          window.dataLayer.push({
191            event: 'zip_submit_event'
192          });
193        }
194
195         var zip = form.find('[name="zipcode"],[name="zip"]').val();
196        //  var type = getInsuranceType(form);
197         var referrer = form.find('[name="referrer"]').val();
198         var requestId = form.find('[name="requestId"]').val();
199         var tag = form.find('[name="tag"]').val();
200         var insured = form.find('[name="insured"]:checked').val();
201         var maPlacement = form.find('[name="ma_placement"]').val();
202         var qwPlacement = form.find('[name="qw_placement"]').val();
203         var paidTraffic = form.find('[name="paid_traffic"]').val();
204         var paidTrafficParams = "";
205         var utm_source = form.find('[name="utm_source"]').val();
206         var utm_medium = form.find('[name="utm_medium"]').val();
207         var utm_campaign = form.find('[name="utm_campaign"]').val();
208         var utm_term = form.find('[name="utm_term"]').val();
209         var utm_content = form.find('[name="utm_content"]').val();
210         var utm_adgroup = form.find('[name="utm_adgroup"]').val();
211         var test_mode = form.find('[name="test_mode"]').val();
212         var gclid = form.find('[name="gclid"]').val();
213         var maToken = form.find('[name="token"]').val();
214         var publisherId = form.find('[name="publisher_id"]').val();
215         var mvaParams = getMVAParams(form);
216         var experimentId = form.find('[name="experimentId"]').val();
217         var category = window.phoenix.config.pageCategory;
218         var userAgent = form.find('[name="useragent"]').val();
219
220         // adding breadcrumb text and replacing arrow symbol with comma
221         var breadCrumbText;
222         if (document.getElementsByClassName("aioseo-breadcrumbs").length === 0) {
223            breadCrumbText = undefined;
224         } else {
225            breadCrumbText = document.getElementsByClassName("aioseo-breadcrumbs")[0].innerText.replaceAll("(", "").replaceAll(")", "");
226         }
227
228        // For custom life insurance modal form
229        var coverage_amount = form.find('[name="coverage_amount"]:checked').val();
230        var smoker = form.find('[name="smoker"]:checked').val();
231        var health = form.find('[name="health"]:checked').val();
232        var age = form.find('[name="age"]:checked').val();
233        var income = form.find('[name="income"]:checked').val();
234
235         paidTrafficParams = "&paid_traffic=" + paidTraffic +
236          "&utm_source=" + utm_source + "&utm_medium=" + utm_medium +
237          "&utm_campaign=" + utm_campaign + "&utm_term=" + utm_term +
238          "&utm_content=" + utm_content + "&utm_adgroup=" +
239          utm_adgroup + "&publisher_id=" + publisherId
240          + (test_mode ? "&test_mode=" + test_mode : "");
241
242         window.open(encodeURI(
243           '/apps?requestId=' + requestId + '&zipcode=' +
244            zip + '&type=' + type + "&referrer=" + referrer +
245            (isKrakenPost() ? "&content_type=kraken" : "") +
246            "&tag=" + tag + (insured ? "&insured=" + insured : "") +
247            paidTrafficParams +
248            (maPlacement ? "&ma_placement=" + maPlacement : "") +
249            (qwPlacement ? "&qw_placement=" + qwPlacement : "") +
250            "&gclid=" + gclid +
251            "&token=" + maToken + '&' + mvaParams +
252            "&coverage_amount=" +  coverage_amount +
253            "&smoker=" + smoker +
254            "&health=" + health +
255            "&age=" + age +
256            "&income=" + income +
257            "&category=" + category +
258            "&breadcrumb=" + breadCrumbText +
259            "&experimentId=" + experimentId +
260            "&useragent=" + userAgent
261         ));
262      }
263
264      if (!_showNative) {
265         e.preventDefault();
266         return false;
267      }
268    }
269  }
270
271   function getInsuranceType(form) {
272      var type = form.find('[name="type"]').val(), alt_type = form.find('[name="alt_type"]').val();
273      if ( type == "Other" && alt_type)
274         return alt_type;
275      else
276         return type;
277   }
278
279   function standardizeType(rawType) {
280      switch(rawType) {
281         case "Home": return "home";
282         case "Renter": return "renter";
283         case "Long Term Care": return "long term care";
284         case "Health": return "health";
285         case "Dental": return "dental";
286         case "Travel": return "travel";
287         case "Life": return "life";
288         case "Business": return "business";
289         case "Motorcycle": return "motorcycle";
290         case "Electronics": return "electronics";
291         case "Pet": return "pet";
292         case "Medicare": return "medicare";
293         case "Burial": return "burial";
294         case "Group Health": return "group health";
295         case "Commercial": return "commercial";
296         case "Child Life": return "child life";
297         case "Rental": return "rental";
298         case "Condo": return "condo";
299         case "RV": return "rv";
300         case "Boat": return "boat";
301         case "Disability": return "disability";
302         case "Personal Injury": return "personal injury";
303         case "Divorce": return "divorce";
304         case "Auto Accident Injury": return "auto accident injury";
305         case "DUI": return "dui";
306         case "Real Estate": return "real estate";
307         case "Criminal Defense": return "criminal defense";
308         case "Prenuptial": return "prenuptial";
309         case "Bankruptcy": return "bankruptcy";
310         case "Child Support": return "child support";
311         case "Immigration": return "immigration";
312         case "Family Law": return "family law";
313         case "Employment": return "employment";
314         case "Copyright": return "copyright";
315         case "Traffic": return "traffic";
316         case "Wills": return "wills";
317         case "Civil Law": return "civil law";
318         case "Elder Law": return "elder law";
319         case "Workers Comp": return "workers comp";
320         case "Social Security Disability": return "social security disability";
321         case "Auto Loan": return "auto loan";
322         case "Business Loan": return "business loan";
323         case "Mortgage Loan": return "mortgage loan";
324         case "Student Loan": return "student loan";
325         case "Payday Loan": return "payday loan";
326         case "Personal Loan": return "personal loan";
327         case "Debt": return "debt";
328      }
329      return "auto";
330   }
331
332   function showPopup(form) {
333      var type = getInsuranceType(form);
334      type = standardizeType(type);
335      return QUOTE_POPUP_TYPES[type];
336   }
337
338   function showNative(form) {
339      var type = getInsuranceType(form);
340      type = standardizeType(type);
341      return QUOTE_NATIVE_TYPES[type];
342   }
343   var paidParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_adgroup', 'token', 'gclid', 'publisher_id'];
344
345   var legalMVAParams = [
346     'email',
347     'first_name',
348     'last_name',
349     'phone',
350     'dob',
351     'have_attorney',
352     'comments',
353     'degree_of_interest',
354     'type_of_legal_problem',
355     'tcpa',
356     'is_incident_date',
357     'incident_date',
358     'incident_date_option_b',
359     'injured',
360     'mva_type',
361     'doctor_treatment',
362     'were_you_at_fault',
363     'police_report',
364     'completed',
365     'original_referrer',
366     'submission_id',
367   ];
368
369   function getMVAParams(form) {
370     var params = [];
371     legalMVAParams.forEach(function(fieldName) {
372       var fieldValue = form.find('[name="' + fieldName + '"]').val();
373       if(fieldValue && fieldValue != ''){
374         params.push(fieldName + '=' + fieldValue);
375       }
376     });
377     return params.join('&');
378   }
379
380   function checkPaidUrlParams() {
381     for (i = 0; i < paidParams.length; i++) {
382       var param = paidParams[i];
383       var cur = getUrlParam(param);
384       if(cur) {  Cookies ? Cookies.set(param, cur, { expires: 1/24 }) : null }
385     }
386   }
387
388   function getVisitorId() {
389     if(!Cookies.get('visitorId')) Cookies.set('visitorId', generateRequestId(), { expires: 1/24 });
390     return Cookies.get('visitorId');
391   }
392
393   function loadPaidUrlParams() {
394     $('.mda-submit').each(function() {
395       var form = $(this).closest('form');
396       for (i = 0; i < paidParams.length; i++) {
397         var param = paidParams[i];
398         cookie = Cookies.get(param);
399         input =  form.find('[name="' + param + '"]');
400         if(cookie && !input.val()) { input.val(cookie); }
401       }
402
403       $("<input />").attr("type", "hidden")
404         .attr("name", "requestId")
405         .attr("value", Cookies.get('visitorId'))
406         .appendTo(form);
407       if( isKrakenPost() ) {
408          $("<input />").attr("type", "hidden")
409            .attr("name", "content_type")
410            .attr("value", 'kraken')
411            .appendTo(form);
412       }
413
414     });
415   }
416
417   // Get zip value from cookies
418   function getSavedZipCode() {
419     var zipVal;
420
421     var contactCookie = Cookies.get('contact');
422     if(contactCookie){
423       contactCookie = JSON.parse(contactCookie);
424       zipVal = contactCookie["contact"]["zip"];
425     }
426     return zipVal;
427   }
428
429   function preFillForms() {
430     $('.mda-submit').each(function() {
431       var form = $(this).closest('form');
432       var zipInput = form.find('[name="zipcode"]');
433
434       if(zipInput && !zipInput.val()){
435         var zipVal = getSavedZipCode();
436         zipInput.val(zipVal);
437       }
438
439     });
440   }
441
442   function getUrlVars() {
443     var vars = {};
444     var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
445       vars[key] = value;
446     });
447     return vars;
448   }
449
450   function getUrlParam(parameter, defaultvalue) {
451     var urlparameter = defaultvalue;
452     if(window.location.href.indexOf(parameter) > -1){
453       urlparameter = getUrlVars()[parameter];
454     }
455     return urlparameter;
456   }
457
458
459   function generateSubmitId() {
460     return Math.random().toString(36).substr(2, 3);
461   }
462
463   // Handles setting hidden fields for paid traffic data from a cookie or
464   //  saving the data in a cookie
465   function loadPaidTrafficParams() {
466     $('.mda-submit').each(function() {
467       var categories = ["internal", "tracking", "contact", "current_insurance", "requested_coverage", "vehicles", "incidents", "individuals", "claims"];
468       var arrayCategories = ["vehicles", "incidents", "individuals", "claims"];
469       var form = $(this).closest('form');
470
471       var inputs = form.find('input[type="hidden"]');
472
473       var paramObject = {};
474
475       // Converts hidden inputs into a js object
476       for (var i = 0; i < inputs.length; i++) {
477         // ex: contact[email]
478         // ex: vehicles[0][submodel]
479         var input = inputs[i];
480         var field = input.name.replace(/\]/g, "");
481         var fieldCat = field.split("[")[0];
482         if(input.value && categories.includes(fieldCat)){
483           if(arrayCategories.includes(fieldCat)){
484             // ex: [ "vehicles", 0, "year" ]
485             var [category, index, param] = field.split("[");
486             if(!paramObject.hasOwnProperty(category)){
487               paramObject[category] = [];
488             }
489             if(!paramObject[category][index]){
490               paramObject[category][index] = {};
491             }
492             paramObject[category][index][param] = input.value;
493           } else {
494             // ex: ["contact", "email"]
495             var [category, param] = field.split("[");
496             if(!paramObject.hasOwnProperty(fieldCat)){
497               paramObject[fieldCat] = {};
498             }
499             paramObject[fieldCat][param] = input.value;
500           }
501         }
502       }
503
504       for (var catIndex = 0; catIndex < categories.length; catIndex++) {
505         var cat = categories[catIndex];
506         try{
507           if(paramObject[cat]) {
508             // Set new cookie for params that are set
509             var newCookie = {};
510             newCookie[cat] = paramObject[cat];
511             var jsonCookie = JSON.stringify(newCookie);
512             Cookies.remove(cat);
513             Cookies.set(cat, jsonCookie, { expires: 1/24 });
514           } else {
515             var cookie = Cookies.get(cat);
516             // if the cookie is set for the category and the fields for the
517             //  category aren't filled then set them to data in the cookie
518             // NOTE: we are filling based on all of the params inside a
519             //  category otherwise we may add incorrect data.
520             if(cookie){
521               // Convert the params to url parameters & use that for input name
522               var urlParams = decodeURI($.param(JSON.parse(cookie)));
523               var cookieParams = urlParams.split("&");
524               // console.log(cookieParams);
525               // add a hidden field for each parameter
526               for (var i = 0; i < cookieParams.length; i++) {
527                 var nameVal = cookieParams[i].split("=");
528                 if(nameVal.length == 2){
529                   var [name, value] = nameVal;
530                   $("<input />").attr("type", "hidden")
531                   .attr("name", name)
532                   .attr("value", value)
533                   .appendTo(form);
534                 }
535               }
536             }
537           }
538         } catch (e) {
539           console.error(e);
540         }
541       }
542     });
543   }
544
545
546   checkPaidUrlParams();
547   getVisitorId();
548   loadPaidUrlParams();
549   loadPaidTrafficParams();
550   preFillForms();
551});

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.