function checkPaxNums(aid,cid,iid,which) {
	var a = document.getElementById(aid);
	var c = document.getElementById(cid);
	var i = document.getElementById(iid);
	if (i.options[i.selectedIndex].value > a.options[a.selectedIndex].value) {
		alert('You can only search for a maximum of one infant per adult');
		i.selectedIndex = a.selectedIndex+1;
	}
}

function oneWay() {
	document.getElementById('returnDay').selectedIndex = '0';
	document.getElementById('returnMonth').selectedIndex = '0';
}

function validateDates(mode) {
	var OutboundDay, OutboundMonth, ReturnDay, ReturnMonth;
	var OutboundDayEl, OutboundMonthEl, ReturnDayEl, ReturnMonthEl;
	var ReturnDayAlert, ReturnMonthAlert;
	var ReturnDayStart, ReturnMonthStart;
	if (mode=='fo') {
		OutboundDayEl = document.getElementById('outboundDay')
		OutboundDay = OutboundDayEl.selectedIndex;

		OutboundMonthEl = document.getElementById('outboundMonth')
		OutboundMonth = OutboundMonthEl.selectedIndex;

		ReturnDayEl = document.getElementById('returnDay')
		ReturnDay = ReturnDayEl.selectedIndex;

		ReturnMonthEl = document.getElementById('returnMonth')
		ReturnMonth = ReturnMonthEl.selectedIndex;

		ReturnDayAlert = ReturnDay - 1;
		ReturnMonthAlert = ReturnMonth - 1;

		ReturnDayStart = 0;
		ReturnMonthStart = 0;
	}
	if (mode=='fh') {
		OutboundDayEl = document.getElementById('fhOutboundDay')
		OutboundDay = OutboundDayEl.selectedIndex;
		OutboundDay = OutboundDay - 1;

		OutboundMonthEl = document.getElementById('fhOutboundMonth')
		OutboundMonth = OutboundMonthEl.selectedIndex;
		OutboundMonth = OutboundMonth - 1;

		ReturnDayEl = document.getElementById('fhReturnDay')
		ReturnDay = ReturnDayEl.selectedIndex;
		ReturnMonthEl = document.getElementById('fhReturnMonth')
		ReturnMonth = ReturnMonthEl.selectedIndex;

		ReturnDayAlert = ReturnDay - 1;
		ReturnMonthAlert = ReturnMonth;

		ReturnDayStart = -1;
		ReturnMonthStart = -1;
	}

	if ((ReturnMonth > ReturnMonthStart) && (ReturnMonth < (OutboundMonth + 1))) {
		ReturnMonthEl.selectedIndex = OutboundMonth + 1;
	} else if ((ReturnDay > ReturnDayStart) && ReturnMonth < (OutboundMonth + 1) && (ReturnDay < OutboundDay + 1)) {
		ReturnMonthEl.selectedIndex = OutboundMonth + 1;
	}

	if (ReturnDay == ReturnDayStart) ReturnMonthEl.selectedIndex = ReturnMonthStart;

	if (mode=='fo') {
		if ((ReturnMonthAlert == (OutboundMonth)) && (ReturnDayAlert == (OutboundDay))) {
			document.getElementById('samedayalert').style.display='block';
		} else {
			document.getElementById('samedayalert').style.display='none';
		}
	}
}

