<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="ckeditor" uri="http://ckeditor.com" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags" %>

<c:choose>
<c:when test="${registerFlag eq 'modify'}">
	<c:set var="actionUrl" value="/fa/edu/update.do" />
</c:when>
<c:otherwise>
	<c:set var="actionUrl" value="/fa/edu/add.do" />
</c:otherwise>
</c:choose>

<form:form commandName="eduVO" id="detailForm" name="detailForm" method="post" action="${actionUrl}">
	<form:hidden path="idx" />
	<form:hidden path="writer" value="${loginUserVO.userid}" />
	<form:hidden path="userId" />
	<div id="table">
		<table class="tbl_add" width="100%" border="0" cellpadding="0" cellspacing="0">
			<colgroup>
	   			<col width="149"/>
	   			<col width="350"/>
	   			<col width="149"/>
	   			<col width="350"/>
	   		</colgroup>	   			
	   		<tr>
   				<th><spring:message code="fa.edu.name" /></th>
   				<td class="search">
   					<form:input path="name"/>
   					<button type="button" id="btnFindMember"><spring:message code="button.goFind" /></button>
   				</td>
	   			<th><spring:message code="fa.edu.eduTerm" /></th>
				<td class="form_day">
					<form:input path="stdate" /> ~ <form:input path="eddate" />
				</td>
			</tr>
			<tr>
				<th><spring:message code="fa.edu.eduCourse" /></th>
				<td class="form_select">
					<form:select path="eduCourse">
			    		<c:forEach var="item" items="${eduCourseList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>
					</form:select>
				</td>
				<th><spring:message code="fa.edu.eduPlace" /></th>
				<td class="form_select">
					<form:select path="eduPlace">
						<c:forEach var="item" items="${eduPlaceList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>
				</td>
			</tr>
			<tr>
				<th><spring:message code="fa.edu.place1" /></th>
				<td class="form_select" id="tdPlace">
					<form:select path="place1">
						<c:forEach var="item" items="${placeList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>
		    	<td class="form_select" colspan="2" >
		    		<form:select path="place2">
						<c:forEach var="item" items="${place2List}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>
		    	</td>
			</tr>	
	   		<tr>
	   			<th><spring:message code="fa.edu.birth" /></th>
				<td class="form_search">
					<form:input path="birth"/>
				</td>
	   			<th><spring:message code="fa.edu.position" /></th>
				<td class="form_select">
					<form:select path="position">
						<c:forEach var="item" items="${positionList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>	
				</td>			
	   		</tr>
	   		<tr>
	   			<th><spring:message code="fa.edu.sdate" /></th>
				<td class="form_select">
					<form:input path="sdate"/>
				</td>
	   			<th><spring:message code="fa.edu.jobtype" /></th>
				<td class="form_select">
					<form:select path="jobtype">
						<c:forEach var="item" items="${jobtypeList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>
				</td>
	   		</tr>
	   		<tr>
	   			<th><spring:message code="fa.edu.scholarship" /></th>
				<td colspan="3" class="form_select scholarship">
					<form:select path="scholarship">
						<c:forEach var="item" items="${scholarshipList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>					
		    		</form:select>
				</td>
	   		</tr>
	   		<tr>
	   			<th><spring:message code="fa.edu.pdate" /></th>
				<td class="form_search">
					<form:input path="pdate"/>
				</td>
				<th><spring:message code="fa.edu.adate" /></th>
				<td class="form_search">
					<form:input path="adate"/>
				</td>
	   		</tr>
	   		<tr>
	   			<th><spring:message code="fa.edu.comment" /></th>
				<td colspan="3">
					<form:textarea path="comment" cssClass="ta"/>
				</td>
	   		</tr>
	   		<tr>
	   			<th>주의사항</th>
				<td class="notice" colspan="3">
					<span>* 외사경찰일 경우 회원찾기로 정보를 입력할 수 있습니다.</span>
				</td>
	   		</tr>
	   	</table>
	</div>
</form:form>

<div class="boardviewinfo">
	<ul class="right btn-style">
		<li>
	     	<a href="javascript:fn_submit();"><spring:message code="button.goSave" /></a>
	    </li>
	    <li>
	    	<a href="javascript:fn_delete();"><spring:message code="button.goDelete" /></a>
	    </li>
	    <li>	
			<a href="javascript:history.back();"><spring:message code="button.goList" /></a>
	    </li>
	</ul>
</div>

<ct:memberSelectPop /> 

<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="eduVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
<!--
function fn_submit(){
	var registerFlag = '${registerFlag}',
		isSubmit = true;
	
	if (registerFlag == 'modify') {
		isSubmit = confirm('<spring:message code="confirm.msg.askUpd" />');
	}
	
	if (isSubmit) {
		var frm = document.detailForm;
		if (!validateEduVO(frm)) {
			return;
		} else {
			frm.submit();
		}
	}
}

function fn_delete() {
	if (confirm('<spring:message code="confirm.msg.askDel" />')) {
		document.detailForm.action = '<c:url value="/fa/edu/delete.do" />';
		document.detailForm.submit();
	}
}

// 사용자 선택 후 실행할 콜백함수
function cbOnSelectMemeber(member) {
	$("#userId").val(member.userid);
	$("#name").val(member.name);
	$("#place1").val(member.place1);
	$("#place1").trigger("change");
	$("#place2").val(member.place2);
	$("#scholarship").val(member.scholarship);
	$("#position").val(member.position);
	$("#jobtype").val(member.jobtype);
	$("#sdate").val(member.sdate);
	$("#pdate").val(member.pdate);
	$("#adate").val(member.adate);
}

function openMemeberSelectPopup(){
	if ($("#name").val().trim().length <= 0){
		alert("<spring:message code="member.msg.invalidNameLength" />");
		$("#name").focus();
		return false;
	}
	
	if (MemberSelectPopup)
		MemberSelectPopup.openAndFill({name: $("#name").val()}, cbOnSelectMemeber);
}

$(document).ready(function(){
	$('#stdate').datepicker({dateFormat: 'yy-mm-dd'});
	$('#eddate').datepicker({dateFormat: 'yy-mm-dd'});
	$('#birth').datepicker({dateFormat: 'yy-mm-dd'});
	$('#sdate').datepicker({dateFormat: 'yy-mm-dd'});
	$('#pdate').datepicker({dateFormat: 'yy-mm-dd'});
	$('#adate').datepicker({dateFormat: 'yy-mm-dd'});
	
	$('#place1').change(function(){
		var place1 = this.value;
		
		$.ajax({
			async: false,
			url: '/code/place2.json',
			data: {code1: place1},
			type: 'get',
			dataType: 'json',
			success: function(result){
				var _data = result.data,
					_selPlace2 = $('#place2');
				
				_selPlace2.empty();
				
				if (_data.length > 0) {
					if (_selPlace2.length == 0) {
						_selPlace2 = $('<select id="place2" name="place2">');
					}
					for (var i=0; i < _data.length; i++){
						var _opt = $('<option>').html(_data[i].codenm).val(_data[i].code2);
						_selPlace2.append(_opt);
					}
					$('#tdPlace').append(_selPlace2);
				}
			}
		});
	});

	$("#btnFindMember").click(function(){
		openMemeberSelectPopup();
	});
	$("#name").keydown(function(e){
		if (e.keyCode == 13){
			openMemeberSelectPopup();			
		}
	});
});
-->
</script>