#set($title = "設問一覧")
#set($menukubun = "3")
#parse( "/WEB-INF/view/common/header_admin.vm" )
<script type="text/javascript" src="/em/js/jquery.tablednd.0.7.min.js"></script>
<script language="JavaScript" type="text/JavaScript">
    <!--
	function enqueteBack(){
		location.href="#q('/admin/enquete/enqueteSearch/back/')";
	}


    function questionEdit(eid,qid){
    	var enqType = "$!enqueteRegistForm.enquete.enqueteType";
    	if(enqType == 2){
    		alert("1%支援団体寄付の場合、新規作成できません。");
    		return;
    	}
		location.href="#q('/admin/enquete/enqueteRegist/questionEdit')?eid="+eid+"&qid="+qid;
	}

    //削除リンククリック
    function delCheck(questionId,rn){
    	var enqType = "$!enqueteRegistForm.enquete.enqueteType";
    	if(enqType == 2){
    		alert("1%支援団体寄付の場合、削除できません。");
    		return;
    	}
    	document.getElementById('delQuestionId').value +=questionId+","
    	delRow(rn);

/*     	if(confirm('削除します。よろしいですか?'+questionId)){
    		delRow(rn);
    	}else{
    		return;
    	} */

    }

    function delRow(rn){
    	document.getElementById('TB').deleteRow(rn);
    }

    function swapRow(r1,upDown ){//r 位置は、0始まり,r1<r2
    	var enqType = "$!enqueteRegistForm.enquete.enqueteType";
    	if(enqType == 2){
    		alert("1%支援団体寄付の場合、移動できません。");
    		return;
    	}
    	
	    	//一行の場合
	    	if(upDown =='up' && r1 == 1){
	    		return;
	    	}

	    	var TB=document.getElementById('TB');
	    	var colsLen=TB.rows[0].cells.length;
	    	var newTR;
	    	var newTD;

	    	var r2 = 0;

	    	if(upDown == 'up'){
	    		r2 = r1 - 1;
	    		var rtemp = r1;
	        	r1 = r2;
	        	r2 = rtemp;
	    	}

	    	if(upDown == 'down'){
	    		r2 = r1 + 1;
	    		if(r2 +1 > TB.rows.length){
	    			return;
	    		}
	    	}

    		//alert("row1="+r1+":row2="+r2+":行数:"+TB.rows.length);
	    	newTR = TB.insertRow(r1);
	    	for(var i=0;i<colsLen;i++){
	    		newTD = newTR.insertCell(i);
	    		newTD.innerHTML = "" + TB.rows[r2+1].cells[i].innerHTML;
	    		newTD.className = TB.rows[r2+1].cells[i].className;
	    		TB.rows[r2+1].cells[i].innerHTML=TB.rows[r1+1].cells[i].innerHTML
	    	}

	    	TB.deleteRow(r1+1);
    	}

    //削除対象がある場合は警告を出す。
    function checkSubmit(){
    	var enqType = "$!enqueteRegistForm.enquete.enqueteType";
    	if(enqType == 2){
    		alert("1%支援団体寄付の場合、更新できません。");
    		return;
    	}
    	
    	if(document.getElementById('delQuestionId').value != ""){
    		if(confirm("削除対象がありますが実行しますか?")){
    			document.frm.submit();
    		}
    	}else{
    		document.frm.submit();
    	}
    }

    //更新(設問定義)画面に変更
    function questionEditUpdate(qid){
    	location.href="#q('/admin/enquete/enqueteRegist/questionEditFromQuestionList')?qid="+qid;
    }
    	//-->
</script>

#set($dateIndex=0)
#foreach($question  in   $!enqueteRegistForm.questionList)

	#if($question.controlId == 5)
		#set($dateIndex = $dateIndex+1)
<script language="javascript" type="text/javascript" charset="utf-8">
		<!--
		//開始日
		$(function() {
		  $("#enqStartFrom${dateIndex}").datepick({showTrigger: "#enqFrom${dateIndex}",
			  yearRange: "$question.yearRange",
			  minDate: "$question.startymd",
			  maxDate: "$question.endymd"});
		});
			// -->
</script>
	#end
#end
#set($dateIndex = 0)

<div id="contents">
<div id="contents_main">
<div id="breadcrumbsWrap">
						<!-- <div id="breadcrumbs" class="fs01 clearfix">
							<ul class="crumbs">
								<li><a href="#q('/admin/enquete/')">アンケート管理</a>&nbsp;></li>
								<li><a href="#q('/admin/enquete/enqueteSearch/')">アンケート検索</a>&nbsp;></li>
								<li><em>設問編集画面</em></li>
							</ul>
						</div>[ /breadcrumbs ] -->
