var $commonParam = {};
$commonParam.accessLimitAndCopyright ={"code":1,"msg":"success","data":{"template":"<style type=\"text\/css\">\n.agentAdvertising{ background: #f5f5f5; text-align: center;color: #666; padding: 10px 0px;float: left;width: 100%;}\n.agentAdvertising a{ color: #666;}\n.agentAdvertising .w50{ width: 45%;}\n.agentAdvertising .w100{ width: 100%;}\n.agentAdvertising .adFr{ float: right; text-align: right}\n.agentAdvertising .adFl{ float: left; text-align: left;}\n.agentAdContent{ display: inline-block; float: right; width: 500px}\n.agentAdContent .adTextList{overflow: hidden; width:400px; height: 25px;   color: #666; float: left;}\n.agentAdContent .adTextList a{ height: 25px; float: left; line-height: 25px; display: inline-block; width: 100%; text-align: left;}\n.agentAdContent .adTextList a:hover{ color: #38a0f4;}\n.agentAdContent .adTextList ul{ margin: 0; padding: 0; float: left;}\n.agentAdContent .adTextList li{ width: 100%; list-style: none; float: left;}\n.agentAdContent .adTitle{ float: left; margin-right: 10px;}\n.agentAdvertisingCon{ display: flex; justify-content: space-between; align-items: center;    width: 100%;}\n<\/style>\n<div class=\"agentAdvertising\">\n        <div class=\"container agentAdvertisingCon\">\n    <div class=\" adFl\">\n        Copyright \u00a92024 \u4e91\u5fae\u8054\u4f01\u4e1a\u90ae\u7bb1 \u7248\u6743\u6240\u6709 <a href=\"\/sitemap.xml\" target=\"_blank\">XML<\/a> |\n        <a href=\"\/sitemap.html\" target=\"_blank\">HTML<\/a> |\n        <a href=\"\/sitemap.txt\" target=\"_blank\">TXT<\/a>\n    <\/div>\n    <div class=\"adFr\">\n                <a href=\"https:\/\/www.yiqihang.vip\/login.html\" target=\"_blank\" rel=\"nofollow\">\u7ba1\u7406\u767b\u9646<\/a> |\n        <a href=\"https:\/\/www.yiqihang.vip\/user.work\/add.html\"  target=\"_blank\">\u8fdd\u89c4\u4e3e\u62a5<\/a> |\n        \u6280\u672f\u652f\u6301:<a href=\"https:\/\/www.yiqihang.vip\" target=\"_blank\" rel=\"nofollow\">\u3010\u58f9\u8d77\u822a\u3011<\/a>\n                <a href=\"https:\/\/beian.miit.gov.cn\/\" rel=\"nofollow\"  target=\"_blank\">\u7ca4ICP\u590718028218\u53f7-5<\/a>\n            <\/div>\n    <\/div>\n\n<\/div>"}};
$commonParam.AutoOnlineService ={"status":"1","online_service_name":"\u5728\u7ebf\u5ba2\u670d","customer_name":"\u5c0f\u4e91\u7cbe\u7075","customer_min_name":"\u548c\u6211\u4eec\u5728\u7ebf\u4ea4\u8c08","icon":"\/static\/online\/images\/icon.png","openLeaving":"1","customer_style_width":"360","customer_style_height":"500","customer_style_bg":"#409EFF","customer_style_pos":"4","customer_style_default":"1","siteId":500,"open_welcome":"1","open_keyword_reply":"1","customer_quick_reply":"\u5ba2\u670d\u70ed\u7ebf,\u4e1a\u52a1\u54a8\u8be2,\u641c\u7d22\u4f18\u5316","customer_default_reply_type":"0","customer_default_reply":"\u60a8\u597d\uff0c\u8bf7\u63cf\u8ff0\u60a8\u7684\u95ee\u9898\uff0c\u673a\u5668\u4eba\u5ba2\u670d24\u5c0f\u65f6\u4e3a\u60a8\u670d\u52a1\u3002\u82e5\u9700\u8981\u4eba\u5de5\u534f\u52a9\u89e3\u51b3,\u8bf7\u62e8\u6253\u7f51\u7ad9\u8054\u7cfb\u7535\u8bdd","open_wait_reply":"1","open_wait_reply_time":"30","sign":"a0d042c80275ec3b79402f71615b99b0","timeStamp":1730237285,"badge":0};
$.extend({
    checkMobile: function () {
        var sUserAgent = navigator.userAgent.toLowerCase();
        var isMobile = sUserAgent.match(/iphone|android|ipad|phone|mobile|wap|netfront|x11|java|operamobi|operamini|uc|windowsce|symbian|symbianos|series|webos|sony|blackberry|dopod|nokia|samsung|palmsource|xda|pieplus|meizu|midp|cldc|motorola|foma|docomo|up.browser|up.link|blazer|helio|hosin|huawei|novarra|coolpad|webos|techfaith|palmsource|alcatel|amoi|ktouch|nexian|ericsson|philips|sagem|wellcom|bunjalloo|maui|smartphone|iemobile|spice|bird|zte-|longcos|pantech|gionee|portalmmm|jig browser|hiptop|benq|haier/i) != null;
        if (isMobile) {return true;}
        if (navigator.userAgent.indexOf('UCBrowser') > -1) {return true;}
        if (sUserAgent.match(/MicroMessenger/i) == 'micromessenger') {return true;}
        if (!!sUserAgent.match(/mqqbrowser|qzone|qqbrowser/i)) {return true;}
        return false;
    },
    isSsl: function () {return (document.location.protocol == 'https:') ? 'https://' : 'http://';},
    onlineServicePos: function (nodeName, defaultW, defaultH) {
        var $pos = parseInt($commonParam.AutoOnlineService.customer_style_pos), $node = $("#" + nodeName);
        var $winWith = $(window).width(), $winHeight = $(window).height(), $cssJson = {'width': defaultW + 'px', 'height': defaultH + 'px', 'bottom': '-' + defaultH + 'px'}, $animate = {'opacity': 1}, $pcNode='online_service_container';
        switch ($pos) {
            case 1 :
                $cssJson.left = nodeName==$pcNode ? 0 : '10px';
                $animate.bottom = (($winHeight - defaultH) / 2) + 'px';
                break;
            case 2 :
                $cssJson.right = nodeName==$pcNode ? 0 : '10px';
                $animate.bottom = (($winHeight - defaultH) / 2) + 'px';
                break;
            case 3 :
                $animate.bottom = nodeName==$pcNode ? 0 : '5px';
                $cssJson.left = nodeName==$pcNode ? 0 : '5px';
                break;
            default :
                $animate.bottom = nodeName==$pcNode ? 0 : '5px';
                $cssJson.right = nodeName==$pcNode ? 0 : '5px';
                break;
        }
        $node.css($cssJson).animate($animate, 'slow')
    },
    maxOnlineService: function ($onlineConfig) {
        if ($("." + $onlineConfig.node).length > 0) { $("." + $onlineConfig.node).remove();}
        $onlineConfig.badge = parseInt($commonParam.AutoOnlineService.badge);
        $onlineConfig.defaultH = $commonParam.AutoOnlineService.customer_style_height;
        $onlineConfig.defaultW = $onlineConfig.checkMobile ? parseFloat($(window).width()) : $commonParam.AutoOnlineService.customer_style_width;
        $onlineConfig.sign = $commonParam.AutoOnlineService.sign;
        $onlineConfig.siteId = $commonParam.AutoOnlineService.siteId;
        $onlineConfig.title = $commonParam.AutoOnlineService.online_service_name;
        $onlineConfig.timeStamp = $commonParam.AutoOnlineService.timeStamp;
        var $onlineServerUrl = '/AutoOnlineService/index?sign=' + $onlineConfig.sign + '&timeStamp=' + $onlineConfig.timeStamp, isFlag = false;
        var $ifRaMeClass = 'iframe_online_service_container';
        var autoOnlineServiceHtml = '<div id="' + $onlineConfig.node + '" class="' + $onlineConfig.node + '">' +
            '   <div class="header-mini-main-top" id="moveHeader">\n' +
            '        <div class="brand"><img src="' + $commonParam.AutoOnlineService.icon + '" alt=""></div>\n' +
            '        <div class="service-name"><div class="name-box">' + $onlineConfig.title + '</div></div>\n' +
            '        <div class="chat-custom">\n' +
            '            <div id="chat_min_btn" class="icon chat_close" title="关闭"></div>\n' +
            '        </div>\n' +
            '    </div>' +
            '<iframe id="' + $ifRaMeClass + '" class="' + $ifRaMeClass + '" width="100%" height="450" frameborder="0"  src="' + $onlineServerUrl + '"></iframe>' +
            '';
        var autoOnlineServiceCss = '<style type="text/css">' +
            '.' + $onlineConfig.node + '{cursor:move;z-index:1000000;background: #fff; position:fixed;opacity:0.5;}' +
            '.header-mini-main-top{height: 45px;background: ' + $commonParam.AutoOnlineService.customer_style_bg + ';cursor: move;-moz-user-select: none; -webkit-user-select: none; display: flex; width: 100%; float: left;}\n' +
            '.header-mini-main-top .brand{margin: 10px 0px 7px 10px;float: left;width: 13%;height: 30px;overflow: hidden;}\n' +
            '.header-mini-main-top .brand img{ width: 30px; height: 30px;}\n' +
            '.header-mini-main-top .service-name{ float: left; width:69%; height: 100%; display: flex;align-items: center;}\n' +
            '.header-mini-main-top .service-name .name-box{ color: #fff; font-size: 16px;}\n' +
            '.header-mini-main-top .chat-custom{ float: left; width: 25%; text-align: right; padding-right: 15px; height: 100%; display: flex; align-items: center; justify-content: flex-end;}\n' +
            '.header-mini-main-top .chat-custom .icon{ width: 20px; cursor: pointer; color: #fff; height: 20px; margin: 0 5px; display: inline-block; background-size: cover;}\n' +
            '.header-mini-main-top .chat-custom .chat_close{ width: 12px; height: 12px; margin:0;background: url("/static/online/images/closewin.png") no-repeat center center;}\n' +
            '.header-mini-main-top .chat-custom .chat_max_btn{ background: url("/static/online/images/max.png") no-repeat center center;}\n' +
            '.header-mini-main-top .chat-custom .chat_min_btn{ background: url("/static/online/images/min.png") no-repeat center center;}' +
            '.' + $ifRaMeClass + '{border:1px #ddd solid;}' +
            '</style>';

        $("body").append(autoOnlineServiceHtml + autoOnlineServiceCss + '</div>');
        $('.' + $ifRaMeClass).height($onlineConfig.defaultH - $("#moveHeader").height());
        $.onlineServicePos($onlineConfig.node, $onlineConfig.defaultW, $onlineConfig.defaultH);
        $("." + $onlineConfig.node).on('mousedown', function (event) {
            var $this = $(this), _top = $this.offset().top, _left = $this.offset().left,//获取div位置偏移量
                divX = event.clientX, divY = event.clientY, //获取鼠标位置
                $winWith = $(document).width(), $winHeight = $(document).height();
            isFlag = true;
            if (document.attachEvent) {
                $this[0].attachEvent('onselectstart', function () {
                    return false;
                });
            }
            $(document).mousemove(function (e) {
                if (isFlag) {
                    var divMoveX = e.clientX, divMoveY = e.clientY;
                    var $scrollTop = $(document).scrollTop(), $scrollLeft = $(document).scrollLeft();//滚动条高度
                    var posLeft = divMoveX - divX + _left - $scrollLeft, posTop = divMoveY - divY + _top - $scrollTop;
                    var intValH = $winHeight - $onlineConfig.defaultH, intValW = $winWith - $onlineConfig.defaultW;
                    posTop = posTop < 0 ? 0 : (posTop > intValH ? intValH : posTop);
                    posLeft = posLeft > intValW ? intValW : posLeft;  //右限制
                    posLeft = posLeft < 0 ? 0 : posLeft; //左边的偏移量小于0的时候设置 左边的位置为0
                    $this.css({'left': posLeft, 'top': posTop});
                }
            }).mouseup(function () {
                isFlag = false;
                $(document).off("mousemove");
            })
        });

    },
    minOnlineService: function ($onlineConfig) {
        if ($("." + $onlineConfig.minNode).length > 0) {
            $("." + $onlineConfig.minNode).remove();
        }
        $onlineConfig.badge = parseInt($commonParam.AutoOnlineService.badge);
        var minHtml = '<div id="' + $onlineConfig.minNode + '" class="' + $onlineConfig.minNode + '"><div class="online-service-min"> ' +
            '<div class="service-icon"></div><div class="service-title">' + $commonParam.AutoOnlineService.customer_min_name + '</div><div class="service-up">' +
            '</div>';
        if ($onlineConfig.badge > 0) {
            minHtml += '<div class="online-service-badge">' + $onlineConfig.badge + '</div>';
        }
        minHtml += '</div><div id="chat_close" class="icon chat_close" title="关闭窗口"></div><style type="text/css">' +
            '.' + $onlineConfig.minNode + ' .online-service-min{position: relative; z-index: 990; width: 100%; display: inline-block;}\n' +
            '.' + $onlineConfig.minNode + '{position: fixed; opacity:0.5; cursor: pointer;  z-index: 10000000; border-radius: 2px;background: rgb(23, 152, 252);box-shadow: rgb(0 0 0 / 6%) 0px 1px 6px, rgb(0 0 0 / 16%) 0px 2px 32px;}' +
            '.' + $onlineConfig.minNode + ' .service-icon{ float: left; width: 42px; height: 42px; background: #409eff url("/static/online/images/chat.png") no-repeat center center;}\n' +
            '.' + $onlineConfig.minNode + ' .service-title{ color: #fff; padding: 10px 8px;font-size: 16px; float: left; display: inline-block;}\n' +
            '.' + $onlineConfig.minNode + ' .service-up{background: url("/static/online/images/up_arrow.png") no-repeat center center; float: right; display: inline-block; width: 12px; height: 12px; margin-top: 15px;    margin-right: 30px;}\n' +
            '.' + $onlineConfig.minNode + ' .online-service-badge{position: absolute; left: -5px; top: -5px; background: #ff0000; color: #fff; border-radius: 50%; width: 20px; height: 20px; line-height: 20px; text-align: center;}\n' +
            '.'+ $onlineConfig.minNode +' .chat_close{ position: absolute;z-index:1000; background: url("/static/online/images/closewin.png") no-repeat center center; width: 12px; height: 12px;top: 15px; right: 7px;}\n' +
            '</style>';
        $("body").append(minHtml + '</div>');
        $.onlineServicePos($onlineConfig.minNode, 225,42);
    },
    mobileOnlineService: function ($onlineConfig) {
        if ($("." + $onlineConfig.mobileNode).length > 0) {
            $("." + $onlineConfig.mobileNode).remove();
        }
        $onlineConfig.badge = parseInt($commonParam.AutoOnlineService.badge);
        var mobileHtml = '<div id="' + $onlineConfig.mobileNode + '" class="' + $onlineConfig.mobileNode + '"><div class="online-service-min"> ' +
            '<img class="online-service-img" src="/static/online/images/chat_mobile.png" alt="">';
        if ($onlineConfig.badge > 0) {
            mobileHtml += '<div class="online-service-badge">' + $onlineConfig.badge + '</div>';
        }
        mobileHtml += '</div><style type="text/css">' +
            '.' + $onlineConfig.mobileNode + ' .online-service-min{position: relative; width: 100%; display: inline-block;}\n' +
            '.' + $onlineConfig.mobileNode + '{opacity:0.5; line-height: 50px; text-align: center;  background: #ffffff;box-shadow: 0px 0px 6px 0px rgb(40 51 75 / 40%); border-radius: 50%;position: fixed;  cursor: pointer; display: block;z-index: 1000000000;} ' +
            '.' + $onlineConfig.mobileNode + ' .online-service-img{ width: 60%;display: inline-block;} ' +
            '.' + $onlineConfig.mobileNode + ' .online-service-badge{position: absolute; right: -5px; top: -5px; background: #ff0000; color: #fff; border-radius: 50%; width: 20px; height: 20px; line-height: 20px; text-align: center;} ' +
            '</style>';
        $("body").append(mobileHtml + '</div>');
        $.onlineServicePos($onlineConfig.mobileNode, 50,50);
    }
})

