<%@ Page CodeBehind="sms_input.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.sms_input" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
<% @ Import Namespace="Webdisk" %>
		<link href="<%=xml.GetStyle()%>" rel="stylesheet" type="text/css">
		<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
  <title>撰写短信</title></HEAD>
	<body>
		<form runat="server">
		<div id="tip"></div>
			<TABLE class="form-table">
				<TR>
					<TD  class="label">收件人：</TD>
                    <TD>
						  <input id="To_User" class="input3" type="text" name="To_User" runat="server">
						  <asp:DropDownList ID="friend"  runat="server" >
							
						  </asp:DropDownList>
						  （多个用户用,分隔）
						  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="请输入收件人" Display="None"
							EnableViewState="False" ControlToValidate="To_User"></asp:RequiredFieldValidator>
                     </TD>
				</TR>
			    <TR>
					<TD class="label"> 标题：</TD>
					<TD>
                              <input id="title" class="input3" type="text" name="Title" runat="server" style="width: 371px;">
                              <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="请输入标题" Display="None"
								EnableViewState="False" ControlToValidate="Title"></asp:RequiredFieldValidator>
                    </TD>
				</TR>
			  <TR>
				<TD class="label">内容：</TD>
				<TD >
				  <textarea name="Content" cols="50" rows="7" class="input3" id="Content" runat="server"></textarea>
				  <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="请输入内容" Display="None"
					EnableViewState="False" ControlToValidate="Content"></asp:RequiredFieldValidator>
				</TD>
			  </TR>
              <TR>
                <TD class="label"></TD>
                <TD>
				<label><INPUT id=save type=checkbox name=save runat="server">
				同时保存到已发件箱</label>
				</TD>
			</TR>
		  <TR >
			<TD  class="label"></td><td>
				<input type="hidden" id="hiddenUser"  runat="server"/>
			  <input class="btn" type="button" value="发送" id="Submit2" name="Submit2" >
			  &nbsp;&nbsp;
			  <input class="btn" type="button" value="保存" id="Submit3" name="Submit3" >
			  &nbsp;&nbsp;
			  <input name="重置" type="reset" class="btn" value="清除">
			  &nbsp;&nbsp;
			  <input name="按钮" type="button" class="btn" value="关闭" id="close" >
			  <asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List" ShowMessageBox="True"
					ShowSummary="False"></asp:ValidationSummary>
			</TD>
		  </TR>
          </TABLE>
		</form>
		<script type="text/javascript">
			var SmsInput = {};
			SmsInput.init = function(){
				
				this.addEvent();
			}
			SmsInput.closeWindow = function(){
				if(typeof window.top.closeWindow == "undefined" ){
						window.close();
					}else{
						window.top.closeWindow();
					}
			}
			SmsInput.addEvent = function () {
			    var that = this;
			    //关闭窗口
			    $("#close").click(function () {
			        that.closeWindow();
			    });
			    //保存信息
			    $("#Submit3").click(function () {
			        that.submitMsg(true);
			    });
			    //发送信息
			    $("#Submit2").click(function () {
			        if ($("#save").attr("checked"))
			            that.submitMsg(true);
			        that.submitMsg(false);
			        this.parent.MsgCtr.init();
			    });
			    //指定收件人
			    $("#friend").change(function () {
			        var tag = $("#To_User");
			        var users = $.trim(tag.val());
			        var value = $(this).val();
			        if (value == "未指定") {
			            return false;
			        }
			        if (users == "") {
			            tag.val(value);
			        } else {
			            var arr = users.split(",");
			            if ($.inArray(value, arr) == -1) {
			                tag.val(users + "," + value);
			            }
			        }
			    });
			}
			/**
			*发送短信
			*/
			SmsInput.submitMsg = function(isSave){
				var that = this ;
				var error = $("#tip").html("");
				var _tousers = $.trim($("#To_User").val());
				var _save = $("#save").is(":checked") ? 1 : 0;
				var _user = $("#hiddenUser").val();
				var _title = $.trim($("#title").val());
				var _content = $.trim($("#Content").val());
				if(_tousers == "" ){
					error.html('<div class="tip" style="color:#f00;"><img src="pics/error_1.png" align="absMiddle">&nbsp;收件人不能为空</div>')
					return false ;
				}
				if(_title == "" ){
					error.html('<div class="tip" style="color:#f00;"><img src="pics/error_1.png" align="absMiddle">&nbsp;信息标题不能为空</div>')
					return false ;
				}
				if(_content == "" ){
					error.html('<div class="tip" style="color:#f00;"><img src="pics/error_1.png" align="absMiddle">&nbsp;信息内容不能为空</div>')
					return false ;
				}
				
				error.html('<div class="tip" style="color:#0EB516;"><img src="pics/msg_send.png" align="absMiddle">&nbsp;正在'+(isSave?"保存":"发送")+',请稍后...</div>');
				$.ajax({
					url :isSave ? "OtherHandler.ashx?cmd=SaveMessage": "OtherHandler.ashx?cmd=SendMessage",
					type :"POST",
					cache:false,
					data : {tousers:encodeURI(_tousers),save:encodeURI(_save),user:encodeURI(_user),title:encodeURI(_title),content:encodeURI(_content)},
					dataType : "json",
					success : function (data){
						if(data.code == 0){
							error.html('<div class="tip" style="color:#0EB516;"><img src="pics/msg_ok.png" align="absMiddle">&nbsp;'+(isSave?"保存":"发送")+'成功</div>');
							setTimeout(function(){
								that.closeWindow();
							},2000);
						}else{
							error.html('<div class="tip" style="color:#0EB516;"><img src="pics/msg_error.png" align="absMiddle">&nbsp;'+(isSave?"保存":"发送")+'失败,请重新尝试</div>');
						}
					}
				});
			}
			SmsInput.init();
		</script>
	</body>
</HTML>
