<%@ Language=JScript %>
<%@ import namespace="ADODB" %>
<%@ Assembly Name="ADODB" %>
<% Response.Buffer=true;

var rst:Recordset=new Recordset;
rst.Open("select survey_question from survey where survey_id="+Request("survey"),appDbConnection);
%>
<HTML>
	<HEAD>
		<LINK rel="stylesheet" type="text/css" href="survey.css">
	</HEAD>
	<BODY>
		<form method="post" action="">
			<table>
				<tr>
					<td class="sq">
						<%=rst.Fields("survey_question").Value%>
					</td>
				</tr>
				<%
rst.Close();
rst.Open("select so_text,so_number from survey_options where so_survey_id=" + Request("survey") + " order by so_number asc",appDbConnection);
while(!rst.EOF) {

	Response.Write("<tr><td class=\"sopt\"><input type=\"radio\" name=\"surveyOpt\" value=\"" + (rst.Fields("so_number")+1) + "\">" + rst.Fields("so_text") + "</td></tr>");
	rst.MoveNext();
}		
rst.Close();
%>
				</tr>
			</table>
			<br>
			<table>
				<tr>
					<td>
						<input name="btnAction" type="submit" value="Vote">
					</td>
					<td>
						<input name="btnAction" type="submit" value="Results">
					</td>
				</tr>
			</table>
		</form>
		<%
		
if (Request.Form("btnAction")=="Vote") {	
	if(Request("surveyOpt") > 0 ) {
		rst.Open("select so_votes from survey_options where so_survey_id=" + Request("survey") +
			" and so_number=" + (Request("surveyOpt")-1),appDbConnection);
		appDbConnection.Execute("update survey_options set so_votes=" + (rst.Fields("so_votes")+1) + 
			" where  so_survey_id=" + Request("survey") +
			" and so_number=" + (Request("surveyOpt")-1));
		rst.Close();
	}	
	Response.Redirect("showResult.aspx?survey="+Request("survey"));
}
else if (Request("btnAction")=="Results")
	Response.Redirect("showResult.aspx?survey="+Request("survey"));

%>
	</BODY>
</HTML>
