function setScwDate( prefix, postfix )
{
	var m = document.getElementById( prefix + 'MONTH' + postfix ).value;
	var d = document.getElementById( prefix + 'DAY' + postfix ).value;
	document.getElementById( prefix + 'DATE' + postfix + '_scw' ).value = m.substr(0,4) + '-' + m.substr(4) + '-' + d;
	return true;
}
function updateScwDate( prefix, postfix )
{
	var v = document.getElementById( prefix + 'DATE' + postfix + '_scw' ).value;
	document.getElementById( prefix + 'MONTH' + postfix ).value = v.substr(0,4) + v.substr(4,2);
	document.getElementById( prefix + 'DAY' + postfix ).value = v.substr(6,2);
	return true;
}

// Global variables
	var todayDate = new Date();
	var tomorrowDate = new Date();
	tomorrowDate.setDate( tomorrowDate.getDate() + 2 );
	var thisMonth = todayDate.getMonth() +1;
	var thisYear = todayDate.getFullYear();
	var thisDay = todayDate.getDate();
	var tomorrowMonth = tomorrowDate.getMonth() +1;
	var tomorrowYear = tomorrowDate.getFullYear();
	var tomorrowDay = tomorrowDate.getDate();

	months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	var writeMonth = thisMonth;
	var writeYear = thisYear;

	var departing_date_selected = false;

	function NumOfAdults()
	{
		var AdultIndex = document.forms[0].FIELD_ADT_NUMBER.selectedIndex;
		var AdultValue = document.forms[0].FIELD_ADT_NUMBER.options[AdultIndex].value;
		var myform = document.forms[0];

		if (AdultValue == 2){
		myform.TRAVELLER_TYPE_2.value = "ADT";
		}
		if (AdultValue == 3){
		myform.TRAVELLER_TYPE_2.value = "ADT";
		myform.TRAVELLER_TYPE_3.value = "ADT";
		}
		if (AdultValue == 4){
		myform.TRAVELLER_TYPE_2.value = "ADT";
		myform.TRAVELLER_TYPE_3.value = "ADT";
		myform.TRAVELLER_TYPE_4.value = "ADT";
		}
		if (AdultValue == 5){
		myform.TRAVELLER_TYPE_2.value = "ADT";
		myform.TRAVELLER_TYPE_3.value = "ADT";
		myform.TRAVELLER_TYPE_4.value = "ADT";
		myform.TRAVELLER_TYPE_5.value = "ADT";
		}
	}

	// Called to validate mandatory information
	function Check()
	{

	var myform = document.forms[0]
	var dYearMonthIndex = myform.B_MONTH.selectedIndex
	var dDayIndex = myform.B_DAY.selectedIndex
	var dYearMonthValue = myform.B_MONTH.options[dYearMonthIndex].value
	var dDayValue = myform.B_DAY.options[dDayIndex].value
	var dTimeIndex = myform.B_TIME_TO_PROCESS.selectedIndex
	var dTimeValue = myform.B_TIME_TO_PROCESS.options[dTimeIndex].value
	var dTimeText = myform.B_TIME_TO_PROCESS.options[dTimeIndex].text

	NumOfAdults()

	if(dTimeValue == "ANY")
	{
		myform.B_ANY_TIME_1.value = "TRUE"
		dTimeValue = "0000"
	}
	else
		myform.B_ANY_TIME_1.value = "FALSE"

	myform.B_DATE_1.value = dYearMonthValue + dDayValue + dTimeValue

	var rYearMonthIndex = myform.E_MONTH.selectedIndex
	var rDayIndex = myform.E_DAY.selectedIndex
	var rTimeIndex = myform.E_TIME_TO_PROCESS.selectedIndex
	var rTimeValue = myform.E_TIME_TO_PROCESS.options[rTimeIndex].value
	var rTimeText = myform.E_TIME_TO_PROCESS.options[rTimeIndex].text

	if(rTimeValue == "ANY")
	{
		myform.B_ANY_TIME_2.value = "TRUE"
		rTimeValue = "0000"
	}
	else
		myform.B_ANY_TIME_2.value = "FALSE"

	var rYearMonthValue = myform.E_MONTH.options[rYearMonthIndex].value
	var rDayValue = myform.E_DAY.options[rDayIndex].value

	myform.B_DATE_2.value = rYearMonthValue + rDayValue + rTimeValue

	myform.B_LOCATION_2.value = myform.E_LOCATION_1.value
	myform.E_LOCATION_2.value = myform.B_LOCATION_1.value

	return true;

	}

	// Update return date so it is after outbound date.
	function ChangeReturnDate()
	{
		var myform = document.forms[0]
		var selectedMonth
		var IsShortMonth
		var btnRetDate = true

		selectedMonth = myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value.charAt(4) + myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value.charAt(5)
		IsShortMonth = (selectedMonth == "02" || selectedMonth == "04" || selectedMonth == "06" || selectedMonth == "09" || selectedMonth == "11")

		if(btnRetDate && departing_date_selected)
		{
			if(myform.B_MONTH.selectedIndex > myform.E_MONTH.selectedIndex || myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value == "XX")
			{
				if ( ((myform.E_DAY.options[myform.E_DAY.selectedIndex].value == 31)&&(IsShortMonth))||((myform.E_DAY.options[myform.E_DAY.selectedIndex].value > 28) && (selectedMonth == "02")))
				{
					myform.E_MONTH.selectedIndex = myform.B_MONTH.selectedIndex+1
					myform.E_DAY.selectedIndex = 0
				}
				else
				{
					myform.E_MONTH.selectedIndex = myform.B_MONTH.selectedIndex
				}
			}
			if((myform.B_DAY.selectedIndex >= myform.E_DAY.selectedIndex || myform.E_DAY.options[myform.E_DAY.selectedIndex].value == "XX")&&(myform.E_MONTH.selectedIndex == myform.B_MONTH.selectedIndex))
			{
				if(((myform.B_DAY.options[myform.B_DAY.selectedIndex].value > 29) && (IsShortMonth))||(myform.B_DAY.options[myform.B_DAY.selectedIndex].value == 31)||((myform.B_DAY.options[myform.B_DAY.selectedIndex].value > 27) && (myform.B_MONTH.selectedIndex == 6)))
				{
					myform.E_MONTH.selectedIndex = myform.B_MONTH.selectedIndex + 1
					myform.E_DAY.selectedIndex = 0
				}
				else
					myform.E_DAY.selectedIndex = myform.B_DAY.selectedIndex + 1
			}
			document.forms[0].E_TIME_TO_PROCESS.selectedIndex = document.forms[0].B_TIME_TO_PROCESS.selectedIndex
		}
		departing_date_selected = false
	}

	function SetDate()
	{
		var myform = document.forms[0];
		var dYearMonthValue = myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value
		var dDayValue = myform.B_DAY.options[myform.B_DAY.selectedIndex].value
		myform.B_CAL_DATE_1.value = dYearMonthValue.substr(0,4) +'-'+dYearMonthValue.substr(4,2)+'-'+ dDayValue

		var rYearMonthValue = myform.E_MONTH.options[myform.E_MONTH.selectedIndex].value
		var rDayValue = myform.E_DAY.options[myform.E_DAY.selectedIndex].value
		myform.E_CAL_DATE_1.value = rYearMonthValue.substr(0,4) +'-'+rYearMonthValue.substr(4,2)+'-'+ rDayValue
	}

	function UpdateDate(bOutbound)
	{
	var MonthYear;
	var Day;
	var myform = document.forms[0];
	var CalendarDate;
		if (bOutbound)
		{
			// format is 'YYYYMMDD'
			CalendarDate = myform.B_CAL_DATE_1.value;
			MonthYear = CalendarDate.substr(0,6)
			Day = CalendarDate.substr(6,2);
			// Now I need to set the dates in the drop lists.
			for (n=0;n<myform.B_MONTH.length;n++)
			{
				if (myform.B_MONTH.options[n].value == MonthYear)
					myform.B_MONTH.selectedIndex=n;
			}
			for (n=0;n<myform.B_DAY.length;n++)
			{
				if (myform.B_DAY.options[n].value == Day)
					myform.B_DAY.selectedIndex=n;
			}


			// And now I need to update the Return date!
			departing_date_selected = true;
			ChangeReturnDate();
		}
		else
		{
			// format is 'YYYYMMDD'
			CalendarDate = myform.E_CAL_DATE_1.value;
			MonthYear = CalendarDate.substr(0,6)
			Day = CalendarDate.substr(6,2);
			// Now I need to set the dates in the drop lists.
			for (n=0;n<myform.E_MONTH.length;n++)
			{
				if (myform.E_MONTH.options[n].value == MonthYear)
					myform.E_MONTH.selectedIndex=n;
			}
			for (n=0;n<myform.E_DAY.length;n++)
			{
				if (myform.E_DAY.options[n].value == Day)
					myform.E_DAY.selectedIndex=n;
			}

		}
	}