function evalTrip()
{
	var single = document.getElementById('single');
	var multi = document.getElementById('multi');
	var display_multi = document.getElementById('display_multi');
	
	if (document.afpForm.TRIP_TYPE.selectedIndex == 0)
	{
		document.afpForm.retMonth.disabled = true;
		document.afpForm.retDay.disabled = true;
		document.afpForm.retTime.disabled = true;
		
		document.afpForm.flexible.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_1.disabled = false;
		document.afpForm.PLUS_DATE_RANGE_1.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_2.disabled = true;
		document.afpForm.PLUS_DATE_RANGE_2.disabled = true;
		document.getElementById('B_TIME_WINDOW_2m').disabled = false;
		document.getElementById('B_DATE_2m').disabled = false;
		document.getElementById('returnDate').disabled = true;
		
		single.style.display = "block";
		multi.style.display = "none";
		setTimeWindow(1);
	}
	else if (document.afpForm.TRIP_TYPE.selectedIndex == 1)
	{
		document.afpForm.retMonth.disabled = false;
		document.afpForm.retDay.disabled = false;
		document.afpForm.retTime.disabled = false;
		
		document.afpForm.flexible.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_1.disabled = false;
		document.afpForm.PLUS_DATE_RANGE_1.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_2.disabled = false;
		document.afpForm.PLUS_DATE_RANGE_2.disabled = false;
		document.getElementById('B_TIME_WINDOW_2m').disabled = true;
		document.getElementById('B_DATE_2m').disabled = true;
		document.getElementById('returnDate').disabled = false;
		
		single.style.display = "block";
		multi.style.display = "none";
		setTimeWindow(1);
	}
	else if (document.afpForm.TRIP_TYPE.selectedIndex == 2)
	{
		document.afpForm.retMonth.disabled = true;
		document.afpForm.retDay.disabled = true;
		document.afpForm.retTime.disabled = true;
		
		document.afpForm.flexible.disabled = true;
		document.afpForm.MINUS_DATE_RANGE_1.disabled = true;
		document.afpForm.PLUS_DATE_RANGE_1.disabled = true;
		document.afpForm.MINUS_DATE_RANGE_2.disabled = true;
		document.afpForm.PLUS_DATE_RANGE_2.disabled = true;
		document.getElementById('B_TIME_WINDOW_2m').disabled = false;
		document.getElementById('B_DATE_2m').disabled = false;
		document.getElementById('returnDate').disabled = true;
		
		single.style.display = "none";
		multi.style.display = "block";
		
		if (document.afpForm.RESTRICTION.selectedIndex == 1) {
			display_multi.style.display = "block";
		}
		else {
			display_multi.style.display = "none";
		}
		
		setTimeWindow(1);
		setTimeWindow(2);
		setTimeWindow(3);
		setTimeWindow(4);
		setTimeWindow(5);
		setTimeWindow(6);
	}
	
	hide_return();
}

function searchBy()
{
	var display_multi = document.getElementById('display_multi');
	
	if (document.afpForm.RESTRICTION.selectedIndex == 0) {
		document.afpForm.action = 'http://wftc2.e-travel.com/plnext/AIEBDBLBDBL/TravelShopperAvailability.action';
		renameEl('AIR_CABIN', 'AIR_CABIN');
		renameEl('AIRLINE_1', 'PREFERRED_AIRLINE_1');
		//document.afpForm.AIR_CABIN.options[3] = new Option ('Premium economy', 'N');
		
		display_multi.style.display = "none";
	}
	else if (document.afpForm.RESTRICTION.selectedIndex == 1) {
		document.afpForm.action = 'http://wftc2.e-travel.com/plnext/AIEBDBLBDBL/AirComplexAvailability.action';
		renameEl('AIR_CABIN', 'CABIN');
		renameEl('AIRLINE_1', 'AIRLINE_1');
		//document.afpForm.CABIN.options[3] = null;
		
		display_multi.style.display = "block";
	}
}

