<%@ 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" %>
<c:set var="registerFlag" value="${registerFlag}"/>
<form:form commandName="boardVO" id="detailForm" name="detailForm" enctype="multipart/form-data">
	<form:hidden path="seq"/>
	<form:hidden path="id"/>
	<c:if test="${boardVO.category != ' '}">
		<input type="hidden" name="category" value="${boardVO.category}"/>
	</c:if>
	<c:if test="${registerFlag == 'reply'}">
		<input type="hidden" name="parentSeq" value="${boardVO.seq}"/>
		<form:hidden path="groupSeq"/>
		<form:hidden path="step"/>
		<form:hidden path="depth"/>
	</c:if>

   	<div id="table">
	   	<table class="tbl_add">
	   		<colgroup>
	   			<col width="180"/>
	   			<col width="820"/>
	   		</colgroup>
	   		<tr>
	   			<th><label for="title"><spring:message code="board.view.title" /></label></th>
	   			<td>
	   				<form:input path="subject" maxlength="50" cssClass="txt"/>	   				
	   			</td>
	   		</tr>
	   		<tr>
	   			<th>공지</th>
	   			<td>	   			
	   				<input type="checkbox" name="notice_checked" <c:if test="${boardVO.notice == 1}">checked="true"</c:if>/>
	   				<form:hidden path="notice"/>
	   				<spring:message code="board.view.notice" />
	   			</td>
	   		</tr>
	   		<tr>
	   			<th><label for="contents"><spring:message code="board.view.attach" /></label></th>
	   			<td>
	   				<c:choose>
				       <c:when test="${registerFlag != 'modify'}">
					   		<p><input type="file" name="file1" class="input_file" size="60" /></p>
		   					<p><input type="file" name="file2" class="input_file" size="60" /></p>
		   					<p><input type="file" name="file3" class="input_file" size="60" /></p>
				       </c:when>				       
				       <c:otherwise>
					       <c:forEach var="count" begin="0" end="2" varStatus="status">
					       		<p>
					       			<c:forEach var="file" items="${boardFileVO}"  varStatus="status2">
					       				<c:if test="${file.orders == status.index}">
					       					<input type="checkbox" name="deleteFile" value="${file.seq}"/>
					       					<c:out value="${file.orgName}"/>는 삭제합니다.
					       					<c:set var="existOrder" value="${true}"/>
					       				</c:if>
					       			</c:forEach>
					       			
					       			<c:if test="${existOrder eq null or existOrder == false}">
					       				<input type="file" name="file${status.count}" class="input_file" size="60" />
					       			</c:if>
				       				<c:set var="existOrder" value="${false}"/>
					       		</p>
							</c:forEach>
				       </c:otherwise>
			       	</c:choose>
	             </td>
	   		</tr>
	   		<tr>
	   			<th><label for="contents"><spring:message code="board.view.content" /></label></th>
	   			<td>
	   				<form:textarea path="content" rows="5" cols="58" htmlEscape="false"/>&nbsp;<form:errors path="content" />
	   				<ckeditor:replace replace="content" basePath="${pageContext.request.contextPath}/ckeditor/" />
	            </td>
	   		</tr>	
	   	</table>
    </div>
   	<div class="boardviewinfo">
		<ul class="right btn-style">
   			<li>
           		<a href="javascript:fn_egov_selectList();"><spring:message code="button.goList" /></a>
            </li>
   			<li>
               	<a href="javascript:fn_egov_save();">
                   	<c:if test="${registerFlag == 'create'}"><spring:message code="button.goCreate" /></c:if>
                   	<c:if test="${registerFlag == 'modify'}"><spring:message code="button.goModify" /></c:if>
                   	<c:if test="${registerFlag == 'reply'}"><spring:message code="button.goReply" /></c:if>
               	</a>
          	</li>
   		</ul>
   	</div>
</form:form>
<script type="text/javascript" src="<c:url value='/validator.do'/>"></script>
<validator:javascript formName="boardVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javaScript" defer="defer">
    <!--
    /* 글 목록 화면 function */
    function fn_egov_selectList() {
       	document.detailForm.action = "<c:url value='/bbs/list.do'/>";
       	document.detailForm.submit();
    }
    
    /* 글 등록 function */
    function fn_egov_save() {
    	frm = document.detailForm;
    	frm.content.value = encodeURIComponent(CKEDITOR.instances.content.getData());
    	frm.notice.value = (frm.notice_checked.checked) ? 1 : 0;
    	if(!validateBoardVO(frm)){
            return;
        }else{
        	frm.action = "<c:url value="${registerFlag == 'modify' ? '/bbs/update.do' : registerFlag == 'reply' ? '/bbs/reply.do' : '/bbs/add.do'}"/>";
           	frm.submit();
        }
    }
    -->
</script>