//var m_MsgPageIndex = 0;
var m_MsgPageSize = 20;
var m_MsgMonth = "";
var m_ShowTimeList = [];
var m_MinTick = 936262421150398406;
var m_HisMsgList = [];//历史记录缓存
var m_FontSize = "";
//重置历史消息记录参数
function ResetHisMsgPara() {
    m_MinTick = 936262421150398406;
    //m_MsgPageIndex = 0;
    m_MsgPageSize = 20;
    m_MsgMonth = "";
    m_ShowTimeList = [];
    $("#divTalkContent").html("");
}

//是否已经显示过此时间
function IsShowTime(timemark) {
    for (var i = 0; i < m_ShowTimeList.length; i++) {
        if (m_ShowTimeList[i] == timemark)
            return true;
    }
    return false;
}

//function BindCacheMsgs(msgList) {
//    //缓存记录自上往下加载
//    if (msgList.length > 0) {
//        for (var i = 0; i < msgList.length; i++) {
//            //时间显示处理，已经显示过，或者本次读取最后一条
//            if (!IsShowTime(msgList[i].sorttime) || (i + 1) == msgList.length) {
//                m_ShowTimeList.push(msgList[i].sorttime);
//                $("#divTalkContent").append("<div class=\"talktip\">" + msgList[i].sorttime + "</div>");
//            }
//            $("#divTalkContent").append(MakeNewMsgHtml(msgList[i]));
//        }

//        var strContent = "<a id=\"btnLookMoreMsg\" href=\"javascript:void(0);\" class=\"moremessage-m\" onclick=\"GetHisMsg();\">更多聊天记录</a><br />";
//        $("#divTalkContent").prepend(strContent);

//    } else {
//        GetHisMsg();//获取历史记录
//    }
//}

//获取历史消息
function GetHisMsg(pid, timefrom, timeend, headimgkey, uin) {
    if (pid.length == 0)
        return;

    //防连击
    $("#btnLookMoreMsg").html("正在获取,请稍候...<br />")
    $("#btnLookMoreMsg").attr("onclick", "javascript:void(0);");

    var strParaJson = $.toJSON({
        pid: pid,
        timefrom: timefrom,
        timeend: timeend,
        headimgkey: headimgkey,
        uin: uin
    });
    talkObj.getsessionmessage(strParaJson);
}

//回执
function AsyncGetSessionMessageResult(jsonResult) {
    if (jsonResult.success) {
        if ($("#btnLookMoreMsg").length > 0) {
            $("#btnLookMoreMsg").remove();
        }

        //聊天记录
        var msgList = jsonResult.result.msgs;
        m_HisMsgList = jsonResult.result.msgs;
        if (msgList.length > 0) {
            for (var i = 0; i < msgList.length; i++) {
            	$("#divTalkContent").prepend(MakeNewMsgHtml(msgList[i], '1'));

            	if (msgList[i].msgtype == "11") {
            		initbaidumap(msgList[i], "width:180px;height:200px;", "His");
            	}
                //时间显示处理，已经显示过，或者本次读取最后一条
                if (!IsShowTime(msgList[i].sorttime) || (i + 1) == msgList.length) {
                    m_ShowTimeList.push(msgList[i].sorttime);
                    //$("#divTalkContent").prepend("<div class=\"talktip\">" + msgList[i].sorttime + "</div>");
                }
            }
            //var strContent = "<a id=\"btnLookMoreMsg\" href=\"javascript:void(0);\" class=\"moremessage-m\" onclick=\"GetHisMsg();\">更多聊天记录</a><br />";
            //$("#divTalkContent").prepend(strContent);

        } else {
            var strContent = "<span class=\"moremessage-m\">没有对话记录...</span><br />";
            $("#divTalkContent").prepend(strContent);
        }

        m_MsgMonth = jsonResult.result.month;
        m_MinTick = jsonResult.result.mintick;
        //m_MsgPageIndex = Number(jsonResult.result.pageindex);
    } else {
        ShowError("myPageAlert", "获取数据异常：" + jsonResult.error);
    }
}