function renameEl(el, newName)
{
	el = (typeof el === "string") ? document.getElementById(el) : el;
	el.name = newName;
	
	if (/*@cc_on!@*/0) { // Internet Explorer
		el.removeAttribute("name");
		attributeEl = document.createElement("INPUT");
		attributeEl.setAttribute("Name", newName);
		holder = document.createElement("DIV");
		holder.appendChild(attributeEl);
		document.body.appendChild(holder);
		holder.innerHTML = holder.innerHTML;
		attributeEl = holder.firstChild;
		el.mergeAttributes(attributeEl, false);
		holder.parentNode.removeChild(holder);
	}
}

function set_date()
{
	var outday=document.afpForm.depDay_1.selectedIndex;
	var outmonth=document.afpForm.depMonth_1.selectedIndex;
	var calendar=new Date();
	var advpurchase=1+2;
	calendar.setDate(calendar.getDate()+advpurchase);
	document.afpForm.depDay_1.selectedIndex=calendar.getDate()-1;
	document.afpForm.depMonth_1.selectedIndex=calendar.getMonth();
	calendar.setDate(calendar.getDate()+7);
	document.afpForm.retDay.selectedIndex=calendar.getDate()-1;
	document.afpForm.retMonth.selectedIndex=calendar.getMonth();
}

function checkRequired()
{
	var str;
	/*
	str = document.afpForm.B_LOCATION_1.value;
	if(str == ""){
		alert("Please select the city to go from");
		document.afpForm.B_LOCATION_1.value = "";
		document.afpForm.B_LOCATION_1.focus();
		return false;
	}
	*/
	str = document.afpForm.E_LOCATION_1.value;
	if(str == "") {
		alert("Please select the city to go to");
		document.afpForm.E_LOCATION_1.value = "";
		document.afpForm.E_LOCATION_1.focus();
		return false;
	}
	
	if(document.afpForm.ADT.value < document.afpForm.INF.value) {
		alert("Only one infant traveller per adult will be accepted.");
		return false;
	}
}

function hide_return()
{
	var element = document.getElementById('return_date');
	if (document.afpForm.TRIP_TYPE.selectedIndex == 0) {
		element.style.display = "none";
	} else {
		element.style.display = "block";
	}
	
	var element = document.getElementById('return_date2');
	if (document.afpForm.TRIP_TYPE.selectedIndex == 0) {
		element.style.display = "none";
	} else {
		element.style.display = "block";
	}
}

function enable_time_window()
{
	if (document.afpForm.TRIP_TYPE.selectedIndex ==0) {
		document.afpForm.retMonth.disabled = true;
		document.afpForm.retDay.disabled = true;
		document.afpForm.retTime.disabled = true;
	} else if (document.afpForm.TRIP_TYPE.selectedIndex ==1) {
		document.afpForm.retMonth.disabled = false;
		document.afpForm.retDay.disabled = false;
		document.afpForm.retTime.disabled = false;
	} else if (document.afpForm.TRIP_TYPE.selectedIndex ==2) {
		document.afpForm.retMonth.disabled = false;
		document.afpForm.retDay.disabled = false;
		document.afpForm.retTime.disabled = false;
	}
	
	hide_return();
}

function setTimeWindow(i)
{
	if(i == 2)
		var timeWindow = "B_TIME_WINDOW_"+i+"m";
	else
		var timeWindow = "B_TIME_WINDOW_"+i;
	
	if (document.afpForm.elements["depTime_"+i].selectedIndex > 0) {
		document.getElementById(timeWindow).disabled = false;
	}
	else {
		document.getElementById(timeWindow).disabled = true;
	}
}

function convert_date(currYear, today, i)
{
	// get form values
	var depMonth = document.afpForm.elements["depMonth_"+i].value;
	var depDay = document.afpForm.elements["depDay_"+i].value;
	var depTime = document.afpForm.elements["depTime_"+i].value;
	var departDate = new Date(currYear, depMonth-1, depDay);
	
	depTime = (depTime == "ANY") ? "0000" : depTime;
	
	if (departDate<today) {
		var currYearD = currYear + 1;
		var departString = currYearD+depMonth+depDay+depTime;
	} else {
		var departString = currYear+depMonth+depDay+depTime;
	}
	
	document.afpForm.elements["B_DATE_"+i].value = departString;
}

