<%@ Language=JScript debug="true" %>
<%

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

appDbConnection.Execute("insert into survey (survey_start,survey_end,survey_question) values('" + 
	Request.Form("dtStart")+" 00:00:01" + "','" +
	Request.Form("dtEnd")+" 23:59:59" + "','" +
	surveyQuestion.replace(/'/,"\'\'") + "');" ,
	nRecsAffected,0);

var rst = new ActiveXObject("ADODB.Recordset");
rst.Open("select max(survey_id) from survey",appDbConnection);
var sid=rst.Fields(0).Value;
rst.Close();
var nIndex;
for(nIndex=0;nIndex<numberOfOptions;nIndex++) {

	appDbConnection.Execute("insert into survey_options (so_survey_id,so_number,so_text,so_votes) values(" +
		Number(sid).toString() + "," +
		Number(nIndex).toString() + ",'" +
		String(Request.Form("txtSurveyOption"+nIndex)).replace(/'/,"\'\'") + "',0);");
}	
	
Response.Redirect("showSurvey.aspx?survey="+sid);

%>
