<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c"         uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring"    uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form"      uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/javaScript" type="text/javascript" defer="defer">
    <!--
	/* 글 목록 화면 function */
	function fn_selectList() {
	   	document.menuForm.action = "<c:url value='/bbs/list.do'/>";
	   	document.menuForm.submit();
	}
    function fn_downFile(seq){
		window.open("<c:url value='/bbs/download.do?id=${boardVO.id}&seq=" + seq + "'/>");
	}	
    function fn_modify(){
	   	document.menuForm.action = "<c:url value='/bbs/updateView.do'/>";
	   	document.menuForm.submit();
	}	
    function fn_delete(){
    	if (confirm("<spring:message code="confirm.msg.askDel" />")){
    		document.menuForm.action = "<c:url value='/bbs/delete.do'/>";
    	   	document.menuForm.submit();	
    	}
	}
    function fn_reply(){
    	document.menuForm.action = "<c:url value='/bbs/replyView.do'/>";
	   	document.menuForm.submit();
    }
    
   
    function fn_comment_insert(){
    	var form = $('form[name=commentForm]');
    	$.ajax({
    		url: '/bbs/commentAdd.json',
    		data: form.serialize(),
    		type: 'post',
    		dataType: 'json',
    		success: function(data){
				if(data.result == 1){
					location.reload();
				}
    		}
    	});
    }
    
    function fn_comment_delete(target, seq){
    	var id = $('input[name=id]').val();
    	$.ajax({
    		url: '/bbs/commentDelete.json',
    		data: {'seq': seq, 'id': id },
    		type: 'post',
    		dataType: 'json',
    		success: function(data){
    			var result = data.result;
    			if(result == 1){
	    			$(target).parent().remove();
    			}
    		}
    	}); 
    }
    
    $(document).ready(function(){
    	$("#content").keydown(function(e){
    		if (e.keyCode == 13) {
    			fn_comment_insert();
    			return false;
    		}
    	});
    });
    -->
</script>
<div id="table">
  	<table class="tbl_view">
  		<colgroup>
  			<col width="166">
  			<col width="166">  			
  			<col width="167">  			
  			<col width="167">  			
  			<col width="167">  						
  			<col width="167">  			
  		</colgroup>
 		<thead>
 			<tr>
	  			<th class="tbl_title" colspan="6" scope="row">
	  				<c:if test="${boardVO.notice == 1}">[공지]</c:if>
	  				<c:out value="${boardVO.subject}"/>
	  			</th>
	  		</tr>
	  		<tr>
	  			<th><label for="writer"><spring:message code="board.view.writer" /></label></th>
	  			<td><c:out value="${boardVO.userName}"/></td>
	  			<th><label for="rgsde"><spring:message code="board.view.regdate" /></label></th>
	  			<td><fmt:formatDate value="${boardVO.regdate}" pattern="yyyy-MM-dd"/></td>
	  			<th><label for="hit"><spring:message code="board.view.hit" /></label></th>
	  			<td><c:out value="${boardVO.hit}"/></td>
	  		</tr>
	  		<tr>   		
	  			<th>첨부파일</th>	
	  			<td colspan="5">
				<c:forEach var="file" items="${boardFileVO}" varStatus="status">
					<a href="#LINK" onclick="javascript:fn_downFile('<c:out value="${file.seq}"/>')">
			       	<c:out value="${file.orgName}"/>
			       	</a>
				</c:forEach>
				</td>
			</tr>			
 		</thead>
  		<tbody>
  			<tr class="tbl_content">
  				<td class="view" colspan="6"><div><c:out value="${boardVO.content}" escapeXml="false"/></div></td> 
  			</tr>
	  		<c:if test="${boardFileVO ne null && fn:length(boardFileVO) > 0}">	  			
  			</c:if>	
  		</tbody>
  	</table>
   	<form:form commandName="boardVO" name="menuForm" method="post">
	<div class="boardviewinfo">
		<ul class="right btn-style">
			<c:if test="${boardVO.prevSeq > 0}">
   			   	<li>
   			   		<a href="/bbs/view.do?id=${boardVO.id}&seq=<c:out value="${boardVO.prevSeq}" />"><spring:message code="button.goPrev" /></a>
	            </li>
   			</c:if>
   			<c:if test="${boardVO.nextSeq > 0}">
   			   	<li>
   			   		<a href="/bbs/view.do?id=${boardVO.id}&seq=<c:out value="${boardVO.nextSeq}" />"><spring:message code="button.goNext" /></a>
	            </li>
   			</c:if>
   			<li>
   				<a href="javascript:fn_reply();"><spring:message code="button.goReply" /></a>
            </li>
   			<li>
   				<a href="javascript:fn_selectList();"><spring:message code="button.goList" /></a>
            </li>
            <c:if test="${loginUserVO ne null && (loginUserVO.isSysAdmin == true || loginUserVO.userid == boardVO.userId)}">
   			<li>
   				<a href="javascript:fn_modify();"><spring:message code="button.goModify" /></a>                    
            </li>
   			<li>
   				<a href="javascript:fn_delete();"><spring:message code="button.goDelete" /></a>                   
            </li>
            </c:if>
		</ul>	
	</div>
   	<form:hidden path="id"/>
   	<form:hidden path="groupSeq"/>
   	<form:hidden path="seq"/>
   	<c:if test="${fn:length(boardVO.category) > 1}">
		<input type="hidden" name="category" value="${boardVO.category}"/>
	</c:if>
   	</form:form>
</div>

<div class="comment-wirte">
  	<form:form commandName="boardCommentVO" name="commentForm" method="post"> 		
 		<ul id="comment">
 		<c:forEach var="comment" items="${boardCommentVOList}" varStatus="status">
			<li>
				<b><c:out value="${comment.userName}"/></b>		
				<c:out value="${comment.content}"/>
				<c:if test="${loginUserVO ne null && (loginUserVO.isSysAdmin == true || loginUserVO.userid == comment.userId)}">
				<a class="delate" href="#delete" onclick="javascript:fn_comment_delete(this, '<c:out value="${comment.seq}"/>')">삭제</a>
				</c:if>
			</li>
		</c:forEach>
 		</ul>
 		<div class="opinion">
			<ul>			
				<li class="comment-img"></li>
				<li class="form_input">
					<form:input path="content" rows="2" cols="15" htmlEscape="false" placeholder="댓글을 입력하세요."/>
				</li>
				<li>
					<span class="btn_blue"> 
						<a href="#comment" onclick="javascript:fn_comment_insert()">댓글달기</a>
					</span>
				</li>
			</ul>
		</div>
 		<form:hidden path="id" />
 		<form:hidden path="parentSeq" />
 	</form:form>
</div>
