        <script type="text/javascript">
            let adCnt = 1;
            $(document).on({
                "contextmenu": function(e) {
                    //e.preventDefault();
                }
            });

            function magictable_closeAllSubs(e){
                if(e == null || jQuery(e.target).is('.magictableSub, .MagicTableSubEntryRowWrap, .MagicTableSubEntryHeadline h3, .MagicTableSubEntryHeadline h3 .icon-remove')){
                    jQuery('body').off('click', magictable_closeAllSubs);
                    jQuery('body').off('touchstart', magictable_closeAllSubs);
                    jQuery('.magictableSub').css("display","none");
                    jQuery('.magictableSub').each(
                        function(){
                            if(jQuery(this).css("z-index") == '999999'){
                                jQuery(this).css("position","relative");
                            }
                        }
                    );
                    setTimeout(function(){
                        jQuery('.MagicTableRowMoreButton').each(function(){
                            jQuery(this).get(0).disabled = false;
                        });
                    }, 500);
                }
            }

            function magictable_openSub(id){
                jQuery('.MagicTableRowMoreButton').css("display","inline-block");
                if(jQuery('#'+id).css("z-index") == '999999'){
                    if(jQuery('#'+id).css("position") != "fixed"){
                        jQuery('.magictableSub').css("display","none");
                        jQuery('#'+id).css("display","inline-block");
                        jQuery('#'+id).css("position","fixed");
                        setTimeout(function(){jQuery('body').on('click', magictable_closeAllSubs)}, 100);
                        setTimeout(function(){jQuery('body').on('touchstart', magictable_closeAllSubs)}, 100);
                        jQuery('.MagicTableRowMoreButton').attr('disabled', 'disabled');
                    }
                }else{
                    if(jQuery('#'+id).css("display") != "inline-block"){
                        jQuery('.magictableSub').css("display","none");
                        jQuery('#'+id).css("display","inline-block");
                        jQuery('#btn'+id).css("display","none");
                    }else{
                        magictable_closeAllSubs(null);
                    }
                }

                magictable_keepNonFreeClosed();
            }

            function magictable_displayExpiredEvents(){
                jQuery('.MagicTableRowHide').each(
                    function(){
                        if(jQuery(this).css('display') == 'none'){
                            jQuery(this).css('display','block');
                            jQuery('#MagicTableExpiredEvents').html("Hide Expired Eventz");
                        }else{
                            jQuery(this).css('display','none');
                            jQuery('#MagicTableExpiredEvents').html("Display Expired Eventz");
                        }
                    }
                );
            }



            var keep_channels_closed = 1;
            function magictable_keepChannelsClosed(){
                if(keep_channels_closed == 0){
                    location.href = "/index.php?option=com_magictable&return=aHR0cHM6Ly93d3cuc3BvcnRldmVudHouY29tL2VuL2Jsb2cvd3AtanNvbi9vZW1iZWQvMS4wL2VtYmVkP2Zvcm1hdD14bWwmdXJsPWh0dHBzJTNBJTJGJTJGd3d3LnNwb3J0ZXZlbnR6LmNvbSUyRmJsb2clMkZldXJvLTIwMjAta25vY2tvdXQtcGhhc2Utc2NoZWR1bGUlMkY=&keep_channels_closed=1&&Itemid=211";
                } else {
                    location.href = "/index.php?option=com_magictable&return=aHR0cHM6Ly93d3cuc3BvcnRldmVudHouY29tL2VuL2Jsb2cvd3AtanNvbi9vZW1iZWQvMS4wL2VtYmVkP2Zvcm1hdD14bWwmdXJsPWh0dHBzJTNBJTJGJTJGd3d3LnNwb3J0ZXZlbnR6LmNvbSUyRmJsb2clMkZldXJvLTIwMjAta25vY2tvdXQtcGhhc2Utc2NoZWR1bGUlMkY=&keep_channels_closed=0&&Itemid=211";
                }
            }

            var free_channels_only = 1;
            function magictable_freeChannels(){
                if(free_channels_only == 0){
                    location.href = "/index.php?option=com_magictable&return=aHR0cHM6Ly93d3cuc3BvcnRldmVudHouY29tL2VuL2Jsb2cvd3AtanNvbi9vZW1iZWQvMS4wL2VtYmVkP2Zvcm1hdD14bWwmdXJsPWh0dHBzJTNBJTJGJTJGd3d3LnNwb3J0ZXZlbnR6LmNvbSUyRmJsb2clMkZldXJvLTIwMjAta25vY2tvdXQtcGhhc2Utc2NoZWR1bGUlMkY=&free_channels_only=1&&Itemid=211";
                } else {
                    location.href = "/index.php?option=com_magictable&return=aHR0cHM6Ly93d3cuc3BvcnRldmVudHouY29tL2VuL2Jsb2cvd3AtanNvbi9vZW1iZWQvMS4wL2VtYmVkP2Zvcm1hdD14bWwmdXJsPWh0dHBzJTNBJTJGJTJGd3d3LnNwb3J0ZXZlbnR6LmNvbSUyRmJsb2clMkZldXJvLTIwMjAta25vY2tvdXQtcGhhc2Utc2NoZWR1bGUlMkY=&free_channels_only=0&&Itemid=211";
                }
            }

            function magictable_keepNonFreeClosed(){
                if(free_channels_only == 0){
                    jQuery('.MagicTableNonFreeChannel').css('display','none');
                }
            }

            $(document).ready(function () {
				
				// var c_cipher = "zyxwvutsrqponmlkjihgfedcba";
                // var c_plain = "abcdefghijklmnopqrstuvwxyz";
				
                // function encrypt(text) {
                //     plain = c_plain + c_plain.toUpperCase();
                //     cipher = c_cipher + c_cipher.toUpperCase();
                //     var newText = '';
                //     for(var i=0; i<text.length; i++) {
                //         var c = text.charAt(i);
                //         var index = plain.indexOf(c);
                //         if(index >= 0 && index < cipher.length) {
                //             newText += cipher.charAt(index);
                //         } else {
                //             newText += c;
                //         }
                //     }
                //     return newText;
                // }

                /*
                $('#jform_offset').val('UTC');
                $('#jform_offset').on('change',
                    function(){
                        location.href = "/index.php?option=com_magictable&return=aHR0cHM6Ly93d3cuc3BvcnRldmVudHouY29tL2VuL2Jsb2cvd3AtanNvbi9vZW1iZWQvMS4wL2VtYmVkP2Zvcm1hdD14bWwmdXJsPWh0dHBzJTNBJTJGJTJGd3d3LnNwb3J0ZXZlbnR6LmNvbSUyRmJsb2clMkZldXJvLTIwMjAta25vY2tvdXQtcGhhc2Utc2NoZWR1bGUlMkY=&set_timezone_offset=1&timezone_offset="+$('#jform_offset').val()+"&Itemid=211";
                    }
                );

                $("#jform_offset option[value='Europe/Istanbul']").prependTo('#jform_offset');
                $("#jform_offset option[value='Europe/Berlin']").prependTo('#jform_offset');
                $("#jform_offset option[value='Europe/London']").prependTo('#jform_offset');
                */

                var client_tz_offset = new Date().toString().match(/([-\+][0-9]+)\s/)[1];

                $('#MagicTableContainer').jtable({
                    title: '',
                    actions: {
                        listAction: '/index.php?option=com_magictable&language_code=en&table=1&accesskey=2011721498&se_date=&se_module=&se_id=&Itemid=211&client_tz_offset=' + encodeURIComponent(client_tz_offset)
                    },
                    recordsLoaded: function(event, data){
                           sport_name = "Football";length = 2;                       $('.item').filter(function() {return $.trim($(this).text()) === sport_name;}).append('<span class="counter">' + length + '</span>');

                        sport_name = "Basketball";length = 3;                       $('.item').filter(function() {return $.trim($(this).text()) === sport_name;}).append('<span class="counter">' + length + '</span>');

                        sport_name = "Futsal";length = 1;                       $('.item').filter(function() {return $.trim($(this).text()) === sport_name;}).append('<span class="counter">' + length + '</span>');

                        
                        /*
                         jQuery(window).on("resize scroll", function() {
                         jQuery('.viewportCloned').remove();
                         jQuery(".MagicTableBegin").each(
                         function(i){
                         if(withinViewport(jQuery(this).get(0))){
                         jQuery('#toTop').css('width', '100%');
                         jQuery('#toTop').css('height', 'auto');
                         var cloned = jQuery(this).clone().addClass('viewportCloned').appendTo('#toTop'); //MagicTableBegin
                         }
                         }
                         );
                         });*/

                        if(data.serverResponse.DateOut != ""){
                            $("#DateOut").html(data.serverResponse.DateOut);
                        } else {
                            $("#ListTitle").html("All Events");
                        }

                        $('#MagicTableContainer').prepend('<button class="btn TopButton" id="MagicTableChannelButtonFreeChannels" onclick="magictable_freeChannels()">'+"<img src='/templates/sportdigga/images/icon_unlocked.png' style='width:10px;height:13px;vertical-align:text-top;' />&nbsp;&nbsp;"+"Free Channels Only"+'</button>');

                        if(free_channels_only == 0){
                            jQuery('.MagicTableNonFreeChannel').css('display','none');
                            jQuery('#MagicTableChannelButtonFreeChannels').addClass('MagicTableChannelButtonFreeChannelsWider');
                            jQuery('#MagicTableChannelButtonFreeChannels').html("<img src='/templates/sportdigga/images/icon_unlocked.png' style='width:12px;height:16px;vertical-align:text-top;' />&nbsp;&nbsp;" + "<img src='/templates/sportdigga/images/icon_locked.png' style='width:12px;height:16px;vertical-align:text-top;' />&nbsp;&nbsp;" + "Free and Crypted Channels");
                        } else {
                            jQuery('#MagicTableChannelButtonFreeChannels').removeClass('MagicTableChannelButtonFreeChannelsWider');
                            jQuery('.MagicTableNonFreeChannel').css('display','inline-block');
                            jQuery('#MagicTableChannelButtonFreeChannels').html("<img src='/templates/sportdigga/images/icon_unlocked.png' style='width:12px;height:16px;vertical-align:text-top;' />&nbsp;&nbsp;" + "Free Channels Only");
                        }

                        $('#MagicTableContainer').prepend('<button class="btn TopButton" id="MagicTableChannelButtonKeepClosed" onclick="magictable_keepChannelsClosed()">'+"Hide Channels"+'</button>');

                        if(keep_channels_closed == 0){
                            jQuery('.MagicTableChannels').css('display','none');
                            jQuery('#MagicTableChannelButtonKeepClosed').html("Show Channels");
                            $('.MagicTableChannelButton h3').html("Show Channels");
                        } else {
                            jQuery('.MagicTableChannels').css('display','block');
                            jQuery('#MagicTableChannelButtonKeepClosed').html("Hide Channels");
                            $('.MagicTableChannelButton h3').html("Hide Channels");
                        }

                        if(jQuery('.MagicTableRowHide').length > 0){
                            $('#MagicTableContainer').prepend('<button class="btn TopButton" id="MagicTableExpiredEvents" onclick="magictable_displayExpiredEvents()">'+"Display Expired Eventz"+'</button>');
                        }

                        $('.MagicTableChannelButton').on('click',
                            function(){
                                if($(this).next('.MagicTableChannels').css('display') == 'block'){
                                    $(this).next('.MagicTableChannels').css('display','none');
                                    $(this).children('h3').html("Show Channels");
                                } else {
                                    $(this).next('.MagicTableChannels').css('display','block');
                                    $(this).children('h3').html("Hide Channels");
                                }
                            }
                        );
                    },
                    fields: {
                        Begin: {
                            title: '',
                            width: '100%',
                            display: function (data) {
                                // console.log(data);
                                var open = '<div class="MagicTableRow'+(typeof data.record.date_diff != "undefined" && data.record.date_diff >= 7200 && data.record.day_diff == 0 ? ' MagicTableRowHide' : '')+'">';
                                var close = '</div>';
								// old
                                var res = '<div class="MagicTableRowHeadline">'+(typeof data.record.Category != "undefined" && typeof data.record.Category['#text'] != "undefined" && data.record.Category['#text'] != "" ? data.record.Category['#text'] + ', ' : '')+(typeof data.record.Tournament != "undefined" && data.record.Tournament['#text'] != "undefined" && data.record.Tournament['#text'] ? data.record.Tournament['#text'] : '')+'</div>';
                               res += '<div class="MagicTableRowMainData"><h1><div class="MagicTableRowMainDataHolder"><div class="MagicTableRowMainHomeTeam"><div style="background: url(/components/com_magictable/flags/'+(typeof data.record.Team1CountryCode == "undefined" || typeof data.record.Team1CountryCode.toLowerCase == "undefined" ? 'redcross' : data.record.Team1CountryCode.toLowerCase())+'.png) no-repeat center center; width: 18px; height: 18px; white-space: nowrap; display: inline-block; margin-right: 10px; background-size: 100% 100%;" class="MagicTableLeftFlag"></div><span class="MagicTableRowMainHomeTeamName">'+ data.record.Team1['#text'] + '</span></div><span class="MagicTableRowMainVs"> vs. </span><div class="MagicTableRowMainAwayTeam"><span class="MagicTableRowMainAwayTeamName">' + data.record.Team2['#text']+'</span> <div style="background: url(/components/com_magictable/flags/'+(typeof data.record.Team2CountryCode == "undefined" || typeof data.record.Team2CountryCode.toLowerCase == "undefined" ? 'redcross' : data.record.Team2CountryCode.toLowerCase())+'.png) no-repeat center center; width: 18px; height: 18px; white-space: nowrap; display: inline-block; margin-left: 5px; background-size: 100% 100%;" class="MagicTableRightFlag"></div></div></div></h1></div>';
                                // var res = '<div class="MagicTableRowHeadline"><span class="matchInfo">'+encrypt((typeof data.record.Category != "undefined" && typeof data.record.Category['#text'] != "undefined" && data.record.Category['#text'] != "" ? data.record.Category['#text'] + ', ' : '')+(typeof data.record.Tournament != "undefined" && data.record.Tournament['#text'] != "undefined" && data.record.Tournament['#text'] ? data.record.Tournament['#text'] : ''))+'</span></div>';
                                // res += '<div class="MagicTableRowMainData"><h1><div style="background: url(/components/com_magictable/flags/'+(typeof data.record.Team1CountryCode == "undefined" || typeof data.record.Team1CountryCode.toLowerCase == "undefined" ? 'redcross' : data.record.Team1CountryCode.toLowerCase())+'.png) no-repeat center center; width: 18px; height: 18px; white-space: nowrap; display: inline-block; margin-right: 10px; background-size: 100% 100%;" class="MagicTableLeftFlag"></div><span class="matchInfo" >'+encrypt(data.record.Team1['#text'] + " vs " + data.record.Team2['#text'])+'</span> <div style="background: url(/components/com_magictable/flags/'+(typeof data.record.Team2CountryCode == "undefined" || typeof data.record.Team2CountryCode.toLowerCase == "undefined" ? 'redcross' : data.record.Team2CountryCode.toLowerCase())+'.png) no-repeat center center; width: 18px; height: 18px; white-space: nowrap; display: inline-block; margin-left: 5px; background-size: 100% 100%;" class="MagicTableRightFlag"></div></h1></div>';
                                res += '<div class="MagicTableRowFootline MagicTableBegin"><h3>'+data.record.Begin+'</h3></div>';

                                var resCompound = {};

                                var channelz = data.record.Channels.Channel;
                                var filterChannelsIds = ["30430", "30431", "30432", "30433", "30434", "30435", "30436", "30437", "30438", "30439", "30440", "30441", "30442", "30622", "30623", "30624", "30920", "30921", "30974", "30975", "30976", "30977", "30979", "31125",  "31171", "31172", "31173", "31177", "31178", "31327", "30428", "31126", "31170", "31688", "31689", "31690", "31692"];
                                var filterChannelsNames = ["Channel49", "Channel12","Channel13", "Channel14","Channel15","Channel16", "Channel17","Channel18","Channel21","Channel22","Channel23","Channel24","Channel25","Channel26","Channel27","Channel28","Channel31","Channel32","Channel33","Channel34","Channel35","Channel36","Channel37","Channel38","Channel39","Channel40","Channel41","Channel44","Channel45","Channel46","Channel47","Channel48","Channel50","Channel11","Channel42","Channel43","Channel52","Channel53","Channel54","Channel51"];
                                if(typeof data.record.Channels.Channel != "undefined" && typeof data.record.Channels.Channel.length != "undefined"){
                                    for(var i = 0; i < data.record.Channels.Channel.length; i++){
                                        if(!filterChannelsIds.includes(channelz[i]["@id"]) && !filterChannelsNames.includes(channelz[i].Name))
                                        populateChannel(data, resCompound, channelz[i]);
                                    }
                                } else {
                                    if(typeof data.record.Channels.Channel != "undefined"){
                                        if(!filterChannelsIds.includes(channelz["@id"]) && !filterChannelsNames.includes(channelz.Name))
                                        populateChannel(data, resCompound, channelz);
                                    }
                                }

                                if( keep_channels_closed == 0 ) {
                                    res += '<button class="btn MagicTableChannelButton"><h3>'+"Hide Channels"+'</h3></button>';
                                }

                                res += '<div class="MagicTableChannels">';
                                for(var key in resCompound){

                                    res += resCompound[key]['head'];
                                    res += '<div class="MagicTableSubEntryRowWrap">';
                                    for(var j = 0; j < resCompound[key]['subentries'].length; j++){
                                        res += resCompound[key]['subentries'][j];
                                    }
                                                                                                                    res += '<div class="se-ad se-ad-details">';
                                                                                    res += '<a href="https://prf.hn/click/camref:1011l4pfu/creativeref:1011l28005"><img src="https://creative.prf.hn/source/camref:1011l4pfu/creativeref:1011l28005" alt="" width="400" height="400" border="0" /></a>';
                                                                                res += '</div>';
                                                                                res += '</div>';
                                                                        res += resCompound[key]['foot'];
                                }
                                res += '</div>';
                                ad = '';
                                                                                                                                    if (typeof data.record.date_diff != 'undefined' && data.record.date_diff >= 10800) {
                                    adCnt--;
                                }
                                adCnt++;
                                return open+res+close+ad;
                            }
                        },
                    }
                });
                $('#MagicTableContainer').jtable('load');
            });

            function populateChannel(data, resCompound, channelz){
                var isFirst = false;

                if(!resCompound[channelz.Name]){

                    isFirst = true;
                    resCompound[channelz.Name] = {};

                    resCompound[channelz.Name]['head']  = '<div id="sub'+data.record['@id']+channelz['@id']+'" style="display:none;" class="magictableSub">';
                    resCompound[channelz.Name]['head'] += '<div onclick="magictable_openSub(\'sub'+data.record['@id']+channelz['@id']+'\');" class="MagicTableSubEntryHeadline"><h3>'+channelz.Name+' <span class="icon-remove"></span></h3></div>';

                }

                if(!resCompound[channelz.Name]['subentries']){
                    resCompound[channelz.Name]['subentries'] = new Array();
                }

                var subentry = '<div class="MagicTableSubEntryRow">';
                subentry += '<div style="width: 20%;" class="MagicTableSubEntry"><strong>'+"Name"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.Name == "undefined" ? 'not available' : channelz.Satellite.Name)+'</div></div>';
                subentry += '<div style="width: 10%;" class="MagicTableSubEntry"><strong>'+"Position"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.Pos == "undefined" ? 'not available' : channelz.Satellite.Pos)+'</div></div>';
                subentry += '<div style="width: 10%;" class="MagicTableSubEntry"><strong>'+"Frequency"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.SatFreq == "undefined" ? 'not available' : channelz.Satellite.SatFreq)+'</div></div>';
                subentry += '<div style="width: 10%;" class="MagicTableSubEntry"><strong>'+"Polarisation"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.Polarisation == "undefined" ? 'not available' : channelz.Satellite.Polarisation)+'</div></div>';
                subentry += '<div class="MagicTableSubEntry"><strong>'+"SR"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.SR == "undefined" ? 'not available' : channelz.Satellite.SR)+'</div></div>';
                subentry += '<div class="MagicTableSubEntry"><strong>'+"FEC"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.FEC == "undefined" ? 'not available' : channelz.Satellite.FEC)+'</div></div>';
                subentry += '<div class="MagicTableSubEntry"><strong>'+"System"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.System == "undefined" ? 'not available' : channelz.Satellite.System)+'</div></div>';
                subentry += '<div class="MagicTableSubEntry"><strong>'+"Modulation"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.Modulation == "undefined" ? 'not available' : channelz.Satellite.Modulation)+'</div></div>';
                subentry += '<div class="MagicTableSubEntry"><strong>'+"Crypt"+'</strong>';
                subentry += '<div>'+(typeof channelz.Satellite.Crypt == "undefined" ? 'not available' : channelz.Satellite.Crypt)+'</div></div>';
                subentry += '</div>';

                resCompound[channelz.Name]['subentries'].push(subentry);

                var freeClass = 'MagicTableNonFreeChannel';
                if(channelz.Satellite.Crypt != "undefined" && typeof channelz.Satellite.Crypt != "undefined" && channelz.Satellite.Crypt.length && ( channelz.Satellite.Crypt.toLowerCase() == 'frei' || channelz.Satellite.Crypt.toLowerCase() == 'free' ) ){
                    freeClass = 'MagicTableFreeChannel';
                }

                if(isFirst){
                    resCompound[channelz.Name]['foot']  = '</div>';
                    resCompound[channelz.Name]['foot'] += '<button onclick="magictable_openSub(\'sub'+data.record['@id']+channelz['@id']+'\');" id="btnsub'+data.record['@id']+channelz['@id']+'" class="btn MagicTableRowMoreButton '+freeClass+'">';
                    resCompound[channelz.Name]['foot'] += "<div><img src='/templates/sportdigga/images/"+(freeClass == 'MagicTableFreeChannel' ? 'icon_unlocked.png' : 'icon_locked.png')+"' style='width:10px;height:13px;vertical-align:text-top;' />&nbsp;&nbsp;"+channelz.Name+"</div>";
                    resCompound[channelz.Name]['foot'] += '</button>';

                }
            }
        </script>

        <!--<div id="apple-badge-mobile"><a href="https://itunes.apple.com/US/app/id979406502?mt=8"><img src="/images/download.png" /></a></div>
        -->


        <h1 class="SportEventzTitle"><span id="SportOut"></span><span>Live Schedule on Sat-TV</span> <span id="DateOut"></span></h1>
        <h2 style="font-weight:400;font-size:12px;line-height:1.2;">
            SportEventz provides TV and livestream sport schedules with broadcasting channel details. Check where you can watch your favorite sport live!        </h2>

        <div id="MagicTableContainer" style="margin-top:0px;"><br /></div>
        <div style="clear:both;"></div>

        