</div><!--[ /breadcrumbsWrap ]-->
<div id="main" class="clearfix">
<div class="btn_area">
#if($enqueteRegistForm.replyCount < 1 && $!enqueteRegistForm.enquete.enqueteType != 2)
<a href="#" onclick="questionEdit($!{enqueteRegistForm.eid},0);" ><img src="/em/images/enq_01_btn_01_off.jpg" width="80" height="30" alt="新規作成" / class="mgr10"></a>
#end
</div>
<form method="POST" action="#q('/admin/enquete/enqueteRegist/questionUpdate/')"  name="frm">
<input type="hidden" name="eid" value="$!enqueteRegistForm.eid"/>
<input type="hidden" name="delQuestionIdList" id="delQuestionId" value=""/>
<input type="hidden" name="replyCount" value="$!{enqueteRegistForm.replyCount}"/>

<!-- <input type="button" onclick="alert(document.getElementById('delQuestionId').value)" value="削除確認" /> -->

<h2 class="contents_title">設問一覧</h2>

#if($!enqueteRegistForm.questionList)
	#foreach($question in $!enqueteRegistForm.questionList)
		<input type="hidden" name="questionNoSortOld" value="$!{question.questionId}" />
	#end
#else
	<input type="hidden" name="questionNoSortOld" value="$!{question.questionId}" />
#end


<div id="right_contents">
	<table border="0" cellpadding="0" cellspacing="0" class="stripe" id="TB">
		<thead>
		<th class="w60  t_center">QNO</th>
			<th class="w340  t_center">項目名</th>
			<th class="w340  t_center">回答方法</th>
			<th class="w50  t_center">表示順</th>
			<th class="w50  t_center"></th>
		</tr>
		</thead>
		#if($!enqueteRegistForm.questionList.size() == 0 )
		<TR><TD class="t_center" colspan="5">定義されている設問はありません。</TD></TR>
		#end
		#set($questionIndex = 0)
		#foreach($question in $!enqueteRegistForm.questionList)

		#set($questionIndex = $velocityCount)
		<tr id="$velocityCount">
			<td class="w60  t_center">$!{question.questionNo}</td>
			<td class="w340  t_left">

			#if($enqueteRegistForm.replyCount < 1) <a href="#" onclick="questionEditUpdate($!{question.questionId})"> #end
			$!{question.questionName}
			#if($enqueteRegistForm.replyCount < 1)</a> #end <BR>$!{question.question}</td>
			<td class="w340  t_center"  >
					<table width="100%" border="0" valign="top" align="left"  >
						<tr>
						##<!-- 質問の表示列項目数を求める -->
						#if($!question.colNum)
							#set($questionColNum = $!question.colNum)
						#else
							#set($questionColNum = 1)
						#end

						#set($tdWidthPercent = (100/$questionColNum))

						##<!-- ○○番目カラム変数 -->
						#set($colNum = 0)

				 #if($!question.controlId == "6")
	 				<td width="100%" valign ="top" align="left"  style="border-right-style:none;border-bottom:0px;" border="0">
	 			<select name="selectedOranizationId" >
					#foreach($pecent1 in $enqueteRegistForm.organizationListFor1Percent)
						<option value="$escape.html($!{pecent1.organizationId})" #if($!percentOrganizationId ==  $!pecent1.organizationId) selected #end>$!{pecent1.organizationNo} : $escape.html($!{pecent1.organizationName})</option>
					#end
					</select>
					</td>
				#else

						#foreach($answer in $question.answerList)
							#set($colNum = $colNum + 1)

							#set($answerIdValueName = "questionList[$questionIndex].answerList[$velocityCount].answerIdValue")
							#set($answerIdValueRadioName = "questionList[$questionIndex].answerList[0].answerIdValue")
							#set($answerValue = "questionList[$questionIndex].answerList[$velocityCount].answerValue")


								##<!-- colSpan変数 -->
								#set($colSpan = 1)

								##<!-- 最後のカラムの場合、不足ColSpan数を計算する。 -->
								#if($question.answerList.size() == $velocityCount+1)
										#set($colSpan = $questionColNum - $colNum + 1)
								#end


								<td width="$tdWidthPercent%" valign ="top" align="left" colspan="$!colSpan" style="border-right-style:none;border-bottom:0px;" border="0">
									<!-- 0:RADIO インデクスを値にする。 -->
									#if($!question.controlId == "0")
										 <input type="radio" name="$!answerIdValueRadioName"  value="$velocityCount"  #if($!answer.answerIdValue ==  $velocityCount.toString()) checked #elseif($!answer.defaultFlg == "1") checked #end>$!escape.html($!answer.answer)

										##<!-- 自由入力欄。freeTextFlg=1(あり)、2(必須) -->
										#if($!answer.freeTextFlg == 1 || $!answer.freeTextFlg == 2)
										##<!-- 自由入力欄。行数が2行以上の場合TextArea、1行の場合Text -->
											#if($!answer.freeTextRowNum > 1)
												<textarea name="$answerValue" cols="$!answer.freeTextColWidth"  rows="$!answer.freeTextRowNum">
													$!answer.answerValue
												</textarea>
											#else
												<input type="text"  name="$answerValue"  size="$!answer.freeTextColWidth"  value="$!answer.answerValue" />
											#end
										 #end
									##<!-- 1:CHECKBOX answer.answerNo値を値にする。-->
									#elseif($!question.controlId == "1")
										<input type="checkbox" name="$answerIdValueName"  value="$!answer.answerNo"  #if($answer.answerIdValue != "") checked  #elseif($answer.defaultFlg =="1") checked #end    >$!escape.html($!answer.answer)

										##<!-- 自由入力欄。freeTextFlg=1(あり)、2(必須) -->
										#if($!answer.freeTextFlg == 1 || $!answer.freeTextFlg == 2)
										##<!-- 自由入力欄。行数が2行以上の場合TextArea、1行の場合Text -->
											#if($!answer.freeTextRowNum > 1)
												<textarea name="$answerValue" cols="$!answer.freeTextColWidth"  rows="$!answer.freeTextRowNum">
													$answerValue
												</textarea>
											#else
												<input type="text"  name="$answerValue" size="$!answer.freeTextColWidth"  value="$!answer.answerValue"/>
											#end
										 #end

									##<!-- 2:SELECTMENU answer.answerNo値を値にする。-->
									#elseif($!question.controlId == "2")
									#if($velocityCount == 0)
									   		<select name="$answerIdValueName"  >
																#foreach($selectAnswer in $question.answerList)
												   					    <option value="0" #if($!selectAnswer.defaultFlg == "1") selected #end >$escape.html($!selectAnswer.answer) </option>
												   				#end
												</select>
												#end
									##<!-- 3:TEXTAREA ユーザー入力値を値にする。-->
									#elseif($!question.controlId == "3")
										<textArea type="text" name="$answerIdValueName" cols="$!question.dispWitdth" rows="$!question.rowCount">$!answer.answerIdValue</textarea>
									##<!-- 4:TEXTFIELD ユーザー入力値を値にする。-->
									#elseif($!question.controlId == "4")
										<input type="text" name="$answerIdValueName"  value="$!answer.answerValue" />
									##<!-- 5:日付入力 ユーザー入力値を値にする。-->
									#elseif($!question.controlId == "5") #set($dateIndex = $dateIndex+1)

