// This funcion is called to set the date controls to a particular
//	date.  It's just used in the beginning to set the controls to
//	be today's date.
function SetDateControls(ctlName, newDate)
{
	var monthCtl = eval('frmDateSearch.' + ctlName + '_month');
	var dateCtl = eval('frmDateSearch.' + ctlName + '_date');
	var yearCtl = eval('frmDateSearch.' + ctlName + '_year');
	monthCtl.selectedIndex = newDate.getMonth() + 1;
	dateCtl.selectedIndex = newDate.getDate();
	yearCtl.selectedIndex = newDate.getYear() - (new Date()).getYear() + 1;
}

// On load, we'll set the date controls to be today
SetDateControls('single', new Date());


// 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;
	}



	// Redirect, using the start, end & excluded dates
	location.href = 'http://www.bestshowticketslasvegas.com/ResultsDate.asp?sdate=' + startDate + '&edate=' + endDate + '&excdays=' + excDays;

	return;
}

