<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.text.NumberFormat,java.util.*"%>
<%@ page import="com.wxpn.tutorial.servlet.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>投票</title>
<script language="JavaScript">
<!--
   function validate(){ 
     var len = document.form.vote.length;
	 for (var i=0; i<len; i++){
		var e = document.form.vote[i];
		if ( e.checked ){
			return true;
		}
	 }
	  alert("请您至少选择一项！");
       return false;
   }
-->
</script>
</head>

<body>
<form action="UpdateVoteServlet" method="post" name="form"
	onSubmit="javaScript: return validate();"><%Question question = (Question) request.getAttribute("question");
			Collection c = question.getItems();

			NumberFormat nf = NumberFormat.getPercentInstance();

			%>
<table width="80%" border="0" align="center">
	<tr>
		<td align="center" valign="middle">主题：<%=question.getTitle()%></td>
	</tr>

</table>
<table width="80%" border="0" align="center">
	<%if (c != null) {
				Iterator iterator = c.iterator();
				int i = 1;
				Item item = null;
				while (iterator.hasNext()) {
					item = (Item) iterator.next();
%>

	<tr>
		<td align="left" valign="middle">[<%=i%>]<input
			type="<%=question.getStyle()%>" value="<%=item.getId()%>" name="vote">
		<%=item.getOptions()%></td>

	</tr>
	<%i++;
				}
			}%>
	<tr>
		<td align="center" valign="middle"><%if (session.getAttribute("voted") == null) {

			%> <input type="submit" value="提交" name="submit"> <%} else {

			%> <font color="red">已经投过票了!</font> <%}

			%></td>
	</tr>

</table>
<table width="80%" border="0" align="center">
	<tr>
		<td align="center" valign="middle"><a href="index.jsp">返回首页</a></td>
	</tr>
</table>
<input type="hidden" value="<%=question.getId() %>" name="id"></form>
</body>
</html>
