<%@ 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="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>

<form:form commandName="memberVO" name="addForm" method="post" enctype="multipart/form-data" id="addForm">
	<div class="memberAdd" id="table">
		<table class="tbl_add" width="100%" border="0" cellpadding="0" cellspacing="0">
			<colgroup>
				<col width="110" >
				<col width="250" >
				<col width="110" >
				<col width="250" >
			</colgroup>
			  <tr>
			  	<th><spring:message code="member.view.name"/></th>
			    <td>
			    	<span class="tbl_addtext"><spring:message code="member.view.hangul"/></span><form:input path="name" /><br/>
			    	<span class="tbl_addtext"><spring:message code="member.view.hanja"/></span><form:input path="chnname"/>
			    </td>
			    <th><spring:message code="member.view.userid"/></th>
			    <td>
					<c:if test="${registerFlag == 'create'}">
				    	<spring:bind path="memberVO.userid"> 
				    	<input type="text" name="${status.expression }"	id="${status.expression }" onkeydown="Member.checkID(this.value);" onkeyup="Member.checkID(this.value);"/><br>
					    <span id="userid_desc" <c:if test="${status.error}">style="color:#f00;"</c:if>>
					    	<c:if test="${!status.error}"><spring:message code="member.msg.userid"/></c:if>
					    	<c:if test="${status.error}">아이디 </c:if>${status.errorMessage }
					    </span>
					    </spring:bind>
			    	</c:if>
			    	<c:if test="${registerFlag == 'modify'}">
			    		<form:hidden path="userid"/>
			    		<c:out value="${memberVO.userid}"/>
			    	</c:if>
			    </td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.password"/></th>
			    <td colspan="3">
			    	<input type="password" name="passwd" onkeyup="Member.chkPW(this.value);" onkeydown="Member.chkPW(this.value);" />
			    	<span id="pw_desc"></span> 
		    	</td>
			  </tr>  
			  <tr>
			    <th>비밀번호 확인</th>
			    <td colspan="3">
			    	<input type="password" name="passwd_confirm" onkeyup="Member.checkPWD(this.value);" onkeydown="Member.checkPWD(this.value);"/>
			    	<span id="pwd_desc"><spring:message code="member.msg.password"/></span>
			    	<c:if test="${registerFlag == 'create'}">
			    		<input type="hidden" name="checkPwd" value="N"/>
			    	</c:if>
			    	<c:if test="${registerFlag == 'modify'}">
			    		<input type="hidden" name="checkPwd" value="Y"/>
			    	</c:if>
		    	</td>
			  </tr>  
			  <tr>
			    <th><spring:message code="member.view.address"/></th>
			    <td colspan="3"><form:input path="address"/></td>
			  </tr>
			  <%-- 가족사항 삭제 이우현경위 요청(2021-04-20)
				  <tr>
				    <th><spring:message code="member.view.family"/></th>
				    <td colspan="3"><form:input path="family"/></td>
				  </tr>  
				  <tr>
			  --%>
			    <th><spring:message code="member.view.charge"/></th>
			    <td><form:input path="charge"/></td>
			    <th><spring:message code="member.view.email"/></th>
			    <td><form:input path="email"/></td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.ophone"/></th>
			    <td><form:input path="ophone"/></td>
			    <th><spring:message code="member.view.sdate"/></th>
			    <td><form:input path="sdate" readonly="readonly"/>
			    </td>
			  </tr>
			  <tr>
			    <%-- 일반전화 삭제 이우현경위 요청(2021-04-20)
			    <th><spring:message code="member.view.hphone"/></th>
			    <td><form:input path="hphone"/></td>
			    --%>
			    <th><spring:message code="member.view.pdate"/></th>
			    <td colspan="3"><form:input path="pdate" readonly="readonly"/></td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.cphone"/></th>
			    <td><form:input path="cphone"/></td>
			    <th><spring:message code="member.view.adate"/></th>
			    <td><form:input path="adate" readonly="readonly"/></td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.place1"/></th>
			    <td class="form_select">
			    	<form:select path="place1" onchange="fncGetCombo($('#place2_div'), 'place2', this.value);">
			    		<c:forEach var="item" items="${place1List}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>
			    	</form:select>			    	
			    </td>
			    <td colspan="2">			
			    	<span id="place2_div"></span>
			    </td>
			 </tr>
			 <tr>
			    <th><spring:message code="member.view.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>
			    <th><spring:message code="member.view.place3"/></th>
			    <td><span id="place3_div"></span></td>
			 </tr>
			 <tr>
			    <th><spring:message code="member.view.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>
			    <th><spring:message code="member.view.duties"/></th>
			    <td class="form_select">
		    		<form:select path="duties">
			    		<c:forEach var="item" items="${dutiesList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>
			    	</form:select>
			    </td>
			 </tr>
			 <tr>
			    <th><spring:message code="member.view.scholarship"/></th>
			    <td class="form_select">
			    	<form:select path="scholarship">
			    		<c:forEach var="item" items="${scholarshipList}">
			    			<form:option value="${item.code2}">${item.codenm}</form:option>
			    		</c:forEach>
			    	</form:select>
			    </td>
			    <th><spring:message code="member.view.inout"/></th>
			    <td colspan="3" class="form_radio">
			    	<form:radiobutton path="inout" value="i"/><spring:message code="member.view.inout.i"/> 
			   	 	<form:radiobutton path="inout" value="o"/><spring:message code="member.view.inout.o"/>  
			   	 	<form:radiobutton path="inout" value="d"/><spring:message code="member.view.inout.d"/>
			   	 	<c:choose>
			   	 		<c:when test="${empty memberVO or memberVO.usegrade eq 0}"><input type="hidden" name="usegrade" value="14"/></c:when>
			   	 		<c:otherwise><input type="hidden" name="usegrade" value="${memberVO.usegrade}"/></c:otherwise>
			   	 	</c:choose> 
			    </td>
			  </tr>
			  <tr>
			 	<th><spring:message code="member.view.excareer_y"/></th>
			    <td class="form_day">
			    	<form:select path="excareer_y">
			    		<c:forEach var="item" begin="0" end="20" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>년</span>
			    	<form:select path="excareer_m">
			    		<c:forEach var="item" begin="0" end="11" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>개월</span>
			    </td>
			    <th><spring:message code="member.view.excareer1_y"/></th>
			    <td class="form_day">
			    	<form:select path="excareer1_y">
			    		<c:forEach var="item" begin="0" end="20" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>년</span>
			    	<form:select path="excareer1_m">
			    		<c:forEach var="item" begin="0" end="11" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>개월</span>
			    </td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.excareer2_y"/></th>
			    <td class="form_day">
			    	<form:select path="excareer2_y">
			    		<c:forEach var="item" begin="0" end="20" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>년</span>
			    	<form:select path="excareer2_m">
			    		<c:forEach var="item" begin="0" end="11" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>개월</span>
			    </td>
			    <th><spring:message code="member.view.excareer3_y"/></th>
			    <td class="form_day">
					<form:select path="excareer3_y">
			    		<c:forEach var="item" begin="0" end="20" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>년</span>
			    	<form:select path="excareer3_m">
			    		<c:forEach var="item" begin="0" end="11" varStatus="status">
			    			<form:option value="${status.index}">${status.index}</form:option>
			    		</c:forEach>
			    	</form:select>
			    	<span>개월</span>
				</td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.explace"/></th>
			  <c:choose>
			  <c:when test="${registerFlag eq 'modify'}">
			  	<td><input type="text" name="explace"/></td>
			  	<th><spring:message code="member.view.division"/></th>
			  	<td class="form_radio">
			    	<form:radiobutton path="usertype" value="f"/><spring:message code="member.type.fa"/> 
			   	 	<form:radiobutton path="usertype" value="g"/><spring:message code="member.type.nofa"/>  
			    </td>
			  </c:when>
			  <c:otherwise>
				<td colspan="3">
					<form:hidden path="usertype"/>
					<input type="text" name="explace"/>
				</td>
			  </c:otherwise>
			  </c:choose>
			  </tr>
			  <tr>
			  	<th><spring:message code="member.view.userimg"/></th>
			  	<td>
			  		<input type="file" name="img"/>
			  		<c:if test="${memberVO.userimg != null and (memberVO.userimg != '' or memberVO.userimg != ' ')}">
			  			<form:hidden path="userimg"/>
			  			<br><input class="fileDelete" type="checkbox" target="userimg" value="${memberVO.userimg}">기존 이미지를 삭제합니다.
			  		</c:if>
			  	</td>
			  	<th><spring:message code="member.view.usersign"/></th>
			  	<td>
			  		<input type="file" name="sign"/>
			  		<c:if test="${memberVO.usersign != null and (memberVO.usersign != '' or memberVO.usersign != ' ')}">
			  			<form:hidden path="usersign"/>
			  			<br><input class="fileDelete" type="checkbox" target="usersign" value="${memberVO.usersign}">기존 이미지를 삭제합니다.
			  		</c:if>
			  		</td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.etc"/></th>
			    <td colspan="3"><form:textarea path="comment_" rows="2" cols="80" /></td>
			  </tr>
			  <tr>
			    <th><spring:message code="member.view.warning"/></th>
			    <td colspan="3" class="notice">
			    	* 비밀번호는 이전비밀번호 확인 없이 그대로 수정됩니다.<br>
					* 사진 수정 시에는 삭제를 꼭 체크하고 등록해 주셔야 이전 이미지가 삭제 됩니다.<br>
			    </td>
			  </tr>
		</table>
	</div>
