Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var translations = [];
  2. var mig={
  3.     siteProperties:{
  4.         orderType:false,
  5.         showProductsListPaging:false,
  6.         hidePaginationWhenLoadingOnScroll:true,
  7.         maskPhone:true,
  8.         loadingOnScroll: false,
  9.         maskZipCode:true
  10.     },
  11.     engines: {
  12.         outlet: 'outlet',
  13.         sizeerde: 'sizeerde',
  14.         sizeer: 'sizeer',
  15.         galeria: 'galeria',
  16.     },
  17.     properties: appProperties,
  18.     pageType:'',
  19.     userCardClub:false,
  20.     userGender:false,
  21.     showLog:false,
  22.     logList:[],
  23.     log:function(text){
  24.         if(this.showLog){
  25.             console.log(text);
  26.         }
  27.         this.logList.push(text);
  28.     },
  29.     search:function(val) {
  30.         this.log('WYSZUKIWANIE');
  31.         val=val.replace(/ /g, '-');
  32.         if(val!=''){
  33.             this.showLoading();
  34.             document.location.href="/szukaj/" + encodeURIComponent(val) + "/";
  35.         }else{
  36.             $.fancybox(this.translations('emptySearch'));
  37.         }
  38.         return false;
  39.     },
  40.     helpers:{
  41.         onlyDigitsFilter:function(context) {
  42.             if(context.length) {
  43.                 context.keydown(function(e) {
  44.                     if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  45.                         (e.keyCode == 65 && e.ctrlKey === true) ||
  46.                         (e.keyCode >= 35 && e.keyCode <= 39)) {
  47.                              return;
  48.                      }
  49.                      if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  50.                          e.preventDefault();
  51.                      }
  52.                 });
  53.             }
  54.         }
  55.     },
  56.     init:function() {
  57.         this.commonInit();
  58.     },
  59.     commonInit:function(){
  60.         this.setMenuEvents();
  61.         this.setFloatingMenu();
  62.         this.contact.init();
  63.         switch (this.pageType) {
  64.             case 'mainPage':
  65.                 this.mainPage.init();
  66.             break;
  67.             case 'product':
  68.                 this.product.init();
  69.                 this.multimedia.init();
  70.             break;
  71.             case 'cart':
  72.                 this.cart.init();
  73.                 this.google.analytics();
  74.             break;
  75.             case 'productsList':
  76.                 this.productsList.init();
  77.             break;
  78.             case 'account':
  79.                 this.account.init();
  80.             break;
  81.             case 'opinionsList':
  82.                 this.opinions.init();
  83.             break;
  84.             case 'makeComments':
  85.                 this.comments.init();
  86.             break;
  87.             case 'printOrder':
  88.                 window.print();
  89.             break;
  90.             default:
  91.         }
  92.         this.setCommonEvents();
  93.         this.replaceCheckboxes();
  94.         this.checkOldBrowsers(9);
  95.         this.lazyLoad('');
  96.         this.help.listen();
  97.         this.cookiePolicy.init();
  98.         $(window).resize();
  99.     },
  100.     checkOldBrowsers:function(minimumIeVersion){
  101.          var myNav = navigator.userAgent.toLowerCase();
  102.          if(myNav.indexOf('msie') != -1) {
  103.              var ieversion = parseInt(myNav.split('msie')[1]);
  104.              if(ieversion < minimumIeVersion && ($('#main-page').length > 0 || $('#cart').length > 0)) {
  105.                  $.fancybox($('#tooOldBrowser').parent().html(),{enableEscapeButton: true});
  106.              }
  107.          }
  108.     },
  109.     setMenuEvents:function(){
  110.         var that=this;
  111.         $('#menu li.level1').hover(function(){
  112.             $(this).addClass('hover');
  113.         },function(){
  114.             $(this).removeClass('hover');
  115.         });
  116.         $('#menu .level3 .icon').click(function(){
  117.             $(this).toggleClass('active');
  118.         });
  119.         $('#menu .bottom a').click(function(){
  120.             that.filterMenu('node');
  121.         });
  122.         $(window).scroll(mig.setFloatingMenu);
  123.     },
  124.     setFloatingMenu: function() {
  125.         var $menuCache = $('#top-menu');
  126.         var $hederCache = $('#header');
  127.         var $bodyCache = $('body');
  128.  
  129.         if($bodyCache.hasClass('no-affix')) {
  130.             return;
  131.         }
  132.  
  133.         var startFloat = $hederCache.height() + $('#top-links-header').height();
  134.         if ($(window).scrollTop() > startFloat) {
  135.             $menuCache.addClass('fixed-menu');
  136.             $hederCache.addClass('fixed-header');
  137.             $bodyCache.addClass('fixed-bg');
  138.         } else{
  139.             $menuCache.removeClass('fixed-menu');
  140.             $hederCache.removeClass('fixed-header');
  141.             $bodyCache.removeClass('fixed-bg');
  142.         }
  143.         if ($('#search-block .input').length > 0) {
  144.             var left = $('#search-block .input').offset().left + parseInt($('#search-block .input').css('padding-left'));
  145.             var top = $('#search-block .input').offset().top + $('#search-block').height();
  146.             $('.ac_results').css('left', left);
  147.             $('.ac_results').css('top', top);
  148.         }
  149.     },
  150.     filterMenu:function(name){
  151.         var link="/szukaj/";
  152.         var data=[];
  153.         var type=false;
  154.         var gender = false;
  155.         $('li.level1.hover .icon.active').each(function(){
  156.             var that = this;
  157.             if ($(that).data('brand')) {
  158.                 if ($(that).parents('.level1').length > 0) {
  159.                     if ($($(that).parents('.level1')[0]).data('type') == 'gender') {
  160.                         gender = $($(that).parents('.level1')[0]).data('value');
  161.                     }
  162.                 }
  163.                 data.push('filtr-marka,' + $(that).data('brand'));
  164.             }
  165.             else {
  166.                 data.push('filtr-'+name+','+$(that).data('key'));
  167.             }
  168.         });
  169.  
  170.         if (gender) {
  171.             data.push('filtr-gender,' + gender);
  172.         }
  173.  
  174.         document.location.href=link+data.join('/')+"/";
  175.     },
  176.     lazyLoad:function(element){
  177.         isMobDevice = (/iphone|ipad|Android|webOS|iPod|BlackBerry|Windows Phone|ZuneWP7/gi).test(navigator.appVersion);
  178.         if(!isMobDevice){
  179.             $(element+" img.lazy").lazyload({
  180.                 effect:'show',
  181.                 load:function(i,n){
  182.                     $(this).removeClass('lazy');
  183.                 }
  184.             });
  185.         } else {
  186.             $(element+" img.lazy").each(function(i,t){
  187.                 $(t).attr('src',$(t).data('original'));
  188.             });
  189.         }
  190.     },
  191.  
  192.     translations:function(name){
  193.         if(translations[name])return translations[name];
  194.         else return name;
  195.     },
  196.     setCommonEvents:function(){
  197.         var that=this;
  198.         this.google.setCommonEvent();
  199.         this.checkLoginUser();
  200.         $('.selectBox').selectbox();
  201.         $('a[href="#"]').on('click',function(e){
  202.             e.preventDefault();
  203.         });
  204.         $('.bigRotator').cmsRotator({
  205.             speed: 500,
  206.             loop: true,
  207.             direction: 'right',
  208.             timeout: 5000
  209.         });
  210. /*      switch(mig.properties.engine) {
  211.             case mig.engines.outlet:
  212.                 $('.logotypes').cmsRotator({
  213.                     speed: 500,
  214.                     loop: false,
  215.                     direction: 'left',
  216.                     timeout: 5000
  217.                 });
  218.             break;
  219.  
  220.             default:
  221.                 $('.logotypes').cmsRotator({
  222.                     speed: 500,
  223.                     loop: true,
  224.                     direction: 'left',
  225.                     timeout: 5000
  226.                 });
  227.             break;
  228.         }*/
  229.         $('#products-list-top-cms').cmsRotator({loop: false});
  230.         var mainSliders = 6;
  231.         switch(appProperties.engine){
  232.             case 'sizeer':
  233.                 mainSliders = 3;
  234.                 break;
  235.             case 'outlet':
  236.                 mainSliders = 8;
  237.                 break;
  238.             default:
  239.                 mainSliders = 6;
  240.                 break;
  241.         }
  242.         var isInfinite = false;
  243.         appProperties.engine === 'outlet' ? isInfinite = true : false;
  244.         switch(mig.pageType){
  245.             case 'cart':
  246.                 $('.othersInCollection .simpleList').recommendations({versionUrl:'B', slidesToShow: 6});
  247.                 break;
  248.             case 'mainPage':
  249.                 ($('.carouselBox').length>0) ? $('.carouselBox').recommendations() :false;
  250.                 if(mig.properties.engine == 'outlet') {
  251.                     $('.products-with-gender-rotator .rotator').recommendations({versionUrl: 'B', slidesToShow: 8, infinite: true});
  252.                 } else {
  253.                     $('.products-with-gender-rotator .rotator').recommendations({versionUrl: 'B', slidesToShow: 3, infinite: false});
  254.                 }
  255.                 break;
  256.             case 'product':
  257.                 if(mig.properties.engine == 'outlet') {
  258.                     /* TODO: Wydzielic do osobnych js */
  259.                     $('.othersInCategory .simpleList').recommendations({versionUrl: 'B', ga_place: 'Karta produktu', wholePagePid: true});
  260.                     $('.othersInCollection .simpleList').recommendations({versionUrl: 'A', ga_place: 'Karta produktu', wholePagePid: true});
  261.                 } else {
  262.                     $('.othersInCategory .simpleList').recommendations({versionUrl: 'B', ga_place: 'Karta produktu'});
  263.                     $('.othersInCollection .simpleList').recommendations({versionUrl: 'A', ga_place: 'Karta produktu'});
  264.                 }
  265.                 break;
  266.             default:
  267.  
  268.                 break;
  269.         }
  270.         $('.oneClick').oneClick();
  271.         $('#search-block form').submit(function(){
  272.             that.search($('#search-word').val().replace(/[/\\*]/g, "-"));
  273.             return false;
  274.         });
  275.         $('#search-word').autocomplete('/autocomplete.ltr', {
  276.             minChars: 1,
  277.             width: 487,
  278.             max:20,
  279.             cacheLength:10,
  280.             matchSubset :false,
  281.             matchContains:true,
  282.             selectFirst: false,
  283.             formatItem: function(row, i, max,value) {
  284.                 var item=row[0];
  285.                 if(row[1] && row[1]!='')item+='<small>'+row[1]+'</small>';
  286.                 if(row[2] && row[2]!='')item+='<div class="small">'+row[2]+'</div>';
  287.                 if(row[4] && row[4]!='')item='<img src="'+row[4]+'"/>'+item;
  288.                 return item;
  289.             },
  290.             formatMatch: function(row, i, max) {
  291.                 return row[0];
  292.             },
  293.             formatResult: function(row) {
  294.                 return row[0];
  295.             }
  296.         }).result(function(event, data, formatted) {
  297.             document.location.href=data[3];
  298.             jQuery.cookie('category',data[2]);
  299.             jQuery.cookie('categoryValue',data[0]);
  300.             mig.google.push(['_trackEvent','Wyszukiwarka - podpowiedź', data[2], data[0]]);
  301.         });
  302.  
  303.         var typingTimer;
  304.         var doneTypingInterval = 800;
  305.         $('#search-block input').keyup(function() {
  306.             clearTimeout(typingTimer);
  307.             if ($('#search-block input').val) {
  308.                 typingTimer = setTimeout(function() {
  309.                     var hints = $('#search-block input').val().replace(/[^A-Z0-9]+/ig, '-');
  310.                     mig.google.push(['_trackPageview', '/szukaj-podpowiedzi/' + hints + '/?q=' + hints + '&c=wyswietlenie-podpowiedzi']);
  311.                     var v = $("#in").val();
  312.                     $("#out").html(v);
  313.                 }, doneTypingInterval);
  314.             }
  315.         });
  316.  
  317.         /*
  318.          * $( "body" ).on( "click", "a[href='#']", function( e ) {
  319.          * e.preventDefault(); });
  320.          */
  321.  
  322.     },
  323.     goToMobilePage:function(){
  324.         mig.log('goToMobilePage');
  325.         document.cookie = 'DEVICE=; Max-Age=0';
  326.         this.showLoading();
  327.         $.cookie('DEVICE','mobile', {domain: '.'+document.domain, path: '/'});
  328.         $.cookie('DEVICE','mobile', {domain: document.domain, path: '/'});
  329.         document.location.reload(true);
  330.     },
  331.     showLoading:function(){
  332.         $.fancybox.showActivity();
  333.     },
  334.     hideLoading:function(){
  335.         $.fancybox.hideActivity();
  336.     },
  337.     checkLoginUser:function(){
  338.         mig.log('checkLoginUser');
  339.         var search=document.location.search;
  340.         var index=search.indexOf('logged=true&user=');
  341.         var that=this;
  342.         /*
  343.         if(index>-1){
  344.             that.showWelcome(decodeURI(search.substr(index+17)).replace("+"," "));
  345.         }
  346.         */
  347.     },
  348.     showWelcome:function(user){
  349.         mig.log('showWelcome');
  350.         $('#userWelcome strong').text(user);
  351.         $.fancybox($('#userWelcome').parent().html(),{enableEscapeButton: true});
  352.     },
  353.     scrollToError:function(){
  354.         var error = '';
  355.         $('span.error').each(function(){
  356.             if($(this).text() != '' && error == '') {
  357.                 error = $(this);
  358.             }
  359.         });
  360.         if(error != ''){
  361.             this.log('BŁĘDY FORMULARZA: ' + error.text());
  362.             var pos = error.offset().top;
  363.             if(pos >= $(window).height()) {
  364.                 var pos = error.offset().top - ($(window).height()/4);
  365.             }
  366.             $(document.body).scrollTop(pos);
  367.         }
  368.     },
  369.     shop:{
  370.         selectShop:function(id){
  371.             $('#errorShop').hide();
  372.             $("#shopSelected").val(id);
  373.             this.getShopInfoById(id);
  374.         },
  375.         getCities:function(province){
  376.             $('#shopList').hide();
  377.             $('#citySelect .label .text').text($('#citySelect ul li:first a').attr('data-text'));
  378.             $('#citySelect li').hide().removeClass('selected');
  379.             $('#citySelect li.'+province).show();
  380.             if (province != 0){
  381.                 $('#citySelect').removeClass('disabled');
  382.             }
  383.             else{
  384.                 $('#citySelect').addClass('disabled');
  385.             }
  386.         },
  387.         changeShop:function(){
  388.             $('#shopSelectedInfo').hide();
  389.             $('#shopAddress').show();
  390.         },
  391.         getShopInfoById:function(id){
  392.             $.ajax({
  393.                 url: '/shop-select.ltr',
  394.                 data:{
  395.                     id:id
  396.                 },
  397.                 type: "GET",
  398.                 success: function (result){
  399.                     $('#shopAddress').hide();
  400.                     $('#shopSelectedInfo').show();
  401.                     $('#shopSelectedInfo').html(result);
  402.                 }
  403.             });
  404.         },
  405.         getShopInfo:function(){
  406.             $.ajax({
  407.                 url: '/shop-select.ltr',
  408.                 data:{
  409.                     province:$('#province').val(),
  410.                     city:$('#city').val()
  411.                 },
  412.                 type: "GET",
  413.                 success: function (result){
  414.                     $('#shopList').html(result).show();
  415.                 }
  416.             });
  417.         }
  418.     },
  419.     contact:{
  420.         formElement: $('#contactForm'),
  421.         formContainerElement: $('#form'),
  422.         responseElement: $('#response'),
  423.         init: function() {
  424.             var that = this;
  425.             $('#contactForm').ajaxForm({
  426.                 beforeSubmit: that.showRequest,
  427.                 success: that.showResponse
  428.             });
  429.             $('#contactForm').validate({
  430.                 rules: {
  431.                     name: "required",
  432.                     content: "required",
  433.                     surname: "required",
  434.                     email: {
  435.                         required: true,
  436.                         email: true
  437.                     }
  438.                 },
  439.                 messages: {
  440.                     name: "Proszę wpisać imię",
  441.                     content: "Proszę wpisać treść wiadomości",
  442.                     surname: "Proszę wpisać nazwisko",
  443.                     email: "Proszę wpisać poprawny adres e-mail"
  444.                 }
  445.             });
  446.         },
  447.         showRequest: function(event) {
  448.             if($('#contactForm').valid()){
  449.                 //$('#contactForm').remove();
  450.                 return true;
  451.             } else {
  452.                 return false;
  453.             }
  454.         },
  455.         showResponse: function(responseText, statusText) {
  456.             $('#response').remove();
  457.             $('#form').prepend(responseText);
  458.             if($('#response').text()=='captcha'){
  459.                 mig.contact.reloadCaptcha();
  460.                 $('#response').addClass('error').html('<span class="error">'+translations['invalidCaptcha']+'</div>');
  461.             } else {
  462.                 $('#form').html(responseText);
  463.             }
  464.         },
  465.         reloadCaptcha: function() {
  466.             $('.captcha img').attr('src', '/cmsUtils/captcha.ltr' + '?' + Math.random());
  467.         }
  468.     },
  469.     mainPage: {
  470.         init:function() {
  471.             $('.bigRotator').slider({
  472.                 autoplay: true,
  473.                 autoplayDirection: 'right',
  474.                 autoplaySpeed: 5000,
  475.                 dots: true,
  476.                 dragable: false,
  477.                 infinite: true,
  478.                 slidesToShow: 1,
  479.                 speed: 500
  480.             });
  481. /*          $('#logotypes').slider({
  482.                 autoplay: true,
  483.                 autoplaySpeed: 5000,
  484.                 draggable: false,
  485.                 slidesToShow: 9,
  486.                 slidesToScroll: 1,
  487.                 speed: 500
  488.             });*/
  489.         }
  490.     },
  491.     mainPage:{
  492.         init:function(){
  493.  
  494.         }
  495.     },
  496.     cart:{
  497.         pageType:'',
  498.         scrollTo:false,
  499.         flowExecutionUrl:'',
  500.         clickedButtons: {
  501.             step1Next: false,
  502.             step3Back: false,
  503.             step3Next: false,
  504.             step3bBack: false,
  505.             step3bNext: false,
  506.             step4Back: false,
  507.             step4Next: false,
  508.             step4bBack: false,
  509.             step4bNext: false,
  510.             saveSurvey: false
  511.         },
  512.         init:function(){
  513.             switch (this.pageType) {
  514.                 case 'basket':
  515.                     this.basketInit();
  516.                 break;
  517.                 case 'login':
  518.                     this.loginInit();
  519.                 break;
  520.                 case 'registration':
  521.                     mig.validate.register();
  522.                 break;
  523.                 case 'orderData':
  524.                     this.orderDataInit();
  525.                 break;
  526.                 case 'summary':
  527.                     this.clubCard();
  528.                     this.summaryInit();
  529.                 break;
  530.                 case 'finalize':
  531.                     //
  532.                 break;
  533.                 default:
  534.             }
  535.             if(this.scrollTo && $(this.scrollTo).length){
  536.                 var position=parseInt($(this.scrollTo).offset().top-10);
  537.                 $.scrollTo(position);
  538.             }
  539.             if(!$('.basketInfo div').length)$('.basketInfo').remove();
  540.         },
  541.         orderDataInit: function(){
  542.             mig.validate.address();
  543.             var firstClick = false;
  544.             $('#order input').click(function() {
  545.                 if(firstClick == false) {
  546.                     mig.google.push(['_trackEvent','Checkout - dane adresowe','Formularz danych adresowych','Rozpoczęto wypełnianie',0]);
  547.                     firstClick = true;
  548.                 }
  549.             });
  550.             if(this.inShop){
  551.                 var shopSelected=$('#shopSelected').val();
  552.                 if(shopSelected.length){
  553.                     mig.shop.getShopInfoById(shopSelected);
  554.                 }else{
  555.                     $('#shopAddress').show();
  556.                 }
  557.             }
  558.             mig.splittedPostalCode();
  559.         },
  560.         summaryInit:function(){
  561.             $('a[href="#voucherInfoPopup"], a[href="#voucherHelpPopup"]').click(function(){
  562.                 $.fancybox($($(this).attr('href')).html(), {
  563.                     enableEscapeButton: true,
  564.                 });
  565.             });
  566.         },
  567.         basketInit:function(){
  568.             var that=this;
  569.             var voucherState = mig.google.voucherState;
  570.             var bondState = mig.google.bondState;
  571.  
  572.             $('.errorRow').each(function(i){
  573.                 var error = $(this).text();
  574.                 if($(this).hasClass('errorVoucher') || $(this).hasClass('errorBond')) {
  575.                     if((voucherState != "")) {
  576.                         mig.google.push(['_trackEvent','Koszyk', 'Kod rabatowy', voucherState]);
  577.                     }
  578.                     if((bondState != "")) {
  579.                         mig.google.push(['_trackEvent','Koszyk', 'Bon podarunkowy', bondState]);
  580.                     }
  581.                 } else {
  582.                     mig.google.push(['_trackEvent','Koszyk', 'Komunikat', error]);
  583.                 }
  584.             });
  585.  
  586.             $('#trusted-checkbox').click(function(){
  587.                 if($(this).is(':checked')){
  588.                     $('#trustedInput').val(that.trustedShopProductId);
  589.                 }else{
  590.                     $('#trustedInput').val('');
  591.                 }
  592.                 that.submitForm('submit');
  593.             });
  594.             $('a.foto, a.productTitle').click(function(){
  595.                 mig.showLoading();
  596.             });
  597.             $('a[href="#voucherInfoPopup"], a[href="#voucherHelpPopup"]').click(function(){
  598.                 $.fancybox($($(this).attr('href')).html(),{enableEscapeButton: true});
  599.             });
  600.         },
  601.         loginInit:function(){
  602.             this.passwordRemind();
  603.             mig.validate.login();
  604.             mig.validate.register();
  605.             mig.validate.passwordReminder();
  606.  
  607.             if($('#registrationForm').find('span.error').length>0) {
  608.                 $('#registrationForm').show();
  609.             }
  610.             var firstClick = false;
  611.             $('#registrationForm input').click(function() {
  612.                 if(firstClick == false) {
  613.                     mig.google.push(['_trackEvent','Checkout - rejestracja','Formularz rejestracji','Rozpoczęto wypełnianie',0]);
  614.                     firstClick = true;
  615.                 }
  616.             });
  617.             $('.next.register').click(function() {
  618.                 mig.google.push(['_trackEvent','Checkout - rejestracja','Formularz rejestracji','Wysłanie formularza',0]);
  619.             });
  620.             $('#selectAll').click(function() {
  621.                 $('#registrationForm input[type=checkbox]').each(function() {
  622.                     if($('#selectAll').prop('checked') && !$(this).prop('checked')) {
  623.                         $(this).trigger('click');
  624.                     } else if(!$('#selectAll').prop('checked') && $(this).prop('checked')) {
  625.                         $(this).trigger('click');
  626.                     }
  627.                 });
  628.             });
  629.         },
  630.         userRegister:function() {
  631.             if($('#registrationForm').is(':visible')) {
  632.                 //wysylamy formularz
  633.                 this.register();
  634.             } else {
  635.                 console.log('213');
  636.                 //otwieramy formularz
  637.                 $('#customer-registration-box').addClass('show-register-form');
  638.                 $('#registrationForm').show();
  639.                 this.registrationFormVisible=1;
  640.             }
  641.         },
  642.         setBirthDate:function(context, part) {
  643.             var c = $(context);
  644.  
  645.             switch(mig.properties.engine) {
  646.                 case mig.engines.outlet:
  647.                     var label = c.parent().parent().parent().parent().parent().find('.label .text');
  648.                 break;
  649.  
  650.                 default:
  651.                     var label = c.parent().parent().parent().find('.label .text');
  652.                 break;
  653.             }
  654.             label.text(c.data('label'));
  655.             var fieldName = '';
  656.             switch(part) {
  657.                 case 'm':
  658.                     fieldName = 'birthMonth';
  659.                 break;
  660.                 case 'd':
  661.                     fieldName = 'birthDay'
  662.                 break;
  663.                 case 'y':
  664.                     fieldName = 'birthYear';
  665.                 break;
  666.             }
  667.             $('input[name='+fieldName+']').val(c.data('value'));
  668.             var birthYear = $('input[name=birthYear]').val();
  669.             var birthMonth = $('input[name=birthMonth]').val();
  670.             var birthDay = $('input[name=birthDay]').val();
  671.             var birthDate = '';
  672.  
  673.             if(birthDay != '' && birthYear != '' && birthMonth != '') {
  674.                 birthDate = birthYear+'-'+birthMonth+'-'+birthDay;
  675.                 this.validateDate(birthDay, birthMonth, birthYear);
  676.                 $('#birthDateField').val(birthDate);
  677.             }
  678.  
  679.         },
  680.         daysInMonth: function(m, y) {
  681.             switch (m) {
  682.                 case 2 :
  683.                     return (y % 4 == 0 && y % 100) || y % 400 == 0 ? 29 : 28;
  684.                 case 9 : case 4 : case 6 : case 11 :
  685.                     return 30;
  686.                 default :
  687.                     return 31
  688.             }
  689.         },
  690.         isDatePast:function(d, m, y) {
  691.             m = m-1;
  692.             var date = new Date(y, m, d, 0, 0, 0, 0);
  693.             var now = new Date();
  694.             return now.getTime()>date.getTime();
  695.         },
  696.         validateDate: function(d, m, y) {
  697.             var m = parseInt(m);
  698.             var y = parseInt(y);
  699.             var d = parseInt(d);
  700.  
  701.             var container = $('#birthDate .error');
  702.             container.html(' ');
  703.             if(d>this.daysInMonth(m, y)) {
  704.                 container.show();
  705.                 container.html('<span class="error">'+mig.validate.messages.birthDate.daysOutOfBounds+'</span>');
  706.                 return;
  707.             }
  708.             if(!this.isDatePast(d, m, y)) {
  709.                 container.show();
  710.                 container.html('<span class="error">'+mig.validate.messages.birthDate.incorrect+'</span>');
  711.                 return;
  712.             }
  713.  
  714.             container.hide();
  715.         },
  716.         passwordRemind:function(){
  717.             if(!this.passwordRemindPopup){
  718.                 this.passwordRemindPopup=$('#passwordRemindPopup').parent().html();
  719.  
  720.                 $('#passwordRemindPopup').remove();
  721.             }
  722.             var that=this;
  723.             $('.passwordRemind').click(function(){
  724.                 $.fancybox(that.passwordRemindPopup,{
  725.                     padding:0,
  726.                     enableEscapeButton: true,
  727.                     onComplete:function(){
  728.                         mig.validate.passwordReminder();
  729.                         $('#email-przypomnienie').val($('#j_username').val());
  730.                     },
  731.                 });
  732.             });
  733.         },
  734.  
  735.         setField:function(input,value){
  736.             mig.log('setField: '+input+' na '+value);
  737.             $('#'+input).val(value);
  738.         },
  739.         submitForm:function(action){
  740.             mig.log('WYSŁANIE FOMULARZA');
  741.             if(action){
  742.                 this.setField('eventId', action);
  743.             }
  744.             mig.showLoading();
  745.             $('#order').submit();
  746.         },
  747.         deleteCoupon:function(index){
  748.             mig.log('deleteCoupon');
  749.             this.setField('itemIndex', index);
  750.             this.submitForm('removeBond');
  751.         },
  752.         voucherCaptcha:function(){
  753.             mig.log('voucherCaptcha');
  754.             $('.coupon > .input').hide();
  755.             $('#captcha-box').show();
  756.         },
  757.         sendCoupon:function(){
  758.             mig.log('sendCoupon');
  759.             this.submitForm('submit');
  760.         },
  761.         sendVoucher:function(){
  762.             mig.log('sendVoucher');
  763.             this.submitForm('submit');
  764.         },
  765.         copyPaymentSelect:function(id){
  766.             var value=$('#'+id).val();
  767.             if(value=='0')value='';
  768.             $('#'+id+'Hidden').val(value);
  769.         },
  770.         changePaymentType:function(){
  771.             this.setField('changeType', 'paymentType');
  772.             var action='submit';
  773.             if(this.pageType!='basket'){
  774.                 action='recalculate';
  775.                 $('#order').ignore(true);
  776.             }
  777.             this.copyPaymentSelect('paymentType');
  778.             this.submitForm(action);
  779.         },
  780.         changeCountry:function(){
  781.             mig.log('changeCountry');
  782.             this.setField('changeType', 'country');
  783.             var action='submit';
  784.             if(this.pageType!='basket'){
  785.                 action='recalculate';
  786.                 $('#order').ignore(true);
  787.             }
  788.             this.copyPaymentSelect('country');
  789.             this.submitForm(action);
  790.         },
  791.         changeDeliveryType:function(){
  792.             var that=this;
  793.             mig.log('changeDeliveryType');
  794.             that.setField('changeType', 'deliveryType');
  795.             var action='submit';
  796.             if(this.pageType!='basket'){
  797.                 action='recalculate';
  798.                 $('#order').ignore(true);
  799.             }
  800.             this.copyPaymentSelect('deliveryType');
  801.             this.submitForm(action);
  802.         },
  803.         changeDeliveryHour:function(){
  804.             mig.log('changeDeliveryHour');
  805.             this.setField('changeType', 'deliveryHour');
  806.             this.copyPaymentSelect('deliveryHour');
  807.             this.submitForm('submit');
  808.         },
  809.         login:function(){
  810.             mig.log('login');
  811.             if($('#loginForm').valid()){
  812.                 mig.showLoading();
  813.                 $('#loginForm').submit();
  814.             }
  815.             //else mig.scrollToError();
  816.         },
  817.         register:function(){
  818.             mig.log('register');
  819.             if($('#registrationForm').valid()){
  820.                 mig.showLoading();
  821.                 if($('.cartPath').length){
  822.                     mig.google.push(['_trackEvent','Checkout - rejestracja','Formularz rejestracji','Pomyślna rejestracja',0]);
  823.                 }
  824.                 var regUrl = $('#registrationForm').attr('action');
  825.                 if (regUrl.indexOf("front-") >= 0) {
  826.                     if ($('#recivingNewsletter').is(':checked')) {
  827.                         mig.google.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  828.                     }
  829.                 }
  830.                 if (regUrl.indexOf("order-") >= 0) {
  831.                     if ($('#recivingNewsletter').is(':checked')) {
  832.                         mig.google.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  833.                         mig.google.push(['_trackPageview','/rejestracja-checkout.bhtml']);
  834.                     } else {
  835.                         mig.google.push(['_trackPageview', '/rejestracja-checkout.bhtml']);
  836.                     }
  837.                 }
  838.                 $('#registrationForm').submit();
  839.             }
  840.             //else mig.scrollToError();
  841.         },
  842.         setPhoneType:function(that){
  843.             if(that===null) {
  844.                 that=$('input[name=frontUser\\.address\\.phoneType][checked=checked]');
  845.                 if (that === null || that.length == 0) {
  846.                     that=$('input[name=deliveryAddress\\.phoneType][checked=checked]');
  847.                 }
  848.             }
  849.             $("input[id$='phone']").each(function(){
  850.                 $(this).data('type',$(that).val().toLowerCase());
  851.             });
  852.             this.checkPhoneFormat();
  853.         },
  854.         checkPostalCodeFormat:function(that){
  855.             if(that.val()!=''){
  856.                 var zip = that.val().replace(/[^0-9]/g,'');
  857.                 if(zip.length >= 5){
  858.                     zip = zip.split('');
  859.                     zip = zip[0]+zip[1]+'-'+zip[2]+zip[3]+zip[4];
  860.                 }
  861.                 that.val(zip);
  862.             }
  863.         },
  864.         checkPhoneFormat:function(){
  865.             $("input[id$='phone']").each(function(){
  866.                 if($(this).val()!=''){
  867.                     var type=$(this).data('type');
  868.                     var phone = $(this).val().replace(/[^0-9]/g,'');
  869.                     if(phone.length >= 9){
  870.                         var phone = phone.split('');
  871.                         if(type=="stationary"){
  872.                             $(this).attr('maxlength', '12');
  873.                             phone=phone[0]+phone[1]+'-'+phone[2]+phone[3]+phone[4]+'-'+phone[5]+phone[6]+'-'+phone[7]+phone[8];
  874.                         }else{
  875.                             $(this).attr('maxlength', '11');
  876.                             phone=phone[0]+phone[1]+phone[2]+'-'+phone[3]+phone[4]+phone[5]+'-'+phone[6]+phone[7]+phone[8];
  877.                         }
  878.                     }
  879.                     $(this).val(phone);
  880.                 }
  881.             });
  882.         },
  883.         setOtherDelivery:function(){
  884.             if($('#otherAdress').is(':checked')){
  885.                 $('#deliveryAddress').show().ignore(false);
  886.                 mig.log('INNE DANE DOSTAWY');
  887.             }else{
  888.                 $('#deliveryAddress').hide().ignore(true).find('input').val('');
  889.                 mig.log('JEDEN ADRES DOSTAWY');
  890.             }
  891.             this.checkFormPosition();
  892.         },
  893.         setInvoice:function(){
  894.             if($('#invoice').is(':checked')){
  895.                 $('#invoiceAddress').show().ignore(false);
  896.                 mig.log('INNE DANE FAKTURY');
  897.             }else{
  898.                 $('#invoiceAddress').hide().ignore(true).find('input').val('');
  899.                 mig.log('BEZ FAKTURY');
  900.             }
  901.             this.checkFormPosition();
  902.         },
  903.         checkFormPosition:function(){
  904.             //nadpisana w outlecie
  905.         },
  906.         copyDataForm: function() {
  907.             if($('#copyDataForm').is(':checked')) {
  908.                 $('#invoiceAddress input[type=text]').each(function() {         //zwielokrotnione z powodu bindowanie do róznych obiektów
  909.                     try{
  910.                         var targetOrder = $('input[id="' +$(this).attr('id').replace('invoiceAddress', 'frontUser.address')+'"]');
  911.                         if(targetOrder.length){
  912.                             $(this).val(targetOrder.val());
  913.                         }
  914.                     }catch(e){mig.log('copyDataForm1')}
  915.                     try{
  916.                         var targetAccount = $('input[name="'+$(this).attr('name').replace('invoiceAddress', 'address')+'"]');
  917.                         if(targetAccount.length){
  918.                             $(this).val(targetAccount.val());
  919.                         }
  920.                     }catch(e){mig.log('copyDataForm2')}
  921.                     try{
  922.                         var targetAccount = $('input[id="'+$(this).attr('id').replace('invoiceAddress', 'address')+'"]');
  923.                         if(targetAccount.length){
  924.                             $(this).val(targetAccount.val());
  925.                         }
  926.                     }catch(e){mig.log('copyDataForm3')}
  927.                 });
  928.             }
  929.         },
  930.         isClicked: function(buttonName) {
  931.             return this.clickedButtons[buttonName];
  932.         },
  933.         setClicked: function(buttonName) {
  934.             this.clickedButtons[buttonName] = true;
  935.         },
  936.         step1Next:function(){
  937.             mig.log('step1Next');
  938.             var error = null;
  939.             if($('.payment-type-error').length > 0) {
  940.                 error = error + 1;
  941.                 $('.payment-type-error').show();
  942.             }
  943.             if($('.delivery-type-error').length > 0) {
  944.                 error = error + 1;
  945.                 $('.delivery-type-error').show();
  946.             }
  947.             if(error == null) {
  948.                 if(this.isClicked('step1Next')) {
  949.                     return false;
  950.                 }
  951.  
  952.                 this.setClicked('step1Next');
  953.                 if(mig.siteProperties.orderType=='make-order') {
  954.                     this.submitForm('doOrderNoPostage');
  955.                 } else {
  956.                     this.submitForm('doOrder');
  957.                 }
  958.             }
  959.         },
  960.         step3Back:function(){
  961.             mig.log('step3Back');
  962.             if(this.isClicked('step3Back')) {
  963.                 return false;
  964.             }
  965.             this.setClicked('step3Back');
  966.             $('#order').ignore(true);
  967.             $('#action').attr('name','_eventId_back');
  968.             this.submitForm('back');
  969.         },
  970.         step3Next:function(){
  971.             mig.log('step3Next');
  972.             $('#action').attr('name','_eventId_submit');
  973.             if($('#order').valid()){
  974.                 if(this.isClicked('step3Next')) {
  975.                     return false;
  976.                 }
  977.                 this.setClicked('step3Next');
  978.                 mig.google.push(['_trackEvent','Checkout - dane adresowe','Formularz danych adresowych','Pomyślne wypełnienie',0]);
  979.                 this.submitForm('step3');
  980.             } else mig.scrollToError();
  981.         },
  982.         step3bBack:function(){
  983.             mig.log('step3bBack');
  984.             $('#order').ignore(true);
  985.             $('#action').attr('name','_eventId_back');
  986.             this.submitForm('stepBack');
  987.         },
  988.         step3bNext:function(){
  989.             mig.log('step3bNext');
  990.             if(this.isClicked('step3bNext')) {
  991.                 return false;
  992.             }
  993.             this.setClicked('step3bNext');
  994.             $('#action').attr('name','_eventId_submit');
  995.             this.submitForm('step4');
  996.         },
  997.         step4Back:function(){
  998.             mig.log('step4Back');
  999.             if(this.isClicked('step4Back')) {
  1000.                 return false;
  1001.             }
  1002.             this.setClicked('step4Back');
  1003.             mig.showLoading();
  1004.             document.location.href=this.flowExecutionUrl+'&_eventId=back';
  1005.             return false;
  1006.         },
  1007.         step4Next:function(){
  1008.             var accepted = true;
  1009.             if($('#acceptRules').length > 0) {
  1010.                 if($('#acceptRules').prop('checked')) {
  1011.                     accepted = true;
  1012.                 } else {
  1013.                     accepted = false;
  1014.                 }
  1015.             }
  1016.             if(accepted) {
  1017.                 mig.log('step4Next');
  1018.                 if(this.isClicked('step4Next')) {
  1019.                     return false;
  1020.                 }
  1021.                 this.setClicked('step4Next');
  1022.                 mig.showLoading();
  1023.                 document.location.href=this.flowExecutionUrl+'&_eventId=submit';
  1024.             } else {
  1025.                 $('.accept-rules .error').css('display', 'block');
  1026.                 mig.scrollToError();
  1027.                 $('#acceptRules').click(function() {
  1028.                     if($('#acceptRules').prop('checked')) {
  1029.                         $('.accept-rules .error').hide();
  1030.                     } else {
  1031.                         $('.accept-rules .error').css('display', 'block');
  1032.                     }
  1033.                 });
  1034.             }
  1035.         },
  1036.         step4bNext:function(){
  1037.             mig.log('step4bNext');
  1038.             if(this.isClicked('step4bNext')) {
  1039.                 return false;
  1040.             }
  1041.             this.setClicked('step4bNext');
  1042.             mig.showLoading();
  1043.             $('#action').attr('name','_eventId_submit');
  1044.             this.submitForm('step5');
  1045.             return false;
  1046.         },
  1047.         refreshBasket:function(){
  1048.             if ($('#basket-block').length){
  1049.                 mig.log('ODŚWIEŻENIE STANU KOSZYKA');
  1050.                 $.ajax({
  1051.                     url : '/cart.ltr',
  1052.                     cache: false,
  1053.                     success : function(html){
  1054.                         $('#basket-block').html(html);
  1055.                     }
  1056.                 });
  1057.             }
  1058.         },
  1059.         setNewSize:function(variant,itemId,name){
  1060.             var variantInput=$('#variant'+itemId);
  1061.             if(variantInput.val()!=variant){
  1062.                 mig.log('setNewSize');
  1063.                 variantInput.val(variant);
  1064.                 //$("#saveSize" + itemId).removeClass('hide');
  1065.                 this.calculate();
  1066.             }
  1067.             mig.google.push(['_trackEvent','Koszyk','Rozmiar', name]);
  1068.         },
  1069.         removeItem:function(itemId){
  1070.             mig.log('USUWANIE Z KOSZYKA: '+itemId);
  1071.             mig.google.push(['_trackEvent','Koszyk','Usuń']);
  1072.             //mig.google.push(['_trackEvent', 'Koszyk', 'Usuń produkt', $('#item'+itemId+' .productTitle').text(), $('#item'+itemId+' .itemPrice .value').text()]);
  1073.             this.setField('itemIndex', itemId);
  1074.             this.submitForm('removeItem');
  1075.         },
  1076.         editPay:function(itemId){
  1077.             var state = $('#card-edit-'+itemId).text();
  1078.             if(state == 'Zapisz') {
  1079.                 this.calculate();
  1080.             } else {
  1081.                 $('#new-price-'+itemId).show();
  1082.                 $('#new-price-change-'+itemId).val('true');
  1083.                 $('#price-'+itemId).hide();
  1084.                 $('#card-edit-'+itemId).text('Zapisz');
  1085.             }
  1086.         },
  1087.         changeQuantity:function(q, itemId){
  1088.             if (q < 0) q = 0;
  1089.             mig.log('changeQuantity: '+itemId+' na '+q);
  1090.             $("#quantity" + itemId).val(q);
  1091.             $("#quantityText" + itemId).empty().text(q);
  1092. //          $("#saveQuantity" + itemId).removeClass('hide');
  1093.             this.calculate();
  1094.         },
  1095.         calculate:function(){
  1096.             mig.log('calculate');
  1097.             mig.google.push(['_trackEvent', 'Koszyk', 'Przelicz koszyk']);
  1098.             this.submitForm('submit');
  1099.         },
  1100.         loadProductSize:function(option){
  1101.             var data={
  1102.                 product : option.product
  1103.             };
  1104.             if(option.variant && typeof option.item !='undefined'){
  1105.                 $.extend(true,data,{
  1106.                     variant:option.variant,
  1107.                     item:option.item
  1108.                 });
  1109.             }
  1110.             $.ajax({
  1111.                 url:'/product-size.ltr',
  1112.                 data: data,
  1113.                 cache: false,
  1114.                 success: function(html){
  1115.                     mig.log('UDANE ŁADOWANIE LISTY ROZMIARÓW PRODUKTU: '+option.product);
  1116.                     $.fancybox(html,{
  1117.                         padding:0,
  1118.                         enableEscapeButton: true,
  1119.                         onComplete: function(){
  1120.                             $('#fancybox-content a[href="#"]').on('click',function(e){
  1121.                                 e.preventDefault();
  1122.                             });
  1123.                         }
  1124.                     });
  1125.                 }
  1126.             });
  1127.         },
  1128.         addToCartSuccessCancel:function(){
  1129.             mig.google.push(['_trackEvent', 'Dodaj do koszyka - Popup', 'Anuluj']);
  1130.             $.fancybox.close();
  1131.         },
  1132.         addProduct:function(product){
  1133.             var pos = $(window).scrollTop();
  1134.             if($('#productPreview').length > 0) {
  1135.                 mig.google.push(['_trackEvent','Karta produktu - warstwa','Do koszyka']);
  1136.             } else {
  1137.                 mig.google.push(['_trackEvent','Karta produktu','Do koszyka']);
  1138.             }
  1139.             //mig.google.push(['_trackEvent', 'Dodaj do koszyka', 'Przycisk', product.name, product.price]);
  1140.             this.loadProductSize({product:product.id});
  1141.         },
  1142.         addVariant:function(productVariantId, productName, productPrice, productVariantVal){
  1143.             var that=this;
  1144.             if($('#productPreview').length > 0) {
  1145.                 if($('#productSizes').length > 0) {
  1146.                     mig.google.push(['_trackPageview','/dodanie-do-koszyka.bhtml']);
  1147.                     mig.google.push(['_trackEvent','Dodaj do koszyka - Popup','Rozmiar',productVariantVal]);
  1148.                 } else {
  1149.                     mig.google.push(['_trackPageview','/kp-warstwa/dodanie-do-koszyka.bhtml']);
  1150.                     mig.google.push(['_trackEvent','Karta produktu - warstwa','Rozmiar',productVariantVal]);
  1151.                 }
  1152.             } else {
  1153.                 mig.google.push(['_trackPageview','/dodanie-do-koszyka.bhtml']);
  1154.                 mig.google.push(['_trackEvent','Karta produktu','Rozmiar',productVariantVal]);
  1155.             }
  1156.  
  1157.             mig.showLoading();
  1158.             $.ajax({
  1159.                 type: "POST",
  1160.                 url: "/add-to-order-and-refresh.bhtml",
  1161.                 data: {
  1162.                     productVariantId : productVariantId
  1163.                 },
  1164.                 cache: false,
  1165.                 success: function(response){
  1166.                     var data=$.parseJSON(response);
  1167.                     mig.hideLoading();
  1168.                     if(data.addToCart){
  1169.                         mig.log('DODAWANIE WARIANTU('+productVariantId+') PRODUKTU DO KOSZYKA: OK');
  1170.                     }else{
  1171.                         mig.log('DODAWANIE WARIANTU('+productVariantId+') PRODUKTU DO KOSZYKA: ERROR');
  1172.                     }
  1173.                     $('#addToCartSuccess .h4').text(productName);
  1174.                     $.fancybox($('#addToCartSuccess').parent().html(),{
  1175.                         padding:0,
  1176.                         enableEscapeButton: true,
  1177.                         onComplete: function() {
  1178.                             $('.oneClick').oneClick();
  1179.                         }
  1180.                     });
  1181.                     that.refreshBasket();
  1182.                 },
  1183.                 error:function(){
  1184.                     mig.hideLoading();
  1185.                     mig.log('DODAWANIE WARIANTU('+productVariantId+') PRODUKTU DO KOSZYKA: ERROR');
  1186.                 }
  1187.             });
  1188.         },
  1189.         addVariantFromSelected: function() {
  1190.             if(!this.isAnyVariantSelected()) {
  1191.                 $.fancybox('Wybierz rozmiar',{
  1192.                     padding:0,
  1193.                     enableEscapeButton: true
  1194.                 });
  1195.             }
  1196.         },
  1197.         addToCartSuccessClose:function(){
  1198.             mig.google.push(['_trackEvent', 'Dodaj do koszyka - Popup', 'Powrot']);
  1199.             $.fancybox.close();
  1200.         },
  1201.         addToCartSuccessToOrder:function(){
  1202.             mig.google.push(['_trackEvent', 'Dodaj do koszyka - Popup', 'Zamawiam']);
  1203.             mig.showLoading();
  1204.         },
  1205.         expandClubSurvey:function(){
  1206.             if($('#fancybox-close').is(':visible')) {
  1207.                 mig.google.push(['_trackEvent','Checkout - podsumowanie','Popup sizeer club','Tak',0]);
  1208.             }
  1209.             $.fancybox.close();
  1210.             $('#clubForm').slideDown();
  1211.             window.scrollTo(0, $('#clubForm').position().top);
  1212.             $('#wannaClub').attr('checked', 'checked');
  1213.             $('#wannaClub').parent().addClass('checked').removeClass('unchecked');
  1214.         },
  1215.         abortClubSurvey:function(){
  1216.             mig.google.push(['_trackEvent','Checkout - podsumowanie','Popup sizeer club','Nie',0]);
  1217.             mig.cart.step4Next();
  1218.         },
  1219.         surveyConfirm:function(){
  1220.             $.fancybox($('#surveyConfirm').html(),{
  1221.                 padding:0,
  1222.                 enableEscapeButton: true
  1223.             });
  1224.         },
  1225.         surveyConfirmYes:function(){
  1226.             $('#saveSurvey').trigger('click');
  1227.             $.fancybox.close();
  1228.         },
  1229.         clubCard: function(){
  1230.             var that = this;
  1231.             if($('#survey').length) {
  1232.  
  1233.                 var _$surveyForm = $('#customerSurvey');
  1234.  
  1235.                 $.fancybox($('#surveyEncourage').html(),{
  1236.                     onClosed: function(){
  1237.                         if(!$('#clubForm').is(":visible")) {
  1238.                             mig.google.push(['_trackEvent','Checkout - podsumowanie','Popup sizeer club','Zamknij',0]);
  1239.                         }
  1240.                     },
  1241.                     padding:0,
  1242.                     enableEscapeButton: true
  1243.                 });
  1244.  
  1245.                 $('#wannaClub').change(function(){
  1246.                     if($(this).is(':checked')) {
  1247.                         $('#clubForm').slideDown();
  1248.                     }
  1249.                     else
  1250.                         $('#clubForm').slideUp();
  1251.                 });
  1252.  
  1253.                 _$surveyForm.validate({
  1254.                     rules:{
  1255.                         "answer-12995875":mig.validate.rules.date,
  1256.                         "answer-12995874":mig.validate.rules.phone,
  1257.                         "zgoda1":mig.validate.rules.termsAccepted,
  1258.                         "zgoda2":mig.validate.rules.termsAccepted
  1259.                     },
  1260.                     messages:{
  1261.                         "answer-64931376": mig.validate.messages.firstname,
  1262.                         "answer-64931378": mig.validate.messages.phone,
  1263.                         "answer-64931379": mig.validate.messages.login.email,
  1264.                         "answer-64931384": mig.validate.messages.postalCode,
  1265.                         "answer-64931385": mig.validate.messages.gender,
  1266.                         "answer-64931386": mig.validate.messages.birthDate,
  1267.                         "answer-12995876": mig.validate.messages.gender,
  1268.                         "answer-12995875":mig.validate.messages.birthDate,
  1269.                         "answer-12995874":mig.validate.messages.phone,
  1270.                         "zgoda1":mig.validate.messages.termsAccepted,
  1271.                         "zgoda2":mig.validate.messages.commercialsAccepted
  1272.                     },
  1273.                     errorElement: "span",
  1274.                     errorPlacement: function(error, element) {
  1275.                         if (element.attr("type") == "checkbox" || element.attr("type") == "radio" )
  1276.                             error.appendTo(element.parent());
  1277.                         else error.insertAfter(element);
  1278.                     },
  1279.                     invalidHandler: function(event, validator){
  1280.                         var errorText = $.map(validator.invalid, function(text, id) {
  1281.                             return text;
  1282.                         });
  1283.                         mig.google.push(['_trackEvent','Checkout - podsumowanie','Formularz sizeerclub',errorText.join(', '),0]);
  1284.                         mig.google.push(['_trackEvent','Checkout - podsumowanie','Formularz sizeerclub','Nieudane dołączenie do klubu',0]);
  1285.                     },
  1286.                 });
  1287.                 $('#saveSurvey').click(function(){
  1288.                     mig.google.push(['_trackEvent','Checkout - podsumowanie','Formularz sizeerclub','Wysłanie formularza',0]);
  1289.                     if(_$surveyForm.valid()) {
  1290.                         if(that.isClicked('saveSurvey')) {
  1291.                             return false;
  1292.                         }
  1293.                         that.setClicked('saveSurvey');
  1294.                         mig.google.push(['_trackEvent','Checkout - podsumowanie','Formularz sizeerclubi','Pomyślne dołączenie do klubu',0]);
  1295.                         _$surveyForm.submit();
  1296.                     } else {
  1297.                         mig.scrollToError();
  1298.                     }
  1299.                 });
  1300.                 var firstClick = false;
  1301.                 $('#clubForm input').click(function() {
  1302.                     if(firstClick == false) {
  1303.                         mig.google.push(['_trackEvent','Checkout - podsumowanie','Formularz sizeerclub','Rozpoczęto wypełnianie',0]);
  1304.                         firstClick = true;
  1305.                     }
  1306.                 });
  1307.             }
  1308.         }
  1309.     },
  1310.     sizeDetails: function(){
  1311.         $.fancybox($('#sizeList').parent().html(), {
  1312.             onStart: function() {
  1313.                 var top = $(window).scrollTop();
  1314.                 $('#sizeList').parents('#fancybox-wrap').css({top: top});
  1315.                 $.scrollTo($('#fancybox-wrap').offset().top);
  1316.             }
  1317.         });
  1318.  
  1319.     },
  1320.     loginRefresh:function(){
  1321.         $.ajax({
  1322.             url: '/login-block.ltr',
  1323.             cache: false,
  1324.             success: function(html){
  1325.                 $('#login-block').html(html);
  1326.                 //if(this.userCardClub)this.google.transaction.push(['_setCustomVar', 1, 'User Type', this.userCardClub, 1]);
  1327.                 //if(this.userGender)this.google.transaction.push(['_setCustomVar', 2, 'Plec', this.userGender, 1]);
  1328.                 /*console.log($('#login-block').find('#registeredUser').length);
  1329.                 if($('#login-block').find('#registeredUser').length) {
  1330.                     $('#login-block').find('#registeredUser').val();
  1331.                     mig.google.transaction.push(['_setCustomVar', 1, $('#login-block').find('#registeredUser').val(),'<UID>',1]);
  1332.                 }*/
  1333.                 //$('#login-block').find('#registeredUser').val();
  1334.  
  1335.                 if(jQuery('#login-block').find('#userGender').length) gaPush(['_setCustomVar', 2, 'Plec', jQuery('#login-block').find('#userGender').val(), 1]);
  1336.                 if($('#login-block').find('#registeredUser').length) {
  1337.                     var registeredUser = $('#login-block').find('#registeredUser').val();
  1338.                     var userCardClub = $('#login-block').find('#userCardClub').val();
  1339.                     var userNewsletter = $('#login-block').find('#userNewsletter').val();
  1340.                     var userId = $('#login-block').find('#userId').val();
  1341.                     mig.google.registeredUser = [registeredUser, userId];
  1342.                     if(userCardClub) {
  1343.                         mig.google.userCardClub = true;
  1344.                     }
  1345.                     if(userNewsletter) {
  1346.                         mig.google.userNewsletter = true;
  1347.                     }
  1348.                 };
  1349.                 mig.google.analytics();
  1350.             }
  1351.         });
  1352.     },
  1353.     splittedPostalCode: function() {
  1354.         if($('.postal-code')) {
  1355.             $('.postal-code').each(function() {
  1356.                 var code = $(this).find('.postal-code-0');
  1357.                 var code1 = $(this).find('.postal-code-1');
  1358.                 var code2 = $(this).find('.postal-code-2');
  1359.                 var error = $(this).find('.error');
  1360.                 if(code.val() != '') {
  1361.                     code1.val(code.val().split('-')[0]);
  1362.                     code2.val(code.val().split('-')[1]);
  1363.                 }
  1364.                 code1.keyup(function() {
  1365.                     var zip = $(this).val().replace(/[^0-9]/g,'');
  1366.                     $(this).val(zip);
  1367.                     code.val(this.value + '-' + code2.val());
  1368.                     if(error.children().length > 0) {
  1369.                         $('.postal-code').closest('form').validate().element(code);
  1370.                     }
  1371.                 });
  1372.                 code2.keyup(function() {
  1373.                     var zip = $(this).val().replace(/[^0-9]/g,'');
  1374.                     $(this).val(zip);
  1375.                     code.val(code1.val() + '-' + this.value);
  1376.                     if(error.children().length > 0) {
  1377.                         $('.postal-code').closest('form').validate().element(code);
  1378.                     }
  1379.                 });
  1380.             });
  1381.         }
  1382.     },
  1383.     multimedia:{
  1384.         init:function(){
  1385.             this.replaceIcon();
  1386.             $('.multimedia').css('overflow','visible');
  1387.             $('.multimedia .big .photo a').fancybox({enableEscapeButton: true});
  1388.             var multimediaBig = $('.multimedia .big');
  1389.             var multimediaSmall = $('.multimedia .small');
  1390.             var initialSlide = 0;
  1391.             if(multimediaSmall.find('.s360').length > 0) {
  1392.                 initialSlide = 1;
  1393.             }
  1394.             multimediaBig.slider({
  1395.                 arrows: false,
  1396.                 draggable: false,
  1397.                 infinite: false,
  1398.                 slidesToShow: 1,
  1399.                 slidesToScroll: 1,
  1400.                 initialSlide: initialSlide
  1401.             });
  1402.             multimediaSmall.slider({
  1403.                 asNavFor: multimediaBig,
  1404.                 draggable: false,
  1405.                 infinite: false,
  1406.                 slidesToShow: 5,
  1407.                 slidesToScroll: 1,
  1408.                 focusOnSelect: true
  1409.             });
  1410.         },
  1411.         /*movie:function(){
  1412.             $('.multimedia .big li.video').each(function(i,n){
  1413.                 $('<div/>').appendTo(this).flash({
  1414.                     id:'totalplayer',
  1415.                     swf:'/swf/totalplayer.swf',
  1416.                     height:500,
  1417.                     width:500,
  1418.                     name:'galeriaVideo',
  1419.                     wmode: 'transparent',
  1420.                     params:{
  1421.                         wmode: 'transparent',
  1422.                         allowfullscreen:"true"
  1423.                     },
  1424.                     majorversion:"9",
  1425.                     allowscriptaccess:"always",
  1426.                     allowfullscreen:"true",
  1427.                     quality:'high',
  1428.                     flashvars:'sourcefile=/product-movies-xml.ltr?id='+mig.product.id+'&movienr='+i
  1429.                 });
  1430.             });
  1431.         },
  1432.         rotator:function(xmlurl){
  1433.             var rotator=$('#rotator');
  1434.             var xmlurl=rotator.attr('data-src');
  1435.             rotator.flash({
  1436.                 id:'rotatorFlash',
  1437.                 swf:'/swf/rotator.swf',
  1438.                 height:380,
  1439.                 width:380,
  1440.                 name:'sizeerRotator',
  1441.                 wmode: 'transparent',
  1442.                 params:{
  1443.                     wmode: 'transparent',
  1444.                     allowfullscreen:"true"
  1445.                 },
  1446.                 majorversion:"9",
  1447.                 allowscriptaccess:"always",
  1448.                 allowfullscreen:"true",
  1449.                 quality:'high',
  1450.                 flashvars:'xmlurl='+xmlurl});
  1451.         }*/
  1452.         replaceIcon:function(){
  1453.             return '';
  1454.         },
  1455.     },
  1456.     product:{
  1457.         id:false,
  1458.         descriptionMaxLength: 10, //in chars
  1459.         init:function(){
  1460.             var that=this;
  1461.             mig.log('PRODUCT: INIT');
  1462.             this.addEntryToProduct();
  1463.             this.setEvents();
  1464.             this.prepareDescription();
  1465.             try{
  1466.                 FB.XFBML.parse();
  1467.             }catch(e){};
  1468.             setTimeout(function() {
  1469.                 that.fbAsyncInit();
  1470.             }, 2000);
  1471.             var billboard=$('#product-billbord');
  1472.             if(billboard.find('ul').length){
  1473.                 $('#product-news').html(billboard.html());
  1474.                 billboard.remove();
  1475.                 var promotionRotator = $('.promotionRotator');
  1476.                 promotionRotator.cmsRotator();
  1477.                 if(promotionRotator.find('li').length==1){
  1478.                     promotionRotator.find('.icons').hide();
  1479.                     promotionRotator.find('.prev').hide();
  1480.                     promotionRotator.find('.next').hide();
  1481.                 };
  1482.             }
  1483.             $('#main-rotator').slider({
  1484.                 arrows: false,
  1485.                 /*autoplay: true,*/
  1486.                 autoplaySpeed: 6000,
  1487.                 dots: true
  1488.             });
  1489.         },
  1490.         prepareDescription: function() {
  1491.             $('.productDesc ').css({'max-height': 'none', 'overflow' : 'visible'});
  1492.             if($('.productDesc .description').length > 0) {
  1493.                 var desc = $('.productDesc');
  1494.                 var text = desc.find('.description');
  1495.                 var more = desc.find('.more');
  1496.                 var less = desc.find('.less');
  1497.                 var limit = text.height() - (5 * parseFloat(text.css('line-height')));
  1498.                 var height = 'auto';
  1499.                 if(limit > 0) {
  1500.                     desc.addClass('expandable');
  1501.                     height = text.height() - limit - $('.disappears').height();
  1502.                     text.height(height);
  1503.                 }
  1504.                 more.click(function() {
  1505.                     text.removeAttr('style');
  1506.                     desc.addClass('expanded');
  1507.                     desc.removeClass('expandable');
  1508.                     less.show();
  1509.                     more.hide();
  1510.                 });
  1511.                 less.click(function() {
  1512.                     text.height(height);
  1513.                     desc.addClass('expandable');
  1514.                     desc.removeClass('expanded');
  1515.                     less.hide();
  1516.                     more.show();
  1517.                 });
  1518.             }
  1519.         },
  1520.         fbAsyncInit:function(){
  1521.             var user = $('#userId').val() || '';
  1522.             if(typeof FB != 'undefined') {
  1523.                 FB.Event.subscribe('edge.create', function(targetUrl, widget) {
  1524.                     $.ajax({
  1525.                         type: "GET",
  1526.                         url: "/facebook.bhtml",
  1527.                         data: {
  1528.                             id:mig.product.id,
  1529.                             user:user
  1530.                         }
  1531.                     });
  1532.                     mig.google.push(['_trackSocial', 'facebook', 'like', targetUrl]);
  1533.                 });
  1534.                 FB.Event.subscribe('edge.remove', function(targetUrl) {
  1535.                     mig.google.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
  1536.                 });
  1537.             }
  1538.         },
  1539.         addEntryToProduct:function(){
  1540.             $.ajax({
  1541.                 type: "GET",
  1542.                 url: "/addEntryToProduct.bhtml",
  1543.                 data: {
  1544.                     id:this.id
  1545.                 }
  1546.             });
  1547.         },
  1548.         setEvents:function(){
  1549.             var askHtml=$('#ask-about').parent().html();
  1550.             var tellHtml=$('#friend-notification').parent().html();
  1551.             $('#ask-about, #friend-notification').remove();
  1552.             $('.tell-a-friend a').click(function(e){
  1553.                 mig.google.push(['_trackPageview', '/polec-znajomemu.bhtml']);
  1554.                 $.fancybox(tellHtml,{padding:0,enableEscapeButton: true, onComplete:function(){
  1555.                     $('#fancybox-content a[href="#"]').on('click',function(e){
  1556.                         e.preventDefault();
  1557.                     });
  1558.                 }});
  1559.             });
  1560.             $('.write-to-us a').click(function(e){
  1561.                 mig.google.push(['_trackPageview', '/zapytaj-o-produkt.bhtml']);
  1562.                 $.fancybox(askHtml,{padding:0,enableEscapeButton: true, onComplete:function(){
  1563.                     $('#fancybox-content a[href="#"]').on('click',function(e){
  1564.                         e.preventDefault();
  1565.                     });
  1566.                 }});
  1567.             });
  1568.             $('.technologies a').click(function(){
  1569.                 $.fancybox($(this).next().html(),{
  1570.                     padding:0,
  1571.                     enableEscapeButton: true
  1572.                 });
  1573.             });
  1574.         },
  1575.         sendFrienNotification:function(){
  1576.             $('#friend-notification .button').hide();
  1577.             $('#friend-notification .loading').show();
  1578.             $('#frienForm').ajaxSubmit({
  1579.                 url:'/friendNotification.ltr',
  1580.                 success:function(html){
  1581.                     mig.log('sendFrienNotification: OK');
  1582.                     var status=$.trim(html);
  1583.                     if(status=='ok'){
  1584.                         $('#friend-notification .formSuccess').show();
  1585.                         $('#friend-notification .form').hide();
  1586.                     }else{
  1587.                         $('#friend-notification .errorBox').html('<span>'+html+'</span>');
  1588.                     }
  1589.                 },complete:function(){
  1590.                     $('#friend-notification .button').show();
  1591.                     $('#friend-notification .loading').hide();
  1592.                 },error:function(){
  1593.                     mig.log('sendFrienNotification: ERROR');
  1594.                 }
  1595.             });
  1596.         },
  1597.         sendAskAbout:function(){
  1598. //          mig.validate.productAsk();
  1599.             mig.validate.sendAskAbout();
  1600.             if($('#askForm').valid()) {
  1601.                 $('#askForm').ajaxSubmit({
  1602.                     url:'/askaboutproduct.ltr',
  1603.                     success:function(html){
  1604.                         mig.log('sendAskAbout: OK');
  1605.                         var status=$.trim(html);
  1606.                         if(status=='ok'){
  1607.                             $('#ask-about .formSuccess').show();
  1608.                             $('#ask-about .form').hide();
  1609.                         }else{
  1610.                             $('#ask-about .errorBox').html('<span>'+html+'</span>');
  1611.                         }
  1612.                     },complete:function(){
  1613.                         $('#ask-about .button').show();
  1614.                         $('#ask-about .loading').hide();
  1615.                     },error:function(){
  1616.                         mig.log('sendAskAbout: ERROR');
  1617.                     }
  1618.                 });
  1619.             }
  1620.         }
  1621.     },
  1622.     opinions:{
  1623.         loading:false,
  1624.         endlessScroll:false,
  1625.         pathInfo:{},
  1626.         init:function(){
  1627.             mig.log('OPINIONS: INIT');
  1628.             var that=this;
  1629.             that.toggleEndlessScroll(mig.pageType);
  1630.             if(that.endlessScroll) {
  1631.                 $(window).scroll(function(){
  1632.                     if(!that.loading){
  1633.                         var delta=$('.footer-box').offset().top-$(window).scrollTop()-$(window).height()+50;
  1634.                         if(delta<0){
  1635.                             that.nextPage();
  1636.                         }
  1637.                     }
  1638.                 });
  1639.             }
  1640.             that.loadForm2();
  1641.             that.rating.init();
  1642.             that.setPaginEvents();
  1643.         },
  1644.         toggleEndlessScroll:function(state) {
  1645.             switch(state){
  1646.                 case 'opinionsList':
  1647.                     (appProperties.engine=='outlet'||appProperties.engine=='galeria') ? false : this.endlessScroll = state;
  1648.                     break;
  1649.                 default:
  1650.                     this.endlessScroll = false;
  1651.             }
  1652.         },
  1653.         addNew:function(){
  1654.             $('#commentForm').submit();
  1655.         },
  1656.         rating: {
  1657.             options: {
  1658.                 isDisabled: false,
  1659.                 canRateAgain: true,
  1660.                 rateMax: 5,
  1661.                 step:true,
  1662.                 sendRequest: false,
  1663.             },
  1664.             el: {},
  1665.             selector: '.rating',
  1666.             init: function() {
  1667.                 var el = $(this.selector);
  1668.                 if(!el.length) {
  1669.                     return;
  1670.                 }
  1671.                 this.el = el;
  1672.                 el.jRating(this.options);
  1673.                 el.find('.jRatingAverage').css('width', '0px');
  1674.             },
  1675.             clear: function() {
  1676.                 $('.jRatingColor, .jRatingAverage, .jRatingBackground, .jStar').remove();
  1677.                 $(this.selector).removeAttr('style');
  1678.             },
  1679.             setCanRateAgain: function(state) {
  1680.                 this.options.canRateAgain = state;
  1681.             },
  1682.             setIsDisabled: function(state) {
  1683.                 this.options.isDisabled = state;
  1684.             }
  1685.         },
  1686.         loadForm2:function() {
  1687.             var that = this;
  1688.             $.get('/store-add-comment.ltr', {}, function(response) {
  1689.                 $('#addCommentForm').html(response);
  1690.                 //that.rating.init();
  1691.                 mig.comments.commentRatingEvent();
  1692.                 mig.validate.opinions();
  1693.             });
  1694.         },
  1695.         submitForm: function() {
  1696.             var form = $('#commentForm');
  1697. //          $.ajax({
  1698. //              type: 'POST',
  1699. //              url: '/store-add-comment.ltr',
  1700. //              data: form.serialize(),
  1701. //              success: function(response) {
  1702. //                  console.log(response);
  1703. //                  if(response == '') {
  1704. //                      form.html('Opinia została dodana');
  1705. //                  }
  1706. //              },
  1707. //              error: function(){}
  1708. //          });
  1709.             form.submit();
  1710.  
  1711.         },
  1712.         setPaginEvents: function() {
  1713.             var that = this;
  1714.             $('.changePageForm').on('submit', function(event) {
  1715.                 event.preventDefault();
  1716.                 var inputPage = $('.activePage', this).val();
  1717.                 that.changePage(inputPage);
  1718.             });
  1719.         },
  1720.         loadForm:function(){
  1721.             $.fancybox({
  1722.                 href:'/store-add-comment.ltr'},{
  1723.                 padding:0,
  1724.                 enableEscapeButton: true,
  1725.                 onComplete:function(html){
  1726.                     $('#description').keyup(function(){
  1727.                         $('#limit span').text(400-$(this).val().length);
  1728.                     }).trigger('keyup');
  1729.                     mig.validate.opinions();
  1730.                     $('#commentForm').attr('href','/store-add-comment.ltr');
  1731.                 }
  1732.             });
  1733.         },
  1734.         nextPage:function(){
  1735.             var lastPage=$('#lastPage');
  1736.             var activePage=$('#activePage');
  1737.             if(parseInt(activePage.val())<parseInt(lastPage.val()) && !this.loading){
  1738.                 activePage.val(parseInt(activePage.val())+1);
  1739.                 this.loadPage({strona:activePage.val(),fragment:'items'});
  1740.             }
  1741.         },
  1742.         loadPage:function(options){
  1743.             var data={
  1744.                 strona:1,
  1745.                 fragment:'list'
  1746.             };
  1747.             $.extend(true,data,options);
  1748.             if(data.fragment=='items'){
  1749.                 $('#loading-page-message').show();
  1750.             }else{
  1751.                 mig.showLoading();
  1752.             }
  1753.             if(!this.loading){
  1754.                 this.loading=true;
  1755.                 var that=this;
  1756.                 $.ajax({
  1757.                     url:'/opinie-o-sklepie.bhtml',
  1758.                     data:data,
  1759.                     success:function(html){
  1760.                         that.loading=false;
  1761.                         mig.log('ŁADOWANIE STRONY: OK');
  1762.                         if(data.fragment=='items'){
  1763.                             $('.ajaxOpinions > ul').append(html);
  1764.                             $('#loading-page-message').hide();
  1765.                         }else{
  1766.                             $('.ajaxOpinions').empty().html(html);
  1767.                             var firstComment = $('.ajaxOpinions li:first');
  1768.                             var offset = $('.ajaxOpinions').offset().top - firstComment.height() - firstComment.css('paddingTop').replace('px', '')*1 - firstComment.css('paddingBottom').replace('px', '')*1;
  1769.                             $.scrollTo(offset);
  1770.                         }
  1771.                         mig.hideLoading();
  1772.                         that.setPaginEvents();
  1773.                     },
  1774.                     error:function(){
  1775.                         that.loading=false;
  1776.                         mobile.log('ŁADOWANIE STRONY: ERROR');
  1777.                         mobile.hideLoading();
  1778.                     }
  1779.                 });
  1780.             }
  1781.         },
  1782.         changePage:function(page){
  1783.             this.loadPage({strona:page});
  1784.         }
  1785.     },
  1786.     productsList:{
  1787.         loading:false,
  1788.         href:false,
  1789.         pathInfo: {},
  1790.         initialLoading:true,
  1791.         pageLoadingOffset: 0,
  1792.         init:function(){
  1793.             var that=this;
  1794.             mig.log('PRODUCTSLIST: INIT');
  1795.  
  1796.             if (that.newUrl && that.newUrl.href) {
  1797.                 var dataHist ={
  1798.                         fragment:'list',
  1799.                         scroll: true,
  1800.                         historyInfo: $.extend(true, {}, that.pathInfo),
  1801.                         saveHistory: true
  1802.                     };
  1803.                 var urlParamsDelimiter = '?';
  1804.                 if(that.isUrlParameterSet(that.newUrl.href)) {
  1805.                     urlParamsDelimiter = '&';
  1806.                 }
  1807.  
  1808.                 if (that.pathInfo.paging.current > 1) {
  1809.                     that.newUrl.href += urlParamsDelimiter+that.pathInfo.paging.name + '=' + that.pathInfo.paging.current;
  1810.                 }
  1811.                 if(that.initialLoading) {
  1812.                     window.history.replaceState(dataHist,null, null);
  1813.                     that.initialLoading = false;
  1814.                 } else {
  1815.                     window.history.replaceState(dataHist,null,that.newUrl.href);
  1816.                 }
  1817.             }
  1818.  
  1819.             if(!that.pathInfo.paging.usePaging){
  1820.                 var that=this;
  1821.                 $(window).bind('scroll', {context:that}, that.productsListScrolling);
  1822.             } else {
  1823.                 $(window).unbind('scroll', that.productsListScrolling);
  1824.             }
  1825.             this.selectedBoxEvents();
  1826.             this.paginationState();
  1827.  
  1828.             $('#main-rotator .scrollable').jScrollPane({showArrows: true, hideFocus: true});
  1829.            
  1830.             this.setPriceSlider();
  1831.             window.onpopstate = function(event) {
  1832.                 if(event.state){
  1833.                     that.ajaxPage(event.state);
  1834.                 }else{
  1835.                     that.ajaxPage();
  1836.                 }
  1837.             };
  1838.  
  1839.             $('#main-rotator').slider({
  1840.                 arrows: false,
  1841.                 autoplaySpeed: 6000,
  1842.                 dots: true
  1843.             });
  1844.  
  1845.             this.backToTop();
  1846.             this.setPaginEvents();
  1847.             this.preview();
  1848.         },
  1849.         preview: function() {
  1850.             // Sizeer 50style
  1851.         },
  1852.         setPaginEvents: function() {
  1853.             var that = this;
  1854.             $('.changePageForm').on('submit', function(event) {
  1855.                 event.preventDefault();
  1856.                 var inputPage = $('.activePage', this).val();
  1857.                 that.changePage(inputPage);
  1858.             });
  1859.         },
  1860.         productsListScrolling: function(event) {
  1861.             if(!event.data.context.loading){
  1862.                 var delta=$('.footer-box').offset().top-$(window).scrollTop()-$(window).height()-($( window ).height()/2);
  1863.                 if(delta<0){
  1864.                     event.data.context.nextPage();
  1865.                 }
  1866.             }
  1867.         },
  1868.         /* fired when page is loaded */
  1869.         paginationState:function() {
  1870.             if(this.pathInfo.paging.usePaging) {
  1871.                 $('.paging').show();
  1872.             } else {
  1873.                 $('.pagination-top').hide();
  1874.                 $('.paging').hide();
  1875.                 $('.paging-on-page').hide();
  1876.             }
  1877.         },
  1878.         generateAjaxURL: function () {
  1879.             var that = this;
  1880.             var link = that.base;
  1881.             var params = [];
  1882.             for (i = 0; i < that.pathInfo.filters.length; i++) {
  1883.                 filter = that.pathInfo.filters[i];
  1884.                 for (j = 0; j < filter.values.length; j++) {
  1885.                     params[params.length] = filter.filter + "=" + filter.values[j];
  1886.                 }
  1887.             }
  1888.             for (i = 0; i < that.pathInfo.nodes.length; i++) {
  1889.                 params[params.length] = "node=" + that.pathInfo.nodes[i];
  1890.             }
  1891.             params[params.length] = that.pathInfo.paging.name + '=' + that.pathInfo.paging.current;
  1892.  
  1893.             if (that.pathInfo.preview) {
  1894.                 params[params.length] = "preview=true";
  1895.                 params[params.length] = "randomPreviewSeed=" + Math.random();
  1896.             }
  1897.  
  1898.             params[params.length] = "iop=" + that.pathInfo.paging.itemsOnPage;
  1899.             params[params.length] = "usePaging=" + that.pathInfo.paging.usePaging;
  1900.  
  1901.             if(link.indexOf('?') === -1)
  1902.                 return link + "?" + params.join("&");
  1903.             else
  1904.                 return link + "&" + params.join("&");
  1905.         },
  1906.         disableFilter: function (name, value) {
  1907.             var that = this;
  1908.             for (i = 0; i < that.pathInfo.filters.length; i++) {
  1909.                 filter = that.pathInfo.filters[i];
  1910.                 if (filter.filter === name) {
  1911.                     if (filter.values.length == 1) {
  1912.                         if (filter.values[0] == value && that.pathInfo.filters.length > 1) {
  1913.                             that.pathInfo.filters.splice(i, 1);
  1914.                         }
  1915.                         else if (filter.values[0] == value  && that.pathInfo.filters.length == 1) {
  1916.                             that.pathInfo.filters = [];
  1917.                         }
  1918.                     }
  1919.                     else {
  1920.                         var index = $.inArray(value, filter.values);
  1921.                         if (index >= 0) {
  1922.                             filter.values.splice(index, 1);
  1923.                         }
  1924.                     }
  1925.                 }
  1926.             }
  1927.         },
  1928.         addFilter: function (name, value) {
  1929.             var that = this;
  1930.             var added = false;
  1931.             for (i = 0; i < that.pathInfo.filters.length; i++) {
  1932.                 filter = that.pathInfo.filters[i];
  1933.                 if (filter.filter === name) {
  1934.                     filter.values[filter.values.length] = value;
  1935.                     added = true;
  1936.                     break;
  1937.                 }
  1938.             }
  1939.  
  1940.             if (!added) {
  1941.                 that.pathInfo.filters[that.pathInfo.filters.length] = {
  1942.                     "values": [value],
  1943.                     "filter": name
  1944.                 };
  1945.             }
  1946.         },
  1947.         replaceFilter: function (name, value) {
  1948.             var that = this;
  1949.             var added = false;
  1950.             for (i = 0; i < that.pathInfo.filters.length; i++) {
  1951.                 filter = that.pathInfo.filters[i];
  1952.                 if (filter.filter === name) {
  1953.                     filter.values = [value];
  1954.                     added = true;
  1955.                     break;
  1956.                 }
  1957.             }
  1958.  
  1959.             if (!added) {
  1960.                 that.pathInfo.filters[that.pathInfo.filters.length] = {
  1961.                     "values": [value],
  1962.                     "filter": name
  1963.                 };
  1964.             }
  1965.         },
  1966.         disableWholeFilter: function (name) {
  1967.             var that = this;
  1968.             for (i = 0; i < that.pathInfo.filters.length; i++) {
  1969.                 filter = that.pathInfo.filters[i];
  1970.                 if (filter.filter === name) {
  1971.                     if (that.pathInfo.filters.length > 1) {
  1972.                         that.pathInfo.filters.splice(i, 1);
  1973.                     }
  1974.                     else if (that.pathInfo.filters.length == 1) {
  1975.                         that.pathInfo.filters = [];
  1976.                     }
  1977.                 }
  1978.             }
  1979.         },
  1980.         setPage: function (nr) {
  1981.             this.pathInfo.paging.current = nr/1;
  1982.         },
  1983.         setLoadingOnScroll: function(state) {
  1984.             var that = this;
  1985.             that.pathInfo.paging.usePaging=!state;
  1986.             if(state !== false) {
  1987.                 mig.help.listen();
  1988.                 this.init();
  1989.                 if (that.pathInfo.paging.current/1 > 1) {
  1990.                     that.pathInfo.paging.current = 1;
  1991.                     this.loadPage();
  1992.                 }
  1993.                 else {
  1994.                     that.pathInfo.paging.itemsOnPage = 100;
  1995.                     this.loadPage({scroll: false});
  1996.                 }
  1997.                 that.nextPage();
  1998.                 that.nextPage();
  1999.             } else {
  2000.                 mig.help.kill();
  2001.             }
  2002.         },
  2003.         isLoadingOnScroll: function() {
  2004.             return !this.pathInfo.paging.usePaging;
  2005.         },
  2006.         highlightLimitOptionAll:function() {
  2007.             $('.paging-on-page a').removeClass('current');
  2008.             $('.paging-on-page .limit-all').addClass('current');
  2009.         },
  2010.         setItemsOnPage: function(itemsNumber, button) {
  2011.             var that = this;
  2012.             if (!$(button).hasClass('current')) {
  2013.                 that.pathInfo.paging.itemsOnPage = itemsNumber;
  2014.                 this.setPage(1);
  2015.                 this.setLoadingOnScroll(false);
  2016.                 this.init();
  2017.                 this.loadPage();
  2018.             }
  2019.         },
  2020.         newUrl:false,
  2021.         setNewUrl:function(data){
  2022. //          if(history.pushState) {
  2023. //              var title = $('title').text();
  2024. //              if($.isNumeric(title.split(' ').slice(-1))) {
  2025. //                  title = (title.split(' ').slice(0, -2)).join(' ');
  2026. //              }
  2027. //              history.pushState(null, null, '?strona=' + page);
  2028. //              document.title = title + ' - ' + page;
  2029. //          }
  2030.             if(this.newUrl && this.newUrl.href!=document.location.pathname){
  2031.                 try {
  2032.                     if (data.saveHistory) {
  2033.                         window.history.pushState(data,null,this.newUrl.href);
  2034.                     }
  2035.                 } catch(err) {
  2036.                     document.location.pathname = this.newUrl.href;
  2037.                 }
  2038.                 this.newUrl=false;
  2039.             }
  2040.         },
  2041.         setPriceSlider:function(){
  2042.             if ($("#priceSlider").length > 0 && !$("#priceSlider").data('initialized')) {
  2043.                 $("#priceSlider").data('initialized', true);
  2044.                 $("#priceSlider").noUiSlider({
  2045.                     range: {
  2046.                         'min': [parseInt($('#priceMin').val())],
  2047.                         'max': [parseInt($('#priceMax').val())]
  2048.                     },
  2049.                     start: [parseInt($('#spanMin').text()), parseInt($('#spanMax').text())],
  2050.                     step: 1
  2051.                 });
  2052.                 $("#priceSlider").on('slide', function(){
  2053.                     var min = Math.round($(this).val()[0]);
  2054.                     var max = Math.round($(this).val()[1]);
  2055.                     $("#min").val(min);
  2056.                     $("#spanMin").text(min);
  2057.                     $("#max").val(max);
  2058.                     $("#spanMax").text(max);
  2059.                 });
  2060.             }
  2061.         },
  2062.         selectedBoxEvents:function(){
  2063.             var that=this;
  2064.             $('.selectedBox a').click(function(e){
  2065.                 that.setPage(1);
  2066.                 if($(this).hasClass('all')){
  2067.                     that.removeAllFilter();
  2068.                 }else if($(this).hasClass('price')){
  2069.                     that.removePriceFilter();
  2070.                 }else{
  2071.                     that.disableFilter($(this).attr('data-name'),$(this).attr('data-value'));
  2072.                     that.loadPage();
  2073.                 }
  2074.                 $(this).fadeOut();
  2075.                 e.preventDefault();
  2076.             });
  2077.         },
  2078.         removePriceFilter:function(){
  2079.             $('#min, #max').val('');
  2080.             this.setPriceFilter();
  2081.             this.loadPage();
  2082.         },
  2083.         removeAllFilter:function(){
  2084.             var that = this;
  2085.             $('.selectedBox').fadeOut();
  2086.             that.pathInfo.filters = [];
  2087.             $('#min, #max').val('');
  2088.             that.setPriceFilter();
  2089.             mig.log('USUNIĘCIE WSZYSTKICH FILTRÓW');
  2090.             this.loadPage();
  2091.         },
  2092.         nextPage:function(){
  2093.             var that = this;
  2094.             if(that.pathInfo.paging.current/1<that.pathInfo.paging.max/1 && !this.loading){
  2095.                 that.setPage(that.pathInfo.paging.current/1 + 1);
  2096.                 this.loadPage({fragment:'items'});
  2097.             }
  2098.         },
  2099.         setPriceFilter: function() {
  2100.             var that = this;
  2101.             this.setPage(1);
  2102.             if($('#min').val()) {
  2103.                 that.replaceFilter('priceFrom', $('#min').val());
  2104.             } else {
  2105.                 that.disableWholeFilter('priceFrom');
  2106.             }
  2107.             if($('#max').val()) {
  2108.                 that.replaceFilter('priceTo', $('#max').val());
  2109.             } else {
  2110.                 that.disableWholeFilter('priceTo');
  2111.             }
  2112.         },
  2113.         changePrice:function(){
  2114.             mig.log('ZMIANA PRZEDZIAŁU CENOWEGO');
  2115.             this.setPriceFilter();
  2116.             this.loadPage();
  2117.         },
  2118.         changePage:function(page){
  2119.             mig.log('ZMIANA NR STRONY');
  2120.             var that = this;
  2121.             that.setPage(page);
  2122.             this.loadPage();
  2123.         },
  2124.         changeFilter:function(select){
  2125.             var value = $(select).data('value');
  2126.             var param = $(select).data('name');
  2127.             if($(select).hasClass('disabled')) {
  2128.                 return false;
  2129.             } else {
  2130.                 this.setPage(1);
  2131.                 if ($(select).hasClass('selected'))
  2132.                     this.disableFilter(param, value);
  2133.                 else
  2134.                     this.addFilter(param, value);
  2135.                 this.loadPage();
  2136.             }
  2137.         },
  2138.         changeSort:function(select){
  2139.             var that = this;
  2140.             var order = $(select).val().split('|');
  2141.             that.replaceFilter("sortF", order[0]);
  2142.             that.replaceFilter("sortO", order[1]);
  2143.             this.setPage(1);
  2144.             this.loadPage();
  2145.         },
  2146.         loadPage:function(options){
  2147.             if(!this.loading){
  2148.                 this.loading=true;
  2149.                 var data={
  2150.                     fragment:'list',
  2151.                     scroll: true,
  2152.                     historyInfo: null,
  2153.                     saveHistory: true
  2154.                 };
  2155.  
  2156.                 $.extend(true,data,options);
  2157.  
  2158.                 if(data.fragment=='items'){
  2159.                     $('#loading-page-message').show();
  2160.                 }else{
  2161.                     mig.showLoading();
  2162.                 }
  2163.                 this.ajaxPage(data);
  2164.             }
  2165.         },
  2166.         isUrlParameterSet:function(url) {
  2167.             return url && url.split('?').length>=2;
  2168.         },
  2169.         ajaxPage:function(data){
  2170.             var that=this;
  2171.             if(data) {
  2172.                 $.ajax({
  2173.                     url:that.generateAjaxURL(),
  2174.                     data:data,
  2175.                     traditional:true,
  2176.                     success:function(html){
  2177.                         mig.log('ŁADOWANIE STRONY: OK');
  2178.                         if (data && data.historyInfo) {
  2179.                             setTimeout(function() {
  2180.                                 that.pathInfo = data.historyInfo;
  2181.                                 that.loadPage({saveHistory: false});
  2182.                             }, 150);
  2183.                         }
  2184.                         else {
  2185.                             if(data.fragment=='items'){
  2186.                                 $('#ajax-products-list .simpleList ul').append(html);
  2187.                                 mig.lazyLoad('#ajax-products-list');
  2188.                                 $('#loading-page-message').hide();
  2189.                             }else{
  2190.                                 $('#ajax-products-list').empty().html(html);
  2191.  
  2192.                                 mig.lazyLoad('#ajax-products-list');
  2193.                                 if (data.scroll && $('#filter-box').length > 0)
  2194.                                     $.scrollTo($('#filter-box').offset().top-$('#top-links-header').height()-that.pageLoadingOffset,200);
  2195.                                 that.setPriceSlider();
  2196.                                 $('#ajax-products-list .selectBox').selectbox();
  2197.                                 that.selectedBoxEvents();
  2198.                                 var urlParamsDelimiter = '?';
  2199.                                 if(that.isUrlParameterSet(that.newUrl.href)) {
  2200.                                     urlParamsDelimiter = '&';
  2201.                                 }
  2202.  
  2203.                                 if (that.pathInfo.paging.current > 1) {
  2204.                                     that.newUrl.href += urlParamsDelimiter+that.pathInfo.paging.name + '=' + that.pathInfo.paging.current;
  2205.                                 }
  2206.  
  2207.                                 if (data.saveHistory) {
  2208.                                     data.historyInfo = $.extend(true, {}, that.pathInfo);
  2209.                                 }
  2210.  
  2211.                                 that.setNewUrl(data);
  2212.                             }
  2213.                             $(window).resize();
  2214.                         }
  2215.                     },
  2216.                     complete:function(){
  2217.                         that.loading=false;
  2218.                         mig.hideLoading();
  2219.    
  2220. //                      setTimeout(function() {
  2221. //                          $('.simpleList .item .img').preview();
  2222. //                      }, 100);
  2223.                         /* TODO: Na galerii nie ma podglodu wywoływać w odpowiednim js */
  2224.    
  2225.                         that.paginationState();
  2226.                         if(that.isLoadingOnScroll()) {
  2227.                             that.highlightLimitOptionAll();
  2228.                         }
  2229.                         that.setPaginEvents();
  2230.                     },
  2231.                     error:function(){
  2232.                         mig.log('ŁADOWANIE STRONY: ERROR');
  2233.                     }
  2234.                 });
  2235.             }
  2236.         },
  2237.         backToTop: function(){
  2238.             var backButton = $('#back-to-top');
  2239.             checkPosition();
  2240.             $(window).bind('scroll', function(){
  2241.                 checkPosition();
  2242.             });
  2243.  
  2244.             function checkPosition() {
  2245.                 var prodBox = $('.products');
  2246.                 if (prodBox) {
  2247.                     var height = prodBox.offset().top + prodBox.height() + backButton.height();
  2248.                     var scroll = $(window).scrollTop() + $(window).height();
  2249.                     var state = height - scroll;
  2250.                     if (state >= -100) {
  2251.                         setFixed();
  2252.                     } else {
  2253.                         setNormal();
  2254.                     }
  2255.                 }
  2256.             }
  2257.             function setFixed() {
  2258.                 backButton.addClass('fixed');
  2259.                 backButton.removeClass('normal');
  2260.             }
  2261.             function setNormal() {
  2262.                 backButton.addClass('normal');
  2263.                 backButton.removeClass('fixed');
  2264.             }
  2265.  
  2266.             $('#back-to-top a').on('click',function(){
  2267.                 $.scrollTo(0,200);
  2268.             });
  2269.         }
  2270.     },
  2271.     account:{
  2272.         pageType:'',
  2273.         init:function(){
  2274.             switch (this.pageType) {
  2275.                 case 'address':
  2276.                     mig.validate.address();
  2277.                     mig.splittedPostalCode();
  2278.                 break;
  2279.                 case 'password':
  2280.                     mig.validate.password();
  2281.                 break;
  2282.                 case 'orders':
  2283.                     //
  2284.                 break;
  2285.                 default:
  2286.             }
  2287.         },
  2288.         sendAddress:function(){
  2289.             if($('#userForm').valid()){
  2290.                 mig.log('sendAddress');
  2291.                 mig.showLoading();
  2292.                 $('#userForm').submit();
  2293.             }
  2294.         },
  2295.         sendPassword:function(){
  2296.             if($('#passwordForm').valid()){
  2297.                 mig.log('sendPassword');
  2298.                 mig.showLoading();
  2299.                 $('#passwordForm').submit();
  2300.             }
  2301.         }
  2302.     },
  2303.     validate:{
  2304.         opinions:function(){
  2305.             $('#commentForm').validate({
  2306.                 rules:{
  2307.                     author:mig.validate.rules.opinionAuthor,
  2308.                     title:mig.validate.rules.opinionTitle,
  2309.                     description:mig.validate.rules.opinionDescription
  2310.                 },
  2311.                 messages:{
  2312.                     author:mig.validate.messages.opinionAuthor,
  2313.                     title:mig.validate.messages.opinionTitle,
  2314.                     description:mig.validate.messages.opinionDescription
  2315.                 },
  2316.                 submitHandler: function(form) {
  2317.                     $(form).ajaxSubmit({
  2318.                         url:'/store-add-comment.ltr',
  2319.                         data:{
  2320.                             'F_ACTION':'SAVE'
  2321.                         },
  2322.                         beforeSubmit:function(){
  2323.                             $('#commentForm .button').text(translations['loading']);
  2324.                         },
  2325.                         success:function(){
  2326.                             $('.addOpinion').remove();
  2327.                             $('#addOpinions .form').remove();
  2328.                             $('#addOpinions .formSuccess').show();
  2329.                         }
  2330.                     });
  2331.                 },
  2332.                 ignore:mig.validate.ignore,
  2333.                 errorElement: mig.validate.errorElement,
  2334.                 errorPlacement: mig.validate.errorPlacement,
  2335.                 success:mig.validate.success,
  2336.                 showErrors: mig.validate.showErrors
  2337.             });
  2338.         },
  2339.         productOpinions: function () {
  2340.             $("#customerCommentsForm").validate({
  2341.                 rules:{
  2342.                     author:mig.validate.rules.opinionAuthor
  2343.                 },
  2344.                 messages:{
  2345.                     author:mig.validate.messages.opinionAuthor
  2346.                 },
  2347.                 ignore: ".ignored"
  2348.             });
  2349.             $("#customerCommentsForm input.title").each(function () {
  2350.                 $(this).rules("add", {
  2351.                     required: true,
  2352.                     messages: mig.validate.messages.opinionTitle
  2353.                 });
  2354.             });
  2355.             $("#customerCommentsForm textarea").each(function () {
  2356.                 $(this).rules("add", {
  2357.                     required: true,
  2358.                     messages: mig.validate.messages.opinionDescription
  2359.                 });
  2360.             });
  2361.             $("#customerCommentsForm input.sendRating").each(function () {
  2362.                 $(this).rules("add", {
  2363.                     required: true,
  2364.                     messages: mig.validate.messages.opinionMark
  2365.                 });
  2366.             });
  2367.         },
  2368. /*      productAsk: function() {
  2369.             $('#askForm .errorBox').empty();
  2370.             $('#askForm').validate({
  2371.                 rules:{
  2372.                     "senderName": mig.validate.rules.firstname,
  2373.                     "senderSurName": mig.validate.rules.surname,
  2374.                     "senderEmail": mig.validate.rules.login,
  2375.                     "question": mig.validate.rules.productAskQuestion
  2376.                 },
  2377.                 messages:{
  2378.                     "senderName": mig.validate.messages.firstname,
  2379.                     "senderSurName": mig.validate.messages.surname,
  2380.                     "senderEmail": mig.validate.messages.login,
  2381.                     "question": mig.validate.messages.productAskQuestion
  2382.                 },
  2383.                 ignore: mig.validate.ignore,
  2384.                 errorPlacement: function(error, element) {
  2385.                     if($('#askForm .errorBox .alertRow').length > 0){
  2386.                         var isEmpty = 1;
  2387.                         $('#askForm .errorBox .alertRow').each(function(index, element){
  2388.                             ($(this).text()===error.text()) ? isEmpty = 0: false;
  2389.                         })
  2390.                         if(isEmpty){$('#askForm .errorBox').append('<span><div class="alertRow">' + error.text() + '</div></span>');}
  2391.                     }else{
  2392.                         $('#askForm .errorBox').append('<span><div class="alertRow">' + error.text() + '</div></span>');
  2393.                     }}
  2394.             });
  2395.         },*/
  2396.         login:function(){
  2397.             $('#loginForm').validate({
  2398.                 rules:{
  2399.                     "j_username":mig.validate.rules.login,
  2400.                     "j_password":mig.validate.rules.password
  2401.                 },
  2402.                 messages:{
  2403.                     "j_username":mig.validate.messages.login,
  2404.                     "j_password":mig.validate.messages.password
  2405.                 },
  2406.                 ignore:mig.validate.ignore,
  2407.                 errorElement: mig.validate.errorElement,
  2408.                 errorPlacement: mig.validate.errorPlacement,
  2409.                 success:mig.validate.success,
  2410.                 showErrors: mig.validate.showErrors
  2411.             });
  2412.         },
  2413.         sendAskAbout:function(){
  2414.             $('#askForm').validate({
  2415.                 rules:{
  2416.                     "senderName": mig.validate.rules.firstname,
  2417.                     "senderSurName": mig.validate.rules.surname,
  2418.                     "senderEmail": mig.validate.rules.login,
  2419.                     "question": mig.validate.rules.productAskQuestion
  2420.                 },
  2421.                 messages:{
  2422.                     "senderName": mig.validate.messages.firstname,
  2423.                     "senderSurName": mig.validate.messages.surname,
  2424.                     "senderEmail": mig.validate.messages.login,
  2425.                     "question": mig.validate.messages.productAskQuestion
  2426.                 },
  2427.                 ignore:mig.validate.ignore,
  2428.                 errorElement: mig.validate.errorElement,
  2429.                 errorPlacement: mig.validate.errorPlacement,
  2430.                 success:mig.validate.success,
  2431.                 showErrors: mig.validate.showErrors
  2432.             });
  2433.         },
  2434.         register:function(){
  2435.             if(mig.siteProperties.maskPhone){
  2436.                 $("input[name$='phone']").bind('focus blur keyup',function(){
  2437.                     mig.cart.checkPhoneFormat();
  2438.                 });
  2439.             }
  2440.             $('#registrationForm').validate({
  2441.                 rules:{
  2442.                     "account.userName":mig.validate.rules.login,
  2443.                     "account.newPassword":mig.validate.rules.password,
  2444.                     "password2":mig.validate.rules.passwordRepeat,
  2445.                     "address.firstname":mig.validate.rules.firstname,
  2446.                     "address.surname":mig.validate.rules.surname,
  2447.                     "address.phoneType":mig.validate.rules.phoneType,
  2448.                     "address.phone":mig.validate.rules.phone,
  2449.                     "address.gender":mig.validate.rules.gender,
  2450.                     "acceptTermsAndConditions":mig.validate.rules.termsAccepted
  2451.                 },
  2452.                 messages:{
  2453.                     "account.userName":mig.validate.messages.login,
  2454.                     "account.newPassword":mig.validate.messages.password,
  2455.                     "password2":mig.validate.messages.passwordRepeat,
  2456.                     "address.firstname":mig.validate.messages.firstname,
  2457.                     "address.surname":mig.validate.messages.surname,
  2458.                     "address.phoneType":mig.validate.messages.phoneType,
  2459.                     "address.phone":mig.validate.messages.phone,
  2460.                     "address.gender":mig.validate.messages.gender,
  2461.                     "acceptTermsAndConditions":mig.validate.messages.termsAccepted
  2462.                 },
  2463.                 ignore:mig.validate.ignore,
  2464.                 errorElement: mig.validate.errorElement,
  2465.                 errorPlacement: mig.validate.errorPlacement,
  2466.                 success:mig.validate.success,
  2467.                 showErrors: mig.validate.showErrors,
  2468.                 invalidHandler: function(event, validator){
  2469.                     if($('.cartPath ').length){
  2470.                         var errorText = $.map(validator.invalid, function(text, id) {
  2471.                             return text;
  2472.                         });
  2473.                         mig.google.push(['_trackEvent','Checkout - rejestracja','Formularz rejestracji',errorText.join(', '),0]);
  2474.                         mig.google.push(['_trackEvent','Checkout - rejestracja','Formularz rejestracji','Nieudana rejestracja',0]);
  2475.                     }
  2476.                 }
  2477.             });
  2478.         },
  2479.         address:function(){
  2480.             mig.cart.setPhoneType(null);
  2481.             if(mig.siteProperties.maskPhone){
  2482.                 $("input[name$='phone']").bind('focus blur keyup',function(){
  2483.                     mig.cart.checkPhoneFormat();
  2484.                 });
  2485.             }
  2486.             if(mig.siteProperties.maskZipCode){
  2487.                 $('input[name*="postalCode"]').bind('focus blur keyup',function(){
  2488.                     mig.cart.checkPostalCodeFormat($(this));
  2489.                 });
  2490.             }
  2491.             $('#order, #userForm').validate({
  2492.                 rules:{
  2493.                     "frontUser.email":mig.validate.rules.login,
  2494.                     "deliveryAddress.firstname":mig.validate.rules.firstname,
  2495.                     "deliveryAddress.surname":mig.validate.rules.surname,
  2496.                     "deliveryAddress.phoneType":mig.validate.rules.phoneType,
  2497.                     "deliveryAddress.phone":mig.validate.rules.phone,
  2498.                     "deliveryAddress.street":mig.validate.rules.street,
  2499.                     "deliveryAddress.houseNumber":mig.validate.rules.houseNumber,
  2500.                     "deliveryAddress.postalCode":mig.validate.rules.postalCode,
  2501.                     "deliveryAddress.locality":mig.validate.rules.locality,
  2502.  
  2503.                     "frontUser.agreement":mig.validate.rules.termsAccepted,
  2504.                     "agreement":mig.validate.rules.termsAccepted,
  2505.  
  2506.                     "frontUser.address.firstname":mig.validate.rules.firstname,
  2507.                     "frontUser.address.surname":mig.validate.rules.surname,
  2508.                     "frontUser.address.phoneType":mig.validate.rules.phoneType,
  2509.                     "frontUser.address.phone":mig.validate.rules.phone,
  2510.                     "frontUser.address.street":mig.validate.rules.street,
  2511.                     "frontUser.address.houseNumber":mig.validate.rules.houseNumber,
  2512.                     "frontUser.address.postalCode":mig.validate.rules.postalCode,
  2513.                     "frontUser.address.locality":mig.validate.rules.locality,
  2514.  
  2515.                     "address.firstname":mig.validate.rules.firstname,
  2516.                     "address.surname":mig.validate.rules.surname,
  2517.                     "address.phoneType":mig.validate.rules.phoneType,
  2518.                     "address.phone":mig.validate.rules.phone,
  2519.                     "address.street":mig.validate.rules.street,
  2520.                     "address.houseNumber":mig.validate.rules.houseNumber,
  2521.                     "address.postalCode":mig.validate.rules.postalCode,
  2522.                     "address.locality":mig.validate.rules.locality,
  2523.  
  2524.                     "invoiceAddress.name":mig.validate.rules.name,
  2525.                     "invoiceAddress.nip":mig.validate.rules.nip,
  2526.                     "invoiceAddress.phoneType":mig.validate.rules.phoneType,
  2527.                     "invoiceAddress.phone":mig.validate.rules.phone,
  2528.                     "invoiceAddress.street":mig.validate.rules.street,
  2529.                     "invoiceAddress.houseNumber":mig.validate.rules.houseNumber,
  2530.                     "invoiceAddress.postalCode":mig.validate.rules.postalCode,
  2531.                     "invoiceAddress.locality":mig.validate.rules.locality
  2532.                 },
  2533.                 messages:{
  2534.                     "frontUser.email":mig.validate.messages.login,
  2535.                     "deliveryAddress.firstname":mig.validate.messages.firstname,
  2536.                     "deliveryAddress.surname":mig.validate.messages.surname,
  2537.                     "deliveryAddress.phoneType":mig.validate.messages.phoneType,
  2538.                     "deliveryAddress.phone":mig.validate.messages.phone,
  2539.                     "deliveryAddress.street":mig.validate.messages.street,
  2540.                     "deliveryAddress.houseNumber":mig.validate.messages.houseNumber,
  2541.                     "deliveryAddress.postalCode":mig.validate.messages.postalCode,
  2542.                     "deliveryAddress.locality":mig.validate.messages.locality,
  2543.  
  2544.                     "frontUser.agreement":mig.validate.messages.termsAccepted,
  2545.                     "agreement":mig.validate.messages.termsAccepted,
  2546.  
  2547.                     "frontUser.address.firstname":mig.validate.messages.firstname,
  2548.                     "frontUser.address.surname":mig.validate.messages.surname,
  2549.                     "frontUser.address.phoneType":mig.validate.messages.phoneType,
  2550.                     "frontUser.address.phone":mig.validate.messages.phone,
  2551.                     "frontUser.address.street":mig.validate.messages.street,
  2552.                     "frontUser.address.houseNumber":mig.validate.messages.houseNumber,
  2553.                     "frontUser.address.postalCode":mig.validate.messages.postalCode,
  2554.                     "frontUser.address.locality":mig.validate.messages.locality,
  2555.  
  2556.                     "address.firstname":mig.validate.messages.firstname,
  2557.                     "address.surname":mig.validate.messages.surname,
  2558.                     "address.phoneType":mig.validate.messages.phoneType,
  2559.                     "address.phone":mig.validate.messages.phone,
  2560.                     "address.street":mig.validate.messages.street,
  2561.                     "address.houseNumber":mig.validate.messages.houseNumber,
  2562.                     "address.postalCode":mig.validate.messages.postalCode,
  2563.                     "address.locality":mig.validate.messages.locality,
  2564.  
  2565.                     "invoiceAddress.name":mig.validate.messages.name,
  2566.                     "invoiceAddress.nip":mig.validate.messages.nip,
  2567.                     "invoiceAddress.phoneType":mig.validate.messages.phoneType,
  2568.                     "invoiceAddress.phone":mig.validate.messages.phone,
  2569.                     "invoiceAddress.street":mig.validate.messages.street,
  2570.                     "invoiceAddress.houseNumber":mig.validate.messages.houseNumber,
  2571.                     "invoiceAddress.postalCode":mig.validate.messages.postalCode,
  2572.                     "invoiceAddress.locality":mig.validate.messages.locality
  2573.                 },
  2574.                 ignore:mig.validate.ignore,
  2575.                 errorElement: mig.validate.errorElement,
  2576.                 errorPlacement: mig.validate.errorPlacement,
  2577.                 success:mig.validate.success,
  2578.                 showErrors: mig.validate.showErrors,
  2579.                 invalidHandler: function(event, validator){
  2580.                     if($('#order').length){
  2581.                         var errorText = $.map(validator.invalid, function(text, id) {
  2582.                             return text;
  2583.                         });
  2584.                         mig.google.push(['_trackEvent','Checkout - dane adresowe','Formularz danych adresowych',errorText.join(', '),0]);
  2585.                         mig.google.push(['_trackEvent','Checkout - dane adresowe','Formularz danych adresowych','Nieudane wypełnienie',0]);
  2586.                     }
  2587.                 }
  2588.             });
  2589.         },
  2590.         password:function(){
  2591.             $('#passwordForm').validate({
  2592.                 rules:{
  2593.                     "oldPassword":mig.validate.rules.passwordOld,
  2594.                     "newPassword":mig.validate.rules.password,
  2595.                     "repeatNewPassord":mig.validate.rules.passwordRepeat
  2596.                 },
  2597.                 messages:{
  2598.                     "oldPassword":mig.validate.messages.passwordOld,
  2599.                     "newPassword":mig.validate.messages.password,
  2600.                     "repeatNewPassord":mig.validate.messages.passwordRepeat
  2601.                 },
  2602.                 ignore:mig.validate.ignore,
  2603.                 errorElement: mig.validate.errorElement,
  2604.                 errorPlacement: mig.validate.errorPlacement,
  2605.                 success:mig.validate.success,
  2606.                 showErrors: mig.validate.showErrors
  2607.             });
  2608.         },
  2609.         passwordReminder:function(){
  2610.             $('#passwordRemindForm').validate({
  2611.                 rules:{
  2612.                     "mail":mig.validate.rules.login
  2613.                 },
  2614.                 messages:{
  2615.                     "mail":mig.validate.messages.login
  2616.                 },
  2617.                 ignore:mig.validate.ignore,
  2618.                 errorElement: mig.validate.errorElement,
  2619.                 errorPlacement: mig.validate.errorPlacement,
  2620.                 success:mig.validate.success,
  2621.                 showErrors: mig.validate.showErrors,
  2622.                 submitHandler: function(form) {
  2623.                     mig.showLoading();
  2624.                     $.ajax({
  2625.                         url:'/password-reminder-for-customer.ltr?'+$(form).serialize(),
  2626.                         data:{back:1},
  2627.                         success:function(html){
  2628.                             mig.hideLoading()
  2629.                             $('#passwordRemindPopup .form').hide();
  2630.                             $('#passwordRemindPopup .formSuccess').show();
  2631.                         }
  2632.                     });
  2633.                 }
  2634.             });
  2635.         },
  2636.         errorElement:"span",
  2637.         rules:{
  2638.             login:{
  2639.                 required:true,
  2640.                 email:true
  2641.             },
  2642.             passwordOld:{
  2643.                 required:true
  2644.             },
  2645.             password:{
  2646.                 required:true,
  2647.                 minlength: 5
  2648.             },
  2649.             passwordRepeat:{
  2650.                 required:true,
  2651.                 equalTo: "#password"
  2652.             },
  2653.             firstname:{
  2654.                 required:true
  2655.             },
  2656.             surname:{
  2657.                 required:true
  2658.             },
  2659.             name:{
  2660.                 required:true
  2661.             },
  2662.             birthDate:{
  2663.                 required:true
  2664.             },
  2665.             nip:{
  2666.                 required:true
  2667.             },
  2668.             postalCode:{
  2669.                 required:true,
  2670.                 zipCode:true
  2671.             },
  2672.             phone:{
  2673.                 required: true,
  2674.                 phone:true
  2675.             },
  2676.             phoneType:{
  2677.                 required: true
  2678.             },
  2679.             locality:{
  2680.                 required:true
  2681.             },
  2682.             street:{
  2683.                 required:true
  2684.             },
  2685.             houseNumber:{
  2686.                 required:true
  2687.             },
  2688.             gender:{
  2689.                 required:true
  2690.             },
  2691.             termsAccepted:{
  2692.                 required:true,
  2693.             },
  2694.             shopCode:{
  2695.                 required: true,
  2696.                 minlength:2
  2697.             },
  2698.             opinionAuthor:{
  2699.                 required:true
  2700.             },
  2701.             opinionTitle:{
  2702.                 required:true
  2703.             },
  2704.             opinionDescription:{
  2705.                 required:true
  2706.             },
  2707.             deliveryType: {
  2708.                 required: true,
  2709.                 minlength: 2
  2710.             },
  2711.             paymentType: {
  2712.                 required: true,
  2713.                 minlength: 2
  2714.             },
  2715.             productAskQuestion: {
  2716.                 required: true,
  2717.             }
  2718.         },
  2719.         messages:{},
  2720.         ignore:'.ignore',
  2721.         showErrors:function(errorMap, errorList) {
  2722.             this.defaultShowErrors();
  2723.         },
  2724.         success:function(label){
  2725.             /*
  2726.             if(label.parent().hasClass('error')){
  2727.                 label.parent().addClass('ok').removeClass('error');
  2728.             }
  2729.             label.remove();
  2730.             */
  2731.         },
  2732.         errorPlacement:function(error, element) {
  2733.             element.parent().parent().find('div.error').append(error);
  2734.         },
  2735.         methods:{
  2736.             phone:function(value, element){
  2737.                 return /\d{2}-\d{3}-\d{2}-\d{2}/.test(value) || /\d{3}-\d{3}-\d{3}/.test(value) || /\d{9}/.test(value);
  2738.             },
  2739.             zipCode:function(value, element){
  2740.                 if(mig.siteProperties.maskZipCode){
  2741.                     return /\d{2}-\d{3}/.test(value);
  2742.                 }
  2743.                 else {
  2744.                     return /\d{5}/.test(value);
  2745.                 }
  2746.                 return true;
  2747.             }
  2748.         }
  2749.     },
  2750.     google:{
  2751.         active:true,
  2752.         tracker:false,
  2753.         tagManegerId:false,
  2754.         page:false,
  2755.         transaction:[],
  2756.         voucherState:'',
  2757.         bondState:'',
  2758.         registeredUser:[],
  2759.         userCardClub:false,
  2760.         userNewsletter:false,
  2761.         push:function(data){
  2762.             try{
  2763.                 window._gaq.push(data);
  2764.                 //console.log('[DONE] ' + data);
  2765.             }catch(e){
  2766.                 mig.log('push Error');
  2767.             }
  2768.         },
  2769.         analytics:function(data){
  2770.             var that = this;
  2771.  
  2772.             var domain = window.location.hostname.split('.');
  2773.             if(domain.length > 2) {
  2774.                 domain.shift();
  2775.             }
  2776.             domain = domain.join('.');
  2777.  
  2778.             if(this.tracker && this.active){
  2779.                 if (document.location.host=="e-sizeer.sport.pl") {
  2780.                     eSizeerSportPl();
  2781.                 }
  2782.                 else {
  2783.                     if (typeof _adblock === 'undefined') {
  2784.  
  2785.                         // TEST
  2786.                         window._gaq = [];
  2787.  
  2788.                         this.push([ '_setAccount', this.tracker ]);
  2789.                         this.push([ '_setDomainName', domain ]);
  2790.                         this.push([ '_setAllowLinker', true ]);
  2791.                         if(this.registeredUser.length) {
  2792.                             this.push(['_setCustomVar', 1, this.registeredUser[0], this.registeredUser[1], 1]);
  2793.                         }
  2794.                         if(this.userCardClub) {
  2795.                             this.push(['_setCustomVar', 2, 'Klubowicz SizeerClub','Tak',1]);
  2796.                         }
  2797.                         if(this.userNewsletter) {
  2798.                             this.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  2799.                         } else {
  2800.                             var utmzCookie = $.cookie('__utmz');
  2801.                             if(utmzCookie) {
  2802.                                 utmzCookie = utmzCookie.split(/[|.]+/).slice(4);
  2803.                                 if((utmzCookie[0] == 'utmcsr=(mailing)' && utmzCookie[2] == 'utmcmd=(email)') || (utmzCookie[0] == 'utmcsr=(salesmanago)' && utmzCookie[2] == 'utmcmd=(mailing)')) {
  2804.                                     this.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  2805.                                 }
  2806.                             }
  2807.                         }
  2808.                         this.push(['_setCustomVar', 4, 'Wersja serwisu','Desktop', 3]);
  2809.                         if(this.page.length){
  2810.                             this.push(['_set', 'page', this.page]);
  2811.                         }
  2812.  
  2813.                         this.push(['_trackPageview']);
  2814.  
  2815.                         if(this.transaction.length){
  2816.                             $.each(this.transaction,function(i,n){
  2817.                                 that.push(n);
  2818.                             });
  2819.                             this.transaction = [];
  2820.                         }
  2821.  
  2822.                         var ga = document.createElement('script');
  2823.                         ga.type = 'text/javascript';
  2824.                         ga.async = true;
  2825.                         ga.src = ('https:' == document.location.protocol ? 'https://'
  2826.                                 : 'http://')
  2827.                                 + 'stats.g.doubleclick.net/dc.js';
  2828.                         var s = document.getElementsByTagName('script')[0];
  2829.                         s.parentNode.insertBefore(ga, s);
  2830.                         // TEST
  2831.  
  2832.  
  2833.                     } else {
  2834.  
  2835.                         // OK
  2836.                         var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
  2837.  
  2838.                         window._gaq = [];
  2839.  
  2840.                         this.push([ '_require', 'inpage_linkid', pluginUrl ]);
  2841.                         this.push([ '_setAccount', this.tracker ]);
  2842.                         this.push([ '_setDomainName', domain ]);
  2843.                         this.push([ '_setAllowLinker', true ]);
  2844.                         if(this.registeredUser.length) {
  2845.                             this.push(['_setCustomVar', 1, this.registeredUser[0], this.registeredUser[1], 1]);
  2846.                         }
  2847.                         if(this.userCardClub) {
  2848.                             this.push(['_setCustomVar', 2, 'Klubowicz SizeerClub','Tak',1]);
  2849.                         }
  2850.                         if(this.userNewsletter) {
  2851.                             this.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  2852.                         } else {
  2853.                             var utmzCookie = $.cookie('__utmz');
  2854.                             if(utmzCookie) {
  2855.                                 utmzCookie = utmzCookie.split(/[|.]+/).slice(4);
  2856.                                 if((utmzCookie[0] == 'utmcsr=(mailing)' && utmzCookie[2] == 'utmcmd=(email)') || (utmzCookie[0] == 'utmcsr=(salesmanago)' && utmzCookie[2] == 'utmcmd=(mailing)')) {
  2857.                                     this.push(['_setCustomVar', 3, 'Zapisany do newslettera','Tak',1]);
  2858.                                 }
  2859.                             }
  2860.                         }
  2861.                         this.push(['_setCustomVar', 4, 'Wersja serwisu','Desktop', 3]);
  2862.                         if(this.page.length){
  2863.                             this.push(['_set', 'page', this.page]);
  2864.                         }
  2865.                         this.push(['_trackPageview']);
  2866.  
  2867.                         if(this.transaction.length){
  2868.                             $.each(this.transaction,function(i,n){
  2869.                                 that.push(n);
  2870.                             });
  2871.                             this.transaction = [];
  2872.                         }
  2873.  
  2874.                         (function() {
  2875.                             if (!_adblock) {
  2876.                                 var ga = document.createElement('script');
  2877.                                 ga.type = 'text/javascript';
  2878.                                 ga.async = true;
  2879.                                 ga.src = ('https:' == document.location.protocol ? 'https://'
  2880.                                         : 'http://')
  2881.                                         + 'stats.g.doubleclick.net/dc.js';
  2882.                                 var s = document.getElementsByTagName('script')[0];
  2883.                                 s.parentNode.insertBefore(ga, s);
  2884.                             } else {
  2885.                                 var ga = document.createElement('script');
  2886.                                 ga.type = 'text/javascript';
  2887.                                 ga.async = true;
  2888.                                 ga.src = ('https:' == document.location.protocol ? 'https://ssl'
  2889.                                         : 'http://www')
  2890.                                         + '.google-analytics.com/ga.js';
  2891.                                 var s = document.getElementsByTagName('script')[0];
  2892.                                 s.parentNode.insertBefore(ga, s);
  2893.                             }
  2894.                         })();
  2895.                         // OK
  2896.  
  2897.                     }
  2898.                 }
  2899.             }
  2900.         },
  2901.         tagManager:function(){
  2902.             if(this.tagManegerId){
  2903.                 (function(w, d, s, l, i) {
  2904.                     w[l] = w[l] || [];
  2905.                     w[l].push({
  2906.                         'gtm.start' :
  2907.  
  2908.                             new Date().getTime(),
  2909.                             event : 'gtm.js'
  2910.                     });
  2911.                     var f = d.getElementsByTagName(s)[0],
  2912.  
  2913.                     j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
  2914.                     j.async = true;
  2915.                     j.src =
  2916.  
  2917.                         '//www.googletagmanager.com/gtm.js?id=' + i + dl;
  2918.                     f.parentNode.insertBefore(j, f);
  2919.  
  2920.                 })(window, document, 'script', 'dataLayer', this.tagManegerId);
  2921.             };
  2922.         },
  2923.         setCommonEvent:function(){
  2924.             var that=this;
  2925.             $('#menu a.level1').click(function(){
  2926.                 var level1=$(this).parents('li.level1').attr('data-label');
  2927.                 that.push(['_trackEvent', 'Gorne menu', level1]);
  2928.             });
  2929.             $('#menu a.level2').click(function(){
  2930.                 var level1=$(this).parents('li.level1').attr('data-label');
  2931.                 var level2=$(this).parents('li.level2').attr('data-label');
  2932.                 that.push(['_trackEvent', 'Gorne menu', level1, level2]);
  2933.             });
  2934.             $('#menu a.level3').click(function(){
  2935.                 var level1=$(this).parents('li.level1').attr('data-label');
  2936.                 var level2=$(this).parents('li.level2').attr('data-label');
  2937.                 var level3=$(this).parents('li.level3').attr('data-label');
  2938.                 that.push(['_trackEvent', 'Gorne menu', level1, level2]);
  2939.                 that.push(['_trackEvent', 'Gorne menu', level1, level3]);
  2940.             });
  2941.             $('#menu .rightColumn a.img-product').click(function(){
  2942.                 that.push(['_trackEvent', 'Gorne menu', $(this).attr('data-label'), $(this).attr('data-name')]);
  2943.             });
  2944.             $('#breadcrumb a').click(function(){
  2945.                 that.push(['_trackEvent', 'Breadcrumb', $(this).text()]);
  2946.             });
  2947.         },
  2948.         pushTransaction:function(data) {
  2949.             var that=this;
  2950.             $.each(data,function(i,n){
  2951.                 that.push(n);
  2952.             });
  2953.             this.transaction = [];
  2954.         }
  2955.     },
  2956.     help:{
  2957.         init:function(){
  2958.             var footer = $('.footer-box');
  2959.             var footerHeight = footer.height();
  2960.             var footerPos = $('.footer-box').position().top;
  2961.             var pos = (footerPos + $('#footer').height()) - ($(window).scrollTop() + $(window).height());
  2962.  
  2963.             $('.footer-box').css({'height': footerHeight});
  2964.  
  2965.             if(footer.hasClass('help-position')){
  2966.                 this.hide(pos);
  2967.             }else{
  2968.                 if(pos > 0){
  2969.                     this.show();
  2970.                 }
  2971.             }
  2972.             this.listen();
  2973.         },
  2974.         show:function(){
  2975.             $('.footer-box').addClass('help-position');
  2976.             $('.footer-box').stop(true).animate({bottom: $('.help-arrow-container').height()}, 500);
  2977.  
  2978.             $('#help-arrow').removeClass('arrow-up').addClass('arrow-down');
  2979.             $('#domainFooter').css('padding-top', $('.footer-box').height());
  2980.         },
  2981.         hide:function(pos){
  2982.             var speed = 500;
  2983.             if(pos > $('.footer-box').height()){
  2984.                 pos = $('.footer-box').height();
  2985.                 speed = 200;
  2986.             }
  2987.             $('.footer-box').stop(true).animate({bottom: '-'+speed}, 500, function(){
  2988.                 $('.footer-box').removeClass('help-position').removeAttr('style');
  2989.                 $('#domainFooter').removeAttr('style');
  2990.             });
  2991.             $('#help-arrow').removeClass('arrow-down').addClass('arrow-up');
  2992.             $('#help-arrow').removeAttr('style');
  2993.         },
  2994.         listen:function(){
  2995.             $(window).bind('scroll', function(){
  2996.                 var pos = $(document).height() - $(window).height();
  2997.  
  2998.                 if($(window).scrollTop() + $(window).height() > $(document).height() - $('.footer-box').height()) {
  2999.                     $('#help-arrow').removeClass('arrow-down').addClass('arrow-up').removeClass('help-arrow-fixed').addClass('help-arrow-normal');
  3000.                     $('#help-arrow').removeAttr('style');
  3001.                 } else {
  3002.                     $('#help-arrow').removeClass('help-arrow-normal').addClass('help-arrow-fixed');
  3003.                 }
  3004.                 if((pos - $(window).scrollTop()) <= 0){
  3005.                     $('.footer-box').removeClass('help-position').removeAttr('style');
  3006.                     $('#domainFooter').removeAttr('style');
  3007.                 }
  3008.             });
  3009.         },
  3010.         kill:function() {
  3011.             $('#help-arrow').hide();
  3012.         }
  3013.     },
  3014.     mobileReload:function(){
  3015.         function getUrlVars() {
  3016.             var vars = [], hash;
  3017.             var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  3018.             for(var i = 0; i < hashes.length; i++)
  3019.             {
  3020.                 hash = hashes[i].split('=');
  3021.                 vars.push(hash[0]);
  3022.                 vars[hash[0]] = hash[1];
  3023.             }
  3024.             return vars;
  3025.         }
  3026.         function locReload() {
  3027.             if($.cookie('DEVICE')){     //sprawdzenie czy ciastka są włączone
  3028.                 if(document.referrer != '') {
  3029.                     var param = '?';
  3030.                     var referrer = 'utm_referrer=';
  3031.  
  3032.                     if(document.location.search != '') {
  3033.                         param = document.location.search + '&';
  3034.                     }
  3035.                     document.location = document.location.pathname + param + referrer + encodeURIComponent(document.referrer);
  3036.                 }
  3037.                 else {
  3038.                     location.reload();
  3039.                 }
  3040.             }
  3041.         }
  3042.         if(typeof(appProperties) !== "undefined" && appProperties.engine=='sizeer'){
  3043.             var devUrl = getUrlVars()['device'];
  3044.             var devCookie = $.cookie('DEVICE');
  3045.  
  3046.             if(devUrl == 'mobile') {
  3047.                 if(devCookie != 'mobile') {
  3048.                     document.cookie = 'DEVICE=; Max-Age=0';
  3049.                     $.cookie('DEVICE', 'mobile', {path: '/'});
  3050.                     locReload();
  3051.                 }
  3052.             }
  3053.  
  3054.             if(devUrl == 'normal') {
  3055.                 if(devCookie != 'normal') {
  3056.                     document.cookie = 'DEVICE=; Max-Age=0';
  3057.                     $.cookie('DEVICE', 'normal',  {path: '/'});
  3058.                     locReload();
  3059.                 }
  3060.             }
  3061.  
  3062.             if(devCookie === undefined) {
  3063.                 $.ajax({
  3064.                     url: "/ajax/mobileSwitcher.ltr",
  3065.                     cache: false,
  3066.                     success: function(result){
  3067.                         $.cookie('DEVICE', result.device, {path: '/'});
  3068.                         if(result.device == 'mobile') {
  3069.                             locReload();
  3070.                         }
  3071.                     }
  3072.                 });
  3073.             }
  3074.         }
  3075.     },
  3076.     replaceCheckboxes: function() {
  3077.         $('.checkbox').each(function(i,t){
  3078.             if ($(t).find("input:checked").length) {
  3079.                 $(t).addClass('checked');
  3080.             } else {
  3081.                 $(t).addClass('unchecked');
  3082.             }
  3083.         });
  3084.         $('.checkbox' + ' input[type="checkbox"]').on('click', function(e){
  3085.             $(this).parents('.checkbox').toggleClass('checked').toggleClass('unchecked');
  3086.             if($(this).attr('checked') == 'checked') {
  3087.                 $(this).removeAttr('checked');
  3088.             } else {
  3089.                 $(this).attr('checked', 'checked');
  3090.             }
  3091.         });
  3092.     },
  3093.     cookiePolicy: {
  3094.         init: function() {
  3095.             if($.cookie('cookiePolicy') != 'accepted') {
  3096.                 $('.cookie-policy-box').css({'display' : 'block'});
  3097.             }
  3098.         },
  3099.         checkbox: function() {
  3100.             $('#cookieCheckbox').toggleClass('unchecked').toggleClass('checked');
  3101.         },
  3102.         accept: function() {
  3103.             $('#cookieCheckbox').removeClass('unchecked').addClass('checked');
  3104.             $.cookie('cookiePolicy', 'accepted', {expires: 365, path: '/'});
  3105.             mig.cookiePolicy.close();
  3106.         },
  3107.         close: function() {
  3108.             $('.cookie-policy-box').css({'display' : 'none'});
  3109.         }
  3110.     },
  3111.     salesManago: {
  3112.         event: function(data) {
  3113.             if (typeof smEvent === 'undefined') {
  3114.                 $.getScript('//salesmanago.pl/static/sm.js').done(function() {
  3115.                     sendSmEvent(data);
  3116.                 });
  3117.             } else {
  3118.                 sendSmEvent(data);
  3119.             }
  3120.             function sendSmEvent(datasend) {
  3121.                 try {
  3122.                     smEvent(datasend);
  3123.                 } catch (error) {
  3124.                     console.error('SM Error: "' + error + '"');
  3125.                 }
  3126.             }
  3127.         },
  3128.         searchEvent: {
  3129.             data: '',
  3130.             send: function() {
  3131.                 var _ = this;
  3132.                 var query = $('#search-word').val() || '';
  3133.                 if (_.data === '') {
  3134.                     mig.salesManago.event(query + '|' + 'brak-wynikow');
  3135.                 } else {
  3136.                     mig.salesManago.event(query + '|' + _.data);
  3137.                 }
  3138.             }
  3139.         }
  3140.     },
  3141.     comments: {
  3142.         init: function(){
  3143.             this.setEvents();
  3144.             mig.validate.productOpinions();
  3145.         },
  3146.         commentsExpanded: false,
  3147.         commentsLoaded: false,
  3148.         toggleComments: function (productId) {
  3149.             var that = this;
  3150.             if ($("#comments-product-card .item").size() <= 1){
  3151.                 return false;
  3152.             }
  3153.             if (that.commentsExpanded) {
  3154.                 $("#comments-product-card .item").filter(":gt(0)").addClass("none");
  3155.                 $(".comments-product-title").removeClass("expanded");
  3156.                 $("#comments-product-card .item").removeClass("cpcBorder");
  3157.                 $('#comments-product-card').data('jsp').destroy();
  3158.                 $("#comments-product-card").removeClass("expanded");
  3159.             }
  3160.             else {
  3161.                 $("#comments-product-card .item").removeClass("none");
  3162.                 for(var ii = 1; ii <$("#comments-product-card .item").length;ii++){
  3163.                     $('#comments-product-card .item',[ii-1]).addClass("cpcBorder");
  3164.                 }
  3165.                 $(".comments-product-title").addClass("expanded");
  3166.                 $("#comments-product-card").addClass("expanded");
  3167.                 $('#comments-product-card').jScrollPane({
  3168.                     verticalDragMaxHeight: 70,
  3169.                     showArrows: true
  3170.                 });
  3171.             }
  3172.             if (!that.commentsLoaded) {
  3173.                 that.commentsLoaded = true;
  3174.                 that.loadRestOfComments(productId);
  3175.             }
  3176.             that.commentsExpanded = !that.commentsExpanded;
  3177.             return false;
  3178.         },
  3179.         loadRestOfComments: function (productId) {
  3180.             $.ajax({
  3181.                 url: ("/comments-for-product.ltr?from=5&max=30&productId=" + productId),
  3182.                 success: function (data) {
  3183.                     if (mig.comments.commentsExpanded) {
  3184.                         $('#comments-product-card .container').append(data);
  3185.                         $("#comments-product-card .item").removeClass("none");
  3186.                         $('#comments-product-card').data('jsp').reinitialise();
  3187.                     }
  3188.                     else {
  3189.                         $('#comments-product-card .container').append(data);
  3190.                     }
  3191.                 }
  3192.             });
  3193.         },
  3194.         setEvents: function(){
  3195.             var that=this;
  3196.             $("#customerCommentsForm .item").each(function () {
  3197.                 var item = this;
  3198.                 $('.checkbox', item).click(function(){
  3199.                     that.showComment(item);
  3200.                 });
  3201.             });
  3202.             this.commentRatingEvent();
  3203.         },
  3204.         showComment:function(item){
  3205.             var comment = $('.item-comment', item);
  3206.             if ($('.checkbox input.comment:checked', item).size() > 0) {
  3207.                 comment.show();
  3208.                 $("input, textarea", comment).removeClass("ignored");
  3209.                 $('.checkbox input.value', item).val('true');
  3210.             } else {
  3211.                 comment.hide();
  3212.                 $("input, textarea", comment).addClass("ignored");
  3213.                 $('.checkbox input.value', item).val('false');
  3214.             }
  3215.         },
  3216.         commentRatingEvent: function() {
  3217.             $(".rate").each(function () {
  3218.                 var rate = this;
  3219.                 var stars = $("a", rate);
  3220.                 stars.click(function(){
  3221.                     var index = $(this).index() +1;
  3222.                     setRating(index, rate, $(this).attr('rel'));
  3223.                 }).hover(function(){
  3224.                     var index = $(this).index();
  3225.                     hoverRating(index, stars);
  3226.                 }, function(){
  3227.                     var index = $('input.sendRating', rate).attr("rel");
  3228.                     hoverRating(index, stars);
  3229.                 });
  3230.             });
  3231.             var hoverRating = function(index, stars){
  3232.                 stars.removeClass('active').filter(":lt("+index+")").addClass('active');
  3233.             };
  3234.             var setRating = function(index, rate, val){
  3235.                 $('input.sendRating', rate).val(val);
  3236.                 $('input.sendRating', rate).attr({rel: index});
  3237.             };
  3238.             var getRating = function(rate){
  3239.                 return $('input.sendRating', rate).attr('rel')/1;
  3240.             };
  3241.         }
  3242.     },
  3243.     recommendedProducts: {
  3244.         enabled: false,
  3245.         smUrlA: '',
  3246.         smUrlB: ''
  3247.     }
  3248. };
  3249.  
  3250. function fixLazyload() {
  3251.     setTimeout(function() {
  3252.         $(window).resize(); // force resize, to load dynamically appended images
  3253.     }, 400);
  3254. }
  3255.  
  3256. function eSizeerSportPl() {
  3257.     if (document.location.host!="/order-finalize.bhtml") {
  3258.  
  3259.         var _gaq = _gaq || [];
  3260.         var utmgif = 'http://kropka.e-sizeer.sport.pl/__utm.gif';
  3261.  
  3262.           gaPush(['_setAccount', 'UA-15997622-1']);
  3263.           gaPush(['_setAllowAnchor', true]);
  3264.           gaPush(['_trackPageview']);
  3265.  
  3266.         (function() {
  3267.             var tg = document.createElement('script');
  3268.             tg.type = 'text/javascript';
  3269.             tg.async = true;
  3270.             tg.src = 'http://analytics.gazeta.pl/tg.js';
  3271.             var s = document.getElementsByTagName('script')[0];
  3272.             s.parentNode.insertBefore(tg, s);
  3273.         })();
  3274.     }
  3275. }
  3276. $.fn.extend({
  3277.     ignore: function(value) {
  3278.         var klasa='ignore';
  3279.         if(this.length){
  3280.             this.find('input').each(function(){
  3281.                 var em=$("label[for='"+$(this).attr('id')+"'] em");
  3282.                 if(value){
  3283.                     $(this).addClass(klasa).removeClass('error');
  3284.                     if(em.length)em.hide();
  3285.                 }else{
  3286.                     $(this).removeClass(klasa);
  3287.                     if(em.length)em.css('display','inline');
  3288.                 }
  3289.             });
  3290.         }
  3291.         return this;
  3292.     }
  3293. });
  3294.  
  3295. $.fn.preview = function(options) {
  3296.     var close=false;
  3297.     var open=false;
  3298.     var id=false;
  3299.     var ajax=false;
  3300.     var settings = $.extend( {
  3301.         intervalClose:15,
  3302.         intervalOpen:1500
  3303.     }, options);
  3304.     if(!$('#productPreview').length){
  3305.         $('body').append('<div id="productPreview"></div>');
  3306.         $('#productPreview').mouseenter(function(){
  3307.             //
  3308.         }).mouseleave(function(){
  3309.             hide();
  3310.         });
  3311.         $("#productPreview").on("click", ".list .photo a", function(e){
  3312.             animatePreviewSlider($(this).attr("data-link"));
  3313.             $("#fancybox-loading").hide();
  3314.             e.preventDefault();
  3315.         });
  3316.     }
  3317.     function hide(){
  3318.         $('#productPreview').hide();
  3319.     };
  3320.     function animatePreviewSlider(targetNr){
  3321.         var offset = $('#productPreview .multimedia .big li.photo').eq(targetNr).position().left;
  3322.         $('#productPreview .multimedia .big ul').animate({ left : -offset}, 200);
  3323.     }
  3324.     return this.each(function(i){
  3325.         if(!$(this).data('preview')){
  3326.             $(this).data('preview',true);
  3327.             var that = $(this);
  3328.             var cache = false;
  3329.             var id = that.parent().attr('data-id');
  3330.             var event = false;
  3331.             var timeout;
  3332.             that.mouseenter(function() {
  3333.                 timeout = setTimeout(function() {
  3334.                     if(!cache){
  3335.                         load(id);
  3336.                     }else{
  3337.                         show();
  3338.                     }
  3339.                 }, settings.intervalOpen);
  3340.                 open = 'enter';
  3341.             }).mouseleave(function() {
  3342.                 clearTimeout(timeout);
  3343.                 open = 'leave';
  3344.             });
  3345.             function show(){
  3346.                 var variant = 'normal';
  3347.                 if(i % 2 == 1) {
  3348.                     variant = 'inverted';
  3349.                 }
  3350.                 if(open != 'leave') {
  3351.                     var productPreview = $('#productPreview');
  3352.                     $('#productPreview').empty().html(cache);
  3353.                     var left = that.parents('li').offset().left;
  3354.                     if(mig.properties.engine == mig.engines.outlet) { //TODO: Przygotować funkcję™ do tego
  3355.                         if(variant == 'inverted') {
  3356.                             left = left - (that.parents('li').width() + 20); //TODO: Zastapic 20 wartoscia pobierana z frontu
  3357.                             $('#productPreview .leftCol, #productPreview .buttons').addClass('flip');
  3358.                         }
  3359.                     } else {
  3360.                         if(left>($('body').width()/2)){
  3361.                             left=that.offset().left-productPreview.outerWidth()+that.width();
  3362.                         }
  3363.                     }
  3364.                     if(left < 0) {
  3365.                         left = 0;
  3366.                     }
  3367.                     var top=that.parents('li').offset().top;
  3368.                     if(that.offset().top+productPreview.height()>$(window).scrollTop()+$(window).height()) {
  3369.                         top=$(window).scrollTop()+$(window).height()-productPreview.height()-10;
  3370.                     } else if($(window).scrollTop()+$('.fixed-header').outerHeight()>that.parents('li').offset().top){
  3371.                         top=$(window).scrollTop()+$('.fixed-header').outerHeight()-20;
  3372.                     }
  3373.                     if(left != 0 && top != 0) {
  3374.                         $('#productPreview').stop().css({
  3375.                             left:left,
  3376.                             top:top,
  3377.                         }).fadeIn('fast');
  3378.                     }
  3379.                     $('#productPreview .multimedia .small a, #productPreview .multimedia .big a').click(function(){
  3380.                         mig.showLoading();
  3381.                     });
  3382.                 }
  3383.             };
  3384.             function load(id){
  3385.                 if(ajax)ajax.abort();
  3386.                 ajax=$.ajax({
  3387.                     url:'/productCardAjax.ltr',
  3388.                     data:{
  3389.                         productId:id
  3390.                     },
  3391.                     success:function(html){
  3392.                         cache=html;
  3393.                         show();
  3394.                     }
  3395.                 });
  3396.             }
  3397.         }
  3398.     });
  3399. };
  3400.  
  3401. $.fn.jRating = function(op) {
  3402.     var defaults = {
  3403.         bigStarsPath : '/images/outlet2/stars.png', // path of the icon stars.png
  3404.         smallStarsPath : '/images/outlet2/stars-small.png', // path of the icon small.png
  3405.         phpPath : 'php/jRating.php',
  3406.         type : 'big', // can be set to 'small' or 'big'
  3407.  
  3408.         /** Boolean vars **/
  3409.         step:false, // if true,  mouseover binded star by star,
  3410.         isDisabled:false, // if true, user could not rate
  3411.         showRateInfo: false, // show rates informations when cursor moves onto the plugin
  3412.         canRateAgain : false, // if true, the user could rates {nbRates} times with jRating.. Default, 1 time
  3413.         sendRequest: true, // send values to server
  3414.  
  3415.         /** Integer vars **/
  3416.         length:5, // number of star to display
  3417.         decimalLength : 0, // number of decimals.
  3418.         rateMax : 20, // maximal rate - integer from 0 to 9999 (or more)
  3419.         rateInfosX : -45, // relative position in X axis of the info box when mouseover
  3420.         rateInfosY : 5, // relative position in Y axis of the info box when mouseover
  3421.         nbRates : 1,
  3422.  
  3423.         /** Functions **/
  3424.         onSuccess : null, // Fires when the server response is ok
  3425.         onError : null, // Fires when the server response is not ok
  3426.         onClick: null // Fires when clicking on a star
  3427.     };
  3428.     if(this.length>0)
  3429.     return this.each(function() {
  3430.         /*vars*/
  3431.         var opts = $.extend(defaults, op),
  3432.         newWidth = 0,
  3433.         starWidth = 0,
  3434.         starHeight = 0,
  3435.         bgPath = '',
  3436.         hasRated = false,
  3437.         globalWidth = 0,
  3438.         nbOfRates = opts.nbRates;
  3439.         if($(this).hasClass('jDisabled') || opts.isDisabled)
  3440.             var jDisabled = true;
  3441.         else
  3442.             var jDisabled = false;
  3443.  
  3444.         getStarWidth();
  3445.         $(this).height(starHeight);
  3446.  
  3447.         var average = parseFloat($(this).attr('data-average')), // get the average of all rates
  3448.         idBox = parseInt($(this).attr('data-id')), // get the id of the box
  3449.         widthRatingContainer = starWidth*opts.length, // Width of the Container
  3450.         widthColor = average/opts.rateMax*widthRatingContainer, // Width of the color Container
  3451.  
  3452.         quotient =
  3453.         $('<div>',
  3454.         {
  3455.             'class' : 'jRatingColor',
  3456.             css:{
  3457.                 width:widthColor
  3458.             }
  3459.         }).appendTo($(this)),
  3460.  
  3461.         average =
  3462.         $('<div>',
  3463.         {
  3464.             'class' : 'jRatingAverage',
  3465.             css:{
  3466.                 width:widthRatingContainer,
  3467.                 top:- starHeight
  3468.             }
  3469.         }).appendTo($(this)),
  3470.  
  3471.         background = $('<div>',
  3472.         {
  3473.             'class' : 'jRatingBackground',
  3474.             css:{
  3475.                 width:0,
  3476.             }
  3477.         }).appendTo($(this)),
  3478.  
  3479.          jstar =
  3480.         $('<div>',
  3481.         {
  3482.             'class' : 'jStar',
  3483.             css:{
  3484.                 width:widthRatingContainer,
  3485.                 height:starHeight,
  3486.                 top:- (starHeight*3),
  3487.                 background: 'url('+bgPath+') repeat-x'
  3488.             }
  3489.         }).appendTo($(this));
  3490.  
  3491.  
  3492.         $(this).css({width: widthRatingContainer,overflow:'hidden',zIndex:1,position:'relative'});
  3493.  
  3494.         if(!jDisabled) {
  3495.             $(this).unbind().bind({
  3496.                 mouseenter : function(e){
  3497.                     var realOffsetLeft = findRealLeft(this);
  3498.                     var relativeX = e.pageX - realOffsetLeft;
  3499.                     if (opts.showRateInfo)
  3500.                     var tooltip =
  3501.                     $('<p>',{
  3502.                         'class' : 'jRatingInfos',
  3503.                         html : getNote(relativeX)+' <span class="maxRate">/ '+opts.rateMax+'</span>',
  3504.                         css : {
  3505.                             top: (e.pageY + opts.rateInfosY),
  3506.                             left: (e.pageX + opts.rateInfosX)
  3507.                         }
  3508.                     }).appendTo('body').show();
  3509.                 },
  3510.                 mouseover : function(e){
  3511.                     $(this).css('cursor','pointer');
  3512.                 },
  3513.                 mouseout : function(){
  3514.                     $(this).css('cursor','default');
  3515.                     if(hasRated) average.width(globalWidth);
  3516.                     else average.width(0);
  3517.                 },
  3518.                 mousemove : function(e){
  3519.                     var realOffsetLeft = findRealLeft(this);
  3520.                     var relativeX = e.pageX - realOffsetLeft;
  3521.                     if(opts.step) newWidth = Math.floor(relativeX/starWidth)*starWidth + starWidth;
  3522.                     else newWidth = relativeX;
  3523.                     average.width(newWidth);
  3524.                     if (opts.showRateInfo)
  3525.                     $("p.jRatingInfos")
  3526.                     .css({
  3527.                         left: (e.pageX + opts.rateInfosX)
  3528.                     })
  3529.                     .html(getNote(newWidth) +' <span class="maxRate">/ '+opts.rateMax+'</span>');
  3530.                 },
  3531.                 mouseleave : function(){
  3532.                     $("p.jRatingInfos").remove();
  3533.                 },
  3534.                 click : function(e){
  3535.                     var element = this;
  3536.  
  3537.                     /*set vars*/
  3538.                     hasRated = true;
  3539.                     globalWidth = newWidth;
  3540.                     nbOfRates--;
  3541.  
  3542.                     if(!opts.canRateAgain || parseInt(nbOfRates) <= 0) $(this).unbind().css('cursor','default').addClass('jDisabled');
  3543.  
  3544.                     if (opts.showRateInfo) $("p.jRatingInfos").fadeOut('fast',function(){$(this).remove();});
  3545.                     e.preventDefault();
  3546.                     var rate = getNote(newWidth);
  3547.                     average.width(newWidth);
  3548.  
  3549.  
  3550.                     /** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
  3551.                         $('.datasSent p').html('<strong>idBox : </strong>'+idBox+'<br /><strong>rate : </strong>'+rate+'<br /><strong>action :</strong> rating');
  3552.                         $('.serverResponse p').html('<strong>Loading...</strong>');
  3553.                     /** END ONLY FOR THE DEMO **/
  3554.  
  3555.                     if(opts.onClick) opts.onClick( element, rate );
  3556.  
  3557.                     if(opts.sendRequest) {
  3558.                         $.post(opts.phpPath,{
  3559.                                 idBox : idBox,
  3560.                                 rate : rate,
  3561.                                 action : 'rating'
  3562.                             },
  3563.                             function(data) {
  3564.                                 if(!data.error)
  3565.                                 {
  3566.                                     /** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
  3567.                                         $('.serverResponse p').html(data.server);
  3568.                                     /** END ONLY FOR THE DEMO **/
  3569.  
  3570.  
  3571.                                     /** Here you can display an alert box,
  3572.                                         or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
  3573.                                         exemple :   */
  3574.                                     if(opts.onSuccess) opts.onSuccess( element, rate );
  3575.                                 }
  3576.                                 else
  3577.                                 {
  3578.  
  3579.                                     /** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
  3580.                                         $('.serverResponse p').html(data.server);
  3581.                                     /** END ONLY FOR THE DEMO **/
  3582.  
  3583.                                     /** Here you can display an alert box,
  3584.                                         or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
  3585.                                         exemple :   */
  3586.                                     if(opts.onError) opts.onError( element, rate );
  3587.                                 }
  3588.                             },
  3589.                             'json'
  3590.                         );
  3591.                     }
  3592.  
  3593.                 }
  3594.             });
  3595.         } else {
  3596.             $(this).addClass('jDisabled');
  3597.         }
  3598.         function getNote(relativeX) {
  3599.             var noteBrut = parseFloat((relativeX*100/widthRatingContainer)*parseInt(opts.rateMax)/100);
  3600.             var dec=Math.pow(10,parseInt(opts.decimalLength));
  3601.             var note = Math.round(noteBrut*dec)/dec;
  3602.             return note;
  3603.         };
  3604.         function getStarWidth(){
  3605.             switch(opts.type) {
  3606.                 case 'small' :
  3607.                     starWidth = 12; // width of the picture small.png
  3608.                     starHeight = 10; // height of the picture small.png
  3609.                     bgPath = opts.smallStarsPath;
  3610.                 break;
  3611.                 default :
  3612.                     starWidth = 23; // width of the picture stars.png
  3613.                     starHeight = 20; // height of the picture stars.png
  3614.                     bgPath = opts.bigStarsPath;
  3615.             }
  3616.         };
  3617.         function findRealLeft(obj) {
  3618.           if( !obj ) return 0;
  3619.           return obj.offsetLeft + findRealLeft( obj.offsetParent );
  3620.         };
  3621.     });
  3622. };
  3623.  
  3624. $.fn.selectbox = function(options) {
  3625.     $('html').unbind('click').click(function() {
  3626.         // $('.selectBox.active').removeClass('active');
  3627.         if($('.filterPrice .selectBox.active').length == 1) {
  3628.             $('.filterPrice .selectBox').removeClass('active');
  3629.         }
  3630.         $('.selectBox.active').trigger('click');
  3631.     });
  3632.     return this.each(function(){
  3633.         $(this).click(function(e){
  3634.             $('.selectBox').not(this).removeClass('active');
  3635.             if($(this).hasClass('active')){
  3636.                 if($(this).parent('.filterPrice').length == 0) {
  3637.                     $(this).removeClass('active');
  3638.                 }
  3639.             }else{
  3640.                 if(!$(this).hasClass('disabled')){
  3641.                     $(this).addClass('active');
  3642.                     if(typeof $.fn.jScrollPane != undefined) {
  3643.                         //$('.filterItemBrand .selectBox ul').jScrollPane({showArrows: true});
  3644.                         $('.filterItemDefault .selectBox ul, .filterItemBrand .selectBox ul, .selectBox.scrollable ul').jScrollPane({showArrows: true});
  3645.                     }
  3646.                 }
  3647.             }
  3648.             //e.preventDefault();
  3649.             e.stopPropagation();
  3650.         }).find('li a').click(function(e){
  3651.             var list=$(this).parent().parent();
  3652.             var oneSelection=list.parent().hasClass('oneSelection');
  3653.             var dontPreventDefault=list.parent().hasClass('dontPreventDefault');
  3654.             var input=list.next();
  3655.             var value=[];
  3656.             if(!$(this).hasClass('disabled')){
  3657.                 if(oneSelection){
  3658.                     list.find('.selected').removeClass('selected');
  3659.                 }
  3660.                 $(this).toggleClass('selected');
  3661.             }
  3662.             if(oneSelection){
  3663.                 //if($(this).attr('data-value')!=input.val()){ -- to nie powinno być w niższym warunku?
  3664.                     value.push($(this).attr('data-value'));
  3665.                     var text=$(this).attr('data-text');
  3666.                     if(text){
  3667.                         list.parent().find('.label .text').text(text);
  3668.                     }
  3669.                 //}
  3670.             }else{
  3671.                 list.find('.selected').each(function(){
  3672.                     value.push($(this).attr('data-value'));
  3673.                 });
  3674.             }
  3675.             input.val(value.join('|')).trigger('change');
  3676.             if (!dontPreventDefault) {
  3677.                 e.preventDefault();
  3678.             }
  3679.         });
  3680.         $(this).find('.select .icon').click(function(e){
  3681.             $(this).parents('.selectBox').find('input').val('').trigger('change');
  3682.             $(this).parent().parent().removeClass('isSelected');
  3683.             e.preventDefault();
  3684.         });
  3685.     });
  3686. };
  3687.  
  3688. $.fn.cmsRotator = function(options){
  3689.     var settings = $.extend( {
  3690.         speed: 500,
  3691.         loop: true,
  3692.         direction: 'right',
  3693.         timeout: 5000
  3694.     }, options);
  3695.  
  3696.     return this.each(function(){
  3697.         var that = $(this);
  3698.         var move = false;
  3699.         var active = 0;
  3700.  
  3701.         var width = that.find('li:first').width();
  3702.         var board = that.find('ul');
  3703.         var cards = that.find('li');
  3704.         var count = that.find('li').length;
  3705.         var showed = Math.floor(that.width()/width);
  3706.  
  3707.         var icons = that.find('.icons');
  3708.         var prev = that.find('a.prev');
  3709.         var next = that.find('a.next');
  3710.  
  3711.         if(that.data('direction')!== undefined && that.data('direction') !== null) {
  3712.             settings.direction=that.data('direction');
  3713.         }
  3714.  
  3715.         if(count == 2) {
  3716.             cards.clone().prependTo(board);
  3717.         }
  3718.  
  3719.         if(count > 1) {
  3720.             icons.show();
  3721.             prev.show();
  3722.             next.show();
  3723.  
  3724.             if(settings.direction == 'right') {
  3725.                 for (var e = showed; e > 0; --e) {
  3726.                     board.find('li').eq(e).clone().prependTo(board);
  3727.                 }
  3728.                 board.css('left', -(width*count));
  3729.             }
  3730.             if(settings.direction == 'left') {
  3731.                 for (var e = 0; e < showed; e++) {
  3732.                     board.find('li').eq(e).clone().appendTo(board);
  3733.                 }
  3734.                 board.css('left', 0);
  3735.             }
  3736.         }
  3737.  
  3738.         if(that.width() >= (cards.width() * cards.length)) {
  3739.             settings.loop = false;
  3740.             board.css('left', 'auto');
  3741.             icons.hide();
  3742.             prev.hide();
  3743.             next.hide();
  3744.         }
  3745.  
  3746.         if(settings.loop) {
  3747.             setInterval(function() {
  3748.                 if(settings.direction == 'right') {
  3749.                     animate(-1);
  3750.                 }
  3751.                 if(settings.direction == 'left') {
  3752.                     animate(1);
  3753.                 }
  3754.             }, settings.timeout);
  3755.         }
  3756.  
  3757.         function animate(i) {
  3758.             if(move == false) {
  3759.                 var position = (board.css('left').replace('px','')) *1  - (width * i);
  3760.                 move = true;
  3761.                 board.animate({
  3762.                     left: position
  3763.                 }, {
  3764.                     duration: settings.spped,
  3765.                     complete: function() {
  3766.                         active = active + i;
  3767.                         if((settings.direction == 'right') && ( board.css('left') == '0px')) {
  3768.                             board.css('left', -(width*count));
  3769.                             active = 0;
  3770.                         } else if ((settings.direction == 'left') && ((position/width) * (-(i)) == count)) {
  3771.                             board.css('left', 0);
  3772.                             active = 0;
  3773.                         }
  3774.                         move = false;
  3775.                         updateList();
  3776.                     }
  3777.                 });
  3778.             }
  3779.         };
  3780.  
  3781.         function updateList(){
  3782.             if(icons.length){
  3783.                 icons.find('.active').removeClass('active');
  3784.                 var eq = active;
  3785.                 if(settings.direction=='right') {
  3786.                     var eq = Math.abs(active);
  3787.                 }
  3788.                 icons.find('a:eq('+eq+')').addClass('active');
  3789.             }
  3790.         };
  3791.  
  3792.         function setEvents(){
  3793.             icons.find('a').click(function(){
  3794.                 if (!($(this).hasClass('active'))) {
  3795.                     var icon = $(this).attr('data-id') / 1;
  3796.                     var factor = (icon / 1 - active);
  3797.                     if(settings.direction == 'right') {
  3798.                         factor = - (icon / 1 - Math.abs(active));
  3799.                     }
  3800.                     animate(factor);
  3801.                 }
  3802.             });
  3803.             prev.click(function(e){
  3804.                 animate(1);
  3805.             });
  3806.             next.click(function(e){
  3807.                 animate(-1);
  3808.             });
  3809.         }
  3810.         setEvents();
  3811.     });
  3812. };
  3813.  
  3814. (function($) {
  3815.     var oneClick = function(element, settings) {
  3816.         var _ = this;
  3817.  
  3818.         _.button = $(element);
  3819.  
  3820.         _.initials = {
  3821.             // default parameters
  3822.         };
  3823.  
  3824.         _.options = $.extend({}, _.initials, settings);
  3825.     };
  3826.  
  3827.     oneClick.prototype.setLock = function() {
  3828.         var _ = this;
  3829.  
  3830.         $(_.button).click(function(event) {
  3831.             if ($(this).hasClass('disabled')) {
  3832.                 event.preventDefault();
  3833.             } else {
  3834.                 _.button.addClass('disabled');
  3835.             }
  3836.         });
  3837.     };
  3838.  
  3839.     $.fn.oneClick = function(settings) {
  3840.         return this.each(function() {
  3841.             new oneClick(this, settings).setLock();
  3842.         });
  3843.     };
  3844. })(jQuery);
  3845.  
  3846. /*!
  3847.  * Version: 1.3
  3848.  * Author:  Marcin Stasiak
  3849.  * Website: http://www.marcinstasiak.pl
  3850.  * Repo:    https://github.com/funkyoself/sm-recommendations
  3851.  */
  3852. (function($) {
  3853.     var recommendations = function(element, settings) {
  3854.         var _ = this;
  3855.  
  3856.         _.container = $(element);
  3857.         _.count = 0;
  3858.  
  3859.         _.initials = {
  3860.             maxElements: 8,
  3861.             slidesToShow: 4,
  3862.             infinite: true,
  3863.  
  3864.             ga_place: '',
  3865.             versionUrl: 'A',
  3866.             smUrl: '',
  3867.             cookieUuid: '',
  3868.             cookieContact: '',
  3869.             pids: '',
  3870.             wholePagePid: false
  3871.         };
  3872.  
  3873.         _.options = $.extend({}, _.initials, settings);
  3874.     };
  3875.  
  3876.     recommendations.prototype.init = function() {
  3877.         var _ = this;
  3878.  
  3879.         _.setSettings();
  3880.         if (_.count == 0) {
  3881.             _.container.parent().hide();
  3882.         }
  3883.         if (mig.recommendedProducts.enabled && _.options.cookieUuid.length > 0) {
  3884.             _.getSmIds(_.options.smUrl, _.options.cookieUuid, _.options.cookieClient, _.options.pids);
  3885.         } else {
  3886.             _.initSlider();
  3887.         }
  3888.     };
  3889.  
  3890.     recommendations.prototype.setSettings = function() {
  3891.         var _ = this;
  3892.  
  3893.         _.count = _.container.find('li').length;
  3894.  
  3895.         if (_.options.versionUrl == 'B') {
  3896.             _.options.smUrl = mig.recommendedProducts.smUrlB;
  3897.         } else {
  3898.             _.options.smUrl = mig.recommendedProducts.smUrlA;
  3899.         }
  3900.  
  3901.         _.options.cookieUuid = $.cookie('smuuid') || '';
  3902.         _.options.cookieContact = $.cookie('smclient') || '';
  3903.  
  3904.         if (_.options.wholePagePid) {
  3905.             _.container.find('li').each(function() {
  3906.                 var itemPid = $(this).data('id') || '';
  3907.                 if (itemPid.toString().length > 0) {
  3908.                     _.options.pids += itemPid + ',';
  3909.                 }
  3910.             });
  3911.         }
  3912.  
  3913.         _.options.pids += $(_.container.parent()).data('pid') || '';
  3914.     };
  3915.  
  3916.     recommendations.prototype.getSmIds = function(url, uuid, contact, pids) {
  3917.         var _ = this;
  3918.  
  3919.         try {
  3920.             var request = $.ajax({
  3921.                 url: url,
  3922.                 type: 'get',
  3923.                 dataType: 'text',
  3924.                 data: {
  3925.                     uuid: uuid,
  3926.                     contactId: contact,
  3927.                     pid: pids
  3928.                 }
  3929.             });
  3930.  
  3931.             request.done(function(data) {
  3932.                 data = data.replace(/\s/g, '');
  3933.                 if (/^[0-9,]+$/.test(data)) {
  3934.                     _.getProducts(data);
  3935.                 } else {
  3936.                     _.initSlider();
  3937.                 }
  3938.             });
  3939.  
  3940.             request.fail(function(err) {
  3941.                 console.log(err.status + ' ' + err.statusText);
  3942.                 _.initSlider();
  3943.             });
  3944.         } catch (err) {
  3945.             console.log(err);
  3946.         }
  3947.     };
  3948.  
  3949.     recommendations.prototype.getProducts = function(ids) {
  3950.         var _ = this;
  3951.         var url = '/productsById.ltr?index=' + ids.replace(/,/g, '&index=');
  3952.  
  3953.         try {
  3954.             var request = $.ajax({
  3955.                 url: url,
  3956.                 type: 'get'
  3957.             });
  3958.  
  3959.             request.done(function(data) {
  3960.                 _.container.find('ul').prepend(data);
  3961.                 _.initSlider();
  3962.             });
  3963.         } catch (err) {
  3964.             console.log(err);
  3965.         }
  3966.     };
  3967.  
  3968.     recommendations.prototype.initSlider = function() {
  3969.         var _ = this;
  3970.  
  3971.         _.count = _.container.find('li').length;
  3972.         if (_.count > 0) {
  3973.             _.container.parent().show();
  3974.             _.container.slider({slidesToShow: _.options.slidesToShow, infinite: _.options.infinite});
  3975.             _.setGaEvents();
  3976.         } else {
  3977.             _.container.parent().hide();
  3978.         }
  3979.     };
  3980.  
  3981.     recommendations.prototype.setGaEvents = function() {
  3982.         var _ = this;
  3983.  
  3984.         if (_.options.ga_place.length > 0) {
  3985.             _.container.find('li a').click(function() {
  3986.                 mig.google.push(['_trackEvent', _.options.ga_place, 'Remarketing onsite']);
  3987.             });
  3988.         }
  3989.     };
  3990.  
  3991.     $.fn.recommendations = function(settings) {
  3992.         return this.each(function() {
  3993.             new recommendations(this, settings).init();
  3994.         });
  3995.     };
  3996. })(jQuery);
  3997.  
  3998. $.fn.rotator = function(options) {
  3999.     var settings = $.extend( {
  4000.         speed:500,
  4001.         item:4
  4002.     }, options);
  4003.  
  4004.     return this.each(function(){
  4005.         var that=$(this);
  4006.         var move=false;
  4007.         var widthLi=that.find('li:first').width();
  4008.         var count=that.find('li').length;
  4009.         var active=0;
  4010.         var prev=that.find('a.prev');
  4011.         var next=that.find('a.next');
  4012.  
  4013.         function disabledArrow(){
  4014.             if(active>0){
  4015.                 prev.removeClass('disabled');
  4016.             }else{
  4017.                 prev.addClass('disabled');
  4018.             }
  4019.             if(active+settings.item<count){
  4020.                 next.removeClass('disabled');
  4021.             }else{
  4022.                 next.addClass('disabled');
  4023.             }
  4024.         };
  4025.         function animate(i){
  4026.             count=that.find('li').length;
  4027.             if(!move){
  4028.                 if((i=='-' && active+settings.item<count) || (i=='+' && active>0) ){
  4029.                     move=true;
  4030.                     active+=(i=='-')?1:-1;
  4031.                     that.find('ul').animate({left:i+'='+widthLi},settings.speed,function(){
  4032.                         move=false;
  4033.                         disabledArrow();
  4034.                     });
  4035.                 }
  4036.             }
  4037.         };
  4038.         function setEvents(){
  4039.             prev.click(function(e){
  4040.                 animate('+');
  4041.             });
  4042.             next.click(function(e){
  4043.                 animate('-');
  4044.             });
  4045.         }
  4046.  
  4047.         if(count>settings.item){
  4048.             setEvents();
  4049.             prev.removeClass('none');
  4050.             next.removeClass('none');
  4051.             disabledArrow();
  4052.         }
  4053.     });
  4054. };
  4055. function plusone_vote( obj ) {
  4056.     mig.google.push(['_trackEvent','plusone',obj.state]);
  4057. }
  4058. mig.mobileReload();
  4059.  
  4060. function rotatorJS(prefix, imagesQuantity, productId){
  4061.     var wBlock = 'inline-block';
  4062.     appProperties.engine === 'galeria' ? wBlock = 'block' : false;
  4063.     jQuery(document).ready(function() {
  4064.         jQuery('#player').SpinPlugin({
  4065.             defaultBlock    :   wBlock,
  4066.             defaultSize     :   'tiny',
  4067.             screenHeight    :   525,
  4068.             screenWidth     :   560,
  4069.             popupLink       :   '/product-rotator-js-popup.ltr?productId=' + productId,
  4070.             imagesQuantity  :   imagesQuantity,
  4071.             sizes           : {
  4072.                 tiny    : {
  4073.                     width       :   560,
  4074.                     height      :   525,
  4075.                     src         :   prefix + '/{$step}-tiny.jpg',
  4076.                     moveMode    :   'rotation'
  4077.                 },
  4078.                 small   : {
  4079.                     width       :   800,
  4080.                     height      :   800,
  4081.                     src         :   prefix + '/{$step}-small.jpg',
  4082.                     moveMode    :   'shift'
  4083.                 },
  4084.                 big : {
  4085.                     width       :   1200,
  4086.                     height      :   1200,
  4087.                     src         :   prefix + '/{$step}-big.jpg',
  4088.                     moveMode    :   'shift'
  4089.                 }
  4090.             }
  4091.         });
  4092.     });
  4093. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement