PageSourceSearch

https://www.delusciouscookies.com/store-locator/css/main.js?v=2025

js delusciouscookies.com collected 2026-09-26 10:11:54 UTC 61,174 bytes, 1,829 lines download raw bytes

1function function_exists(function_name) {
2  // Return TRUE if the given function has been defined
3  if (typeof function_name == 'string') {
4    return typeof window[function_name] == 'function';
5  } else {
6    return function_name instanceof Function;
7  }
8}
9
10// stop the carusel on click on the indicators
11function stopCaruselOnClick() {
12  $('.carousel-indicators > li').click(function (event) {
13    $('.carousel').carousel('pause');
14  });
15}
16
17//products tab collapse
18function init_tabs_collapse() {
19  if (typeof fakewaffle != 'undefined') fakewaffle.responsiveTabs(['xs', 'sm']);
20}
21
22jQuery.extend({
23  part: function (str, i, separator) {
24    //console.log(this);
25    if (!separator) separator = ':';
26    if (!i) i = 0;
27
28    var parts = str.split(separator);
29    if (parts.length <= i) return false;
30    return parts[i];
31  },
32});
33
34jQuery.fn.extend({
35  get_part: function (i, aName, separator) {
36    if (!i) i = 0;
37    if (!aName) aName = 'id';
38    if (!separator) separator = ':';
39    return jQuery.part($(this).attr(aName), i, separator);
40  },
41});
42
43jQuery.extend({
44  chunk: function (str, chunk, separator) {
45    //console.log(this);
46    if (!str) return;
47    if (!separator) separator = ':';
48    if (!chunk) chunk = 0;
49
50    chunks = str.split(separator);
51    return chunks[chunk];
52  },
53});
54
55jQuery.fn.extend({
56  chunkId: function (chunk, separator) {
57    return jQuery.chunk($(this).attr('id'), chunk, separator);
58  },
59});
60
61jQuery.extend({
62  sendPostForm: function ($form, $element, addData, callback) {
63    var url = $form.attr('action');
64    var post = {};
65    var params = $form.serializeArray();
66
67    jQuery.each(params, function (i, obj) {
68      post[obj.name] = obj.value;
69    });
70
71    if (typeof (addData == 'object')) {
72      for (add in addData) {
73        post[add] = addData[add];
74      }
75    }
76
77    $element.load(url, post, callback);
78
79    return true;
80  },
81});
82
83jQuery.fn.extend({
84  sendPostForm: function ($form) {
85    var $element = $(this);
86    var url = $form.attr('action');
87    var post = {};
88    var params = $form.serializeArray();
89
90    jQuery.each(params, function (i, obj) {
91      post[obj.name] = obj.value;
92    });
93
94    $element.load(url, post);
95    return true;
96  },
97});
98
99//following fucntion is required for backward compatibility
100function open_with_ajax(url, output_ID, callback_func, async, post_params) {
101  if (typeof async == 'undefined') var async = true;
102
103  if (typeof post_params == 'undefined') var post_params = '';
104
105  if (typeof jQuery != 'undefined') {
106    var sURL = url;
107    var bAsync = async;
108    var sMethod = post_params == '' ? 'GET' : 'POST';
109    $.ajax({
110      url: sURL,
111      async: bAsync,
112      type: sMethod,
113      data: post_params,
114      success: function (data) {
115        if (output_ID != '' && $('#' + output_ID).length) {
116          $('#' + output_ID).html(data);
117        }
118        if (typeof callback_func != 'undefined' && callback_func != '') eval(callback_func + '(data);');
119      },
120    });
121    return;
122  }
123}
124
125function log(msg) {
126  if (typeof console != 'undefined') {
127    console.log(msg);
128  }
129}
130
131function init_bbcode_wysiwyg() {
132  if (!$('.bbcode_wysiwyg').length) return;
133  if (typeof $('.bbcode_wysiwyg') == 'undefined') return;
134  $('.bbcode_wysiwyg').bbcode_wysiwyg();
135}
136
137function init_comments() {
138  if (!$('#comments').length) return;
139
140  $('.s-msg-reply').click(function () {
141    var parent = $(this).parents('div.info').get(0);
142    var parent_id = '#' + $(parent).attr('id');
143    $('#COMMENT').html(
144      '[quote=' +
145        $('#AUTHOR_' + $(parent).attr('id')).text() +
146        ']' +
147        $('#SOURCE_' + $(parent).attr('id')).text() +
148        '[/quote]'
149    );
150    $('#comment_PARENT_ID').val($('#ID_' + $(parent).attr('id')).text());
151    $('#comment_LEVEL').val(parseInt($('#LEVEL_' + $(parent).attr('id')).text() + 1));
152    $('#comment_PARENT_ID').removeAttr('disabled');
153    $('#comment_LEVEL').removeAttr('disabled');
154    $('#form-comment-add').insertAfter('#comment' + $('#ID_' + $(parent).attr('id')).text());
155    $('.s-msg-reply, .s-msg-add, .s-msg-top').hide();
156    $('#form-comment-add').show();
157    setTimeout(function () {
158      $('#comments')
159        .find('.bbcode_wysiwyg')
160        .each(function (i, obj) {
161          $(obj).bbcode_initIframe();
162        });
163    }, 1000);
164    return false;
165  });
166  $('.s-msg-add').click(function () {
167    $('#comment_PARENT_ID').attr('disabled', 'disabled');
168    $('#comment_LEVEL').attr('disabled', 'disabled');
169    $('#comment_PARENT_ID').val('');
170    $('#comment_LEVEL').val('');
171    $('#COMMENT').html('');
172    $('#form-comment-add').insertAfter('#comments_form_start_position');
173    $('.s-msg-reply, .s-msg-add, .s-msg-top').hide();
174    $('#form-comment-add').show();
175    setTimeout(function () {
176      $('#comments')
177        .find('.bbcode_wysiwyg')
178        .each(function (i, obj) {
179          $(obj).bbcode_initIframe();
180        });
181    }, 1000);
182    return false;
183  });
184  $('.s-msg-cancel').click(function () {
185    $('#comment_PARENT_ID').attr('disabled', 'disabled');
186    $('#comment_LEVEL').attr('disabled', 'disabled');
187    $('#comment_PARENT_ID').val('');
188    $('#comment_LEVEL').val('');
189    $('#COMMENT').html('');
190    $('#form-comment-add').hide();
191    $('#form-comment-add').insertAfter('#comments_form_start_position');
192    $('.s-msg-reply, .s-msg-add, .s-msg-top').show();
193    return false;
194  });
195}
196
197function init_lightbox() {
198  if (!$('.lightbox').length || typeof $('.lightbox').lightBox == 'undefined') return;
199  $.each($('a.lightbox_single'), function (i, obj) {
200    $(obj).lightBox();
201  });
202  $('.lightbox').lightBox();
203}
204
205function getCookie(name) {
206  return $.cookie(name);
207  /*var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
208    return matches ? decodeURIComponent(matches[1]) : undefined;*/
209}
210
211function setCookie(name, value, expires, path, domain, secure) {
212  $.cookie(name, value, {
213    expires: expires, //expires in 10 days
214
215    path: path, //The value of the path attribute of the cookie
216    //(default: path of page that created the cookie).
217
218    domain: domain, //The value of the domain attribute of the cookie
219    //(default: domain of page that created the cookie).
220
221    secure: secure, //If set to true the secure attribute of the cookie
222    //will be set and the cookie transmission will
223    //require a secure protocol (defaults to false).
224  });
225
226  //document.cookie
227}
228
229function init_after_login_logout_return() {
230  $('.after_login_return').click(function () {
231    //alert("You should login");
232    setCookie('after_login_return_url', document.location.href, '', '/');
233    //location.href="/login/";
234  });
235  $('.after_logout_return').click(function () {
236    //alert("You should login");
237    setCookie('after_logout_return_url', document.location.href, '', '/');
238    //location.href="/login/";
239  });
240  $('.after_logout_return2home').click(function () {
241    //alert("You should login");
242    setCookie('after_logout_return_url', $('SPAN#SITEHOME').text(), '', '/');
243    //location.href="/login/";
244  });
245}
246
247function init_non_auth_message() {
248  $('.non_auth').click(function () {
249    alert($(this).attr('title'));
250    location.href = $(this).attr('href');
251  });
252}
253
254function init_gallery() {
255  if (!$('div.gallery_full_list').length) return;
256  jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
257    return -c * ((t = t / d - 1) * t * t * t - 1) + b;
258  };
259  $('div.gallery_full_list').serialScroll({
260    //target:'.gallery_full_list',
261    items: 'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
262    prev: '.gallery_nav_prev', // Selector to the 'prev' button (absolute!, meaning it's relative to the document)
263    next: '.gallery_nav_next', // Selector to the 'next' button (absolute too)
264    axis: 'x', // The default is 'y' scroll on both ways
265    //navigation:'#greybox_m img.nav_first, #navigation_hidden a, #greybox_m img.nav_last',
266    duration: 700, // Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
267    force: true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
268
269    //queue:false,// We scroll on both axes, scroll both at the same time.
270    //event:'click',// On which event to react (click is the default, you probably won't need to specify it)
271    //stop:false,// Each click will stop any previous animations of the target. (false by default)
272    //lock:true, // Ignore events if already animating (true by default)
273    //start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )
274    //cycle:true,// Cycle endlessly ( constant velocity, true is the default )
275    //step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
276    //jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
277    //lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
278    //interval:1000, // It's the number of milliseconds to automatically go to the next
279    //constant:true, // constant speed
280
281    onBefore: function (e, elem, $pane, $items, pos) {
282      //those arguments with a $ are jqueryfied, elem isn't.
283      e.preventDefault();
284      if (this.blur) this.blur();
285    },
286    onAfter: function (elem) {
287      //'this' is the element being scrolled ($pane) not jqueryfied
288    },
289  });
290}
291
292function init_confirmations() {
293  if (!$('.confirmation').length && !$('.open_confirmation').length) return;
294  $('.confirmation').dialog({
295    bgiframe: true,
296    resizable: false,
297    height: 350,
298    autoOpen: false,
299    modal: true,
300    overlay: {
301      backgroundColor: '#000',
302      opacity: 0.5,
303    },
304    buttons: {
305      'I agree to terms and conditions': function () {
306        $('#' + $(this).attr('rel')).attr('checked', 'checked');
307        $(this).dialog('close');
308      },
309      Cancel: function () {
310        $('#' + $(this).attr('rel')).removeAttr('checked');
311        $(this).dialog('close');
312      },
313    },
314  });
315  $('.open_confirmation')
316    .css({ cursor: 'pointer' })
317    .click(function () {
318      $('#' + $(this).attr('rel')).dialog('open');
319      return false;
320    });
321}
322
323function init_msgbox() {
324  $('.msgBox').each(function (i, obj) {
325    var height_val = $(obj).attr('height') ? $(obj).attr('height') : 350;
326    var width_val = $(obj).attr('width') ? $(obj).attr('width') : 600;
327    $(obj).dialog({
328      height: height_val * 1,
329      width: width_val * 1,
330      autoOpen: false,
331    });
332  });
333  $('.open_msgBox')
334    .css({ cursor: 'pointer' })
335    .click(function () {
336      $('#' + $(this).attr('rel')).dialog('open');
337      return false;
338    });
339}
340
341function init_slideshow() {
342  if (!$('.start_gallery_slideshow').length || !$('.start_slideshow_here').length) return;
343  $VisualLightBoxParams$ = {
344    autoPlay: true,
345    borderSize: 39,
346    enableSlideshow: true,
347    overlayOpacity: 0,
348    startZoom: true,
349  };
350  init_lightslideshow();
351  $('.start_slideshow_here').click();
352  $('.start_gallery_slideshow')
353    .css({ cursor: 'pointer' })
354    .click(function () {
355      $('#firstimg').click();
356    });
357}
358
359function init_on_focus_replace() {
360  if ($('INPUT.on_focus_replace').length)
361    alert('.on_focus_replace class is deprecated. Use placeholder attribute instead');
362}
363
364function init_fading_tabs() {
365  if ($('.tabs_listing').length && typeof console != 'undefined')
366    console.log('Alla, you cannot use .tabs_listing. It is stuff done by Gena and we do not use it anymore.');
367}
368
369function correct_zindex4menu(selector4_zindex_correction) {
370  $(selector4_zindex_correction).css({ 'z-index': '20' });
371  $(selector4_zindex_correction + ' li').css({ 'z-index': '20' });
372  $(selector4_zindex_correction + ' li ul').css({ 'z-index': '30' });
373  $(selector4_zindex_correction + ' li ul li').css({ 'z-index': '30' });
374}
375
376function get_parent_div_of_class(element, class_name) {
377  while ($(element).parent().length) {
378    element = $(element).parent();
379    if ($(element).hasClass(class_name)) break;
380  }
381  /*while(pp = $(element).parent().length){
382
383    }*/
384  return element;
385}
386
387function init_job_offers_menu() {
388  $('.seemore')
389    .css({ cursor: 'pointer' })
390    .click(function () {
391      var parent = $(this).parents('div.left_items_container').get(0);
392      $(parent).find('div.hidden').removeClass('hidden');
393      parent = $(this).parents('div').get(0);
394      $(parent).addClass('hidden');
395    });
396  $('.search_submit_link')
397    .css({ cursor: 'pointer' })
398    .click(function () {
399      var id = $(this).attr('rel');
400      $('#' + id).val($(this).text());
401      $('#search_frm').submit();
402    });
403}
404
405/******* DIALOG RELATED ****************/
406
407function updateTips(t) {
408  tips.text(t).effect('highlight', {}, 1500);
409}
410
411function checkLength(o, n, min, max) {
412  if (o.val().length > max || o.val().length < min) {
413    o.addClass('ui-state-error');
414    updateTips('Length of ' + n + ' must be between ' + min + ' and ' + max + '.');
415    return false;
416  }
417  return true;
418}
419
420function checkRegexp(o, regexp, n) {
421  if (!regexp.test(o.val())) {
422    o.addClass('ui-state-error');
423    updateTips(n);
424    return false;
425  }
426  return true;
427}
428
429function init_contacts_form_dialog() {
430  if ($('.contact_login_dialog_open').length) {
431    $('.contact_login_dialog_open').click(function () {
432      alert('You should login to contact the member!');
433      setCookie('after_login_return_url', document.location.href, '', '/');
434      location.href = '/login/';
435      return false;
436    });
437    return;
438  }
439
440  if (!$('#contact_dialog').length) return false;
441
442  $('.contact_dialog_open').click(function () {
443    $('#SRC_ID').val($(this).attr('rel'));
444    $('#SENDER_NAME').val($('#CURRENT_USER_NAME').text());
445    $('#SENDER_EMAIL').val($('#CURRENT_USER_EMAIL').text());
446    $('#COMMENTS').val('');
447    $('#contact_dialog').dialog('open');
448    return false;
449  });
450
451  var name = $('#SENDER_NAME'),
452    email = $('#SENDER_EMAIL'),
453    text = $('#COMMENTS'),
454    //captcha = $("#dialog_captcha"),
455    allFields = $([]).add(name).add(email).add(text); //.add(captcha);
456
457  $('#contact_dialog').dialog({
458    bgiframe: true,
459    autoOpen: false,
460    height: 430,
461    modal: true,
462    buttons: {
463      Submit: function () {
464        var bValid = true;
465        allFields.removeClass('ui-state-error');
466
467        bValid = bValid && checkLength(name, 'Name', 3, 50);
468        bValid = bValid && checkLength(email, 'E-Mail', 6, 80);
469        //bValid = bValid && checkLength(captcha,"Validation Code",5,5);
470        bValid = bValid && checkLength(text, 'Details', 5, 255);
471
472        //bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
473        // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
474        bValid =
475          bValid &&
476          checkRegexp(
477            email,
478            /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,
479            'eg. [email protected] '
480          );
481        /*" ))))*/
482        //bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
483
484        if (bValid) {
485          //$("#post_contact").submit();
486          $(this).dialog('close');
487          $.post('/mail.php', $('#post_contact').serialize(), function (data) {
488            if (data) {
489              $('#post_contact_confirm').html(data);
490              $('#post_contact_confirm').dialog('open');
491            }
492          });
493        }
494      },
495      Cancel: function () {
496        $(this).dialog('close');
497      },
498    },
499    close: function () {
500      allFields.removeClass('ui-state-error');
501    },
502  });
503
504  $('#post_contact_confirm').dialog({
505    bgiframe: true,
506    resizable: false,
507    height: 50,
508    width: 300,
509    autoOpen: false,
510    modal: true,
511    buttons: {
512      OK: function () {
513        $(this).dialog('close');
514      },
515    },
516  });
517}
518
519function init_mega_menu() {
520  if (!$('UL.mega_menu LI').length || typeof $.hoverIntent == 'undefined') return;
521  var mega_menu_Config = {
522    interval: 100,
523    timeout: 100,
524    sensitivity: 4,
525    over: function () {
526      $(this).addClass('hovering');
527    },
528    out: function () {
529      $(this).removeClass('hovering');
530    },
531  };
532  if (typeof $.hoverIntent != 'undefined') $('UL.mega_menu LI').hoverIntent(mega_menu_Config);
533}
534
535function init_calendar_selectors() {
536  if (
537    !$('#calendar_month').length ||
538    !$('#calendar_month_selector').length ||
539    !$('#calendar_year').length ||
540    !$('#calendar_year_selector')
541  )
542    return;
543
544  $('#calendar_month_selector_close').click(function () {
545    $('#calendar_month_selector').hide();
546  });
547
548  $('#calendar_year_selector_close').click(function () {
549    $('#calendar_year_selector').hide();
550  });
551
552  $('#calendar_month').click(function (e) {
553    el = $('#calendar_month_selector');
554    el.css('position', 'absolute');
555    el.css('left', $(this).offset().left);
556    el.css('top', e.pageY - el.height() / 2);
557    el.show();
558  });
559  $('#calendar_year').click(function (e) {
560    el = $('#calendar_year_selector');
561    el.css('position', 'absolute');
562    el.css('left', $(this).offset().left);
563    el.css('top', e.pageY - el.height() / 2);
564    el.show();
565  });
566}
567
568function init_panel_scrollers() {
569  if (!$('div.box_in').length) return;
570  if (typeof $.serialScroll == 'undefined') return;
571  jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
572    return -c * ((t = t / d - 1) * t * t * t - 1) + b;
573  };
574  $('div.box_in').each(function () {
575    var scroll_exclude = typeof $(this).attr('exclude') == 'undefined' ? 3 : $(this).attr('exclude') * 1;
576    var prev_arrow_id =
577      '#' + (typeof $(this).attr('prev_arrow') == 'undefined' ? 'categories_index_prev' : $(this).attr('prev_arrow'));
578    var next_arrow_id =
579      '#' + (typeof $(this).attr('next_arrow') == 'undefined' ? 'categories_index_next' : $(this).attr('next_arrow'));
580    var scroll_step = typeof $(this).attr('step') == 'undefined' ? 4 : $(this).attr('step') * 1;
581    var scroll_duration = typeof $(this).attr('duration') == 'undefined' ? 500 : $(this).attr('duration') * 1;
582    var scroll_direction = typeof $(this).attr('direction') == 'undefined' ? 'x' : $(this).attr('direction');
583    var scroll_cycle = typeof $(this).attr('cycle') == 'undefined' ? false : $(this).attr('cycle') ? true : false;
584    $(this).serialScroll({
585      //target:'.gallery_full_list',
586      items: 'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
587      prev: prev_arrow_id, // Selector to the 'prev' button (absolute!, meaning it's relative to the document)
588      next: next_arrow_id, // Selector to the 'next' button (absolute too)
589      axis: scroll_direction, // The default is 'y' scroll on both ways
590      //navigation:'#greybox_m img.nav_first, #navigation_hidden a, #greybox_m img.nav_last',
591      duration: scroll_duration, // Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
592      force: true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
593      cycle: scroll_cycle, //don't pull back once you reach the end
594      //queue:false,// We scroll on both axes, scroll both at the same time.
595      //event:'click',// On which event to react (click is the default, you probably won't need to specify it)
596      //stop:false,// Each click will stop any previous animations of the target. (false by default)
597      //lock:true, // Ignore events if already animating (true by default)
598      //start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )
599      exclude: scroll_exclude, //Exclude n elements before end
600      step: scroll_step, // How many items to scroll each time ( 1 is the default, no need to specify )
601      //jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
602      //lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
603      //interval:1000, // It's the number of milliseconds to automatically go to the next
604      //constant:true, // constant speed
605
606      onBefore: function (e, elem, $pane, $items, pos) {
607        //those arguments with a $ are jqueryfied, elem isn't.
608        e.preventDefault();
609        if (this.blur) this.blur();
610      },
611      onAfter: function (elem) {
612        //'this' is the element being scrolled ($pane) not jqueryfied
613      },
614    });
615  });
616}
617
618function init_date_pickers() {
619  var $dp = $('.date_picker');
620  if (!$dp.length) return;
621  if (typeof $dp.datepicker == 'undefined') {
622    console.log('Datepicker requires JQuery UI in Main JS.');
623    return;
624  }
625  $dp.datepicker({ showOn: 'button', buttonImage: 'img/show-calendar.gif', buttonImageOnly: true });
626}
627
628function get_date_format() {
629  var format = 'mm-dd-yy';
630  if (
631    $('meta[http-equiv=Content-Type]').attr('content').replace('text/html; charset=', '').toLowerCase() ==
632    'windows-1255'
633  )
634    format = 'dd-mm-yy';
635  return format;
636}
637
638function init_wishlist() {
639  var $wishlist_add_button = $('.add2wishlist');
640  var $wishlist_remove_button = $('.remove_from_wishlist');
641  if (!$wishlist_add_button.length && !$wishlist_remove_button.length) return;
642  $wishlist_add_button.click(function () {
643    tmp = $(this).attr('id').split('-');
644    if (tmp.length < 3) {
645      alert('ID should have 3 parts, e.g. addtowishlist-products-$ID');
646      return false;
647    }
648
649    $('#' + $(this).attr('id') + '-adding-caption').show();
650    $(this).hide();
651
652    var section = $(tmp).get(1);
653
654    $.get(
655      'index.php?' + Math.random(),
656      { section: $(tmp).get(1), ac: 'add2wishlist', ID: $(tmp).get(2) },
657      function (data) {
658        tmp = data.split('-');
659        if (tmp.length > 2 || !$('#add2wishlist-' + section + '-' + $(tmp).get(0) + '-adding-caption').length) {
660          alert('Error: ' + tmp);
661          return;
662        }
663        $('#add2wishlist-' + section + '-' + $(tmp).get(0) + '-adding-caption').hide();
664        if (tmp.length < 2) {
665          $('#add2wishlist-' + section + '-' + $(tmp).get(0) + '-added-caption').show();
666          $('#remove_from_wishlist-' + section + '-' + $(tmp).get(0)).show();
667        } else alert($(tmp).get(1));
668        //$('#'+$(this).attr('id') + '-adding-caption').show();
669      }
670    );
671    return false;
672  });
673  $wishlist_remove_button.click(function () {
674    tmp = $(this).attr('id').split('-');
675    if (tmp.length < 3) {
676      alert('ID should have 3 parts, e.g. remove_from_wishlist-products-$ID');
677      return false;
678    }
679
680    $('#' + $(this).attr('id') + '-removing-caption').show();
681    $(this).hide();
682
683    var section = $(tmp).get(1);
684
685    $.get(
686      'index.php?' + Math.random(),
687      { section: $(tmp).get(1), ac: 'remove_from_wishlist', ID: $(tmp).get(2) },
688      function (data) {
689        tmp = data.split('-');
690        if (
691          tmp.length > 2 ||
692          !$('#remove_from_wishlist-' + section + '-' + $(tmp).get(0) + '-removing-caption').length
693        ) {
694          alert('Error: ' + tmp);
695          return;
696        }
697        $('#remove_from_wishlist-' + section + '-' + $(tmp).get(0) + '-removing-caption').hide();
698        if (tmp.length < 2) {
699          $('#remove_from_wishlist-' + section + '-' + $(tmp).get(0) + '-removed-caption').show();
700          $('#add2wishlist-' + section + '-' + $(tmp).get(0)).show();
701        } else alert($(tmp).get(1));
702        //$('#'+$(this).attr('id') + '-adding-caption').show();
703      }
704    );
705    return false;
706  });
707}
708
709function validate_product_quantity(obj) {
710  //Let's get parameters for validation
711  var id = $(obj).get_part(0);
712  if (!id) {
713    alert(
714      'An object with class product_quantity must have an ID that look like: {$ID}:{$PRICE_STR}:{$QUANTITY_BREAKS}:{$MIN_QUANTITY}:{$MAX_QUANTITY}'
715    );
716    return false; //If id is empty, it's an HTML programmer error.
717  }
718  var price = $(obj).get_part(1);
719  var q_breaks = $(obj).get_part(2);
720  var min_q = $(obj).get_part(3);
721  var max_q = $(obj).get_part(4);
722
723  //We're gonna need amaximal integer number. Let's get it by a bit shifting of -1 to the right.
724  var maxInt = -1 >>> 1;
725
726  //Let's make sure all parameter are fine and let's set the defaults
727  price = !price || isNaN(price) || price < 0 ? 0 : price;
728  q_breaks = isNaN(q_breaks) || q_breaks < 1 ? 1 : Math.round(q_breaks);
729  min_q = isNaN(min_q) || min_q < 1 ? 1 : Math.round(min_q);
730  max_q = isNaN(max_q) || max_q < min_q ? maxInt : Math.round(max_q);
731
732  //Let's make the error messages block in case it's missing
733  if (!$('DIV#ERR_' + id).length)
734    $($(obj).parents('*').get(0)).prepend(
735      '<div class="qty_err_message error_mess" id="ERR_' +
736        id +
737        '"> \n' +
738        '<span class="qty_is_not_number_error">The value of "Quantity" field must be numeric</span>\n' +
739        '<span class="qty_q_breaks_error">This item must be ordered in multiplies of ' +
740        q_breaks +
741        '</span>\n' +
742        '<span class="qty_min_q_error">Minimal quantity for this product is ' +
743        min_q +
744        '</span>\n' +
745        '<span class="qty_max_q_error">Maximal quantity for this product is ' +
746        max_q +
747        '</span>\n' +
748        '</div>'
749    );
750  //Let's hide all the errors by default.
751  $('DIV#ERR_' + id).hide();
752  $('DIV#ERR_' + id + ' SPAN').hide();
753  $(obj).removeClass('mandatory_selected');
754
755  //Let's get something to validate. Jsut in case, you know :-)
756  var q_value = $(obj).val();
757
758  //This var will contain a selector to hilight once we find errors
759  //If no errors found the var should remain empty
760  var erros2show = '';
761
762  if (isNaN(q_value)) {
763    erros2show += ', DIV#ERR_' + id + ' SPAN.qty_is_not_number_error ';
764    q_value = 0;
765  }
766
767  q_value = Math.round(q_value);
768  //if the quantity is numeric, let's see what we've got here...
769  if (erros2show == '' && q_value > 0) {
770    //Let's round the quantity up, since fractions are not allowed anyway.
771    if (q_breaks > 1 && Number($(obj).val()) % q_breaks != 0) {
772      erros2show += ', DIV#ERR_' + id + ' SPAN.qty_q_breaks_error ';
773      q_value = q_breaks * Math.round(q_value / q_breaks);
774      if (q_value == 0) q_value = q_breaks;
775    }
776
777    if (q_value < min_q) {
778      erros2show += ', DIV#ERR_' + id + ' SPAN.qty_min_q_error ';
779      q_value = min_q;
780    }
781
782    if (q_value > max_q) {
783      erros2show += ', DIV#ERR_' + id + ' SPAN.qty_max_q_error ';
784      q_value = max_q;
785    }
786  }
787
788  //Once we validated everything, let's assign corrected q_value and flash error messages if needed:
789  $(obj).val(q_value);
790  if (erros2show != '') {
791    $('DIV#ERR_' + id + ', ' + erros2show).show();
792    $(obj).addClass('mandatory_selected');
793  }
794
795  if ($('#PRICE_' + id).length > 0) {
796    var total = price * (q_value < 1 ? 1 : q_value);
797    $('#PRICE_' + id).html(total.toFixed(2));
798  }
799  if ($(obj).parents('FORM').length && $($(obj).parents('FORM').get(0)).hasClass('validate4selected_items_failed'))
800    validate_add2cart_form4selected_items($(obj).parents('FORM').get(0));
801  return erros2show == '';
802}
803
804function validate_add2cart_form4selected_items(obj) {
805  var is_add2cart_form = $(obj).find("INPUT[name='ac'][value='addtocart']").length > 0;
806  if (!is_add2cart_form) return true;
807
808  $(obj).find('.form_err_message, .form_err_message span').hide();
809  $(obj).removeClass('validate4selected_items_failed');
810  var products = 0;
811  $(obj)
812    .find('.product_quantity')
813    .each(function (i, object) {
814      if ($(object).val() > 0) products++;
815    });
816  if (!products) {
817    if ($(obj).find('.form_err_message').length < 1)
818      $(obj)
819        .find('input[type=submit], input[type=image]')
820        .before(
821          '<div class="form_err_message error_mess" align="center"><span class="form_field_error">Please, enter quantity for at least one product<br></span></div>'
822        );
823    $(obj).find('.form_err_message, .form_err_message span').show();
824    $(obj).addClass('validate4selected_items_failed');
825    return false;
826  }
827  return true;
828}
829
830function init_product_inventory_check() {
831  if (!$('.product_check_inventory').length) return;
832  $('.product_check_inventory').click(function () {
833    $('#INVENTORY_ERROR_MESSAGE').hide();
834    var prod_id = $(this).attr('PROD_ID');
835    if (prod_id == null) {
836      alert('Error: PROD_ID attribute is missing while product_check_inventory class is assigned');
837      return false;
838    }
839    var quantity_field_id = $(this).attr('QUANTITY_FIELD_ID');
840    if (quantity_field_id == null) {
841      alert('Error: QUANTITY_FIELD_ID attribute is missing while product_check_inventory class is assigned');
842      return false;
843    }
844    var q = 1;
845    quantity_field_id = quantity_field_id.replace(/(:|\.)/g, '\\$1');
846    if ($('#' + quantity_field_id).length) q = $('#' + quantity_field_id).val();
847
848    if (typeof sitehome == 'undefined') sitehome = '/';
849    var res = true;
850    jQuery.ajax({
851      url: sitehome + '?section=produts&ac=inventory_verify&prod_id=' + prod_id + '&q=' + q,
852      success: function (result) {
853        if (result != 1) {
854          $('#INVENTORY_ERROR_MESSAGE').show();
855          return (res = false);
856        }
857      },
858      async: false,
859    });
860    return res;
861  });
862}
863
864function init_product_quantity() {
865  $('FORM:has(INPUT.product_quantity), FORM:has(SELECT.product_quantity)').submit(function () {
866    if (validate_add2cart_form4selected_items($(this).get(0))) {
867      $(this).find('.qty_err_message').hide();
868      $(this).find('.product_quantity').removeClass('mandatory_selected');
869      return true;
870    }
871    return false;
872  });
873  $('FORM INPUT.product_quantity, FORM SELECT.product_quantity')
874    .blur(function () {
875      validate_product_quantity($(this).get(0));
876    })
877    .keypress(function (event) {
878      if (event.keyCode == 13) {
879        if (!validate_product_quantity($(this).get(0))) event.returnValue = false;
880        else if (this.form) this.form.submit();
881      }
882    });
883
884  $('FORM SELECT.product_quantity').change(function () {
885    validate_product_quantity($(this).get(0));
886  });
887
888  $('FORM .product_buy_button').click(function () {
889    var id = $(this).get_part(0);
890    if (!id) {
891      alert(
892        'An object with class product_quantity must have an ID that look like: {$ID}:{$PRICE_STR}:{$QUANTITY_BREAKS}:{$MIN_QUANTITY}:{$MAX_QUANTITY}'
893      );
894      return false; //If id is empty, it's an HTML programmer error.
895    }
896    var price = $(this).get_part(1);
897    var q_breaks = $(this).get_part(2);
898    var min_q = $(this).get_part(3);
899    var max_q = $(this).get_part(4);
900    var q_id = id + ':' + price + ':' + q_breaks + ':' + min_q + ':' + max_q;
901    var q_id_esc = q_id.replace(/(:|\.)/g, '\\$1');
902
903    // In some cases (e.g. pmember products index) duplicate ID-s might exist
904    if ($(".product_quantity[ID='" + q_id_esc + "']").length > 1) {
905      var parent_form = $(this).attr('form');
906      if (
907        $(parent_form).length &&
908        $(parent_form).find('#' + q_id_esc).length == 1 &&
909        $($(parent_form).find('#' + q_id_esc)).val() == '0'
910      ) {
911        q_breaks = isNaN(q_breaks) || q_breaks < 1 ? 1 : Math.round(q_breaks);
912        min_q = isNaN(min_q) || min_q < 1 ? 1 : Math.round(min_q);
913        $($(parent_form).find('#' + q_id_esc)).val(q_breaks > min_q ? q_breaks : min_q);
914        return;
915      }
916    }
917
918    if (!$('#' + q_id_esc).length) {
919      alert('Buy button error: corresponding quantity field with ID = ' + q_id_esc + ' is not found');
920      return false;
921    }
922    if ($('#' + q_id_esc).val() == '0') {
923      q_breaks = isNaN(q_breaks) || q_breaks < 1 ? 1 : Math.round(q_breaks);
924      min_q = isNaN(min_q) || min_q < 1 ? 1 : Math.round(min_q);
925      $('#' + q_id_esc).val(q_breaks > min_q ? q_breaks : min_q);
926    }
927  });
928}
929
930function init_limited_choice() {
931  if (!$('input[type=checkbox].limited_choice').length) return;
932  if (!$('#limited_choice_msgbox').length) {
933    $('body').append(
934      '<div class="msgBox" id="limited_choice_msgbox" title="Warning!" width="300" height="100" style="display:none;">You can choose only <span id="limited_choice_limit">1</span> items</div>'
935    );
936    $('#limited_choice_msgbox').dialog({
937      height: 100,
938      width: 300,
939      autoOpen: false,
940    });
941  }
942  $('input[type=checkbox].limited_choice').click(function () {
943    var classname = $(this).get_part(0, 'rel');
944    var length = $(this).get_part(1, 'rel');
945    var id = $(this).get_part(2, 'rel');
946    if (!id || !$('#' + id).length) id = 'limited_choice_msgbox';
947    if ($('.' + classname + ':checked').length > length) {
948      $('#limited_choice_limit').html(length);
949      $('#' + id).dialog('open');
950      return false;
951    }
952  });
953}
954
955function homeSlider(opt) {
956  var options = {
957    parentItem: opt.parent,
958    childItems: opt.children,
959    next: opt.next,
960    prev: opt.prev,
961    speed: opt.speed,
962  };
963  var itemWidth,
964    positionCount = 1;
965  itemWidth = $(options.childItems).width();
966  $(options.next).click(function () {
967    if (positionCount < $(options.childItems).length - 1) {
968      $(options.parentItem).animate({ left: '-=' + itemWidth + 'px' }, options.speed);
969      positionCount++;
970    }
971  });
972  $(options.prev).click(function () {
973    if (positionCount > 1) {
974      $(options.parentItem).animate({ left: '+=' + itemWidth + 'px' }, options.speed);
975      positionCount--;
976    }
977  });
978}
979
980function init_new_contact_forms() {
981  // Please note that your contact form or registration form should have one of the following classes:
982  var selector4forms = 'FORM.contact_form, FORM.registration_form, FORM.comment_form';
983  var $forms2use = $(selector4forms);
984  if (!$forms2use.length) {
985    console.info('[init_new_contact_forms] Notice: No contact forms on this page detected. Is it right?');
986    return false;
987  }
988  if (typeof $.fn.ajaxForm === 'undefined') {
989    console.error(
990      "[init_new_contact_forms] ERROR: you're trying to use contact forms, but jquery.form.js is not included anywhere in inc_top_scripts.inc"
991    );
992    return false;
993  }
994  if (typeof validate_any_form !== 'function') {
995    console.error(
996      "[init_new_contact_forms] ERROR: you're trying to use contact forms, but validate_any_form() is not a function"
997    );
998    return false;
999  }
1000
1001  $forms2use.each(function () {
1002    if (!$(this).is('[data-json]')) {
1003      console.info('[init_new_contact_forms] INFO: form has not data-json attribute. Is it right?', this);
1004    }
1005  });
1006
1007  $forms2use.find('[data-other!=""][data-other]').change(function () {
1008    var $t = $(this);
1009    var OTHER_ID = $t.data('other');
1010    var other_val = $t.data('other_val') ? $t.data('other_val') : 'Other';
1011    if ($t.val() == other_val) {
1012      $('#' + OTHER_ID + '_DIV').show();
1013      $('#' + OTHER_ID)
1014        .show()
1015        .removeAttr('disabled');
1016    } else {
1017      $('#' + OTHER_ID + '_DIV').hide();
1018      $('#' + OTHER_ID)
1019        .hide()
1020        .attr('disabled', 'disabled');
1021    }
1022  });
1023
1024  function showResponse(responseText, statusText, xhr, $form) {
1025    unlock_form($form);
1026    var is_json = $form.data('json');
1027    var resp_status = is_json ? responseText.res : responseText;
1028
1029    //Hookup that helps defining action in case a custom action is required
1030    //Please note: it is preferable not to use this one, but use the two other events below
1031    if (typeof on_contactform_responce === 'function') {
1032      if (on_contactform_responce(responseText, statusText, xhr, $form, is_json)) {
1033        return true;
1034      }
1035    }
1036
1037    if (resp_status == 'OK') {
1038      try {
1039        /**
1040         * Sending event to Google Analytics
1041         * data-ga-event-category="contact_form" data-ga-event-action="submit" data-ga-event-label="CONTACT1"
1042         * data-ga-event-value=""
1043         */
1044        var formData = $form.data();
1045        if (formData.gaEventCategory && formData.gaEventAction) {
1046          if (typeof ga !== 'function') {
1047            console.error(
1048              '[init_new_contact_forms] ERROR: Google analytics data-attributes installed, but ga tracker not found'
1049            );
1050          } else {
1051            console.log(
1052              '[init_new_contact_forms] Sending GA event... ga("send", "event", "' +
1053                formData.gaEventCategory +
1054                '", "' +
1055                formData.gaEventLabel +
1056                '", "' +
1057                formData.gaEventValue +
1058                '")'
1059            );
1060            ga(
1061              'send',
1062              'event',
1063              formData.gaEventCategory,
1064              formData.gaEventAction,
1065              formData.gaEventLabel,
1066              formData.gaEventValue
1067            );
1068          }
1069        }
1070      } catch (e) {
1071        console.error('[init_new_contact_forms] EXCEPTION: ', e);
1072      }
1073
1074      // Hookup that helps defining action in case a custom action is required upon form successful submisison
1075      if (typeof on_contactform_submitted === 'function') {
1076        if (on_contactform_submitted(responseText, statusText, xhr, $form)) {
1077          return true;
1078        }
1079      }
1080
1081      if ($form.find('.ajax_next_url').length && $form.find('.ajax_next_url').text() !== '') {
1082        document.location = $form.find('.ajax_next_url').text();
1083        return true;
1084      }
1085
1086      var $next_section = $form.find('input[name=next_section]');
1087      var next_section_value = 'contact_us_thanks';
1088      if ($next_section.length) {
1089        next_section_value = $next_section.val();
1090      }
1091      document.location = '/cms/' + next_section_value + '/';
1092      return true;
1093    }
1094
1095    var default_errors = {};
1096    default_errors.reg_err_code_LOGIN_NOT_UNIQUE = 'Login is not unique';
1097    var error_message = is_json ? responseText.error : responseText;
1098    error_message = $.trim(error_message);
1099
1100    //Hookup that helps defining action in case a custom action is required upon form successful submisison
1101    if (typeof on_contactform_error === 'function') {
1102      if (on_contactform_error(error_message, statusText, xhr, $form)) {
1103        return true;
1104      }
1105    }
1106
1107    if (typeof default_errors[error_message] !== 'undefined') {
1108      error_message = default_errors[error_message];
1109    }
1110    var $ajax_errors = $form.find('.ajax_errors');
1111    if (!$ajax_errors.length) {
1112      alert(error_message);
1113      return false;
1114    }
1115    $ajax_errors.show().html(error_message);
1116    return false;
1117  }
1118
1119  function form_locked($form) {
1120    return $form.data('lock') ? 1 : 0;
1121  }
1122
1123  function lock_form($form) {
1124    $form.data('lock', 1);
1125  }
1126
1127  function unlock_form($form) {
1128    $form.data('lock', 0);
1129  }
1130
1131  $(document).on('submit', selector4forms, function (e) {
1132    var $form = $(this);
1133
1134    if (form_locked($form)) {
1135      e.preventDefault();
1136      return false;
1137    }
1138
1139    lock_form($form);
1140
1141    var $ajax_errors = $form.find('.ajax_errors');
1142
1143    if ($ajax_errors.length) {
1144      $ajax_errors.hide().html('');
1145    }
1146    if (!validate_any_form($form.get(0))) {
1147      unlock_form($form);
1148      return false;
1149    }
1150
1151    var use_JSON = $form.data('json');
1152    if (typeof sitehome === 'undefined') {
1153      var sitehome = '/cms/';
1154    }
1155    var url4code = sitehome + '?section=contact_form&ac=ajax_code&rand=' + (use_JSON ? '&json=1' : '');
1156
1157    var dataType = use_JSON ? 'json' : null;
1158    jQuery.ajax({
1159      url: url4code,
1160      type: 'GET',
1161      cache: false,
1162      dataType: dataType,
1163      success: function (result) {
1164        if (use_JSON) {
1165          $form.append(result.code_field + result.session_fields);
1166        } else {
1167          $form.append(result);
1168        }
1169
1170        // Submit form
1171        $form.ajaxSubmit({
1172          cache: false,
1173          dataType: dataType,
1174          data: {
1175            confirm_ajax: 1,
1176            json: use_JSON ? 1 : 0,
1177          },
1178          success: showResponse,
1179          error: function (jqXHR, textStatus, errorThrown) {
1180            unlock_form($form);
1181            console.error('[init_new_contact_forms] ERROR while submit form: ', jqXHR, textStatus, errorThrown);
1182          },
1183        });
1184      },
1185      error: function (jqXHR, textStatus, errorThrown) {
1186        unlock_form($form);
1187        console.error('[init_new_contact_forms] ERROR while get session fields: ', jqXHR, textStatus, errorThrown);
1188      },
1189    });
1190    return false;
1191  });
1192}
1193
1194function init_login_json() {
1195  var $login_btn = $('#main_login_dialog_submit_btn');
1196  if (!$login_btn.length) return;
1197
1198  var $login_dialog = $login_btn.closest('.modal');
1199
1200  $login_dialog.on('hidden.bs.modal', function (e) {
1201    $login_dialog.find('.error_mess').hide();
1202  });
1203
1204  var $modal_title = $login_dialog.find('.modal-title');
1205
1206  var login_fom_id = $login_btn.data('main_login_form');
1207  if (!login_fom_id) login_fom_id = 'main_login_form';
1208  var $login_form = $('#' + login_fom_id);
1209  if (!$login_form) log('Error: Login button exists, but login form is not found');
1210  if (typeof $login_form.ajaxForm == 'undefined') {
1211    log(
1212      "main.js ERROR: you're trying to use login form, but jquery.form.js is not included anywhere in inc_top_scripts.inc "
1213    );
1214    return false;
1215  }
1216
1217  var $login_forgot_pass = $('.login_forgot_pass');
1218  var $login_login = $('.login_login');
1219  var $forgot_pass_btn = $('#main_forgot_pass_submit_btn');
1220  var $forgot_form = $('#forgot_form');
1221
1222  function process_login_responce(data) {
1223    if (data['res'] == 'OK') {
1224      if (data['next_url_recommended'] != '') {
1225        documant.location = data['next_url_recommended'];
1226        return;
1227      }
1228      var $ajax_url = $login_form.find('.ajax_next_url');
1229      if ($ajax_url.length && $ajax_url.text() != '') {
1230        document.location = $ajax_url.text();
1231        return true;
1232      }
1233      //alert(data['USER_DATA']['LNAME']);
1234      if (typeof data.WASOID != 'undefined' && typeof data.WASUID != 'undefined') {
1235        setCookie('WASOID', data.WASOID, '', '/');
1236        setCookie('WASUID', data.WASUID, '', '/');
1237      }
1238
1239      window.location.reload();
1240      return;
1241    }
1242
1243    if (data['error'] != '') {
1244      $('.error_mess').hide();
1245      $('.form_err_message').removeClass('hidden').show();
1246      $login_form
1247        .find('.' + data['error'])
1248        .removeClass('hidden')
1249        .show();
1250    }
1251  }
1252
1253  function process_forgot_responce(data) {
1254    function show_error(error_class, $form_id) {
1255      if ($form_id) {
1256        $form_id.find('.error_mess').hide();
1257        $form_id.find('.form_err_message').removeClass('hidden').show();
1258        $form_id
1259          .find('.' + error_class)
1260          .removeClass('hidden')
1261          .show();
1262        return;
1263      }
1264      console.log('process_forgot_responce(data)');
1265      $forgot_form.find('.error_mess').hide();
1266      $forgot_form.find('.form_err_message').removeClass('hidden').show();
1267      $forgot_form
1268        .find('.' + error_class)
1269        .removeClass('hidden')
1270        .show();
1271    }
1272
1273    if (data['res'] == 'OK') {
1274      if (data['next_url_recommended'] != '') {
1275        documant.location = data['next_url_recommended'];
1276        return;
1277      }
1278      var $ajax_url = $forgot_form.find('.ajax_next_url');
1279      if ($ajax_url.length && $ajax_url.text() != '') {
1280        document.location = $ajax_url.text();
1281        return true;
1282      }
1283      //alert(data['USER_DATA']['LNAME']);
1284      $login_form.find('.email').val(data['EMAIL']);
1285      $login_login.click();
1286      show_error('password_reset', $('#main_login_form'));
1287      return;
1288    }
1289    if (data['error'] != '') show_error(data['error']);
1290  }
1291
1292  $login_login.click(function () {
1293    $('.forgot_pass_related').hide();
1294    $('.login_related').show();
1295    $modal_title.html($modal_title.data('login_title'));
1296    return false;
1297  });
1298
1299  $login_forgot_pass.click(function () {
1300    $forgot_form.find('INPUT.email').val($login_form.find('INPUT.email').val());
1301    $('.login_related').hide();
1302    $('.forgot_pass_related').show();
1303    $modal_title.html($modal_title.data('forgot_title'));
1304    return false;
1305  });
1306
1307  $login_btn.click(function () {
1308    $('.error_mess').hide();
1309    if (!validate_any_form($login_form.get(0))) return false;
1310    $login_form.ajaxSubmit({
1311      dataType: 'json',
1312      success: process_login_responce,
1313      data: { json: 1 },
1314    });
1315    return false;
1316  });
1317
1318  $forgot_pass_btn.click(function () {
1319    $('.error_mess').hide();
1320    if (!validate_any_form($forgot_form.get(0))) return false;
1321    $forgot_form.ajaxSubmit({
1322      dataType: 'json',
1323      success: process_forgot_responce,
1324      data: { json: 1 },
1325    });
1326    return false;
1327  });
1328
1329  $login_dialog.on('show.bs.modal', function (event) {
1330    var button = $(event.relatedTarget); // Button that triggered the modal
1331    //var registration = button.data('registration') // Extract info from data-* attributes
1332    var custom_title = button.data('custom_title');
1333    var forgot_active = button.data('forgot');
1334    var title2use = custom_title ? custom_title : '';
1335
1336    if (forgot_active) {
1337      $login_dialog.find('.login_related').hide();
1338      $login_dialog.find('.forgot_pass_related').show();
1339      title2use = title2use ? title2use : $modal_title.data('forgot_title');
1340      $modal_title.html(title2use);
1341      return;
1342    }
1343    $login_dialog.find('.login_related').show();
1344    $login_dialog.find('.forgot_pass_related').hide();
1345    title2use = title2use ? title2use : $modal_title.data('login_title');
1346    $modal_title.html(title2use);
1347  });
1348}
1349
1350function init_review() {
1351  //debugger;
1352  let $piker_spans = $('DIV#RATING_PICKER span');
1353  if (!$piker_spans.length) return;
1354  let $item_rating = $('#ITEM_RATING');
1355  if (!$item_rating.length) $item_rating = $('#COMMENT_ITEM_RATING');
1356
1357  function class4rating(class_name, curr_rating) {
1358    $piker_spans.each(function () {
1359      var $obj = $(this);
1360      var rate = $obj.attr('rate');
1361      if (rate <= curr_rating) {
1362        $obj.addClass(class_name);
1363        return;
1364      }
1365      $obj.removeClass(class_name);
1366    });
1367  }
1368
1369  $piker_spans
1370    .mouseover(function () {
1371      $piker_spans.removeClass('selected');
1372      class4rating('o-act', $(this).attr('rate'));
1373    })
1374    .mouseout(function () {
1375      $piker_spans.removeClass('o-act');
1376      class4rating('selected', $item_rating.val());
1377    })
1378    .click(function () {
1379      let curr_rating = $(this).attr('rate');
1380      class4rating('selected', curr_rating);
1381      $item_rating.val(curr_rating);
1382    });
1383}
1384
1385function init_videojs() {
1386  if (typeof _V_ == 'undefined') return;
1387  if (!$('#player').length) return;
1388  _V_('player').ready(function () {
1389    var player = this;
1390
1391    log(player.currentTime());
1392
1393    player.addEvent('play', function (e) {
1394      if (player.currentTime() == 0) {
1395        log('Playback started!');
1396      } else {
1397        log('Playback resumed!');
1398      }
1399    });
1400
1401    player.addEvent('ended', function (e) {
1402      log('Playback ended!');
1403    });
1404  });
1405}
1406function init_dialog_st() {
1407  if ($('.dialog_st').length) console.log('dialog_st is depricated...');
1408}
1409
1410function init_sorting() {
1411  var $sorting_form = $('.sorting_form');
1412  if (!$sorting_form.length) return;
1413  var $sorting_dd = $('.sorting_swith');
1414  if (!$($sorting_dd.length)) return;
1415  var $sort_dir = $('.sorting_dir');
1416  $sorting_dd.change(function () {
1417    if ($sort_dir.length)
1418      $sorting_dd.val() == '' ? $sort_dir.hide().addClass('hidden') : $sort_dir.show().removeClass('hidden');
1419    $sorting_form.submit();
1420  });
1421  var sort = $sorting_dd.data('sort');
1422  var sort_dir = $sorting_dd.data('dir');
1423  $sorting_dd.val(sort);
1424  if ($sort_dir.length) {
1425    $sort_dir.val(sort_dir == '' ? 'a' : sort_dir);
1426    $sorting_dd.val() == '' ? $sort_dir.hide().addClass('hidden') : $sort_dir.show().removeClass('hidden');
1427  }
1428  $sort_dir.change(function () {
1429    $sorting_form.submit();
1430  });
1431}
1432
1433function init_viewcart() {
1434  var $cart = $('FORM#cart, FORM.viewcart');
1435  if (!$cart.length) return;
1436  var cart_buttons_selector = '.checkout_button, .update_button, .clear_button, .viewcart_action_button';
1437  //Following validates if some essential classes are missing from the view cart form
1438  $cart.each(function () {
1439    var $this = $(this);
1440    if (!$this.find('.wc_action').length) log('Error: action hidden field should have class "wc_action"');
1441    if (!$this.find('.viewcart_next_section').length)
1442      log(
1443        'Error: Next section hidden field of the view cart form should have a field next_section with class "viewcart_next_section"'
1444      );
1445    if (!$this.find(cart_buttons_selector).length) log('Warning: view cart form has no controls. Is it on purpose?"');
1446  });
1447  //Instead of using "live" we use "on" to track the clicks to comply with AJAX
1448  $cart.parent().on('click', cart_buttons_selector, function () {
1449    var $t = $(this);
1450    var $cart = $t.closest('form');
1451    var $wc_ac = $cart.find('.wc_action');
1452    var $viewcart_next_section = $cart.find('.viewcart_next_section');
1453    //next section could be set for each button as data-next_section="<next section>"
1454    if ($t.data('next_section')) $viewcart_next_section.val($t.data('next_section'));
1455    else $viewcart_next_section.val($t.hasClass('checkout_button') ? 'checkout' : 'viewcart');
1456    //action could be set for each button as data-ac="<action>"
1457    if ($t.data('ac')) $wc_ac.val($t.data('ac'));
1458    else $wc_ac.val($t.hasClass('clear_button') ? 'clear_cart' : 'updatecart');
1459
1460    //If the <form ..> tag contains data-ajax="1" then we call AJAX using js/jquery.form.js
1461    //Latest version of shared/cart.inc is required too (!) as responce is in JSON format.
1462    if ($t.data('ajax')) {
1463      if (typeof $cart.ajaxSubmit == 'undefined') {
1464        log('jquery.form.js  is missing from inc_top_scripts.html, so the form cannot use AJAX');
1465      }
1466      var $ajax_target = $t.data('ajax_target') ? $($t.data('ajax_target')) : $cart.parent();
1467      var ex_params = $('.module_params').text();
1468      ex_params = ex_params ? decodeURIComponent(ex_params) : '';
1469      var $cart_parent = $cart.parent();
1470      $cart_parent.addClass('loading');
1471      $cart.ajaxSubmit({
1472        dataType: 'json',
1473        success: function (response) {
1474          var params = '';
1475          if (typeof response.messages != 'undefined') {
1476            for (var i in response.messages) params += '&params[' + i + ']=' + response.messages[i];
1477          }
1478
1479          $.get('?ac=list&name=viewcart' + ex_params + params, function (data) {
1480            $ajax_target.html(data);
1481            if (typeof on_cart_ajax_loaded != 'undefined') on_cart_ajax_loaded($cart, $ajax_target);
1482            $cart_parent.removeClass('loading');
1483          });
1484        },
1485        data: { JSON: 1 },
1486      });
1487
1488      return false;
1489    }
1490    $cart.trigger('submit');
1491  });
1492}
1493
1494function init_login_and_account_on_checkout() {
1495  var $billing_wrapper = $('.billing-email-wrapper');
1496  if (!$billing_wrapper.length) return;
1497  var $billing_wrapper_input = $('.billing-email-wrapper input');
1498  var $checkout_block = $('.checkout-account-block');
1499
1500  $('.action-checkout').click(function (e) {
1501    e.preventDefault();
1502
1503    $('.checkout-account-block, .checkout-checkout-block').css({ maxHeight: 0 });
1504
1505    if ($(this).hasClass('checkout_create_acc_link')) {
1506      $checkout_block.css({ maxHeight: 10000 });
1507      $checkout_block.find('INPUT').prop('disabled', false);
1508    }
1509
1510    $billing_wrapper.hide();
1511    $billing_wrapper_input.prop('disabled', true);
1512  });
1513
1514  $billing_wrapper_input.blur(function () {
1515    var email = $(this).val();
1516    if (email == '') return;
1517    $('#acc_already_exists_prompt').hide();
1518    $.getJSON('/cms/?section=login&ac=exists&DATA[ACC_TPY]=CUSTOMERS&DATA[EMAIL]=' + email, function (data) {
1519      if (data['res'] != 'OK') return;
1520      $('#acc_already_exists_prompt').removeClass('hidden').show();
1521    });
1522  });
1523
1524  $('.checkout-block .title_background_checkout .close-block').click(function () {
1525    $(this).closest('.checkout-block').css({ maxHeight: 0 });
1526
1527    $billing_wrapper.show();
1528    $billing_wrapper_input.prop('disabled', false);
1529    $checkout_block.find('INPUT').prop('disabled', true);
1530  });
1531}
1532
1533function init_pop_ups() {
1534  var $dialogs = $('.video_modals');
1535  if (!$dialogs.length) return;
1536
1537  $dialogs.on('show.bs.modal', function (event) {
1538    //var button = $(event.relatedTarget) // Button that triggered the modal
1539    var $t = $(this);
1540    if ($t.data('video_ref') != '') $t.find('iframe').attr('src', $t.data('video_ref'));
1541    if ($t.find('.video-js').length) $t.find('.video-js')[0].player.play();
1542  });
1543
1544  $dialogs.on('hidden.bs.modal', function (event) {
1545    //var button = $(event.relatedTarget) // Button that triggered the modal
1546    var $t = $(this);
1547    $t.data('video_ref', $t.find('iframe').attr('src'));
1548    $t.find('iframe').attr('src', '');
1549    if ($t.find('.video-js').length) $t.find('.video-js')[0].player.pause();
1550  });
1551}
1552
1553/**
1554 * Function init_masonry_imagesloaded
1555 * @author Anton Vanin
1556 * @version 1.0.0
1557 * Unloaded images can throw off Masonry layouts and cause item elements to overlap
1558 */
1559function init_masonry_imagesloaded() {
1560  var masonryItem = $('.js-masonry');
1561
1562  if (!masonryItem.length) {
1563    return;
1564  }
1565
1566  if (!jQuery.fn.masonry) {
1567    console.error('[init_masonry_imagesloaded] Couldn`t find masonry.pkgd.min.js library!');
1568    return;
1569  }
1570
1571  if (!jQuery.fn.imagesLoaded) {
1572    console.error('[init_masonry_imagesloaded] Couldn`t find imagesloaded.pkgd.min.js library!');
1573    return;
1574  }
1575
1576  masonryItem.imagesLoaded().progress(function () {
1577    masonryItem.masonry('layout');
1578  });
1579}
1580
1581function submit_sku_on_viewcart(sku, skip_submit) {
1582  var $corresponding_hidden = $('.milk_input[data-sku=' + sku + ']');
1583  if (!$corresponding_hidden) alert('Corresponding hidden field is missing');
1584  $corresponding_hidden.removeAttr('disabled');
1585
1586  if (skip_submit) return;
1587
1588  var $form = $corresponding_hidden.parents('form');
1589
1590  $(
1591    '<div class="preloader__fullscreen"><div class="preloader__fullscreen__center"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i></div></div>'
1592  ).appendTo('.page_viewcart');
1593
1594  $form.ajaxSubmit({
1595    cache: false,
1596    success: function () {
1597      $.get('/?section=viewcart&ac=list&name=viewcart', function (data) {
1598        /*$('#view_cart_wrapper').html(data);
1599                init_viewcart();
1600                init_viewcart_custom();
1601                $('.preloader__fullscreen').remove();
1602                $('.modal-backdrop').remove();*/
1603        location.reload();
1604      });
1605    },
1606    error: function (jqXHR, textStatus, errorThrown) {
1607      console.error('[init_new_contact_forms] ERROR while submit form: ', jqXHR, textStatus, errorThrown);
1608      $('.preloader__fullscreen').remove();
1609      $('.modal-backdrop').remove();
1610      location.reload();
1611    },
1612  });
1613}
1614
1615function init_viewcart_custom() {
1616  var $cart = $('#cart');
1617  if (!$cart.length) return;
1618
1619  var $milk_buttons = $('.milk-btn');
1620  if (!$milk_buttons.length) return;
1621
1622  $milk_buttons.off().on('click', function () {
1623    var $t = $(this);
1624    if ($t.data('bs-target')) {
1625      var $modal = $($t.data('bs-target'));
1626      if ($modal.length) {
1627        $modal.on('click', '.btn', function () {
1628          if ($(this).data('sku')) submit_sku_on_viewcart($(this).data('sku'), true);
1629          submit_sku_on_viewcart($t.data('sku'));
1630        });
1631        $modal.modal();
1632        return;
1633      }
1634    }
1635    submit_sku_on_viewcart($t.data('sku'));
1636    return false;
1637  });
1638}
1639
1640function init_country_state_block(prefix) {
1641  var class_prefix = prefix != '' ? prefix.toLowerCase() + '_' : '';
1642  var $country_field = $('FORM #' + prefix + 'COUNTRY');
1643  var $state_fields = $('.' + class_prefix + 'state');
1644  var $state_captions = $('.' + class_prefix + 'state_caption');
1645  var $alt_state = $('#' + prefix + 'ALT_STATE');
1646
1647  if ($country_field.length != 1) return;
1648  $country_field.change(function () {
1649    var this_val = $(this).val();
1650    var $this_state = $('#' + prefix + 'STATE_' + this_val);
1651
1652    $state_fields.hide().removeClass('mandatory').removeClass('mandatory_selected').attr('disabled', 'disabled');
1653    $state_fields.attr('disabled', 'disabled');
1654    $state_captions.hide();
1655
1656    if ($this_state.length) {
1657      var $this_caption = $('#' + prefix + 'STATE_CAPTION_' + this_val);
1658      $this_state.addClass('mandatory').show().attr('disabled', false).removeClass('hidden');
1659      if ($this_state.hasClass('search')) $this_state.removeClass('mandatory');
1660      $this_caption.show().removeClass('hidden');
1661      return;
1662    }
1663    if (!$alt_state.length) return;
1664    $alt_state.show().attr('disabled', false);
1665    $('#' + prefix + 'STATE_CAPTION_ALT')
1666      .show()
1667      .removeClass('hidden');
1668  });
1669  $country_field.trigger('change');
1670}
1671
1672function init_adrecom_search_field() {
1673  var $toggle = $('.js-adrecom-search-toggle');
1674  var $form = $('.js-searchform');
1675  if (!$toggle.length) {
1676    return;
1677  }
1678
1679  var isSearchActive = function () {
1680    return $form.hasClass('active');
1681  };
1682  var showForm = function () {
1683    $toggle.addClass('active');
1684    $form.addClass('active');
1685  };
1686
1687  var hideForm = function () {
1688    $toggle.removeClass('active');
1689    $form.removeClass('active');
1690  };
1691
1692  $toggle.on('click', function () {
1693    showForm();
1694  });
1695
1696  $(document).on('click', function (event) {
1697    var isForm = $(event.target).hasClass('.js-searchform').length || $(event.target).closest('.js-searchform').length;
1698    var isToggle =
1699      $(event.target).hasClass('.js-adrecom-search-toggle').length ||
1700      $(event.target).closest('.js-adrecom-search-toggle').length;
1701
1702    if (isForm) {
1703      return;
1704    }
1705
1706    if (isToggle) {
1707      return;
1708    }
1709
1710    if (isSearchActive()) {
1711      hideForm();
1712    }
1713  });
1714}
1715
1716//main jquery hook-up function
1717$(document).ready(function () {
1718  //init_videojs();
1719  init_tabs_collapse();
1720  stopCaruselOnClick();
1721
1722  init_country_state_block('');
1723  init_country_state_block('SHIP');
1724  init_bbcode_wysiwyg();
1725  init_login_and_account_on_checkout();
1726  init_lightbox();
1727  init_comments();
1728  init_contacts_form_dialog();
1729  init_login_json();
1730  init_after_login_logout_return();
1731  init_non_auth_message();
1732  //$(".jqueryui_tabs").tabs();
1733
1734  init_mega_menu();
1735  init_fading_tabs();
1736
1737  //Patch, that fixes z-index issue. Must be after init_fading_tabs
1738  correct_zindex4menu('UL.mega_menu');
1739
1740  init_gallery();
1741  init_confirmations();
1742  init_msgbox();
1743  init_slideshow();
1744  init_on_focus_replace();
1745  init_job_offers_menu();
1746
1747  init_date_pickers();
1748
1749  init_calendar_selectors();
1750
1751  init_panel_scrollers();
1752  init_wishlist();
1753  init_product_quantity();
1754  init_product_inventory_check();
1755  init_limited_choice();
1756  init_new_contact_forms();
1757  init_dialog_st();
1758  init_review();
1759  init_sorting();
1760  init_viewcart();
1761  init_viewcart_custom();
1762  init_pop_ups();
1763  init_masonry_imagesloaded();
1764  init_adrecom_search_field();
1765  init_viewcart_popup();
1766  init_mask();
1767  init_tooltips();
1768  if (typeof on_custom_jquery_init != 'undefined') on_custom_jquery_init();
1769});
1770
1771function init_viewcart_popup() {
1772  const $viewcart = $('.js_viewcart'),
1773    $viewcart_btn = $('.js_viewcart_open');
1774
1775  $viewcart_btn.on('mouseover', function (evt) {
1776    evt.preventDefault();
1777
1778    $.get(
1779      `${sitehome}?section=viewcart&ac=list&name=viewcart&ELT=viewcart_popup_list.html&IT=viewcart_popup_item.html&r=${Math.random()}`,
1780      function (data) {
1781        if (!$viewcart.find('.vc-popup').length) {
1782          $viewcart.append($(data));
1783          init_tooltips()
1784          init_popup_form();
1785        }
1786      }
1787    );
1788  });
1789
1790  function init_popup_form() {
1791    $viewcart.find('.js_viewcart_close').one('click', function (evt) {
1792      evt.preventDefault();
1793
1794      close_popup();
1795    });
1796
1797    $('.vc-popup button[type="submit"]').on('click', function () {
1798      let $next_section = $viewcart.find('.viewcart_next_section');
1799
1800      $next_section.val($(this).hasClass('js_checkout_button') ? 'checkout' : 'viewcart');
1801    });
1802
1803    $(document).on('click', function vc_popup_document_click_handler(evt) {
1804      if (!$(evt.target).closest($viewcart.find('.vc-popup')).length) {
1805        close_popup();
1806        $(document).off('click', vc_popup_document_click_handler);
1807      }
1808    });
1809  }
1810
1811  function close_popup() {
1812    $viewcart.find('.vc-popup').fadeOut(300, function () {
1813      $(this).remove();
1814    });
1815  }
1816}
1817
1818function init_mask() {
1819  const $phone_input = $('.js_phone_input');
1820
1821  $phone_input.mask('+1 (000) 000-00-00');
1822}
1823
1824function init_tooltips() {
1825  var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
1826  var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
1827    return new bootstrap.Tooltip(tooltipTriggerEl);
1828  });
1829}

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.