</form:form>
<div class="boardviewinfo">
	<ul class="right btn-style">
		<li>
			<a href="javascript:fn_goAdd();">
           	<spring:message code="button.${registerFlag == 'modify' ? 'modify' : 'memberAdd'}"/>
           </a>
        </li>
		<li>
		 	<a href="javascript:fn_selectList();"><spring:message code="button.list"/></a>
        </li>            
	</ul>	
</div>
<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="memberVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
$(document).ready(function(){
	$('#place1').change();
	$("#sdate").datepicker({
		dateFormat: 'yy-mm-dd',
		onSelect: function(date){
			$("#sdate").val(date);
		}
	});
	$("#pdate").datepicker({
		dateFormat: 'yy-mm-dd',
		onSelect: function(date){
			$("#pdate").val(date);
		}
	});
	$("#adate").datepicker({
		dateFormat: 'yy-mm-dd',
		onSelect: function(date){
			$("#adate").val(date);
		}
	});
	
	$('.fileDelete').click(function(){
		var target = $(this).attr('target');
		if($(this).prop('checked')){
			$('input[name=' + target + ']').val('');
		} else {
			$('input[name=' + target + ']').val($(this).val());
		}
	});
});


<!--
/* 
 * 글 등록 function
 * 비밀번호 입력값이 null이 아닌 경우 수정  가능(임영민, 2019-09-03) 
 */

 var isEmpty = function(value){
	  if( value == "" || value == null || value == undefined || ( value != null && typeof value == "object" && !Object.keys(value).length ) ){
	    return true
	  }else{
	    return false
	  }
	};

