<%@ Register TagPrefix="webdiyer" Namespace="Wuqi.Webdiyer" Assembly="AspNetPager" %>
<%@ Page CodeBehind="user_sms.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.user_sms" %>

		<% @ Import Namespace="Webdisk" %>
		<link href="<%=xml.GetStyle()%>" type=text/css rel=stylesheet>
        		<%--<link href="css/BaseStyle.css" rel="stylesheet" type="text/css" />--%>
		<script type="text/javascript" language="javascript" src="js/function.js"></script>

<form id=Form1 method=post runat="server"><FONT face=宋体></FONT><br>
<div class="menuBlock">
	<div class="menuHead" style="overflow:hidden;border-bottom: 1px dashed #cfcfcf;">
	<h2 style="font-size: 18px;color: #1EA7DF;"><img src="pics/menu_file_cut.gif" align="absMiddle"> 短信管理——<asp:label id=curr runat="server"></asp:Label></h2>
	</div>
	
			<div class="menubox">
			<input onclick=showly(); type=button class="but5 sendMsg" value="撰写短信" />
			<INPUT class="but5 deleteMsg" id=Submit1 type=button value=删除选中 name=Submit1 /> 
			</div>
		<div  class="menuBox2">
            <div class="mListT">
                <span class="l1">
                    <input name="" id="codeCheckAll"  type="checkbox" value="全选" />
		        </span>
                <span class="l3">状态</span> 
		        <span class="l3" id="ToUserTitle" runat="server">收件人</span>
                <span class="l3" id="FromUserTitle" runat="server">发件人</span>
                <span class="l7">主题</span>
                <span class="l3">日期</span>
            </div>
            <ul class="menuList" id="codeList">
                <asp:repeater runat="server" id="rptSmsList" 
                    onitemdatabound="rptSmsList_ItemDataBound">
                    <ItemTemplate>
                        <li>
                            <span class="l1">
                                <INPUT class=chkSelect type=checkbox value='<%#DataBinder.Eval(Container.DataItem,"id")%>' name=checkbox>
		                    </span>
                            <span class="l3"><%# ShowType(DataBinder.Eval(Container.DataItem, "InceptTime").ToString()) %></span> 
		                    <span class="l3" id="ToUser" runat="server"><a class="linked" onclick="showDialog('查看用户信息',this)" data-href='userinfo.aspx?username=<%# Eval("To_User").ToString() %>'><%# Eval("To_User").ToString() %></a></span>
                            <span class="l3" id="FromUser" runat="server"><a class="linked" onclick="showDialog('查看用户信息',this)" data-href='userinfo.aspx?username=<%# Eval("From_User").ToString() %>'><%# Eval("From_User").ToString() %></a></span>
                            <span class="l7"><a class="linked" onclick="readMsg('查看及回复短信',this)" data-href='sms_show.aspx?id=<%# Eval("id").ToString() %>'><%# Eval("Title").ToString()%></a></span>
                            <span class="l3"><%# Eval("SendTime").ToString()%></span>
                        </li>
                    </ItemTemplate>
                </asp:repeater>
                <input type="hidden" id="H_itemtCount"  runat="server"/>
	            <input type="hidden" id="H_currentPage"  runat="server"/>
                <input type="hidden" value="" id="H_pagesize" runat="server" />
				<div class="pageList" id="page"> </div>
            </ul>
			
			<INPUT id=HdnSelectedValues type=hidden name=HdnSelectedValues runat="server"> 
            </DIV></div>
			