function checkDates(mode) {
	if (mode=='fo' && document.getElementById('returnDay')) {
		var OutboundDay = document.getElementById('outboundDay').selectedIndex;
		var OutboundMonth = document.getElementById('outboundMonth').selectedIndex;
		var ReturnDay = document.getElementById('returnDay').selectedIndex;
		var ReturnMonth = document.getElementById('returnMonth').selectedIndex;
		if (ReturnDay == 0 && ReturnMonth == 0) {
			document.foForm.submit();
		}
		else if (ReturnMonth -1 < OutboundMonth) {
			alert('Your return date cannot be before your outbound date. Please select the correct date.');
		}
		else if ((ReturnMonth -1 == OutboundMonth) && (ReturnDay -1 < OutboundDay)) {
			alert('Your return date cannot be before your outbound date. Please select the correct date.');
		}
		else document.foForm.submit();
	}
	else if (mode=='fo') {
		document.foForm.submit();
	}
	else if (mode=='fh') {
		var OutboundDay = document.getElementById('fhOutboundDay').selectedIndex;
		var OutboundMonth = document.getElementById('fhOutboundMonth').selectedIndex;
		var ReturnDay = document.getElementById('fhReturnDay').selectedIndex;
		var ReturnMonth = document.getElementById('fhReturnMonth').selectedIndex;
		var hotelInDay = document.getElementById('hotelinD').selectedIndex;
		var hotelInMonth = document.getElementById('hotelinM').selectedIndex;
		var hotelOutDay = document.getElementById('hoteloutD').selectedIndex;
		var hotelOutMonth = document.getElementById('hoteloutM').selectedIndex;
		if (ReturnMonth < OutboundMonth) {
			alert('Your return date cannot be before your outbound date. Please select the correct date.');
		}
		else if ((ReturnMonth == OutboundMonth) && (ReturnDay < OutboundDay)) {
			alert('Your return date cannot be before your outbound date. Please select the correct date.');
		}
		else if ((ReturnMonth == OutboundMonth) && (ReturnDay == OutboundDay)) {
			alert('Your outbound and return dates cannot be the same. Please select the correct dates.');
		}
		else if (document.getElementById('parthotel').checked == true) {
			if (hotelOutMonth < hotelInMonth) {
				alert('You have selected to only stay in a hotel for part of your stay, but you have selected to check out before you check in. Please select the correct dates.');
			}
			else if ((hotelOutMonth == hotelInMonth) && (hotelOutDay < hotelInDay)) {
				alert('You have selected to only stay in a hotel for part of your stay, but you have selected to check out before you check in. Please select the correct dates.');
			}
			else if ((hotelOutMonth == hotelInMonth) && (hotelInDay > hotelOutDay)) {
				alert('You have selected to only stay in a hotel for part of your stay, but you have selected to check out before you check in. Please select the correct dates.');
			}
			else if ((hotelInMonth < OutboundMonth) || (hotelInMonth > OutboundMonth) || (hotelOutMonth < ReturnMonth) || (hotelOutMonth > ReturnMonth)) {
				alert('You have selected to only stay in a hotel for part of your stay, but your hotel stay dates are not within the dates of your flights. Please select the correct dates.');
			}
			else document.fhForm.submit();
		}
		else document.fhForm.submit();
	}
}

function changeDestination(select) { 
  if (select=='dfe') {
	document.getElementById('dfe').style.display='none';
	document.getElementById('ddd').style.display='block';
	document.getElementById('destinationSelectFreeEntry').checked=false;
	}
	if (select=='ddd') {
	document.getElementById('dfe').style.display='block';
	document.getElementById('ddd').style.display='none';
	document.getElementById('destinationSelectDropdown').checked=false;
	}
}

function clickDestination(select) { 
	document.getElementById('ddd').style.display='none';
	document.getElementById('dfe').style.display='block';
	document.getElementById('destinationSelectFreeEntry').checked=true;
	document.getElementById('destinationSelectDropdown').checked=false;
	 document.getElementById('iataTo').value=select;
}

function clickDestinationAlternate(id, select) { 
	document.getElementById(id).style.backgroundColor='#FFFF80';
	document.getElementById(id).value=select;
}

function DoReturnDate() {
	var OutboundDay = document.getElementById('outboundDay').selectedIndex;
	var OutboundMonth = document.getElementById('outboundMonth').selectedIndex;
	var ReturnDay = document.getElementById('returnDay').selectedIndex;
	var ReturnMonth = document.getElementById('returnMonth').selectedIndex;
	if (ReturnDay -1 < OutboundDay && ReturnMonth <= (OutboundMonth +1)) {
		document.getElementById('returnMonth').value = document.getElementById('outboundMonth').options[OutboundMonth + 1].value;
	} 
}

function multiLegAddLeg(num) {
	$('#multilegaddleg'+num).slideUp();
	$('#multileg'+(num+1)).slideDown();
}

function updateChildrenCount(type, room) {
	if (type == 'hotel') {
		var display = 'none';
		var newValue = document.getElementById('numChildren' + room).selectedIndex;
		for (var i=1; i <= 9; i++) {
			if (i <= newValue) {
				display = 'block';
			} else {
				display = 'none';
			}
			document.getElementById('room' + room + 'child' + i + 'box').style.display=display;
		}
	}
}