function fn_goAdd() {
	var frm = document.addForm;
	if (frm.checkPwd.value != 'Y') {
		alert('비밀번호가 일치하지 않습니다');
		frm.passwd.focus();
		return;
	}
	if(frm.sdate.value == ""){
		alert('경찰임용일 형식이 올바르지 않습니다.');
		frm.sdate.focus();
		return;
	}
	if(frm.pdate.value == ""){
		alert('현계급임용일 형식이 올바르지 않습니다.');
		frm.pdate.focus();
		return;
	}
	if(frm.adate.value == ""){
		alert('현부서배치일 형식이 올바르지 않습니다.');
		frm.adate.focus();
		return;
	}
	if(frm.inout.value == ""){
		alert('근무형태 형식이 올바르지 않습니다.');
		frm.inout.focus();
		return;
	}
	
	if(!validateMemberVO(frm)){
        return;
    }else{
    	var listType = "<c:out value='${listType}'/>",
    		registerFlag = "<c:out value='${registerFlag}'/>",
    		updateUrl = "";
    	if (registerFlag == 'modify') {
    		if (listType == "fa") {
            	frm.action = "<c:url value='/admin/faMemberUpdate.do'/>";
        	}
           	else {
            	frm.action = "<c:url value='/admin/cmmnMemberUpdate.do'/>";
           	}
    	} else {
    		frm.action = "<c:url value='/admin/faMemberAdd.do'/>";
    	}
       	frm.submit();
    }
}

