<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");
%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%@page import="com.eactive.eai.rms.common.util.CommonConstants"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>

<script language="javascript" >
var isDetail = false;

function isValid() {
	if($('input[name=BASE_DT]').val() == "") {
		alert("기준일자를 입력하여 주십시요.");
		return false;
	} else if($('input[name=LRCL_DT]').val() == "") {
		alert("음력일자 입력하여 주십시요.");
		return false;
	}

	return true;
}

function detail( base_dt, lrcl_dt, lpmn_yn, holday_cd) {
	if (!isDetail) return;
	$("input[name=BASE_DT]").val(base_dt);
	$("input[name=LRCL_DT]").val(lrcl_dt);
	$("select[name=LPMN_YN]").val(lpmn_yn);
	$("select[name=HOLDAY_CD]").val(holday_cd);
	$("input[name=BASE_DT]").attr('readonly', true);
//	$("select[name=holday_cd]").attr('disabled', true);
}

$(document).ready(function() {
	var returnUrl = getReturnUrlForReturn();

	var url = '<c:url value="/bap/admin/schedule/businessDayMan.json" />';
	var base_dt = "${param.base_dt}";
	var lrcl_dt = "${param.lrcl_dt}";
	var lpmn_yn = "${param.lpmn_yn}";
	var holday_cd = "${param.holday_cd}";
	if (base_dt != "" && base_dt != "null") {
		isDetail = true;
	}

	detail(base_dt, lrcl_dt, lpmn_yn, holday_cd);

	$("#btn_modify").click(function() {
		if (!isValid()) return;

		if (isDetail) {
			if ( confirm( "수정 하시겠습니까?" ) != true ) return;
		} else {
			if ( confirm( "등록 하시겠습니까?" ) != true ) return;
		}
		
		//공통부만 form으로 구성
		var postData = $('#ajaxForm').serializeArray();

		if (isDetail) {
			postData.push({ name: "cmd" , value:"UPDATE"});
		} else {
			postData.push({ name: "cmd" , value:"INSERT"});
		}
		$.ajax({
			type: "POST",
			url: url,
			data: postData,
			success: function(args) {
				alert("저장 되었습니다.");
				goNav(returnUrl);//LIST로 이동
			},
			error: function(e) {
				alert(e.responseText);
			}
		});
	});
	
	$("#btn_delete").click(function() {

		if ( confirm( "삭제 하시겠습니까?" ) != true ) return;
		
		var postData = $('#ajaxForm').serializeArray();
		postData.push({ name: "cmd", value: "DELETE"});
		postData.push({ name: "BASE_DT" , value: $("select[name=BASE_DT]").val()});
		$.ajax({
			type: "POST",
			url: url,
			data: postData,
			success: function(args) {
				alert("삭제 되었습니다.");
				goNav(returnUrl);//LIST로 이동
			},
			error: function(e) {
				alert(e.responseText);
			}
		});
	});	
	$("#btn_previous").click(function() {
		goNav(returnUrl);//LIST로 이동
	});

	buttonControl(isDetail);
	titleControl(isDetail);
});
 
</script>
</head>
	<body>
		<div class="right_box">
			<div class="content_top">
				<ul class="path">
					<li><a href="#">${rmsMenuPath}</a></li>
				</ul>
			</div><!-- end content_top -->
			<div class="content_middle">
				<div class="search_wrap">
					<img src="<c:url value="/img/btn_delete.png"/>" alt="" id="btn_delete" level="W" status="DETAIL"/>
					<img src="<c:url value="/img/btn_modify.png"/>" alt="" id="btn_modify" level="W" status="DETAIL,NEW" />
					<img src="<c:url value="/img/btn_previous.png"/>" alt="" id="btn_previous" level="R" status="DETAIL,NEW"/>	
				</div>
				<div class="title">영업일</div>	
				
				<form id="ajaxForm">
					<table class="table_row" cellspacing="0">
						<!-- 공통-->
						<tr>
							<th>기준일자</th><td><input type="text" maxlength="8" name="BASE_DT" /> </td>
						</tr>
						<tr>
							<th>음력일자</th><td><input type="text" maxlength="8" name="LRCL_DT" /> </td>
						</tr>
						<tr>
							<th style="width:180px;">윤달여부</th>
							<td><div class="select-style"><select name="LPMN_YN">
									<option value="0">아니요</option>
									<option value="1">예</option>
								</select></div>
							</td>
						</tr>
						<tr>
							<th style="width:180px;">일자유형</th>
							<td><div class="select-style"><select name="HOLDAY_CD">
									<option value="1">영업일</option>
									<option value="2">휴일</option>
									<option value="3">토요일</option>
								</select></div>
							</td>
						</tr>
					</table>
				</form>
			</div><!-- end content_middle -->
		</div><!-- end right_box -->
	</body>
</html>
