var files, files2, files3, files4, notintid, shindid;
/*! alertify - v0.3.11 - 2013-10-08 */
!function (a, b) {
    "use strict";
    var c, d = a.document;
    c = function () {
        var c, e, f, g, h, i, j, k, l, m, n, o, p, q = {}, r = {}, s = !1, t = {ENTER: 13, ESC: 27, SPACE: 32}, u = [];
        return r = {
            buttons: {
                holder: '<nav class="alertify-buttons">{{buttons}}</nav>',
                submit: '<button type="submit" class="alertify-button alertify-button-ok" id="alertify-ok">{{ok}}</button>',
                ok: '<button class="alertify-button alertify-button-ok" id="alertify-ok">{{ok}}</button>',
                cancel: '<button class="alertify-button alertify-button-cancel" id="alertify-cancel">{{cancel}}</button>'
            },
            input: '<div class="alertify-text-wrapper"><input type="text" class="alertify-text" id="alertify-text"></div>',
            message: '<p class="alertify-message">{{message}}</p>',
            log: '<article class="alertify-log{{class}}">{{message}}</article>'
        }, p = function () {
            var a, c, e = !1, f = d.createElement("fakeelement"), g = {
                WebkitTransition: "webkitTransitionEnd",
                MozTransition: "transitionend",
                OTransition: "otransitionend",
                transition: "transitionend"
            };
            for (a in g) if (f.style[a] !== b) {
                c = g[a], e = !0;
                break
            }
            return {type: c, supported: e}
        }, c = function (a) {
            return d.getElementById(a)
        }, q = {
            labels: {ok: "OK", cancel: "Cancel"},
            delay: 5e3,
            buttonReverse: !1,
            buttonFocus: "ok",
            transition: b,
            addListeners: function (a) {
                var b, c, i, j, k, l = "undefined" != typeof f, m = "undefined" != typeof e,
                    n = "undefined" != typeof o, p = "", q = this;
                b = function (b) {
                    return "undefined" != typeof b.preventDefault && b.preventDefault(), i(b), "undefined" != typeof o && (p = o.value), "function" == typeof a && ("undefined" != typeof o ? a(!0, p) : a(!0)), !1
                }, c = function (b) {
                    return "undefined" != typeof b.preventDefault && b.preventDefault(), i(b), "function" == typeof a && a(!1), !1
                }, i = function () {
                    q.hide(), q.unbind(d.body, "keyup", j), q.unbind(g, "focus", k), l && q.unbind(f, "click", b), m && q.unbind(e, "click", c)
                }, j = function (a) {
                    var d = a.keyCode;
                    (d === t.SPACE && !n || n && d === t.ENTER) && b(a), d === t.ESC && m && c(a)
                }, k = function () {
                    n ? o.focus() : !m || q.buttonReverse ? f.focus() : e.focus()
                }, this.bind(g, "focus", k), this.bind(h, "focus", k), l && this.bind(f, "click", b), m && this.bind(e, "click", c), this.bind(d.body, "keyup", j), this.transition.supported || this.setFocus()
            },
            bind: function (a, b, c) {
                "function" == typeof a.addEventListener ? a.addEventListener(b, c, !1) : a.attachEvent && a.attachEvent("on" + b, c)
            },
            handleErrors: function () {
                if ("undefined" != typeof a.onerror) {
                    var b = this;
                    return a.onerror = function (a, c, d) {
                        b.error("[" + a + " on line " + d + " of " + c + "]", 0)
                    }, !0
                }
                return !1
            },
            appendButtons: function (a, b) {
                return this.buttonReverse ? b + a : a + b
            },
            build: function (a) {
                var b = "", c = a.type, d = a.message, e = a.cssClass || "";
                switch (b += '<div class="alertify-dialog">', b += '<a id="alertify-resetFocusBack" class="alertify-resetFocus" href="#">Reset Focus</a>', "none" === q.buttonFocus && (b += '<a href="#" id="alertify-noneFocus" class="alertify-hidden"></a>'), "prompt" === c && (b += '<div id="alertify-form">'), b += '<article class="alertify-inner">', b += r.message.replace("{{message}}", d), "prompt" === c && (b += r.input), b += r.buttons.holder, b += "</article>", "prompt" === c && (b += "</div>"), b += '<a id="alertify-resetFocus" class="alertify-resetFocus" href="#">Reset Focus</a>', b += "</div>", c) {
                    case"confirm":
                        b = b.replace("{{buttons}}", this.appendButtons(r.buttons.cancel, r.buttons.ok)), b = b.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
                        break;
                    case"prompt":
                        b = b.replace("{{buttons}}", this.appendButtons(r.buttons.cancel, r.buttons.submit)), b = b.replace("{{ok}}", this.labels.ok).replace("{{cancel}}", this.labels.cancel);
                        break;
                    case"alert":
                        b = b.replace("{{buttons}}", r.buttons.ok), b = b.replace("{{ok}}", this.labels.ok)
                }
                return l.className = "alertify alertify-" + c + " " + e, k.className = "alertify-cover", b
            },
            close: function (a, b) {
                var c, d, e = b && !isNaN(b) ? +b : this.delay, f = this;
                this.bind(a, "click", function () {
                    c(a)
                }), d = function (a) {
                    a.stopPropagation(), f.unbind(this, f.transition.type, d), m.removeChild(this), m.hasChildNodes() || (m.className += " alertify-logs-hidden")
                }, c = function (a) {
                    "undefined" != typeof a && a.parentNode === m && (f.transition.supported ? (f.bind(a, f.transition.type, d), a.className += " alertify-log-hide") : (m.removeChild(a), m.hasChildNodes() || (m.className += " alertify-logs-hidden")))
                }, 0 !== b && setTimeout(function () {
                    c(a)
                }, e)
            },
            dialog: function (a, b, c, e, f) {
                j = d.activeElement;
                var g = function () {
                    m && null !== m.scrollTop && k && null !== k.scrollTop || g()
                };
                if ("string" != typeof a) throw new Error("message must be a string");
                if ("string" != typeof b) throw new Error("type must be a string");
                if ("undefined" != typeof c && "function" != typeof c) throw new Error("fn must be a function");
                return this.init(), g(), u.push({
                    type: b,
                    message: a,
                    callback: c,
                    placeholder: e,
                    cssClass: f
                }), s || this.setup(), this
            },
            extend: function (a) {
                if ("string" != typeof a) throw new Error("extend method must have exactly one paramter");
                return function (b, c) {
                    return this.log(b, a, c), this
                }
            },
            hide: function () {
                var a, b = this;
                u.splice(0, 1), u.length > 0 ? this.setup(!0) : (s = !1, a = function (c) {
                    c.stopPropagation(), b.unbind(l, b.transition.type, a)
                }, this.transition.supported ? (this.bind(l, this.transition.type, a), l.className = "alertify alertify-hide alertify-hidden") : l.className = "alertify alertify-hide alertify-hidden alertify-isHidden", k.className = "alertify-cover alertify-cover-hidden", j.focus())
            },
            init: function () {
                d.createElement("nav"), d.createElement("article"), d.createElement("section"), null == c("alertify-cover") && (k = d.createElement("div"), k.setAttribute("id", "alertify-cover"), k.className = "alertify-cover alertify-cover-hidden", d.body.appendChild(k)), null == c("alertify") && (s = !1, u = [], l = d.createElement("section"), l.setAttribute("id", "alertify"), l.className = "alertify alertify-hidden", d.body.appendChild(l)), null == c("alertify-logs") && (m = d.createElement("section"), m.setAttribute("id", "alertify-logs"), m.className = "alertify-logs alertify-logs-hidden", d.body.appendChild(m)), d.body.setAttribute("tabindex", "0"), this.transition = p()
            },
            log: function (a, b, c) {
                var d = function () {
                    m && null !== m.scrollTop || d()
                };
                return this.init(), d(), m.className = "alertify-logs", this.notify(a, b, c), this
            },
            notify: function (a, b, c) {
                var e = d.createElement("article");
                e.className = "alertify-log" + ("string" == typeof b && "" !== b ? " alertify-log-" + b : ""), e.innerHTML = a, m.appendChild(e), setTimeout(function () {
                    e.className = e.className + " alertify-log-show"
                }, 50), this.close(e, c)
            },
            set: function (a) {
                var b;
                if ("object" != typeof a && a instanceof Array) throw new Error("args must be an object");
                for (b in a) a.hasOwnProperty(b) && (this[b] = a[b])
            },
            setFocus: function () {
                o ? (o.focus(), o.select()) : i.focus()
            },
            setup: function (a) {
                var d, j = u[0], k = this;
                s = !0, d = function (a) {
                    a.stopPropagation(), k.setFocus(), k.unbind(l, k.transition.type, d)
                }, this.transition.supported && !a && this.bind(l, this.transition.type, d), l.innerHTML = this.build(j), g = c("alertify-resetFocus"), h = c("alertify-resetFocusBack"), f = c("alertify-ok") || b, e = c("alertify-cancel") || b, i = "cancel" === q.buttonFocus ? e : "none" === q.buttonFocus ? c("alertify-noneFocus") : f, o = c("alertify-text") || b, n = c("alertify-form") || b, "string" == typeof j.placeholder && "" !== j.placeholder && (o.value = j.placeholder), a && this.setFocus(), this.addListeners(j.callback)
            },
            unbind: function (a, b, c) {
                "function" == typeof a.removeEventListener ? a.removeEventListener(b, c, !1) : a.detachEvent && a.detachEvent("on" + b, c)
            }
        }, {
            alert: function (a, b, c) {
                return q.dialog(a, "alert", b, "", c), this
            }, confirm: function (a, b, c) {
                return q.dialog(a, "confirm", b, "", c), this
            }, extend: q.extend, init: q.init, log: function (a, b, c) {
                return q.log(a, b, c), this
            }, prompt: function (a, b, c, d) {
                return q.dialog(a, "prompt", b, c, d), this
            }, success: function (a, b) {
                return q.log(a, "success", b), this
            }, error: function (a, b) {
                return q.log(a, "error", b), this
            }, set: function (a) {
                q.set(a)
            }, labels: q.labels, debug: q.handleErrors
        }
    }, "function" == typeof define ? define([], function () {
        return new c
    }) : "undefined" == typeof a.alertify && (a.alertify = new c)
}(this);
function gplsz() {
    let monsx = 0;
    let szxw = $(window).width();
    if(szxw > 575) monsx = szxw;
    else if(szxw>=661) monsx = szxw-2;
    else if(szxw>1000) monsx=789;
    let szh = Math.ceil(monsx/1.89);
    let psxh = monsx+'x'+szh;
    return psxh;
}
/**** alertify ******/
function validateEmail(email) {
    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,}))$/;
    return re.test(String(email).toLowerCase());
}

