<%@ Language=JScript %>
<HTML>
	<HEAD>
		<LINK rel="stylesheet" type="text/css" href="survey.css">
			<SCRIPT LANGUAGE="JScript">
<!--

function dateAddDays(startDate,nDays)
{
  var dayInMilliseconds;
  var nDaysInMilliseconds=nDays*86400000;
  dayInMilliseconds = Date.parse(startDate)+nDaysInMilliseconds;
  // convert back to the number of days
  var newDate=new Date(dayInMilliseconds);
  return (new Date(dayInMilliseconds));
}

function isValidDate(argDate) {
	var tmpDay = getDay(argDate)
	var tmpMon = getMonth(argDate)
	var tmpYear = getYear(argDate)

	return isDateValid(tmpMon,tmpDay,tmpYear) && isMonthValid(tmpMon) && isYearValid(tmpYear)
}

function isWhiteSpace(arg) {
	var localString = arg.toString();
	var nIndex;
	
	for (var nIndex=0; nIndex < localString.length; nIndex++){
		if (localString.charAt(nIndex) != ' ' && localString.charAt(nIndex) != '\t');
			return false;
	}	
	return true;
}

function isLeapYear(theYear) {
	return ( ((theYear % 4 == 0) && (theYear % 100 != 0)) || 
		(theYearr % 400 == 0));
}

function daysInMonth(argMonth, argYear) {
	switch (Number(argMonth)) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return 31;
			break;
		
		case 4:
		case 6:
		case 9:
		case 11:
			return 30;
			break;
		
		case 2:
			if (isLeapYear(argYear))
				return 29;
			else
				return 28;
			break;
		
		default:
			return 0;
	}
}

function getDateSepChar(arg) {
	if ((arg.indexOf('-') > 0) && (arg.indexOf('/') > 0))
		return " ";

	if (arg.indexOf('-') > 0)
		return "-";
	else
		return "/";
}

function getYear(arg) {
	var sepChar = getDateSepChar(arg);
	
	if (sepChar == ' ')
		return -1;

	if(arg.split(sepChar).length == 3)
		return arg.split(sepChar)[2];
	else
		return -1;
}

function getMonth(arg) {
	var sepChar = getDateSepChar(arg)
	
	if (sepChar == ' ')
		return -1;

	if(arg.split(sepChar).length == 3)
		return arg.split(sepChar)[0];
	else
		return -1;
}

function getDay(arg) {
	var sepChar = getDateSepChar(arg)
	
	if (sepChar == ' ')
		return -1;

	if(arg.split(sepChar).length == 3)
		return arg.split(sepChar)[1];
	else
		return -1;
}

function isDateValid(argMonth,argDate, argYear) {
	if ((isWhiteSpace(argDate)) || (argDate == 0))
		return false;

	return ((argDate > 0) && (argDate < daysInMonth(argMonth, argYear) + 1));
}

function isMonthValid(argMonth) {
	if ((isWhiteSpace(argMonth)) || (argMonth == 0))
		return false;
	
	return ((argMonth > 0) && (argMonth < 13));
}

function isYearValid(argYear) {
	if ((isWhiteSpace(argYear)) || (argYear.toString().length > 4) || (argYear.toString().length == 3))
		return false;
	return (argYear >=2000);
}


function getDateString(){
   var dateStr;
   dateStr="";
   if (this.getMonth() < 9)
      dateStr += "0";
   dateStr +=  (this.getMonth() + 1) + "/";
   if (this.getDate() < 10)
      dateStr += "0";
   dateStr += this.getDate() + "/";
   dateStr +=  this.getFullYear();
   return dateStr;
}


function Init() {
	Date.prototype.getDateString = getDateString;
	
	var currentDate=new Date();
	var expireDate=dateAddDays(currentDate,7);
	frmMain.dtStart.value=new Date().getDateString();
	frmMain.dtEnd.value=expireDate.getDateString();
	
}

function isFormValid() {
	if(!isValidDate(frmMain.dtStart.value)){
		divStartDate.innerHTML="<font color=\"red\"><b>* - Please correct this date</b></font>";
		return false;
	}	
		
	if(!isValidDate(frmMain.dtEnd.value)){
		divEndDate.innerHTML="<font color=\"red\"><b>* - Please correct this date</b></font>";
		return false;
	}
	frmMain.submit();	
}
	

//-->
			</SCRIPT>
			<title>Create New Survey - Step 1</title>
	</HEAD>
	<BODY onload="Init()">
		<form id="frmMain" action="setSurveyOptions.aspx" method="post">
			<H1>
				Create New Survey
			</H1>
			<P>
				Use this Wizard to create a new Survey:
			</P>
			<ul>
				<li>
					The first step asks you for the an overview of the <em>Survey</em> including:
					<ul>
						<li>
							<em>Survey</em> question</li>
						<li>
							Activation and Expiration dates</li>
						<li>
							Number of options (answers) users can vote on</li>
					</ul>
				<li>
					The second step asks you for the text for each option users can vote on</li>
				<li>
					The Wizard will present the survey to you after you complete step 2</li>
			</ul>
			<H3 class="stepNumber">
				Step 1
			</H3>
			<P>
				Type the Survey question in the <EM>Survey Question</EM>&nbsp;box - use these 
				guidelines:
			</P>
			<UL>
				<LI>
					Keep the question brief</LI>
				<LI>
					Phrase the question using the active voice</LI>
			</UL>
			<P class="fieldLabel">
				Survey Question (80 charaxters max):
			</P>
			<P>
				<input type="text" name="txtSQ" id="txtSQ" size="80" maxlength="80">
			</P>
			<table>
				<tr>
					<td class="fieldLabel">
						Start Date:
					</td>
					<td>
						<input type="text" name="dtStart" id="dtStart" size="10" maxlength="10">
					</td>
					<td>
						<div id="divStartDate">
						</div>
					</td>
				</tr>
				<tr>
					<td class="fieldLabel">
						End Date
					</td>
					<td>
						<input type="text" name="dtEnd" id="dtEnd" size="10" maxlength="10">
					</td>
					<td>
						<div id="divEndDate">
						</div>
					</td>
				</tr>
			</table>
			<P class="fieldLabel">
				Number of options: <SELECT id="selOptions" name="selOptions">
					<OPTION selected>
						2</OPTION>
					<OPTION>
						3</OPTION>
					<OPTION>
						4</OPTION>
					<OPTION>
						5</OPTION>
				</SELECT>
			</P>
			<P>
				<INPUT id="submit1" type="button" value="Submit" onclick="isFormValid()">
			</P>
		</form>
	</BODY>
</HTML>
