<%@ 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="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<link rel="stylesheet" type="text/css" href="/css/lib/jquery.datetimepicker.css"/>
<script type="text/javascript" src="/css/lib/jquery.datetimepicker.full.min.js"></script>
<script type="text/javascript" src="/js/lib/jquery.number.min.js"></script>
<form:form commandName="equipVO" id="detailForm" name="detailForm" enctype="multipart/form-data">
	
	<form:hidden path="num" />
	<form:hidden path="serNo" />
	<form:hidden path="writer" />
	<form:hidden id="fileName1" path="fileName1" value="${equipVO.fileName1 }"/>
	<form:hidden id="fileName2" path="fileName2" value="${equipVO.fileName2 }"/>
	<form:hidden id="fileName3" path="fileName3" value="${equipVO.fileName3 }"/>
   	<div id="table">
   	<table class="tbl_add">
   		<colgroup>
   			<col width="150"/>
   			<col width="300"/>
   			<col width="150"/>
   			<col width="?"/>
   		</colgroup>
   		<tr>
   			<th class="tbtd_caption">
   				<label for="title" id="care" name="care">주의사항</label>
   			</th>
   			<td class="tbtd_content" colspan="3">
   				* 표시는 필수입력 사항입니다.
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.police" /> *</label></th>
   			<td class="tbtd_content form_search sw-200 iw-320">
   				<form:select id="police" name="police" path="police" cssClass="use" onchange="changePlace(this.value);">
					<c:forEach var="result" items="${policeList}" varStatus="status">
						<form:option value="${result.code2}" label="${result.codenm}" />
					</c:forEach>
    			</form:select>
   			</td>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.equipType" /> *</label></th>
   			<td class="tbtd_content form_search sw-156 iw-320">
   				<form:select id="equipType" name="equipType" path="equipType" cssClass="use" onchange="changePlace(this.value);">
					<c:forEach var="result" items="${equipList}" varStatus="status">
						<form:option value="${result.code2}" label="${result.codenm}" />
					</c:forEach>
    			</form:select>
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.equipName" /> *</label></th>
   			<td class="tbtd_content" colspan="3">
   				<form:input id="equipName" name="equipName" path="equipName" cssClass="" />
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.buyDate" /> *</label></th>
   			<td class="tbtd_content">
   				<%-- <fmt:parseDate var="buyDate" value="${equipVO.buyDate}" pattern="yyyyMMdd" scope="page" />
   				<fmt:formatDate var="buyDate" value="${buyDate}" pattern="yyyy-MM-dd" /> --%>
   				<form:input id="buyDate" name="buyDate" path="buyDate" cssClass="txt" readonly="false" value="${buyDate}" kind="date"/>
   			</td>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.useTerm" /> *</label></th>
   			<td class="tbtd_content w-214">
   				<form:input id="useTerm" name="useTerm" path="useTerm" cssClass="txt text_num" class="text_num" maxLength="3"/> 년
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.standard" /></label></th>
   			<td class="tbtd_content" colspan="3">
   				<form:input id="standard" name="standard" path="standard" cssClass="txt" class=""/>
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.purpose" /></label></th>
   			<td class="tbtd_content" colspan="3">
   				<form:input id="purpose" name="purpose" path="purpose" cssClass="txt" />
   			</td>
   		</tr>
   		
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.buyPlace" /></label></th>
   			<td class="tbtd_content">
   				<form:input id="buyPlace" name="buyPlace" path="buyPlace" cssClass="txt" />
   			</td>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.price" /></label></th>
   			<td class="tbtd_content w-214">
   				<form:input id="price" name="price" path="price" cssClass="txt text_num"/> 원
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.madeIn" /></label></th>
   			<td class="tbtd_content">
   				<form:input id="madeIn" name="madeIn" path="madeIn" cssClass="txt" />
   			</td>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.serialNo" /></label></th>
   			<td class="tbtd_content w-214">
   				<form:input id="serialNo" name="serialNo" path="serialNo" cssClass="txt " />
   			</td>
   		</tr>
   		
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.useSection" /></label></th>
   			<td class="tbtd_content" colspan="3">
   			
   				<form:textarea id="useSection" name="useSection" path="useSection" cssClass="ta" />
   				<c:choose>
			    	<c:when test="${registerFlag != 'modify'}">
			       		<p><input type="file" id="file1" name="file1" class="input_file" size="60" /></p>
			       	</c:when>
			       	<c:otherwise>
			       		
			      		<p>
			      			<c:choose>
				      			<c:when test="${equipVO.fileName1 ne null and equipVO.fileName1 ne ' '}">
				       				<input type="checkbox" name="deleteFile" value="1"/>
				       				<c:out value="${equipVO.fileName1}"/> 는 삭제합니다.
				       			</c:when>
				       			<c:otherwise>
				       				<input type="file" id="file1" name="file1" class="input_file" size="60" />
			       				</c:otherwise>
		       				</c:choose>
				    	</p>
			       	</c:otherwise>
		       	</c:choose>
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.operate" /></label></th>
   			<td class="tbtd_content" colspan="3">
   				<form:textarea id="operate" name="operate" path="operate" cssClass="ta" />
   				<c:choose>
			    	<c:when test="${registerFlag != 'modify'}">
			       		<p><input type="file" id="file2" name="file2" class="input_file" size="60" /></p>
			       	</c:when>
			       	<c:otherwise>
			       		
			      		<p>
			      			<c:choose>
				      			<c:when test="${equipVO.fileName2 ne null and equipVO.fileName2 ne ' '}">
				       				<input type="checkbox" name="deleteFile" value="2"/>
				       				<c:out value="${equipVO.fileName2}"/> 는 삭제합니다.
				       			</c:when>
				       			<c:otherwise>
				       				<input type="file" id="file2" name="file2" class="input_file" size="60" />
			       				</c:otherwise>
		       				</c:choose>
				    	</p>
			       	</c:otherwise>
		       	</c:choose>
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.bigo" /></label></th>
   			<td class="tbtd_content" colspan="3">
   				<form:textarea id="bigo" name="bigo" path="bigo" cssClass="ta" />
   				
   			</td>
   		</tr>
   		<tr>
   			<th class="tbtd_caption"><label for="title"><spring:message code="equip.equipImage" /></label></th>
   			<td class="tbtd_content" colspan="3">
   				
   				<c:choose>
			    	<c:when test="${registerFlag != 'modify'}">
			       		<p><input type="file" id="file3" name="file3" class="input_file" size="60" /></p>
			       	</c:when>
			       	<c:otherwise>
			       		
			      		<p>
			      			<c:choose>
				      			<c:when test="${equipVO.fileName3 ne null and equipVO.fileName3 ne ' '}">
				       				<input type="checkbox" name="deleteFile" value="3"/>
				       				<c:out value="${equipVO.fileName3}"/> 는 삭제합니다.
				       			</c:when>
				       			<c:otherwise>
				       				<input type="file" id="file3" name="file3" class="input_file" size="60" />
			       				</c:otherwise>
		       				</c:choose>
				    	</p>
			       	</c:otherwise>
		       	</c:choose>
   			</td>
   		</tr>
   	</table>
    </div>
   	<div class="boardviewinfo">
		<ul class="right btn-style">
   			<li>
           		<a href="javascript:fn_selectList();"><spring:message code="button.goList" /></a>
            </li>
            
   			<li>
               	<a href="javascript:fnSave();">
                 	<c:if test="${registerFlag == 'create'}"><spring:message code="button.goCreate" /></c:if>
                 	<c:if test="${registerFlag == 'modify'}"><spring:message code="button.goModify" /></c:if>
             	</a>
          	</li>
   		</ul>
   	</div>
