<%--
  Class Name : EgovItnQustnrQestnManageRegist.jsp
  Description : 설문문항 등록 페이지
  Modification Information
 
      수정일         수정자                   수정내용
    -------    --------    ---------------------------
     2008.03.09    장동한          최초 생성
     2011.08.31  JJY       경량환경 버전 생성
 
    author   : 공통서비스 개발팀 장동한
    since    : 2009.03.19
   
--%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="validator" uri="http://www.springmodules.org/tags/commons-validator" %>

<c:set var="ImgUrl" value="/images/egovframework/com/uss/olp/qqm/"/>

<!DOCTYPE html>
<html>
<head>
<title>설문문항 등록</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="content-language" content="ko">
<script type="text/javascript" src="<c:url value="/validator.do"/>"></script>
<validator:javascript formName="qustnrQestnManageVO" staticJavascript="false" xhtml="true" cdata="false"/>
<script type="text/javascript" src="<c:url value='/js/showModalDialog.js'/>" ></script>
<script src="<c:url value='/js/jquery.js' />"></script>
<script type="text/javaScript" language="javascript">
/* ********************************************************
 * 목록 으로 가기
 ******************************************************** */
function fn_egov_list_QustnrQestnManage(){
	var varFrom = document.getElementById("qustnrQestnManageVO");
	varFrom.action =  "<c:url value='/uss/olp/qqm/EgovQustnrQestnManageList.do'/>";
	varFrom.submit();
	
}
/* ********************************************************
 * 저장처리화면
 ******************************************************** */
function fn_egov_save_QustnrQestnManage(form){
	if(confirm("<spring:message code="common.save.msg" />")){

		if(form.qestnrCn.value == "" ||
				form.qestnrTmplatId.value == "" ||
				form.qestnrId.value == ""  
				){
			alert("설문지정보를  입력해주세요!");
			form.qestnrCn.focus();
			return;
			
		}
		
		if(!validateQustnrQestnManageVO(form)){ 			
			return;
		}else{
			form.submit();
		} 
	}
}
/* ********************************************************
 * 설문지정보 팝업창열기
 ******************************************************** */
 function fn_egov_QustnrManageListPopup_QustnrQestnManage(){

 	window.showModalDialog("<c:url value='/uss/olp/qmc/EgovQustnrManageListPopup.do'/>", self,"dialogWidth=800px;dialogHeight=500px;resizable=yes;center=yes");
 	
 }
 
 /* ********************************************************
  * 설문문제
  ******************************************************** */
 function addRow(){
	  var oRow = itemTable.insertRow();
	  
   		th = document.createElement('th');
		th.innerHTML = itemTable.rows.length;;
		oRow.appendChild(th);
	
     	var oCell2 = oRow.insertCell();
     	oCell2.innerHTML = "<input type='text' name='iemCn'  style='width:90%; float:left;' maxlength='50' />";

}
function delRow(){
	if(itemTable.rows.length==0)
	{
	    alert("삭제 할 문항이 없습니다.");
	}else{
		itemTable.deleteRow(itemTable.rows.length-1);
	}
}


/* ********************************************************
 * 설문문제저장
 ******************************************************** */
function fn_egov_save_QustnrItemManage(cmd){
	var varFrom = document.getElementById("qustnrItemManageVO");
	var iemCnCheck = false;
	var message = "등록하시겠습니까?";
	if(cmd == "upda")  message = "수정하시면 이전의 설문결과\n정보가 초기화 됩니다.\n\n수정하시겠습니까?" ;
	if(confirm(message)){
		varFrom.action =  "/uss/olp/qim/EgovQustnrItemManageRegist.do";
		
		if(varFrom.qestnCn.value == ""){
			alert("질문내용을   입력해주세요!");
			return;
		}
		
		if(varFrom.qestnSn.value == ""){
			alert("질문순번이 없습니다.");
			return;
		}
		
		{
			$("input[name=iemCn]").each(function(idx){ 
				var value = $(this).val();
				console.log(value);
				if(value == ""){
					iemCnCheck = true;
					return false;
				}
			});	 
			if(iemCnCheck){
				alert("설문문항정보를  입력해주세요!");
				return ;
			}
		}
		
		varFrom.cmd.value= cmd 
		varFrom.submit();
	}
}

function fnList() {
	document.searchForm.submit(); 
}