function callneuromedia(id, acid, title, category, idelm, tip, subttl, divi, team1, team2, team1id, team2id, clubname, clubid) {
    let player = document.getElementById(id);

    if(acid > 0) _nm['context'] = acid; // l'ID de votre client ou site?
    if(idelm > 0) _nm['contentid'] = idelm; // Votre ID Unique de contenu qui concerne le contexte
    if(title != "") _nm['title'] = title; // Texte arbitraire qui sera utilisé dans les rapports
    if(category != '') _nm['category'] = category; // Champs qui pourra être utilisé dans les rapports pour faire des regroupements
    if(tip != '') _nm['type'] = tip; // par exemple VOD ou Live, mais vous êtes libres de mettre ce que vous voulez
    if(subttl != '') _nm['subtitle'] = subttl;
    if(divi != '') _nm['division'] = divi;
    if(team1 != '') _nm['team1'] = team1;
    if(team2 != '') _nm['team2'] = team2;
    if(team1id != '') _nm['team1id'] = team1id;
    if(team2id != '') _nm['team2id'] = team2id;
    if(clubname != '') _nm['clubname'] = clubname;
    if(clubid != '') _nm['clubid'] = clubid;
    _nm['custom'] = clubname+','+clubid+','+team1+','+team1id+','+team2+','+team2id;

    player.addEventListener('play', (event) => nm_actionws('play', player.currentTime))
    player.addEventListener('pause', (event) => nm_actionws('pause', player.currentTime))
    player.addEventListener('ended', (event) => nm_actionws('ended', player.currentTime))
    player.addEventListener('seeked', (event) => nm_actionws('seeked', player.currentTime))
}

function calcTime(offset) {
    d = new Date();

    utc = d.getTime() + (d.getTimezoneOffset() * 60000);

    nd = new Date(utc + (3600000 * offset));

    return nd;
}

function getTinsec(id) {
    var n = $('#' + id).html();
    var z = String(n).split(':');
    var t = 0;
    if (z.length == 2) {
        t = (Number(z[0]) * 60) + Number(z[1]);
    } else if (z.length == 3) {
        t = (Number(z[0]) * 60 * 60) + Number(z[1] * 60) + Number(z[2]);
    }
    return t;
}

function getSecondsInt(val) {
    var n = val;
    var z = String(n).split(':');
    var t = 0;
    if (z.length == 2) {
        t = (Number(z[0]) * 60) + Number(z[1]);
    } else if (z.length == 3) {
        t = (Number(z[0]) * 60 * 60) + Number(z[1] * 60) + Number(z[2]);
    }
    return t;
}

function insertParam(key, value) {
    key = encodeURI(key);
    value = encodeURI(value);

    var kvp = document.location.search.substr(1).split('&');

    var i = kvp.length;
    var x;
    while (i--) {
        x = kvp[i].split('=');

        if (x[0] == key) {
            x[1] = value;
            kvp[i] = x.join('=');
            break;
        }
    }

    if (i < 0) {
        kvp[kvp.length] = [key, value].join('=');
    }

    //this will reload the page, it's likely better to store this until finished
    return kvp.join('&');
}

function setScore(eid) {
    $.post('/act.php?act=chkscore', {eid: eid}, function (rez) {
        if (rez.result == "ok") {
            $('.timeout1').removeClass('s1').removeClass('s2').removeClass('s3').removeClass('s4').addClass('s' + rez.to1);
            $('.timeout2').removeClass('s1').removeClass('s2').removeClass('s3').removeClass('s4').addClass('s' + rez.to2);
            $('.score1').html(rez.s1);
            $('.score2').html(rez.s2);
            $('.smsc1').html(rez.s1);
            $('.smsc2').html(rez.s2);
            $('.center_dataview_first').html(rez.n);
            if (rez.timesh == 'no') {
                $('#view_timeprod2').hide();
                $('#dashqq').hide();
            } else {
                $('#view_timeprod2').show();
                if ($('#view_timeq').html() != '') $('#dashqq').show();
            }
            if (rez.smb == 'no') {
                $('.small_board').hide();
            } else {
                $('.small_board').show();
            }
            if (rez.qtt == 'none') {
                $('#view_timeq').html('');
                $('#dashqq').hide();
            } else {
                $('#view_timeq').html(rez.qtt);
                if ($('#view_timeprod2').html() != '' && $('#view_timeprod2').is(":visible")) $('#dashqq').show();
            }
            if (rez.lgon == 'no') {
                $('#logoischain').hide();
            } else {
                $('#logoischain').show();
            }
            if (rez.flg == "off") $('#flagextra').hide();
            else if (rez.flg == "on") $('#flagextra').show();
            if (rez.x45 != '') offset = rez.x45;
            if (rez.prodon == 'no') $('.score_board').hide();
            else $('.score_board').show();
        }
    }, 'json')
}

function setScore2(eid, dif) {
    $.post('/act.php?act=chkscore2', {eid: eid, dif: dif}, function (rez) {
        if (rez.result == "ok") {
            $('.timeout1').removeClass('s1').removeClass('s2').removeClass('s3').removeClass('s4').addClass('s' + rez.to1);
            $('.timeout2').removeClass('s1').removeClass('s2').removeClass('s3').removeClass('s4').addClass('s' + rez.to2);
            $('.score1').html(rez.s1);
            $('.score2').html(rez.s2);
            $('.smsc1').html(rez.s1);
            $('.smsc2').html(rez.s2);
            $('.center_dataview_first').html(rez.n);
            if (rez.timesh == 'no') {
                $('#view_timeprod2').hide();
                $('#dashqq').hide();
            } else {
                $('#view_timeprod2').show();
                if ($('#view_timeq').html() != '') $('#dashqq').show();
            }
            if (rez.smb == 'no') {
                $('.small_board').hide();
            } else {
                $('.small_board').show();
            }
            if (rez.qtt == 'none') {
                $('#view_timeq').html('');
                $('#dashqq').hide();
            } else {
                $('#view_timeq').html(rez.qtt);
                if ($('#view_timeprod2').html() != '' && $('#view_timeprod2').is(":visible")) $('#dashqq').show();
            }
            if (rez.lgon == 'no') {
                $('#logoischain').hide();
            } else {
                $('#logoischain').show();
            }
            if (rez.flg == "off") $('#flagextra').hide();
            else if (rez.flg == "on") $('#flagextra').show();
            if (rez.x45 != '') offset = rez.x45;
            if (rez.prodon == 'no') $('.score_board').hide();
            else $('.score_board').show();
        }
    }, 'json')
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
        var end = document.cookie.indexOf(";", begin);
        if (end == -1) {
            end = dc.length;
        }
    }
    // because unescape has been deprecated, replaced with decodeURI
    //return unescape(dc.substring(begin + prefix.length, end));
    return decodeURI(dc.substring(begin + prefix.length, end));
}

function restoreindex(s) {
    if (s === undefined) s = 0;
    if (s == 3) {
        $('.dologgin').click();
    }
    window.history.pushState({}, '', 'index.php');
}

function hasUpperCase(str) {
    return (/[A-Z]/.test(str));
}

function openVid(id, w) {
    if (w == undefined || isNaN(parseInt(w))) w = 0;
    var ob = {id: id, w: w};
    let oldVideos = document.querySelectorAll(".video-js video");
    if (oldVideos.length > 0) {
        oldVideos.forEach((elem) => {
            videojs(elem).pause();
            videojs(elem).dispose();
        })
    }
    $('#openVideo .modal-content').html("");
    $.post('/act.php?act=requestVidCode', ob, function (rez) {
        if ($('#video_ilive video').length > 0) {
            if ($('#video_ilive video')[0].currentTime > 0) $('#video_ilive video')[0].pause();
        }
        $('#openVideo .modal-content').html(rez);
        $('#openVideo').modal('show');

        let helloD = $('#openVideo .modal-content .video-hello-data');
        let folder = 0;

        if (helloD.length) {
            folder = (helloD.attr('data-type') === 'playlist') ? helloD.attr('data-folc-id') : 0;
        }

        setTimeout(() => {
            wow($('#openVideo div.video-js'), {
                videoId: id,
                live: 0,
                playlist: folder,
                isWaitUser: false
            });
        }, 1000);

        if (w > 0) {
            var nrmin = parseInt($('.user_notif .nr').html()) - 1;
            if (nrmin < 1) {
                $('.user_notif .nr').html(0).hide();
            } else {
                $('.user_notif .nr').html(nrmin);
            }
            loadnotifs_startrutine();
        }
    }, 'html');
}

