var ABRecord = (function () {
    var headers = window.location.host == 'www.acadsoc.com' ? 'https://record.acadsoc.com' : ''

    var tmpData = {
        puid: 0,    //Visit.ID
        pvid: 0  //VisitDetail.ID
    };
    var agent = navigator.userAgent.toLowerCase();
    //判断系统是32位还是64位,仅在windows下有效
    var getOSBit = function () {
        if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) {
            return 32;
        }
        if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) {
            return 64;
        }
        return 0;
    };
    var getQS = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return "";
    };
    //获取广告和来源
    var getAdAndSource = function () {
        var _st = getQS("_s");
        var _ad = getQS("search");
        return {
            ad: _ad,
            sourceType: _st
        }
    };
    //浏览记录上传
    var record = function () {
        var data = {
            referrer: document.referrer,    //来源页
            url: document.URL,
            page: window._LoadingPageUrl,   //中转页中转地址
            hash: location.hash,
            ieVersion: document.documentMode,
            ieCompatible: agent.indexOf("compatible") >= 0,
            osbit: getOSBit(),
            sourceType: window._ABST,    //来源类型,对应 IpRecord的 SourceType
            adid: window._ABADID //广告ID,对应IpRecord的 SearchType
        };
        var adAndSource = getAdAndSource();
        if (adAndSource.ad) {
            data.adid = adAndSource.ad;
        }
        if (adAndSource.sourceType) {
            data.sourceType = adAndSource.sourceType;
        }

        var options = {
            url: headers + "/Ajax/Web.UI.Fun.ABRecord.aspx?__=ABVisit",
            data: data,
            type: "post",
            xhrFields: { "withCredentials": true },
            dataType: "json",
            success: function (json) {
                var jsonData = json.value;
                if (jsonData.result) {
                    if (jsonData.data) {
                        tmpData.puid = jsonData.data.puid;
                        tmpData.pvid = jsonData.data.pvid;
                    }
                }
            }
        };
        jQuery.ajax(options);
    };
    //客户端注册成功后通知后台注册数加1
    var abrecord = {
        registUID: 0,    //本页面注册的用户UID
        registNotice: function (fn) {  //fn表示回调函数
            var result = null;
            if (window.__a2b__ !== true) {    //如果页面不是A页面跳转到B页面,则记录流量,否则不记录
                var data = {
                    referrer: document.referrer,    //来源页
                    url: document.URL,
                    page: window._LoadingPageUrl,   //中转页中转地址
                    hash: location.hash,
                    ieVersion: document.documentMode,
                    ieCompatible: agent.indexOf("compatible") >= 0,
                    osbit: getOSBit(),
                    sourceType: window._ABST,    //来源类型,对应 IpRecord的 SourceType
                    adid: window._ABADID, //广告ID,对应IpRecord的 SearchType
                    puid: tmpData.puid,
                    pvid: tmpData.pvid,
                    registUID: abrecord.registUID   //在本页面注册的UID
                };
                var adAndSource = getAdAndSource();
                if (adAndSource.ad) {
                    data.adid = adAndSource.ad;
                }
                if (adAndSource.sourceType) {
                    data.sourceType = adAndSource.sourceType;
                }
                $.ajax({
                    url: headers + "/Ajax/Web.UI.Fun.ABRecord.aspx?__=RegistNotice",
                    data: data,
                    async: !!fn,
                    type: "post",
                    xhrFields: { "withCredentials": true },
                    dataType: "json",
                    success: function (json) {
                        var jsonData = json.value;
                        if (jsonData.result) {
                            abrecord.registUID = 0;
                        }
                        if (fn) {
                            fn(jsonData.data);
                        } else {
                            result = jsonData;
                        }
                    },
                    error: function () {

                    }
                });
                if (!fn) {  //同步时返回结果
                    return result;
                }
            }
        }
    };
    if (window.__a2b__ !== true) {    //如果页面不是A页面跳转到B页面,则记录流量,否则不记录
        if (window.__wait__) {
            setTimeout(record, 500);    //如果有这个变量,则延迟500毫秒再执行流量统计
        } else {
            record();
        }
    }
    return abrecord;
}());
(function () { var _actTopTipsBar = document.createElement("script"); _actTopTipsBar.src = "https://img.acadsoc.com.cn/web/img/activity/dsp/js/topbar.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_actTopTipsBar, s); })();