<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GGDetail.aspx.cs" Inherits="Webdisk.GGDetail" %>
<%@ Register TagPrefix="uc" TagName="uc1" Src="~/Top.ascx" %>
<%@ Register TagPrefix="uc" TagName="uc2" Src="bottom.ascx" %>

<!DOCTYPE html >

<html >
<head runat="server">
    <title>发布公告</title>
     <link href="css/common.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="js/artDialog/css/ui-dialog.css" />
    <script src="js/artDialog/dist/dialog-plus.js" type="text/javascript"></script>
</head>
<body>
    <!-- Header Start -->
    <uc:uc1 ID="top" runat="server" />
     <!-- Header End -->
    <form id="form1" runat="server">
    
       <!-- Content Start -->
    <div class="content">
        <div class="block01 mt20">
        	<div class="qusC ">
        		<div class="title">添加公告</div>
        		<input type="text" value="" id="noticName" class="textarea mt10" style="height:35px;line-height:35px;" placeholder="请在这里描述您的标题"/>
				<span class="label_text" style="color:#333;border-bottom: 1px solid #c5c5c5;display: block;"><span style="display:inline-block;width:75px;color: #848484;">发布类型</span>
				<label><input type="checkbox" name="type" value="1" checked="checked">外部显示</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label><input type="checkbox" name="type" value="2"  checked="checked">内部显示</label></span>
				<span class="label_text" id="role" style="color:#333;border-bottom: 1px solid #c5c5c5;display: block;"><span style="display:inline-block;width:75px;color: #848484;">角色</span>
				<label><input type="checkbox" name="role" value="3" checked="checked">管理</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label><input type="checkbox" name="role" value="1" checked="checked">教师</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label><input type="checkbox" name="role" value="2" checked="checked">学生</label></span>
        		<span class="label_text" style="color:#333;">公告内容</span><br>
        		<textarea class="textarea" id="content" name="content" placeholder="您可以继续在这里补充问题的细节" style="margin-bottom:5px;display:none;"></textarea>
				<iframe ID="Editor" name="Editor" src="HtmlEditor/index.html?ID=content" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:225px;width:100%;"></iframe>
        		<input type="button" class="but1 floatR" onclick="submitN();" value="添加公告" />
                <span class="font1 floatR" id="error"></span>
        	</div>
        </div>
            <input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>
    </div>
    <!-- Content End -->
    </form>
    <!-- Footer Start -->
    <uc:uc2 ID="bootom" runat="server" />
    
    <!-- Footer End -->
	<script type='text/javascript'>
	    $(function () {
	        $("[name='type']:checkbox").on("click", function () {
	            $("[name='type']:checkbox").each(function () {
	                if ($(this).attr("checked") && $(this).val() == "2") {
	                    $("#role").attr("style", "color:#333;border-bottom: 1px solid #c5c5c5;display: block;");
	                    $("[name='role']:checkbox").each(function () {
	                        $(this).attr("checked",true);
	                    })
	                } else {
	                    $("#role").attr("style", "display:none;");
	                    $("[name='role']:checkbox").each(function () {
	                        $(this).attr("checked", false);
	                    })
	                }
	            });
	        });
	    });
	function submitN(){
		var error = $("#error").html("")
		var title = $.trim($("#noticName").val());
		var html = $.trim(document.getElementById("Editor").contentWindow.window.frames["HtmlEditor"].document.getElementsByTagName("body")[0].innerHTML) ;
		if(title == ""){
			error.html("公告标题不能为空");
			return false;
		}
		if(html == ""){
			error.html("公告内容不能为空");
			return false;
		}
		var types  = [];
		$("[name='type']").each(function(){
			types.push(this.checked == true ? this.value : 0);
		});
		var roles  = [];
		$("[name='role']").each(function(){
			roles.push(this.checked == true ? this.value : 0);
		});
		$.ajax({
			url : "OtherHandler.ashx?cmd=AddGG",
			data : {title:encodeURI(title),content:encodeURI(html),type:types.join(","),role:roles.join(","),user:encodeURI($("#hiddenUser").val())},
			dataType : "json",
			cache:false,
			success : function(data){
				if(data.code == "0"){
					var d= dialog().content('<div style="font-size: 16px;font-weight: bold;" ><img src="images/ico_38.png" style="vertical-align: middle;"/>您的公告已提交，请耐心等待...</div>').showModal();
					setTimeout(function(){d.close().remove();location.href="GGMore.aspx";},2000);
				}else{
					error.html("添加公告失败，请稍后再试");
				}
			}
		});
	}
		
setPalceHolder($("#noticName"));
function setPalceHolder(tag){
	if(typeof Worker === "undefined"){
		tag.val(tag.attr("placeholder")).css({color:"#cecece"});
		tag.focus(function(){
			if($(this).val() == tag.attr("placeholder")){
				$(this).val("").css({color:""});
			}
		}).blur(function(){
			if($(this).val() == ""||$(this).val() == tag.attr("placeholder")){
				$(this).val(tag.attr("placeholder")).css({color:"#cecece"});
			}
		});
	}
}
	</script>
</body>
</html>
