<%@ Language=JScript  %>
<% 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;

// corrected: added var statement
var rst=new ActiveXObject("ADODB.Recordset");
// changed
var currentDate=getDateString(new Date());
var startOfDay=currentDate + " 00:00:01";
var endOfDay=currentDate + " 23:59:59";
rst.Open("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 " ,
	appDbConnection);	
%>
<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=(rst.BOF && rst.EOF);

while(!rst.EOF & !noQuestions) {
%>
			<tr>
				<td class="surveyList">
					<a href="showSurvey.aspx?survey=<%=rst.Fields("survey_id").Value%>">
						<%=rst.Fields("survey_question").Value%>
					</a>
				</td>
				<td class="surveyList">
					<%=getDateString(new Date(rst.Fields("survey_end").Value))%>
				</td>
				<td class="surveyList" align="right">
					<%=rst.Fields("SumOfVotes")%>
				</td>
			</tr>
			<%
	rst.MoveNext();

}

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