PageSourceSearch

https://mexicanautoinsurance.com/js/lewis.js?v=95

js mexicanautoinsurance.com collected 2026-10-02 06:36:27 UTC 9,969 bytes, 349 lines download raw bytes

1// poly fill just incase ie
2if (window.NodeList && !NodeList.prototype.forEach) {
3    NodeList.prototype.forEach = Array.prototype.forEach;
4}
5
6/* custom date input boxes as spec'd.  This code can only handle one of these on the page. */
7var dateInputBoxesJS = (function () {
8
9    var dateInputBoxes = null;
10    var inputs = [];
11    var targetSelector = null;
12    var targetInput;
13
14    const getNextInput = (el) => {
15        let sibling = el.nextElementSibling;
16
17        while(sibling) {
18            if(sibling.matches('input')) return sibling;
19            sibling = sibling.nextElementSibling;
20        }
21    }
22
23    function handleKeyup(idx, e, next) {
24        if (e.code == 'Tab') {
25            return;
26        }
27        var me = e.currentTarget;
28        var myValue = me.value;
29
30        // must be numeric
31        myValue = myValue.replace(/\D/g, '');
32        me.value = myValue
33
34        if (idx == 0) {
35            // month
36            if (myValue.length == 2) {
37                next.focus()
38                return;
39            }
40        } else if (idx == 1) {
41            // day
42            if (myValue.length == 2) {
43                next.focus()
44                return;
45            }
46        } else if (idx == 2) {
47            // year
48            if (myValue.length == 4) {
49                if(e.target.id == 'birth_year') {
50                    document.querySelector('#driversLicenseNumber').focus()
51                } else {
52                    document.querySelector('#timePolicyEffective').focus()
53                }
54                return
55            }
56        }
57    }
58
59    function handleChange(idx, e) {
60        var values = Array.from(dateInputBoxes.querySelectorAll('input')).map( x => x.value);
61        var formatted = values.join('/');
62        targetInput.value = formatted;
63    }
64
65    var addEventListeners = function () {
66        dateInputBoxes.querySelectorAll('input').forEach((x, idx) => {
67            const next = getNextInput(x)
68            x.addEventListener('keyup', e => handleKeyup(idx, e, next));
69        })
70        dateInputBoxes.querySelectorAll('input').forEach((x, idx) => {
71            x.addEventListener('change', e => handleChange(idx, e));
72        })
73    }
74
75    var targetValueToBoxes = function () {
76        // set initial values for the boxes.
77        var value = targetInput.value;
78        if (!value) {
79            return;
80        }
81        var values = value.split('/');
82        values.forEach((x, idx) => {
83            inputs[idx].value = x
84        });
85    }
86
87    var init = function () {
88        dateInputBoxes = document.querySelector('.date_inputboxes--js');
89        if (!dateInputBoxes) {
90            // boxes not present on this page.
91            return;
92        }
93
94        inputs = dateInputBoxes.querySelectorAll('input');
95        targetSelector = dateInputBoxes.dataset.target;
96        targetInput = document.querySelector(targetSelector);
97
98        targetValueToBoxes();
99        addEventListeners();
100    }
101
102    return {
103        init: init,
104    }
105})();
106
107marketValueInputJS = (function () {
108
109    var marketValueInput = null;
110    var coverageTypeInput = null;
111    var coverageTypeValue = null;
112
113    function handleKeyup(e) {
114        if (e.code == 'Tab') {
115            return;
116        }
117        var me = e.currentTarget;
118        var myValue = me.value;
119
120        // must be numeric
121        myValue = myValue.replace(/\D/g, '');
122        me.value = myValue
123    }
124
125    function checkDisabled(value, ele) {
126    	if (value == 'Liability') {
127        	ele.disabled = true;
128        	ele.value = 0;
129        } else {
130        	ele.disabled = false;
131        }
132    }
133
134    function handleTypeChange(mvinput, val) {
135    	checkDisabled(val, mvinput)
136    }
137
138    var init = function () {
139        marketValueInput = document.getElementById('cmv');
140        coverageTypeInput = document.querySelectorAll('input[type=radio][name="specifiedVehicle[coverageType]"]');
141
142        if (document.querySelector('input[type=radio][name="specifiedVehicle[coverageType]"]:checked')) {
143	        coverageTypeValue = document.querySelector('input[type=radio][name="specifiedVehicle[coverageType]"]:checked').value;
144	    }
145        if (!document.querySelector('input[type=radio][name="specifiedVehicle[coverageType]"]:checked')) {
146            //short circuit for 'cmv' input on the 'towed-unit' page of form where no disabling radio selector is present
147            return;
148        }
149        if (!marketValueInput) {
150            // box not present on this page.
151            return;
152        }
153        marketValueInput.addEventListener('keyup', e => handleKeyup(e));
154        coverageTypeInput.forEach((x, idx) => {
155            x.addEventListener('change', e => checkDisabled(e.target.value, marketValueInput));
156        })
157        if (coverageTypeValue) {
158	        checkDisabled(coverageTypeValue, marketValueInput);
159	    }
160    }
161
162    return {
163        init: init,
164    }
165})();
166
167window.addEventListener('DOMContentLoaded', () => dateInputBoxesJS.init()); // init js for component if its on the page.
168window.addEventListener('DOMContentLoaded', () => marketValueInputJS.init()); // init js for component if its on the page.
169
170const dlStateSelectJS = (function () {
171    // let dlStateSelect = null;-
172    
173    const init = function () {
174        const dlStateSelect = document.querySelector('#driversLicenseState');
175        const dlWriteIn = document.querySelector('#dlWriteIn');
176        const newOption = document.createElement('option');
177        
178        if (!dlStateSelect) {
179            // select not present on this page.
180            return;
181        }
182
183        const addOption = (string) => {
184            newOption.textContent = string;
185            newOption.value = string;
186            dlStateSelect.append(newOption);
187        }
188        
189        const reassignState = (string) => {
190            dlStateSelect.value = string
191        }
192        
193        dlStateSelect.addEventListener('click', ({ target }) => {
194            if(target.value == 'Other') {
195                dlWriteIn.removeAttribute('disabled');
196            }
197        })
198        
199        dlWriteIn.addEventListener('blur', ({ target }) => {
200            addOption(target.value)
201            reassignState(target.value)
202        })
203        
204    }
205    
206    return {
207        init: init,
208    }
209})();
210
211window.addEventListener('DOMContentLoaded', () => dlStateSelectJS.init());
212
213
214// after slideshow on home page runs one full time - display youtube video
215window.addEventListener('DOMContentLoaded', () => {
216    const slideshow = document.getElementById('home_slideshow')
217    if(slideshow) {
218        const youtubeVid = document.getElementById('home_youtube_vid')
219        const slides = document.querySelectorAll('#home_slideshow > *')
220        const timer = slides.length * 7300
221    
222        setTimeout(() => {
223            slideshow.style.background = "rgb(0, 0, 0)"
224            slideshow.classList.add('fade-out')
225        }, timer - 2000)
226    
227        setTimeout(() => {
228            slideshow.classList.add('removed')
229            youtubeVid.classList.add('displayed')
230        }, timer)
231
232    }
233
234    // event listener for back button on hints page
235    const hintsBack = document.getElementById('hints_back')
236    if(hintsBack) {
237        hintsBack.addEventListener('click', () => {
238            document.getElementById('hint_loading').classList.add('show-loading')
239        })
240    }
241})
242
243// Not Implemented
244function notImplemented() {
245	alert('Not yet implemented.');
246};
247
248// Bootstrap Popover
249$(function () {
250  $('[data-toggle="popover"]').popover()
251})
252
253//  Select field
254
255function select(field) {
256	field.focus();
257	field.select();
258	return false;
259 }
260
261//  Validation
262
263function isEmpty(inputStr) {
264	if (inputStr == null || inputStr == "") {
265		return true;
266	}
267	return false;
268}
269
270function isNumber(inputVal) {
271	var oneDecimal = false
272	var inputStr = inputVal.toString();
273	for (var i = 0; i < inputStr.length; i++) {
274		var oneChar = inputStr.charAt(i) 
275		if (oneChar == "." && !oneDecimal) {
276			oneDecimal = true
277			continue
278		}
279		if (oneChar < "0" || oneChar > "9") {
280			return false;
281		}
282	}
283	return true;
284}
285
286function isAmount(inputVal) {
287	if (!isEmpty(inputVal) && !isNumber(inputVal)){
288		return false;
289	}
290	return true;
291}
292
293//  Formatting functions
294
295function strToDate(inputStr){ // string must be in mm/dd/yyyy format. Outputs milliseconds.
296	var delim1 = inputStr.indexOf("/")
297	var delim2 = inputStr.lastIndexOf("/")
298	if (delim1 != -1) {
299		var mm = parseInt(inputStr.substring(0,delim1),10) - 1  // subtract one for corresponding month value in JS array (0-11)
300		var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
301		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10)
302	}
303	var oneDateObject = new Date(yyyy,mm,dd)
304	return(oneDateObject);
305}
306
307function formatNum(expr,decplaces) {
308	var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString()
309	while (str.length <= decplaces) {
310		str = "0" + str
311	}
312	var decpoint = str.length - decplaces
313	if (decplaces > 0) {
314		return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length)
315	} else {
316		return str.substring(0,decpoint)
317	}
318}
319
320
321function checkDateOfEntry(field) {
322		var inputStr = field.value;
323		var entryDate = strToDate(inputStr);
324		var entryDateInMs = entryDate.getTime();
325
326		var today = new Date();
327		var todayInMs = today.getTime();
328
329		var oneDayInMs = ((60 * 1000) * 60) * 24
330		var allowedDate = todayInMs - oneDayInMs
331
332		if (entryDateInMs >= allowedDate) {
333		 	return true;
334		} else {
335			return false;
336		}
337}
338
339function strToDate(inputStr){ // string must be in mm/dd/yyyy format. Outputs milliseconds.
340	var delim1 = inputStr.indexOf("/")
341	var delim2 = inputStr.lastIndexOf("/")
342	if (delim1 != -1) {
343		var mm = parseInt(inputStr.substring(0,delim1),10) - 1  // subtract one for corresponding month value in JS array (0-11)
344		var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10)
345		var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10)
346	}
347	var oneDateObject = new Date(yyyy,mm,dd)
348	return(oneDateObject);
349}

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.