</script>
<style>
.td {
	vertical-align: middle;
}
</style>
</head>
<body>
<!-- 자바스크립트 경고 태그  -->
<noscript class="noScriptTitle">자바스크립트를 지원하지 않는 브라우저에서는 일부 기능을 사용하실 수 없습니다.</noscript>
<form name="qustnrItemManageVO"  id="qustnrItemManageVO" action="${pageContext.request.contextPath}/uss/olp/qqm/EgovQustnrQestnManageRegist.do" method="post">
	<input name="qestnrId" type="hidden" value="${qustnrQestnManageVO.qestnrId}">
	<input name="qestnrTmplatId" type="hidden" value="${qustnrQestnManageVO.qestnrTmplatId}"> 
	<input name="qestnrQesitmId" type="hidden" value="${qustnrQestnManageVO.qestnrQesitmId}">
	<input name="cmd" type="hidden" value=""> 
	
	<div class="ad_content">
	<div class="ad_con_head">
		<div class="ad_head_text">
			<p class="today_txt">설문문항 등록</p>
			<div class="ad_head_ment">
				<p class="today_last_txt"><span id="cnt_cate_list"></span></p>
			</div>
		</div>
	</div>
	<div class="ad_subcon">
		<div class="main1_div2">
		<table class="main1_table">
				<tr>
					<th class="td_title1"><span class="star_t">*</span>설문지정보(제목)</th>
					<td colspan="3" class="td_txt_exist">
						${qestnrInfo.qustnrSj}
						<input type="hidden" name="qestnrCn" id="qestnrCn" value="${qestnrInfo.qustnrSj}" />
					</td>
				</tr>
				<tr>
					<th class="td_title1"><span class="star_t">*</span>질문 내용</th>
					<td colspan="3">
						<input type="text" name="qestnCn" id="qestnCn" maxlength="50" value="${qestnrInfo.qestnCn}" style="width:100%"/>
					</td>
				</tr>
				
				<tr>
					<th class="td_title1"><span class="star_t">*</span>질문순번</th>
					<td colspan="3" class="td_txt_exist">
						${qustnrQestnManageVO.qestnSn}
						<input type="hidden" name="qestnSn" id="qestnSn" value="${qustnrQestnManageVO.qestnSn}">
					</td>
				</tr>
				
				<tr>
					<th class="td_title1"><span class="star_t">*</span>질문유형</th>
					<td colspan="3">
						<select id="qestnTyCode" name="qestnTyCode" title="질문유형 선택">
						    <c:forEach items="${cmmCode018}" var="comCodeList" varStatus="status">
						        <option value="${comCodeList.code}" <c:if test="${qestnrInfo.qestnTyCode == comCodeList.code }"> selected="selected" </c:if>> ${comCodeList.codeNm}</option>
						    </c:forEach>  
						</select>
					</td>
				</tr>
				<tr>
					<th class="td_title1"><span class="star_t">*</span>최대선택건수</th>
					<td colspan="3">
					    <select id="mxmmChoiseCo" name="mxmmChoiseCo" title="최대선택건수 선택">
					        <option value="1" <c:if test="${qestnrInfo.mxmmChoiseCo == '1' }"> selected="selected" </c:if>>1</option>
					      	<option value="2" <c:if test="${qestnrInfo.mxmmChoiseCo == '2' }"> selected="selected" </c:if>>2</option>
					        <option value="3" <c:if test="${qestnrInfo.mxmmChoiseCo == '3' }"> selected="selected" </c:if>>3</option>
					        <option value="4" <c:if test="${qestnrInfo.mxmmChoiseCo == '4' }"> selected="selected" </c:if>>4</option>
					        <option value="5" <c:if test="${qestnrInfo.mxmmChoiseCo == '5' }"> selected="selected" </c:if>>5</option>
					        <option value="6" <c:if test="${qestnrInfo.mxmmChoiseCo == '6' }"> selected="selected" </c:if>>6</option>
					        <option value="7" <c:if test="${qestnrInfo.mxmmChoiseCo == '7' }"> selected="selected" </c:if>>7</option>
					        <option value="8" <c:if test="${qestnrInfo.mxmmChoiseCo == '8' }"> selected="selected" </c:if>>8</option>
					        <option value="9" <c:if test="${qestnrInfo.mxmmChoiseCo == '9' }"> selected="selected" </c:if>>9</option>
					        <option value="10" <c:if test="${qestnrInfo.mxmmChoiseCo == '10' }"> selected="selected" </c:if>>10</option>
				        </select>
					</td>
				</tr>
			</table>
		</div>
	</div>
	
	
	
	<div class="ad_con_head">
		<div class="ad_head_text">
			<p class="today_txt">설문문항</p>
		</div>
	</div>
	<div class="ad_subcon">
		<div class="ad_mem_list">
			<table class="main1_table" id="itemTable">
				<c:choose>
				<c:when test="${fn:length(qustnrItemList) < 1}">
					<tr>
						<th class="td_title1"><span class="star_t"></span>1</th>
						<td colspan="3">
							<input type="text" name="iemCn"  style="width:90%; float:left;"  maxlength="50" />
						</td>
					</tr>
					<tr>
						<th class="td_title1"><span class="star_t"></span>2</th>
						<td colspan="3">
							<input type="text" name="iemCn"  style="width:90%; float:left;" maxlength="50" />
						</td>
					</tr>
				</c:when>
				<c:otherwise>
					<c:forEach var="resultList" items="${qustnrItemList}" varStatus="status">
					<tr>
						<th class="td_title1"><span class="star_t"></span>${status.count}</th>
						<td colspan="3">
							<input type="text" name="iemCn" style="width:100%" maxlength="50" value="${resultList.iemCn}"/>
						</td>
					</tr>
					</c:forEach>
				</c:otherwise>
				</c:choose>
			</table>
			<div class="main1_div2_btn" style="float: left;margin-top: 9px;" >
				<button class="main1_btn" onclick="addRow(); return false;">문항추가</button>
				<button class="main1_btn" onclick="delRow(); return false;">문항삭제</button>
			</div>
			
			<div class="main1_btn_div">
				<button class="main1_btn" onclick="fnList(); return false;" >이전페이지</button>
				<c:choose>
					<c:when test="${fn:length(qustnrItemList) == 0}">
						<button class="main1_btn main1_save_btn" id="main1_save_btn" onclick="fn_egov_save_QustnrItemManage('regi'); return false; ">저 장 </button>
					</c:when>
					<c:otherwise>
						<button class="main1_btn main1_save_btn" id="main1_save_btn" onclick="fn_egov_save_QustnrItemManage('upda'); return false; ">수 정 </button>
					</c:otherwise>
				</c:choose>
			</div>		
		
		</div>
	</div>
	</div>
</form>
<form name="searchForm" id="searchForm" method="get" action="<c:url value='/uss/olp/qmc/EgovQustnrManageModify.do'/>" >
	<input name="qestnrId" type="hidden" value="${qustnrQestnManageVO.qestnrId}" />
</form>
</body>
</html>