PageSourceSearch

https://turtlerescue.co.nz/public/js/app.js?v7?1791409314626

js turtlerescue.co.nz collected 2026-10-08 04:52:16 UTC 33,500 bytes, 915 lines download raw bytes

1var csrf_token = "NA";
2var server_date = "";
3var user_country = "";
4var scrollEventInitComplete = false;
5
6
7app.getCsrf = function (cb) {
8   var m = this;
9   $.ajax({
10      url: '/function/csrf?_dc=' + Math.random(),
11      type: 'GET',
12      contentType: 'application/json',
13      dataType: 'json',
14      success: function (d) {
15         if (cb) {
16            cb(null, d);
17         }
18      },
19      failure: function (err) {
20         if (cb) {
21            cb(err, null);
22         }
23      }
24   });
25};
26
27
28
29app.registerAppEvents = function (filtersOnly) {
30   var m = this;
31   if (!$) {
32      if (jQuery) {
33         var $ = jQuery;
34      }
35   }
36   
37   app.getCsrf(function(err, obj) {
38       csrf_token = obj.csrf || "NA";
39       server_date = obj.date;
40       user_country = obj.country;
41       $(".csrf").val(obj.csrf);
42   });   
43   
44   
45   $(".fnc-facet-sort").off("click").on("click", function (e) {
46      app.facetSortChange($(this), $(this).attr("data-mode"), $(this).attr("data-length"));
47      e.preventDefault();
48      return false;
49   }); 
50   
51   if (!scrollEventInitComplete) {
52      $(".mobile-menu").css("display", "block");
53      $(".mobile-menu").slideUp(0);
54      $(".fnc-facet-sort").each(function (index) {
55         app.facetSortChange($(this), "count", $(this).attr("data-length"));
56      });
57
58      app.facetShowMore();
59   }
60   
61   $(".fnc-toggle-categories").off("click").on("click", function (e) {
62      //console.log("categories");
63      if (!scrollEventInitComplete) {
64         window.scrollTo(0,0); 
65      }
66      var mm = $($(".mobile-menu")[0]);
67      if (mm.hasClass("expanded")) {
68         $(".mobile-menu").slideUp();
69         mm.removeClass("expanded");
70      } else {
71         $(".mobile-menu").slideDown();
72         mm.addClass("expanded");
73      }
74      e.preventDefault();
75      return false;
76   });
77
78
79   var inpfld = $("#listing-pager");
80
81   var minValue = Number(inpfld.attr("data-min"));
82   var maxValue = Number(inpfld.attr("data-max"));
83   var currentValue = Number(inpfld.attr("value"));
84
85   if (currentValue) {
86      $('.product-filter .btn-number').removeAttr('disabled');
87      inpfld.val(currentValue);
88   }
89   
90   $(".fnc-link-home").off("click").on("click", function(e) {
91      window.location = '/';
92   });
93
94   $('.product-filter .btn-number').off().mousedown(function (e) {
95      e.preventDefault();
96      var fieldName = $(this).attr('data-field');
97      var type = $(this).attr('data-type');
98      var input = $("input[name='" + fieldName + "']");
99
100      var currentVal = parseInt(input.val());
101
102      if (!isNaN(currentVal)) {
103         if (type == 'minus') {
104            if (currentVal > minValue) {
105               input.val(currentVal - 1).change();
106            }
107            if (parseInt(input.val()) == minValue) {
108               $(this).attr('disabled', true);
109            }
110         } else if (type == 'plus') {
111            if (currentVal < maxValue) {
112               input.val(currentVal + 1).change();
113            }
114            if (parseInt(input.val()) == maxValue) {
115               $(this).attr('disabled', true);
116            }
117         }
118      } else {
119         input.val(0);
120      }
121      return false;
122   });
123
124   $('.product-filter .input-number').off().focusin(function () {
125      $(this).data('oldValue', $(this).val());
126   });
127
128   $('.product-filter .input-number').change(function () {
129      var valueCurrent = parseInt($(this).val());
130      var name = $(this).attr('name');
131      if (valueCurrent >= minValue) {
132         $(".btn-number[data-type='minus'][data-field='" + name + "']").removeAttr('disabled')
133      } else {
134         $(this).val($(this).data('oldValue'));
135      }
136      if (valueCurrent <= maxValue) {
137         $(".btn-number[data-type='plus'][data-field='" + name + "']").removeAttr('disabled')
138      } else {
139         $(this).val($(this).data('oldValue'));
140      }
141
142      if (currentValue != valueCurrent) {
143         m.state.page = valueCurrent;
144         m.changeView();
145      }
146   });
147
148   $(".product-filter .input-number").keydown(function (e) {
149      // Allow: backspace, delete, tab, escape, enter and .
150      if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
151         // Allow: Ctrl+A
152          (e.keyCode == 65 && e.ctrlKey === true) ||
153         // Allow: home, end, left, right
154          (e.keyCode >= 35 && e.keyCode <= 39)) {
155         // let it happen, don't do anything
156         return;
157      }
158      // Ensure that it is a number and stop the keypress
159      if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
160         e.preventDefault();
161      }
162   });
163
164   $(".fnc-change-page").off("click").on("click", function (e) {
165      m.state.page = $(this).attr("data-page");
166      m.changeView();
167   });
168
169   $(".fnc-change-page-select").off("change").on("change", function (e) {
170      m.state.page = $(this).val();
171      m.changeView();
172   });
173
174   $(".product-filter .fnc-result-order").off("change").on("change", function (e) {
175      m.state.sort = $(this).val();
176      m.state.page = 1;
177      m.changeView();
178   });
179
180   $(".product-filter .fnc-result-rows").off("change").on("change", function (e) {
181      m.state.rows = $(this).val();
182      m.state.page = 1;
183      m.changeView();
184   });
185
186   $(".fnc-clear-filter").off("click").on("click", function (e) {
187      m.changeView(true);
188   });
189
190   $(".fnc-price-range").off("click").on("click", function () {
191      m.state.min = parseInt($(this).attr("data-min"));
192      m.state.max = parseInt($(this).attr("data-max")) + 10000;
193      m.state.page = 1;
194      m.changeView();
195   });
196
197  $(".navbar-form").submit(function() {
198      switch (this.id) {
199         
200         default:
201            return false;
202      }
203      return false;
204   });
205
206   $('.fnc-search-field').off("keyup").on("keyup", function (ev) {
207      if (ev.keyCode == 13) {
208         var groupId = $(this).attr("data-group-field");
209         var txtId = $(this).attr("data-query-field");
210         var urlOverride = $(this).attr("data-url-override");
211         
212         m.state.search = $(this).val();
213         m.state.url = "/";
214        // debugger;
215         if (groupId) {
216            if (groupId.length > 5) {
217               if ($("#" + groupId + " option:selected")) {
218                  m.state.url = $("#" + groupId + " option:selected").attr("data-url");
219               }            
220            }
221         }
222         
223         m.state.page = 1;
224         if (urlOverride && urlOverride != "") {
225            m.state.url = urlOverride;
226         } else {
227            if (m.state.url) {
228               m.state.url = m.state.url.replace("//","/");
229            } else {
230               m.state.url = "/";
231            }
232         }
233         
234         m.changeView(true);
235         ev.preventDefault();
236         return false;
237      }
238   });
239
240   $('.fnc-search').off("click").on("click", function (ev) {
241      var txtId = $(this).attr("data-query-field");
242      var groupId = $(this).attr("data-group-field");
243      var urlOverride = $(this).attr("data-url-override");
244      
245      app.updateLocalState("search", $('#' + txtId).val());
246      
247      m.state.search = $('#' + txtId).val();
248      m.state.url = "/";
249   
250      if (groupId) {
251         if (groupId.length > 5) {
252            if ($("#" + groupId + " option:selected")) {
253               m.state.url = $("#" + groupId + " option:selected").attr("data-url");
254            }            
255         }
256      }
257      
258      m.state.page = 1;
259      
260      if (urlOverride && urlOverride != "") {
261         m.state.url = urlOverride;
262      } else {
263         if (m.state.url) {
264            m.state.url = m.state.url.replace("//","/");
265         } else {
266            m.state.url = "/";
267         }
268      }
269      m.changeView(true);
270   });
271
272   $('.fnc-search-term').off("click").on("click", function (ev) {
273      var txt = $(this).text();
274      txt = txt.substr(0, txt.indexOf("(")).trim();
275      m.state.search = txt;
276      m.state.page = 1;
277      m.changeView(true);
278   });
279
280   $(".fnc-currency").off("change").on("change", function (e) {
281      app.changeCurrency($(this).val());
282      $('.selectpicker').selectpicker('refresh');
283   });
284   
285   //$("a:not(.ediy-fnc)").on("mousedown", function (e) {
286   $(".ediy-fastclick a:not(.ediy-fnc)").on("mousedown", function (e) {
287      //console.log(e);
288      if (!e) e = window.event;
289      if (e.which == 1 && !e.ctrlKey) {  // left click
290         var loc = $(this).attr("href");
291         let target = $(this).attr("target");
292         if (target) {
293            if (target == "_blank") {
294               return false;
295            }
296         }
297         if (loc) {
298            if ((loc.indexOf("#") == -1) && (loc.substr(0, 4) != "java") && (loc.substr(0, 4) != "mail")) {
299               window.location = loc;
300               return false;
301            }
302         }
303      }
304   });
305
306   if ($.magnificPopup) {
307      $('.images-block').magnificPopup({
308         delegate: 'a',
309         type: 'image',
310         gallery: {
311            enabled: true
312         }
313      });
314   }
315
316   if ($.tooltip) {
317      // TOOLTIP	
318      $(".header-links .fa, .tool-tip").tooltip({
319         placement: "bottom"
320      });
321   
322      $(".btn-wishlist, .btn-compare, .display .fa").tooltip('hide');
323   }
324   
325   // Product Owl Carousel
326   // $(".owl-carousel").owlCarousel({
327   //    autoPlay: false, //Set AutoPlay to 3 seconds
328   //    items: 3,
329   //    stopOnHover: true,
330   //    navigation: true, // Show next and prev buttons
331   //    pagination: false,
332   //    navigationText: ["<span class='glyphicon glyphicon-chevron-left'></span>", "<span class='glyphicon glyphicon-chevron-right'></span>"]
333   // });
334
335   // TABS
336   $('.nav-tabs a').click(function (e) {
337      e.preventDefault();
338      $(this).tab('show');
339   });
340
341   $(".fnc-share").off().on("click", function (e) {
342      app.showShareForm(this);
343      e.preventDefault();
344      return false;
345   });
346
347   setTimeout(function() {
348      $(".owl-carousel").css("display","block");
349      $(".owl-carousel").css("overflow","hidden");
350   },200);
351
352  
353   
354   if (m.state.search != "") {
355      $(".fnc-search-field").val(m.state.search);
356   } 
357
358   // nav and dropdown stuff
359   if ($('#main_navbar').length > 0 && !scrollEventInitComplete) {
360      scrollEventInitComplete = true;
361      //Start navbar toggle fix top bottom
362      $(document).on('click', '.toggle_fixing', function (e) {
363         e.preventDefault();
364         if ($('#main_navbar').hasClass('navbar-fixed-top')) {
365            $('#main_navbar').toggleClass('navbar-fixed-bottom navbar-fixed-top');
366            $(this).children('i').toggleClass('fa-chevron-down fa-chevron-up');
367         } else {
368            $('#main_navbar').toggleClass('navbar-fixed-bottom');
369            $(this).children('i').toggleClass('fa-chevron-down fa-chevron-up');
370            if ($('#main_navbar').parent('div').hasClass('container')) $('#main_navbar').children('div').addClass('container').removeClass('container-fluid');
371            else if ($('#main_navbar').parent('div').hasClass('container-fluid')) $('#main_navbar').children('div').addClass('container-fluid').removeClass('container');
372            FixMegaNavbar(navHeight);
373         }
374         if ($('#main_navbar').hasClass('navbar-fixed-top')) { $('body').css({ 'margin-top': $('#main_navbar').height() + 'px', 'margin-bottom': '' }); }
375         else if ($('#main_navbar').hasClass('navbar-fixed-bottom')) { $('body').css({ 'margin-bottom': $('#main_navbar').height() + 'px', 'margin-top': '' }); }
376      })
377      //End navbar toggle fix top bottom
378
379      //Start Fix MegaNavbar on scroll page.
380      var navHeight = $('#main_navbar').offset().top;
381      FixMegaNavbar(navHeight);
382     // $(window).bind('scroll', function () { FixMegaNavbar(navHeight); });
383
384      function FixMegaNavbar(navHeight) {
385         if (!$('#main_navbar').hasClass('navbar-fixed-bottom')) {
386            if ($(window).scrollTop() > navHeight) {
387               $('#main_navbar').addClass('navbar-fixed-top')
388               $('body').css({ 'margin-top': $('#main_navbar').height() + 'px' });
389               if ($('#main_navbar').parent('div').hasClass('container')) $('#main_navbar').children('div').addClass('container').removeClass('container-fluid');
390               else if ($('#main_navbar').parent('div').hasClass('container-fluid')) $('#main_navbar').children('div').addClass('container-fluid').removeClass('container');
391            }
392            else {
393               $('#main_navbar').removeClass('navbar-fixed-top');
394               $('#main_navbar').children('div').addClass('container-fluid').removeClass('container');
395               $('body').css({ 'margin-top': '' });
396            }
397         }
398      }
399      $(document).on('click', '.navbar .dropdown-menu', function (e) { e.stopPropagation(); });
400
401      var $menu = $(".dropdown-menu");
402
403      $menu.menuAim({
404         activate: activateSubmenu,
405         deactivate: deactivateSubmenu
406      });
407
408      function activateSubmenu(row) {
409         var $row = $(row),
410             submenuId = $row.data("submenuId"),
411             $submenu = $("#" + submenuId),
412             height = $menu.outerHeight(),
413             width = $menu.outerWidth();
414
415         // Show the submenu
416         $submenu.css({
417            display: "block",
418            top: -1,
419            left: width - 3,  // main should overlay submenu
420            height: height - 4  // padding for main dropdown's arrow
421         });
422         $row.find("a").addClass("maintainHover");
423      }
424
425      function deactivateSubmenu(row) {
426         var $row = $(row),
427             submenuId = $row.data("submenuId"),
428             $submenu = $("#" + submenuId);
429
430         // Hide the submenu and remove the row's highlighted look
431         $submenu.css("display", "none");
432         $row.find("a").removeClass("maintainHover");
433      }
434
435      $(".dropdown-menu li").click(function (e) {
436         e.stopPropagation();
437      });
438
439      $(document).click(function () {
440         $(".popover").css("display", "none");
441         $("a.maintainHover").removeClass("maintainHover");
442      });
443
444      $("#accordian h3").click(function () {
445         $("#accordian ul ul").slideUp();
446         if (!$(this).next().is(":visible")) {
447            $(this).next().slideDown();
448         }
449      });
450   }
451   
452   if (app.ls.geoCountry) {
453      if (app.ls.geoCountry == "") {
454         app.setGeoCountry();
455      }
456   } else {
457      app.setGeoCountry(); 
458   }
459   app.sync();
460   $(function() {
461      if (ec) {
462        // console.log("App Init EC",ec);
463         m.setLocalState(m.ls);
464      }
465   });
466};
467
468app.showShareForm = function (m, shareLink) {  // info from https://jonsuh.com/blog/social-share-links/
469   if (!shareLink) {
470      shareLink = window.location.href;
471   }
472   var url = "";
473   var width = 640;
474   var height = 480;
475
476   switch ($(m).attr("data-mode")) {
477      case "facebook":
478         url = "https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(shareLink);
479         break;
480      case "twitter":
481         url = "https://twitter.com/intent/tweet/?url=" + encodeURIComponent(shareLink);
482         break;
483      case "linkedin":
484         url = "https://www.linkedin.com/shareArticle?mini=true&url=" + encodeURIComponent(shareLink); //&title=Jonathan%20Suh&source=https%3A%2F%2Fjonsuh.com%2F&summary=Short%20summar
485         break;
486      case "googleplus":
487         url = "https://plus.google.com/share?url=" + encodeURIComponent(shareLink);
488         break;
489      case "pinterest":
490         url = "https://www.pinterest.com/pin/create/button/?url=" + encodeURIComponent(shareLink);
491         break;
492      case "reddit":
493         url = "http://www.reddit.com/submit/?url=" + encodeURIComponent(shareLink);
494         break;
495     
496   }
497
498   var left = (screen.width / 2) - (width / 2),
499       top = (screen.height / 2) - (height / 2);
500   if (screen.availLeft) {
501      left = screen.availLeft + left;
502   }
503   if (screen.availTop) {
504      top = screen.availTop + top;
505   }
506   window.open(
507       url,
508       "",
509       "menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width=" 
509+ width + ",height=" + height + ",top=" + top + ",left=" + left
510   );
511}
512
513app.syncRemoteDb = function () {
514   var m = this;
515   m.remoteDb = window.location.origin + '/db/' + m.sessionDbName;
516   m.sync();
517}
518
519app.timer = null;
520
521app.sync = function (cb, immediate) {
522   var m = this;
523   var timeout = 1000;
524   var server = window.location.origin;
525   if (immediate) {
526      timeout = 0;
527   }
528   
529   var remote = server + '/db/session_' + app.ls.sessionGuid;
530   if (app.timer) clearTimeout(app.timer);
531   app.timer = setTimeout(function () {
532      //var pdbsync = PouchDB.sync("session_" + app.ls.sessionGuid, remote, {
533      //   live: false,
534      //   retry: false
535      //}).on('complete', function (info) {
536        /* if (app.ls.profileDbName) {
537            //console.log("Sync profile: " + app.ls.profileDbName);
538            var pdbsync = PouchDB.sync(app.ls.profileDbName, server + '/db/' + app.ls.profileDbName, {
539               live: false,
540               retry: false
541            }).on('complete', function (info) {
542               if (cb) {
543                  cb(info);
544               }
545            });
546         } else { */
547            if (cb) {
548               cb(null);
549            }
550        // }
551      //});
552
553      app.timer = null;
554   }, timeout);
555};
556
557app.facetShowMore = function () {
558   try {
559//      $("div").remove(".fnc-list-toggle");
560      let foldingFilter = ($(".folding-filter").length > 0);
561
562      $(".sidebar-filter ul").not(".facet-list").filter(function (i) { return $('li', this).length >= 1; }).each(function (i) {
563         var numItems = $(this).children(".hidden-list").length;
564         var alreadyInited = ($(this).children(".fnc-list-toggle").length > 0);
565         if (numItems > 0 && !alreadyInited) {  // && !foldingFilter
566            $(this).append(
567                $("<div class=\"fnc-list-toggle\" />").html("Show " + numItems + " More <i class=\"fa fa-angle-double-down\"/>")
568            )
569                .click(function (e) {
570                   var $ul = $(this).children(".hidden-list");
571                   if ($ul.is(":visible")) {
572                      $ul.find(".hidden-list").slideUp();
573                      $ul.slideUp();
574                      $(this).find(".fnc-list-toggle").html("Show " + numItems + " More <i class=\"fa fa-angle-double-down\"/>");
575
576                   }
577                   else {
578                      $ul.slideDown();
579                      $(this).find(".fnc-list-toggle").html("Show Less <i class=\"fa fa-angle-double-up\"/>");
580                      if ($($(this).parents("div")).hasClass("fnc-facet-filter")) {
581                         app.facetSortChange($(this), "disporder", $(this).attr("data-length"));
582                      }
583                      //app.facetSortChange($(this), "count");
584                   };
585                })
586         }
587      });
588   }
589   catch(ex) {}
590}
591
592app.facetSortChange = function (section, newMode, listLength) {
593   function sort_disporder(a, b) {
594      return ($($(b).find("input")[0]).data('display-order')) < ($($(a).find("input")[0]).data('display-order')) ? 1 : -1;
595   }
596   function sort_count(a, b) {
597      return ($($(b).find("input")[0]).data('count')) < ($($(a).find("input")[0]).data('count')) ? -1 : 1;
598   }
599   var group = $(section.parents("div")[0]);
600   var link = $(group.find(".fnc-facet-sort")[0]);
601   
602   // let foldingMode = (link.attr("data-folding") == "1");
603   let foldingFilter = ($(".folding-filter").length > 0);
604   
605   if (newMode == "disporder") {
606      $(group.find("i")[0]).attr("class", "fa fa-sort-amount-desc");
607      $(group.find("img")[0]).attr("src", $(group.find("img")[0]).attr("data-count-icon"));
608      link.attr("data-mode", "count");
609      link.attr("title", "Order by item count");
610      
611      var list = $(group.find("ul")[0]);
612      list.find("li").sort(sort_disporder).appendTo(list);
613      list.children(".hidden-list").slideDown();
614      list.find(".fnc-list-toggle").css("display", "none");
615   } else {
616      if (listLength > 4) {
617         $(group.find("i")[0]).attr("class", foldingFilter ? "fa fa-chevron-down" : "fa fa-bars");
618      } else {
619         $(group.find("i")[0]).attr("class", foldingFilter ? "fa fa-chevron-down" : "fa fa-bars");
620      }
621      
622      $(group.find("img")[0]).attr("src", $(group.find("img")[0]).attr("data-org-icon"));
623      link.attr("data-mode", "disporder");
624
625      link.attr("title", "Show organised list");
626      var list = $(group.find("ul")[0]);
627
628      list.find("li").sort(sort_count).appendTo(list);
629
630   }
631}
632
633app.toHex = function (str) {
634   var arr = [];
635   for (var i = 0, l = str.length; i < l; i++) {
636      var hex = Number(str.charCodeAt(i)).toString(16);
637      arr.push(hex.length > 1 && hex || "0" + hex);
638   }
639   return arr.join('');
640}
641
642app.formatLinkName = function (st) {
643   var lIndex = 0;
644   var sOut = [];
645   var cTemp = "";
646   var lChar = 0;
647   var bskip = false
648
649   st = st.toLowerCase().trim(); 
650   if (st.length > 0) {
651      for (lIndex = 0; lIndex < st.length; lIndex++) {
652         cTemp = st.substr(lIndex, 1);
653         lChar = cTemp.charCodeAt(0);
654         switch (lChar) {
655            // convert space
656            case 32: {
657               if (!bskip) {
658                  if (lIndex > 2) {
659                     sOut.push("-");
660                  }
661                  bskip = true;
662               }
663               break;
664            }
665
666               // convert dash
667            case 45: { 
668               if (!bskip) {
669                  if (lIndex > 2) {
670                     sOut.push("-");
671                  }
672                  bskip = true;
673               }
674               break;
675            }
676
677               // convert forwardslash
678            case 47: {
679               if (!bskip) {
680                  if (lIndex > 2) {
681                     sOut.push("-");
682                  }
683                  bskip = true;
684               }
685               break;
686            }
687
688            case 46: { // .
689               if (!bskip) {
690                  if (lIndex < 3) {
691                  } else {
692                     sOut.push(cTemp);
693                  }
694               }
695               bskip = true;
696               break;
697            }
698               // allow a-z, 0-9, @
699            default: {
700               if (lChar == 64) {
701                  sOut.push('_at_');
702                  bskip = false;
703               }
704               if ((lChar >= 97) && (lChar <= 122)) {
705                  sOut.push(cTemp);
706                  bskip = false;
707               }
708               if ((lChar >= 48) && (lChar <= 57)) {
709                  sOut.push(cTemp);
710                  bskip = false;
711               }
712            }
713         }
714      }
715      return sOut.join("");
716   } else {
717      return "";
718   }
719};
720
721app.notify = function (msg, type) {
722   var popupLocation = 'top-right';
723   if (typeof window.popupNotifyLocation !== 'undefined' ) {
724      popupLocation = window.popupNotifyLocation;
725   }
726   
727   $.notify(app.htmlEncode(msg), { 
728      className: type,
729      position: popupLocation
730   });
731}
732
733app.alert = function (title, message, closecallback) {
734   $("#alert-title").text(title);
735   $("#alert-body").html(app.htmlEncode(message));
736   $("#dialog-alert").modal();
737   $(".fnc-close-alert").off().on("click", function () {
738      $("#dialog-alert").modal('hide');
739      if (closecallback) closecallback(); 
740   });
741}
742
743app.confirm = function (title, message, confirmbutton, cancelbutton, confirmcallback) {
744   $("#confirm-title").text(title);
745   $("#confirm-body").html(app.htmlEncode(message));
746   
747   $("#confirm-cancel").css("display","none");
748   if (cancelbutton) {
749      if (cancelbutton != "") {
750         $("#confirm-cancel").text(cancelbutton);
751         $("#confirm-cancel").css("display","inline-block");      
752      }
753   }
754   
755   $("#confirm-accept").css("display","none");
756   if (confirmbutton) {
757      if (confirmbutton != "") {
758         $("#confirm-accept").text(confirmbutton);
759         $("#confirm-accept").css("display","inline-block");      
760      }
761   }
762   
763   $("#dialog-confirm").modal();
764   
765   $(".fnc-confirm-yes").off().on("click", function () {
766      if (confirmcallback) confirmcallback();
767   });
768}
769
770
771app.requireLogin = function (label, cb) {
772   var m = this;
773   delete app.loginCallback;
774   if (!app.ls.profile.email) {
775      app.loginCallback = cb;
776      if (label != "") {
777         $("#text-login-msg").text(label);
778      }
779      profile.modalAnimate(profile.$formLogin);
780      $("#login-modal").modal();
781      app.loadPickupSelectLists();
782      return null;
783   } else {
784      cb(app.ls.profile);
785   }
786}
787
788
789app.getGeoByIp = function (cb) {
790   var m = this;
791   $.ajax({
792      url: '/api/geo?_dc=' + Math.random(),
793      type: 'GET',
794      contentType: 'application/json',
795      dataType: 'json',
796      success: function (d) {
797         if (cb) {
798            cb(d);
799         }
800      },
801      failure: function () {
802         if (cb) {
803            cb(null);
804         }
805      }
806   });
807};
808
809app.setGeoCountry = function() {
810   app.getGeoByIp(function(data) {
811      if (data) {
812         if (data.geo) {
813            app.ls.geoCountry = data.geo.country;
814            //console.log("Set geo country to: " , data);
815         } else {
816            app.ls.geoCountry = "NZ";
817            //console.log("Set geo country to default NZ");
818         }
819         app.setLocalState(app.ls);
820      } 
821   });
822};
823
824app.countryList = { "": "[Please select country]", "BD": "Bangladesh", "BE": "Belgium", "BF": "Burkina Faso", "BG": "Bulgaria", "BA": "Bosnia and Herzegovina", "BB": "Barbados", "WF": "Wallis and Futuna", "BL": "Saint Barthelemy", "BM": "Bermuda", "BN": "Brunei", "BO": "Bolivia", "BH": "Bahrain", "BI": "Burundi", "BJ": "Benin", "BT": "Bhutan", "JM": "Jamaica", "BV": "Bouvet Island", "BW": "Botswana", "WS": "Samoa", "BQ": "Bonaire, Saint Eustatius and Saba ", "BR": "Brazil", "BS": "Bahamas", "JE": "Jersey", "BY": "Belarus", "BZ": "Belize", "RU": "Russia", "RW": "Rwanda", "RS": "Serbia", "TL": "East Timor", "RE": "Reunion", "TM": "Turkmenistan", "TJ": "Tajikistan", "RO": "Romania", "TK": "Tokelau", "GW": "Guinea-Bissau", "GU": "Guam", "GT": "Guatemala", "GS": "South Georgia and the South Sandwich Islands", "GR": "Greece", "GQ": "Equatorial Guinea", "GP": "Guadeloupe", "JP": "Japan", "GY": "Guyana", "GG": "Guernsey", "GF": "French Guiana", "GE": "Georgia", "GD": "Grenada", "GB": "United Kingdom", "GA": "Gabon", "SV": "El Salvador", "GN": "Guinea", "GM": "Gambia", "GL": "Greenland", "GI": "Gibraltar", "GH": "Ghana", "OM": "Oman", "TN": "Tunisia", "JO": "Jordan", "HR": "Croatia", "HT": "Haiti", "HU": "Hungary", "HK": "Hong Kong", "HN": "Honduras", "HM": "Heard Island and McDonald Islands", "VE": "Venezuela", "PR": "Puerto Rico", "PS": "Palestinian Territory", "PW": "Palau", "PT": "Portugal", "SJ": "Svalbard and Jan Mayen", "PY": "Paraguay", "IQ": "Iraq", "PA": "Panama", "PF": "French Polynesia", "PG": "Papua New Guinea", "PE": "Peru", "PK": "Pakistan", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PM": "Saint Pierre and Miquelon", "ZM": "Zambia", "EH": "Western Sahara", "EE": "Estonia", "EG": "Egypt", "ZA": "South Africa", "EC": "Ecuador", "IT": "Italy", "VN": "Vietnam", "SB": "Solomon Islands", "ET": "Ethiopia", "SO": "Somalia", "ZW": "Zimbabwe", "SA": "Saudi Arabia", "ES": "Spain", "ER": "Eritrea", "ME": "Montenegro", "MD": "Moldova", "MG": "Madagascar", "MF": "Saint Martin", "MA": "Morocco", "MC": "Monaco", "UZ": "Uzbekistan", "MM": "Myanmar", "ML": "Mali", "MO": "Macao", "MN": "Mongolia", "MH": "Marshall Islands", "MK": "Macedonia", "MU": "Mauritius", "MT": "Malta", "MW": "Malawi", "MV": "Maldives", "MQ": "Martinique", "MP": "Northern Mariana Islands", "MS": "Montserrat", "MR": "Mauritania", "IM": "Isle of Man", "UG": "Uganda", "TZ": "Tanzania", "MY": "Malaysia", "MX": "Mexico", "IL": "Israel", "FR": "France", "IO": "British Indian Ocean Territory", "SH": "Saint Helena", "FI": "Finland", "FJ": "Fiji", "FK": "Falkland Islands", "FM": "Micronesia", "FO": "Faroe Islands", "NI": "Nicaragua", "NL": "Netherlands", "NO": "Norway", "NA": "Namibia", "VU": "Vanuatu", "NC": "New Caledonia", "NE": "Niger", "
824NF": "Norfolk Island", "NG": "Nigeria", "NZ": "New Zealand", "NP": "Nepal", "NR": "Nauru", "NU": "Niue", "CK": "Cook Islands", "XK": "Kosovo", "CI": "Ivory Coast", "CH": "Switzerland", "CO": "Colombia", "CN": "China", "CM": "Cameroon", "CL": "Chile", "CC": "Cocos Islands", "CA": "Canada", "CG": "Republic of the Congo", "CF": "Central African Republic", "CD": "Democratic Republic of the Congo", "CZ": "Czech Republic", "CY": "Cyprus", "CX": "Christmas Island", "CR": "Costa Rica", "CW": "Curacao", "CV": "Cape Verde", "CU": "Cuba", "SZ": "Swaziland", "SY": "Syria", "SX": "Sint Maarten", "KG": "Kyrgyzstan", "KE": "Kenya", "SS": "South Sudan", "SR": "Suriname", "KI": "Kiribati", "KH": "Cambodia", "KN": "Saint Kitts and Nevis", "KM": "Comoros", "ST": "Sao Tome and Principe", "SK": "Slovakia", "KR": "South Korea", "SI": "Slovenia", "KP": "North Korea", "KW": "Kuwait", "SN": "Senegal", "SM": "San Marino", "SL": "Sierra Leone", "SC": "Seychelles", "KZ": "Kazakhstan", "KY": "Cayman Islands", "SG": "Singapore", "SE": "Sweden", "SD": "Sudan", "DO": "Dominican Republic", "DM": "Dominica", "DJ": "Djibouti", "DK": "Denmark", "VG": "British Virgin Islands", "DE": "Germany", "YE": "Yemen", "DZ": "Algeria", "US": "United States", "UY": "Uruguay", "YT": "Mayotte", "UM": "United States Minor Outlying Islands", "LB": "Lebanon", "LC": "Saint Lucia", "LA": "Laos", "TV": "Tuvalu", "TW": "Taiwan", "TT": "Trinidad and Tobago", "TR": "Turkey", "LK": "Sri Lanka", "LI": "Liechtenstein", "LV": "Latvia", "TO": "Tonga", "LT": "Lithuania", "LU": "Luxembourg", "LR": "Liberia", "LS": "Lesotho", "TH": "Thailand", "TF": "French Southern Territories", "TG": "Togo", "TD": "Chad", "TC": "Turks and Caicos Islands", "LY": "Libya", "VA": "Vatican", "VC": "Saint Vincent and the Grenadines", "AE": "United Arab Emirates", "AD": "Andorra", "AG": "Antigua and Barbuda", "AF": "Afghanistan", "AI": "Anguilla", "VI": "U.S. Virgin Islands", "IS": "Iceland", "IR": "Iran", "AM": "Armenia", "AL": "Albania", "AO": "Angola", "AQ": "Antarctica", "AS": "American Samoa", "AR": "Argentina", "AU": "Australia", "AT": "Austria", "AW": "Aruba", "IN": "India", "AX": "Aland Islands", "AZ": "Azerbaijan", "IE": "Ireland", "ID": "Indonesia", "UA": "Ukraine", "QA": "Qatar", "MZ": "Mozambique" };
825
826app.loadCountryLists = function () {
827   app.countryArray = [];
828   $.each(app.countryList, function (key, value) {
829      app.countryArray.push({
830         code: key,
831         name: value
832      });
833   });
834   app.countryArray.sort(function (a, b) { 
835      if (a.name < b.name) { return -1; }
836      if (a.name > b.name) { return 1; }
837      return 0;
838   });
839   
840   if(typeof store !== 'undefined'){
841      store.state.countryList = app.countryArray;
842   }
843   
844   $(".data-country-select").each(function (index) {
845      var sel = $(this);
846      sel.find('option').remove();
847      sel.append('<option value="">Please select a country</option>');
848      for (var i = 0; i < app.countryArray.length; i++) {
849         sel.append('<option value="' + app.countryArray[i].code + '">' + app.countryArray[i].name + '</option>');
850      }
851   });
852}
853
854app.pickupList = [];
855app.loadPickupSelectLists = function () {
856	$.getJSON("/api/shipping/pickuplocations","", function(data) {
857		app.pickupList = data;
858		$(".data-pickup-select").each(function (index) {
859	      var sel = $(this);
860	      sel.find('option').remove();
861	      sel.append('<option value="">Please choose a pickup location</option>');
862	      for (var i = 0; i < data.length; i++) {
863	         sel.append('<option data-content="' + data[i].company + '" value="' + data[i].guid + '">' + data[i].company + '</option>');
864	      }
865	   });
866	}); 
867} 
868
869app.hashCode = function(str) {
870  var hash = 0, i, chr;
871  if (str.length === 0) return hash;
872  for (i = 0; i < str.length; i++) {
873    chr   = str.charCodeAt(i);
874    hash  = ((hash << 5) - hash) + chr;
875    hash |= 0; // Convert to 32bit integer
876  }
877  return hash;
878};
879
880app.dumpDb = function (cb) {
881   var m = this;
882   var options = {
883      startkey: "",
884      endkey: "\uffff",
885      include_docs: true
886   };
887
888   m.db.allDocs(options, function (err, docs) {
889      console.log(docs);
890   });
891}
892
893app.registerAppEvents();
894app.registerFormEvents();
895
896app.initCart();
897profile.init();
898
899
900
901switch(utils.getParam("operation")) {
902   case "reset":
903      setTimeout(function() {
904         var targetUrl = atob(utils.getParam("targetUrl"));
905         app.safeNavigate (targetUrl);
906      }, 100);
907      break;
908   case "notify":
909      app.notify(utils.getParam("message"), "error");
910      break;
911}
912
913
914
915//app.initQuickSearch();

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.