$(function () {
    ESONCalendar.bind("start_time");
    ESONCalendar.bind("end_time");

    //查询数据
    $("#search_Btn").click(function () {
        if ($("#start_time").val() != "" && $("#end_time").val()) {
            var para = "";
            para += "?starttime=" + $("#start_time").val();
            para += "&endtime=" + $("#end_time").val();
            location.href = $(this).attr("rel") + para;
        } else {
            alert("请选择时间范围");
        }
        return false;
    });

    //删除统计记录
    $("a[rel='del']").click(function () {
        var $delObject = $(this);
        if (confirm("确定要删除该记录吗？")) {
            $.ajax({
                type: "POST",
                url: "Ajax/Visit.ashx",
                data: { 'com': 'delsitevisit', 'sid': $delObject.attr("href") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    showMsg("正在删除记录", true);
                },
                success: function (data, textStatus) {
                    if (data == "1") {
                        $delObject.parent().parent("tr").remove();
                    } else {
                        alert("删除失败!");
                    }
                    showMsg("", false);
                },
                error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
            })
        }
        return false;
    });

    //订单明细
    $("a[rel='intro']").click(function () {
        $object = $(this);
        if ($("#ouBox").is(":hidden")) $("#ouBox").slideToggle(60);
        $.ajax({
            type: "POST",
            url: "Ajax/Visit.ashx",
            data: { 'com': 'getsitevisit', 'sid': $object.attr("href") },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                var showHtml = "";
                showHtml += "<div class=\"title\">访问明细</div>";
                showHtml += "<p>加载中...</p>";
                $("#ouBox .content").html(showHtml);
            },
            success: function (data, textStatus) {
                var showHtml = "";
                //拆分Josn数据
                var JosnData = eval(data);
                if (JosnData != null) {
                    showHtml += "<div class=\"title\">" + JosnData[0].ip + "(" + JosnData[0].ipcity + ")</div>";
                    showHtml += "<p>";
                    showHtml += "<span class=\"C B\">访问信息：</span><br />";
                    if (JosnData[0].pageurl == "/") {
                        showHtml += "访问页面:网站首页<br />";
                    } else {
                        showHtml += "访问页面:" + JosnData[0].pageurl + "<br />";
                    }
                    if (JosnData[0].pagename != "") {
                        showHtml += "页面来源:" + JosnData[0].pagename + "<br />";
                    }
                    if (JosnData[0].naviname != "") {
                        showHtml += "访问栏目:" + JosnData[0].naviname + "<br />";
                    }
                    showHtml += "访问次数:" + JosnData[0].number + "<br />";
                    showHtml += "访问时间:" + JosnData[0].addtime + "<br />";
                    showHtml += "活动时间:" + JosnData[0].updatetime + "<br />";
                    showHtml += "<span class=\"C B\">访客客户端信息追踪：</span><br />";
                    showHtml += "客户端IP:" + JosnData[0].ip + "<br />";
                    showHtml += "ip所在地:" + JosnData[0].ipcity + "<br />";
                    showHtml += "浏览器:" + JosnData[0].browser + "<br />";
                    showHtml += "操作系统:" + JosnData[0].os + "<br />";
                    showHtml += "<span class=\"C B\">访客痕迹追踪：</span><br />";
                    showHtml += showIPpage(JosnData[0].ip);
                    showHtml += "</p>";


                }
                $("#ouBox .content").html(showHtml);
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })

        return false;
    })
    function showIPpage(ip) {
        var retValue = "";
        $.ajax({
            type: "POST",
            url: "Ajax/Visit.ashx",
            data: { 'com': 'getipsitevisit', 'ip': ip },
            datatype: "json",
            async: false,
            beforeSend: function (data, textStatus) { },
            success: function (data, textStatus) {
                var JosnData = eval(data);
                for (var i = 0; i < JosnData.length; i++) {
                    if (JosnData[i].pageurl == "/") {
                        retValue += "网站首页 <span class=\"X Size9\">(" + JosnData[i].addtime + ")</span><br />";
                    } else {
                        retValue += "" + JosnData[i].pageurl + " <span class=\"X Size9\">(" + JosnData[i].addtime + ")</span><br />";
                    }
                    
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); }
        })
        return retValue;
    }
});