<%@ Language=JScript %>
<%@ import namespace="ADODB" %>
<%@ Assembly Name="ADODB" %>
<%

var numberOfOptions:int=parseInt(Request.Form("selOptions"),10);
var surveyQuestion:String=Request.Form("txtSQ");
var surveyStartDate:String=Request.Form("dtStart");
var surveyExpireDate:String=Request.Form("dtEnd");

appDbConnection.Execute("insert into survey (survey_start,survey_end,survey_question) values(\'" + 
	surveyStartDate+" 00:00:01" + "\',\'" +
	surveyExpireDate+" 23:59:59" + "\',\'" +
	surveyQuestion.replace(/'/,"\'\'") + "\');" ,
	0,0);

var rst : Recordset = new Recordset;
rst.Open("select max(survey_id) from survey",appDbConnection);
var surveyID:String=rst.Fields(0).Value;
rst.Close();
var nIndex:int;
for(nIndex=0;nIndex<numberOfOptions;nIndex++) {
	appDbConnection.Execute("insert into survey_options (so_survey_id,so_number,so_text,so_votes) values(" +
		surveyID + "," +
		nIndex + ",\'" +
		String(Request.Form("txtSurveyOption"+nIndex)).replace(/'/,"\'\'") + "\',0);");
}	
	
Response.Redirect("showSurvey.aspx?survey="+surveyID);

%>