function submit_form()
{
	if(checkRequired() == false) return false;
	
	var retMonth = document.afpForm.retMonth.value;
	var retDay = document.afpForm.retDay.value;
	var retTime = document.afpForm.retTime.value;
	
	// get today - midnight
	var today = new Date();
	today.setHours(0);
	today.setMilliseconds(0);
	today.setMinutes(0);
	today.setSeconds(0);
	var currYear = today.getFullYear();
	
	var returnDate = new Date(currYear, retMonth-1, retDay);
	retTime = (retTime == 'ANY') ? "0000" : retTime;
	
	if (returnDate<today) {
		var currYearR = currYear + 1;
		var returnString = currYearR+retMonth+retDay+retTime;
	} else {
		var returnString = currYear+retMonth+retDay+retTime;
	}
	
	document.getElementById('returnDate').value = returnString;
	
	convert_date(currYear, today, 1);
	if (document.afpForm.TRIP_TYPE.selectedIndex == 2) {
		document.getElementById('B_DATE_2m').disabled = false;
		convert_date(currYear, today, 2);
		document.getElementById('B_DATE_2m').value = document.afpForm.elements['B_DATE_2'].value;
	}
	convert_date(currYear, today, 3);
	convert_date(currYear, today, 4);
	convert_date(currYear, today, 5);
	convert_date(currYear, today, 6);
	
	// clean up
	var k=0;
	var field_str = "";
	for(i=1; i<=6; i++)
	{
		k++;
		field_str = "TRAVELLER_TYPE_"+k;
		if(i==1)
			document.afpForm.elements[field_str].value = "ADT";
		else
			document.afpForm.elements[field_str].value = "";
	}
	for(i=1; i<=3; i++)
	{
		k++;
		field_str = "TRAVELLER_TYPE_"+k;
		document.afpForm.elements[field_str].value = "";
	}
	k=0;
	for(i=1; i<=2; i++)
	{
		k++;
		field_str = "HAS_INFANT_"+k;
		document.afpForm.elements[field_str].value = "";
	}
	
	// set traveller type
	var k=0;
	var field_str = "";
	for(i=1; i<=document.afpForm.ADT.value; i++)
	{
		k++;
		field_str = "TRAVELLER_TYPE_"+k;
		document.afpForm.elements[field_str].value = "ADT";
	}
	for(i=1; i<=document.afpForm.CHD.value; i++)
	{
		k++;
		field_str = "TRAVELLER_TYPE_"+k;
		document.afpForm.elements[field_str].value = "CHD";
	}
	k=0;
	for(i=1; i<=document.afpForm.INF.value; i++)
	{
		k++;
		field_str = "HAS_INFANT_"+k;
		document.afpForm.elements[field_str].value = "TRUE";
	}
	
	for(i=1; i<=6; i++)
	{
		field_str = "B_ANY_TIME_"+i;
		
		if (document.afpForm.elements["depTime_"+i].selectedIndex > 0) {
			document.afpForm.elements[field_str].value = "FALSE";
		}
		else {
			document.afpForm.elements[field_str].value = "TRUE";
		}
	}
	
	if(document.afpForm.flexible.checked == true)
	{
		document.afpForm.MINUS_DATE_RANGE_1.disabled = false;
		document.afpForm.PLUS_DATE_RANGE_1.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_2.disabled = false;
		document.afpForm.PLUS_DATE_RANGE_2.disabled = false;
		document.afpForm.MINUS_DATE_RANGE_1.value = 1;
		document.afpForm.PLUS_DATE_RANGE_1.value = 1;
		document.afpForm.MINUS_DATE_RANGE_2.value = 1;
		document.afpForm.PLUS_DATE_RANGE_2.value = 1;
	}
	else
	{
		document.afpForm.MINUS_DATE_RANGE_1.disabled = true;
		document.afpForm.PLUS_DATE_RANGE_1.disabled = true;
		document.afpForm.MINUS_DATE_RANGE_2.disabled = true;
		document.afpForm.PLUS_DATE_RANGE_2.disabled = true;
	}
	
	document.afpForm.submit();
}