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

// changed to a regular function
function getDateString(dateValue:Date) : String {
   var dateStr : String = new String();
   if (dateValue.getMonth() < 9)
      dateStr+="0";
   dateStr +=  (dateValue.getMonth() + 1) + "/";
   if (dateValue.getDate() < 10)
      dateStr += "0";
   dateStr += dateValue.getDate() + "/";
   dateStr +=  dateValue.getFullYear();
   return dateStr;
}

//removed: Date.prototype.getDateString = getDateString;

var rst : OleDbDataReader;
var currentDate:String=getDateString(new Date());
var startOfDay:String=currentDate + " 00:00:01";
var endOfDay:String=currentDate + " 23:59:59";

var DbCmd : OleDbCommand = new OleDbCommand();

DbCmd.Connection=Application("appDbConnection");
DbCmd.Connection.Close();
DbCmd.CommandText="SELECT survey.survey_id, survey.survey_start, survey.survey_end, survey.survey_question, Sum(survey_options.so_votes) AS SumOfVotes " +
	"FROM survey INNER JOIN survey_options ON survey.survey_id = survey_options.so_survey_id " +
	"where survey.survey_start <= #" + startOfDay + "# and " +
	"survey.survey_end >= #"+endOfDay+"#" +
	" GROUP BY survey.survey_id, survey.survey_start, survey.survey_end, survey.survey_question ";

DbCmd.Connection.Open();
rst = DbCmd.ExecuteReader();

%>
<HTML>
	<HEAD>
		<LINK rel="stylesheet" type="text/css" href="survey.css">
			<title>Survey - the source for Internet voting</title>
	</HEAD>
	<BODY>
		<h1>
			Survey
		</h1>
		<p>
			Welcome to <em>Survey</em> - <b>the</b> source for Internet voting!
		</p>
		<p>
			Select a <em>Survey</em> from the list, or <a href="newSurvey.aspx">click here to 
				create a new <em>Survey</em></a>.
		</p>
		<br>
		<table border="1">
			<tr>
				<th>
					Question</th>
				<th>
					Expires</th>
				<th>
					Total Votes</th>
			</tr>
			<%
var noQuestions:Boolean=true;

while( rst.Read() ) {
	noQuestions	= false;
%>
			<tr>
				<td class="surveyList">
					<a href="showSurvey.aspx?survey=<%=rst("survey_id")%>">
						<%=rst("survey_question")%>
					</a>
				</td>
				<td class="surveyList">
					<%=getDateString(new Date(rst("survey_end")))%>
				</td>
				<td class="surveyList" align="right">
					<%=rst("SumOfVotes")%>
				</td>
			</tr>
			<%
	//removed: rst.MoveNext();

}
rst.Close();
if(noQuestions) {
%>
			<tr>
				<td class="surveyList">
					Sorry, there aren't any quesitions available
				</td>
				<td class="surveyList">
					0
				</td>
			</tr>
			<% } %>
		</table>
	</BODY>
</HTML>
