//// Search form presets handling	////

function checkQuickSearch(objForm, mustHaveDestination, mustHaveDeparture)
{
	var len = 0;
	
	// This checks the user is not simply moving between 'packages' and 'flights' search
	
	if(objForm.boardbasis)
	{
		if(objForm.boardbasis.value == -1)
		{
			alert("Please select a board basis.");
			return false;	
		}
	}
	
	if(objForm.airporttoid)
	{
		len = objForm.airporttoid.value.length;
		if ( objForm.airporttoid.value == '-1' )
		{
			len = 0;
		}
			
		if( mustHaveDestination && (len == 0) )
		{
			alert("Please select a destination airport");
			return false;
		}
		
		if(objForm.airportgroupfromid)
		{
			len = len + objForm.airportgroupfromid.value.length;
		}
		else if(objForm.airportcombinedfromid)
		{
			len = len + objForm.airportcombinedfromid.value.length;
		}	
		
		if( len == 0 )
		{
			alert("Please select a departure or destination area");
			return false;
		}
	}
	else if(objForm.resortgroupid)
	{
		len = objForm.resortgroupid.value.length + objForm.resorttoid.value.length;
		if(len == 0)
		{
			alert("Please select a country or resort");
			return false;
		}
	}
	
	if (mustHaveDeparture)
	{
		var error = '';
			
		if(objForm.airportgroupfromid && objForm.airportgroupfromid.value == '')
		{
			error = error + "Please select where you are travelling from.\n";	
		}
		
		if(objForm.airportfromid && objForm.airportfromid.value == '')
		{
			error = error + "Please choose a departure airport.\n";	
		}
		
		if(objForm.airportcombinedfromid && objForm.airportcombinedfromid.value.substring(0,1) != '|')
		{
			error = error + "Please choose a departure airport.\n";	
		}
		
		if(error.length > 0)
		{
			alert(error);
			return false;
		}
	}
	
	return true;
}

/* - for non-combined dates...
function changeMonth(objForm, date)
{
	var month, year;
	var today = new Date();

	// Get the existing day of month, to preserve where possible
	var daySelection = objForm.departure_day.value;
	
	date = date.split('-');
	day = date[2];
	month = date[1];
	year = date[0];

	var temp_start;
	
	if(typeof(addToToday) != 'undefined' && addToToday > 0)
	{
		temp_start = today.getDate() + addToToday	
	}
	else
	{
		temp_start = today.getDate();	
	}
		
	var start = (today.getMonth()+1 == month && year == today.getFullYear()) ? temp_start : 1;
	var max = 31;
	
	if(2 == month)
	{
		max = 28;
		if((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)))
		{
			max = 29;
		}
	}
	else if(4 == month || 6 == month || 9 == month || 11 == month)
	{
		max = 30;
	}
	
	objForm.departure_day.options.length = 0;
	var foundSelected = false;
	var selectedIndex; 

	for(var i = start; i < (max+1); i++)
	{
		var txt = '' + i;
		var isSelected = false;

		if(txt.length == 1)
		{
			txt = "0" + txt;
		}
		
		if (i == daySelection)
		{
			selectedIndex = i;
			foundSelected = true;
		}
		
		objForm.departure_day.options[objForm.departure_day.options.length]
			= new Option(txt, txt, false);
	}

	// Set selection if not done so already
	if ((! foundSelected) && objForm.departure_day.options.length)
	{
		if (daySelection < start)
		{
			objForm.departure_day.options[0].selected = true;
		}
		else if (daySelection > max)
		{
			objForm.departure_day.options[objForm.departure_day.options.length-1].selected = true;
		}
	}
	else if (selectedIndex)
	{
		//objForm.departure_day.options[selectedIndex-start].selected = true;
		objForm.departure_day.selectedIndex = selectedIndex-start;
	}
}

function update_dates_from_calendar(dateval)
{
	var date = dateval.split("-");
	
	var monthyear = document.getElementById("departure");
	monthyear.value = date[0] + "-" + date[1] + "-" + date[2];
	
	// update the days drop down
	changeMonth(monthyear.form, monthyear.value);	
}

function update_calendar_from_dates()
{
	var monthyear = document.getElementById("departure_monthyear");
	var day = document.getElementById("departure_day");
	var calendar = document.getElementById("f_date_c");
	
	calendar.value = monthyear.value + "-" + day.value;
	
}
 */

 // Show individual airports after an airport group has been selected
function changeAirports(element, type, keepFirst)
{
	// Get element for sub-menu
	var subElement;
	var subList;
	if (type == 'dep_airport_groups')
	{
		subElement = eval('document.forms.' + element.form.name + '.airportfromid');
		subList = arrDepAirports;
	}
	else if (type == 'dest_airport_groups')
	{
		subElement = eval('document.forms.' + element.form.name + '.airporttoid');
		subList = arrDestAirports;
	}
	else if (type == 'dest_resort_groups')
	{
		subElement = eval('document.forms.' + element.form.name + '.resorttoid');
		subList = arrDestResorts;
	}

	// Id for the current main menu selection, e.g. airport group id
	var elementId = element.value;

	// Clear out elements (if keepFirst is 1, the first item, probably "Any", will be kept)
	subElement.options.length = keepFirst;

	
	// Create select options for sub-elements matching current selection
	for (var i = 0; i < subList.length; i++)
	{
		if (subList[i][2] == elementId)
		{
			subElement[subElement.length] = new Option
			(
				subList[i][1],
				subList[i][0]
			);
		}
	}

	if(subElement.length > 1)
	{
		subElement.disabled = false;
	}
	else 
	{
		subElement.disabled = true;
	}
	

}
 
 function change_required_selected(select)
{
	//alert(select.name + ': ' + select.value); //ian@ithomas.name
	var style, color;
	if(!select)
	{
		return;
	}
	
	if(select.value != -1)
	{
		style = 'normal';
		color = '#000000';
	}
	else
	{
		style = 'bold';
		color = '#32BF00';
	}

	select.style.fontWeight = style;
	select.style.color = color;
	
	if ( select.options[0].value == -1)
	{
		select.options[0].style.fontWeight = 'bold';
		select.options[0].style.color = '#32BF00';
	}
	
	for(var i = 1; i < select.options.length; i++)
	{
		if(select.options[i].value != -1)
		{
			select.options[i].style.fontWeight = 'normal';
			select.options[i].style.color = '#000000';
		}
	}	
}
 