var myInterval ;
(function() {
    if (document.cookie.indexOf("UID") < 0) {
        return;
    }
    var requestAjax = function(settings) {
        if (!settings || !settings.url) {
            return;
        }
        var url = settings.url;
        if (!settings.data) {
            data = {};
        }
        var cbName = ("jsonp" + Math.random()).replace(".", "");
        var oScript = document.createElement("script");
        window[cbName] = function(json) {
            oScript.parentNode.removeChild(oScript);
            if (settings.success) {
                settings.success(json);
            }
        };
        data.jsoncallback = cbName;
        data.t = new Date().getTime();
        var arr = [];
        for (var attr in data) {
            arr.push(attr + "=" + data[attr]);
        }
        if (url.indexOf("?") > 0) {
            url += "&" + arr.join("&");
        } else {
            url += "?" + arr.join("&");
        }
        oScript.src = url;
        oScript.setAttribute("defer", "defer");
        if (settings.charset) {
            oScript.setAttribute("charset", settings.charset);
        }
        var head = document.getElementsByTagName("head")[0];
        head.appendChild(oScript);
    };
    var fid = 22281;
    var fn = function() {
        var refer = encodeURIComponent('http://i.mooc.chaoxing.com');
        requestAjax({
            url: window.location.protocol+"//" + 'detect.chaoxing.com' + '/api/monitor?version=' + 1767634705601 + '&refer=' +refer + '&from=' + ''+'&fid='+fid,
            success: function(json) {
                var myjson = eval("(" + json + ")");

                var from = '';
                if (myjson.status == false) {
                    if (from == 'exam'){
                        console.log(json);
                        callback_exam(myjson);
                        console.log(json);
                    }else if ((fid == 179952 || fid == 74287) && myjson.lock == true) {
                        callback_course(myjson);
                    }else{
                        var mes = myjson.mes;
                        var time = myjson.time;
                        var sign = myjson.sign;
                        location.href = window.location.protocol+"//" + 'detect.chaoxing.com' + '/api/monitor_temp?refer=' + refer+ '&from=' + ''
                        +"&mes="+decodeURIComponent(mes)+"&time="+time+"&sign="+sign;
                    }
                }
            }
        });
    };
    fn();
    if (fid == 179952 || fid ==  74287) {
        myInterval = setInterval(fn, 30000);
    }else{
        setInterval(fn, 30000);
    }

})();