/* 글 목록 화면 function */
function fn_selectList() {
	var listType = "<c:out value='${listType}'/>";
	if (listType == "fa")
   		location.href = "<c:url value='/admin/faMemberList.do'/>";
   	else
   		location.href = "<c:url value='/admin/faMemberCmmnList.do'/>";
}
var Member = {
	checkID : function(_str) {
		var form = document.forms['write_form'];
		if(_str.length < 5 ) return;
		
		$.ajax({
			url: '/member/faIdCheck.json',
			type: 'get',
			data : {userid: _str},
			dataType: 'json',
			success: function (result) {
				var data = result.data;
				if (data == "1") {
					$('#checkid').val("N");
					$('#userid_desc').html("<spring:message code="member.msg.duplicate"/>");
					$('#userid_desc').css('color', '#f00');
					return;
				}else{
					$('#checkid').val("Y");
					$('#userid_desc').html("<spring:message code="member.msg.available"/>");
					$('#userid_desc').css('color', '#00f');
				}
			}
		});
	},
	checkPWD : function(_str){
		var form = document.forms['addForm'];
		var passwd = form.passwd.value;
		if(passwd == _str){
			if(form.checkPwd.value == 'N'){
				return;
			}else{
				$('#pwd_desc').html("<spring:message code="member.msg.match"/>");
				$('#pwd_desc').css('color', '#00f');
				form.checkPwd.value = 'Y';
			}
		}else{
			$('#pwd_desc').html("<spring:message code="member.msg.dismatch"/>");
			$('#pwd_desc').css('color', '#f00');			
		}
	},
	chkPW : function(_str){
		var form = document.forms['addForm'];
		var passwd = form.passwd.value;
		var num = passwd.search(/[0-9]/g);
		var eng = passwd.search(/[a-z]/ig);
		var spe = passwd.search(/['~!@@#$%^&*|₩₩₩'₩";:₩/?]/gi);
		
		if((passwd.length < 8) || (passwd.length > 20) || (num <0) || (eng < 0) || (spe < 0)){
			$('#pw_desc').html("8~20자 영문, 숫자, 특수문자를 사용하세요.");
			$('#pw_desc').css('color', '#f00');
			form.checkPwd.value = 'N'; 
		}else {
			$('#pw_desc').html("확인");
			$('#pw_desc').css('color', '#00f');
			form.checkPwd.value = 'Y'; 
		}  
	},
	goList : function(){
		location.href="admin_member_list.php?list_type=admin";
	},	
	regist : function() {
	} 
};
	
function fncGetCombo(_obj, _id, _value) {
	var select = $('#place2').empty();

	$.ajax({
		url: '/code/place2.json',
		type: 'get',
		data : {code1: _value},
		dataType: 'json',
		success: function (result) {
			var data = result.data;
			if (select.length == 0) {
				select = $('<select id="place2" name="place2">');
			}			
			if (data.length > 0) {
				for (var i=0; i < data.length; i++) {
					var option = $('<option>')
								.html(data[i].codenm)
								.val(data[i].code2);
					if ('${memberVO.place2}' == data[i].code2) {
						option.attr('selected', true);
					}
					select.append(option);
				}
			}
			$("#place2_div").append(select);

			var combo2 = $("#place3_div");
			if(_value.toUpperCase() != "PS00"){				
				fncGetCombo2(combo2, "place3", "C009", "11");
			}else{
				fncGetCombo2(combo2, "place3", "C009");
			}
		}
	});
}
function fncGetCombo2(_obj, _id, _value, _option) {
	var select = $('#place3').empty();
	
	$.ajax({
		url: '/code/place3.json',
		type: 'get',
		data : {code1: _value, code2: _option},
		dataType: 'json',
		success: function (result) {
			var data = result.data;
			if (select.length == 0) {
				select = $('<select id="place3" name="place3">');
			}
			
			if (data.length > 0) {
				for (var i=0; i < data.length; i++) {
					var option = $('<option>')
								.html(data[i].codenm)
								.val(data[i].code2);
					if ('${memberVO.place3}' == data[i].code2) {
						option.attr('selected', true);
					}
					select.append(option);
				}
			}
			
			_obj.append(select);			
		}
	});
}
-->
</script>