<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Show.aspx.cs" Inherits="MTCUN.Mobile.Msg.Show" %>

<%@ Register Src="../User_Col/col_Header.ascx" TagName="col_Header" TagPrefix="uc1" %>
<%@ Import Namespace="MTCUN" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title></title>

    <link id="mobileCss" runat="server" href="../themes/mobile.css" rel="stylesheet"
        type="text/css" />
    <link runat="server" href="Themes/css.css" rel="stylesheet"
        type="text/css" />
    <script type="text/javascript">
        function ScrollBottom() {
            var height = document.body.scrollHeight;
            window.scrollBy(0, height);

        }

    </script>

    <script type="text/javascript">

    var xmlHttp = null;
    //var newcount = 0;

    //接收消息并返回本地未读消息数。
    function ReceiveMsg() {
        try {
            if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
            else if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlHttp.open("GET", __mt_requesturl + "&action=1&s=" + Math.random(), false);
            xmlHttp.send("");

            var text = xmlHttp.responseText;
            var count = parseInt(text);

            if (count > 0) {
                var sound = true;

                var chat = document.getElementById("__mt_chat");
                if (chat != null) {
                    doRefresh(); //刷新消息列表或对话窗。
                    sound = false;
                }

                //显示消息数。
                setMsgCount(count, sound);
            }
        }
        catch (ex) {
            //alert(ex);
        }
    }

    //心跳程序，保持与服务器连接。
    function HeartRequest() {
        try {

            if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
            else if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            //连接心跳程序。
            xmlHttp.open("GET", __mt_requesturl + "&action=0&s=" + Math.random(), false);
            xmlHttp.send("");

            //存在新消息，需要更新。
            if (xmlHttp.responseText == "1") {
                ReceiveMsg();
            }

            window.setTimeout(HeartRequest, 15000);
        }
        catch (ex) {
            //alert(ex);
            window.setTimeout(HeartRequest, 15000);
        }
    }
    window.setTimeout(HeartRequest, 15000);

    //显示消息数。
    function setMsgCount(num, sound) {
        if (num > 0) {
            divNum.innerHTML = num;
            divNumBg.style.display = "block";
            if (sound)
                PaySound();
        } else {
            divNum.innerHTML = "";
            divNumBg.style.display = "none";
        }
    }

    //播放声音。
    function PaySound() {
        try {
            document.getElementById('bgaudio').play();
        } catch (e) {
        }
    }
</script>
</head>
<body runat="server" id="body">
    <form id="form1" runat="server">

                <!--用于标识作用//-->
        <div id="__mt_chat" style="display: none"></div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div class="top_nav" style="height: 42px; width: 100%;">
            <table class="table_simple_kuan" cellpadding="0" cellspacing="0" style="margin: 4px">
                <tr>

                    <td style="width: 100px; text-align: center;">
                        <input class="app_button" style="height: 30px; width: 80px" onclick="back(this)" type="button" value="返回" /></td>
                    <td align="center" style="font-weight: bold; color: white"><span title='<%=ViewState["FriendName"] + ((int)ViewState["FriendID"] ==0 ? "" : " ID号："+ViewState["FriendID"])%>'><%=ViewState["FriendName"]%></span></td>
                    <td style="width: 100px; text-align: center;"></td>
                </tr>
            </table>
        </div>
        <div id="web_page_contents">
            <div class="search biao_zhun_suo_jin">
                <div style="margin-top: 50px; margin-bottom: 120px">
                    <asp:UpdatePanel ID="upMsgs" runat="server">
                        <ContentTemplate>
                            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="AppMsgID"
                                ShowHeader="False" Width="100%">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <div class='<%#(int)Eval("Reply") == 1 ? "rechat" :"chat" %>'>
                                                <div class="logo" style='<%# string.Format("background-image:url(\"{0}\")",(int)Eval("Reply") == 1 ? ShowUserFace(ViewState["MyFace"].ToString()): ShowUserFace(ViewState["FriendFace"].ToString())) %>'>
                                                </div>
                                                <div class="content wrap">
                                                    <%#swq.Tools.UBBEncode(Eval("PostContent").ToString()) %>
                                                    <div class="time">
                                                        <%#Eval("PostTime","{0:M-d HH:mm}") %>
                                                    </div>
                                                </div>
                                            </div>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <span style="display: none; visibility: hidden">
                                <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" /></span>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>

            </div>
            <br />
            <br />
            <br />
            <br />
            <asp:UpdatePanel ID="upSend" runat="server">
                <ContentTemplate>
                    <div class="bottom_nav" style="height: 45px; width: 100%;" id="divSend" runat="server">
                        <table class="table_simple_kuan" cellpadding="0" cellspacing="0" style="margin: 4px;">
                            <tr>
                                <td>
                                    <asp:TextBox ID="tbxContent" runat="server" Height="30px" Width="100%" Font-Size="14px"></asp:TextBox></td>
                                <td style="width: 140px; text-align: center;">
                                    <asp:Button ID="btnPost" CssClass="app_button" runat="server" Text="发送" Height="30px" Width="100px"
                                        OnClick="btnPost_Click" /></td>
                            </tr>
                        </table>

                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