function openEvt(id, w, n) {
    if (w == undefined || isNaN(parseInt(w))) w = 0;
    if(n == undefined || n === "") n = 'no';
    var ob = {id: id, w: w, n:n};
    $.post('/act.php?act=requestEvtCode', ob, function (rez) {
        $('#openEvt .modal-content').html(rez);
        $('#openEvt').modal('show');
        if (w > 0) {
            var nrmin = parseInt($('.user_notif .nr').html()) - 1;
            if (nrmin < 1) {
                $('.user_notif .nr').html(0).hide();
            } else {
                $('.user_notif .nr').html(nrmin);
            }
            loadnotifs_startrutine();
        }
    }, 'html');
}

let waitTimeout;
const comingSoon = (id, ms, club) => {
    return;
    if (waitTimeout) {
        window.clearTimeout(waitTimeout);
    }

    checkAvailableAlready(id, true, club);


    $('.left_evtmod').addClass('video-js');

    waitTimeout = setTimeout(() => {
        $('.left_evtmod').addClass('video-js');

        if (ms) {
            setTimeout(() => {
                document.dispatchEvent(new CustomEvent("kill:wow", {}));
            }, ms);
        }

        if (ms <= 0) {
            checkAvailableAlready(id, true, club)
        }

        wow($('.left_evtmod'), {
            videoId: id,
            live: id,
            playlist: 0,
            isWaitUser: true
        });
    }, 2000);
};

let waitInterval;
const checkAvailableAlready = (id, isModal = true, club) => {
    console.log("check avail");
    if (waitInterval) {
        window.clearInterval(waitInterval);
    }

    waitInterval = setInterval(async () => {
        const payload = await fetch(`/hellos.php?act=event-went-live&event=${id}`)
            .then(res => res.json())
            .then(result => result)
            .catch(err => err);

        if (payload.success) {

            if (window.location.pathname === '/index.php') {
                window.location.href = `/club.php?c=${club}&trigger_event=${id}&${isModal ? '&modal=yes' : ''}`;
                return;
            }

            if (window.location.pathname === '/liveevt.php') {
                window.location.reload();
            }

            let url = window.location.href;
            if (url.indexOf('?') > -1) {
                url += `&trigger_event=${id}${isModal ? '&modal=yes' : ''}`
            } else {
                url += `?trigger_event=${id}${isModal ? '&modal=yes' : ''}`
            }
            window.location.href = url;
        }
    }, 15000);
};

function openLiveEvt(id, w, t, n) {
    var $iframe = $('#myliveevent');
    if(n == undefined) n = 'no';
    $iframe.attr('src', '/liveevt'+((t == 'yes') ? '2' : '')+'.php?e=' + w + '&ide=' + id + '&dr=1&bg=0&isFrame=1&isaff='+n);
    $('#iframeliveevt').modal('show');
}

function playingVideo(id) {
    $.post('/act.php?act=sp', {id: id}, function (rez) {
        //
    }, 'json');
}

function delfc(id) {
    $.post('/act.php?act=delfcnt', {id: id}, function (rez) {
        if (rez.result == 'ok') {
            swal({type: 'success', text: rez.msg}).then((result) => {
                if (result.value) {
                    window.location.reload();
                }
            });
        }
    }, 'json');
}

function deladmc(id) {
    $.post('/act.php?act=deladmcnt', {id: id}, function (rez) {
        if (rez.result == 'ok') {
            swal({type: 'success', text: rez.msg}).then((result) => {
                if (result.value) {
                    window.location.reload();
                }
            });
        }
    }, 'json');
}

function delvd(id) {
    $.post('/act.php?act=delvId', {id: id}, function (rez) {
        if (rez.result == 'ok') {
            swal({type: 'success', text: rez.msg}).then((result) => {
                if (result.value) {
                    window.location.reload();
                }
            });
        }
    }, 'json');
}

function deled(id) {
    $.post('/act.php?act=deleId', {id: id}, function (rez) {
        if (rez.result == 'ok') {
            swal({type: 'success', text: rez.msg}).then((result) => {
                if (result.value) {
                    window.location.reload();
                }
            });
        }
    }, 'json');
}

function ClearAllNotifs() {
    $.post('/act.php?act=markasreadn', {d: 1}, function (re) {
        if (re.result == 'ok') {
            $('.user_notif .nr').html('0').hide();
            $('#mynotifs_content .item').removeClass('unread');
        }
    }, 'json');

}

function callStats(id) {
    $.post('/act.php?act=logstat', {eid: id}, function (re) {
        if (re.result == 'ok') {
            console.log('ok')
        } else console.log('bad');
    }, 'json');
}