</FORM>
<script language=javascript>

    var MsgCtr = {};
    MsgCtr.iframeDialog = null;
    MsgCtr.urlParam = {};
    MsgCtr.dialogShow = function (href, title) {
        var that = this;
        var d = this.iframeDialog = dialog({
            content: "<iframe src='" + href + "' frameborder='0' style='border:none;width:500px;height:350px;'></iframe>",
            title: title
        });
        d.showModal();
    }

    /**
    *关闭模态窗口
    */
    MsgCtr.closeWindow = function (flag) {
        if (this.iframeDialog) {
            this.iframeDialog.close().remove();
            this.iframeDialog = null;
        }
    }
    /***
    ** 获取url中的参数
    ***/
    MsgCtr.initUrlParam = function () {
        var s = $("#wdContent").attr("src");
        if (s != "") {
            if (s.indexOf('?') < 0) {
                this.urlParam = {};
            } else {
                var sarr = s.substr(s.indexOf('?') + 1).split("&");
                var tarr;
                for (i = 0; i < sarr.length; i++) {
                    tarr = sarr[i].split("=");
                    this.urlParam[tarr[0]] = tarr[1];
                }
            }
        }
    }
    /***
    **获取url中的指定参数，无该值则返回空字符
    ***/
    MsgCtr.getUrlParam = function (param) {
        return typeof this.urlParam[param] == "undefined" ? "" : this.urlParam[param];
    }
    /***
    **刷新窗口 
    ***/
    MsgCtr.refreshDialog = function (href, title) {
        this.iframeDialog.content("<iframe src='" + href + "' frameborder='0' style='border:none;width:500px;height:350px;'></iframe>");
        this.iframeDialog.title(title);
    }
    MsgCtr.addEvent = function () {
        var that = this;
        //全选反选
        $("#codeCheckAll").click(function () {
            var checked = this.checked;
            $(".chkSelect").each(function () {
                this.checked = checked;
                $(this).parents("li")[checked ? "addClass" : "removeClass"]("checked");
            });
        });
        $(".chkSelect").click(function () {
            var flag = $(".chkSelect").size() == $(".chkSelect:checked").size();
            var checked = this.checked;
            $(this).parents("li")[checked ? "addClass" : "removeClass"]("checked");
            $("#codeCheckAll")[0].checked = flag;
        });
        $("#codeList li").click(function (event) {
            if (event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a") {
                $(this).find(".chkSelect")[0].click();
            }
        });
        //删除勾选
        $("#Submit1").click(function () {
            var checked = [];
            $(".chkSelect:checked").each(function () {
                checked.push(this.value);
            });
            var d = dialog();
            if (checked.length == 0) {
                d.content("您没有勾选任何内容！");
                d.showModal();

                that.autoClose(d);
            } else {
                that.submitDelete(checked);
            }
        });
    }
    MsgCtr.submitDelete = function (checked) {
        var that = this;
        var d = dialog();
        d.showModal();
        $.ajax({
            url: "OtherHandler.ashx?cmd=DeleteMessage",
            type: "POST",
			cache:false,
            data: { id: checked.join(","), type: this.getUrlParam("type") },
            dataType: "json",
            success: function (data) {
                d.content(data.msg);
                that.autoClose(d);
                if (data.code == 0) {
                    //重新获取该页内容
                    that.getPage($("#H_currentPage").val());
                }
            }
        });
    }
    MsgCtr.autoClose = function (d) {
        setTimeout(function () {
            d.close().remove();
        }, 2000);
    }
    MsgCtr.page = function () {
        var that = this;
        var maxlength = parseInt($("#H_itemtCount").val());
        $("#page").pagination(maxlength, {
            prev_text: '< 上一页',
            next_text: '下一页 >',
            items_per_page: parseInt($("#H_pagesize").val()),
            num_display_entries: 5,
            current_page: parseInt($("#H_currentPage").val()),
            num_edge_entries: 2,
            link_to: "javascript:void(0);",
            callback: function (page_id, panel) {
                var self = this;
                that.getPage(page_id);
            }
        });
    }
    MsgCtr.getPage = function (page) {
        var that = this;
        var d = dialog();
        d.showModal();
        $.ajax({
            url: $("#wdContent").attr("src"),
            data: { page: page },
            type: "POST",
			cache:false,
            dataType: "html",
            success: function (data) {
                $("#wdContent").empty().append(data);
                d.close().remove();
            }
        });
    }
    MsgCtr.init = function () {
        this.initUrlParam();
        this.addEvent();
        this.page();
    }
    MsgCtr.init();
    var refreshWindow = function (href, title) {
        MsgCtr.refreshDialog(href, title);
    }
    var closeWindow = function (flag) {
        MsgCtr.closeWindow(flag);
    }
    function showDialog(title, tag) {
        MsgCtr.dialogShow($(tag).data("href"), title);
    }
    function readMsg(title, tag) {
        $(tag).parents("li").find("img").attr("src", "pics/m_olds.gif");
        MsgCtr.dialogShow($(tag).data("href"), title);
    }
    function showly() {
        MsgCtr.dialogShow('sms_input.aspx', '编辑短信');
    }
</script>
	
