<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="js" uri="net.sourceforge.jsurveyor.jsurveyorlib" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="net.sourceforge.jsurveyor.*" %>
<js:noCache />
<js:login access="normal" />
<js:border title="jSurveyor">
<%
int questionnaireID = Integer.parseInt(request.getParameter("questionnaireID"));
Questionnaire editQ = DataAccess.retrieveQuestionnaire(questionnaireID);
%>
<form action='normal_next.jsp' method='post'>

<input name='questionnaireID' type='hidden' value='<%= editQ.getQuestionnaireID() %>' />
<input name='page' type='hidden' value='0' />
<tr>
	  <td class='mainmenu_headline'><%= editQ.getQuestionnaireName() %></td>
 	  <td class='mainmenu_headline_emptyfield'>&nbsp;</td>
</tr>

	<tr>
	  <td colspan='2' class='mainmenu_blueframe'>
	    <table border='0' cellspacing='0' cellpadding='0'>
		  <tr>
		  	<td align='right'>
		  	<table cellpadding='0' cellspacing='0' style='width:150px'>
	<!--	  	<tr>
			  	<td align='center'>
			  	<table cellpadding='0' cellspacing='0' style='border:1px solid #000000'>
			  		<tr>
				  		<% 
				  		ArrayList questionPages = editQ.getRefQuestionPages();
				  		int size = questionPages.size();
			 			%>
			  			<td style='width:0;background-color:#8697b0'>&nbsp;</td>
			  			<td style='width:100%;background-color:#ffffff'>&nbsp;</td>
			  		</tr>
			  	</table>
			  	</td>
		  	</tr> -->
		  	<tr>
			  <td colspan='2' align='center'>
			  <small>page 1 of <%= size %></small>
			  </td>
			  </tr>
		  	</table>
		  	</td>
		  </tr>
		  <td class='mainmenu_workframe'> <!-- Main workframe start -->
	        <table border='0' cellspacing='0' cellpadding='0'> 
			  <tr>
			  <td class='mainmenu_inner_workframe'>

			  <table>
			  
		      <tr>
				<td class='centeralign'>
				  <h2><%= editQ.getQuestionnaireName() %></h2>  <!-- Headline of questionnaire -->
				</td>
			  </tr>
			  <tr>

			    <td><b>Introduction</b><br /><br />
				  <%= editQ.getIntroText() %><br /><br /><!-- Introduction -->
				</td>
			  </tr>
			  <tr>
			    <td rowspan='2' valign='middle'>
				<%
				QuestionPage QPage = DataAccess.retrieveQuestionPage(Integer.parseInt(((String)questionPages.get(0)).substring(1)));
				ArrayList questions = QPage.getRefQuestions();
				for(int i = 0; i < questions.size(); i++) {
					String tempQRef = (String)questions.get(i);
					if(tempQRef.substring(0,1).equals("M")) {
						QuestionMultipleChoice tempQ = (QuestionMultipleChoice)DataAccess.retrieveQuestion(Integer.parseInt(tempQRef.substring(1)));
						%>
						<table  class='user_question_border'> 
					<tr>
					  <td colspan='4' class='centeralign'>
					  <%= tempQ.getText() %>
					  </td>
					</tr>
					<tr>
					  <td class='centeralign'>

					  <table border='0'>
					  <tr>
					  <td style='width:10%;'>
					  </td>
					  <td>
					  <table border='0'>
					  <tr>
					  <%
					  String[] choices = tempQ.getChoice();
					  for(int j = 0; j < choices.length; j++ ) {
					  
  					  if(j != 0 && j%5 == 0) { 
  					  	%>
  					  	<tr>
  					  	<% 
  					  	} 
  					  %>
  					  <td class='centeralign' style='width:<%= 80/(choices.length)%>%;'><input type='radio' name='<%= tempQ.getQuestionID()%>' value='<%= j %>' /><br /><%= choices[j] %></td>
					  <%
					  if(j != 0 && j+1%5 == 0) { 
  					  	%>
  					  	</tr>
  					  	<% 
  					  	}
					  }
					  %>
					  </tr>
					  </table>
					  </td>
						<td width='10%'></td>
					  </tr>
					  </table>
					  </td>
					</tr>
				  </table> 
	  			  
				  <br /> 
						<%
						
					}
					if(tempQRef.substring(0,1).equals("F")) {
						QuestionFreeText tempQ = (QuestionFreeText)DataAccess.retrieveQuestion(Integer.parseInt(tempQRef.substring(1)));
						%>
						<table class='user_question_border'> 
					<tr>
					  <td colspan='4' class='centeralign'>
					  <%= tempQ.getText() %>
					  </td>
					</tr>
					<tr>

					  <td class='centeralign'>
					  <table>
					  <tr>
					  	<td style='width:10%;'>
					  	</td>
					    <td>
						  <textarea name='<%= tempQ.getQuestionID()%>' cols='100' rows='2'></textarea>
						</td>
					  	<td style='width:10%;'>
					  	</td>
					  </tr>					  
					  </table>

					  </td>
					</tr>
				  </table> 
					<br />	
						<%
					}
				}
				%>
				
				
				
				  

				  
	  		
	  		
				</td>
			  </tr>
			  </table>
			  </td>
			  </tr>


			</table>

		  </td> 
		  </tr>
	    </table>
      </td>
	</tr>

	<tr>
	<td colspan='2' style='padding:2px;'> <!-- Makes space between blue border and top of buttons -->
	</td>

	</tr>
	
	
	<tr>
		<td></td>
	  <td class='mainmenu_buttonline'><input class='stdbutton' name='button' type='submit' value='Cancel'/> 
	  <%
	  if(editQ.getRefQuestionPages().size() == 1) {
	  %>
	  <input class='stdbutton' name='button' type='submit' value='Finish'/> 
      <%
      } else {
      %>
  	  <input class='stdbutton' name='button' type='submit' value='Next'/> 
      <%
      }
      %>
      </td>
    </tr>

</form>
 </js:border>