$(function () {
    if ($commonParam.accessLimitAndCopyright.code == 1) {$("body").append($commonParam.accessLimitAndCopyright.data.template)}
    if (parseInt($commonParam.AutoOnlineService.status) == 1) {
        var $serviceConfig = {'checkMobile': $.checkMobile(), 'node': 'online_service_container', 'minNode': 'minOnlineServer', 'mobileNode': 'mobileOnlineServer',};
        var $defaultStyle=parseInt($commonParam.AutoOnlineService.customer_style_default);
        if ($serviceConfig.checkMobile) {
            $.mobileOnlineService($serviceConfig);
        } else {
            switch ($defaultStyle) {
                case 3 :
                    $.mobileOnlineService($serviceConfig);
                    break;
                case 2 :
                    $.minOnlineService($serviceConfig);
                    break;
                default :
                    $.maxOnlineService($serviceConfig);
                    break;
            }
        }
        $(document).on("click", '#chat_min_btn', function () {
            $("#" + $serviceConfig.node).off('mousedown').remove();
            if ($serviceConfig.checkMobile) {
                $.mobileOnlineService($serviceConfig);
            } else {
                switch ($defaultStyle) {
                    case 3 :
                        $.mobileOnlineService($serviceConfig);
                        break;
                    default :
                        $.minOnlineService($serviceConfig);
                        break;
                }
            }
        })
        $(document).on("click", '#chat_close', function () {
            $("#" + $serviceConfig.node).off('mousedown').remove();
            $("#" + $serviceConfig.minNode).remove();
        })
        $(document).on("click", '#' + $serviceConfig.minNode+' .online-service-min', function () {
            $("#" + $serviceConfig.minNode).remove();
            $.maxOnlineService($serviceConfig);
        })
        $(document).on("click", '#' + $serviceConfig.mobileNode, function () {
            $("#" + $serviceConfig.mobileNode).remove();
            $.maxOnlineService($serviceConfig);
        })
    }
})