<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="cm" uri="/commons-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>加班单核准</title>
<link href="../resources/style/base.css" rel="stylesheet" type="text/css"/>
<s:include value="../common/head.jsp" />
<script language="javascript" src="../resources/js/calendar/calendar.js"></script>
<script language="javascript">
var swapFlag="<s:property value='@com.hrmex.web.constants.ConstantCode$YesNo@YES'/>";

function changeSwap(){
	var isSwap=$("#swapSelect").val()==swapFlag;
	$("#swapTbody").css("display",isSwap?"":"none");
}

$(function(){
	changeSwap();
});

function calHours(){
	var d1=$("#beginTimeId").val();
	var d2=$("#endTimeId").val();
	if(d1==""||d2=="") {
		msgAlert("计算失败：实际加班时间填写不完整。");
		return;	
	}
	var date1 = new Date(
		parseInt(d1.substring(0,4),10), 
		parseInt(d1.substring(5,7),10)-1, 
		parseInt(d1.substring(8,10),10),
		parseInt(d1.substring(11,13),10), 
		parseInt(d1.substring(14,16),10)
	);
	var date2 = new Date(
		parseInt(d2.substring(0,4),10), 
		parseInt(d2.substring(5,7),10)-1, 
		parseInt(d2.substring(8,10),10),
		parseInt(d2.substring(11,13),10), 
		parseInt(d2.substring(14,16),10)
	);
	var msec=date2.getTime()-date1.getTime();
	if(msec<1) {
		checkMessage($("#endTimeId").get(0),"计算失败：“结束时间” 必须晚于 “开始时间”。");
		return;	
	}	
	var hour=Math.round(msec/360000.0)/10.0;
	$("#swapTotalId").val(hour);
}

//checkMessage($("#endTimeId").get(0),"加班结束时间早于了开始时间。");

function otherCheck(){
	var isSwap=$("#swapSelect").val()==swapFlag;
	if(isSwap){
		if($("#swapTotalId").val()==""){
			checkMessage($("#swapTotalId").get(0),"调休时间为必填项。");
			return false;	
		}
		if($("#swapEndId").val()==""){
			checkMessage($("#swapEndId").get(0),"调休截止日期为必填项。");
			return false;	
		}
	}
	return true;
}

</script>
</head>

<body>
<s:include value="../common/body.jsp" />

<s:form action="attOvertimeApplyConfirm" namespace="/att" onsubmit="return checkForm(this,otherCheck)" >
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr class="form_tr">
      <td align="right">员工：</td>
      <td valign="top"><s:property value="apply.applyEmplInfo.name"/></td>
    </tr>
    <tr class="form_tr">
      <td align="right">部门：</td>
      <td valign="top"><s:property value="apply.applyEmplInfo.emplOrg.name"/></td>
    </tr>
    <tr class="form_tr">
      <td align="right">申请加班时间：</td>
      <td valign="top">
      <s:date name="apply.beginTime" format="yyyy-MM-dd HH:mm"/>
      至
      <s:date name="apply.endTime" format="yyyy-MM-dd HH:mm"/>
	   （<s:property value="apply.overtimes"/>小时）
      </td>
    </tr>
    <tr class="form_tr">
      <td align="right">加班原因：</td>
      <td valign="top"><s:property value="apply.cause"/></td>
    </tr>
    <tbody id="yearBody" style="display:none;">
    </tbody>
    <tr class="form_tr">
      <td align="right"><span class="required">•</span>实际加班时间：</td>
      <td valign="top">
      <s:textfield id="beginTimeId" name="apply.beginTime" readonly="true" onClick="showDateTime(this)" cssClass="date_input" cssStyle="width:120px;">
      		<s:param name="value"><s:date name="apply.beginTime" format="yyyy-MM-dd HH:mm"/></s:param>
      </s:textfield>
      至
      <s:textfield id="endTimeId" name="apply.endTime" readonly="true" onClick="showDateTime(this)" cssClass="date_input" cssStyle="width:120px;">
      		<s:param name="value"><s:date name="apply.endTime" format="yyyy-MM-dd HH:mm"/></s:param>
      </s:textfield>
      </td>
    </tr>
    <tr class="form_tr">
      <td align="right">核准备注：</td>
      <td valign="top"><s:textarea name="apply.cause" value="" cssStyle="width:265px;height:50px;"/></td>
    </tr>    
    <tr class="form_tr">
      <td align="right"><span class="required">•</span>是否调休：</td>
      <td valign="top">
      	<s:select cssStyle="width:100px;" id="swapSelect" onchange="changeSwap()" title="是否调休 为必填项"  name="apply.swapFlag.id"  list='#request.SysCodeFinder.find("YES_NO")'  headerKey="" headerValue="" listKey="id" listValue="codeName"/>
      </td>
    </tr>
    <tbody id="swapTbody">
        <tr class="form_tr">
          <td align="right"><span class="required">•</span>调休时间：</td>
          <td valign="top"><s:textfield id="swapTotalId" name="apply.swapTotal" cssStyle="width:100px;"/>
          小时&nbsp;&nbsp;<a href="javascript:calHours()">[根据实际加班时间计算]</a></td>
        </tr>
        <tr class="form_tr">
          <td align="right"><span class="required">•</span>调休截止：</td>
          <td valign="top">
           <s:textfield name="apply.swapEnd" id="swapEndId" readonly="true" onClick="showDate(this)" cssClass="date_input" cssStyle="width:100px;">
                <s:param name="value"><s:date name="apply.swapEnd" format="yyyy-MM-dd"/></s:param>
          </s:textfield>     
          </td>
        </tr>
	</tbody>
    <tr class="form_tr">
      <td width="31%" align="right">&nbsp;</td>
      <td width="69%" valign="top">
        <input type="submit" name="button" id="button" value=" 核 准 " />
        &nbsp;
        <!-- back begin -->
        <input name="winID" type="hidden" value="${param.winID}" />
        <input type="button" onclick="iframeWindowClose('${param.winID}')" name="button" id="button" value="返 回" />
        <!-- back end -->
        
        <s:hidden name="apply.id"/>
        <s:hidden name="oper"/></td>
    </tr>
  </table>
</s:form>
</body>
</html>