<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="col_StuHeader.ascx.cs" Inherits="MTCUN.Mobile.User_Col.col_StuHeader" %>
<%@ Import Namespace="MTCUN" %>

<script src="../JScript/Cookie.js" type="text/javascript"></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>
<style type="text/css">
    .header_menu {
        text-align: right;
    }

    #header {
        text-align: right;
    }

    #header_menu, #header_menu ul {
        text-align: right;
    }

    #header_sub {
        right: 0px;
        left: auto;
        bottom: auto;
    }

        #header_sub .dian {
            right: 20px;
            left: auto;
        }
</style>
<div id="header">
    <div id="header_menu">
        <ul>
            <li class="header_menu_item" onclick="window.location='index.aspx';" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">桌面
            </li>
            <li class="header_menu_item" onclick="window.location='Topic.aspx';" style="position: relative">消息
                <div id="divNumBg" style="display: none; border-radius: 10px; position: absolute; background-color: rgba(255, 0, 0,0.9); color: #ffffff; width: 18px; height: 18px; bottom: 1px; right: 1px"></div>
                <div id="divNum" style="position: absolute; color: #ffffff; width: 18px; height: 18px; line-height: 18px; vertical-align: middle; text-align: center; bottom: 1px; right: 1px"></div>
            </li>
            <li class="header_menu_item" onclick="setMode()" id="sysMode" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">M/P</li>
            <li class="header_menu_item" onclick="OpenSub(1)" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">菜单
            </li>
        </ul>
    </div>
    <div id="header_sub" class="header_sub_bg" style="display: none; position: absolute; text-align: left; padding-top: 4px; right: 0px">
        <div class="header_sub_bg" style="position: absolute; top: -10px; right: 20px; width: 10px; height: 10px; border-top-left-radius: 7px; border-top-right-radius: 7px;"></div>
        <div id="items" style="text-align: left; margin-top: 4px;"></div>
        <%--<a href="exit.aspx">退出系统</a>--%>
    </div>
</div>

<span style="display: none; visibility: hidden">
    <audio id="bgaudio">
<source src='<%=swq.SystemVirtualPath + "Sound/msg.mp3" %>' type="audio/mpeg">
</audio>
</span>


<script type="text/javascript">
    function OpenSub(id) {
        if (header_sub.style.display == 'none') {
            header_sub.style.display = 'block';
        }
        else {
            header_sub.style.display = 'none';
        }

        items.innerHTML = document.getElementById(__mt_SelectedModule).innerHTML;
    }

    function setMode() {
        var num = __mt__getModeCookie();
        if (num == 1) {
            sysMode.innerHTML = '平';
            __mt__setModeCookie(0);
            location.replace(location.href);
        }
        else {
            sysMode.innerHTML = '手';
            __mt__setModeCookie(1);
            location.replace(location.href);
        }
    }

    function defaultMode() {
        var num = __mt__getModeCookie();
        if (num == 0) {
            document.getElementById("sysMode").innerHTML = '平';
        }
        else {
            document.getElementById("sysMode").innerHTML = '手';
        }
    }

    defaultMode();

    //初始化数目。
    setMsgCount(__mt_newmsgcount,true);
</script>

<div style="display: none">
    <div id="menu_1" style="text-align: right" runat="server" visible="false">
        <div id="group_2" class="menu_group" style="border-radius: 5px; padding: 3px; text-align: center; padding-left: 20px; padding-right: 20px;">
            <div style="text-align: center"><b>学员中心</b></div>
            <div>
                <ul class="sub_menus">

                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="LessonTable.aspx">我的课表</a>
                    </li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="StuClass.aspx">我的班级</a>
                    </li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="StuPayment.aspx">我的钱包</a>
                    </li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="FoundClass.aspx">我要购班</a></li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="SubAccount.aspx">切换帐号</a> </li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="Password.aspx">修改密码</a> </li>
                    <li class="header_menu_item" onmouseover="__mt_NavMouseover(this,'header_menu_item')" onmouseout="__mt_NavMouseout(this,'header_menu_item')">
                        <a href="exit.aspx">退出系统</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>