function uploadFiles(event) {
    event.stopPropagation(); // Stop stuff happening
    event.preventDefault(); // Totally stop stuff happening

    // START A LOADING SPINNER HERE
    // Create a formdata object and add the files
    var data = new FormData();
    $.each(files, function (key, value) {
        data.append("fisier", value);
    });
    data.append("ev_club", $('#ev_club').val());
    data.append("evt-nameen", $('#evt-nameen').val());
    data.append("evt-descren", $('#evt-descren').val());
    data.append("evt-namefr", $('#evt-namefr').val());
    data.append("evt-descrfr", $('#evt-descrfr').val());
    data.append("evt-cat", $('#evt-cat').val());
    data.append("evt-date", $('#evt-date').val());
    data.append("evt-key", $('#evt-key').val());

    $.ajax({
        url: '/act.php?act=add_evt',
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function (data, textStatus, jqXHR) {
            if (data.result == "ok") {
                swal({type: 'success', text: data.msg}).then((result) => {
                    if (result.value) {
                        window.location.reload();
                    }
                });
            } else {
                swal({type: 'error', text: data.msg});
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // Handle errors here
            console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });
}

function uploadFiles3(event) {
    event.stopPropagation(); // Stop stuff happening
    event.preventDefault(); // Totally stop stuff happening

    // START A LOADING SPINNER HERE
    // Create a formdata object and add the files
    var data = new FormData();

    $.each(files3, function (key, value) {
        data.append("fisier", value);
    });
    data.append("ev_club", $('#ev_clube').val());
    data.append("ev_id", $('#evide').val());
    data.append("evt-nameen", $('#evt-nameene').val());
    data.append("evt-descren", $('#evt-descrene').val());
    data.append("evt-namefr", $('#evt-namefre').val());
    data.append("evt-descrfr", $('#evt-descrfre').val());
    data.append("evt-cat", $('#evt-cate').val());
    data.append("evt-date", $('#evt-datee').val());
    data.append("evt-key", $('#evt-keye').val());

    $.ajax({
        url: '/act.php?act=edit_evt',
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function (data, textStatus, jqXHR) {
            if (data.result == "ok") {
                swal({type: 'success', text: data.msg}).then((result) => {
                    if (result.value) {
                        window.location.reload();
                    }
                });
            } else {
                swal({type: 'error', text: data.msg});
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // Handle errors here
            //console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });
}

function uploadFiles2(event) {
    event.stopPropagation(); // Stop stuff happening
    event.preventDefault(); // Totally stop stuff happening

    // START A LOADING SPINNER HERE
    // Create a formdata object and add the files
    var data = new FormData();
    $.each(files2, function (key, value) {
        data.append("fisier", value);
    });
    data.append("clbid", $('#vid_club').val());
    data.append("name", $('#video-name').val());
    data.append("descr", $('#video-descr').val());
    data.append("folid", $('#video-folder').val());
    data.append("tim", $('#video-time').val());
    data.append("views", $('#video-views').val());
    data.append("vurl", $('#video-url').val());
    data.append("chbig", $('#video-chbig').val());

    $.ajax({
        url: '/act.php?act=addvint',
        type: 'POST',
        data: data,
        cache: false,
        dataType: 'json',
        processData: false, // Don't process the files
        contentType: false, // Set content type to false as jQuery will tell the server its a query string request
        success: function (data, textStatus, jqXHR) {
            if (data.result == "ok") {
                swal({type: 'success', text: data.msg}).then((result) => {
                    if (result.value) {
                        window.location.reload();
                    }
                });
            } else {
                swal({type: 'error', text: data.msg});
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // Handle errors here
            //console.log('ERRORS: ' + textStatus);
            // STOP LOADING SPINNER
        }
    });
}

function returnuservalid(re) {
    validuser = re;
}

function returnmailvalid(re) {
    validemail = re;
}

function checkusername(usr) {
    $.post('/act.php?act=checkusrn&t=' + Math.random(), {usr: usr}, function (rez) {
        if (rez.result == 'ok') {
            returnuservalid(rez.answer);
        }
    }, 'json');
}

function checkemail(em) {
    $.post('/act.php?act=checkmail&t=' + Math.random(), {em: em}, function (rez) {
        if (rez.result == 'ok') {
            returnmailvalid(rez.answer);
        }
    }, 'json');
}

async function doconfacc(e) {
    e.preventDefault();
    $('#parameters').removeAttr('tabindex');
    var msgt = $('#dodelacc').data('mttl');
    var msgp = $('#dodelacc').data('ppl');
    var msge = $('#dodelacc').data('ems');
    var patt = new RegExp("^(?=.*[A-Z])[a-zA-Z0-9\!\@\#\$\%\^\.\&\*\(\)\_\+]{8,}$");
    const {value: mypass} = await Swal({
        title: msgt,
        type: "question",
        input: 'password',
        inputPlaceholder: msgp,
        showCancelButton: true,
        inputValidator: (value) => {
            return new Promise((resolve) => {
                if (patt.test(value)) {
                    resolve()
                } else {
                    resolve(msge)
                }
            })
        }
    })

    if (mypass) {
        var dd = $('#dodelacc').data('key');
        $.post("https://file.mytvchain.com/process/dodela.php?a=ck", {d: dd, p: mypass}, function (re) {
            var succmsg = $('#dodelacc').data('succmsg');
            if (re.result == "more") {
                clearInterval(notintid);
                var msgx = String($('#dodelacc').data('xmsg')).replace('%tmpl1%', re.num).replace('%tmpl2%', re.clubs);
                var confbtnrm = $('#dodelacc').data('cnfbtn1');
                Swal({
                    text: msgx,
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: confbtnrm
                }).then((result) => {
                    if (result.value) {
                        $.post("https://file.mytvchain.com/process/dodela.php?a=k", {d: dd, p: mypass}, function (re) {
                            if (re.result == "ok") {
                                $.post('/act.php?act=logout', {}, function (re) {
                                    swal(succmsg);
                                    window.location.href = window.location.href;
                                }, 'json');
                            } else swal(msge);
                        }, "json");
                    }
                })
            } else if (re.result == "ok") {
                clearInterval(notintid);

                $.post('/act.php?act=logout', {}, function (re) {
                    swal(succmsg);
                    window.location.href = window.location.href;
                }, 'json');

            } else {
                swal(msge);
            }
        }, 'json');
    }


}

function setCookie(name, value, days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function checkevt(eid) {
    if (imloggedinsys == 1) {
        var ttl = $('#btnofevt_' + eid).data('ttl');
        var txt = $('#btnofevt_' + eid).data('question');
        var btn = $('#btnofevt_' + eid).data('btn');
        var elm = $('#btnofevt_' + eid);
        swal({
            title: ttl,
            text: txt,
            type: 'question',
            showCancelButton: true,
            confirmButtonColor: '#4726E0',
            cancelButtonColor: '#D2D2D4',
            confirmButtonText: btn
        }).then((result) => {
            if (result.value) {
                $.post('/act.php?act=notifevt', {id: eid}, function (rez) {
                    if (rez.result == 'ok') {
                        if (rez.tips == 'cancel') {
                            $('#btnofevt_' + eid).data('question', rez.txt);
                            $('#btnofevt_' + eid).data('btn', rez.btn);
                            elm.html(elm.data('cancel'));
                        } else {
                            $('#btnofevt_' + eid).data('question', rez.txt);
                            $('#btnofevt_' + eid).data('btn', rez.btn);
                            elm.html(elm.data('ok'));
                        }
                        swal({type: rez.tip, text: rez.msg});
                    } else {
                        swal({type: rez.tip, text: rez.msg});
                    }
                }, 'json');
            }
        });
    } else {
        $('#makelogin').modal('show');
    }
}

function buyTicket(eid) {
    if (imloggedinsys == 1) {
        $.post("act.php?act=checkpaidevt", {evtid: eid}, function (rez) {
            if (rez.result == "already") {
                if (rez.started == 'yes') {
                    openLiveEvt(eid, rez.clubid,rez.imalive_pub);
                } else {
                    swal({text: rez.text, type: rez.tip});
                }
            } else if (rez.result == "ask") {
                //open swall ask.
                swal({
                    title: rez.ttl,
                    text: rez.txt,
                    type: 'question',
                    showCancelButton: true,
                    confirmButtonColor: '#4726E0',
                    cancelButtonColor: '#D2D2D4',
                    confirmButtonText: rez.btn
                }).then((result) => {
                    if (result.value) {
                        $.post('act.php?act=buy-evt-ticket', {evtid: eid}, function (rasp) {
                            if (rasp.result === 'ok') {
                                if (rasp.started === 'yes') {
                                    openLiveEvt(eid, rasp.clubid,rasp.imalive_pub);
                                } else {
                                    swal({text: rasp.text, type: 'success'});
                                }
                            } else if (rasp.result === "already") {
                                if (rasp.started === 'yes') {
                                    openLiveEvt(eid, rasp.clubid,rasp.imalive_pub);
                                }
                            } else {
                                swal({text: rasp.text, type: rasp.tip});
                            }
                        }, 'json');
                    }
                });
            } else {
                swal({text: rez.message, type: "error"});
            }
        }, 'json');
    } else {
        $('#makelogin').modal('show');
    }
}

function loadnotifs_startrutine() {
    $.post('/act.php?act=checknotifs', {}, function (rez) {
        if (rez.result == 'ok') {
            if (rez.c > 0) {
                $('.nr').html(rez.c).show();
            } else $('.nr').hide();
            $('#mynotifs_content').html(rez.html);
            $('#mynotifs_content2').html(rez.html);
            if (!notintid) notintid = setInterval(loadnotifs_startrutine, 30000);
        } else if (rez.result == 'nl') {
            window.location.href = window.location.href;
            //$('#makelogin').modal('show');
        } else {
            swal({type: 'error', text: rez.msg});
        }
    }, 'json');

}

function copyvidurl() {
    var copyText = document.getElementById("copymytxtvidur");
    copyText.select();
    document.execCommand("copy");
    var mytxt = $('#copymytxtvidur').data('msg');
    swal({type: 'success', text: mytxt});
}

function copyevturl() {
    var copyText = document.getElementById("copymytxtvidur2");
    copyText.select();
    document.execCommand("copy");
    var mytxt = $('#copymytxtvidur2').data('msg');
    swal({type: 'success', text: mytxt});
}

// Grab the files and set them to our variable
function prepareUpload(event) {
    files = event.target.files;
}

function prepareUpload3(event) {
    files3 = event.target.files;
}

function prepareUpload2(event) {
    files2 = event.target.files;
}

function find_something() {

    var re = $('#search_something').val();
    var url = '/search.php?key=' + encodeURI(re).replace(".", "%2E");
    window.location.href = url;
}


var validpass = 0;
var validpasscp = 0;
var validpasscp3 = 0;
var validemail = 0;
var validuser = 0;
var clc = 0;

$(document).ready(function (e) {
    $('#openVideo').on('hidden.bs.modal', function (e) {
        let oldVideos = document.querySelectorAll(".video-js video");
        if (oldVideos.length > 0) {
            oldVideos.forEach((elem) => {
                videojs(elem).pause();
                videojs(elem).dispose();
            })
        }
        $('#openVideo .modal-content').html("");
    });
    $('body').on('click', '#sendreq', function (e) {
        e.preventDefault();
        let usrnm = $('#usernamex').val();
        let email = $('#email').val();
        let passwd = $('#passwdx').val();
        let ih18p = $('#ihave18plus').is(':checked');
        let iacccg = $('#acceptcgu').is(':checked');
        let accept_news = $('#acceptnewsletter').is(':checked') ? '1' : '0';
        //console.log(validuser);
        //checkemail(email); checkusername(usrnm);

        if (!validuser) {
            swal({type: 'error', text: $('#usernamex').data('errmsg')});
        } else if (!validemail) {
            swal({type: 'error', text: $('#email').data('errmsg')});
        } else if (validpass < 2) {
            swal({type: 'error', text: $('#passwdx').data('errmsg')});
        } else if (!ih18p) {
            swal({type: 'error', text: $('#ihave18plus').data('errmsg')});
        } else if (!iacccg) {
            swal({type: 'error', text: $('#acceptcgu').data('errmsg')});
        } else if (validemail && validuser && validpass == 2 && ih18p && iacccg) {

            $.post('/act.php?act=checklogind', {
                provider: 'mytch',
                usr: usrnm,
                email: email,
                passwd: passwd,
                accept_news: accept_news
            }, function (rez) {
                if (rez.result == "ok") {
                    $('#usernamex').val('');
                    $('#email').val('');
                    $('#passwdx').val('');
                    swal({type: 'success', text: rez.msg}).then((result) => {
                        if (result.value) {
                            window.location.reload();
                        }
                    });
                } else if (rez.result === "accal") {
                    swal({type: 'error', text: rez.msg});
                    var auth2 = gapi.auth2.getAuthInstance();
                    auth2.signOut().then(function () {
                        console.log('User signed out.');
                    });
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');

        }

    });
    if (imloggedinsys == 1) {
        var mffttl1 = $('#mytvfanspopover').data('title');
        $('#popupmytvfan[data-toggle=popover],#popupmytvfan2[data-toggle=popover]').popover({
            content: $('#mytvfanspopover').html(),
            html: true,
            placement: 'bottom',
            trigger: 'click focus',
            title: mffttl1
        }).click(function () {
            $(this).popover('show');

        });
        $('body').on('click', '.buyfansm', function (e) {
            var id = $(this).data('id');
            var v = $(this).data('value');
            if (id > 0) {
                var rew = $('.howm_' + id).html();
                var qqs = String($('#mytvfanspopover').data('question')).replace('@1@', v).replace('@2@', rew);

                swal({
                    title: qqs,
                    type: 'question',
                    showCancelButton: true,
                }).then((result) => {
                    if (result.value) {
                        $('#popupmytvfan[data-toggle=popover],#popupmytvfan2[data-toggle=popover]').popover('hide');
                        $('#dopaymentifr').html('<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button><iframe src="/act.php?act=makepayment&eid=' + id + '" name="Payment" width="100%" height="100%" style="min-height:460px;"></iframe>');
                        $('#makepaymentfans').modal('show');
                    }
                });
            }
        });

    }


    $(document).on('keyup', function (evt) {
        if (evt.keyCode == 27) {
            $('.doasearch').hide('fast');
        }
    });
    $('body').on('click', '#hidethissearchsomething', function (e) {
        e.preventDefault();
        $('.doasearch').hide('fast');
    });
    $('body').on('click', '.search_menu', function (e) {
        e.preventDefault();
        $('.doasearch').toggle('fast');
    });

    $('body').on('click', '#find_something', function (e) {
        find_something();
    });
    $('body').on('keyup', '#search_something', function (e) {
        if (e.keyCode == 13) {
            find_something();
        }
    });
    $('#iframeliveevt').on('hidden.bs.modal', function (e) {
        $('#myliveevent').prop('src', 'about:blank');
    });

    $("body").on("click", ".star", function (e) {
        e.stopImmediatePropagation();
        clc = 1;
        var n = $(this).data('note');
        var id = $(this).data('id');
        switch (n) {
            case 1:
                $('.star').removeClass('r');
                $('.star:nth-child(1)').addClass('r');
                break;
            case 2:
                $('.star').removeClass('r');
                $('.star:nth-child(1),.star:nth-child(2)').addClass('r');
                break;
            case 3:
                $('.star').removeClass('r');
                $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3)').addClass('r');
                break;
            case 4:
                $('.star').removeClass('r');
                $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4)').addClass('r');
                break;
            case 5:
                $('.star').removeClass('r');
                $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4),.star:nth-child(5)').addClass('r');
                break;
            default:
                $('.star').removeClass('r');
                break;
        }
        if (n > 0 && n < 6) {
            switch (n) {
                case 1:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1)').addClass('r');
                    $('.start_anim').removeClass('s2 s3 s4 s5').addClass('s1');
                    break;
                case 2:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2)').addClass('r');
                    $('.start_anim').removeClass('s1 s3 s4 s5').addClass('s2');
                    break;
                case 3:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s4 s5').addClass('s3');
                    break;
                case 4:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s5').addClass('s4');
                    break;
                case 5:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4),.star:nth-child(5)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s4').addClass('s5');
                    break;
                default:
                    $('.star').removeClass('r');
                    break;
            }


            var txt = $('.video_overdescription,.firstvideo').data('text');
            var ttl = $('.video_overdescription,.firstvideo').data('title');
            var btn = $('.video_overdescription,.firstvideo').data('btnname');
            if (imloggedinsys == 1) {
                swal({
                    title: ttl,
                    text: txt,
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#4726E0',
                    cancelButtonColor: '#D2D2D4',
                    confirmButtonText: btn
                }).then((result) => {
                    if (result.value) {
                        $.post('/act.php?act=ratevid', {id: id, n: n}, function (rez) {
                            if (rez.result == 'ok') {
                                $('.stars5bbl').html('<div class="blue5" style="width:' + rez.w + '"></div>');
                                $('.stars5bbl').addClass('novote');
                                clc = 0;
                            } else {
                                swal({type: 'error', text: rez.msg});
                                clc = 0;
                            }
                        }, 'json');
                    } else clc = 0;
                });
            } else {
                $('#makelogin').modal('show');
            }
        }
    });
    $("body").on("click", ".confirmdel", function (e) {
        e.preventDefault();
        var url = $(this).attr("href");
        var name = $(this).data("name");
        alertify.confirm(name, function (e) {
            if (e) {
                window.location.href = url;
            } else {
                return false;
            }
        });
    });
    $("body").on("mouseover", ".star", function (e) {
        var n = $(this).data('note');
        var tt = $(this).data('text');
        $('.text_whoo').html(tt);
        if (clc == 0) {
            switch (n) {
                case 1:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1)').addClass('r');
                    $('.start_anim').removeClass('s2 s3 s4 s5').addClass('s1');
                    break;
                case 2:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2)').addClass('r');
                    $('.start_anim').removeClass('s1 s3 s4 s5').addClass('s2');
                    break;
                case 3:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s4 s5').addClass('s3');
                    break;
                case 4:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s5').addClass('s4');
                    break;
                case 5:
                    $('.star').removeClass('r');
                    $('.star:nth-child(1),.star:nth-child(2),.star:nth-child(3),.star:nth-child(4),.star:nth-child(5)').addClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s4').addClass('s5');
                    break;
                default:
                    $('.star').removeClass('r');
                    break;
            }
        }
    });
    $("body").on("mouseout", ".star", function (e) {
        var n = $(this).data('note');
        if (clc == 0) {
            switch (n) {
                case 1:
                    $('.star:nth-child(1)').removeClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s4 s5');
                    break;
                case 2:
                    $('.start_anim').removeClass('s2 s3 s4 s5');
                    $('.star:nth-child(2)').removeClass('r');
                    break;
                case 3:
                    $('.start_anim').removeClass('s3 s4 s5');
                    $('.star:nth-child(3)').removeClass('r');
                    break;
                case 4:
                    $('.start_anim').removeClass('s4 s5');
                    $('.star:nth-child(4)').removeClass('r');
                    break;
                case 5:
                    $('.start_anim').removeClass('s5');
                    $('.star:nth-child(5)').removeClass('r');
                    break;
                default:
                    $('.star').removeClass('r');
                    $('.start_anim').removeClass('s1 s2 s3 s4 s5');
                    break;
            }
        }
    });

    $('body').on('change', '#rcvnewsletter', function (r) {
        var vv = $(this).is(':checked');
        var nsl = '0';
        if (vv) {
            nsl = '1';
        } else {
            nsl = '0';
        }
        $.post('/act.php?act=rcvnews', {n: nsl}, function (re) {
            if (re.result == 'ok') {

            } else {
                swal({type: 'error', text: rez.msg});
            }
        }, 'json');
    });
    $('body').on('change', '#emailnotifs', function (r) {
        var vv = $(this).is(':checked');
        var nsl = '0';
        if (vv) nsl = '1';
        else nsl = '0';
        $.post('/act.php?act=rcvnotifs', {n: nsl}, function (re) {
            if (re.result == 'ok') {

            } else {
                swal({type: 'error', text: rez.msg});
            }
        }, 'json');
    });
    $('body').on('change', '#rcvlivestream', function (r) {
        var vv = $(this).is(':checked');
        var nsl = '0';
        if (vv) nsl = '1';
        else nsl = '0';
        $.post('/act.php?act=rcvlivenotifs', {n: nsl}, function (re) {
            if (re.result == 'ok') {

            } else {
                swal({type: 'error', text: rez.msg});
            }
        }, 'json');
    });
    $('body').on('change', '#rcvvideonotifs', function (r) {
        var vv = $(this).is(':checked');
        var nsl = '0';
        if (vv) nsl = '1';
        else nsl = '0';
        $.post('/act.php?act=rcvvideonotifs', {n: nsl}, function (re) {
            if (re.result == 'ok') {

            } else {
                swal({type: 'error', text: rez.msg});
            }
        }, 'json');
    });

    $('body').on('click', '#dodelacc', doconfacc);

    $('body').on('click', '#sendreq2', function (e) {
        e.preventDefault();
        var chclubname = $('#chclubname').val();
        var email = $('#emailch').val();
        var phoneno = $('#chphoneno').val();
        var chfullnom = $('#chfullnom').val();
        var chcoutnry = $('#countrych').val();
        var chlien = $('#liench').val();
        var msgch = $('#msgch').val();
        var chch = $('#chch').val();
        var chex = $('#chex').val();

        if (chclubname != '' && chcoutnry != '' && chlien != '' && validateEmail(email) && chfullnom != '' && phoneno != '' && msgch != '' && chch != '') {

            $.post('/act.php?act=requestchannelweb', {
                fullname: chfullnom,
                clubname: chclubname,
                email: email,
                details: msgch,
                phoneno: phoneno,
                chlien: chlien,
                chcoutnry: chcoutnry,
                chch: chch,
                chex: chex
            }, function (rez) {
                if (rez.result == "ok") {
                    $('#chclubname').val('');
                    $('#emailch').val('');
                    $('#chfullnom').val('');
                    $('#msgch').val('');
                    $('#chphoneno').val('');
                    $('#countrych').val('');
                    $('#liench').val('');
                    $('#chch').val('');
                    swal({type: 'success', text: rez.msg});
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');

        } else {
            var mm = $('#requestnewchannel2').data('errmsg');
            swal({type: 'error', text: mm});
        }

    });
    $('body').on('keyup', '#passwdx', function (e) {
        var x = $(this).val();
        if (hasUpperCase(x)) {
            validpass = 1
        }
        if (x.length > 7 && hasUpperCase(x)) {
            validpass = 2;
        }
    });
    $('body').on('keyup', '#npass', function (e) {
        var x = $(this).val();
        if (hasUpperCase(x)) {
            validpasscp = 1;
            $('#majcond').removeClass('uncheck').addClass('check');
        } else {
            $('#majcond').removeClass('check').addClass('uncheck');
        }
        if (x.length > 7) {
            $('#min8cond').removeClass('uncheck').addClass('check');
        } else {
            $('#min8cond').removeClass('check').addClass('uncheck');
        }
        if (x.length > 7 && hasUpperCase(x)) {
            validpasscp = 2;
        } else {
            validpasscp = 0;
        }
    });

    $('body').on('click', '#uploadnewimgavatar', function (e) {
        $('#uploadifive-uploadavatar_container').find('input').last().click();
    });

    $('#sendcontactmsg').on('show.bs.modal', function (e) {
        if ($(window).width() > 1000) {
            $('#sendcontactmsg .close').hide();
        } else if ($(window).width() < 1001) {
            $('#menu_left_mobile').click();
        }
    });
    $('#parameters').on('show.bs.modal', function (e) {
        if ($(window).width() < 1001) {
            $('#menu_left_mobile').click();
        }
    });
    $('#makelogin').on('show.bs.modal', function (e) {
        if ($(window).width() < 1001) {
            $('#menu_left_mobile').click();
        }
    });
    $('#requestnewchannel').on('show.bs.modal', function (e) {
        if ($(window).width() < 1001) {
            $('#menu_left_mobile').click();
        }
    });
    $('body').on('change', '#spf_incats', function (e) {
        $('#videosearch').keyup();
    });
    $('body').on('keyup', '#videosearch', function (e) {
        var l = $(this).val();
        var id = $(this).data('id');
        var es = parseInt($("#videosearch").data("n"));
        var zzn = parseInt($("#videosearch").data("sec"));
        if (id > 0) {
            var elem = {cid: id, v: encodeURIComponent(l), es: es, zzn: 0};
            if ($('#spf_incats').length > 0) {
                var vid_cat = $('#spf_incats').val();
                elem = {cid: id, v: encodeURIComponent(l), vid_cat: vid_cat, es: es, zzn: 0};
            }
            if (zzn == 1) {
                elem.zzn = 1;
            }
            $.post('/act.php?act=vidsearch', elem, function (rez) {
                if (rez.num > 4) {
                    $('#idsffv').show();
                } else {
                    $('#idsffv').hide();
                }
                $('#vid_search').html(rez.html);
            }, 'json');
        } else {
            $('#vid_search').html('');
            $('#idsffv').hide();
        }
    });

    $('body').on('click', '#recover_passbtn', function (e) {
        e.preventDefault();
        var elm = $('#usrormailrp').val();
        if (elm != '' && String(elm).length > 1) {
            $.post('/act.php?act=checkaccount', {em: elm}, function (rez) {
                if (rez.result == 'ok') {
                    $('#step1rp').hide('fast');
                    $('#keysrp').val(rez.id);
                    $('.input-surfaceek').find('span').html(rez.mail);
                    $('#step2rp').show('fast');
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        }
    });

    $('body').on('click', '#recover_pass2', function (e) {
        e.preventDefault();
        var elm = $('#keysrp').val();
        if (elm > 0) {
            $.post('/act.php?act=generatemail', {em: elm}, function (rez) {
                if (rez.result == 'ok') {
                    $('#recover_pass').modal('hide');
                    swal({type: 'success', text: rez.msg});
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        }
    });

    $("body").on("keyup", "#accmodadm_em", function (r) {
        var tt = $(this).val();
        var ttic = $("#adm_clubid").val();
        if (tt.length > 0) {
            $.post('/act.php?act=chkemi', {clbid: ttic, w: tt}, function (rez) {
                if (rez.length > 0) {
                    $('.acc_modemail').html(rez).show();
                }
            }, 'html');

        }
    });

    $("body").on("click", ".emtip", function (r) {
        var em = $(this).data('mail');
        if (em != '') {
            $('#accmodadm_em').val(em);
            $('.acc_modemail').html('').hide();
        }
    });

    $("body").on("click", "#addnewadminaccmod", function (r) {
        var em = $('#accmodadm_em').val();
        var clbid = $("#adm_clubid").val();
        var tp = $('#accmodadm_tp').val();
        if (validateEmail(em) && clbid > 0 && tp != '') {
            $.post('/act.php?act=updlink', {em: em, clbid: clbid, tp: tp}, function (rez) {
                if (rez.result == 'ok') {
                    swal({type: 'success', text: rez.msg}).then((resu) => {
                        window.location.reload();
                    });
                } else {
                    swal({type: 'error', text: rez.msg});
                }

            }, 'json');

        }
    });

    $("body").on("click", "#createwithdrawbtn", function (r) {
        var em = $('#adm_cw_val').val();
        var clbid = $("#adm_clubidwd").val();
        var tp = $('#adm_cw_descr').val();
        if (clbid > 0 && parseInt(em) > 0) {
            $.post('/act.php?act=withdraw', {em: em, clbid: clbid, tp: tp}, function (rez) {
                if (rez.result == 'ok') {
                    swal({type: 'success', text: rez.msg}).then((resu) => {
                        window.location.reload();
                    });
                } else {
                    swal({type: 'error', text: rez.msg});
                }

            }, 'json');
        } else {
            swal({type: 'error', text: "Withdraw value must be greather than 0 !"});
        }
    });


    $('body').on('click', '.dissmissalerter', function (e) {
        e.preventDefault();
        $('.alerter').hide();
    });

    $('body').on('keyup', '#chpass1', function (e) {
        var x = $(this).val();
        if (hasUpperCase(x)) {
            validpasscp3 = 1;
            $('#majcond2').removeClass('uncheck').addClass('check');
        } else {
            $('#majcond2').removeClass('check').addClass('uncheck');
        }
        if (x.length > 7) {
            $('#min8cond2').removeClass('uncheck').addClass('check');
        } else {
            $('#min8cond2').removeClass('check').addClass('uncheck');
        }
        if (x.length > 7 && hasUpperCase(x)) {
            validpasscp3 = 2;
        } else {
            validpasscp3 = 0;
        }
    });

    $('body').on('click', '#recover_passbtn3', function (e) {
        e.preventDefault();
        var elm = $('#codchp').val();
        var errmsg2 = $('#recover_passrp2').data('errmsg');
        var chp1 = $('#chpass1').val();
        var chp2 = $('#chpass2').val();
        if (elm.length == 32 && validpasscp3 == 2 && chp1 == chp2) {
            $.post('/act.php?act=changepasswithcode', {em: elm, chp1: chp1, chp2: chp2}, function (rez) {
                if (rez.result == 'ok') {
                    $('#recover_passrp2').modal('hide');
                    swal({type: 'success', text: rez.msg}).then((resu) => {
                        window.location.href = 'index.php';
                    });
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        } else {
            swal({type: 'error', text: errmsg2});
        }
    });

    $('body').on('click', '.input-surfaceek', function () {
        $('.input-surfaceek').addClass('issel');
    });

    $('#recover_pass').on('show.bs.modal', function (e) {
        $('#usrormailrp').val('');
        $('#step1rp').show();
        $('#step2rp').hide();
    });


    $('body').on('click', '.dofollow', function (e) {
        var id = $(this).data('id');
        var btntxt = $(this).data('unfollow');
        var elm = $(this);
        if (id > 0) {
            $.post('/act.php?act=dofoll', {cid: id}, function (rez) {
                if (rez.result == 'ok') {
                    $('#ni_fls').html(rez.n);
                    elm.addClass('unfollow').removeClass('dofollow').html(btntxt);
                } else if (rez.result == 'nl') {
                    $('#makelogin').modal('show');
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        }
    });

    $('body').on('click', '.unfollow', function (e) {
        var id = $(this).data('id');
        var questiontitle = $(this).data('ttl');
        var question = $(this).data('question');
        var btntxt = $(this).data('follow');
        var btnctxt = $(this).data('unfoll');
        var elm = $(this);
        swal({
            title: questiontitle,
            text: question,
            type: 'question',
            showCancelButton: true,
            confirmButtonText: btnctxt
        }).then((result) => {
            if (result.value) {
                if (id > 0) {
                    $.post('/act.php?act=dounfoll', {cid: id}, function (rez) {
                        if (rez.result == 'ok') {
                            $('#ni_fls').html(rez.n);
                            elm.addClass('dofollow').removeClass('unfollow').html(btntxt);
                        } else {
                            swal({type: 'error', text: rez.msg});
                        }
                    }, 'json');
                }
            }
        });
    });

    $('body').on('click', '.user_notif', function (e) {
        e.preventDefault();
        $('#mynotifs_popover').toggle('fast');
    });
    $('body').on('click', '#rightnotificon', function (e) {
        e.preventDefault();
        $('#mynotifs_popover2').show('fast');
    });
    $('body').on('click', '#pop_arrow2', function () {
        $('#mynotifs_popover2').hide('fast');
    });
    $('body').on('click', '#leftmenuicon', function (re) {
        re.preventDefault();
        $('body').addClass('mopen');
        $('#menu_left_mobile').addClass('open');
    });
    $('body').on('click', '#menu_left_mobile', function (re) {
        if ($(re.target).prop('id') == 'menu_left_mobile') {
            re.preventDefault();
            $('#menu_left_mobile').removeClass('open');
            $('body').removeClass('mopen');
        }
    });
    $('body').on('click', '#saveitsetssecurite', function (e) {
        var npass = $('#npass').val();
        var cpass = $('#cpass').val();
        if (npass.length > 7 && hasUpperCase(npass)) {
            validpasscp = 2;
        }
        if (validpasscp == 2 && cpass != '' && cpass.length > 6) {
            $.post('/act.php?act=chpass', {npass: npass, cpass: cpass}, function (rez) {
                if (rez.result == "ok") {
                    swal({type: 'success', text: rez.msg}).then((result) => {
                        if (result.value) {
                            window.location.reload();
                        }
                    });
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        }

    });

    $('body').on('keyup', '#email', function (e) {
        var r = $(this).val();
        checkemail(r);
    });
    $('body').on('keyup', '#usernamex', function (e) {
        var r2 = $(this).val();
        checkusername(r2);
    });

    $('#requestnewchannel').on('show.bs.modal', function (e) {
        $('#makelogin').modal('hide');
        $('#requestnewchannel2').modal('hide');
        $('body').addClass('modal-open');
    });
    $('#makelogin').on('show.bs.modal', function (e) {
        $('#requestnewchannel').modal('hide');
        $('#requestnewchannel2').modal('hide');
        $('body').addClass('modal-open');
    });
    $('#requestnewchannel2').on('show.bs.modal', function (e) {
        $('#makelogin').modal('hide');
        $('#requestnewchannel').modal('hide');
        $('body').addClass('modal-open');
    });
    $('#requestnewchannel2,#makelogin,#requestnewchannel').on('shown.bs.modal', function (e) {
        $('body').addClass('modal-open');
    });
    //
    $('body').on('keyup', '#lpasswd,#nmormail', function (e) {
        if (e.keyCode === 13) {
            $('#login_btn').click();
        }
    });


    $('body').on('click', '#login_btn', function (e) {
        e.preventDefault();
        var nmormail = $('#nmormail').val();
        var pass = $('#lpasswd').val();
        var rmb = parseInt(($('#loginrmbr').is(":checked") ? 1 : 0));
        if (nmormail !== '' && pass !== '') {
            $.post('/act.php?act=checklogind', {provider: 'wlo', usr: nmormail, pass: pass, rmb: rmb}, function (rez) {
                if (rez.result === "ok") {
                    window.location.href = String(window.location.href).replace('lang=', 'oll=').replace('#', '');
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');

        } else {
            var errmsg = $('#nmormail').data('emsg');
            swal({type: 'error', text: rez.msg});
        }

    });
    $('body').on('click', function (e) {
        if (!$('#mynotifs_popover').is(e.target) && $('#mynotifs_popover').has(e.target).length === 0 && $('#mynotifs_popover').has(e.target).length === 0 && !$('.user_notif').is(e.target) && $('.user_notif').has(e.target).length === 0 && $('#mynotifs_popover').is(':visible')) {
            $('#mynotifs_popover').hide('fast');
        }
        $('[data-toggle="popover"]').each(function () {
            if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
            }
        });
    });
    $('body').on('click', '#sendcreq', function (e) {
        e.preventDefault();
        var fullname = $('#ctfn').val();
        var email = $('#ctmail').val();
        var obj = $('#obj').val();
        var serv = $('#serv').val();
        var details = $('#cdetails').val();
        var chch = $('#chchk1').val();
        var chex = $('#chex').val();
        var errmsg = $('#sendcreq').data('errmsg');
        //console.log(chch);

        if (fullname != '' && details != '' && validateEmail(email) && obj != '' && serv != '' && chch != '') {

            $.post('/act.php?act=sendcontact', {
                'fullname': fullname,
                'email': email,
                'details': details,
                'obj': obj,
                'serv': serv,
                'chch': chch,
                'chex': chex
            }, function (rez) {
                if (rez.result == "ok") {
                    $('#ctfn').val('');
                    $('#ctmail').val('');
                    $('#cdetails').val('');
                    $('#obj').val('');
                    $('#serv').val('');
                    $('#chch').val('');
                    $('#sendcontactmsg').modal('hide');
                    swal({type: 'success', text: rez.msg});
                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');

        } else {
            swal({type: 'error', text: errmsg});
        }

    });

    $('body').on('click', '.embed', function (e) {
        e.preventDefault();

        var shid = $(this).data('id');

        $('#copyembed').val('<iframe frameborder="0" width="480" height="270" src="https://mytvchain.com/videoe.php?vID=' + shid + '" allowfullscreen="" allow="autoplay"></iframe></textarea>')

        $('#embedmodal').modal('show');
    });

    var clipb211 = new ClipboardJS('#copyxtextx211m');

    clipb211.on('success', function (e) {
        swal({type: 'success', text: "Code copied to your clipboard"});
        $('#embedmodal .close').click();
        e.clearSelection();
    });

    clipb211.on('error', function (e) {
        console.error('Action:', e.action);
        console.error('Trigger:', e.trigger);
    });

    $('body').on('click', '.copytextembed', function (e) {
        e.preventDefault();
        var eltxt = $('.copytextembedtxt')[0];
        eltxt.focus();
        eltxt.select();
        try {
            var successful = document.execCommand('copy');
            var msg = successful ? 'successful' : 'unsuccessful';
            console.log('Fallback: Copying text command was ' + msg);
        } catch (err) {
            console.error('Fallback: Oops, unable to copy', err);
        }

    });

    $('body').on('click', '#dologout,#dologout2', function (e) {
        e.preventDefault();
        $.post('/act.php?act=logout', {}, function (rez) {
            if (rez.result == 'ok') {
                if (getCookie('gcrt') !== null) {
                    dogglout();
                }
                FB.getLoginStatus(function (response) {
                    if (response.status === 'connected') {
                        FB.logout(function (response) {
                            //console.log('User signed out fb.');
                        });
                    }
                });

                window.location.href = 'index.php';
            }
        }, 'json');
    });

    $('body').on('click', '#saveitsetscompte', function (e) {
        e.preventDefault();
        var prenom = $('#pre_nom').val();
        var lastname = $('#last_nom').val();
        var username = $('#user_name').val();
        var user_mail = $('#user_mail').val();
        $.post('/act.php?act=savedata', {
            prenom: prenom,
            lastname: lastname,
            username: username,
            mail: user_mail
        }, function (rez) {
            if (rez.result == "ok") {
                swal({type: 'success', text: rez.msg});
            } else {
                swal({type: 'error', text: rez.msg});
            }
        }, 'json');

    });

    $('body').on('click', '.modaledit', function (e) {
        e.preventDefault();
        let id = $(this).data('id');
        $('.popover').hide();
        $.post('/act.php?act=getfcnta', {id: id}, function (rez) {

            if (rez.result === 'ok') {
                $('#folder-id').val(rez.folc_id);
                $('#folder-name2').val(rez.folc_name);
                $('#folder-descr2').val(rez.folc_shortdescr);
                $('#folder-order2').val(rez.folc_order);
                $('#show_site2').prop("checked", rez.folc_show === '1');
                $('#show_sef2').prop("checked", rez.folc_show_sef === '1');
                $('#editfolderc').modal('show');
            }
        }, 'json');
    });


    $('body').on('click', '.menu_param .menu_item', function (e) {
        e.preventDefault();
        var dopen = $(this).data('open');
        if (dopen == '#compte_p') {

            $(dopen).show('fast');
            $('#securite_p').hide('fast');
            $('#notifs_p').hide('fast');
            $('#mystats_p').hide('fast');
            $('#trans_p').hide('fast');
        } else if (dopen == '#securite_p') {
            $(dopen).show('fast');
            $('#compte_p').hide('fast');
            $('#notifs_p').hide('fast');
            $('#mystats_p').hide('fast');
            $('#trans_p').hide('fast');
        } else if (dopen == '#notifs_p') {
            $(dopen).show('fast');
            $('#securite_p').hide('fast');
            $('#compte_p').hide('fast');
            $('#mystats_p').hide('fast');
            $('#trans_p').hide('fast');
        } else if (dopen == '#trans_p') {
            $(dopen).show('fast');
            $('#securite_p').hide('fast');
            $('#compte_p').hide('fast');
            $('#mystats_p').hide('fast');
            $('#notifs_p').hide('fast');
            $('#trans_cntt1').load('act.php?act=gettrans');
        } else if (dopen == '#mystats_p') {
            var s = $('#mystats_p').data('code');

            $.post('https://stats.mytvchain.com/actions.php', {
                act: 'gettotals',
                extra: 'chain' + s + 'chain'
            }, function (rez) {
                if (re != 0) {
                    var re = $('#mystats_p').data('lp2p');
                    var re1 = $('#mystats_p').data('upload');
                    var re2 = $('#mystats_p').data('down');
                    var re3 = $('#mystats_p').data('mo');
                    $('#stat_table').remove();
                    var tohtml = String(rez).replace('[P2P]', re).replace('[UPL]', re1).replace('[DLD]', re2).replace('[MO]', re3).replace('[MO]', re3).replace('[MO]', re3);
                    //console.log(tohtml);
                    $('#mystats_p').append(tohtml);
                }
            }, 'html');

            $(dopen).show('fast');
            $('#securite_p').hide('fast');
            $('#compte_p').hide('fast');
            $('#notifs_p').hide('fast');
            $('#trans_p').hide('fast');


        }
        $('.menu_param .menu_item').removeClass('sel');
        $(this).addClass('sel');
    });

    $('body').on('click', '.modalvidedit', function (e) {
        e.preventDefault();
        var id = $(this).data('id');
        $.post('/act.php?act=getvidcdta', {id: id}, function (rez) {
            if (rez.result == 'ok') {
                $('#vid_id').val(rez.vid_id);
                $('#video-name2').val(rez.vid_name);
                $('#video-descr2').val(rez.vid_description);
                $('#video-folder2').val(rez.vid_cat);
                $('#video-time2').val(rez.vid_time);
                $('#video-views2').val(rez.vid_views);
                $('#video-url2').val(rez.vid_video);
                $('#video-img2').val(rez.vid_img);
                $('#video-poster2').val(rez.vid_poster);
                $('#video-chbig2').val(rez.vid_chbig);
                $('#editvideoc').modal('show');
            }
        }, 'json');
    });
    $('body').on('click', '.modalevtedit', function (e) {
        e.preventDefault();
        var id = $(this).data('id');
        $.post('/act.php?act=getevtcdta', {id: id}, function (rez) {
            if (rez.result == 'ok') {
                $('#evide').val(rez.evt_id);
                $('#evt-nameene').val(rez.evt_nameEN);
                $('#evt-namefre').val(rez.evt_nameFR);
                $('#evt-descrene').val(rez.evt_descrEN);
                $('#evt-descrfre').val(rez.evt_descrFR);
                $('#evt-cate').val(rez.evt_category);
                $('#evt-datee').val(rez.evt_date);
                $('#evt-keye').val(rez.evt_key);
                $('#evt_imgurl2').html(rez.imglink);

                $('#editnewevtc').modal('show');
            }
        }, 'json');
    });
    $('body').on('click', '#editnvideomod', function (e) {
        e.preventDefault();
        var name = $('#video-name2').val();
        var descr = $('#video-descr2').val();
        var folid = $('#video-folder2').val();
        var tim = $('#video-time2').val();
        var views = $('#video-views2').val();
        var vurl = $('#video-url2').val();
        var img = $('#video-img2').val();
        var poster = $('#video-poster2').val();
        var chbig = $('#video-chbig2').val();
        var chann = $('#vid_id').val();
        if (chann > 0 && name != '' && vurl != '' && folid > 0 && tim != '' && poster != '') {
            $.post('/act.php?act=editvint', {
                vidid: chann,
                name: name,
                descr: descr,
                folid: folid,
                tim: tim,
                views: views,
                vurl: vurl,
                img: img,
                poster: poster,
                chbig: chbig
            }, function (rez) {
                if (rez.result == 'ok') {
                    swal({type: 'success', text: rez.msg}).then((result) => {
                        if (result.value) {
                            window.location.reload();
                        }
                    });
                    $('#editvideoc').modal('hide');

                } else {
                    swal({type: 'error', text: rez.msg});
                }
            }, 'json');
        } else {
            var msgerr = $('#editnvideomod').data('vid_error');
            swal({type: 'error', text: msgerr});
        }
    });
    $('#evt-img').on('change', prepareUpload);
    $('#evt-imge').on('change', prepareUpload3);
    $('#video-poster').on('change', prepareUpload2);
    $('#event_dates').on('submit', uploadFiles);
    $('#event_dates3').on('submit', uploadFiles3);
    $('#addnewvideof').on('submit', uploadFiles2);
    $('body').on('click', '#editfoldermodc', function (e) {
        e.preventDefault();
        var id = $('#folder-id').val();
        var clbid = $('#folc_clubid').val();
        var name = $('#folder-name2').val();
        var descr = $('#folder-descr2').val();
        var ord = $('#folder-order2').val();
        var show = $('#folder_show2').val();
        if (id > 0 && name !== '' && ord > 0) {
            $.post('/act.php?act=savefcnt', {
                id: id,
                clbid: clbid,
                name: name,
                descr: descr,
                ord: ord,
                show: show
            }, function (rez) {
                if (rez.result == 'ok') {
                    swal({type: 'success', text: rez.msg}).then((result) => {
                        if (result.value) {
                            window.location.reload();
                        }
                    });
                }
            }, 'json');
        }
    });
    $('body').on('click', '#addnewfoldermod', function (e) {
        e.preventDefault();
        var id = $('#folc_clubid').val();
        var name = $('#folder-name').val();
        var descr = $('#folder-descr').val();
        var ord = $('#folder-order').val();
        var show = $('#folder_show').val();
        if (id > 0 && name != '' && ord > 0) {
            $.post('/act.php?act=addfcnt', {clbid: id, name: name, descr: descr, ord: ord, show: show}, function (rez) {
                if (rez.result == 'ok') {
                    swal({type: 'success', text: rez.msg}).then((result) => {
                        if (result.value) {
                            window.location.reload();
                        }
                    });
                    $('#addnewfolderc').modal('hide');

                }
            }, 'json');
        }
    });

    $('body').on('click', '.gostreamon', function (e) {
        e.preventDefault();
        var msg = $('#admin-modo-table3').data('msg');
        var id = $(this).data('id');
        if (id > 0) {

            swal({
                text: msg,
                type: 'question',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33'
            }).then((result) => {
                if (result.value) {
                    $.post('/act.php?act=broadcast', {e: id}, function (rez) {
                        if (rez.result == "ok") {
                            window.location.reload();
                        }
                    }, 'json');
                }
            });

        }
    });

    /*$('body').on('click','#addnewvideomod',function(e){
		e.preventDefault();
		var name = $('#video-name').val();
		var descr = $('#video-descr').val();
		var folid = $('#video-folder').val();
		var tim = $('#video-time').val();
		var views = $('#video-views').val();
		var vurl = $('#video-url').val();
		var img = $('#video-img').val();
		var poster = $('#video-poster').val();
		var chbig = $('#video-chbig').val();
		var chann = $('#vid_club').val();
		if(chann > 0 && name != '' && vurl != '' && folid > 0 && tim != '' && poster != '') {
			$.post('/act.php?act=addvint',{clbid:chann,name:name,descr:descr,folid:folid,tim:tim,views:views,vurl:vurl,img:img,poster:poster,chbig:chbig},function(rez){
				if(rez.result == 'ok') {
					swal({type: 'success',text:rez.msg}).then((result) => {
					  if (result.value) {
						window.location.reload();
					  }
					});
					$('#addnewvideoc').modal('hide');

				} else {
					swal({type: 'error',text:rez.msg});
				}
			},'json');
		} else {
			var msgerr = $('#addnewvideomod').data('vid_error');
			swal({type: 'error',text:msgerr});
		}
	});*/

    $('body').on('click', '#closeubar1', function (e) {
        setCookie('hideunderbar1', 'yes', 31);
        $('#underbar1,#underbar2').hide();
    });

    $('body').on('click', '.del', function (e) {
        e.preventDefault();
        var ttl = $(this).data('questionttl');
        var txt = $(this).data('question');
        var btnyes = $(this).data('btnyes');
        var url = $(this).prop('href');
        swal({
            title: ttl,
            text: txt,
            type: 'question',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: btnyes
        }).then((result) => {
            if (result.value) {
                window.location.href = url;
            }
        });
    });

    $('body').on('click', '.allbtn', function (e) {
        if ($(this).prop('href') == '#') e.preventDefault();
        var id = $(this).data('id');
        $('#' + id).toggleClass('more');
        if ($('#' + id).hasClass('more')) {
            $(this).html($(this).data('more'));
        } else {
            $(this).html($(this).data('less'));
        }
    });
    $(window).scroll();
});
$(window).on('scroll', function (e) {
    if ($('body').hasClass('exp')) {
        if ($(window).width() > 1000) {
            if ($(window).scrollTop() >= $(window).height()) {
                $('#top_menu').show();
            } else $('#top_menu').hide();

            if ($('#vsc').css('position') == 'absolute') {
                $('#vsc').prop('style', '');
                $('#vsc2').prop('style', '');
                $('#evts').prop('style', '');
                $('#nextk').css({'width': $('#nextk').data('wd'), 'position': 'absolute'});
            }
            //console.log($(window).scrollTop() >= 50);
            if ($(window).scrollTop() >= 50) {
                $('#firstmobtop').hide();
            } else $('#firstmobtop').show();
        } else {
            if ($('#vsc').css('position') != 'absolute') {
                $('#vsc').prop('style', $('#vsc').data('style'));
                $('#vsc2').prop('style', $('#vsc2').data('style'));
                $('#nextk').css({'width': $('#nextk').data('w'), 'position': 'absolute'});
                $('#evts').prop('style', $('#evts').data('style'));
            }

            if ($(window).scrollTop() >= $(window).height()) {
                $('#top_menu').show();
            } else $('#top_menu').hide();

            if ($(window).scrollTop() >= 50) {
                $('#firstmobtop').hide();
            } else $('#firstmobtop').show();
        }
    } else {
        if ($(window).width() > 1000) {
            if ($('#vsc').css('position') == 'absolute') {
                $('#vsc').prop('style', '');
                $('#vsc2').prop('style', '');
                $('#evts').prop('style', '');
                $('#nextk').css({'width': $('#nextk').data('wd'), 'position': 'absolute'});
            }
        } else {
            if ($('#vsc').css('position') != 'absolute') {
                $('#vsc').prop('style', $('#vsc').data('style'));
                $('#vsc2').prop('style', $('#vsc2').data('style'));
                $('#nextk').css({'width': $('#nextk').data('w'), 'position': 'absolute'});
                $('#evts').prop('style', $('#evts').data('style'));
            }
        }
        if ($('body').hasClass('exp3')) {
            if ($(window).scrollTop() >= 100) {
                $('#top_menu').addClass('notv');
            } else $('#top_menu').removeClass('notv');
        }

        if ($(window).width() <= 1000) {
            if ($(window).scrollTop() >= 50) {
                $('#firstmobtop').slideUp("fast");
                $('.editbar').css("top", "45px");
            } else {
                $('#firstmobtop').slideDown("fast");
                $('.editbar').css("top", "90px");
            }
        }
    }
});
$(window).on("resize", function () {
    if ($(window).width() <= 1000) {
        if ($("#firstmobtop").css('display') === 'none') {
            $('.editbar').css("top", "45px");
        } else {
            $('.editbar').css("top", "90px");
        }
    } else {
        $('.editbar').css("top", "70px");
    }
});
