<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>

<link rel="stylesheet" type="text/css" href="${ctxStatic}/fullcalendar/css/jquery-ui.css">
<div class="fancy" style="width: 460px; height:300px;">
	<h3>新建日程</h3>
    <form id="add_form" action="${ctx }/iim/myCalendar/add" method="post">
    <p>日程内容：<input type="text" class="input" name="event" id="event" style="width:320px" placeholder="简述日程主题..."></p>
    <p>日程地点：<input type="text" class="input" name="location" id="location" style="width:320px" placeholder="输入日程地点..."></p>
    <p id="p_start">开始时间：<input type="text" class="input datepicker" name="startdate" id="startdate" value="${date}" readonly>
    <span id="sel_start">
     <select name="s_hour">
    	<option value="00">00</option>
        <option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08" selected>08</option>
        <option value="09">09</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="23">23</option>
    </select>:
    <select name="s_minute">
    	<option value="00" selected>00</option>
        <option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08">08</option>
        <option value="09">09</option>
        <c:forEach begin="10" end="59" step="1" var="minute">
            <option value="${minute}">${minute}</option>
        </c:forEach>
    </select>
    </span>
    </p>
    <p id="p_end">结束时间：<input type="text" class="input datepicker" name="enddate" id="enddate" value="${enddate}" readonly>
       <span id="sel_end">
       <select name="e_hour">
    	<option value="00">00</option>
    	<option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08">08</option>
        <option value="09">09</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18" selected>18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="23">23</option>
    </select>:
    <select name="e_minute">
    	<option value="00" selected>00</option>
        <option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08">08</option>
        <option value="09">09</option>
        <c:forEach begin="10" end="59" step="1" var="minute">
            <option value="${minute}">${minute}</option>
        </c:forEach>
    </select>
    </span>
    </p>
    <p id="p_notice">提醒时间：<input type="text" class="input datepicker" name="noticedate" id="noticedate" value="${noticedate}" readonly>
      <span id="sel_notice">
      <select name="n_hour">
    	<option value="00">00</option>
    	<option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08" selected>08</option>
        <option value="09">09</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="23">23</option>
    </select>:
    <select name="n_minute">
    	<option value="00" selected>00</option>
        <option value="01">01</option>
        <option value="02">02</option>
        <option value="03">03</option>
        <option value="04">04</option>
        <option value="05">05</option>
        <option value="06">06</option>
        <option value="07">07</option>
        <option value="08">08</option>
        <option value="09">09</option>
        <c:forEach begin="10" end="59" step="1" var="minute">
            <option value="${minute}">${minute}</option>
        </c:forEach>
    </select>
    </span>
<%--
    </p>
    <label><input type="checkbox" value="0" id="allDay" name="allDay"> 全天</label>
    </p>
--%>
    <div class="sub_btn">
    <span class="del"><input type="button" class="btn btn_del" id="del_event" value="删除"></span>
    <input type="submit" class="btn btn_ok" value="确定"> 
    <input type="button" class="btn btn_cancel" value="取消" onClick="$.fancybox.close()"></div>
    </form>
</div>

<script type="text/javascript" src="${ctxStatic}/fullcalendar/js/jquery.form.min.js"></script>
<script type="text/javascript">
$(function(){

	$(".datepicker").datepicker();

	//提交表单
	$('#add_form').ajaxForm({
		beforeSubmit: showRequest, //表单验证
        success: showResponse //成功返回
    }); 
	
	//删除事件
	$("#del_event").click(function(){
		if(confirm("您确定要删除吗？")){
			var eventid = $("#eventid").val();
			$.post("${ctx }/iim/evolution.do?del",{id:eventid},function(msg){
				if(msg==1){//删除成功
					$.fancybox.close();
					$('#calendar').fullCalendar('refetchEvents'); //重新获取所有事件数据
				}else{
					alert(msg);	
				}
			});
		}
	});
});

function showRequest(){
	var events = $("#event").val();
	var location = $("#location").val();
	if(events==''){
		alert("请输入日程内容！");
		$("#event").focus();
		return false;
	}else if(location==''){
	    alert("请输入日程地点！");
	    $("#location").focus();
	    return false ;
    }
}

function showResponse(responseText, statusText, xhr, $form){
	if(statusText=="success"){	
		if(responseText==1){
			$.fancybox.close();
			$('#calendar').fullCalendar('refetchEvents'); //重新获取所有事件数据
		}else{
			alert(responseText);
		}
	}else{
		alert(statusText);
	}
}
</script>