PageSourceSearch

https://cdn.trustedsite.com/static/js/common.js?2026092408-02

js trustedsite.com collected 2026-09-24 08:24:32 UTC 44,812 bytes, 1,207 lines download raw bytes

1//-----------------------------------------------------------------------------------------------------------------
2if (typeof console == "undefined") {
3    window.console = { log: function () {} };
4}
5//-----------------------------------------------------------------------------------------------------------------
6$(document).ready(function() {
7   renderPage();
8   if($.modal) {
9      $.modal.defaults.overlayClose = true;
10      $.modal.defaults.escClose = true;
11   }
12});
13function renderPage() {
14   document.dispatchEvent(new Event('halo-render-page'));
15   messageSaveShow();
16   linkHrefs();
17   init_tooltips();
18   init_accordian();
19   init_form_google_recaptcha();
20   init_csrf_token();
21   init_select2();
22   $('input.tb0').attr('data-lpignore', true);
23   $('.norc').on("contextmenu",function(){ return false; }); 
24   $('.code-copy').click(function() { copy_me(this); });
25   $('[data-copy]').click(function() { copy_this($(this).attr('data-copy')); });
26   $('textarea.autoheight-init').each(function() { textarea_autoheight(this); });
27   $('form.lpignore').each(function() { $(this).find(':input').attr('data-lpignore', true); });
28
29   if ($.fn.chosen) {
30      $('div.ts-select.chosen').find('select').chosen({
31           placeholder_text_multiple: 'Any',
32           placeholder_text_single: 'Select'
33      });
34      $('div.ts-select select[multiple]').chosen({
35           placeholder_text_multiple: 'Any',
36           placeholder_text_single: 'Select'
37      });
38   }
39
40   $('form.auto-submit').each(function() {
41      var fm = this;
42      $(fm).find('select').change(function() { 
43         if($(this).find('option:selected').hasClass('custom-set')) return;
44         form_submit(fm);
45      });
46   });
47   $('select.auto-submit').change(function() {
48      $(this).closest('form')[0].requestSubmit();
49   });
50   $('form.change-activate').each(function() {
51      var form = this;
52      $(form).find('input,select,textarea').change(function() {
53         do_form_change_activate(form);
54      });
55   });
56   $('form.submit-loader').submit(function() {
57      $(this).find('button[type=submit]').each(function() {
58         var btn = this;
59         $(btn).html('<i class="fa fa-circle-notch fa-spin"></i>' + $(btn).html());
60         $(btn).prop('disabled',true);
61      });
62   });
63   $('button[onclick-disable]').click(function() {
64      var btn = this;
65      window.setTimeout(function() { 
66         $(btn).html('<i class="fa fa-circle-notch fa-spin"></i>' + $(btn).html());
67         $(btn).prop('disabled',true); 
68      },0);
69      var tosec = parseInt($(btn).attr('onclick-disable'));
70      if(tosec > 0) window.setTimeout(function() { $(btn).prop('disabled',false); },tosec * 1000);
71   });
72
73   $('form').each(function() {
74      if($(this).hasClass('remove-empty')) {
75         $(this).submit(function() {
76            form_remove_empty(this);
77         });
78      }
79   });
80
81   $('select.perform-action').change(function () {
82      var v = $(this).val();
83      var t = $(this).find("option:selected").text();
84      $(this)[0].selectedIndex = 0;
85      console.log('perform-action',v);
86      if(event.ctrlKey) return;
87      golink(v,{title:t});
88   });
89
90}
91$(window).bind("pageshow", function(event) {
92   $('button[onclick-disable]').prop('disabled',false);
93});
94//-----------------------------------------------------------------------------------------------------------------
95function init_select2() {
96   if (typeof $.fn.select2 !== 'function') {
97      //console.warn('select2 is not loaded');
98      return;
99   }
100   $('div.ts-select.select2 select')
101      .not('.select2-hidden-accessible')
102      .each(function() {
103         //console.log('select2 load',this);
104         const $select = $(this);
105         const opts = typeof select2_config === 'function'
106            ? select2_config($select) || {}
107            : {};
108         $select.select2(opts);
109      });
110}
111//-----------------------------------------------------------------------------------------------------------------
112let csrf_interval = null;
113function init_csrf_token() {
114   start_csrf_token();
115   document.addEventListener('visibilitychange', function() {
116      if (document.hidden) {
117         clearInterval(csrf_interval);
118         csrf_interval = null;
119      } else {
120         start_csrf_token();
121      }
122   });
123}
124function start_csrf_token() {
125   clearInterval(csrf_interval);
126   csrf_interval = window.setInterval(function() {
127      run_csrf_token();
128   },5 * 60 * 1000);
129}
130function run_csrf_token() {
131      $.get('/rpc/ajax?do=csrf-token',function(data) {
132         console.log('refresh csrf-token',data);
133         if(data.token) {
134            $('meta[name="csrf-token"]').attr('content', data.token);
135            $('input[name="csrf-token"]').val(data.token);
136         }
137      },'json');
138}
139//-----------------------------------------------------------------------------------------------------------------
140function do_form_change_activate(form) {
141   $(form).closest('form').find('button[type=submit]').addClass('green');
142}
143//-----------------------------------------------------------------------------------------------------------------
144function copy_this(txt) {
145   navigator.clipboard.writeText(txt).then(function() {
146      messageShow('Copied to Clipboard');
147   }, function() {
148      messageShow('Copy Failed');
149   });
150}
151function copy_me(ele) {
152   if($(ele).is('textarea')) {
153      ele.select();
154      document.execCommand("copy");
155      messageShow('Copied to Clipboard');
156   } else {
157      copy_this($(ele).html());
158   }
159}
160//-----------------------------------------------------------------------------------------------------------------
161function textarea_autoheight(ele) {
162   if(typeof ele === 'string') ele = $(ele)[0];
163   $(ele).height(0);
164   while($(ele).outerHeight() < Math.floor(ele.scrollHeight + parseFloat($(ele).css("borderTopWidth")) + parseFloat($(ele).css("borderBottomWidth")))) {
165      $(ele).height($(ele).height()+1);
166   };
167}
168//-----------------------------------------------------------------------------------------------------------------
169function init_tooltips() {
170   if (!($.fn.tooltip)) return;
171   $(document).tooltip({
172      items:'[data-tt]',
173      tooltipClass:'tooltip-btn',
174      content:function(callback) { callback($(this).attr('data-tt')); },
175      position:{ my: "left top+5", at: "left bottom" }
176   });
177}
178//-----------------------------------------------------------------------------------------------------------------
179function validate_form(id) {
180   if($('#' + id)[0].checkValidity()) return true;
181
182   var ele = $('#' + id).find(':submit')[0];
183   if(!ele) {
184      ele = document.createElement('button');
185      ele.type = 'submit';
186      ele.style.display = 'none';
187      $('#' + id).append(ele);
188   }
189   $(ele).click();
190   return false;
191}
192//-----------------------------------------------------------------------------------------------------------------
193function messageShow(txt,color) {
194   if(!txt) {
195      console.log('messageShow called with no message');
196      return;
197   }
198   while(txt.indexOf('R#') == 0) { color = 'red'; txt = txt.substring(2); }
199   while(txt.indexOf('Y#') == 0) { color = 'yellow'; txt = txt.substring(2); }
200   while(txt.indexOf('B#') == 0) { color = 'blue'; txt = txt.substring(2); }
201   while(txt.indexOf('G#') == 0) { color = 'green'; txt = txt.substring(2); }
202   if(color && color != 'green') {
203      messageTopShow(txt,color);
204   } else {
205      messageAwkShow(txt,'green');
206   }
207}
208function messageHide(delay) {
209   if(delay) {
210      window.setTimeout(function() {
211         messageHide();
212      },delay);
213   } else {
214      messageTopHide();
215      messageAwkHide();
216   }
217}
218function messageSave(s) {
219   localStorage.setItem('message',s);
220}
221function messageSaveShow() {
222   var v = localStorage.getItem('message');
223   if(v) {
224      localStorage.removeItem('message');
225      messageShow(v);
226   }
227}
228//-----------------------------------------------------------------------------------------------------------------
229var message_hide_to = 0;
230function messageTopShow(txt,color) {
231   window.clearTimeout(message_hide_to);
232   $('#message-top').remove();
233
234   var ele = document.createElement('div');
235   ele.id = 'message-top';
236   $(ele).addClass(color?color:'green');
237   $(ele).html('<span>' + txt + '</span>');
238   $(ele).appendTo('body');
239   message_hide_to = window.setTimeout(function() { messageTopHide() },5000);
240   $('#message-top').click(function() { messageTopHide(); });
241}
242function messageTopHide() {
243   $('#message-top').slideUp(function() { $(this).remove(); });
244}
245//-----------------------------------------------------------------------------------------------------------------
246var message_awk_hide_to = 0;
247function messageAwkShow(txt,color) {
248   window.clearTimeout(message_awk_hide_to);
249   $('#message-awk').remove();
250
251   if(!color) color = 'green';
252   var icon;
253   if(color == 'green') icon = 'fas fa-check';
254   else if(color == 'red') icon = 'fas fa-times';
255
256   var html = '<span>' + txt + '</span>';
257   if(icon) html = '<i class="'+icon+'"></i>' + html;
258
259   var ele = document.createElement('div');
260   ele.id = 'message-awk';
261   $(ele).addClass(color);
262   $(ele).html(html);
263   $(ele).appendTo('body');
264   window.setTimeout(function() { $('#message-awk').addClass('show'); },100);
265   message_awk_hide_to = window.setTimeout(function() { messageAwkHide() },5000);
266   $('#message-awk').click(function() { messageAwkHide(); });
267}
268function messageAwkHide() {
269   $('#message-awk').fadeOut('fast',function() { $(this).remove(); });
270}
271//-----------------------------------------------------------------------------------------------------------------
272function linkHrefs() {
273   //--- Link non link tags such as tr,td,div
274   $('* [href!=""]').each(function() {
275      if($(this).attr('href')) {
276         if($(this).attr('href-linked')) return;
277         if($(this)[0].tagName == 'LINK') return;
278         if($(this)[0].tagName == 'A') return;
279         $(this).click(function() { 
280            if('_blank' == $(this).attr('target') || event.shiftKey) {
281               window.open($(this).attr('href')); 
282            } else if('_top' == $(this).attr('target')) {
283               window.top.location = $(this).attr('href'); 
284            } else {
285               golink($(this).attr('href')) ;
286            }
287         });
288         $(this).attr('href-linked','1');
289      }
290   });
291}
292//-----------------------------------------------------------------------------------------------------------------
293function encode(s) {
294   s = encodeURIComponent(s);
295   s = s.replace("'",'%27');
296   return s;
297}
298function decode(s) {
299   s = s.replace(/\+/g,' ');
300   s = decodeURIComponent(s);
301   return s;
302}
303//-----------------------------------------------------------------------------------------------------------------
304function fuzzyParseFloat(v) {
305   if(!v || v == '') return 0;
306   v = new String(v).replace(/[^0-9\.]+/g,"");
307   return parseFloat(v);
308}
309function fuzzyParseInt(v) {
310   if(!v || v == '') return 0;
311   v = new String(v).replace(/[^0-9\.]+/g,"");
312   return parseInt(v);
313}
314//-----------------------------------------------------------------------------------------------------------------
315function anc_cp(name,dv) {
316   var qrys = document.location.hash;
317   if(!qrys) return dv;
318   qrys = qrys.substring(1);
319   var qryss = qrys.split("&");
320   for(var i = 0; i < qryss.length; i++) {
321      var a = qryss[i].indexOf('=');
322      var n = qryss[i].substring(0,a);
323      if(n == name) {
324         var v = qryss[i].substring(a + 1);
325         if(v && v != '') return v;
326      }
327   }
328   return dv;
329}
330//-----------------------------------------------------------------------------------------------------------------
331function myStripeErrorMessage(err) {
332   if(!err) return 'E1';
333   if(err.code && err.code == 'invalid_expiry_year') return 'Expiration Year Not Valid';
334   if(err.code && err.code == 'invalid_expiry_month') return 'Expiration Month Not Valid';
335   return err.message;
336}
337//-----------------------------------------------------------------------------------------------------------------
338Number.prototype.formatMoney = function(c, d, t){
339var n = this, 
340    c = isNaN(c = Math.abs(c)) ? 2 : c, 
341    d = d == undefined ? "." : d, 
342    t = t == undefined ? "," : t, 
343    s = n < 0 ? "-" : "", 
344    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
345    j = (j = i.length) > 3 ? j % 3 : 0;
346   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
347 };
348function formatNumber(x) {
349   if(!x) return '0';
350   x = parseInt(x);
351   return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
352}
353function format_money(p) {
354   if(!p) return '0';
355   var n = parseFloat(p);
356   var decimalPart = (n % 1).toFixed(2);
357   return decimalPart === "0.00"
358   ? n.toLocaleString(undefined, { maximumFractionDigits: 0 })
359   : n.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
360}
361function display_money(p) {
362   return '$' + format_money(p);
363}
364function format_number(p) {
365   if(!p) return '0';
366   var n = parseFloat(p);
367   return n.toLocaleString(undefined, { maximumFractionDigits: 0 });
368}
369//-----------------------------------------------------------------------------------------------------------------
370function modal_before() {
371   if($.modal) { $.modal.close() }
372   $('body').addClass('modal-open'); 
373}
374function modal_close() {
375   if($.modal) { $.modal.close(); } 
376   $('body').removeClass('modal-open');
377}
378//-----------------------------------------------------------------------------------------------------------------
379function playVideo(videoId) {
380   if(!videoId) videoId = 1;
381  
382   var mediaId;
383   var fileId;
384   if(videoId == 10) { //Website Diagnostics
385      mediaId = 'x0qpxpv55f';
386      fileId = '17e1c374bbb8affbb4588c132857c83c';
387   } else if(videoId == 12) { //Consumer Identity Protection
388      mediaId = '7weqypf9ol';
389      fileId = '610591cc065395e9ddbb8518fec21bdb';
390   } else if(videoId == 20) { //Breach Insurance
391      mediaId = 'kb69evxxso';
392      fileId = '784555aa4395e69abad9ea973aa3e79a45219f39';
393   } else if(videoId == 28) { //Search Submission
394      mediaId = '71q8tr8qas';
395      fileId = '5cb040b6523dd8bc3c462f384e6c7339';
396   } else if(videoId == 29) { //Halo Security Overview
397      mediaId = 'zoskv6518h';
398      fileId = '603041bb3932dbbfefa191ab2b329634';
399   } else if(videoId == 31) { //SIP explainer
400      mediaId = 'j5y9yxyhu0';
401      fileId = 'c506281f8eee5d0abe0473ba7a640dc8';
402   } else if(videoId == 32) { //TS Cert Main
403      mediaId = 'abev1dv5uy';
404      fileId = '3a9c16c0e1ad375c6e23283f3e957f81';
405   } else if(videoId == 33) { //Issue Free Orders
406      mediaId = 'p7k7f5jky0';
407      fileId = '3a9c16c0e1ad375c6e23283f3e957f81';
408   } else if(videoId == 34) { //Verified Business
409      mediaId = '46995q6dkl';
410      fileId = 'a6e9e9d399619ec75b8ab0f13a2a04fb';
411   } else if(videoId == 35) { //TS Cert Consumer
412      mediaId = 'ey03j2ywnv';
413      fileId = '49c4c7d0c2798d18d335d6daee8ac7d85051289b';
414   } else if(videoId == 36) { //Test TS
415      mediaId = 'ya3gccoc3y';
416      fileId = 'f1ed36393494dbda5b3952878920d6b15c7e51a9';
417   } else if(videoId == 37) { //CRO Agency
418      mediaId = '0g590hbb8c';
419      fileId = 'f1ed36393494dbda5b3952878920d6b15c7e51a9';
420   } else if(videoId == 38) { //TS Cert Upgrade
421      mediaId = 'h04o4ou8tz';
422      fileId = '9d38af14db26caba4aa3b4ef414df509';
423   } else if(videoId == 40) { //Opt In Video TS
424      mediaId = 'jocoe2n6ue';
425      fileId = '7012a1163119b733d1009349df7af861';
426   } else if(videoId == 41) { //IFO Customer Experience Explainer
427      mediaId = 'mgxig5vkcq';
428      fileId = '015595576fccadf69e4e363e97232a40';
429   } else if(videoId == 42) { //TSS demo video
430      mediaId = '1o99tobouv';
431      fileId = '9ef44dc9a4f620f6aa5a08a4ca1f04714a2ff813';
432   } else if(videoId == 43) { //TSS risk scores explained
433      mediaId = '2r5e2a0w7w';
434      fileId = '1813084c5df20727bfeaae41a6c10b32';
435   } else if(videoId == 44) { //ASM explainer
436      mediaId = 'p6cxn564ha';
437      fileId = '447705fbd88e49a162cc59513c050284';
438   } else if(videoId == 45) { //Pentesting
439      mediaId = 'it4m1ilxez';
440      fileId = 'b391232c944b7246767a7a8e0bac7ecb';
441   } else {
442      alert('Unknown Video ' + videoId);
443      return;
444   }
445
446   if($(window).width() <= 450) {
447      console.log('playVideo small screen');
448      document.location = 'https://fast.wistia.net/embed/iframe/'+mediaId;//+'?videoFoam=true&autoPlay=true&popover=true';
449      //window.open('http://fast.wistia.net/embed/iframe/'+mediaId+'?popover=true');
450      //document.location = 'https://embed-ssl.wistia.com/deliveries/' + fileId + '/file.mp4';
451      return;
452   }
453
454   var w = $(window).width() - 100;
455   if(w > 1200) w = 1200;
456   var h = parseInt(w * 0.56285714285714);
457
458   var url = '//fast.wistia.net/embed/iframe/' + mediaId + '?videoFoam=true&autoPlay=true&rand=' + new Date().getTime();
459   var ele = document.getElementById('lay-playVideo');
460   if(!ele) {
461      ele = document.createElement('div');
462      ele.id = 'lay-playVideo';
463      ele.style.display = 'none';
464      ele.innerHTML = '<iframe style="width:100%;border:0;" src="'+url+'" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen></iframe>';
465      document.body.appendChild(ele);
466      $.getScript('//fast.wistia.net/assets/external/E-v1.js');
467   }
468   ele.style.width = w + 'px';
469   ele.style.height = h + 'px';
470
471   modal_before();
472   $('#lay-playVideo').modal({overlayClose:true,onClose:function() {
473      modal_close();
474      $('#lay-playVideo').remove();
475   }});
476   $('#lay-playVideo iframe').height(h);
477}
478//-----------------------------------------------------------------------------------------------------------------
479function playVideoList(id) {
480   var w = $(window).width() - 100;
481   if(w > 1200) w = 1200;
482   var h = parseInt(w * 0.56285714285714);
483
484   $.getScript("//fast.wistia.com/assets/external/playlist-v1.js",function() {
485      var ele = document.createElement('div');
486      ele.id = 'wistia_' + id;
487      ele.style.width = w + 'px';
488      ele.style.height = h + 'px';
489      modal_before();
490      $(ele).modal({overlayClose:true,onClose:function() {
491         modal_close();
492         $('wistia_' + id).remove();
493      }});
494      wistiaPlaylist = Wistia.playlist(id, {
495         version: "v1",
496         theme: "tab",
497         videoOptions: {
498           volumeControl: true,
499           playerColor: "787878",
500           autoPlay: true,
501           videoWidth: "640",
502           videoHeight: "360"
503         },
504         media_0_0: {
505           autoPlay: true,
506           controlsVisibleOnLoad: false
507         }
508      });
509   });
510}
511//-----------------------------------------------------------------------------------------------------------------
512function m_alert(title,body,on_ok,opts) {
513   if(!opts) opts = [];
514   if(!opts.ok_text) opts.ok_text = 'Ok';
515   if(!opts.ok_class) opts.ok_class = 'green';
516   $.modal.close();
517   var html = '';
518   if(title) html += '<div class="modal-title">' + title + '</div>';
519   html += '<div class="pad20">';
520   html += body;
521   html += '<div style="padding-top:25px;text-align:right;">' +
522           '<button class="btn '+opts.ok_class+'" id="btn-modal-alert-ok">'+opts.ok_text+'</button>' +
523           '</div>';
524   html += '</div>';
525   var ele = document.createElement('div');
526   ele.className = 'alert-modal bg-card';
527   ele.innerHTML = html;
528   ele.style.width = '350px';
529   $(ele).find('button').css('outline','none');
530   $(ele).modal({overlayClose:true,minWidth:350,onClose:function() {
531      $.modal.close();
532      if(on_ok) on_ok();
533   }});
534   $('#btn-modal-alert-ok').click(function() {
535      $.modal.close();
536      if(on_ok) on_ok();
537   });
538}
539function m_confirm(title,body,on_ok,on_cancel,opts) {
540   console.log(opts);
541   if(!opts) opts = [];
542   if(!opts.ok_text) opts.ok_text = 'Ok';
543   if(!opts.ok_class) opts.ok_class = 'green';
544   if(!opts.cancel_text) opts.cancel_text = 'Cancel';
545   if(!opts.cancel_class) opts.cancel_class = 'grey';
546
547   $.modal.close();
548   var ele = document.createElement('div');
549   ele.className = 'confirm-modal bg-card';
550   ele.style.width = '350px';
551   var html = '';
552   if(title) html += '<div class="modal-title">' + title + '</div>';
553   html += '<div class="pad20">';
554   html += body;
555   html += '<br><br><br>' +
556           '<button class="btn marr5 '+opts.ok_class+'" id="btn-modal-confirm-ok">'+opts.ok_text+'</button>' +
557           '&nbsp;' +
558           '<button class="btn '+opts.cancel_class+'" id="btn-modal-confirm-cancel">'+opts.cancel_text+'</button>';
559   html += '</div>';
560   ele.innerHTML = html;
561   $(ele).find('button').css('outline','none');
562   $(ele).modal({overlayClose:true,minWidth:350,onClose:function() {
563      $.modal.close();
564      if(on_cancel) on_cancel();
565   }});
566   $('#btn-modal-confirm-cancel').click(function() {
567      $.modal.close();
568      if(on_cancel) on_cancel();
569   });
570   $('#btn-modal-confirm-ok').click(function() {
571      on_cancel = '';
572      $.modal.close();
573      if(on_ok) on_ok();
574   });
575   $('#btn-modal-confirm-ok')[0].focus();
576}
577//-----------------------------------------------------------------------------------------------------------------
578function setCookie(cname, cvalue, expireHours, path) {
579    var s = cname + '=' + cvalue + ';';
580    if(expireHours && expireHours > 0) {
581       var d = new Date();
582       d.setTime(d.getTime() + (expireHours*60*60*1000));
583       s += "expires="+d.toUTCString() + ';';
584    }
585    if(path) s += 'path=' + path + ';';
586    document.cookie = s;
587}
588function getCookie(cname) {
589    var name = cname + "=";
590    var ca = document.cookie.split(';');
591    for(var i=0; i<ca.length; i++) {
592        var c = ca[i];
593        while (c.charAt(0)==' ') c = c.substring(1);
594        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
595    }
596    return "";
597}
598//-----------------------------------------------------------------------------------------------------------------
599function init_accordian() {
600   $('.accordian b').click(function() {
601      if($(this).parent().find('p,div.content').is(':visible')) {
602         $(this).parent().find('p').slideUp();
603         $(this).parent().find('div.content').slideUp();
604         $(this).parent().find('li').slideUp();
605         $(this).parent().find('i.fa').first().addClass('fa-chevron-down');
606         $(this).parent().find('i.fa').first().removeClass('fa-chevron-up');
607      } else {
608         $(this).parent().find('p').slideDown();
609         $(this).parent().find('div.content').slideDown();
610         $(this).parent().find('li').slideDown();
611         $(this).parent().find('i.fa').first().removeClass('fa-chevron-down');
612         $(this).parent().find('i.fa').first().addClass('fa-chevron-up');
613      }
614   });
615}
616$(document).ready(function() {
617   $('select.golink').change(function() {
618      golink($(this).val());
619      $(this)[0].selectedIndex = 0;
620   });
621   $('select.golinkconf').change(function() {
622      golinkconf($(this).val());
623      $(this)[0].selectedIndex = 0;
624   });
625});
626//-----------------------------------------------------------------------------------------------------------------
627function golinkconf(v,txt) {
628   if(!txt) txt = 'Are you sure?';
629   m_confirm('Confirm',txt,function() {
630      golink(v);
631   });
632}
633function golink(href, options = {}) {
634   if(!href) return;
635   const opts = { ...options };
636   console.log('golink',href,opts);
637
638   if(event.shiftKey) opts.target = '_blank';
639   if(href.startsWith('js:')) {
640      eval(href.substring(3));
641   } else if(href.startsWith('javascript:')) {
642      eval(href.substring(11));
643   } else {
644      if(href.indexOf('do=') != -1) {
645         go_post(href,opts);
646      } else if(opts.target === '_blank') {
647         window.open(ts_link_prefix(href), "_blank", "noopener");
648      } else if(opts.target === '_top') {
649         window.top.location.href = ts_link_prefix(href);
650      } else {
651         window.location.href = ts_link_prefix(href);
652      }
653   }
654}
655//-----------------------------------------------------------------------------------------------------------------
656function go_post(href, options = {}) {
657   if(!href) return;
658   const opts = { ...options };
659   console.log('go_post',href,opts);
660
661   let url, params;
662   if (href.includes('?')) {
663      const parts = href.split('?');
664      url = parts[0];
665      params = new URLSearchParams(parts[1]);
666   } else {
667      url = href;
668      params = new URLSearchParams();
669   }
670
671   if(typeof spa_load_page == 'function') {
672      spa_load_page('go-post',url ,params);
673      return;
674   }
675
676   const form = document.createElement('form');
677   form.method = 'POST';
678   form.action = ts_link_prefix(url);
679   if(opts.target) form.target = opts.target;
680   for (const [key, value] of params.entries()) {
681      form.appendChild(input_hidden(key, value));
682   }
683   form.appendChild(input_hidden('csrf-token', csrf_token()));
684   document.body.appendChild(form);
685   form.submit();
686}
687//-----------------------------------------------------------------------------------------------------------------
688function input_hidden(n, v) {
689   const input = document.createElement('input');
690   input.type = 'hidden';
691   input.name = n;
692   input.value = v;
693   return input;
694}
695//-----------------------------------------------------------------------------------------------------------------
696function ts_link_prefix(s) {
697   try {
698      return ts_link_prefix_sub(s);
699   } catch(e) {
700      return s;
701   }
702}
703//-----------------------------------------------------------------------------------------------------------------
704function remainingCharacters(ele_cnt,ele_inp,max) {
705   $(ele_cnt).html(formatNumber(max - $(ele_inp).val().length));
706   $(ele_inp).keyup(function() {
707      $(ele_cnt).html(formatNumber(max - $(ele_inp).val().length));
708   });
709}
710//-----------------------------------------------------------------------------------------------------------------
711function recordEvent(category,action,label) {
712   try { ga('send', 'event', category,action, label); } catch(e) { console.log(e); }
713}
714//-----------------------------------------------------------------------------------------------------------------
715function in_frame() {
716  try {
717    return window.self !== window.top;
718  } catch (e) {
719    return true;
720  }
721}
722function frameme_required(url) {
723   if (!in_frame()) top.location = url;
724}
725function frameme_block() {
726   if (in_frame()) top.location.replace(self.location.href);
727}
728//-----------------------------------------------------------------------------------------------------------------
729if (!String.prototype.endsWith) {
730  String.prototype.endsWith = function(searchString, position) {
731      var subjectString = this.toString();
732      if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
733        position = subjectString.length;
734      }
735      position -= searchString.length;
736      var lastIndex = subjectString.lastIndexOf(searchString, position);
737      return lastIndex !== -1 && lastIndex === position;
738  };
739}
740//-----------------------------------------------------------------------------------------------------------------
741function form_focus_first(ele) {
742   $(ele + ' input[type!=hidden]').each(function() {
743      if($(this).val() == '') {
744         //console.log($(this).attr('name'));
745         $(this).focus();
746         return false;
747      }
748   });
749}
750//-----------------------------------------------------------------------------------------------------------------
751function popupCenter(url,w,h) {
752  var left = (screen.width/2)-(w/2);
753  var top = (screen.height/2)-(h/2);
754   window.open(ts_link_prefix(url),'_blank','WIDTH=' + w + ',HEIGHT=' + h +  ',TOP=' + top + ',LEFT=' + left);
755}
756//-----------------------------------------------------------------------------------------------------------------
757function modal_loading(text) {
758   var ele = '<div class="loader-100 loading-100-modal bg-grey"><p>'+(text?text:'')+'</p></div>';
759   $(ele).modal();
760}
761//-----------------------------------------------------------------------------------------------------------------
762function modal_open(id,opts) {
763   $(id).modal(opts);
764}
765function modal_iframe(url,w,h,scrolling) {
766   var opts = [];
767   opts.url = url;
768   if(w) opts.width = w;
769   if(h) opts.height = h;
770   if(scrolling) opts.scrolling = scrolling;
771   modal_frame(opts)
772}
773//-----------------------------------------------------------------------------------------------------------------
774function modal_frame(opts) {
775
776   if(in_modal_frame() && !opts.allowInFrame) {
777      opts.allowInFrame = 1;
778      window.parent.modal_frame(opts);
779      return;
780   }
781
782   var noModalPlugin = !($.modal) 
783   modal_close();
784   var w = opts.width  ? opts.width  : '80%';
785   var h = opts.height ? opts.height : '80%';
786   if(new String(w).endsWith('%')) w = $(window).width() / 100.0 * parseInt(w);
787   if(new String(h).endsWith('%')) h = $(window).height() / 100.0 * parseInt(h);
788
789
790   if(opts.popupIfSmall || noModalPlugin) {
791      if($(window).height() < h + 50 || $(window).width() < w + 50 || noModalPlugin) {
792         popupCenter(opts.url,w,h);
793         return;
794      }
795   }
796
797   if(h > $(window).height()) h = $(window).height() - 50;
798   if(w > $(window).width()) w = $(window).width() - 50;
799
800
801   var url = ts_link_prefix(opts.url);
802   console.log('modal_frame[w='+w+'][h='+h+']' + url);
803
804   var ele = document.createElement('div');
805   ele.style.display = 'none';
806   ele.style.height = h + 'px';
807   ele.style.width = w + 'px';
808   ele.style.backgroundColor = 'var(--color-bg-100)';
809   ele.style.overflow = 'hidden';
810   if(opts.id) ele.id = opts.id;
811   ele.innerHTML = '<iframe scrolling="'+(opts.scrolling?'yes':'no')+'" src="'+url+'" style="width:'+w+'px;height:'+h+'px;border:0;"></iframe>';
812   document.body.appendChild(ele);
813
814   var l_escClose = true;
815   var l_overlayClose = true;
816
817   if(opts.noclose) {
818      l_escClose = false;
819      l_overlayClose = false;
820   }
821
822   modal_before();
823   $(ele).modal({escClose:l_escClose,overlayClose:l_overlayClose,containerCss:{width:w,height:h},onClose:function() {
824      modal_close();
825   }});
826   if(opts.noclose) {
827      $('.simplemodal-close').remove();
828   }
829}
830//-----------------------------------------------------------------------------------------------------------------
831function is_modal_open() {
832   return document.getElementById('simplemodal-container') ? 1 : 0
833}
834function in_modal_frame() {
835   try {
836      return window.parent.document.getElementById('simplemodal-container') ? 1 : 0
837   } catch(e) { return 0; }
838}
839//-----------------------------------------------------------------------------------------------------------------
840function highlightText(id) {
841   if (document.body.createTextRange) {
842      range = document.body.createTextRange();
843      range.moveToElementText(document.getElementById(id));
844      range.select();
845   } else if (window.getSelection) {
846      selection = window.getSelection();
847      range = document.createRange();
848      range.selectNodeContents(document.getElementById(id));
849      selection.removeAllRanges();
850      selection.addRange(range);
851   }
852}
853//-----------------------------------------------------------------------------------------------------------------
854function menu_show(id) {
855   
856   $('#menu-' + id).slideDown('fast');
857
858   var pos = $('#menu-' + id).attr('data-menu-position');
859   if(pos) $('#menu-' + id).position(JSON.parse(pos));
860
861   var ele_angle = $('#menu-'+id+'-angle')[0];
862   if(ele_angle) $('#menu-'+id+'-angle').addClass('fa-rotate-180');
863
864   var ele = menu_overlay_show();
865   $(ele).click(function() { menu_close(); });
866}
867function menu_close() {
868   menu_overlay_hide();
869   $('.menu-popdown:visible').slideUp('fast');
870
871   $('i.fa-angle-down.fa-rotate-180,i.fa-caret-down.fa-rotate-180').each(function() {
872      var href = $(this).parent().attr('href');
873      if(href && href.indexOf('menu_show(') != -1) $(this).removeClass('fa-rotate-180');
874   });
875}
876function menu_overlay_show(clazz) {
877   $('#menu-overlay').remove();
878   window.clearTimeout(menu_overlay_hide_to);
879   var ele = document.getElementById('menu-overlay');
880
881   if(!ele) {
882      ele = document.createElement('div');
883      ele.id = 'menu-overlay';
884      $('body').append(ele);
885   }
886   $(ele).removeClass('invisible');
887   if(clazz) $(ele).addClass(clazz);
888   $(ele).show();
889   return ele;
890}
891function menu_overlay_hide(dur) {
892   //console.log('menu_overlay_hide');
893   window.clearTimeout(menu_overlay_hide_to);
894   if(!dur || dur <= 0) {
895      $('#menu-overlay').remove();
896   } else {
897      $('#menu-overlay').css('transition','background-color '+(dur/1000.0)+'s');
898      $('#menu-overlay').addClass('invisible');
899      menu_overlay_hide_to = window.setTimeout(function() { $('#menu-overlay').remove(); },dur);
900   }
901}
902var menu_overlay_hide_to = 0;
903//-----------------------------------------------------------------------------------------------------------------
904function handle_response(data,success_message) {
905   if(!handle_notsuccess(data)) return;
906   if(!success_message) success_message = 'Saved';
907   messageShow(success_message);
908}
909function handle_notsuccess(data) {
910   if(data && data.success) return 1;
911   if(data && data.errmsg) messageShow(data.errmsg);
912   else {
913      messageShow('R#An Unknown Error Occurred');
914      console.log(data);
915   }
916   return 0;
917}
918//-----------------------------------------------------------------------------------------------------------------
919function set_class(ele,clazz,onoff) {
920   if(onoff) $(ele).addClass(clazz);
921   else $(ele).removeClass(clazz);
922}
923//-----------------------------------------------------------------------------------------------------------------
924function randomid(length) {
925   var result           = '';
926   var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
927   var charactersLength = characters.length;
928   for ( var i = 0; i < length; i++ ) result += characters.charAt(Math.floor(Math.random() * charactersLength));
929   return result;
930}
931//-----------------------------------------------------------------------------------------------------------------
932function refresh_on_resize() {
933   $(window).resize(function() { history.go(0); });
934}
935//-----------------------------------------------------------------------------------------------------------------
936function modal_security_price_calc() {
937   var url = is_hs() ? '/modal-price-calculator' : '/security/modal-price-calculator';
938   modal_frame({url:url,width:600,height:600,scrolling:1});
939}
940//-----------------------------------------------------------------------------------------------------------------
941function pad(v) {
942   if(v < 10) return '0' + v;
943   return v;
944}
945//-----------------------------------------------------------------------------------------------------------------
946function form_submit(form,clear_empty) {
947   var f = $(form)[0];
948   if(!f) {
949      alert('Form Not Found['+form+']');
950      return;
951   }
952   //if(clear_empty) form_remove_empty(form);
953   //f.submit();
954   $(f).trigger('submit');
955}
956function form_remove_empty(form) {
957   $(form).find('input,textarea,select').each(function() { 
958      if($(this).val() == '') {
959         $(this).prop('disabled',true); 
960         return;
961      }
962      if(!$(this).is(':visible')) {
963         var type = $(this).attr('type');
964         if(type == 'hidden') return;
965         if(type == 'select' && $(this).parent().is('.chosen')) return;
966         $(this).prop('disabled',true); 
967      }
968   });
969}
970//-----------------------------------------------------------------------------------------------------------------
971function form_submit_upload(form,options = {}) {
972   var fm = $(form)[0];
973   //console.log(fm.action)
974   //console.log(fm.method)
975   //console.log(fm)
976   var fd = new FormData(fm);
977   $.ajax({
978      url: fm.action,
979      method: fm.method || 'POST',
980      data: fd,
981      processData: false,
982      contentType: false,
983      dataType: 'json',
984      timeout: 60000,
985      success: function (json, _status, xhr) {
986         console.log('success',json);
987         if(options.callback_success) options.callback_success(json, _status, xhr);
988      },
989      error: function (xhr) {
990         console.log('error',xhr);
991         messageShow('Request failed: ' + xhr.status);
992         if(options.callback_error) options.callback_error(xhr);
993      }
994    });
995}
996//-----------------------------------------------------------------------------------------------------------------
997// used for non-authenticated dark mode
998function theme_save(v) {
999   if(v == 'dark' || v == 'light' || v == 'default' || v == '') {
1000      localStorage.setItem('theme',v);
1001   } else { 
1002      localStorage.removeItem('theme');
1003   }
1004}
1005function theme_get() {
1006   return localStorage.getItem('theme');
1007}
1008function theme_use() {
1009   var v = theme_get();
1010   if(v == 'dark' || v == 'light') return v;
1011   return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
1012}
1013function is_darkmode() {
1014   return theme_use() == 'dark';
1015}
1016//-----------------------------------------------------------------------------------------------------------------
1017function page_loading_progress(color,sec) {
1018   var ele = document.createElement('div');
1019   ele.id = 'page-loading-progress';
1020   ele.style = 'transition:' + sec + 's';
1021   $(ele).addClass(color);
1022   $(ele).appendTo('body');
1023   window.setTimeout(function() { $('#page-loading-progress').addClass('done'); },100);
1024   window.setTimeout(function() { $('#page-loading-progress').remove(); },1000 * sec);
1025}
1026//-----------------------------------------------------------------------------------------------------------------
1027function is_ts() {
1028   return window.location.hostname.endsWith('.trustedsite.com');
1029}
1030function is_hs() {
1031   return window.location.hostname.endsWith('.halosecurity.com');
1032}
1033//-----------------------------------------------------------------------------------------------------------------
1034function generate_uuid() {
1035    var d = new Date().getTime();//Timestamp
1036    var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
1037    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
1038        var r = Math.random() * 16;//random number between 0 and 16
1039        if(d > 0){//Use timestamp until depleted
1040            r = (d + r)%16 | 0;
1041            d = Math.floor(d/16);
1042        } else {//Use microseconds since page-load if supported
1043            r = (d2 + r)%16 | 0;
1044            d2 = Math.floor(d2/16);
1045        }
1046        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
1047    });
1048}
1049//-----------------------------------------------------------------------------------------------------------------
1050function uri_this() {
1051   var p = document.location.pathname;
1052   var q = document.location.search;
1053   if(q) p += q;
1054   return p;
1055}
1056//-----------------------------------------------------------------------------------------------------------------
1057function is_fontawesome_loaded() {
1058  let span = document.createElement('span');
1059  span.className = 'fa';
1060  span.style.display = 'none';
1061  document.body.insertBefore(span, document.body.firstChild);
1062  var ff = window.getComputedStyle(span, null).getPropertyValue('font-family');
1063  var is = ff.indexOf('Font Awesome') != -1;
1064  document.body.removeChild(span);
1065  return is;
1066}
1067//-----------------------------------------------------------------------------------------------------------------
1068function toLowerCase(s) {
1069   return s ? s.toLowerCase() : '';
1070}
1071//-----------------------------------------------------------------------------------------------------------------
1072function csrf_token() {
1073   return document.querySelector('meta[name="csrf-token"]').getAttribute('content');
1074}
1075
1076$(document).ready(function() {
1077   $.ajaxSetup({
1078       beforeSend: function(xhr, settings) {
1079           var req_url = new URL(settings.url,window.location.href).toString();
1080           if (req_url.startsWith(window.location.origin)) {
1081               xhr.setRequestHeader('x-csrf-token', csrf_token());
1082           }
1083       }
1084   });
1085});
1086
1087//-----------------------------------------------------------------------------------------------------------------
1088function handle_jq_xhr(jqXHR) {
1089   if(jqXHR.status == 403 || jqXHR.getResponseHeader('x-login')) {
1090      window.top.location = '/login/';
1091      return 1;
1092   }
1093   if(jqXHR.getResponseHeader('x-login-mfa')) {
1094      window.top.location = '/login/mfa';
1095      return 1;
1096   }
1097   if(jqXHR.getResponseHeader('x-csrf-block')) {
1098      console.log('csrf-block',jqXHR);
1099      //alert('Request Token Required');
1100      return  1;
1101   }
1102   return 0;
1103}
1104//-----------------------------------------------------------------------------------------------------------------
1105//-----------------------------------------------------------------------------------------------------------------
1106function init_form_google_recaptcha() {
1107   $('form.google-recaptcha').each(function () {
1108      var fm = this;
1109      console.log('init recpap', fm);
1110      $(fm).submit(function () {
1111         grecaptcha.ready(function () {
1112            const site_key = $('#script-google-recaptcha').attr('data-site-key');
1113            if(site_key === '') throw new Error("site-key not found");
1114            grecaptcha.execute(site_key, {action: 'submit'}).then(function (token) {
1115               var hiddenInput = $('<input>').attr({type: 'hidden', name: 'g-recaptcha-response', value: token});
1116               $(fm).append(hiddenInput);
1117               $(fm)[0].submit();
1118            });
1119         });
1120         return false;
1121      });
1122   });
1123}
1124//-----------------------------------------------------------------------------------------------------------------
1125function godaddy_close_modal() {
1126   if(in_frame()) {
1127      window.parent.postMessage('pleaseCloseWidgetSettingsModal','*');
1128   } else {
1129      messageShow('Parent Frame Not Found','red');
1130   }
1131}
1132//-----------------------------------------------------------------------------------------------------------------
1133function tags_init(ele,opts) {
1134   if(!opts) opts = [];
1135   if(!opts.placeholderText) opts.placeholderText = 'Add Tag';
1136   if(!opts.acAction) opts.acAction = 'tag-target';
1137   if(!opts.acPath) opts.acPath = '/rpc/ajax-user';
1138   if(!opts.validateRegex) opts.validateRegex = '^!?[0-9a-zA-Z\\-\\_\\.\\#]{2,30}$';
1139   if(!opts.fieldName) opts.fieldName = 'tags';
1140   if(!opts.errorMessage) opts.errorMessage = 'R#Tag Not Valid';
1141
1142
1143   var topts = {
1144      placeholderText: opts.placeholderText,
1145      fieldName: opts.fieldName,
1146      tagLimit: opts.tagLimit,
1147      afterTagRemoved: function(event, ui) { 
1148         if(opts.cb_afterTagRemoved) opts.cb_afterTagRemoved(event,ui);
1149      },
1150      afterTagAdded: function(event, ui) { 
1151         do_form_change_activate(); 
1152         if(opts.cb_afterTagAdded) opts.cb_afterTagAdded(event,ui);
1153      },
1154      beforeTagAdded: function(event, ui) {
1155         var v = ui.tagLabel;
1156
1157         if(!opts.noValidation) {
1158            if(opts.validateRegex && !(new RegExp(opts.validateRegex).test(v))) {
1159               console.log('tag-not-valid',v);
1160               messageShow(opts.errorMessage);
1161               messageHide(1000);
1162               return false;
1163            }
1164         }
1165
1166         if(opts.cb_beforeTagAdded) {
1167            return opts.cb_beforeTagAdded(event,ui);
1168         } else {
1169            return true;
1170         }
1171
1172
1173      }
1174   }
1175   if(opts.acPath != 'none' && opts.acAction != 'none') {
1176      topts = $.extend(true,{},topts,{
1177         autocomplete: {
1178            source: function( request, response ) {
1179               $.ajax({
1180                  url: opts.acPath,
1181                  dataType: "json",
1182                  data: { 'do': 'autocomplete-' + opts.acAction, q: request.term },
1183                  success: function( data ) { console.log(data); response(data); }
1184               });
1185            },
1186            minLength: 1
1187      }});
1188   }
1189   console.log('tags_init',$(ele),$.extend(true,{},topts,opts));
1190   $(ele).tagit($.extend(true,{},topts,opts));
1191
1192   $(ele).find('.tagit-new input').removeClass('ui-autocomplete-input');
1193   $(ele).find('.tagit-new input').addClass('ts-input');
1194   $(ele).find('.tagit-new input').attr('autocomplete','off');
1195   $(ele).find('.tagit-new input').attr('data-lpignore','true');
1196   $(ele).find('.tagit-new input').css('width','100px');
1197   //$(ele).find('#datatags span.tagit-label:contains(pci)').parent().find('.tagit-close').remove();
1198}
1199//-----------------------------------------------------------------------------------------------------------------
1200function debounce(fn, delay) {
1201    let timeout;
1202    return function () {
1203        clearTimeout(timeout);
1204        timeout = setTimeout(fn, delay);
1205    };
1206}
1207//-----------------------------------------------------------------------------------------------------------------

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.