PageSourceSearch

https://mikolajofon.pl/js/common.js

js mikolajofon.pl collected 2026-10-02 02:05:36 UTC 88,324 bytes, 2,172 lines download raw bytes

1var _products = {
2    "trailer": {
3        "preview": [
4            {
5                "type": "video/mp4",
6                "url": "video/preview-movie-trailer.mp4",
7            }
8        ]
9    },
10    "movieaudiobook": {
11        "title": "FILM<span class=\"free-product\"> + AUDIOBOOK </span><span class=\"gratis\">GRATIS</span>",
12        "titleShort": "FILM<span class=\"free-product\"> + AUDIOBOOK </span><span class=\"gratis\">GRATIS</span>",
13        "price": "<span class=\"new-price\">39,99 zł </span> <span class=\"old-price\">84,98 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">60%</span>",
14        "claim": "10 personalizacji:",
15        "mainFeatures": [
16            {
17                "key": "Zawartość pakietu",
18                "value": "Film: 20 min<br />Audiobook: 8 min",
19            },
20            {
21                "key": "Dostawa",
22                "value": "do 5 min",
23            },
24            {
25                "key": "Następny zakup",
26                "value": "20% taniej",
27            },
28        ],
29        "features": [
30            "<li>Imię dziecka</li>",
31            "<li>Wiek dziecka</li>",
32            // "<li>Pochodzenie</li>",
33            "<li>Prezent</li>",
34            "<li>Pochwała</li>",
35            "<li>4x zdjęcie: 2x zdjęcie dziecka, 1x zdjęcie osoby zamawiającej, 1x zdjęcie bliskich</li>",
36            "<li>Film z udziałem dziecka lub dodatkowe zdjęcie dziecka</li>",
37            "<li>🎁 Specjalna dedykacja od Świętego&nbsp;Mikołaja</li>",
38        ],
39        "cta": "DALEJ",
40        "description": "Podaruj dziecku wyjątkowy prezent na święta. Zamów personalizowany film, w którym dziecko zobaczy w magicznej kuli i księdze Św.&nbsp;Mikołaja swoje zdjęcia oraz film ze swoim udziałem. Święty Mikołaj zabierze dziecko w magiczną podróż do świata baśni i przeczyta mu niezwykłą książkę przygotowaną specjalnie do niego.<br /><br />GRATIS otrzymasz audiobook z imienną dedykacją dla dziecka.",
41        "steps": 6,
42        "basic_price": 39.99,
43        "preview": null,
44    },
45    "movie": {
46        "title": "FILM",
47        "titleShort": "FILM",
48        // "price": "<span class=\"new-price\">39,99 zł </span> <span class=\"old-price\">64,99 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">40%</span>",
49        "price": "49.99",
50        "claim": "10 personalizacji:",
51        "mainFeatures": [
52            {
53                "key": "Czas trawania",
54                "value": "20 min",
55            },
56            {
57                "key": "Dostawa",
58                "value": "do 2h",
59            },
60            {
61                "key": "Następny zakup",
62                "value": "20% taniej",
63            },
64        ],
65        "features": [
66            "<li>Imię dziecka</li>",
67            "<li>Wiek dziecka</li>",
68            // "<li>Pochodzenie</li>",
69            "<li>Prezent</li>",
70            "<li>Pochwała</li>",
71            "<li>4x zdjęcie: 2x zdjęcie dziecka, 1x zdjęcie osoby zamawiającej, 1x zdjęcie bliskich</li>",
72            "<li>Film z udziałem dziecka lub dodatkowe zdjęcie dziecka</li>",
73            "<li>🎁 Specjalna dedykacja od Świętego&nbsp;Mikołaja</li>",
74        ],
75        "cta": "DALEJ",
76        "description": "<ul><li>Wyjątkowy film dedykowany Twojemu dziecku.</li><li>Wybrana przez Ciebie baśń w świątecznym wydaniu czytana przez Św.&nbsp;Mikołaja.</li><li>Magiczna biblioteka Św.&nbsp;Mikołaja. w chmurach na Biegunie Północnym.</li><li>Niezapomniane doświadczenie i możliwość pojawienia się w filmie razem ze Św.&nbsp;Mikołajem.</li></ul>",
77        "steps": 5,
78        "basic_price": 49.99,
79        "preview": [
80            {
81                "type": "video/mp4",
82                "url": "video/preview-movie.mp4",
83            }
84        ]
85    },
86    "audiobook": {
87        "title": "AUDIOBOOK",
88        "titleShort": "AUDIOBOOK",
89        // "price": "<span class=\"new-price\">5,99 zł </span> <span class=\"old-price\">19,99 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">70%</span>",
90        "price": "9.99",
91        "claim": "Personalizacja:",
92        "mainFeatures": [
93            {
94                "key": "Czas trawania",
95                "value": "ponad 8 min",
96            },
97            {
98                "key": "Dostawa",
99                "value": "do 5 min",
100            },
101            {
102                "key": "Następny zakup",
103                "value": "20% taniej",
104            },
105        ],
106        "features": [
107            "<li>Imię dziecka</li>",
108            "<li>🎁 Specjalna dedykacja od Świętego&nbsp;Mikołaja</li>",
109        ],
110        "cta": "DALEJ",
111        "description": "<ul><li>Personalizowany audiobook dedykowany Twojemu dziecku.</li><li>Wybrana przez Ciebie baśń w świątecznym wydaniu czytana przez Św.&nbsp;Mikołaja.</li><li>Interpretacja Św.&nbsp;Mikołaja i efekty dźwiękowe.</li><li>Niezapomniane doświadczenie rozwijające wyobraźnię Twojego dziecka.</li></ul>",
112        "steps": 2,
113        "basic_price": 9.99,
114        "preview": [
115            {
116                "type": "video/mp4",
117                "url": "video/preview-audiobook.mp4",
118            }
119        ]
120    },
121    "combo": {
122        "title": "FILM i KSIĄŻKA <span class=\"free-product\"> + AUDIOBOOK i E-BOOK </span><span class=\"gratis\">GRATIS</span>",
123        "titleShort": "FILM i KSIĄŻKA <span class=\"free-product\"> + AUDIOBOOK i E-BOOK </span><span class=\"gratis\">GRATIS</span>",
124        "price": "<span class=\"new-price\">89,98 zł </span> <span class=\"old-price\">214,96 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">60%</span>",
125        "claim": "10 personalizacji:",
126        "mainFeatures": [
127            {
128                "key": "Zawartość pakietu",
129                "value": "<span style=\"font-weight: normal;\">Film:</span> 20 min<br /><span style=\"font-weight: normal;\">Audiobook:</span> 8 min<br /><span style=\"font-weight: normal;\">Książka/E-book:</span> ponad 40 str.",
130            },
131            {
132                "key": "Dostawa",
133                "value": "do 5 min",
134            },
135            {
136                "key": "Następny zakup",
137                "value": "20% taniej",
138            },
139        ],
140        "features": [
141            "<li>Imię dziecka</li>",
142            "<li>Wiek dziecka</li>",
143            // "<li>Pochodzenie</li>",
144            "<li>Prezent</li>",
145            "<li>Pochwała</li>",
146            "<li>4x zdjęcie: 2x zdjęcie dziecka, 1x zdjęcie osoby zamawiającej, 1x zdjęcie bliskich</li>",
147            "<li>Film z udziałem dziecka lub dodatkowe zdjęcie dziecka</li>",
148            "<li>🎁 Specjalna dedykacja od Świętego&nbsp;Mikołaja</li>",
149        ],
150        "cta": "DALEJ",
151        "description": "Podaruj dziecku wyjątkowe prezenty na święta. Zamów film, w którym dziecko zobaczy siebie na ekranie oraz książkę, w której Św.&nbsp;Mikołaj zwraca się do niego po imieniu. Mikołaj zabierze dziecko w magiczną podróż do świata baśni, czytając książkę przygotowaną dla niego.<br /><br />GRATIS otrzymasz audiobook i e-book, w których Św.&nbsp;Mikołaj zwraca sią do dziecka po imnieniu.",
152        "steps": 7,
153        "basic_price": 89.98,
154        "preview": null,
155    },
156    "book": {
157        "title": "KSIĄŻKA",
158        "titleShort": "KSIĄŻKA",
159        // "price": "<span class=\"new-price\">49,99 zł </span> <span class=\"old-price\">99,99 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">50%</span>",
160        "price": "59.99",
161        "claim": "Personalizacja:",
162        "mainFeatures": [
163            {
164                "key": "Ilość stron",
165                "value": "ponad 40",
166            },
167            {
168                "key": "Dostawa",
169                "value": "do 5 dni roboczych",
170            },
171            {
172                "key": "Następny zakup",
173                "value": "20% taniej",
174            },
175        ],
176        "features": [
177            "<li>Imię dziecka</li>",
178            "<li>🎁 Specjalna dedykacja od Świętego Mikołaja</li>",
179        ],
180        "cta": "DALEJ",
181        "description": "<ul><li>Personalizowana książka z wybraną baśnią w świątecznym wydaniu.</li><li>Odręczna dedykacja dla Twojego dziecka od Św.&nbsp;Mikołaja.</li><li>Najpiękniejsze baśnie ilustracje i magia ukryta w każdej zwrotce.</li><li>Piękne wydanie w twardej oprawie ze złoceniami.</li><li>Możliwość zapakowania na prezent - otrzymujesz prezent gotowy do położenia pod choinką.</li></ul>",
182        "steps": 3,
183        "basic_price": 59.99,
184        "preview": [
185            {
186                "type": "video/mp4",
187                "url": "video/preview-book.mp4",
188            }
189        ]
190    },
191    "ebook": {
192        "title": "E-BOOK",
193        "titleShort": "E-BOOK",
194        // "price": "<span class=\"new-price\">9,99 zł </span> <span class=\"old-price\">29,99 zł </span>&nbsp;&nbsp;<span class=\"saving\">zyskujesz</span> <span class=\"saving-num\">60%</span>",
195        "price": "gratis",
196        "claim": "Personalizacja:",
197        "mainFeatures": [
198            {
199                "key": "Ilość stron",
200                "value": "ponad 40",
201            },
202            {
203                "key": "Dostawa",
204                "value": "do 5 min",
205            },
206            {
207                "key": "Następny zakup",
208                "value": "20% taniej",
209            },
210        ],
211        "features": [
212            "<li>Imię dziecka</li>",
213            "<li>🎁 Specjalna dedykacja od Świętego Mikołaja</li>",
214        ],
215        "cta": "DALEJ",
216        "description": "<ul><li>Personalizowany e-book z wybraną baśnią w świątecznym wydaniu.</li><li>Dedykacja dla Twojego dziecka od Św.&nbsp;Mikołaja.</li><li>Pięknie ilustrowane baśnie z magią ukrytą w każdej zwrotce.</li><li>Elektroniczne wydanie książki łatwe do zabrania w podróż lub na świąteczny rodzinny wyjazd.</li>",
217        "steps": 2,
218        "basic_price": 0.00,
219        "preview": [
220            {
221                "type": "video/mp4",
222                "url": "video/preview-ebook-book.mp4",
223            }
224        ]
225    },
226};
227
228var _product_type = "movie";
229var _max_steps = 6;
230var fileUploads = new Array(
231    'child-photo-1',
232    'child-photo-2',
233    'child-photo-3',
234    'custom-photo-1',
235    'custom-photo-2',
236);
237var fileBlobs = {
238    'child-photo-1': null,
239    'child-photo-2': null,
240    'child-photo-3': null,
241    'custom-photo-1': null,
242    'custom-photo-2': null,
243};
244var _currentStory = null;
245var _currentFileUpload = null;
246var _promo_price = 1.0;
247var _redeemMovieQuality = null;
248var _redeemOrderTime = null;
249var _redeemAudiobook = false;
250var _redeem = null;
251
252function showModal(product_type) {
253    if (product_type == 'movie') {
254        alert('Film od Mikołaja dostępny wkrótce 🎅🏻');
255        return;
256    }
257
258    if (_redeem == null) {
259        window.dataLayer = window.dataLayer || [];
260        window.dataLayer.push({
261            'event': 'click_zamow',
262            'item_name': (product_type == 'movie' ? 'Film' : (product_type == 'audiobook' ? 'Audiobook' : (product_type == 'ebook' ? 'E-book' : 'Książka'))),
263        });
264    }
265
266    _promo_price = 1.0;
267    $('.order-fv-check').parent().show();
268    $('.order-total-sum').show();
269    $('#order-item-movie').show();
270    $('.row-order-promo-code').show();
271    $('.hr-order').show();
272    // $('.header-order').show();
273    $('#paymentMethod').show();
274    $('#orderSummaryAddressOverlay').hide();
275    $('#order-item-row-gift').hide();
276    $('#btnOrder')[0].innerText = 'Zamów i zapłać';
277    $($('#purchaseModal')[0].children[0]).removeClass('modal-fullscreen');
278    $('#btnPrev').hide();
279    $('.file-upload-custom-label').hide();
280    if (product_type == 'movie' && (window.innerWidth || document.body.clientWidth) < 992) {
281        $('#modal-purchase-content').css('min-height', '110vh');
282    }
283    else if (product_type != 'movie' && (window.innerWidth || document.body.clientWidth) < 992) {
284        $('#modal-purchase-content').css('min-height', '68vh');
285    }
286    _product_type = product_type;
287    // ustawienie kreatora
288    _max_steps = _products[_product_type]["steps"];
289    $('#progressbar').attr('aria-valuenow', '1');
290    $('#progressbar').attr('aria-valuemax', _max_steps);
291    $('.progress-bar')[0].style.width = (1/_max_steps)*100 + '%';
292    // $('.progress-bar').html('<span class="progress-bar-label">Krok </span>1 z ' + _max_steps);
293    $('.custom-progress-bar-label').html('Krok 1/' + _max_steps);
294
295    $('#productType').val(product_type);
296    $('#product-title-details').html(_products[_product_type].title);
297    $('#product-title-order').html(_products[_product_type].titleShort);
298    $('#product-price').html(_products[_product_type].price);
299    $('#modal-subtitle').html(_products[_product_type].price);
300    if (_product_type == 'ebook' || (_product_type == 'movie' && _redeem) || (_product_type == 'audiobook' && _redeem)) {
301        $('#modal-subtitle').html('Odbierz');
302    }
303    $('#productTitleBackButton').hide();
304    $('#productTitleOverlay').show();
305    $('#product-claim').html(_products[_product_type].claim);
306    $('#product-button-customize').html(_products[_product_type].cta);
307    $('#product-description').html(_products[_product_type].description);
308    $('#product-features').html(_products[_product_type].features.join(''));
309    if (_products[_product_type].features.length < 4) {
310        $('#product-features')[0].style['columns'] = 1;
311        $('#product-features')[0].style['-webkit-columns'] = 1;
312        $('#product-features')[0].style['-moz-columns'] = 1;
313    }
314    else {
315        if (window.innerWidth >= 992) {
316            $('#product-features')[0].style['columns'] = 2;
317            $('#product-features')[0].style['-webkit-columns'] = 2;
318            $('#product-features')[0].style['-moz-columns'] = 2;
319        }
320    }
321    for (var i = 0; i < _products[_product_type].mainFeatures.length; i++) {
322        $('#feature-'+(i+1)+'-key').html(_products[_product_type].mainFeatures[i].key);
323        $('#feature-'+(i+1)+'-value').html(_products[_product_type].mainFeatures[i].value);
324    }
325    // $('#productModal').modal('show');
326    $('#purchaseModal').modal('show');
327    // openStoryStep();
328    $('#product-description').removeOrphans();    
329
330    // if (!$('#modal-purchase-left').is(':hidden')) {
331    if ($('#modal-purchase-right')[0].classList.contains('col-md-12')) {
332        $('#modal-purchase-left').show();
333        $('#modal-purchase-right').toggleClass('col-md-12');
334        $('#modal-purchase-right').toggleClass('col-md-8');
335        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kapturek');
336        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-jas-i-malgosia');
337        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kopciuszek');
338    }
339
340    window.dataLayer = window.dataLayer || [];
341    dataLayer.push({
342        'event' : 'personalization_path',
343        'item_name' : (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),
344        'step': 0,
345        'user_type' : (_redeem == true ? 'App' : 'Web')
346    });
347}
348
349var _scrollDistance = 1400;
350if (window.innerWidth < 992) {
351    _scrollDistance = window.innerWidth + window.innerWidth * 5/100;
352}
353
354function scrollLeftClick() {
355    $('#product-cards').animate({ scrollLeft: '-=' + _scrollDistance }, 300, function() {
356        // if ($('#product-cards')[0].scrollLeft == 0) {
357        if (_scrollDistance == 800)
358            $('#btn-scroll-left').animate({ opacity: 0 }, 300);
359        // }
360        $('#btn-scroll-right').animate({ opacity: 1 }, 300);
361        // if ($('#product-cards')[0].scrollLeftMax > $('#product-cards')[0].scrollLeft) {
362        //     $('#btn-scroll-right').animate({ opacity: 1 }, 300);
363        // }
364    });
365}
366
367function scrollRightClick() {
368    $('#product-cards').animate({ scrollLeft: '+=' + _scrollDistance }, 300, function() {
369        // if ($('#product-cards')[0].scrollLeft > 0) {
370        $('#btn-scroll-left').animate({ opacity: 1 }, 300);
371        // }
372        // if ($('#product-cards')[0].scrollLeftMax >= $('#product-cards')[0].scrollLeft) {
373        if (_scrollDistance == 800)
374            $('#btn-scroll-right').animate({ opacity: 0 }, 300);
375        // }
376    });
377}
378
379document.onkeydown = checkKey;
380
381function checkKey(e) {
382    e = e || window.event;
383
384    if (e.keyCode == '37') {
385       scrollLeftClick();
386    }
387    else if (e.keyCode == '39') {
388       scrollRightClick();
389    }
390
391}
392
393function isScrolledIntoView(elem) {
394    var docViewTop = $(window).scrollTop();
395    var docViewBottom = docViewTop + $(window).height();
396
397    var elemTop = $(elem).offset().top;
398    var elemBottom = elemTop + $(elem).height();
399
400    return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
401}
402
403function onPurchasePrevStep() {
404    document.getElementById('purchaseModal').scrollTo({top: 0, left: 0, behavior: "smooth"});
405    $('#paymentMethod').show();
406    $($('#purchaseModal')[0].children[0]).removeClass('modal-fullscreen');
407
408    var currentStep = parseInt($('#purchaseStep').val());
409    // console.log('onPurchasePrevStep: ', currentStep);
410    if (_product_type == 'movie' && (currentStep - 1 == 4 || currentStep - 1 == 5)) {
411        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kapturek');
412        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-jas-i-malgosia');
413        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kopciuszek');
414    }
415    if ( (_product_type == 'movie' && (currentStep - 1 == 3)) 
416        || (_product_type == 'book' && currentStep == 8)
417        || (_product_type == 'audiobook' && currentStep == 7)
418    ) {
419        switch (_currentStory) {
420            case '1':
421                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kapturek');
422                break;
423            case '2':
424                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kopciuszek');
425                break;
426            case '3':
427                $('#modal-purchase-content').addClass('modal-purchase-content-bg-jas-i-malgosia');
428                break;
429        }
430    }
431    if (currentStep - 1 == STEP_ORDER_EMAIL) {
432        $('#btnPrev').hide();
433        if ($('#modal-purchase-left').is(':hidden')) {
434            $('#modal-purchase-left').show();
435            $('#modal-purchase-right').toggleClass('col-md-12');
436            $('#modal-purchase-right').toggleClass('col-md-8');
437            $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kapturek');
438            $('#modal-purchase-content').removeClass('modal-purchase-content-bg-jas-i-malgosia');
439            $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kopciuszek');
440        }
441    }
442    else {
443        $('#btnPrev').show();
444    }
445    // console.log(currentStep);
446    if (_product_type == "book" && currentStep == STEP_ORDER_SUMMARY) {
447        $('#purchaseStep' + currentStep).fadeOut(function() {
448            $('#progressbar').show();
449            $('.custom-progress-bar-label').show();
450            currentStep = STEP_ORDER_ADDRESS;
451            showStep(currentStep);
452            $('#purchaseStep').val(STEP_ORDER_ADDRESS);
453            animateProgressBar(3);
454            // $('#modal-subtitle').text('Personalizacja');
455            $('#modal-subtitle').html(_products[_product_type].price);
456            $('#productTitleBackButton').hide();
457            $('#productTitleOverlay').show();
458            $('#btnNext').text('Dalej');
459            $('#btnNext').fadeIn();
460            $('#paymentButtonOverlay').hide();
461            $('#productPurchaseButtons').show();
462        });
463        return;
464    }
465    if (_product_type == "book" && currentStep == STEP_ORDER_ADDRESS) {
466        $('#purchaseStep' + currentStep).fadeOut(function() {
467            $('#progressbar').show();
468            $('.custom-progress-bar-label').show();
469            currentStep = STEP_ORDER_CHILD_NAME;
470            showStep(currentStep);
471            animateProgressBar(currentStep);
472            // $('#modal-subtitle').text('Personalizacja');
473            $('#modal-subtitle').html(_products[_product_type].price);
474            $('#productTitleBackButton').hide();
475            $('#productTitleOverlay').show();
476        });
477        return;
478    }
479
480    if (_product_type == "combo" && currentStep == STEP_ORDER_SUMMARY) {
481        $('#purchaseStep' + currentStep).fadeOut(function() {
482            $('#progressbar').show();
483            $('.custom-progress-bar-label').show();
484            currentStep = STEP_ORDER_ADDRESS;
485            showStep(currentStep);
486            $('#purchaseStep').val(STEP_ORDER_ADDRESS);
487            animateProgressBar(7);
488            // $('#modal-subtitle').text('Personalizacja');
489            $('#modal-subtitle').html(_products[_product_type].price);
490            $('#productTitleBackButton').hide();
491            $('#productTitleOverlay').show();
492            $('#btnNext').text('Dalej');
493            $('#btnNext').fadeIn();
494            $('#paymentButtonOverlay').hide();
495            $('#productPurchaseButtons').show();
496        });
497        return;
498    }
499    if (_product_type == "combo" && currentStep == STEP_ORDER_ADDRESS) {
500        $('#purchaseStep' + currentStep).fadeOut(function() {
501            $('#progressbar').show();
502            $('.custom-progress-bar-label').show();
503            currentStep = 6;
504            showStep(currentStep);
505            animateProgressBar(currentStep);
506            // $('#modal-subtitle').text('Personalizacja');
507            $('#modal-subtitle').html(_products[_product_type].price);
508            $('#productTitleBackButton').hide();
509            $('#productTitleOverlay').show();
510        });
511        return;
512    }
513
514    // console.log(currentStep);
515    // console.log(_product_type);
516    if (currentStep == 8) {
517        currentStep = 7;
518    }
519    if (currentStep - 1 >= 1) {
520        // if movie then skip one step
521        if (_product_type == "movie" && currentStep - 1 == 3) {
522            $('#purchaseStep' + currentStep).hide();
523            currentStep--;
524        }
525
526        $('#purchaseStep' + currentStep).fadeOut(function() {
527            if (currentStep >= 7) {
528                // console.log('b1');
529                $('#btnNext').fadeOut(() => {
530                    $('#btnNext').text('Dalej');
531                    $('#btnNext').fadeIn();
532                });
533                $('#paymentButtonOverlay').hide();
534            }
535            if (currentStep >= 7 && (_product_type == 'audiobook' || _product_type == 'ebook' || _product_type == 'book')) {
536                // console.log('b2');
537                currentStep = 2;
538            }
539            else {
540                // console.log('b3');
541                currentStep--;
542            }
543            
544            showStep(currentStep);
545            $('#progressbar').show();
546            $('.custom-progress-bar-label').show();
547            animateProgressBar(currentStep);
548            // $('#modal-subtitle').text('Personalizacja');
549            $('#modal-subtitle').html(_products[_product_type].price);
550            if (_product_type == 'ebook' || (_product_type == 'movie' && _redeem) || (_product_type == 'audiobook' && _redeem)) {
551                $('#modal-subtitle').html('Odbierz');
552            }
553            $('#productTitleBackButton').hide();
554            $('#productTitleOverlay').show();
555        });
556    }
557    if (currentStep == STEP_ORDER_EMAIL) {
558        $('#purchaseModal').modal('hide');
559        // $('#productModal').modal('show');
560        $('#storyModal').modal('show');
561    }
562}
563
564function generateOrderSummary() {
565    if (_product_type == "ebook") {
566        $('#paymentMethod').hide();
567        $('#order-item-ebook').hide();
568        $('.row-order-promo-code').hide();
569        $('.order-total-sum').hide();
570        $('.order-fv-check').parent().hide();
571        $('.hr-order').hide();
572        $('#btnOrder')[0].innerText = 'Zamawiam';
573    }
574    if (_product_type == 'ebook' || (_product_type == 'movie' && _redeem) || (_product_type == 'audiobook' && _redeem)) {
575        $('#btnOrder')[0].innerText = 'Zamawiam';
576    }
577    $($('#purchaseModal')[0].children[0]).addClass('modal-fullscreen');
578    $('#btnPrev').hide();
579    $('#orderSummaryEmail').text($('#email').val());
580    $('#orderSummaryEmailName').text($('#name').val());
581    switch (_currentStory) {
582        case '1':
583            $('#orderSummaryStory').text('Czerwony Kapturek');
584            break;
585        case '2':
586            $('#orderSummaryStory').text('Kopciuszek');
587            break;
588        case '3':
589            $('#orderSummaryStory').text('Jaś i Małgosia');
590            break;
591    }
592    
593    $('#orderSummaryAge').text($('#childAge').val());
594    // $('#orderSummaryName').text($('#childFirstName option:selected').text());
595    $('#orderSummaryName').text($('#childFirstName').val());
596    // $('#orderSummaryPoliteness').text($('#childPoliteness option:selected').text());
597    $('#orderSummaryGift').text($('#childGift option:selected').text());
598    $('#orderSummaryPraise').text($('#childPraise option:selected').text());
599    // $('#orderSummaryHobby').hide();
600    // $('#orderSummaryHobby').text($('#childHobby option:selected').text());
601
602    for (var i = 1; i <= 5; i++) {
603        var imgPreview = $('#img-preview-' + i)[0].parentElement;
604        var imgSource = $('#photo-' + i)[0];
605        imgPreview.style.backgroundImage = imgSource.style.backgroundImage.replace('photo-ok.png', 'photo-ok-2.png');
606        imgPreview.style.backgroundSize = 'contain';
607        imgPreview.style.backgroundRepeat = 'no-repeat';
608        imgPreview.style.backgroundPosition = 'center';
609        imgPreview.style.border = 'solid 2px green';
610        if (imgSource.style.backgroundImage.substring(0, 32).indexOf('video/quicktime') == -1) {
611            $('#img-preview-' + i).hide();    
612        }
613        else {
614            $('#img-preview-' + i).show();    
615            $('#video-done-2').show();
616        }
617    }
618
619    if (_product_type == "combo" || _product_type == "book") {
620        $('#orderSummaryAddressOverlay').show();
621        $('#orderSummaryAddress').html('<span>'
622            + $('#parentsName').val() + '<br />'
623            + $('#parentsStreet').val() + ' ' + $('#parentsStreetNum').val() + ($('#parentsStreetFlat').val() != '' ? '/' + $('#parentsStreetFlat').val() : '' ) + '<br />'
624            + $('#parentsPostCode').val() + ' ' + $('#parentsCity').val() + '<br />'
625            + $('#parentsPhone').val() + '<br />'
626            + '</span>'
627        );
628        var deliveryType = '';
629        switch ($('input[name="deliveryType"]:checked').val()) {
630            case '2':
631                deliveryType = 'Paczkomaty InPost';
632                break;
633            case '3':
634                deliveryType = 'ORLEN Paczka';
635                break;
636            case '1':
637            default:
638                deliveryType = 'Kurier InPost';
639                break;
640        }
641        $('#orderSummaryDeliveryType').html('<span>' + deliveryType + '</span>');
642    }
643    if (_product_type == "combo" || _product_type == "book") {
644        var gift = '';
645        switch ($('input[name="bookAsGift"]:checked').val()) {
646            case '2':
647                deliveryType = 'Paczkomaty InPost';
648                $('#order-item-row-gift').show();
649                break;
650            case '1':
651            default:
652                $('#order-item-row-gift').hide();
653                break;            
654        }
655    }
656    $('#order-item-audiobook').hide();
657    $('#order-item-ebook').hide();
658    $('#order-item-book').hide();
659    $('#order-item-movieaudiobook').hide();
660    $('#order-item-book').hide();
661    $('#order-item-combo').hide();
662    $('#order-item-movie').hide();
663    $('#order-item-'+_product_type).show();
664
665    if (_product_type == 'ebook') {
666        $('#order-item-ebook').hide();
667    }
668    if (_product_type == 'audiobook' && _redeem) {
669        $('#order-item-audiobook').hide();
670        $('.order-fv-check').parent().hide();
671        $('.order-total-sum').hide();
672        $('.hr-order').hide();
673    }
674    if (_product_type == 'movie' && _redeem) {
675        $('.order-fv-check').parent().hide();
676        $('.order-total-sum').hide();
677        $('#order-item-movie').hide();
678        $('.row-order-promo-code').hide();
679        // $('.header-order').hide();
680        $('.hr-order').hide();
681    }
682}
683
684function validateAddress() {
685    var addressFields = new Array();
686    addressFields.push('parentsName');
687    addressFields.push('parentsStreet');
688    addressFields.push('parentsStreetNum');
689    addressFields.push('parentsPostCode');
690    addressFields.push('parentsCity');
691    addressFields.push('parentsPhone');
692    for (var i = 0; i < addressFields.length; i++) {
693        if ($('#' + addressFields[i]).val() == '') {
694            $('#' + addressFields[i])[0].reportValidity();
695            return false;
696        }
697    }
698    if ($('input[name="deliveryType"]:checked').val() == '2' && $('#currentPaczkomat').val() == '') {
699        alert('Proszę wybrać Paczkomat.');
700        return false;
701    }
702    return true;
703}
704
705var STEP_ORDER_EMAIL = 1;
706var STEP_ORDER_CHILD_NAME = 2;
707var STEP_ORDER_SUMMARY = 7;
708var STEP_ORDER_ADDRESS = 8;
709
710function onPurchaseNextStepShort(currentStep) {
711    document.getElementById('purchaseModal').scrollTo({top: 0, left: 0, behavior: "smooth"});
712    // wysyłka formularza zamówienia
713    if (currentStep == STEP_ORDER_SUMMARY) {
714        if ($('#agreeBasic')[0].reportValidity()) {
715            $('#btnPrev').prop('disabled', true);
716            $('#btnNext').prop('disabled', true);
717
718            $('#purchaseCreator').submit();    
719        }
720        return;
721    }
722    if (currentStep == STEP_ORDER_EMAIL) {
723        if ($('input[type=radio][name=story]:checked').length == 1) {
724            $('#choosenStory').val($('input[name="story"]:checked').val());
725        }
726        else {
727            alert('Wybierz tytuł baśni');
728            return false;
729        }
730        if (!$('#email')[0].checkValidity()) {
731            $('#email')[0].reportValidity();
732            return false;
733        }        
734        if (!$('#name')[0].checkValidity()) {
735            $('#name')[0].reportValidity();
736            return false;
737        }
738        $('#modal-purchase-left').hide();
739        $('#modal-purchase-right').toggleClass('col-md-8');
740        $('#modal-purchase-right').toggleClass('col-md-12');
741        switch (_currentStory) {
742            case '1':
743                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kapturek');
744                break;
745            case '2':
746                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kopciuszek');
747                break;
748            case '3':
749                $('#modal-purchase-content').addClass('modal-purchase-content-bg-jas-i-malgosia');
750                break;
751        }
752        $('#btnPrev').show();
753    }
754    // akcje do wykonania przed zmianą kroku
755    if (currentStep + 1 == STEP_ORDER_CHILD_NAME) {
756        // w krótkich personalizacjach ukrywamy wiek
757        $('#childAgeOverlay').hide();
758    }
759    if (currentStep == STEP_ORDER_CHILD_NAME) {
760        if ($('#childFirstName').val() == '') {
761            $('#childFirstName')[0].reportValidity();
762            return false;
763        }
764        else {
765            var is_valid_child_name = false;
766            for (var i = 0; i < $('#childFirstName')[0].list.options.length; i++) {
767                var opt = $('#childFirstName')[0].list.options[i];
768                if (opt.value == $('#childFirstName')[0].value.toUpperCase()) {
769                    $('#childFirstName')[0].value = $('#childFirstName')[0].value.toUpperCase();
770                    is_valid_child_name = true;
771                }
772            }
773            if (!is_valid_child_name) {
774                $('#childFirstName')[0].setCustomValidity('Wybierz imię z listy.');
775                $('#childFirstName')[0].reportValidity();
776                return false;
777            }
778        }
779    }
780    if (_product_type == "book" && currentStep == STEP_ORDER_ADDRESS) {
781        if (!validateAddress()) {
782            return false;
783        }
784    }
785    if (currentStep + 1 == 3) {
786        if (_product_type == "book") {
787            $('#bookDetails').show();
788        }
789        else {
790            $('#bookDetails').hide();
791        }
792    }
793    if (_product_type == "book" && currentStep + 1 == 3) {
794        // książka - następny krok to wyświetlenie adresu
795        $('#purchaseStep' + currentStep).fadeOut(function() {
796            $('#parentsName').val($('#name').val());
797            currentStep = 8;
798            showStep(currentStep);
799            $('#purchaseStep').val(STEP_ORDER_ADDRESS);
800            animateProgressBar(3);
801            // $('#modal-subtitle').text('Personalizacja');
802            $('#modal-subtitle').html(_products[_product_type].price);
803            $('#productTitleBackButton').hide();
804            $('#productTitleOverlay').show();
805        });
806        return;
807    }
808    // formularz podsumowania
809    if ((currentStep + 1 > _products[_product_type]["steps"]) || (_product_type == "book" && currentStep == STEP_ORDER_ADDRESS)) {
810        $('#progressbar').fadeOut();
811        $('.custom-progress-bar-label').fadeOut();
812        $('#purchaseStep' + currentStep).fadeOut(function() {
813            generateOrderSummary();
814            // tabelka podsumowania
815            var basic_price = _products[_product_type]["basic_price"];
816            basic_price *= _promo_price;
817
818            $('#order-item-movie-quality').hide();
819            $('#order-item-order-time').hide();
820
821            if (_product_type == "book") {
822                switch ($('input[name="deliveryType"]:checked').val()) {
823                    case '2':
824                        // deliveryType = 'Paczkomaty InPost';
825                        basic_price += 0.0;
826                        // $('#order-item-delivery-type').text('19,99');
827                        break;
828                    case '3':
829                        // deliveryType = 'ORLEN Paczka';
830                        basic_price += 0.0;
831                        // $('#order-item-delivery-type').text('11,99');
832                        break;
833                    case '1':
834                    default:
835                        // deliveryType = 'Kurier InPost';
836                        basic_price += 0.0;
837                        // $('#order-item-delivery-type').text('19,99');
838                        break;
839                }
840                var gift = '';
841                switch ($('input[name="bookAsGift"]:checked').val()) {
842                    case '2':
843                        basic_price += 29.99;
844                        break;
845                    case '1':
846                    default:
847                        break;            
848                }
849            }
850            $('#order-total-price').text(sprintf("%.2f", basic_price).replace('.', ','));
851            
852            // ustawienia widoku
853            $('#orderDetails').hide();
854            $('.order-photos-preview').hide();
855            $('.order-photos-preview-content').hide();
856            $('.order-photos-preview-confirm').hide();
857            $('#btnNext').fadeOut(() => {
858                // $('#btnNext').text('Zamów i zapłać');
859                // $('#btnNext').fadeIn();
860            });
861            $('#paymentButtonOverlay').fadeIn();
862            $('#modal-subtitle').fadeOut(() => {
863                $('#productTitleBackButton').show();
864                $('#productTitleOverlay').hide();
865                // $('#modal-subtitle').text('Podsumowanie');
866                $('#modal-subtitle').fadeIn();
867
868                window.dataLayer = window.dataLayer || [];
869                dataLayer.push({ ecommerce: null });
870                window.dataLayer.push({
871                    event: 'initiate_checkout',           
872                    ecommerce: {      
873                        currency: 'PLN',
874                        value: parseFloat(_products[_product_type]["basic_price"]),   
875                        coupon: '',                    
876                        items: [{                          
877                            item_name: (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),          
878                            item_id: _product_type,           
879                            price: parseFloat(_products[_product_type]["basic_price"]),                            
880                            item_category: (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),               
881                            item_variant: (_currentStory == '1' ? 'Czerwony Kapturek' : (_currentStory == '2' ? 'Kopciuszek' : 'Jaś i Małgosia')),                                    
882                            quantity: 1                   
883                        }]
884                    }
885                });
886    
887                showStep(STEP_ORDER_SUMMARY);
888            });
889            recalculatePrice();
890        });
891    }
892    else {
893        // zmiana kroku
894        $('#purchaseStep' + currentStep).fadeOut(function() {
895            currentStep++;
896            showStep(currentStep);
897            animateProgressBar(currentStep);
898            // $('#modal-subtitle').text('Personalizacja');
899            $('#modal-subtitle').html(_products[_product_type].price);
900            if (_product_type == 'ebook' || (_product_type == 'movie' && _redeem) || (_product_type == 'audiobook' && _redeem)) {
901                $('#modal-subtitle').html('Odbierz');
902            }
903            $('#productTitleBackButton').hide();
904            $('#productTitleOverlay').show();
905        });
906    }
907}
908
909function onPurchaseNextStep() {
910    document.getElementById('purchaseModal').scrollTo({top: 0, left: 0, behavior: "smooth"});
911    var currentStep = parseInt($('#purchaseStep').val());
912    // console.log('onPurchaseNextStep: ', currentStep);
913
914    if (_product_type == 'movie' && (currentStep + 1 == 7 || currentStep == 5) && _redeemMovieQuality != null && _redeemOrderTime != null) {
915        $('[name="movieQuality"]').attr('checked', false);
916        $('[name="orderTime"]').attr('checked', false);
917        $('#movieQuality' + _redeemMovieQuality).attr('checked', true);
918        $('#orderTime' + _redeemOrderTime).attr('checked', true);
919        $('[name="movieQuality"]').attr('disabled', true);
920        $('[name="orderTime"]').attr('disabled', true);
921        $('#btnOrder').val('Zamawiam');
922    }
923    else {
924        $('[name="movieQuality"]').attr('disabled', false);
925        $('[name="orderTime"]').attr('disabled', false);
926    }
927
928    if ( (_product_type == 'movie' && (currentStep + 1 == 3)) 
929        || (_product_type == 'book' && currentStep == 2)
930        || (_product_type == 'audiobook' && currentStep == 2)
931        || (_product_type == 'ebook' && currentStep == 2)
932    ) {
933        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kapturek');
934        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-kopciuszek');
935        $('#modal-purchase-content').removeClass('modal-purchase-content-bg-jas-i-malgosia');
936    }
937
938    // console.log(_product_type, currentStep, STEP_ORDER_ADDRESS);
939
940    if (_product_type == "audiobook" || _product_type == "ebook" || _product_type == "book") {
941        $('#childGiftOverlay').hide();
942        $('#childPraiseOverlay').hide();
943        onPurchaseNextStepShort(currentStep);
944        return;
945    }
946    else {
947        $('#childGiftOverlay').show();
948        $('#childPraiseOverlay').show();
949    }
950
951    // obsługa kreatora movieaudiobook zostaje poniżej
952    if (currentStep == 1) {
953        if ($('input[type=radio][name=story]:checked').length == 1) {
954            $('#choosenStory').val($('input[name="story"]:checked').val());
955        }
956        else {
957            alert('Wybierz tytuł baśni');
958            return false;
959        }
960        if (!$('#email')[0].checkValidity()) {
961            $('#email')[0].reportValidity();
962            return false;
963        }
964        if (!$('#name')[0].checkValidity()) {
965            $('#name')[0].reportValidity();
966            return false;
967        }
968        $('#modal-purchase-left').hide();
969        switch (_currentStory) {
970            case '1':
971                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kapturek');
972                break;
973            case '2':
974                $('#modal-purchase-content').addClass('modal-purchase-content-bg-kopciuszek');
975                break;
976            case '3':
977                $('#modal-purchase-content').addClass('modal-purchase-content-bg-jas-i-malgosia');
978                break;
979        }
980        $('#modal-purchase-right').toggleClass('col-md-8');
981        $('#modal-purchase-right').toggleClass('col-md-12');
982        $('#btnPrev').show();
983    }
984    if (currentStep + 1 == 2) {
985        if (_product_type == 'audiobook' || _product_type == 'ebook' || _product_type == 'book') {
986            $('#childAgeOverlay').hide();
987        }
988        else {
989            $('#childAgeOverlay').show();    
990        }
991    }
992    if (currentStep == 2) {
993        if (_product_type == 'movie' || _product_type == 'combo' || _product_type == 'movieaudiobook') {
994            if ($('#childFirstName').val() == '') {
995                $('#childFirstName')[0].reportValidity();
996                return false;
997            }
998            var is_valid_child_name = false;
999            for (var i = 0; i < $('#childFirstName')[0].list.options.length; i++) {
1000                var opt = $('#childFirstName')[0].list.options[i];
1001                if (opt.value == $('#childFirstName')[0].value.toUpperCase()) {
1002                    $('#childFirstName')[0].value = $('#childFirstName')[0].value.toUpperCase();
1003                    is_valid_child_name = true;
1004                }
1005            }
1006            if (!is_valid_child_name) {
1007                $('#childFirstName')[0].setCustomValidity('Wybierz imię z listy.');
1008                $('#childFirstName')[0].reportValidity();
1009                return false;
1010            }
1011            if ($('#childAge').val() == '') {
1012                $('#childAge')[0].reportValidity();
1013                return false;
1014            }
1015            var is_valid_age = false;
1016            for (var i = 0; i < $('#childAge')[0].list.options.length; i++) {
1017                var opt = $('#childAge')[0].list.options[i];
1018                if (opt.value == $('#childAge')[0].value.toUpperCase()) {
1019                    $('#childAge')[0].value = $('#childAge')[0].value.toUpperCase();
1020                    is_valid_age = true;
1021                }
1022            }
1023            if (!is_valid_age) {
1024                $('#childAge')[0].setCustomValidity('Wybierz wiek z listy.');
1025                $('#childAge')[0].reportValidity();
1026                return false;
1027            }
1028        }
1029    }
1030    if (currentStep == 6) {
1031        if (_product_type == "combo") {
1032            $('#bookDetails').show();
1033        }
1034        else {
1035            $('#bookDetails').hide();
1036        }
1037    }
1038    if (currentStep + 1 <= 6) {
1039        if (currentStep + 1 == 3 && (_product_type == 'audiobook' || _product_type == 'ebook' || _product_type == 'book')) {
1040            $('#purchaseStep' + currentStep).hide();
1041            $('#orderDetails').hide();
1042            $('.order-photos-preview').hide();
1043            $('.order-photos-preview-content').hide();
1044            $('.order-photos-preview-confirm').hide();
1045            if (_product_type == 'book') {
1046                currentStep = 7;    
1047            }
1048            else {
1049                currentStep = 8;
1050            }
1051            $('#purchaseStep').val(currentStep)
1052            showStep(currentStep);
1053            animateProgressBar(currentStep);
1054            return;
1055        }
1056        // weryfikacja plików
1057        if (currentStep == 4) {
1058            for (var i = 0; i < 3; i++) {
1059                if ($('#' + fileUploads[i]).val() == '') {
1060                    alert('Upewnij się, że dołączono wszystkie pliki.');
1061                    return false;
1062                }
1063            }
1064        }
1065        if (currentStep == 5) {
1066            for (var i = 3; i < fileUploads.length; i++) {
1067                if ($('#' + fileUploads[i]).val() == '') {
1068                    alert('Upewnij się, że dołączono wszystkie pliki.');
1069                    return false;
1070                }
1071            }
1072        }
1073        if (currentStep == 6) {
1074            switch(_product_type) {
1075                case "combo":
1076                    $('#movieDetails').show();
1077                    $('#addressDetails').show();
1078                    $('#parentsName').val($('#name').val());
1079                    break;
1080                case "book":
1081                    $('#movieDetails').hide();
1082                    $('#addressDetails').show();
1083                    $('#parentsName').val($('#name').val());
1084                    break;
1085                case "movie":
1086                default:
1087                    $('#movieDetails').show();
1088                    $('#addressDetails').hide();
1089                    break;
1090            }
1091        }
1092        // if movie then skip one step
1093        if (_product_type == "movie" && currentStep + 1 == 3) {
1094            $('#purchaseStep' + currentStep).hide();
1095            currentStep++;
1096        }
1097        $('#purchaseStep' + currentStep).fadeOut(function() {
1098            currentStep++;
1099            showStep(currentStep);
1100            animateProgressBar(currentStep);
1101            // $('#modal-subtitle').text('Personalizacja');
1102            $('#modal-subtitle').html(_products[_product_type].price);
1103            if (_product_type == 'ebook' || (_product_type == 'movie' && _redeem) || (_product_type == 'audiobook' && _redeem)) {
1104                $('#modal-subtitle').html('Odbierz');
1105            }
1106            $('#productTitleBackButton').hide();
1107            $('#productTitleOverlay').show();
1108        });
1109    }
1110    if (_product_type == "combo" && currentStep + 1 == 7) {
1111        // jestem na rozdzielczości filmu i przechodzę na adres
1112        $('#purchaseStep' + currentStep).fadeOut(function() {
1113            currentStep = 8;
1114            showStep(currentStep);
1115            $('#purchaseStep').val(STEP_ORDER_ADDRESS);
1116            animateProgressBar(7);
1117            // $('#modal-subtitle').text('Personalizacja');
1118            $('#modal-subtitle').html(_products[_product_type].price);
1119            $('#productTitleBackButton').hide();
1120            $('#productTitleOverlay').show();
1121        });
1122        return;
1123    }
1124    if (_product_type == "combo" && currentStep == STEP_ORDER_ADDRESS) {
1125        if (!validateAddress()) {
1126            return false;
1127        }
1128        // adres prawidłowy - wskakujemy do podsumowania
1129        $('#purchaseStep' + currentStep).fadeOut();
1130        currentStep = 6;
1131    }
1132
1133    // console.log(currentStep);
1134    if (currentStep + 1 == STEP_ORDER_SUMMARY) {
1135        $('#purchaseStep' + currentStep).fadeOut(function() {
1136            switch(_product_type) {
1137                case "movie":
1138                default:
1139                    $('#orderSummaryAddressOverlay').hide();
1140                    break;
1141                case "combo":
1142                    $('#orderSummaryAddressOverlay').show();
1143                    break;
1144            }
1145            currentStep++;
1146            $('#progressbar').fadeOut();
1147            $('.custom-progress-bar-label').fadeOut();
1148            $('#btnNext').fadeOut(() => {
1149                // $('#btnNext').text('Zamów i zapłać');
1150                // $('#btnNext').fadeIn();
1151            });
1152            $('#paymentButtonOverlay').fadeIn();
1153            $('#modal-subtitle').fadeOut(() => {
1154                $('#productTitleBackButton').show();
1155                $('#productTitleOverlay').hide();
1156                // $('#modal-subtitle').text('Podsumowanie');
1157                $('#modal-subtitle').fadeIn();
1158                showStep(currentStep);
1159            });
1160
1161            generateOrderSummary();
1162
1163            // cennik start
1164            if (_product_type == "movieaudiobook" || _product_type == "combo" || _product_type == "movie" || _product_type == "book") {
1165                var basic_price = _products[_product_type]["basic_price"];
1166                var basic_price_no_promo = basic_price;
1167                // $('#order-item-movie-quality').show();
1168                // $('#order-item-order-time').show();
1169
1170                var _movieQuality = $('input[name="movieQuality"]:checked').val();
1171                var _orderTime = $('input[name="orderTime"]:checked').val();
1172
1173                if (_movieQuality == 3) {
1174                    // $('#order-item-movie-quality-label').text('4K');
1175                    // $('#order-item-movie-quality-price').text('20,00');
1176                    basic_price += 20;
1177                }
1178                else if (_movieQuality == 2) {
1179                    // $('#order-item-movie-quality-label').text('FULL HD');
1180                    // $('#order-item-movie-quality-price').text('10,00');
1181                    basic_price += 10;
1182                }
1183                else {
1184                    $('#order-item-movie-quality').hide();
1185                    // $('#order-item-movie-quality-label').text('HD');
1186                    // $('#order-item-movie-quality-price').text('0,00');
1187                }
1188                if (_orderTime == 3) {
1189                    // $('#order-item-order-time-label').text('2 GODZINY');
1190                    // $('#order-item-order-time-price').text('20,00');
1191                    basic_price += 20;
1192                }
1193                else if (_orderTime == 2) {
1194                    // $('#order-item-order-time-label').text('8 GODZIN');
1195                    // $('#order-item-order-time-price').text('10,00');
1196                    basic_price += 10;
1197                }
1198                else {
1199                    $('#order-item-order-time').hide();
1200                    // $('#order-item-order-time-label').text('24 GODZINY');
1201                    // $('#order-item-order-time-price').text('0,00');
1202                }
1203                basic_price *= _promo_price;
1204                if (_product_type != "combo" && _product_type != "movieaudiobook") {
1205                    $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", basic_price).replace(".", ",")  + " zł");
1206                }
1207                if (_product_type == "combo") {
1208                    $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", (basic_price - 43.99 - 1 - 1)).replace(".", ",")  + " zł");
1209                }
1210                if (_product_type == "movieaudiobook") {
1211                    $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", (basic_price - 1)).replace(".", ",")  + " zł");
1212                }
1213                if (_product_type == "combo") {
1214                    switch ($('input[name="deliveryType"]:checked').val()) {
1215                        case '2':
1216                            // deliveryType = 'Paczkomaty InPost';
1217                            basic_price += 0.00;
1218                            // $('#order-item-delivery-type-2').text('19,99');
1219                            break;
1220                        case '3':
1221                            // deliveryType = 'ORLEN Paczka';
1222                            basic_price += 0.00;
1223                            // $('#order-item-delivery-type-2').text('11,99');
1224                            break;
1225                        case '1':
1226                        default:
1227                            // deliveryType = 'Kurier InPost';
1228                            basic_price += 0.0;
1229                            // $('#order-item-delivery-type-2').text('19,99');
1230                            break;
1231                    }
1232                    var gift = '';
1233                    switch ($('input[name="bookAsGift"]:checked').val()) {
1234                        case '2':
1235                            basic_price += 29.99;
1236                            break;
1237                        case '1':
1238                        default:
1239                            break;            
1240                    }
1241                }
1242                // console.log(basic_price);
1243                $('#order-total-price').text(sprintf("%.2f", basic_price).replace('.', ','));
1244                window.dataLayer = window.dataLayer || [];
1245                dataLayer.push({ ecommerce: null });
1246                window.dataLayer.push({
1247                    event: 'initiate_checkout',           
1248                    ecommerce: {      
1249                        currency: 'PLN',
1250                        value: parseFloat(_products[_product_type]["basic_price"]),   
1251                        coupon: '',                    
1252                        items: [{                          
1253                            item_name: (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),          
1254                            item_id: _product_type,           
1255                            price: parseFloat(_products[_product_type]["basic_price"]),                            
1256                            item_category: (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),               
1257                            item_variant: (_currentStory == '1' ? 'Czerwony Kapturek' : (_currentStory == '2' ? 'Kopciuszek' : 'Jaś i Małgosia')),                                    
1258                            quantity: 1                   
1259                        }]
1260                    }
1261                });
1262                recalculatePrice();
1263            }
1264            // cennik end
1265        });
1266    }
1267    else if (currentStep + 1 >= 8) {
1268        // console.log('submit');
1269        if ($('#agreeBasic')[0].reportValidity()) {
1270            $('#btnPrev').prop('disabled', true);
1271            $('#btnNext').prop('disabled', true);
1272            
1273            $('#purchaseCreator').submit();
1274        }
1275    }
1276}
1277
1278function showStep(currentStep) {
1279    window.dataLayer = window.dataLayer || [];
1280    dataLayer.push({
1281        'event' : 'personalization_path',
1282        'item_name' : (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),
1283        'step': currentStep,
1284        'user_type' : (_redeem == true ? 'App' : 'Web')
1285    });
1286
1287    $('#purchaseStep' + currentStep).fadeIn();
1288    $('#purchaseStep').val(currentStep);
1289}
1290
1291function animateProgressBar(currentStep) {
1292    if (_product_type == "movie") {
1293        if (currentStep > 3) {
1294            currentStep--;
1295        }
1296    }
1297    $('#progressbar > div.progress-bar').animate({ width: (currentStep / _max_steps * 100) + '%' }, 400, 'linear', () => {
1298        // $('.progress-bar').html('<span class="progress-bar-label">Krok </span>' + currentStep + ' z ' + _max_steps);
1299        $('.custom-progress-bar-label').html('Krok ' + currentStep + '/' + _max_steps);
1300    });
1301}
1302
1303var file_upload_in_progress = false;
1304var show_video_upload = false;
1305
1306$(document).ready(function() {
1307    const purchaseModal = document.getElementById('purchaseModal')
1308    purchaseModal.addEventListener('hidden.bs.modal', event => {
1309        // resetowanie ustawień okna zakupu
1310        parseInt($('#purchaseStep').val(1));
1311        $('#purchaseStep1').fadeIn();
1312        for (var i = 2; i <= 8; i++) {
1313            $('#purchaseStep'+i).hide();
1314        }
1315        animateProgressBar(1);
1316        $('#btnNext').text('Dalej');
1317        $('#btnNext').fadeIn();
1318        $('#paymentButtonOverlay').hide();
1319        $('#orderDetails').show();
1320        $('.order-photos-preview').show();
1321        $('.order-photos-preview-content').show();
1322        $('.order-photos-preview-confirm').show();
1323        $('#order-item-movie-quality').hide();
1324        $('#order-item-order-time').hide();
1325        // $('#modal-subtitle').text('Personalizacja');
1326        $('#modal-subtitle').html(_products[_product_type].price);
1327        $('#productTitleBackButton').hide();
1328        $('#productTitleOverlay').show();
1329        $('#progressbar').show();
1330        $('.custom-progress-bar-label').show();
1331        _currentStory = null;
1332        // $('.snowflake').each(function() {
1333        //     $(this)[0].classList.remove('snowflake-bg');
1334        // });
1335        // $('.snowflake-small-1').each(function() {
1336        //     $(this)[0].classList.add('snowflake-hidden');
1337        // });
1338        // $('.snowflake-small-2').each(function() {
1339        //     $(this)[0].classList.add('snowflake-hidden');
1340        // });
1341        $('input[type=radio][name=story]:checked').each(function() {
1342            $(this)[0].checked = false;
1343        });
1344    });
1345    purchaseModal.addEventListener('hide.bs.modal', event => {
1346        if (!confirm('Czy na pewno chcesz przerwać proces zakupu?')) {
1347            event.preventDefault();
1348        }
1349    });
1350
1351    var fu1 = document.getElementById('child-photo-1');
1352    fu1.onchange = function(event) {
1353        var output = fu1.parentElement;
1354        updateBackgroundImage(output, event.target.files[0], 'child-photo-1', 'progress-1');
1355        hideImages(output);
1356        hideDivs(output);
1357        // $('#progress-1').show();
1358    }
1359    $(fu1).on('click', function(event, openFileUpload) {
1360        if (file_upload_in_progress) {
1361            alert('Elfy odbierają jeszcze Twoje zdjęcie lub film. Daj im chwilę :)');
1362            return false;
1363        }
1364        _currentFileUpload = 'child-photo-1';
1365        if (event.target.parentElement.textContent.indexOf('EDYTUJ') != -1 && (typeof openFileUpload === 'undefined' || openFileUpload == false)) {
1366            event.preventDefault();
1367            editImage(fu1.parentElement, _currentFileUpload);
1368            return false;
1369        }
1370    }); 
1371    var fu2 = document.getElementById('child-photo-2');
1372    fu2.onchange = function(event) {
1373        var output = fu2.parentElement;
1374        updateBackgroundImage(output, event.target.files[0], 'child-photo-2', 'progress-2');
1375        hideImages(output);
1376        hideDivs(output);
1377        // $('#progress-2').show();
1378    }
1379    $(fu2).on('click', function(event, openFileUpload) {
1380        if (file_upload_in_progress) {
1381            alert('Elfy odbierają jeszcze Twoje zdjęcie lub film. Daj im chwilę :)');
1382            return false;
1383        }
1384        _currentFileUpload = 'child-photo-2';
1385        if (event.target.parentElement.textContent.indexOf('EDYTUJ') != -1 && (typeof openFileUpload === 'undefined' || openFileUpload == false)) {
1386            event.preventDefault();
1387            editImage(fu2.parentElement, _currentFileUpload);
1388            return false;
1389        }
1390    }); 
1391    var fu3 = document.getElementById('child-photo-3');
1392    fu3.onchange = function(event) {
1393        const fileSize = fu3.files[0].size / 1024 / 1024;
1394        if (fileSize > 50) {
1395            event.preventDefault();
1396            alert('Maksymalny rozmiar pliku to 50MB. Wybierz krótszy film.');
1397            return false;
1398        }
1399        else {
1400            var mimeType = fu3.files[0].type;
1401            // console.log(mimeType);
1402            if (mimeType.indexOf('video/') != -1) {
1403                hideImages(fu3.parentElement);
1404                _currentPhoto = 'child-photo-3';
1405                event.preventDefault();
1406                // obsługa video bez cropowania
1407
1408                let progressbar = $('#' + _currentProgressbar);
1409                let file = fu3.files[0];
1410                let formdata = new FormData();
1411                formdata.append('file', file); 
1412                formdata.append('photo', _currentPhoto);
1413                let request = new XMLHttpRequest();
1414
1415                request.open('POST', '/ajax/fileupload');
1416                request.upload.addEventListener('progress', event => {
1417                    progressbar.attr('aria-valuenow', ((event.loaded/event.total)*100).toFixed(2));
1418                });
1419                request.onreadystatechange = () => {
1420                    if (request.readyState == 4 && request.status == 200) {
1421                        progressbar.hide();
1422                    }
1423                    file_upload_in_progress = false;
1424                };
1425                file_upload_in_progress = true;
1426                request.send(formdata);
1427                $('#' + _currentPhoto + '-done').show();
1428
1429                var fileReader = new FileReader();
1430                fileReader.onload = function(fileLoadedEvent) {
1431                    fu3.parentElement.style.backgroundImage = "url('/img/photo-ok.png'), url('" + fileLoadedEvent.target.result + "')";
1432                    fu3.parentElement.style.backgroundSize = '10%, contain';
1433                    fu3.parentElement.style.backgroundRepeat = 'no-repeat';
1434                    fu3.parentElement.style.backgroundPosition = 'center';
1435                    fu3.parentElement.style.border = 'solid 2px green';
1436                    hideDivs(fu3.parentElement);
1437                    if (mimeType == 'video/quicktime' && navigator.userAgent.indexOf('Chrome') != -1) {
1438                        // $('#video-done-1').show();
1439                    }
1440                };
1441                fileReader.readAsDataURL(fu3.files[0]);
1442
1443                return;
1444            }
1445
1446
1447            var output = fu3.parentElement;
1448            updateBackgroundImage(output, event.target.files[0], 'child-photo-3', 'progress-3');
1449            hideImages(output);
1450            hideDivs(output);
1451            // $('#progress-3').show();
1452        }
1453    }
1454    $(fu3).on('click', function(event, openFileUpload) {
1455        if (file_upload_in_progress) {
1456            alert('Elfy odbierają jeszcze Twoje zdjęcie lub film. Daj im chwilę :)');
1457            return false;
1458        }
1459        _currentFileUpload = 'child-photo-3';
1460        if (fu3.files.length > 0) {
1461            var mimeType = fu3.files[0].type;
1462            if (mimeType.indexOf('video/') == -1) {
1463                if (event.target.parentElement.textContent.indexOf('EDYTUJ') != -1 && (typeof openFileUpload === 'undefined' || openFileUpload == false)) {
1464                    event.preventDefault();
1465                    editImage(fu3.parentElement, _currentFileUpload);
1466                    return false;
1467                }
1468            }
1469        }
1470    }); 
1471    var fu4 = document.getElementById('custom-photo-1');
1472    fu4.onchange = function(event) {
1473        var output = fu4.parentElement;
1474        updateBackgroundImage(output, event.target.files[0], 'custom-photo-1', 'progress-4');
1475        hideImages(output);
1476        hideDivs(output);
1477        // $('#progress-4').show();
1478    }
1479    $(fu4).on('click', function(event, openFileUpload) {
1480        if (file_upload_in_progress) {
1481            alert('Elfy odbierają jeszcze Twoje zdjęcie lub film. Daj im chwilę :)');
1482            return false;
1483        }
1484        _currentFileUpload = 'custom-photo-1';
1485        if (event.target.parentElement.textContent.indexOf('EDYTUJ') != -1 && (typeof openFileUpload === 'undefined' || openFileUpload == false)) {
1486            event.preventDefault();
1487            editImage(fu4.parentElement, _currentFileUpload);
1488            return false;
1489        }
1490    }); 
1491    var fu5 = document.getElementById('custom-photo-2');
1492    fu5.onchange = function(event) {
1493        var output = fu5.parentElement;
1494        updateBackgroundImage(output, event.target.files[0], 'custom-photo-2', 'progress-5');
1495        hideImages(output);
1496        hideDivs(output);
1497        // $('#progress-5').show();
1498    }
1499    $(fu5).on('click', function(event, openFileUpload) {
1500        if (file_upload_in_progress) {
1501            alert('Elfy odbierają jeszcze Twoje zdjęcie lub film. Daj im chwilę :)');
1502            return false;
1503        }
1504        _currentFileUpload = 'custom-photo-2';
1505        if (event.target.parentElement.textContent.indexOf('EDYTUJ') != -1 && (typeof openFileUpload === 'undefined' || openFileUpload == false)) {
1506            event.preventDefault();
1507            editImage(fu5.parentElement, _currentFileUpload);
1508            return false;
1509        }
1510    }); 
1511
1512    // TESTY
1513    // $('#purchaseStep1').hide();
1514    // $('#movieDetails').hide();
1515    // parseInt($('#purchaseStep').val(5));
1516    // showStep(5);
1517    // animateProgressBar(5);
1518
1519    $('input[name="deliveryType"]').on('change', function() {
1520        if ($('input[name="deliveryType"]:checked').val() == "2") {
1521            $('.row-paczkomat').show();
1522        }
1523        else {
1524            $('.row-paczkomat').hide();    
1525        }
1526    });
1527
1528    $('#fv').on('change', function() {
1529        if ($('#fv').is(':checked')) {
1530            $('.order-fv').show();
1531        }
1532        else {
1533            $('.order-fv').hide();
1534        }
1535    });
1536
1537    $('#agreeToAll').on('change', function() {
1538        if ($('#agreeToAll')[0].checked == true) {
1539            $('#agreeBasic')[0].checked = true;
1540            $('#agreeOwn')[0].checked = true;
1541            $('#agreeExt')[0].checked = true;
1542            $('#agreeMore')[0].checked = true;
1543        }
1544        else {
1545            $('#agreeBasic')[0].checked = false;
1546            $('#agreeOwn')[0].checked = false;
1547            $('#agreeExt')[0].checked = false;
1548            $('#agreeMore')[0].checked = false;
1549        }
1550    });
1551
1552    $('#name').on('change', function() { saveLead(); });
1553    $('#email').on('change', function() { saveLead(); });
1554});
1555
1556function saveLead() {
1557    var name = $('#name').val();
1558    var email = $('#email').val();
1559    if (name != '' && email != '') {
1560        var data = {
1561            name: name,
1562            email: email,
1563            product_type: _product_type,
1564        };
1565        $.ajax({
1566            url: '/ajax/savelead',
1567            type: 'POST',
1568            data: JSON.stringify(data),
1569            contentType: "application/json; charset=utf-8",
1570            dataType: "json",
1571            success: function(response) {
1572                // console.log(response);
1573            }
1574        });
1575    }
1576}
1577
1578var image = null;
1579var outputToUpdate = null;
1580var _currentPhoto = null;
1581var _currentProgressbar = null;
1582
1583var _aspectRatios = {
1584    'child-photo-1': 4/5,
1585    'child-photo-2': 1/1,
1586    'child-photo-3': 1/1,
1587    'custom-photo-1': 4/5,
1588    'custom-photo-2': 4/5,
1589};
1590
1591function editImage(output, currentPhoto) {
1592    outputToUpdate = output;
1593    var imageToCrop = fileBlobs[currentPhoto];
1594
1595    if (image != null) {
1596        // image.cropper('destroy');
1597        $('.image-editor').cropit('destroy');
1598        image = null;
1599    }
1600
1601    if (image == null) {
1602        // image = $('#cropper-image');
1603        // image[0].src = imageToCrop;
1604    }
1605    else {
1606    //     image.cropper('replace', imageToCrop);
1607    }
1608    $('#cropper-overlay').show();
1609    if (_aspectRatios[currentPhoto] == 1) {
1610        $('.cropit-preview').removeClass('cropit-preview-4-5');
1611    }
1612    else {
1613        $('.cropit-preview').addClass('cropit-preview-4-5');
1614    }
1615    $('.image-editor').cropit({
1616        imageState: {
1617            src: imageToCrop,
1618        },
1619    });
1620    // image.cropper({
1621    //   aspectRatio: _aspectRatios[currentPhoto],
1622    //   crop: function(event) {
1623    //   }
1624    // });
1625}
1626
1627function updateBackgroundImage(output, filename, currentPhoto, currentProgressbar) {
1628    // output.style.backgroundImage = "url('" + URL.createObjectURL(filename) + "')";
1629    // output.onload = function() {
1630    //   URL.revokeObjectURL(output.src) // free memory
1631    // }
1632    outputToUpdate = output;
1633    _currentPhoto = currentPhoto;
1634    _currentProgressbar = currentProgressbar;
1635
1636    if (image != null) {
1637        // image.cropper('destroy');
1638        $('.image-editor').cropit('destroy');
1639        image = null;
1640    }
1641    // console.log(output, filename, currentPhoto);
1642    // console.log(URL.createObjectURL(filename));
1643    fileBlobs[currentPhoto] = URL.createObjectURL(filename);
1644    // poprzednia wersja croppera
1645    
1646    if (image == null) {
1647        // image = $('#cropper-image');
1648        $('.image-editor').cropit('destroy');
1649        // image[0].src = URL.createObjectURL(filename);
1650        // console.log(1);
1651    }
1652    else {
1653        // image.cropper('replace', URL.createObjectURL(filename));
1654        // console.log(2);
1655    }
1656    
1657    // $('#cropperModal').modal('show');
1658    $('#cropper-overlay').show();
1659    if (_aspectRatios[currentPhoto] == 1) {
1660        $('.cropit-preview').removeClass('cropit-preview-4-5');
1661    }
1662    else {
1663        $('.cropit-preview').addClass('cropit-preview-4-5');
1664    }
1665    $('.image-editor').cropit({
1666        imageState: {
1667            src: URL.createObjectURL(filename),//'http://127.0.0.1:8000/img/photo-5.png',
1668        },
1669        onImageError: function(err) {
1670            if (err.message.indexOf('too small') != -1) {
1671                alert('Zdjęcie jest zbyt małe. Proszę wybrać inne zdjęcie.');
1672            }
1673            else {
1674                alert('Nie udało się odczytać zdjęcia. Proszę wybrać inne zdjęcie.');
1675            }
1676            $('#cropper-overlay').hide();
1677        },
1678        onImageLoaded: function() {
1679        }
1680    });
1681    
1682    return;
1683
1684    // console.log(_aspectRatios[currentPhoto], currentPhoto);
1685    image.cropper({
1686      aspectRatio: _aspectRatios[currentPhoto],
1687      crop: function(event) {
1688      }
1689    });
1690    // window.setTimeout(function() {
1691    //     $('#cropperModal .modal-footer').show();
1692    // }, 1500);
1693    
1694    // Get the Cropper.js instance after initialized
1695    // var cropper = image.data('cropper');    
1696}
1697function hideImages(output) {
1698    var imgs = output.getElementsByTagName('img');
1699    for (var i = 0; i < imgs.length; i++) {
1700        imgs[i].style.display = 'none';
1701    }
1702}
1703function hideDivs(output) {
1704    var divs = output.getElementsByTagName('div');
1705    for (var i = 0; i < divs.length; i++) {
1706        divs[i].style.display = 'none';
1707        break;
1708    }
1709    // divs[1].innerText = "EDYTUJ";
1710    // divs[1].style.color = "white";
1711    // divs[1].style.textShadow = '1px 1px black';
1712}
1713
1714function setCroppedImage() {
1715    // poprzedni wersja croppera
1716    /*
1717    var imageData = image.cropper('getImageData');
1718
1719    var croppedCanvas = image.cropper('getCroppedCanvas', {
1720        // maxWidth:imageData.naturalHeight,
1721        // maxHeight:imageData.naturalWidth,
1722        maxWidth:2000,
1723        maxHeight:2000,
1724        imageSmoothingQuality: 'high',
1725    });
1726    */
1727    var base64 = $('.image-editor').cropit('export')
1728    // outputToUpdate.style.backgroundImage = "url('/img/photo-ok.png'), url('" + croppedCanvas.toDataURL() + "')";
1729    outputToUpdate.style.backgroundImage = "url('/img/photo-ok.png'), url('" + base64 + "')";
1730    outputToUpdate.style.backgroundSize = '10%, contain';
1731    outputToUpdate.style.backgroundRepeat = 'no-repeat';
1732    outputToUpdate.style.backgroundPosition = 'center';
1733    outputToUpdate.style.border = 'solid 2px green';
1734    $('#cropper-overlay').hide();
1735    
1736    // console.log(base64);
1737    // console.log(atob()
1738    uploadFile(base64);
1739    // console.log(base64.split(',')[1]);
1740    // console.log(atob(base64.split(',')[1]));
1741    // uploadFile(atob(base64.split(',')[1]));
1742
1743    // uploadFile(croppedCanvas.toDataURL());
1744    // croppedCanvas.toBlob(function (blob) {
1745    //     uploadFile(blob);
1746    // });
1747}
1748
1749function uploadFile(blobData) {
1750    let progressbar = $('#' + _currentProgressbar);
1751    let file = document.getElementById(_currentPhoto).files[0];
1752    let formdata = new FormData();
1753    // formdata.append('file', file);
1754    formdata.append('file', blobData); 
1755    formdata.append('photo', _currentPhoto);
1756    let request = new XMLHttpRequest();
1757
1758    request.open('POST', '/ajax/fileupload');
1759    request.upload.addEventListener('progress', event => {
1760        progressbar.attr('aria-valuenow', ((event.loaded/event.total)*100).toFixed(2));
1761        // Add the current progress to the button
1762        // uploadForm.querySelector('button').innerHTML = 'Uploading... ' + '(' + ((event.loaded/event.total)*100).toFixed(2) + '%)';
1763        // Update the progress bar
1764        // uploadForm.querySelector('.progress').style.background = 'linear-gradient(to right, #25b350, #25b350 ' + Math.round((event.loaded/event.total)*100) + '%, #e6e8ec ' + Math.round((event.loaded/event.total)*100) + '%)';
1765        // Disable the submit button
1766        // uploadForm.querySelector('button').disabled = true;
1767    });
1768    request.onreadystatechange = () => {
1769        if (request.readyState == 4 && request.status == 200) {
1770            progressbar.hide();
1771        }
1772        file_upload_in_progress = false;
1773    };
1774    file_upload_in_progress = true;
1775    request.send(formdata);
1776    $('#' + _currentPhoto + '-done').show();
1777}
1778
1779var _currentClaimIdx = 0;
1780
1781function rotateClaims() {
1782    var items = $('#claims')[0].children;
1783    $(items[_currentClaimIdx]).toggleClass('d-none');
1784    $(items[_currentClaimIdx]).toggleClass('d-md-inline');
1785    _currentClaimIdx++;
1786    if (_currentClaimIdx >= 3) {
1787        _currentClaimIdx = 0;
1788    }
1789    for (var i = 0; i < items.length; i++) {
1790        if (i == _currentClaimIdx) {
1791            $(items[i]).toggleClass('d-none');
1792            $(items[i]).toggleClass('d-md-inline');
1793            break;
1794        }
1795    }
1796}
1797// if (window.innerWidth < 992) {
1798//     window.setInterval(rotateClaims, 5 * 1000);
1799// }
1800
1801(function($){
1802    $.fn.removeOrphans = function(){
1803        if($(this).length > 0) {
1804            var $html = $(this).html();
1805            $html = $html.replace(/(\s)([\S])[\s]+/g, "$1$2&nbsp;");
1806            // stosując wyrażenie regularne, do każdej pojedyńczej litery 
1807            // posiadającej z obu stron spacje, dodajemy encje &nbsp;,
1808            // czyli popularną "twardą spację"
1809             $(this).empty().html($html);
1810        }
1811    }
1812})(jQuery);
1813
1814$(document).ready(function(){
1815    $('.product-description').each(function() { $(this).removeOrphans(); });
1816    if (window.innerWidth > 1920) {
1817        $('#btn-scroll-right').hide();
1818    }
1819
1820    $('#previewModal')[0].addEventListener('hidden.bs.modal', event => {
1821        $('#previewVideo')[0].pause(); 
1822        $('#previewVideo')[0].currentTime = 0;
1823    });
1824
1825    $('input[type=radio][name=story]').change(function() {
1826        // $('.snowflake').each(function() {
1827        //     $(this)[0].classList.remove('snowflake-bg');
1828        // });
1829        // $('.snowflake-small-1').each(function() {
1830        //     $(this)[0].classList.add('snowflake-hidden');
1831        // });
1832        // $('.snowflake-small-2').each(function() {
1833        //     $(this)[0].classList.add('snowflake-hidden');
1834        // });
1835        var current = $('input[type=radio][name=story]:checked')[0].value;
1836        // console.log('currentStroy', current);
1837        
1838        // var items = $('.snowflake');
1839        // items[current - 1].classList.add('snowflake-bg');
1840
1841        // var ss1 = $('.snowflake-small-1');
1842        // ss1[current - 1].classList.remove('snowflake-hidden');
1843
1844        // var ss2 = $('.snowflake-small-2');
1845        // ss2[current - 1].classList.remove('snowflake-hidden');
1846
1847        _currentStory = current;
1848    });
1849});
1850
1851
1852function playPreviewVideo(product_type) {
1853    window.dataLayer = window.dataLayer || [];
1854    window.dataLayer.push({
1855        'event': 'click_zobacz',
1856        'item_name': (_product_type == 'movie' ? 'Film' : (_product_type == 'audiobook' ? 'Audiobook' : (_product_type == 'ebook' ? 'E-book' : 'Książka'))),
1857    });
1858
1859    $('#previewModal').modal('show'); 
1860    $('#btnPreviewOrder').attr('onclick', "javascript:closePreviewModalAndBuy('" + product_type + "');");
1861
1862    $('#previewVideo')[0].removeChild($('#previewVideo')[0].children[0]);
1863
1864    var movieUrl = _products[product_type].preview[0].url;
1865    if (window.innerHeight > window.innerWidth && product_type != 'trailer' && product_type != 'movie') {
1866        movieUrl = movieUrl.replace('.mp4', '-45.mp4');
1867    }
1868
1869    var source = document.createElement('source');
1870    source.setAttribute('src', movieUrl);
1871    source.setAttribute('type', _products[product_type].preview[0].type);
1872    // console.log($('#previewVideo')[0]);
1873    $('#previewVideo')[0].appendChild(source);
1874
1875    $('#previewVideo')[0].load();
1876    $('#previewVideo')[0].play();
1877}
1878
1879function closePreviewModal() {
1880    $('#previewVideo')[0].pause(); 
1881    $('#previewVideo')[0].currentTime = 0; 
1882    $('#previewModal').modal('hide');    
1883}
1884
1885function closePreviewModalAndBuy(product_type) {
1886    closePreviewModal();
1887    showModal(product_type);
1888}
1889
1890function openStoryStep() {
1891    if (_currentStory == null) {
1892        $('#story-title-order').html(_products[_product_type].titleShort);
1893        $('#story-subtitle').html(_products[_product_type].price);
1894        $('input[type=radio][name=story]:checked').each(function() {
1895            $(this)[0].checked = false;
1896        })
1897        $('#storyModal').modal('show');
1898        $('#productModal').modal('hide');
1899    }
1900    else {
1901        $('#purchaseModal').modal('show');
1902        $('#productModal').modal('hide');
1903    }
1904    // if (_product_type == 'movie' || _product_type == 'ebook' || _product_type == 'movieaudiobook' || _product_type == 'audiobook') {
1905    //     $('.order-fv-check').hide();
1906    // }
1907    // else {
1908    //     $('.order-fv-check').show();   
1909    // }
1910}
1911
1912function goToCreator() {
1913    if ($('input[type=radio][name=story]:checked').length == 1) {
1914        $('#purchaseModal').modal('show');
1915        $('#storyModal').modal('hide');
1916        $('#choosenStory').val($('input[name="story"]:checked').val());
1917    }
1918    else {
1919        alert('Wybierz tytuł baśni');
1920    }
1921}
1922
1923function changeActiveFAQCategory(category) {
1924    location.href = '/faq#category' + category;
1925
1926    $('.faq-category-button').each(function() {
1927        if ($(this)[0].id.replace('categoryBtn', '') == category.toString()) {
1928            $(this)[0].classList.add('active');
1929        }
1930        else {
1931            $(this)[0].classList.remove('active');
1932        }
1933    });
1934}
1935
1936function loginPasswordOnClick(inputId, eyeId) {
1937    var password = document.getElementById(inputId);
1938    var type = (password.getAttribute('type') == 'password' ? 'text' : 'password');
1939    password.setAttribute('type', type);
1940    $('#' + eyeId).toggleClass('fa-eye-slash');    
1941}
1942
1943function afterPointSelected(point) { 
1944    $('#currentPaczkomatLabel').html(point.name); 
1945    $('#currentPaczkomat').val(point.name);
1946} 
1947
1948function checkPromoCode() {
1949    if ($('#promo_code').val() != '') {
1950        $.post('/order/check_promo_code', { 'promo_code': $('#promo_code').val() }).done(function(data) {
1951            if (data.is_valid == true) {
1952                alert('Świetnie, kod jest prawidłowy!');
1953                _promo_price = 0.8;
1954                if (data.discount_rate != null) {
1955                    _promo_price = 1-parseFloat(data.discount_rate);
1956                }
1957                recalculatePrice();
1958            }
1959            else {
1960                alert('Przykro nam, ale kod jest nieprawidłowy.')
1961            }
1962        });
1963    }
1964    else {
1965        alert('Proszę wprowadzić kod promocyjny.')
1966    }
1967}
1968
1969function recalculatePrice() {
1970    // cennik start
1971    var basic_price = _products[_product_type]["basic_price"];
1972    var basic_price_no_promo = basic_price;
1973    // $('#order-item-movie-quality').show();
1974    // $('#order-item-order-time').show();
1975
1976    if (_product_type == "movieaudiobook" || _product_type == "combo" || _product_type == "movie") {
1977        var _movieQuality = $('input[name="movieQuality"]:checked').val();
1978        var _orderTime = $('input[name="orderTime"]:checked').val();
1979
1980        if (_movieQuality == 3) {
1981            // $('#order-item-movie-quality-label').text('4K');
1982            // $('#order-item-movie-quality-price').text('20,00');
1983            basic_price += 20;
1984        }
1985        else if (_movieQuality == 2) {
1986            // $('#order-item-movie-quality-label').text('FULL HD');
1987            // $('#order-item-movie-quality-price').text('10,00');
1988            basic_price += 10;
1989        }
1990        else {
1991            $('#order-item-movie-quality').hide();
1992            // $('#order-item-movie-quality-label').text('HD');
1993            // $('#order-item-movie-quality-price').text('0,00');
1994        }
1995        if (_orderTime == 3) {
1996            // $('#order-item-order-time-label').text('2 GODZINY');
1997            // $('#order-item-order-time-price').text('20,00');
1998            basic_price += 20;
1999        }
2000        else if (_orderTime == 2) {
2001            // $('#order-item-order-time-label').text('8 GODZIN');
2002            // $('#order-item-order-time-price').text('10,00');
2003            basic_price += 10;
2004        }
2005        else {
2006            $('#order-item-order-time').hide();
2007            // $('#order-item-order-time-label').text('24 GODZINY');
2008            // $('#order-item-order-time-price').text('0,00');
2009        }
2010        if (_product_type != "combo" && _product_type != "movieaudiobook") {
2011            $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", basic_price).replace(".", ",")  + " zł");
2012        }
2013        if (_product_type == "combo") {
2014            $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", basic_price - 43.99 - 1 - 1).replace(".", ",")  + " zł");
2015        }
2016        if (_product_type == "movieaudiobook") {
2017            $($('#order-item-'+_product_type)[0].children[0].children[1]).text(sprintf("%.2f", (basic_price - 1)).replace(".", ",")  + " zł");
2018        }
2019        basic_price *= _promo_price;
2020        if (_product_type == "combo") {
2021            switch ($('input[name="deliveryType"]:checked').val()) {
2022                case '2':
2023                    // deliveryType = 'Paczkomaty InPost';
2024                    basic_price += 0.0;
2025                    // $('#order-item-delivery-type-2').text('19,99');
2026                    break;
2027                case '3':
2028                    // deliveryType = 'ORLEN Paczka';
2029                    basic_price += 0.0;
2030                    // $('#order-item-delivery-type-2').text('11,99');
2031                    break;
2032                case '1':
2033                default:
2034                    // deliveryType = 'Kurier InPost';
2035                    basic_price += 0.0;
2036                    // $('#order-item-delivery-type-2').text('19,99');
2037                    break;
2038            }
2039            var gift = '';
2040            switch ($('input[name="bookAsGift"]:checked').val()) {
2041                case '2':
2042                    basic_price += 29.99;
2043                    break;
2044                case '1':
2045                default:
2046                    break;            
2047            }
2048        }
2049    }
2050    else {
2051        basic_price *= _promo_price;
2052    }
2053
2054    if (_product_type == "book") {
2055        switch ($('input[name="deliveryType"]:checked').val()) {
2056            case '2':
2057                // deliveryType = 'Paczkomaty InPost';
2058                basic_price += 0.0;
2059                // $('#order-item-delivery-type').text('19,99');
2060                break;
2061            case '3':
2062                // deliveryType = 'ORLEN Paczka';
2063                basic_price += 0.0;
2064                // $('#order-item-delivery-type').text('11,99');
2065                break;
2066            case '1':
2067            default:
2068                // deliveryType = 'Kurier InPost';
2069                basic_price += 0.00;
2070                // $('#order-item-delivery-type').text('19,99');
2071                break;
2072        }
2073        var gift = '';
2074        switch ($('input[name="bookAsGift"]:checked').val()) {
2075            case '2':
2076                basic_price += 29.99;
2077                break;
2078            case '1':
2079            default:
2080                break;            
2081        }
2082    }
2083
2084    // console.log(basic_price);
2085    $('#order-total-price').text(sprintf("%.2f", basic_price).replace('.', ','));
2086    // cennik end
2087}
2088
2089function setLocalStorage(cname, exdays) {
2090    const d = new Date();
2091    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
2092    localStorage.setItem(cname, d.getTime());
2093}
2094
2095function getLocalStorage(cname) {
2096    var value = parseInt(localStorage.getItem(cname));
2097    const d = new Date();
2098    if (isNaN(value) || d.getTime() > (value + (1 * 24 * 60 * 60 * 1000))) {
2099        return "";
2100    }
2101    else {
2102        return "1";
2103    }
2104}
2105
2106
2107if (location.pathname == '/') {
2108    let ebookModalExp = getLocalStorage('EbookModal');
2109    
2110    if (ebookModalExp == "") {
2111        window.setTimeout(function() {
2112            if ($('#purchaseModal').modal().css('display') != 'block') {
2113                setLocalStorage("EbookModal", 2);                
2114                $('#freeEbookModal').modal('show');
2115            }
2116        }, 5 * 1000);
2117    }
2118}
2119
2120
2121
2122
2123// image cropper
2124
2125$(document).ready(function() {
2126    $('.rotate-cw').click(function() {
2127      $('.image-editor').cropit('rotateCW');
2128    });
2129    $('.rotate-ccw').click(function() {
2130      $('.image-editor').cropit('rotateCCW');
2131    });
2132    $('.zoom-in').click(function() {
2133      var actual_zoom = $('.image-editor').cropit('zoom');
2134      actual_zoom = actual_zoom + 0.1;
2135      $('.image-editor').cropit('zoom', actual_zoom);
2136    });
2137    $('.zoom-out').click(function() {
2138      var actual_zoom = $('.image-editor').cropit('zoom');
2139      actual_zoom = actual_zoom - 0.1;
2140      $('.image-editor').cropit('zoom', actual_zoom);
2141    });
2142    $('.export').click(function() {
2143      var imageData = $('.image-editor').cropit('export');
2144      window.open(imageData);
2145    });
2146
2147    var readmores = document.querySelectorAll('a.read-more-dark, a.read-more, a.read-more-light');
2148    for (var i = 0; i < readmores.length; i++) {
2149        readmores[i].addEventListener('click', function() {
2150            if (!this.parentElement.parentElement.children[1].classList.contains('collapsed')) {
2151                this.parentElement.parentElement.children[1].innerHTML = 'Zwiń tekst';
2152            }
2153            else {
2154                this.parentElement.parentElement.children[1].innerHTML = 'Czytaj więcej';
2155            }
2156        });
2157    }
2158
2159    var readmoresLinks = document.querySelectorAll('a.read-more-custom');
2160    for (var i = 0; i < readmoresLinks.length; i++) {
2161        readmoresLinks[i].addEventListener('click', function() {
2162            if (!this.classList.contains('collapsed')) {
2163                this.innerHTML = 'Zwiń tekst';
2164            }
2165            else {
2166                this.innerHTML = 'Czytaj więcej';
2167            }
2168        });
2169    }
2170
2171    $(window).on('scroll', function() { if ($('#navbarMain').hasClass('show')) { $('#navbarMain').toggleClass('show') } });
2172});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.