PageSourceSearch

https://www.pordenonelegge.it/cache-buster-1789982365/js/main.js

js pordenonelegge.it collected 2026-10-02 07:46:40 UTC 81,001 bytes, 2,262 lines download raw bytes

1function getUrlParameter(sParam) {
2    var sPageURL = window.location.search.substring(1),
3        sURLVariables = sPageURL.split('&'),
4        sParameterName,
5        i;
6
7    for (i = 0; i < sURLVariables.length; i++) {
8        sParameterName = sURLVariables[i].split('=');
9
10        if (sParameterName[0] === sParam) {
11            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
12        }
13    }
14    return false;
15}
16
17
18function goToTop() {
19    document.body.scrollTop = 0; // For Safari
20    document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
21}
22
23
24$(document).ready(function() {
25
26    var getUrlParameter = function getUrlParameter(sParam) {
27        var sPageURL = window.location.search.substring(1),
28            sURLVariables = sPageURL.split('&'),
29            sParameterName,
30            i;
31
32        for (i = 0; i < sURLVariables.length; i++) {
33            sParameterName = sURLVariables[i].split('=');
34
35            if (sParameterName[0] === sParam) {
36                return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
37            }
38        }
39        return false;
40    };
41
42    $(document).ajaxStart(function(){
43        // Show image container
44        $('#spinner-div').show();
45    });
46    $(document).ajaxComplete(function(){
47        // Hide image container
48        $('#spinner-div').hide();
49    });
50
51    if(window.location.pathname == '/cerca'){
52        var q = getUrlParameter('q');
53        if(q != '') {
54            $.ajax({
55                //url: "/dynamic-search/default/j-search?q="+q,
56                url: "/search?q="+q,
57                success: function (result) {
58                    if(result.total_count > 0){
59                        $.ajax({
60                            type: "POST",
61                            url: "/cercaUrl",
62                            dataType: "json",
63                            data: JSON.stringify(result),
64                            success: function (data) {
65                                const a_autori = [];
66                                const a_notizie = [];
67                                const a_eventi = [];
68                                const a_guardaeascolta = [];
69                                const a_ospiti = [];
70                                for(var i = 0; i < result.result.length; i++) {
71                                    if(result.result[i].class_name == 'Autore' && data.Autore && !a_autori.includes(result.result[i].id)){
72                                        a_autori.push(result.result[i].id);
73                                        $('#settore-autori').show();
74                                        if(data.Autore[result.result[i].id])
75                                            $('#settore-autori ul').append('<li><a href="' + data.Autore[result.result[i].id] + '">' + result.result[i].nome + ' ' +result.result[i].cognome + '</a><p></p></li>');
76                                    }else if(result.result[i].class_name == 'Notizia' && data.Notizia && !a_notizie.includes(result.result[i].id)){
77                                        a_notizie.push(result.result[i].id);
78                                        $('#settore-notizie').show();
79                                        if(data.Notizia[result.result[i].id])
80                                            $('#settore-notizie ul').append('<li><a href="' + data.Notizia[result.result[i].id] + '">' + result.result[i].titolo + '</a><p>' + result.result[i].sottotitolo + '</p></li>');
81                                    }else if(result.result[i].class_name == 'Evento' && data.Evento && !a_eventi.includes(result.result[i].id)){
82                                        a_eventi.push(result.result[i].id);
83                                        $('#settore-eventi').show();
84                                        if(data.Evento[result.result[i].id])
85                                            $('#settore-eventi ul').append('<li><a href="' + data.Evento[result.result[i].id] + '">' + result.result[i].titolo + '</a><p>' + result.result[i].sottotitolo + '</p></li>');
86                                    }else if(result.result[i].class_name == 'MediaLibrary' && data.MediaLibrary && !a_guardaeascolta.includes(result.result[i].id)){
87                                        a_eventi.push(result.result[i].id);
88                                        $('#settore-guardaeascolta').show();
89                                        if(data.MediaLibrary[result.result[i].id])
90                                            $('#settore-guardaeascolta ul').append('<li><a href="' + data.MediaLibrary[result.result[i].id] + '">' + result.result[i].titolo + '</a></li>');
91                                    }else if(result.result[i].class_name == 'Ospite' && data.Ospite && !a_ospiti.includes(result.result[i].id)){
92                                        a_ospiti.push(result.result[i].id);
93                                        $('#settore-ospiti').show();
94                                        if(data.Ospite[result.result[i].id])
95                                            $('#settore-ospiti ul').append('<li><a href="' + data.Ospite[result.result[i].id] + '">' + result.result[i].nome + ' ' +result.result[i].cognome + '</a><p></p></li>');
96                                    }
97                                }
98                            }
99                        });
100                    }
101                }
102            });
103        }
104    }
105
106    
107
108    // navbar bootstrap bianca o trasparente
109    function manageSiteHeaderBg() {
110
111        let h = $('#site-header');
112        let navToggler = h.find('.navbar-toggler');
113
114        let mypnleggeAside = $('.mypnlegge-aside');
115
116        let turnTransparent = false;
117        let dark = false;
118
119        if ($(window).scrollTop() < 100) {
120            let hero = $('.hero');
121            let heroWithImage = $('.hero-with-image');
122            let hpSliderTuttolanno = $('.home-tuttolanno-slider');
123            let hpSliderTuttolannoSlidesLength = $(hpSliderTuttolanno).find('.swiper-slide').length; 
124            let medialibraryThemes = $('.medialibrary-themes');
125            if ( hero.length > 0 || heroWithImage.length > 0 || hpSliderTuttolanno.length > 0 || medialibraryThemes.length > 0 ) {
126                turnTransparent = true;
127                if (
128                    hero.hasClass('bg-secondary') ||
129                    heroWithImage.length > 0 ||
130                    ( hpSliderTuttolannoSlidesLength > 1 && hpSliderTuttolanno.find('.swiper-slide-active .slide').hasClass('bg-secondary') && !hero.hasClass('hero-home-festival') ) ||
131                    ( hpSliderTuttolannoSlidesLength == 1 && hpSliderTuttolanno.find('.slide').hasClass('bg-secondary') && !hero.hasClass('hero-home-festival') )
132                ) {
133                    dark = true;
134                } else {
135                    dark = false;
136                }
137            }
138        }        
139
140        if (turnTransparent) {
141            if (dark) {
142                h.removeClass('transparent');
143                h.addClass('transparent-dark');
144                navToggler.addClass('navbar-toggler-white');
145            } else {
146                h.removeClass('transparent-dark');
147                h.addClass('transparent');
148                navToggler.removeClass('navbar-toggler-white');
149            }
150            h.removeClass('bg-light');
151
152        } else {
153
154            h.addClass('bg-light');
155            navToggler.removeClass('navbar-toggler-white');
156            h.removeClass('transparent-dark');
157            h.removeClass('transparent');
158
159        }
160
161        /*if (mypnleggeAside.length > 0) {
162            h.find('.navbar-brand').addClass('white')
163            $(window).scroll(function() {
164                if ($(this).scrollTop() > 100) $('.navbar-brand').removeClass('white')
165                else $('.navbar-brand').addClass('white')
166            });
167        }*/
168
169    }
170
171    // Show password btn
172    $('.show-password').click(function() {
173        $('input#' + $(this).data('for'))[0].type = ( $('input#' + $(this).data('for')).attr('type') == 'password' ? 'text' : 'password' );
174        $(this).toggleClass('active')
175    })
176
177    // navbar bianca o trasparente mentre si sta scorrendo
178    $(window).scroll(function() {
179        manageSiteHeaderBg();
180    });    
181
182
183    // Slider homepage tuttolanno
184    $('.home-tuttolanno-slider .swiper').each(function(index, swiper) {
185        const sliderNews = new Swiper(swiper, {
186            slidesPerView: 1,
187            loop: true,
188            pagination: {
189                el: '.swiper-pagination',
190                clickable: true,
191                dynamicBullets: true,
192                dynamicMainBullets: 5
193            },
194            navigation: {
195                nextEl: '.btn-next-circle',
196                prevEl: '.btn-prev-circle'
197            },
198            breakpoints: {
199                0: {
200                    navigation: {
201                        enabled: false
202                    }
203                },
204                576: {
205                    navigation: {
206                        enabled: true
207                    }
208                }
209            },
210            on: {
211                slideChangeTransitionEnd: manageSiteHeaderBg
212            }
213        });
214    });
215
216    // NEWS SLIDER WITH SWIPER PLUGIN
217    $('.slider-news .swiper').each(function(index, swiper) {
218        const sliderNews = new Swiper(swiper, {
219            slidesPerView: 1,
220            slidesPerGroup: 1,
221            loop: false,
222            pagination: {
223                el: '.swiper-pagination',
224                clickable: true,
225                dynamicBullets: true,
226                dynamicMainBullets: 5
227            },
228            navigation: {
229                nextEl: '.btn-next-circle',
230                prevEl: '.btn-prev-circle'
231            },
232            breakpoints: {
233                0: {
234                    pagination: {
235                        enabled: true
236                    },
237                    navigation: {
238                        enabled: false
239                    }
240                },
241                768: {
242                    slidesPerView: 2,
243                    spaceBetween: 50,
244                    pagination: {
245                        enabled: false
246                    },
247                    navigation: {
248                        enabled: true
249                    }
250                },
251                1200: {
252                    slidesPerView: 3,
253                    spaceBetween: 100,
254                    pagination: {
255                        enabled: false
256                    },
257                    navigation: {
258                        enabled: true
259                    }
260                }
261            }
262        });
263    });
264
265    // NEXT APPOINTMENTS SLIDER WITH SWIPER PLUGIN
266    $('.slider-prossimi-appuntamenti .swiper').each(function(index, sliderNews) {
267        const sliderProssimiAppuntamenti = new Swiper(sliderNews, {
268            slidesPerView: 1,
269            slidesPerGroup: 1,
270            spaceBetween: 30,
271            watchOverflow: true,
272            loop: false,
273            pagination: {
274                el: '.swiper-pagination',
275                clickable: true,
276                dynamicBullets: true,
277                dynamicMainBullets: 5
278            },
279            navigation: {
280                nextEl: '.swiper-button-next',
281                prevEl: '.swiper-button-prev'
282            },
283            scrollbar: {
284                el: '.swiper-scrollbar',
285                draggable: true,
286                dragSize: 20
287            },
288            breakpoints: {
289                0: {
290                    pagination: {
291                        enabled: true
292                    },
293                    navigation: {
294                        enabled: false
295                    }
296                },
297                768: {
298                    slidesPerView: 2,
299                    pagination: {
300                        enabled: false
301                    },
302                    navigation: {
303                        enabled: true
304                    }
305                },
306                992: {
307                    slidesPerView: 3,
308                    pagination: {
309                        enabled: false
310                    },
311                    navigation: {
312                        enabled: true
313                    }
314                },
315                1200: {
316                    slidesPerView: 4,
317                    pagination: {
318                        enabled: false
319                    },
320                    navigation: {
321                        enabled: true
322                    }
323                },
324                1600: {
325                    slidesPerView: 4,
326                    spaceBetween: 40,
327                    pagination: {
328                        enabled: false
329                    },
330                    navigation: {
331                        enabled: true
332                    }
333                }
334
335            },
336            on: {
337                lock: function() {
338                    this.el.classList.toggle('locked', true)
339                },
340                unlock: function() {
341                    this.el.classList.toggle('locked', false)
342                }
343            }
344        });
345    });
346     
347
348    manageSiteHeaderBg();
349
350    // Filtri news
351    $(".filter_category_news").click(function() {
352        let filter = $(this).data("filter");
353        if(!$(this).hasClass("active")){
354            $(".filter_category_news").removeClass("active");
355            $(this).addClass("active");
356            $(".filter_single_news").each(function(index, singleNews) {
357                let is_in_filter = false;
358                $(singleNews).find(".tag3").each(function(index, cat) {
359                    let filter_single = $(cat).data("filter");
360                    if(filter_single == filter){
361                        is_in_filter = true;
362                    }
363                })
364                $(singleNews).css("display", "none");
365                if(is_in_filter){
366                    $(singleNews).css("display", "block");
367                }
368            })
369        } else {
370            $(".filter_category_news").removeClass("active");
371            $(".filter_single_news").css("display", "block");
372        }
373    });
374
375    if($('.filter_category_news').length > 0){
376        var cat = getUrlParameter('cat');
377        if(cat) {
378            $('.filter_category_news[data-filter="'+cat+'"]').trigger('click');
379        }
380    }
381
382    // form registrati - parte 1
383    $(document).on("click", "#signup-part1-btn", function(e){
384        let checkedRadio = $('input[name=profileType]:checked').val();        
385        if (checkedRadio == 'visitor') {
386            $("#signup-part1").removeClass('d-block');
387            $("#signup-part1").addClass('d-none');
388            $("#signup-part2-visitor").addClass('d-block');
389            $("#signup-part2-visitor").removeClass('d-none');
390            $('#signup-part1-progress').addClass('done');
391            $('#signup-part2-progress').addClass('active');
392        }
393        if (checkedRadio == 'teacher') {
394            $("#signup-part1").removeClass('d-block');
395            $("#signup-part1").addClass('d-none');
396            $("#signup-part2-teacher").addClass('d-block');
397            $("#signup-part2-teacher").removeClass('d-none');
398            $('#signup-part1-progress').addClass('done');
399            $('#signup-part2-progress').addClass('active');
400        }
401    })
402
403    // form registrati - parte 2 visitatore
404    function visitorFormSubmitted(){
405        $("#signup-part2-visitor").removeClass('d-block');
406        $("#signup-part2-visitor").addClass('d-none');
407        $("#signup-part3").addClass('d-block');
408        $("#signup-part3").removeClass('d-none');
409        $('#signup-part2-progress').addClass('done');
410        $('#signup-part3-progress').addClass('active');
411    }
412
413    // form registrati - parte 2 insegnante
414    function teacherFormSubmitted(){
415        $("#signup-part2-teacher").removeClass('d-block');
416        $("#signup-part2-teacher").addClass('d-none');
417        $("#signup-part3").addClass('d-block');
418        $("#signup-part3").removeClass('d-none');
419        $('#signup-part2-progress').addClass('done');
420        $('#signup-part3-progress').addClass('active');
421    }
422
423    // checkbox disabilità in signup-part2-visitor
424    $('#disabilita-checkbox').click(function() {
425        $('#disabilita-extra-fields').toggleClass('d-block', $(this)[0].checked);
426    })
427
428
429    // filter tabs nella pagina programma festival
430        if(window.innerWidth<1200){
431            $('#festival-programme-filter-tab').click(function() {
432                $('#festival-programme-filters-mobile').addClass('show')
433            })
434        } else { 
435            $('#festival-programme-filter-tab').click(function() {
436                if ($(this).hasClass('active')) {
437                    $(this).removeClass('active')
438                    $('#festival-programme-filters').removeClass('show')
439                    $('.overlay-filters').hide()
440                } else {
441                    $(this).addClass('active')
442                    $('#festival-programme-filters').addClass('show')
443                    $('.overlay-filters').show()
444                }
445            })
446         }
447
448
449    $('.festival-programme-event-buttons, .festival-event-left-details').find('.btn-favourite.loggedin').each(function() {
450        $(this).click(function() {
451            $(this).toggleClass('active')            
452            //$(this).find('span').toggleClass('active')
453        });
454    })
455
456    
457    $(window).on('resize', function(){
458    
459        // posizione sticky del filter tabs
460        $('.festival-programme-filter-nav').css("top", $('#main-navbar').outerHeight() - 1);
461
462        // posizione sticky del filter tags
463        $('.festival-programme-filter-tags').css("top", $('#main-navbar').outerHeight() + $('.festival-programme-filter-nav').outerHeight() - 1);
464
465        // posizione sticky delle lettere in lista autori
466        $('.authors-sticky-list').css("top", $('#main-navbar').outerHeight());
467
468        // posizione sticky degli anni in rassegna stampa
469        $('.content-with-side-sticky-bar').css("top", $('#main-navbar').outerHeight());
470
471    });
472
473
474    $(window).scroll(function() {
475
476        // posizione sticky delle lettere in lista autori
477        $('.authors-sticky-list').css("top", $('#main-navbar').outerHeight());
478        
479        // posizione sticky degli anni in rassegna stampa
480        $('.content-with-side-sticky-bar').css("top", $('#main-navbar').outerHeight());
481        
482        // pulsante vai su
483        if ($(this).scrollTop() > 500) {
484            $('#goToTopBtn').addClass('show');   
485        } else  $('#goToTopBtn').removeClass('show'); 
486
487    });
488
489
490    // scheda evento festival - testo sotto libri della stessa larghezza della copertina
491    $('.festival-event-book').each(function() {
492        $(this).width($(this).find('img').outerWidth());
493    });
494
495    // medialibrary
496    $('.medialibrary-item .cta').click(function() {
497        let item = $(this).parents('.medialibrary-item');
498        $(this).toggleClass('d-lg-block', false);
499        item.find('.medialibrary-item-content').toggleClass('d-lg-none', false);
500        item.find('.medialibrary-item-close').toggleClass('d-none', false);
501        item.find('.medialibrary-item-thumbnail').toggleClass('d-lg-block', false);
502    });
503    $('.medialibrary-item .btn-close').click(function() {
504        let item = $(this).parents('.medialibrary-item');
505        item.find('.cta').toggleClass('d-lg-block', true);
506        item.find('.medialibrary-item-content').toggleClass('d-lg-none', true);
507        item.find('.medialibrary-item-close').toggleClass('d-none', true);
508        item.find('.medialibrary-item-thumbnail').toggleClass('d-lg-block', true);
509    });
510
511
512    $.extend(true, $.magnificPopup.defaults, {
513        tClose: 'Chiudi (Esc)', // Alt text on close button
514        tLoading: 'Attendi...', // Text that is displayed during loading. Can contain %curr% and %total% keys
515        gallery: {
516          tPrev: 'Precedente (freccia sx)', // Alt text on left arrow
517          tNext: 'Prossimo (freccia dx)', // Alt text on right arrow
518          tCounter: '%curr% di %total%' // Markup for "1 of 7" counter
519        },
520        image: {
521          tError: '<a href="%url%">L\'immagine</a> non può essere caricata.' // Error message when image could not be loaded
522        },
523        ajax: {
524          tError: '<a href="%url%">Il contenuto content</a> non può essere caricato.' // Error message when ajax request failed
525        }
526    });
527
528    $('.popup-youtube').magnificPopup({
529        disableOn: 700,
530        type: 'iframe',
531        mainClass: 'mfp-fade',
532        removalDelay: 160,
533        preloader: false,
534        fixedContentPos: false
535    });
536
537    $('.magnific-gallery').magnificPopup({
538        delegate: 'a', // child items selector, by clicking on it popup will open
539        type: 'image',
540        gallery: {
541          enabled: true,
542          navigateByImgClick: true,
543          preload: [0,1] // Will preload 0 - before current, and 1 after the current image
544        }
545    });
546
547    $.ajax( {
548        url: '/account/login/true',
549        success: function ( result ) {
550            $('#login-form').html(result);
551        },
552        failure: function () {
553            alert('unable to load a form');
554        }
555    });
556
557    $("#visitor-disability").change(function() {
558        if($(this).is(':checked'))
559        {
560            $("#disabilita-extra-fields").show();
561        }else{
562            $("#disabilita-extra-fields").hide();
563        }       
564    }).change();
565
566    $("#visitor_self_disablity_accompany").change(function() {
567        if($(this).is(':checked')) {
568            $("#extra-people").removeClass('d-none');
569        } else{
570            $("#extra-people").addClass('d-none');
571        }       
572    }).change();
573
574    // $.ajax( {
575    //     url: '/account/register',
576    //     success: function ( result ) {
577    //         $('#registration-form').html(result);
578    //     },
579    //     failure: function () {
580    //         alert('unable to load a form');
581    //     }
582    // });
583
584    $('form#payment_option input').change(function() {
585        $('#bank-transfer-details').toggleClass('d-none', !$('input[value=bank_transfer]').is(':checked'));
586    });
587
588    $('label[for=plan_1]').click(function() {
589        $(`input[value=plan_1]`).prop('checked', true);
590    });
591
592    $('label[for=plan_2]').click(function() {
593        $(`input[value=plan_2]`).prop('checked', true);
594    });
595
596});
597
598
599// $(document).on("click", "#registration-btn", function(e){
600//     e.preventDefault();
601//     $.ajax( {
602//         url: '/account/register',
603//         success: function ( result ) {
604//             $('.modal-body-right').append(result);
605//         },
606//         failure: function () {
607//             alert('unable to load a form');
608//         }
609//     });
610//     return  false;
611// });
612
613var urlParams;
614(window.onpopstate = function () {
615    var match,
616        pl     = /\+/g,  // Regex for replacing addition symbol with a space
617        search = /([^&=]+)=?([^&]*)/g,
618        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
619        query  = window.location.search.substring(1);
620  
621    urlParams = {};
622    while (match = search.exec(query))
623       urlParams[decode(match[1])] = decode(match[2]);
624})();
625
626
627$(document).on("submit", "#login-form-container", function(e){
628    e.preventDefault();
629    $.ajax({
630        url: '/account/login/true',
631        
632        method:'post',
633        data: $(this).serialize(),
634        datatype:'html',
635        success: function ( result ) {
636            const obj = result;            
637            if(obj.success == false){
638                alert("Credenziali di accesso errate");
639            }else{
640                window.location = '/account/login';
641            }
642        },
643        failure: function () {
644            alert('unable to load a form');
645        },
646        complete: function(xhr, textStatus) {
647            if(xhr.status == 500){
648                window.location = '/';
649            }else if(xhr.status == 302){
650                window.location = '/account/login';
651            }
652        } 
653    });
654    return  false;
655});
656
657
658$(document).on("submit", "#signup-part2-visitor,#signup-part2-teacher", function(e){
659    e.preventDefault();
660
661    
662
663    let visitorType = $('input[name="profileType"]:checked').val();
664    let visitorDisability = $('#visitor-disability').is(":checked");
665
666    // Confirm password
667    let password = $('#'+visitorType+'-password').val();
668    let confirmPassword = $('#'+visitorType+'-confirm-password').val();
669
670    if(password != confirmPassword){
671        alert("La password non corrisponde");
672        return false;
673    }
674   
675    let visitorDob = new Date($('#'+visitorType+'-dob').val());
676    visitorDob = calculateAge(visitorDob);
677    if (visitorDob < 10) {
678        alert("L'età deve essere superiore ai 10 anni per la registrazione");
679        return false;    
680    }
681    
682    // Confirm email
683    let email = $('#'+visitorType+'-email').val();
684    let confirmEmail = $('#'+visitorType+'-confirm-email').val();
685
686    if(email != confirmEmail){
687        alert("Email non abbinata");
688        return false;
689    }
690
691    // Confirm username
692    let username = $('#'+visitorType+'-username').val();
693    let confirmUsername = $('#'+visitorType+'-confirm-username').val();
694
695    if(username != confirmUsername){
696        alert("Nome utente non corrispondente");
697        return false;
698    }
699
700    /*if($(this).attr('id') == 'signup-part2-teacher'){
701        if(!validateInstitutionalEmail(email)){
702            alert("Si prega di utilizzare l'e-mail istituzionale");
703            return false;
704        }
705    }*/
706
707    if(visitorDisability)
708    {
709        if($('#visitor-disability-badge').val() == ''){
710            $('.visitor-disability-badge-validate').show();
711            return false;
712        }else{
713            $('.visitor-disability-badge-validate').hide();
714        }
715    }
716    
717    let formData = $(this).serialize();
718    $.ajax({
719        url: '/account/register/async/'+visitorType,
720        
721        method:'post',
722        data: formData,
723        datatype:'json',
724        beforeSend: function() {
725            // setting a timeout
726            $('#spinner-div').show();
727        },
728        success: function ( result ) {
729            const obj = result;           
730
731            if(obj.success == false){
732               
733                    alert(result.message);
734            }
735            else if(obj.success == true){               
736                $('#spinner-div').show();
737                $('#registered_email').html(obj.registered_email);             
738                $('#signup-part1').hide();
739                $('#signup-part2-visitor').hide();
740                $('#signup-part3').show();
741                window.location = '/account/thankyou';
742            }
743        },        
744        complete: function(xhr, textStatus) {
745           // alert('here');
746           $('#spinner-div').hide();
747            if(xhr.status == 500){
748                $('#spinner-div').hide();
749                //$('#registered_email').html(obj.registered_email);             
750                $('#signup-part1').hide();
751                $('#signup-part2-visitor').hide();
752                $('#signup-part3').show();
753                window.location = '/account/thankyou';
754            }
755        },
756        failure: function(xhr, textStatus) {
757            $('#spinner-div').hide();
758            window.location = '/account/thankyou';
759        }
760    });
761    return  false;
762});
763
764$(document).on('click','.visitor_form_submit', function(e){
765    
766    let booking_type = $('.booking_type_visitor.active').val();     
767    visitorValidation(booking_type);  
768    
769    var error_exists = 0;
770    $('.validate').each(function(e){
771        if($(this).is(":visible")){
772            error_exists = 1;
773        }
774    });
775
776    if(error_exists == 1)
777    {
778        return false;
779    }
780    else{
781        $.ajax({
782            url : "/booking/add",
783            type: "POST",
784            
785            data : $('#visitor_form').serialize()+"&booking_type="+booking_type,
786            dataType: 'json',
787            beforeSend: function() {
788                // setting a timeout
789                $('#spinner-div').show();
790            },
791            success: function(data, textStatus, jqXHR)
792            {
793                if(data.success == true){
794                    window.location = "/booking/thanks/"+$('#event_id').val()+"/"+data.booking_id;
795                }else{
796                    alert(data.message);                    
797                }
798            },            
799            failure: function () {
800                alert('unable to load a form');
801            },
802            complete: function(xhr, textStatus) {
803                $('#spinner-div').hide();
804                if(xhr.status == 500){
805                    window.location = '/';
806                }else if(xhr.status == 302){
807                    window.location = '/account/login';
808                }
809            }
810        });
811    }  
812});
813
814
815
816$(document).on('click','.visitor_form_submit_edit', function(e){    
817    let booking_type = 'visitor_other';     
818    visitorValidation(booking_type);  
819    
820    var error_exists = 0;
821    $('.validate').each(function(e){
822        if($(this).is(":visible")){
823            error_exists = 1;
824        }
825    });
826
827    if(error_exists == 1)
828    {
829        return false;
830    }
831    else{
832        $.ajax({
833            url : $('#visitor_form_edit').attr('action'),
834            type: "POST",          
835            data : $('#visitor_form_edit').serialize()+"&booking_type="+booking_type,
836            dataType: 'json',
837            beforeSend: function() {
838                // setting a timeout
839                $('#spinner-div').show();
840            },
841            success: function(data, textStatus, jqXHR)
842            {
843                if(data.success == true){
844                    window.location = "/booking/thanks/"+$('#event_id').val()+"/"+data.booking_id;
845                }else{
846                    alert(data.message);                    
847                }
848            },            
849            failure: function () {
850                alert('unable to load a form');
851            },
852            complete: function(xhr, textStatus) {
853                $('#spinner-div').hide();
854                if(xhr.status == 500){
855                    window.location = '/';
856                }else if(xhr.status == 302){
857                    window.location = '/account/login';
858                }
859            }
860        });
861    }  
862});
863
864
865$(document).on('click','.teacher_form_submit', function(e){
866    e.preventDefault();
867    let booking_type = 'teacher';    
868
869    visitorValidation(booking_type);  
870    
871    var error_exists = 0;
872    $('.validate').each(function(e){
873        if($(this).is(":visible")){
874            error_exists = 1;
875        }
876    });
877
878    if(error_exists == 1)
879    {
880        return false;
881    }
882
883    var totalSeats = $('#visitor_no_of_seats').val();
884    if(totalSeats > 30 || totalSeats < 1){
885        validateFieldsDynamically('visitor_no_of_seats','text');
886        alert('Puoi richiedere al massimo 30 posti (comprensivi di allievi, insegnanti e accompagnatori)');
887        return false;
888    }else{
889        validateFieldsDynamically('visitor_self_firstname','text');
890    }
891   
892    $.ajax({
893        url : "/booking/add",
894        
895        type: "POST",
896        dataType: 'json',
897        data : $('#teacher_form').serialize()+"&booking_type="+booking_type,
898        beforeSend: function() {
899            // setting a timeout
900            $('#spinner-div').show();
901        },
902        success: function(data, textStatus, jqXHR)
903        {
904            if(data.success == true){
905                window.location = "/booking/thanks/"+$('#event_id').val()+"/"+data.booking_id;
906            }else{
907                alert(data.message);                    
908            }
909        },       
910        failure: function () {
911            alert('unable to load a form');
912        },
913        complete: function(xhr, textStatus) {
914            $('#spinner-div').hide();
915            if(xhr.status == 500){
916                window.location = '/';
917            }else if(xhr.status == 302){
918                window.location = '/account/login';
919            }
920        }
921    });
922     
923});
924
925
926$(document).on('click','.disabled_form_submit', function(e){
927    e.preventDefault();
928    let booking_type = 'disabled';    
929
930    visitorValidation(booking_type);  
931    
932    var error_exists = 0;
933    $('.validate').each(function(e){
934        if($(this).is(":visible")){
935            error_exists = 1;
936        }
937    });
938
939    if(error_exists == 1)
940    {
941        return false;
942    }
943   
944    $.ajax({
945        url : "/booking/add",
946        
947        type: "POST",
948        dataType: 'json',
949        data : $('#disabled_form').serialize()+"&booking_type="+booking_type,
950        beforeSend: function() {
951            // setting a timeout
952            $('#spinner-div').show();
953        },
954        success: function(data, textStatus, jqXHR)
955        {
956            if(data.success == true){
957                window.location = "/booking/thanks/"+$('#event_id').val()+"/"+data.booking_id;
958            }else{
959                alert(data.message);                    
960            }
961        },        
962        failure: function () {
963            alert('unable to load a form');
964        },
965        complete: function(xhr, textStatus) {
966            $('#spinner-div').hide();
967            if(xhr.status == 500){
968                window.location = '/';
969            }else if(xhr.status == 302){
970                window.location = '/account/login';
971            }
972        }
973    });
974     
975});
976
977$(document).on('change','#visitor_no_of_seats', function(e){
978    let edit_booking = false;
979    let total_required_seats = parseInt($(this).val());
980    if($(this).hasClass('edit')){
981        total_required_seats = parseInt(total_required_seats)+1;
982        edit_booking = true;
983    }
984
985    if(total_required_seats < 1){
986        $(this).val(0);
987        total_required_seats = 1;
988        return false;
989    }
990
991    if(total_required_seats > 1)
992    {
993        generateNewVisitorForm('extra-person',total_required_seats,edit_booking);
994    }else
995    {
996        $(this).val(1);
997        generateNewVisitorForm('extra-person',1,edit_booking);
998    }   
999
1000});
1001
1002$(document).on('click','.btn-seats', function(e){
1003    e.preventDefault();
1004    $('#visitor_no_of_seats').trigger('change');
1005});
1006
1007$(document).on('keyup','.vis_form', function(e){
1008    e.preventDefault();
1009    var elem =  $(this).attr('id');
1010    var type = $(this).attr('type');
1011    console.log(elem,type);
1012    validateFieldsDynamically(elem,type);
1013});
1014
1015$(document).on('keyup','.cf-input', function(e){
1016    e.preventDefault();
1017    validateCodiceFiscaleField($(this).attr('id'));
1018});
1019
1020$(document).on('change','.cf-checkbox', function(e){
1021    validateCodiceFiscaleField($(this).attr('id').replace('non_italian_fiscalcode','codiceFiscale'));
1022});
1023
1024
1025$(document).on('click','.remove_row', function(e){
1026    e.preventDefault();
1027    $(this).parent().parent().parent().remove();
1028    if($('.disabled_add_accompany').length > 0) {
1029        $('.disabled_add_accompany').show();
1030    }
1031});
1032
1033function generateNewVisitorForm(extra_visitor_class,desired_visitors,edit_booking){
1034
1035    let total_elements = $('.'+extra_visitor_class);   
1036   // console.log('total element', total_elements.length, desired_visitors);
1037    
1038    
1039    if(total_elements.length > desired_visitors){
1040        // delete elements
1041        for(let i=desired_visitors;i<total_elements.length;i++){
1042                var curr_elem = parseInt(i)+1;
1043                $("#accompany_"+curr_elem).remove();
1044                //console.log('deleting element', curr_elem);
1045        }
1046
1047    }else if(total_elements.length < desired_visitors){
1048        // add elements
1049        let formfields = '';
1050       
1051        for(let i=(total_elements.length+1);i<=desired_visitors;i++){
1052
1053            formfields += `<div class="extra-person" id="accompany_`+i+`">
1054                <h4>Persona numero `+i+`</h4>
1055                <div class="row mb-1">
1056                    <div class="col-xxl-6 col-sm">
1057                        <div class="row">
1058                            <div class="col-xxl">
1059                                <label class="col-form-label">Cognome</label>
1060                            </div>
1061                            <div class="col-xxl">
1062                                <input type="text" name="visitor_accompany_lastname[]" id="visitor_accompany_lastname_`+i+`" class="form-control vis_form" minlength="3" maxlength="30">
1063                                <small class="validate visitor_accompany_lastname_`+i+`_validate">il cognome è obbligatorio</small>
1064                            </div>
1065                        </div>
1066                    </div>  
1067                    <div class="col-xxl-6 col-sm">
1068                        <div class="row">
1069                            <div class="col-xxl">
1070                                <label class="col-form-label">Nome</label>
1071                            </div>
1072                            <div class="col-xxl">
1073                                <input type="text" name="visitor_accompany_firstname[]" id="visitor_accompany_firstname_`+i+`" class="form-control vis_form" minlength="3" maxlength="30">
1074                                <small class="validate visitor_accompany_firstname_`+i+`_validate">il nome è obbligatorio</small>                                            
1075                            </div>
1076                        </div>
1077                    </div>
1078                </div>
1079                <div class="row mb-1">
1080                    <div class="col-xxl-6 col-sm">
1081                        <div class="row">
1082                            <div class="col-xxl">
1083                                <label class="col-form-label">Email</label>
1084                            </div>
1085                            <div class="col-xxl">
1086                                <input type="email" name="visitor_accompany_email[]" id="visitor_accompany_email_`+i+`" class="form-control vis_form" minlength="3" maxlength="100">
1087                                <small class="validate visitor_accompany_email_`+i+`_validate">L'e-mail è necessaria</small>
1088                            </div>
1089                        </div>
1090                    </div>
1091                    <div class="col-xxl-6 col-sm">
1092                        <div class="row">
1093                            <div class="col-xxl">
1094                                <label class="col-form-label">Cellulare</label>
1095                            </div>
1096                            <div class="col-xxl">
1097                                <input type="tel" name="visitor_accompany_telephone[]" id="visitor_accompany_telephone_`+i+`" class="form-control vis_form" minlength="3" maxlength="30">
1098                                <small class="validate visitor_accompany_telephone_`+i+`_validate">è necessario un cellulare</small>
1099                            </div>
1100                        </div>
1101                    </div>
1102                </div>
1103                `;
1104
1105            var mostraCodiceFiscale = ($('#mostra_codice_fiscale').val() == '1');
1106            if(mostraCodiceFiscale){
1107                formfields += `<div class="row mb-1">
1108                    <div class="col-xxl-6 col-sm">
1109                        <div class="row">
1110                            <div class="col-xxl">
1111                                <label class="col-form-label">Codice Fiscale</label>
1112                            </div>
1113                            <div class="col-xxl">
1114                                <input type="text" name="visitor_accompany_codiceFiscale[]" id="visitor_accompany_codiceFiscale_`
1114+i+`" class="form-control cf-input" maxlength="16">
1115                                <small class="validate visitor_accompany_codiceFiscale_`+i+`_validate">codice fiscale non valido</small>
1116                            </div>
1117                        </div>
1118                    </div>
1119                    <div class="col-xxl-6 col-sm">
1120                        <div class="form-check mt-1">
1121                            <input class="form-check-input cf-checkbox" type="checkbox" name="visitor_accompany_non_italian_fiscalcode_`+i+`" id="visitor_accompany_non_italian_fiscalcode_`+i+`">
1122                            <label class="form-check-label" for="visitor_accompany_non_italian_fiscalcode_`+i+`">Non ho un codice fiscale italiano</label>
1123                        </div>
1124                    </div>
1125                </div>
1126                `;
1127            }
1128
1129            var userRole = ($('#visitor_form').data('user-role') || $('#visitor_form_edit').data('user-role') || '');
1130            if(userRole === 'jolly'){
1131                formfields += `<div class="row mb-1">
1132                    <div class="col-xxl-6 col-sm">
1133                        <div class="row">
1134                            <div class="col-xxl">
1135                                <label class="col-form-label">Sottosettore</label>
1136                            </div>
1137                            <div class="col-xxl">
1138                                <select name="visitor_accompany_sottosettore[]" id="visitor_accompany_sottosettore_`+i+`" class="form-control">
1139                                    <option value="">-- Seleziona --</option>
1140                                    <option value="JA">JA</option>
1141                                    <option value="JB">JB</option>
1142                                    <option value="JC">JC</option>
1143                                    <option value="JD">JD</option>
1144                                    <option value="JE">JE</option>
1145                                    <option value="JF">JF</option>
1146                                    <option value="JG">JG</option>
1147                                    <option value="JH">JH</option>
1148                                    <option value="JHA">JHA</option>
1149                                    <option value="JJ">JJ</option>
1150                                    <option value="JK">JK</option>
1151                                </select>
1152                            </div>
1153                        </div>
1154                    </div>
1155                    <div class="col-xxl-6 col-sm">
1156                        <div class="row">
1157                            <div class="col-xxl">
1158                                <label class="col-form-label">Note</label>
1159                            </div>
1160                            <div class="col-xxl">
1161                                <input type="text" name="visitor_accompany_note[]" id="visitor_accompany_note_`+i+`" class="form-control" maxlength="255">
1162                            </div>
1163                        </div>
1164                    </div>
1165                </div>`;
1166            }
1167
1168            formfields += `<div class="row justify-content-end">
1169                <div class="col-auto">
1170                    <button type="button" class="cta cta-arrow next-fieldset-btn remove_row">Cancella persona `+i+`</button>
1171                </div>
1172            </div>
1173            </div>
1174
1175            `;
1176        }
1177
1178        //console.log(formfields);
1179
1180        $('#extra-people-inputs').append(formfields);
1181
1182    }    
1183}
1184
1185
1186function visitorValidation(booking_type)
1187{
1188    var mostraCodiceFiscale = ($('#mostra_codice_fiscale').val() == '1');
1189
1190    if(booking_type == 'visitor_solo')
1191    {
1192        validateFieldsDynamically('visitor_self_firstname','text');
1193        validateFieldsDynamically('visitor_self_lastname','text');
1194        validateFieldsDynamically('visitor_self_email','email');
1195        validateFieldsDynamically('visitor_self_telephone','tel');
1196        if(mostraCodiceFiscale){
1197            validateCodiceFiscaleField('visitor_self_codiceFiscale');
1198        }
1199    }
1200    else if(booking_type == 'visitor_acompany')
1201    {
1202
1203        validateFieldsDynamically('visitor_self_firstname','text');
1204        validateFieldsDynamically('visitor_self_lastname','text');
1205        validateFieldsDynamically('visitor_self_email','email');
1206        validateFieldsDynamically('visitor_self_telephone','tel');
1207        if(mostraCodiceFiscale){
1208            validateCodiceFiscaleField('visitor_self_codiceFiscale');
1209        }
1210
1211        let elements = $('#extra-people-inputs').find('input');
1212
1213        $(".extra-person input:not(.cf-input):not(.cf-checkbox)").each(function(){
1214            // Test if the div element is empty
1215            var elem =  $(this).attr('id')
1216            var type =  $(this).attr('type');
1217            console.log(elem,type);
1218            validateFieldsDynamically(elem,type);
1219        });
1220        if(mostraCodiceFiscale){
1221            $('.extra-person .cf-input').each(function(){
1222                validateCodiceFiscaleField($(this).attr('id'));
1223            });
1224        }
1225
1226    }else if(booking_type == 'visitor_other')
1227    {
1228        $(".extra-person input:not(.cf-input):not(.cf-checkbox)").each(function(){
1229            // Test if the div element is empty
1230            var elem =  $(this).attr('id')
1231            var type =  $(this).attr('type');
1232            console.log(elem,type);
1233            validateFieldsDynamically(elem,type);
1234        });
1235        if(mostraCodiceFiscale){
1236            $('.extra-person .cf-input').each(function(){
1237                validateCodiceFiscaleField($(this).attr('id'));
1238            });
1239        }
1240    }
1241    else if(booking_type == 'teacher')
1242    {
1243
1244        validateFieldsDynamically('visitor_self_firstname','text');
1245        validateFieldsDynamically('visitor_self_lastname','text');
1246        validateFieldsDynamically('visitor_self_email','email');
1247        validateFieldsDynamically('visitor_self_telephone','tel');
1248        validateFieldsDynamically('visitor_self_school_name','text');
1249        //validateFieldsDynamically('visitor_self_school_system','text');
1250        validateFieldsDynamically('visitor_self_school_city','text');
1251        //validateFieldsDynamically('visitor_self_comprohensive_inst','text');
1252
1253    }
1254    else if(booking_type == 'disabled')
1255    {
1256
1257        validateFieldsDynamically('visitor_self_firstname','text');
1258        validateFieldsDynamically('visitor_self_lastname','text');
1259        validateFieldsDynamically('visitor_self_email','email');
1260        validateFieldsDynamically('visitor_self_telephone','tel');
1261        //validateFieldsDynamically('visitor_self_disablity_badge','number');
1262        //validateFieldsDynamically('visitor_self_school_system','text');
1263        if(mostraCodiceFiscale){
1264            validateCodiceFiscaleField('visitor_self_codiceFiscale');
1265        }
1266        if($('#visitor_self_disablity_accompany').is(':checked') == true){
1267            $(".extra-person input:not(.cf-input):not(.cf-checkbox)").each(function(){
1268                // Test if the div element is empty
1269                var elem =  $(this).attr('id')
1270                var type =  $(this).attr('type');
1271                console.log(elem,type);
1272                validateFieldsDynamically(elem,type);
1273            });
1274            if(mostraCodiceFiscale){
1275                $('.extra-person .cf-input').each(function(){
1276                    validateCodiceFiscaleField($(this).attr('id'));
1277                });
1278            }
1279        }
1280
1281    }
1282}
1283
1284
1285function validateCodiceFiscaleField(fieldId){
1286    var checkboxId = fieldId.replace('codiceFiscale','non_italian_fiscalcode');
1287    var value = $('#'+fieldId).val();
1288    var nonItalian = $('#'+checkboxId).is(':checked');
1289
1290    if(value == ''){
1291        $('.'+fieldId+'_validate').html('Il codice fiscale è obbligatorio').show();
1292    }else if(!nonItalian && !validaCodiceFiscale(value)){
1293        $('.'+fieldId+'_validate').html('Inserire un codice fiscale valido').show();
1294    }else{
1295        $('.'+fieldId+'_validate').hide();
1296    }
1297}
1298
1299
1300function validateEmail(email) {
1301    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
1302    return emailReg.test( email );
1303}
1304
1305function validateAlpha(name){
1306    //var nameReg = /^[ A-Za-z0-9_@./#&+-]*$/;
1307    //return nameReg.test(name);
1308    return true;
1309}
1310
1311function validateNum(num){  
1312    var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
1313    if(num.length < 5){
1314        return false;
1315    }else if (filter.test(num)) {
1316        return true;
1317    }
1318    else {
1319        return false;
1320    }   
1321}
1322
1323function validateFieldsDynamically(elementId,type){   
1324      
1325    var element =  $('#'+elementId).val();
1326
1327    if(element == '')
1328    {
1329        $('.'+elementId+'_validate').html('Il campo è obbligatorio').show();  
1330
1331    }
1332    else if(element.length < 2 || element.length > 100)
1333    {
1334        $('.'+elementId+'_validate').html("L'input deve essere superiore a 2 caratteri e inferiore a 100 caratteri.").show();
1335    }
1336    else{
1337
1338        $('.'+elementId+'_validate').hide(); 
1339    }
1340
1341    if(!validateNum(element) && type == 'tel')
1342    {           
1343        $('.'+elementId+'_validate').html("inserire un numero di cellulare valido").show();  
1344    } 
1345    else if(!validateEmail(element) && type == 'email'){
1346
1347        $('.'+elementId+'_validate').html("inserire un'email valida").show();  
1348    }
1349    else if(!validateAlpha(element) && type == 'text'){
1350
1351        $('.'+elementId+'_validate').html("inserire un valore valido").show();  
1352    } 
1353    else if(!validateNum(element) && type == 'number'){
1354
1355        $('.'+elementId+'_validate').html("inserire un valore valido").show();  
1356    }   
1357}
1358
1359
1360function calculateAge(birthday) { // birthday is a date
1361    var ageDifMs = Date.now() - birthday;
1362    var ageDate = new Date(ageDifMs); // miliseconds from epoch
1363    return Math.abs(ageDate.getUTCFullYear() - 1970);
1364  }
1365
1366$('body').on('click', '.btn-add-favroite:not(.loggedin)', function (e) {
1367    if(confirm('Per aggiungere un evento alla tua lista di preferiti, registrati ed effettua il login')){
1368        window.location = '/account/login';
1369    }
1370});
1371 
1372$('body').on('click', '.btn-add-favroite.loggedin', function (e) {
1373        e.preventDefault();
1374        var $this = $(this);       
1375        var id = $(this).attr('data-id');   
1376        var type = true;
1377        var text = 'Aggiungi ai preferiti';
1378        if($(this).hasClass('active')){
1379            type = false;
1380            text = 'Rimuovi dai preferiti';
1381        }
1382        
1383        $.ajax({
1384            url: '/account/favroites/' + id+'/'+type,
1385            data: {},
1386            method: 'post',
1387            dataType: 'json',
1388            success: function (result) {
1389                console.log(result);						
1390                if (result.success) {
1391                  // alert('Evento aggiunto ai preferiti');
1392                  //alert(text);
1393                  //$('.fav-label').html(text);
1394                    $('.fav-label', $this).html(text);
1395                  //console.log($this);
1396                }
1397            },
1398            failure: function () {
1399                $this.text("Sorry something went wrong.");
1400            },
1401            complete: function(xhr, textStatus) {
1402                if(xhr.status == 500){
1403                    window.location = '/';
1404                }else if(xhr.status == 302){
1405                    window.location = '/account/login';
1406                }
1407            }
1408        });
1409});
1410
1411$('body').on('click', '.book-empty', function (e) {
1412    e.preventDefault();
1413    if(confirm('Registrati ed effettua il login. Troverai tutte le informazioni relative a come e quando prenotare gli eventi del Festival')){
1414        window.location = '/account/login';
1415    }
1416});
1417
1418$('body').on('click', '.btn-favourite-empty', function (e) {
1419    e.preventDefault();
1420    if(confirm('Per aggiungere un evento alla tua lista di preferiti, registrati ed effettua il login')){
1421        window.location = '/account/login';
1422    }
1423});
1424
1425$('#make-gift').change(function() {
1426    if($(this).is(':checked')){
1427        $('#rec_name').attr('required',"required");
1428        $('#rec_lastname').attr('required',"required");
1429        $('#rec_email').attr('required',"required");
1430        $('#rec_confirm_email').attr('required',"required");
1431        $('#rec_phone').attr('required',"required");
1432        $('#flexRadioDefault1').attr('required',"required");
1433        $('#rec_name').attr('required',"required");  
1434    }else{
1435        $('#rec_name').removeAttr('required');
1436        $('#rec_lastname').removeAttr('required');
1437        $('#rec_email').removeAttr('required');
1438        $('#rec_confirm_email').removeAttr('required');
1439        $('#rec_phone').removeAttr('required');
1440        $('#flexRadioDefault1').removeAttr('required');
1441        $('#rec_name').removeAttr('required'); 
1442    }
1443})
1444
1445
1446
1447
1448$('body').on('click', '#personal_btn_submit', function (e) {
1449    e.preventDefault();
1450    var isValid = true;
1451    $.each($('#personal_detail_form').serializeArray(), function(i, field) {       
1452        var input = $('input[name='+field.name+']');         
1453        
1454        
1455        if(field.value == ''){
1456                // input.focus();              
1457                // isValid = false;
1458                // return false;
1459        }
1460        else if(field.name == 'fiscal_code'){   
1461                
1462            if($('#non-italian-fiscalcode').is(':checked') == false){
1463                if(validaCodiceFiscale(field.value) == false){
1464                    alert('Inserire un codice fiscale valido');
1465                    input.focus();              
1466                    isValid = false;
1467                    return false;
1468                }
1469            }else if(field.value == ''){
1470                // input.focus();              
1471                // isValid = false;
1472                // return false;
1473            }
1474        }
1475               
1476    });
1477
1478    if(isValid == false){
1479        return false;
1480    }
1481    
1482    $('#personal_detail_form').submit();
1483    return false;
1484});
1485
1486$('body').on('click', '#author_btn_submit', function (e) {
1487    e.preventDefault();
1488    $('#biografia').val($('.ql-editor').html());
1489
1490    let doc = new DOMParser().parseFromString($('#biografia').val(), 'text/html')
1491    if(doc.body.textContent.length > 2000){
1492        alert("Attenzione la biografia non può superare le 2000 battute spazi inclusi, ora ne ha "+doc.body.textContent.length);
1493        return false;
1494    }
1495
1496    if($('input[name="fiscal_code"]').val() != ''){
1497        if($('#non-italian-fiscalcode').is(':checked') == false){
1498            if(validaCodiceFiscale($('input[name="fiscal_code"]').val()) == false){
1499                alert('Inserire un codice fiscale valido');
1500                $('input[name="fiscal_code"]').focus();
1501                return false;
1502            }
1503        }
1504    }
1505
1506    if(typeof  $('input[name="acconsento[]"]:checked').val() === "undefined"){
1507        alert("Seleziona una opzione per l'utilizzo di video e foto");
1508        return false;
1509    }
1510
1511    if($('#privacy_foto').is(":checked")) {
1512        //$('#personal_detail_form').submit();
1513    }else{
1514        alert("Devi accettare le condizioni per l'utilizzo dell'immagine inserita per il sito");
1515        return false;
1516    }
1517
1518    if($('#privacy').is(":checked")) {
1519        $('#personal_detail_form').submit();
1520    }else{
1521        alert("Devi confermare la privacy");
1522    }
1523    return false;
1524});
1525
1526$('body').on('click', '.author_accredito_submit', function (e) {
1527    e.preventDefault();
1528    var form = $('#' + $(this).attr('data-form'));
1529    form.find(':input:disabled').prop('disabled', false);
1530    form.submit();
1531    return false;
1532});
1533
1534$('#cerca-accredito').on('input',function(e){
1535    var search_text = $(this).val();
1536
1537    $('#accordionExample .accordion-item').each(function(){
1538        if($(this).attr('data-search').toLowerCase().indexOf(search_text.toLowerCase())<0){
1539            $(this).hide();
1540        }else{
1541            $(this).show();
1542        }
1543    });
1544});
1545
1546$('body').on('submit', '#personal_form', function (e) {
1547    e.preventDefault();
1548    var $this = $(this);   
1549    var isValid = true;
1550    $.each($('#personal_form').serializeArray(), function(i, field) {  
1551
1552        var input = $('input[name='+field.name+']');
1553
1554        if (
1555            field.value == '' &&
1556            ( (field.name == 'rec_lastname' || field.name == 'rec_firstname') && $('#make-gift').is(':checked') )
1557        ) {
1558            input.focus();
1559            isValid = false;
1560            alert($(`label[for${field.name}]`));
1561            return false;
1562        }
1563
1564        if (
1565            field.value != '' &&
1566            ((field.name == 'rec_lastname' || field.name == 'rec_firstname') && !($('#make-gift').is(':checked')))
1567        ) {
1568            $('#make-gift').focus();
1569            isValid = false;
1570            alert('Se vuoi fare un regalo, metti la spunta sulla checkbox');
1571            return false;
1572        }
1573
1574        //if ((field.name == 'rec_lastname' || field.name == 'rec_firstname') && $('#make-gift').is(':checked'))
1575        
1576        if(field.name == 'fiscal_code'){
1577            if($('#non-italian-fiscalcode').is(':checked') == false){
1578                if(validaCodiceFiscale(field.value) == false){
1579                    alert('Inserire un codice fiscale valido');
1580                    input.focus();
1581                    isValid = false;
1582                    return false;
1583                }
1584            } else if(field.value == ''){
1585                input.focus();
1586                isValid = false;
1587                return false;
1588            }
1589        }
1590               
1591    });  
1592    
1593  
1594    if(isValid == false){
1595        return false;
1596    }
1597
1598   
1599    $.ajax({
1600        url: '/account/buycredits/personal',
1601        data: $('#personal_form').serialize(),
1602        method: 'post',
1603        dataType: 'json',
1604        success: function (result) {
1605            if (result.success) {
1606                window.location = result.redirectto;
1607            }else{
1608                alert(result.message);
1609            }
1610        },
1611        failure: function () {
1612            $this.text("Sorry something went wrong.");
1613        },
1614        complete: function(xhr, textStatus) {
1615            if(xhr.status == 500){
1616                window.location = '/';
1617            }else if(xhr.status == 302){
1618                window.location = '/account/login';
1619            }
1620        }
1621    });
1622});
1623
1624
1625$('body').on('submit', '#choose_plan', function (e) {
1626    e.preventDefault();
1627    var $this = $(this);   
1628    $.each($('#choose_plan').serializeArray(), function(i, field) {       
1629        var input = $('input[name='+field.name+']');    
1630        console.log(field.name);          
1631        if(field.value == ''){
1632           input.focus();
1633           return false;
1634        }       
1635    });
1636   
1637        
1638    $.ajax({
1639        url: '/account/buycredits/choose_plan',
1640        data: $('#choose_plan').serialize(),
1641        method: 'post',
1642        dataType: 'json',
1643        success: function (result) {
1644            if (result.success) {
1645                window.location = result.redirectto;
1646            }else{
1647                alert(result.message);
1648            }
1649        },
1650        failure: function () {
1651            $this.text("Sorry something went wrong.");
1652        },
1653        complete: function(xhr, textStatus) {
1654            if(xhr.status == 500){
1655                window.location = '/';
1656            }else if(xhr.status == 302){
1657                window.location = '/account/login';
1658            }
1659        }
1660    });
1661});
1662
1663$('body').on('submit', '#payment_option', function (e) {
1664    e.preventDefault();
1665    var $this = $(this);   
1666    $.each($('#payment_option').serializeArray(), function(i, field) {       
1667        var input = $('input[name='+field.name+']');    
1668        console.log(field.name);          
1669        if(field.value == ''){
1670           input.focus();
1671           return false;
1672        }       
1673    });
1674   
1675        
1676    $.ajax({
1677        url: '/account/buycredits/payment_option',
1678        data: $('#payment_option').serialize(),
1679        method: 'post',
1680        dataType: 'json',
1681        success: function (result) {
1682            if (result.success) {
1683                window.location = result.redirectto;
1684            }else{
1685                alert(result.message);
1686            }
1687        },
1688        failure: function () {
1689            $this.text("Sorry something went wrong.");
1690        },
1691        complete: function(xhr, textStatus) {
1692            if(xhr.status == 500){
1693                window.location = '/';
1694            }else if(xhr.status == 302){
1695                window.location = '/account/login';
1696            }
1697        }
1698    });
1699});
1700
1701$('body').on('click', '.booking_action', function (e) {
1702    e.preventDefault();
1703    var $this = $(this);   
1704    var url = '';
1705    var booking_id = $(this).attr('data-id');
1706    var url = $(this).attr('data-href');
1707    var openInNewTab = false;
1708    if($(this).hasClass('generate_pdf') && booking_id){
1709        var url = '/booking/custom_generate_pdf/'+booking_id;
1710        openInNewTab = true;
1711        window.open(url, '_blank');
1712        return false;
1713        // return false;
1714    }
1715    else if($(this).hasClass('generate_pdf_bulk')){
1716        var url = '/booking/bulkaction/generate_pdf_bulk'; 
1717        window.open(url, '_blank');
1718        return false;
1719        openInNewTab = true;
1720    }
1721    else if($(this).hasClass('generate_pdf_zip')){
1722        var url = '/booking/custom_generate_pdf_zip/'+booking_id;
1723        window.open(url, '_blank');
1724        return false;
1725        openInNewTab = true;
1726    }
1727    else if($(this).hasClass('modify_booking') && booking_id){
1728        window.location = url;
1729        return false;
1730    }
1731    else if($(this).hasClass('new_booking') && booking_id){
1732        //var url = '/booking/add/'+booking_id;
1733        window.location = url;
1734        return false;
1735    }
1736    else if($(this).hasClass('delete_booking') && booking_id){
1737        if(confirm('Sei sicuro? Vuole cancellare questa prenotazione')){
1738            var url = '/booking/cancel/'+booking_id;
1739        }else{
1740            return false;
1741        }
1742    }else{
1743        alert("Invalid request");
1744    }
1745        
1746    $.ajax({
1747        url: url,
1748        data: {},
1749        method: 'post',
1750        dataType: 'json',
1751        success: function (result) {
1752            if (result.success) {
1753                if(openInNewTab){
1754                    window.open(result.redirectto, '_blank');
1755                }else{
1756                    window.location = result.redirectto;
1757                }
1758            }else{
1759                alert(result.message);
1760            }
1761        },
1762        failure: function () {
1763            $this.text("Sorry something went wrong.");
1764        },
1765        complete: function(xhr, textStatus) {
1766            location.reload();
1767            // if(xhr.status == 500){
1768            //     window.location = '/';
1769            // }else if(xhr.status == 302){
1770            //     window.location = '/account/login';
1771            // }
1772        }
1773    });
1774
1775});
1776
1777
1778
1779function validaCodiceFiscale(cf)
1780{
1781    var validi, i, s, set1, set2, setpari, setdisp;
1782    if( cf == '' )  return '';
1783    cf = cf.toUpperCase();
1784    if( cf.length != 16 )
1785        return false;
1786    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1787    for( i = 0; i < 16; i++ ){
1788        if( validi.indexOf( cf.charAt(i) ) == -1 )
1789            return false;
1790    }
1791    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1792    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
1793    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1794    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
1795    s = 0;
1796    for( i = 1; i <= 13; i += 2 )
1797        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
1798    for( i = 0; i <= 14; i += 2 )
1799        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
1800    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
1801        return false;
1802    return true;
1803}
1804
1805function validateInstitutionalEmail(email) { 
1806    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1807    if(re.test(email)){
1808        //Email valid. Procees to test if it's from the right domain (Second argument is to check that the string ENDS with this domain, and that it doesn't just contain it)
1809        if(email.indexOf(".edu.it", email.length - ".edu.it".length) !== -1){
1810            //VALID
1811            return true;
1812        }
1813    }
1814
1815    return false;
1816}
1817
1818    
1819  /* ajax loader */
1820 
1821$(document).ready(function () {
1822    $(".btn-prova").click(function () {//The load button
1823        $('#spinner-div').show();//Load button clicked show spinner
1824        $.ajax({
1825            url: "https://api.domain.com/call/",
1826            type: 'GET',
1827            dataType: 'json',
1828            success: function (res) {
1829               //On success do something....
1830            },
1831            complete: function () {
1832                $('#spinner-div').hide();//Request is complete so hide spinner
1833            }
1834        });
1835    });
1836});
1837
1838$(".filter-events").click(function(e) {
1839    e.preventDefault();
1840    $('#active-filters').html('');
1841
1842    goFilters();
1843
1844    if($(this).hasClass('filter-events-mobile')){
1845        $('#festival-programme-filters-mobile').removeClass('show');
1846        $("html, body").animate({ scrollTop: 0 }, "slow");
1847    }else{
1848        $('#festival-programme-filter-tab').trigger('click');
1849    }
1850
1851    $('#active-filters-section').removeClass('d-none');
1852    $('#active-filters-section-mobile').addClass('d-none');
1853
1854});
1855
1856function goFilters(){
1857    var temi_selezionati = [];
1858    $('.temi-checkbox:checkbox:checked').each(function(i){
1859        temi_selezionati.push($(this).val());
1860    });
1861
1862    var incontri_selezionati = [];
1863    $('.incontri-checkbox:checkbox:checked').each(function(i){
1864        incontri_selezionati.push($(this).val());
1865    });
1866
1867    var luoghi_selezionati = [];
1868    $('.luoghi-checkbox:checkbox:checked').each(function(i){
1869        luoghi_selezionati.push($(this).val());
1870    });
1871
1872    var luoghi_pordenone = [];
1873    $('.luoghi-pordenone-checkbox:checkbox:checked').each(function(i){
1874        luoghi_pordenone.push($(this).val());
1875    });
1876
1877    var fascia_selezionati = [];
1878    $('.fascia-checkbox:checkbox:checked').each(function(i){
1879        fascia_selezionati.push($(this).val());
1880    });
1881
1882    var pnleggetv_selezionati = [];
1883    $('.pnleggetv-checkbox:checkbox:checked').each(function(i){
1884        pnleggetv_selezionati.push($(this).val());
1885    });
1886
1887    var anteprima_selezionati = [];
1888    $('.anteprima-checkbox:checkbox:checked').each(function(i){
1889        anteprima_selezionati.push($(this).val());
1890    });
1891
1892    var autori_selezionati = [];
1893    $('input[name="listAutori"]').each(function(){
1894        if($(this).val() != ''){
1895            autori_selezionati.push($(this).val());
1896        }
1897    });
1898
1899    $(".festival-programme-event").show();
1900
1901    $(".festival-programme-event").each(function(index, singleEvent) {
1902
1903        setEventoFilter(singleEvent, "tema", temi_selezionati, "span");
1904        setEventoFilter(singleEvent, "tag", incontri_selezionati, "span");
1905        setEventoFilter(singleEvent, "luoghi", luoghi_selezionati, "a");
1906        setEventoFilter(singleEvent, "luogo-pordenone", luoghi_pordenone, "a");
1907        setEventoFilter(singleEvent, "fascia", fascia_selezionati, "h4");
1908        setEventoFilter(singleEvent, "pnleggetv", pnleggetv_selezionati, "div");
1909        setEventoFilter(singleEvent, "anteprima", anteprima_selezionati, "div");
1910        setEventoFilter(singleEvent, "autori", autori_selezionati, "span");
1911
1912    });
1913
1914    setFilterActive(temi_selezionati, "temi-checkbox");
1915    setFilterActive(incontri_selezionati, "incontri-checkbox");
1916    setFilterActive(luoghi_selezionati, "luoghi-checkbox");
1917    setFilterActive(luoghi_pordenone, "luoghi-pordenone-checkbox");
1918    setFilterActive(fascia_selezionati, "fascia-checkbox");
1919    setFilterActive(pnleggetv_selezionati, "pnleggetv-checkbox");
1920    setFilterActive(anteprima_selezionati, "anteprima-checkbox");
1921    setFilterActiveDataList(autori_selezionati, "listAutori");
1922
1923    if($('.festival-programme-event:not([style*="display: none"])').length > 0){
1924        $('#no-events-section').addClass('d-none');
1925    }else{
1926        $('#no-events-section').removeClass('d-none');
1927    }
1928}
1929
1930function setFilterActiveDataList(data_selected, element_name){
1931    if (data_selected[0] !== undefined) {
1932        $('#active-filters').append('<span class="active-filter" data-filter="' + data_selected[0] + '" data-filtertypelist="' + element_name + '">' + data_selected[0] + '</span>');
1933        $('#active-filters-mobile').append('<span class="active-filter" data-filter="' + data_selected[0] + '" data-filtertypelist="' + element_name + '">' + data_selected[0] + '</span>');
1934    }
1935}
1936
1937function setFilterActive(data_selected, elements_class){
1938    $('.'+elements_class+':checkbox:checked').each(function(i){
1939        if($.inArray($(this).val(), data_selected ) !== -1){
1940            var element_label = $('label[for="'+$(this).attr('id')+'"').text();
1941            $('#active-filters').append('<span class="active-filter" data-filter="'+$(this).val()+'" data-filtertype="'+elements_class+'">'+element_label+'</span>');
1942            $('#active-filters-mobile').append('<span class="active-filter" data-filter="'+$(this).val()+'" data-filtertype="'+elements_class+'">'+element_label+'</span>');
1943        }
1944    });
1945}
1946
1947function setEventoFilter(singleEvent, dataType, data_selected, selector){
1948    let is_in_filter = false;
1949    $(singleEvent).find(selector+"[data-"+dataType+"]").each(function(index, elm) {
1950        let filter_single = $(elm).data(dataType);
1951        if($.inArray( filter_single, data_selected ) !== -1){
1952            is_in_filter = true;
1953        }
1954    })
1955    if(!is_in_filter && data_selected.length > 0){
1956        $(singleEvent).hide();
1957    }
1958}
1959
1960function resetEventoFilters(){
1961    $(".festival-programme-event").show();
1962    $('#festival-programme-filters .form-check-input').prop('checked', false);
1963    $('#festival-programme-filters-mobile .form-check-input').prop('checked', false);
1964    $('input[name="listAutori"]').val('');
1965    $('#no-events-section').addClass('d-none');
1966}
1967
1968$('#reset-filters a').click(function(e){
1969    e.preventDefault();
1970    resetEventoFilters();
1971    $('#active-filters').html('');
1972    $('#active-filters-section').addClass('d-none');
1973});
1974$('#reset-filters-mobile a').click(function(e){
1975    e.preventDefault();
1976    resetEventoFilters();
1977    $('#active-filters-mobile').html('');
1978    $('#active-filters-section-mobile').addClass('d-none');
1979});
1980
1981$('body').on('click', '#active-filters .active-filter', function() {
1982    var data_filter = $(this).data('filter');
1983    $('#festival-programme-filters .'+$(this).data('filtertype')).each(function(index, element){
1984        if($(this).val() == data_filter){
1985            $(this).prop('checked', false);
1986        }
1987    });
1988    if($(this).data('filtertypelist')){
1989        $('input[name="listAutori"]').val('');
1990    }
1991    $('#active-filters').html('');
1992    $('#active-filters-mobile').html('');
1993    goFilters();
1994    $(this).remove();
1995    if($('#active-filters').html() == ''){
1996        $('#active-filters-section').addClass('d-none');
1997    }
1998    if($('#active-filters-mobile').html() == ''){
1999        $('#active-filters-section-mobile').addClass('d-none');
2000    }
2001});
2002
2003
2004function alert(message){
2005    $('#alert_message').html(message);
2006    $('#alertPopup').modal('show');
2007}
2008
2009jQuery(document).ready(function(){
2010    if(jQuery('#concorso-messaggio').length){
2011        alert(jQuery('#concorso-messaggio').text());
2012    }
2013    $(document).on('submit','form[name="concorso_caro_autore"]',function(){
2014        $('#spinner-div').show();
2015    });
2016    $(document).on('submit','form[name="inaugurazione"]',function(){
2017        $('#spinner-div').show();
2018    });
2019    $(document).on('submit','#personal_detail_form',function(e){
2020        if ($('#formcodiceFiscale', $(this)).length > 0) {
2021            var cfValue = $('#formcodiceFiscale', $(this)).val();
2022            if ($('#non-italian-fiscalcode', $(this)).is(':checked')) {
2023                if (cfValue == '') {
2024                    e.preventDefault();
2025                    alert('Inserire un codice fiscale');
2026                    return false;
2027                }
2028            } else if (!validaCodiceFiscale(cfValue)) {
2029                e.preventDefault();
2030                alert('Inserire un codice fiscale valido');
2031                return false;
2032            }
2033        }
2034        $('#spinner-div').show();
2035    });
2036    $('.checkminorenne').change(function(){
2037
2038        var ageDifMs = Date.now() - new Date($(this).val()).getTime();
2039        var ageDate = new Date(ageDifMs);
2040        if(Math.abs(ageDate.getUTCFullYear() - 1970)<18){
2041            $('#'+$(this).data('checkminorenne')).attr('required', 'required');
2042        }else{
2043            $('#'+$(this).data('checkminorenne')).removeAttr('required');
2044        }
2045    });
2046    $(document).on('submit','form.tuttolanno-default-form',function(e){
2047        var done = true;
2048        $('form.tuttolanno-default-form .control_check').each(function(){
2049            var elements = $(this).data('controlcheck').split("|");
2050            var alert_label = $(this).data('controllabel');
2051            var passed = false;
2052            for (let i = 0; i < elements.length; i++) {
2053                if($('#'+elements[i]).is(":checked")){
2054                    passed = true;
2055                }
2056            }
2057            if(!passed){
2058                e.preventDefault();
2059                alert(alert_label);
2060                done = false;
2061            }
2062        });
2063        $('form.tuttolanno-default-form .control_check2').each(function(){
2064            var elements = $(this).data('controlcheck').split("|");
2065            var alert_label = $(this).data('controllabel');
2066            var passed = false;
2067            for (let i = 0; i < elements.length; i++) {
2068                if($('#'+elements[i]).is(":checked")){
2069                    passed = true;
2070                }
2071            }
2072            if(!passed){
2073                e.preventDefault();
2074                alert(alert_label);
2075                done = false;
2076            }
2077        });
2078        if($('.data-16-26').length > 0){
2079            var userDob = calculateAge(new Date($('.data-16-26 input').val()));
2080            if (userDob < 16 || userDob > 26) {
2081                alert("Per poter partecipare devi avere<br/>dai 16 ai 26 anni");
2082                return false;
2083            }
2084        }
2085        if($('#formeta').length && $('#formeta').attr('data-min')) {
2086            if ($('#formeta').val() < $('#formeta').attr('data-min')) {
2087                e.preventDefault();
2088                alert("Possono partecipare lettrici e lettori dai "+$('#formeta').attr('data-min')+" anni in su.");
2089                return false;
2090            }
2091        }
2092        console.log($('#formrecensione').val().length);
2093        if($('#formrecensione').length && $('#formrecensione').attr('data-maxlength')) {
2094            console.log($('#formrecensione').val().length);
2095            if ($('#formrecensione').val().length > $('#formrecensione').attr('data-maxlength')) {
2096                e.preventDefault();
2097                alert("Attenzione la recensione non può superare le "+$('#formrecensione').attr('data-maxlength')+" battute spazi inclusi, ora ne ha "+$('#formrecensione').val().length);
2098                return false;
2099            }
2100        }
2101
2102        if(done) {
2103            if ($('#formcodiceFiscale', $(this)).length > 0) {
2104                if (!validaCodiceFiscale($('#formcodiceFiscale', $(this)).val())) {
2105                    e.preventDefault();
2106                    alert('Inserire un codice fiscale valido');
2107                    return false;
2108                } else {
2109                    $('#spinner-div').show();
2110                }
2111            }else{
2112                $('#spinner-div').show();
2113            }
2114        }
2115    });
2116
2117    
2118
2119});
2120
2121
2122
2123var isMobile2=false;
2124var agent=navigator.userAgent.toLowerCase();
2125if((agent.indexOf('iphone')!=-1)||(agent.indexOf('ipod')!=-1)||(agent.indexOf('ipad')!=-1)||(agent.indexOf('android')!=-1)){isMobile2=true;}
2126var addEvent=function(elem,type,eventHandle){
2127    if(elem==null||elem==undefined)return;
2128    if(elem.addEventListener){elem.addEventListener(type,eventHandle,false);}
2129    else if(elem.attachEvent){elem.attachEvent("on"+type,eventHandle);}
2130};
2131
2132function calameo(calameo_url){
2133    if(isMobile2){
2134        location.href=calameo_url;
2135    }else{
2136        $("html:not(:animated),body:not(:animated)").animate({scrollTop:0},300);
2137        var ww_overlay=$(window).width();
2138        var wh_overlay=$(window).height();
2139        var wwi=$(window).width()*0.8;
2140        var whe=$(window).height()*0.8;
2141        $('#calameo_overlay').css({'width':ww_overlay+'px','height':wh_overlay+'px'});
2142        $('#calameo_div').css({'width':wwi+'px','height':whe+'px','margin-left':(-(wwi/2))+'px'});
2143        $('#calameo_overlay').fadeIn(300);
2144        $('#calameo_div').fadeIn(300,function(){
2145            $('#contenuto_calameo').html('<iframe src="'+calameo_url+'" width="100%" height="99%" frameborder="0" allowtransparency="" allowfullscreen="" style="margin:0 auto;"></iframe>');
2146        });
2147        $('#chiudi_calameo').fadeIn(300);
2148        $('#calameo_overlay').click(function(){
2149            $('#calameo_overlay').fadeOut(300);
2150            $('#calameo_div').fadeOut(300,function(){deleteContenuto()});
2151            $('#chiudi_calameo').fadeOut(300);}
2152        );
2153        $('#chiudi_calameo').click(function(){
2154            $('#calameo_overlay').fadeOut(300);
2155            $('#calameo_div').fadeOut(300,function(){
2156                deleteContenuto()}
2157            );$('#chiudi_calameo').fadeOut(300);
2158        });
2159    }
2160}
2161function deleteContenuto(){
2162    $('#contenuto_calameo').html('')
2163}
2164
2165$(document).ready(function () {
2166    $('.disabled_form_add_accompany').click(function(){
2167        generateNewVisitorForm('extra-person',2,1);
2168        $('.disabled_add_accompany').hide();
2169    });
2170
2171    $('.tuttolanno-checkbox-dependency').click(function(){
2172        console.log('.dep-parent-'+$(this).attr('id'));
2173        if($(this).is(":checked")){
2174            $('.dep-parent-'+$(this).attr('id')).toggleClass('dep-hidden');
2175            $('input', '.dep-parent-'+$(this).attr('id')).attr('readonly', false);
2176        }else{
2177            $('.dep-parent-'+$(this).attr('id')).toggleClass('dep-hidden');
2178            $('input', '.dep-parent-'+$(this).attr('id')).attr('readonly', true);
2179        }
2180    });
2181
2182    $('.select-dependency').change(function(){
2183        var selected = $(this).val();
2184        if(selected == $(this).data('depselect')){
2185            var strValues = $(this).data('depvalue').split("|");
2186            for(var i = 0; i < strValues.length; i++) {
2187                $('#'+strValues[i]).parent().parent().parent().parent().hide();
2188                $('#'+strValues[i]).attr('readonly', true);
2189            }
2190        }else{
2191            var strValues = $(this).data('depvalue').split("|");
2192            for(var i = 0; i < strValues.length; i++) {
2193                $('#'+strValues[i]).parent().parent().parent().parent().show();
2194                $('#'+strValues[i]).attr('readonly', false);
2195            }
2196        }
2197    });
2198
2199    var eventiGiornoCache = {};
2200
2201    function caricaEventiGiorno(giorno) {
2202        var container = $('#eventi-giorno-container');
2203        if (eventiGiornoCache[giorno]) {
2204            container.html(eventiGiornoCache[giorno]);
2205            return;
2206        }
2207        container.html('<div class="text-center py-4"><div class="spinner-border text-primary" role="status"><span class="visually-hidden">Caricamento...</span></div><p class="mt-2 text-muted">Caricamento eventi...</p></div>');
2208        $.ajax({
2209            url: '/account/buycredits/eventi-giorno',
2210            data: { day: giorno },
2211            method: 'get',
2212            success: function(html) {
2213                eventiGiornoCache[giorno] = html;
2214                container.html(html);
2215            },
2216            error: function() {
2217                container.html('<p class="text-danger py-3">Errore nel caricamento degli eventi. Riprova.</p>');
2218            }
2219        });
2220    }
2221
2222    $('.favourites-list-nav button').click(function(){
2223        $('.favourites-list-nav button').removeClass('active');
2224        $(this).addClass('active');
2225        var giorno = $(this).data('giorno');
2226
2227        $('.festival-programme-event').addClass('d-none');
2228        $('.favourites-list-no-events').addClass('d-none');
2229        if(giorno == 'tutto'){
2230            $('.festival-programme-event').removeClass('d-none');
2231        }else {
2232            if ($('.festival-programme-event[data-giornoevento="' + giorno + '"]').length) {
2233                $('.festival-programme-event[data-giornoevento="' + giorno + '"]').removeClass('d-none');
2234            } else {
2235                $('.favourites-list-no-events').removeClass('d-none');
2236            }
2237        }
2238        caricaEventiGiorno(giorno);
2239    });
2240
2241    $('#tabellaEventi').on('shown.bs.collapse', function() {
2242        var primoGiorno = $('.favourites-list-nav button.active').data('giorno');
2243        if (primoGiorno && !eventiGiornoCache[primoGiorno]) {
2244            caricaEventiGiorno(primoGiorno);
2245        }
2246    });
2247
2248    if($('.do-filter-active').length){
2249        if($(window).width()>767) {
2250            $('#festival-programme-filters .incontri-checkbox[value="' + $('.do-filter-active').data('type') + '"]').prop('checked', true);
2251        }else{
2252            $('#festival-programme-filters-mobile .incontri-checkbox[value="' + $('.do-filter-active').data('type') + '"]').prop('checked', true);
2253        }
2254
2255        goFilters();
2256
2257        $('#active-filters-section').removeClass('d-none');
2258        $('#active-filters-section-mobile').removeClass('d-none');
2259
2260
2261    }
2262});

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.