function initDates(theForm)
{
	var today = new Date();
	var checkInDate = new Date();
	var checkOutDate = new Date();
	checkInDate.setDate( today.getDate() + 3 );
	checkOutDate.setDate( today.getDate() + 4 );
			
	// daysInMonth contains no. of days in each month, adjusted for leap years
	if ((parseInt(today.getFullYear()) % 4) == 0)
		var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	else
		var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		
	theForm.elements["gswCheckinDay"].options.length = daysInMonth[checkInDate.getMonth()];
	theForm.elements["gswCheckoutDay"].options.length = daysInMonth[checkOutDate.getMonth()];

	theForm.elements["gswCheckinMonth"].selectedIndex = checkInDate.getMonth();
	theForm.elements["gswCheckinDay"].selectedIndex = checkInDate.getDate()-1;
	theForm.elements["gswCheckinYear"].value = checkInDate.getFullYear();
			
	theForm.elements["gswCheckoutMonth"].selectedIndex = checkOutDate.getMonth();
	theForm.elements["gswCheckoutDay"].selectedIndex = checkOutDate.getDate()-1;			
	theForm.elements["gswCheckoutYear"].value = checkOutDate.getFullYear();
}

function setDates(theForm,target)
{
	var today = new Date();
	var m = theForm.elements["gsw"+target+"Month"];
	var y = theForm.elements["gsw"+target+"Year"];
	var d = theForm.elements["gsw"+target+"Day"];
	
	// if selected date is prior to today's date, then advance year
	if (m.selectedIndex < today.getMonth() || (m.selectedIndex == today.getMonth() && (d.selectedIndex + 1) < today.getDate()))
		y.value = today.getFullYear() + 1;
	// otherwise reset to current year
	else
		y.value = today.getFullYear();
	
	// daysInMonth contains no. of days in each month
	// adjusted for leap years
	if ((parseInt(y.value) % 4) == 0)
		var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	else
		var daysInMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		
	// only do the following if the month has changed
	if (m.value != today.getMonth() + 1)
	{
		// reset no. of date options to selected month
		d.options.length = daysInMonth[m.selectedIndex];
		
		// repopulate date options for selected month
		for (i = 0; i < d.options.length; i++)
		{
			d.options[i].value = i + 1;
			d.options[i].text = i + 1;
		}
	}
}

function adjustFormElements(theForm)
{
	theForm.elements["checkin"].value = theForm.elements["gswCheckinMonth"].value + "/" + theForm.elements["gswCheckinDay"].value + "/" + theForm.elements["gswCheckinYear"].value;
	theForm.elements["checkout"].value = theForm.elements["gswCheckoutMonth"].value + "/" + theForm.elements["gswCheckoutDay"].value + "/" + theForm.elements["gswCheckoutYear"].value;
	theForm.elements["gswCheckinMonth"].disabled = true;
	theForm.elements["gswCheckinDay"].disabled = true;
	theForm.elements["gswCheckinYear"].disabled = true;
	theForm.elements["gswCheckoutMonth"].disabled = true;
	theForm.elements["gswCheckoutDay"].disabled = true;
	theForm.elements["gswCheckoutYear"].disabled = true;			
}
