<%@ Language=JScript debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.OleDb" %>
<%

var rst : OleDbDataReader;

var DbCmd : OleDbCommand = new OleDbCommand();
DbCmd.Connection=Application("appDbConnection");
if (DbCmd.Connection.State==ConnectionState.Open) DbCmd.Connection.Close();
DbCmd.CommandText="select survey_question from survey where survey_id="+Request("survey");
DbCmd.Connection.Open();
var surveyQuestion:String = DbCmd.ExecuteScalar();

//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>
		<table>
			<tr>
				<td class="sq">
					<%=surveyQuestion%>
				</td>
			</tr>
		</table>
		<table border="1">
			<tr>
				<th>
					Option
				</th>
				<th>
					Percent
				</th>
				<th>
					Votes
				</th>
			</tr>
			<%
DbCmd.Connection.Close();

DbCmd.CommandText="select sum(so_votes) from survey_options where so_survey_id=" + Request("survey");
DbCmd.Connection.Open();
var totalVotes:int = DbCmd.ExecuteScalar();
if (DbCmd.Connection.State==ConnectionState.Open) DbCmd.Connection.Close();

//rst.Open("select sum(so_votes) from survey_options where so_survey_id=" + Request("survey"),appDbConnection);
//var totalVotes:int=rst.Fields(0).Value;
//rst.Close();

var pcntVotes:double;

DbCmd.CommandText="select so_text,so_votes from survey_options where so_survey_id=" + Request("survey") + " order by so_number asc";
DbCmd.Connection.Open();
rst = DbCmd.ExecuteReader();

//rst.Open("select so_text,so_votes from survey_options where so_survey_id=" + Request("survey") + " order by so_number asc",appDbConnection);
while(rst.Read()) {
	Response.Write("<tr><td>" + rst("so_text") + "</td>");
	pcntVotes=Math.round(((parseInt(rst("so_votes"))/totalVotes)*100));
	Response.Write("<td width=\"50%\" ><img src=\"images/blue.gif\" height=5 width=" + (pcntVotes*3) + "></td>");
	Response.Write("<td>" + rst("so_votes") + "</td></tr>");
	//rst.MoveNext();
}
rst.Close();
DbCmd.Connection.Close();
%>
			<tr>
				<td>
					Total Votes
				</td>
				<td width="50%">
					<img src="images/blue.gif" height="5" width="300">
				</td>
				<td>
					<%=totalVotes%>
				</td>
			</tr>
		</table>
		<br>
		<a href="default.aspx">Back to Surveys Screen</a>
	</BODY>
</HTML>
