function adjustYear(month) {

	frm = document.resLauncher;
	var now = new Date();
	
	if (month < now.getMonth() + 1) {
		frm.arrYear.selectedIndex = 1;
	} else {
		frm.arrYear.selectedIndex = 0;
	}
}

// initDateFields() initializes the month, day, and year select inputs
// the form must be named "resLauncher" and the date fields must be 
// named: "arriveMonth" "arriveDate" and "arriveYear"
// the select inputs will be populated dynamically

function initDateFields() {

	frm = document.resLauncher;

	//
	// Begine creation of Month/Year <select>
	//
	var mnths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

	var now = new Date();
	//tomorrowDt   = new Date(now.getTime() + (1 * 86400000));
	currMnth = now.getMonth();
	currYear = now.getFullYear();
	currDay  = now.getDate();

	var mt,yr,dy,mnthYr,len;

	// Day
	for (var dayIdx = 1; dayIdx <= 31; dayIdx++) {
		lenDay = frm.arrDate.options.length;
		if (dayIdx == currDay) {
			selDay = true;
			selDayIdx = dayIdx;
		} else {
			selDay = false;
		}
		
		frm.arrDate.options[lenDay] = new Option(dayIdx, dayIdx, selDay, selDay);
	}

	// Month
	for (var mnthIdx = 0; mnthIdx < 12; mnthIdx++) {
		lenMnth = frm.arrMonth.options.length;
		if (mnthIdx == currMnth) {
			selMnth = true;
			selMnthIdx = mnthIdx;
		} else {
			selMnth = false;
		}
		
		frm.arrMonth.options[lenMnth] = new Option(mnths[mnthIdx], mnthIdx+1, selMnth, selMnth);
	}

	//  Years
	for (var yearIdx = currYear; yearIdx < currYear + 2; yearIdx++) {
		lenYear = frm.arrYear.options.length;
		selYear = (yearIdx == currYear) ? true : false;
		frm.arrYear.options[lenYear] = new Option(yearIdx, yearIdx, selYear, selYear);
	}
}

function submitNetbookerForm()
{

	// generate Netbooker URL from resLauncher form
	var url = 'http://kimpton.ibe.netbooker.com/web/FrontController.nb4?'
		+'module=PropertySearch&'
		+'operation=SinglePropertySearchResult&'
		+'instanceId=31&'
		+'execute=yes&'
		+'chainCode=KC&';
	
	with (document.resLauncher) {
	
		// generate arrival date
		var arrivalDateJSObject = new Date();
		arrivalDateJSObject.setFullYear(arrYear.value);
		arrivalDateJSObject.setMonth(arrMonth.value-1);
		arrivalDateJSObject.setDate(arrDate.value);
		
		/*var now = new Date();
		
		// original line has (now.getTime() + 86400))...
		if (arrivalDateJSObject.getTime() < (now.getTime())) {
			alert('Please select a date in the future');
			return false;
		}*/
		
		
		//new time code start here
			var curDateTime = new Date();
				var curHour = curDateTime.getHours();
				var curMin = curDateTime.getMinutes()+parseInt(01);
				var curSec = curDateTime.getSeconds();
				var curAMPM = " AM"
				var curTime = ""
				if (curHour >= 12)
				{
				curHour -= 12
				curAMPM = " PM"
				}
				if (curHour == 0) curHour = 12
				curTime = curHour + ":" 
				+ ((curMin < 10) ? "0" : "") + curMin + ":" 
				+ ((curSec < 10) ? "0" : "") + curSec 
				+ curAMPM
		//new Time code ends here
		
		var tryDate =arrMonth.value+"/"+arrDate.value+"/"+arrYear.value;
		var tryDateTime =tryDate + " " +curTime;

		var now = new Date();
		var strArrivalDate = new Date(tryDateTime);
		
		if (strArrivalDate < now) {
			alert('Please select a date in the future');
			return false;
		}

		url += 'lookAndFeelId='+lookAndFeelId.value+'&'
			+ 'propertyCode='+propertyCode.value+'&'
			+ 'arriveMonth='+ arrMonth.value +'&'
			+ 'arriveDate='+arrDate.value+'&'
			+ 'arriveYear='+arrYear.value+'&'
//			+ 'departMonth='+???+'&'
//			+ 'departDate='+???+'&'
//			+ 'departYear='+???+'&'
			+ 'numberOfNights='+numberOfNights.value+'&'
			+ 'adults='+adults.value+'&'
			+ 'children='+children.value+'&'
			+ 'rateCode='+rateCode.value+'&'
			+ 'corporateId='+corporateId.value+'&'
			+ 'specialRate='+specialRate.value
	}

	// open window to Netbooker
	window.open(url, 'reservationWin', 'width=775,height=800,location=no,resizable=yes,menubar=no,toolbar=no,scrollbars=yes');

}

function calePopUp(width, height)
{
	// Get the month/year/dates
	// these must be converted from there full date format to single
	// states such as individual month/year/dates (all numeric values returned)
	
	// month/year here
	
	var selMnth_index = document.resLauncher.arrMonth.selectedIndex;
	var selYear_index = document.resLauncher.arrYear.selectedIndex;
	var selMnthYr = new Date(document.resLauncher.arrYear.options[selYear_index].value, document.resLauncher.arrMonth.options[selMnth_index].value);
	
	var selMnthYr_mnth = selMnthYr.getMonth()-1;
	var selMnthYr_year = selMnthYr.getFullYear();
	
	// day here
	
	var selDate_index = document.resLauncher.arrDate.selectedIndex;
	var selDate = new Date(document.resLauncher.arrYear.value, document.resLauncher.arrMonth.value, document.resLauncher.arrDate.value);
	
	var selMnthYr_dayy = selDate.getDate();

	// Create url
	
	var winURL = "../calendar.html?var_month=" + selMnthYr_mnth + "&var_year=" + selMnthYr_year + "&var_day=" + selMnthYr_dayy;

	// open popup
	
	window.open(winURL,"winCale","toolbar=no,location=no,status=no,directories=no,width=" +width+ ",height=" +height+ ",left=390,top=350,scrollbars=no,resizable=no");
}

/**
 * Sets the form dates
 *
 * @param integer month
 * @param integer year
 * @param integer day
 */
function setFormDates(month, year, day)
{
	// set month
	document.resLauncher.arrMonth.selectedIndex = month;
	
	// set year
	var select_arrYear_length = document.resLauncher.arrYear.options.length;
	var select_arrYear_index = 0;
	for (m = 0; m < select_arrYear_length; m++) {
		var select_arrYear = document.resLauncher.arrYear.options[m].value;
		if (year == select_arrYear) select_arrYear_index = m;
	}
	document.resLauncher.arrYear.selectedIndex = select_arrYear_index;
		
	// set day
	document.resLauncher.arrDate.selectedIndex = day - 1;
}