function SetDateControls(ctlName, newDate)
{
	var monthCtl;
	monthCtl = eval('window.document.mscitysearch1.' + ctlName + '_month');
	var dateCtl = eval('window.document.mscitysearch1.' + ctlName + '_day');
	var yearCtl = eval('window.document.mscitysearch1.' + ctlName + '_year');
	monthCtl.selectedIndex = newDate.getMonth() + 1;
	dateCtl.selectedIndex = newDate.getDate();
	yearCtl.selectedIndex = newDate.getYear() - (new Date()).getYear() + 1;
}
// It took some Experimentation, but this will return true , if the Date given is valid, false if not.
function IsValidDate(year, month, day)
{
	month = month - 1;
	var tmpDate = new Date(year, month, day);
	var yearOkay = (tmpDate.getFullYear() == year);
	var monthOkay = (tmpDate.getMonth() == month);
	var dayOkay = (tmpDate.getDate() == day);
	return (yearOkay && monthOkay && dayOkay);
}
// When a date is submitted, we have to first check its validity,
//	and then we can create the new href & redirect to it.
function SubmitDate(useSingle)
{
	var startDate ="";
	var endDate = "";
	var excDays = "";
	// User is only looking for a single date, not a range
/*	if (useSingle)
	{
		// Check the validity
		if (!IsValidDate(frmDateSearch.single_year.value, frmDateSearch.single_month.value, frmDateSearch.single_date.value))
		{
			alert('The date you have chosen is not a valid date.');
			return;
		}
		// We can create only the start date, and then just copy to the end date
		startDate = frmDateSearch.single_month.value + '/' + frmDateSearch.single_date.value + '/' + frmDateSearch.single_year.value;
		endDate = startDate;
	} */
	// Here, the user want's a date range, so we have to check & include both
	//else
if (useSingle)
	{
		// Check the start date validity
		if (!IsValidDate(fdatesearch.start_year.value, fdatesearch.start_month.value, fdatesearch.start_day.value))
		{
			alert('The starting date you have chosen is not a valid date.');
			return false;
		}
		// Create the start date
		startDate = fdatesearch.start_month.value + '/' + fdatesearch.start_day.value + '/' + fdatesearch.start_year.value;
		
		// Check the end date validity
		if (!IsValidDate(fdatesearch.end_year.value, fdatesearch.end_month.value, fdatesearch.end_day.value))
		{
			alert('The ending date you have chosen is not a valid date.');
			return false;
		}
		//Create the end date
		endDate = fdatesearch.end_month.value + '/' + fdatesearch.end_day.value + '/' + fdatesearch.end_year.value;
		
		// Make sure it's a legit range (i.e. start <= end)
		if ((new Date(startDate)) > (new Date(endDate)))
		{
			alert('The starting date you have chosen is after the ending date.');
			return false;
		}
		// We want to pass the excluded days of the week, so we add the character
		//	only if the checkbox is NOT checked
		if (fdatesearch.chkMon.checked) excDays += 'M';
		if (fdatesearch.chkTue.checked) excDays += 'T';
		if (fdatesearch.chkWed.checked) excDays += 'W';
		if (fdatesearch.chkThu.checked) excDays += 'H';
		if (fdatesearch.chkFri.checked) excDays += 'F';
		if (fdatesearch.chkSat.checked) excDays += 'S';
		if (fdatesearch.chkSun.checked) excDays += 'U';
		//alert(excDays);
	}
	// Redirect, using the start, end & excluded dates
	document.fdatesearch.action='city-date-tickets.asp?sdate=' + startDate + '&edate=' + endDate + '&excdays=' + excDays;
	document.fdatesearch.submit();
	//location.href = 'city-date-tickets.asp?sdate=' + startDate + '&edate=' + endDate + '&excdays=' + excDays;
	return;
}