</form:form>


<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="equipVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
<!--
	$(window).ready(function() {
		
		//날짜 설정
		$('input[kind="date"]').datetimepicker({
			format:'Y-m-d'
		});
		
		// 숫자만 입력 (금액, 수량)
		inputNumberOnly($("#useTerm"));
		inputNumberOnly($("#price"));
		
		// 금액 콤마
		//$(document).on("keyup","#price", function(){	$(this).number(true);	});
		//$("#marginPaymentAmt").number($("#marginPaymentAmt").val());
		$("#price").on("change", function(){	
			$("#price").val( comma($("#price").val()));
		});
		
		
		$("#chkUserNameSetting").click(function() {
			if (this.checked){
				$("#chargeNm").val($("#hdChargeNm").val());	
			} else {
				$("#chargeNm").val("");
			}
		});
		
		//$("#buyDate").datepicker({
		//	onSelect: function(date){
		//		$("#buyDate").val(date);
		//	}
		//});
		
		$("#care").click(function(){
			tempSetting();
		});
		
	})
	
	function fn_selectList(){
		location.href = "<c:url value='/equip/equipList.do'><c:param name="serNo" value="${equipVO.serNo}" /></c:url>";
	}
	
	function fn_save(){
    	frm = document.detailForm;
    	if(!validatePromotVO(frm)){
            return;
        }else{
           	frm.submit();
        }		
	}
	
	/* 나포정보 등록 function */
	function fnSave(status) {
		
		// 등록 / 수정 Flag		
		var registerFlag = '<c:out value="${registerFlag}"/>';	// create / modify
		
		/* 기관 Validation */
		if($("#police").val() == ""){
			alert("배치기관은  필수 입력항목입니다.");
			$("#police").focus();
			return;				
		}
		if($("#equipType").val() == ""){
			alert("장비구분은  필수 입력항목입니다.");
			$("#equipType").focus();
			return;				
		}
		if($("#equipName").val() == ""){
			alert("장비명칭은  필수 입력항목입니다.");
			$("#equipName").focus();
			return;				
		}
						
		
		
		
		//$("#fileName1").val(  $("#file1").val()  );
		//$("#fileName2").val(  $("#file2").val()  );
		//$("#fileName3").val(  $("#file3").val()  );
		//alert(file1.value);
		//alert($("#fileName1").val());
		var frm = document.detailForm;
		frm.action = "<c:url value='/equip/equipSave.do'/>";
		$("#status").val(status);
		var msg = registerFlag == "create" ? "등록" : "수정";
				
		$("#price").val(   uncomma($("#price").val()) );
		
		if(!validateEquipVO(frm)){			
	    	return false;	    	
	    }else{
	    	if(confirm(msg + ' 하시겠습니까?')){
	    		frm.action = "<c:url value='/equip/equipSave.do'/>";		       	
		       	frm.submit();   	
	    	}
	    }
	}
	
	function changePlace(place1) {
		var wpNo = $('#hdWpNo_'+place1).val();
		
		//$('#spanWpNo').html(wpNo);
		//$('#wpNo').val(wpNo);	
	}
	
	/* 테스트 등록 데이터 세팅  function */
	function tempSetting(){
		if(location.host != "localhost:8081" && location.host != "localhost:8080"){
			return;
		}
		$("#police").val("PS02");
		$("#equipType").val("06");
		$("#equipName").val("ST080 디지털카메라");
		$("#buyDate").val("2017-06-08");
		$("#standard").val("STDS-508");
		$("#purpose").val("그냥");
		$("#useTerm").val("9");
		$("#buyPlace").val("롯데마트");
		$("#price").val("518000");
		$("#madeIn").val("소닉");
		$("#serialNo").val("1580401");
		
		
		$("#useSection").val("소요부속없음");
		$("#bigo").val("유지보수내역없음");
		$("#operate").val("정상동작");
		$("#fileName1").val("sony_camera.jpg");
		$("#fileName2").val("ac.jpg");
		$("#fileName3").val("sony_camera.jpg");
		
		
		
	}
	
	/**
	 * 숫자만 입력
	 * @param obj
	 */
	function inputNumberOnly(obj)
	{
		obj.keyup(function(e){
			var regexp = /[^0-9]/gi;
			var str = obj.val();
		    if (regexp.test(str))
		    {
		    	obj.val(str.replace(regexp, ''));
		    }
		});
	}
	
	//콤마찍기
	function comma(str) {
	    str = String(str);
	    return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, '$1,');
	}
	 
	//콤마풀기
	function uncomma(str) {
	    str = String(str);
	    return str.replace(/[^\d]+/g, '');
	}
	
	function getFileName(str){
		var filePath = str.split("\\");
		var fileName = "";
		
		if( filePath.length == 3 ){
			fileName = filePath[2];
		} 
		
		return fileName;
	}
-->	
</script>