<input id="enqStartFrom${dateIndex}" type="text" value="$!enqueteSearchForm.enqStartFrom" />
<div style="display: none;"><img id="enqFrom${dateIndex}" src="/em/images/icon_cal.gif" style="padding-left:0px;padding-right:0px; vertical-align: middle;"></div>
									#end
								</td>
								##<!-- TRの開閉 -->
								#if($questionColNum ==  $colNum)  ##<!-- カラム数と同一になった場合 -->
									#set($colNum = 0)
									</tr>
								#elseif($question.answerList.size() == ($velocityCount+1)) ##<!-- 最後のカラムになった場合 -->
									</tr>
									##終わりじゃない場合開始タグを作る。
								#elseif($question.answerList.size() == ($velocityCount+1)) ##<!-- 表示するのカラムが残っている場合 -->
									<tr>
								#end
						#end
					#end
						</table>
						</div>
		    </td>
		    #set($startCount = $velocityCount + 2)
		    #set($preVelocityCount = $startCount - 1)
		    #set($nextVelocityCount = $startCount + 1)

			<td class="w50  t_center" >
			<input type="hidden" id="preVelocityCount${startCount}"  value="${preVelocityCount}"/>
			<input type="hidden" id="startCount${startCount}"        value="${startCount}"/>
			<input type="hidden" id="nextVelocityCount${startCount}" value="${nextVelocityCount}"/>


				<a href="#" onclick="swapRow(this.parentNode.parentNode.rowIndex,'up')">▲ </a><a href="#" onclick="swapRow(this.parentNode.parentNode.rowIndex,'down')">▽</a>

			</td>
			<td class="w50  t_center">
			
			<a href="#" onclick="delCheck($!{question.questionId},this.parentNode.parentNode.rowIndex)">削除</a>
			<input type="hidden" name="questionNoSort" value="$!{question.questionId}" />

			</td>
		</tr>

		#end
</table>
<BR>

		<div class="btn_area2" style="width:840px;">

			<!-- <a href="#" onclick="enqueteBack()"><img src="/em/images/btn_back_off.jpg" width="130" height="35" alt="戻る" /></a> -->
			<input type="button" class="button"  value="戻る" onclick="enqueteBack()"/>
			#if($enqueteRegistForm.replyCount < 1)
				#if($!enqueteRegistForm.questionList.size() > 0)
					<!-- <a href="#" onclick="checkSubmit()"><img src="/em/images/reload_off.jpg" width="130" height="35"/></a> -->
					<input type="button" class="button"  value="上記設問を更新" onclick="checkSubmit()"/>
				#end
				<input type="button" class="button"  value="新規作成" onclick="questionEdit($!{enqueteRegistForm.eid},0);"/>
			#end
			<BR><BR><BR><BR>#if($!enqueteRegistForm.questionList.size() == 0 )<BR><BR><BR><BR><BR><BR><BR><BR>#end
		</div>


</div>

<BR><BR><BR><BR>



</form>

</div>
	<div id="contents_bottom">
		<img src="/em/images/bg_contents_bottom.jpg" width="1036" height="15" /> </div>
</div>
 </div>
#parse( "/WEB-INF/view/common/footer_admin.vm" )