<%@ page language="C#" autoeventwireup="true" inherits="MsgGroup_MsgGroup, App_Web_zqyakmif" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>无标题页</title>
    <script src="../Scripts/MyDate.js"></script>
    <script src="../Scripts/UserMsgClass.js"></script>
    <script type="text/javascript">
        //禁止返回键
        javascript:window.history.forward(1);
        
        function PageLoad()
        {
            window.parent.ShowOrHideToolBar(true);
            
            LoadMsgGroupList();
        }
        //加载当前群组列表
        function LoadMsgGroupList()
        {
            XMLHttpGet(window.parent._UserNo);
        }
        
        var xmlHttpRequest = null;
        //收到消息，发现没有用户信息，就到服务器端下载用户信息
        function XMLHttpGet(userno)
        { 
            xmlHttpRequest = new XMLHttpRequest();
            xmlHttpRequest.open("POST", "../SisenMESS-Mobile-WebService.asmx/GetMsgGroupList", true);
            // 当发生状态变化时就调用这个回调函数
            xmlHttpRequest.onreadystatechange = ajaxCallBack;
            // 使用post提交时必须加上下面这行代码
            xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            
            // 向服务器发出一个请求
            xmlHttpRequest.send("userNo=" + userno);
            
        }
        
        function ajaxCallBack()
        {
            if(xmlHttpRequest.readyState == 4)
            {
                if(xmlHttpRequest.status == 200)
                {
                    var content = xmlHttpRequest.responseText;
                    ShowMsgGroupList(content);
                }
            }
        }
        //显示通讯群组
        function ShowMsgGroupList(tempinfo)
        {
            var tempmsg = tempinfo.split('\n');
            
            for (var i=0;i<tempmsg.length;i++)
            {
                if(tempmsg[i]=="")
                {
                    continue;
                }
                
                var minfo =tempmsg[i].split('\t');
                var msgcount = minfo[2];
                var htmltxt = "";
                
                var imgpath = "../Images/MsgGroup1.png";
                
                if(minfo[3]!="0")
                {
                    imgpath = "../Images/MsgGroup2.png";
                }
                
                if(msgcount>0)
                {
                    htmltxt = GetMsgGroupShowItem(minfo[0], minfo[1], "", msgcount, "visible", imgpath);
                }
                else
                {
                    htmltxt = GetMsgGroupShowItem(minfo[0], minfo[1], "", msgcount, "hidden", imgpath);
                }
                
                document.getElementById("MsgGroupList").innerHTML = document.getElementById("MsgGroupList").innerHTML + htmltxt;
            }
        }
        
        //得到用户Item（visible、hidden）
        function GetMsgGroupShowItem(msgid,msgname,userdetail,msgCount,isVisible,usericonpath)
        {
            userdetail += "&nbsp;";
            var htmltxt = "<div id = \"SisenMESSUserItem-" + msgid + "\" class ='MsgListDivPro' onclick=\"OpenMsgGroupWindow('" + msgid + "','" + msgname + "');\" >";
            htmltxt += "<table width=\"100%\" height=\"100%\"  border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
            htmltxt += "<tr>";
            htmltxt += "<td style=\"width:48px; height:48px;\" align=\"center\"><img id = 'userIcon-" + msgid + "' style='border:1px #e0e1e3 solid;background-color:#FFFFFF' src=\"" + usericonpath + "\" width=\"32\" height=\"32\"></td>";
            htmltxt += "<td style='color:#4f5152;'><span id ='UserInfo-UserName-" + msgid + "'>" + msgname  + "</span><br><span class = 'UserDetail' id ='UserInfo-UserDetail-" + msgid + "'>" + userdetail + "</span></td>";
            htmltxt += "<td align='right'>";
            htmltxt += " <table id ='MsgCount-" + msgid + "' style='height:16px;visibility:" + isVisible + "' border='0' cellspacing='0' cellpadding='0'>";
            htmltxt += " <tr style='height:16px; '>";
            htmltxt += " <td style='width:5px; background-image:url(../Images/y1.gif);background-size:5px 16px;'></td>";
            htmltxt += " <td style='width:5px; height:16px; background-image:url(../Images/y2.gif);background-size:40px 16px; font-size:10px; color:#FFFFFF;' align='center'>";
            htmltxt += " <div style='margin-top:2px;width:100%;text-align:right;' id ='msg_count_" + msgid + "'>" + msgCount + "</div>";
            htmltxt += " </td>";
            htmltxt += " <td style='width:6px; background-image:url(../Images/y3.gif);background-size:6px 16px'></td>";
            htmltxt += " </tr>";
            htmltxt += " </table>";
            htmltxt += "</td>";//<span id ='msg_count_" + tempmsg[0] + "'>1</span>
            htmltxt += "<td style='width:4px;'></td>";                    
            htmltxt += "</tr>";
            htmltxt += "</table>";
            htmltxt += "</div>";
            
            return htmltxt;
        }
        //接收到群组消息
        function RecvMsgGroup(msggroupid)
        {
            if (document.getElementById("SisenMESSUserItem-" + msggroupid))
            {
                //说明这个用户存在
                var newitem = document.getElementById("SisenMESSUserItem-" + msggroupid);
                if(MsgGroupList.firstChild != newitem)
                {
                    newitem.remove();
                    MsgGroupList.insertBefore(newitem,MsgGroupList.firstChild);
                }
                
                document.getElementById("MsgCount-" + msggroupid).style.visibility = 'visible';
                var count = parseInt(document.getElementById("msg_count_" + msggroupid).innerText) + 1;
                document.getElementById("msg_count_" + msggroupid).innerText = count;
            }
            else
            {
                var htmltxt = GetUserMsgShowItem(msggroupid,msggroupid,"","1","visible","../UserIcon/SisenMESS-User-None-Icon.gif");
                    
                document.getElementById("MsgGroupList").innerHTML = htmltxt + document.getElementById("MsgGroupList").innerHTML;
                    
                    
                //XMLHttpGet(sender);
            }
        }
        
        //打开群组聊天窗口
        function OpenMsgGroupWindow(msgid,msggroupname)
        {
            if(!window.parent._IsLogin)
            {
                return;
            }
            
            document.getElementById("msg_count_" + msgid).innerText = "0";
            document.getElementById("MsgCount-" + msgid).style.visibility = 'hidden';
            msggroupname = msggroupname.replace(/&/g,"＆").replace(/=/g,"＝");
            window.location.href = "MsgGroupShow.aspx?MsgGroupId=" + msgid+"&MsgGroupName="+msggroupname;
        }
        
    </script>
    <link href="../Css/MsgList.css" rel="stylesheet" />
</head>
<body onload="PageLoad()">
    <form id="form1" runat="server">
    <br />
    <br />
    <div id = "MsgGroupList" runat="server"></div>
    </form>
</body>
</html>
