function Register(txtRegister)
{
	openWindow(300,250,'register','register.asp?data=' + window.document.frmRegister.txtRegister.value);
}

// Manages Day change next to dates as well as aligning return dates with outbound
function changeSelectionFlight(source,target)
{
	if(window.document.frmFlightSearch.cboTicketType.options[window.document.frmFlightSearch.cboTicketType.selectedIndex].value=='')
	{
		target.selectedIndex = source.selectedIndex;
		updateDaysFlight(true);
	}
	else
		updateDaysFlight(false);
}

function updateDaysFlight(bIncInBound)
{
	
	//update day of week
	var days = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var dtOut = new Date(window.document.frmFlightSearch.dtOutDay.options[window.document.frmFlightSearch.dtOutDay.selectedIndex].value + " " + window.document.frmFlightSearch.dtOutMth.options[window.document.frmFlightSearch.dtOutMth.selectedIndex].value + " " + window.document.frmFlightSearch.dtOutYr.options[window.document.frmFlightSearch.dtOutYr.selectedIndex].value);

	if(bIncInBound)
	{
		var dtIn = new Date(window.document.frmFlightSearch.dtInbDay.options[window.document.frmFlightSearch.dtInbDay.selectedIndex].value + " " + window.document.frmFlightSearch.dtInbMth.options[window.document.frmFlightSearch.dtInbMth.selectedIndex].value + " " + window.document.frmFlightSearch.dtInbYr.options[window.document.frmFlightSearch.dtInbYr.selectedIndex].value);
		window.lblInDay.innerText = '(' + days[dtIn.getDay()] + ')';
	}

		window.lblOutDay.innerText = '(' + days[dtOut.getDay()] + ')';
	
	/*
	//update day of week
	var days = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	var dtOut = new Date(window.document.frmFlightSearch.dtOutDay.options[window.document.frmFlightSearch.dtOutDay.selectedIndex].value + " " + window.document.frmFlightSearch.dtOutMth.options[window.document.frmFlightSearch.dtOutMth.selectedIndex].value + " " + window.document.frmFlightSearch.dtOutYr.options[window.document.frmFlightSearch.dtOutYr.selectedIndex].value);

	if(bIncInBound)
	{
		var dtIn = new Date(window.document.frmFlightSearch.dtInbDay.options[window.document.frmFlightSearch.dtInbDay.selectedIndex].value + " " + window.document.frmFlightSearch.dtInbMth.options[window.document.frmFlightSearch.dtInbMth.selectedIndex].value + " " + window.document.frmFlightSearch.dtInbYr.options[window.document.frmFlightSearch.dtInbYr.selectedIndex].value);
		lblInDay.innerText = '(' + days[dtIn.getDay()] + ')';
	}
		lblOutDay.innerText = '(' + days[dtOut.getDay()] + ')';
	*/
	
}

//Manages Ticket Type
function TicketType_Change() {
	window.document.frmFlightSearch.ckOneWay.value = window.document.frmFlightSearch.cboTicketType.options[window.document.frmFlightSearch.cboTicketType.selectedIndex].value;
	window.document.frmFlightSearch.submit();
}

//Manage Holiday Book Now
function BookHolidayNow(resort_id,resort,country_code,flying_from,dtDate,nights)
{
	document.frmHolidaySearch.cboBoard.value = flying_from;
	document.frmHolidaySearch.txtResort.value = resort;
	document.frmHolidaySearch.cboCountries.value = country_code;
	document.frmHolidaySearch.cboResort.value = resort_id;
	document.frmHolidaySearch.dtDate.value = dtDate;
	document.frmHolidaySearch.cboDuration.value = nights;
	document.frmHolidaySearch.submit();
}

//Manage Flight Book Now
function BookFlightNow(dept,arv,dt)
{
	if(document.frmFlightSearch.cboBoard.value!='')
	{
		if(!confirm("It may not be possible to select the correct routes for this special offer due to a previous selection.\n\nWould you like to try anyway?\n\nClick OK to try, click cancel to select the route yourself."))
			return;
	}

	document.frmFlightSearch.cboBoard.value = dept;
	if(document.frmFlightSearch.cboBoard.selectedIndex == -1)
		document.frmFlightSearch.cboBoard.selectedIndex = 0;
		
	document.frmFlightSearch.cboArriv.value = arv;
	if(document.frmFlightSearch.cboArriv.selectedIndex == -1)
		document.frmFlightSearch.cboArriv.selectedIndex = 0;

	var dtDate = new Date(dt);
	var day = dtDate.getDate();

	if(day<10)
	{
		document.frmFlightSearch.dtOutDay.value = '0' + day;
			
		if(document.frmFlightSearch.cboTicketType.value == '')
			document.frmFlightSearch.dtInbDay.value = '0' + day;
	}
	else 
	{
		document.frmFlightSearch.dtOutDay.value = day;
		
		if(document.frmFlightSearch.cboTicketType.value == '')
			document.frmFlightSearch.dtInbDay.value = day;
	}

	var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	document.frmFlightSearch.dtOutMth.value = months[dtDate.getMonth()];
	//document.frmFlightSearch.dtInbMth.value = months[dtDate.getMonth()];

	document.frmFlightSearch.dtOutYr.value = dtDate.getFullYear();
	//document.frmFlightSearch.dtInbYr.value = dtDate.getFullYear();

	alert("Please select your prefered return date, your ticket type and the number of passengers. Once done click 'Search Now'.");
}

//Manage Flight Search
function Next() {

	var frm = window.document.frmFlightSearch;
	var szError = "";

	var dtOut = new Date(frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value + " " + frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value + " " + frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value);
	var dtNow = new Date();
	var lAdults = new Number(frm.cboAdult.options[frm.cboAdult.selectedIndex].value);
	var lChildren = new Number(frm.cboChild.options[frm.cboChild.selectedIndex].value);
	var lInfants = new Number(frm.cboInfant.options[frm.cboInfant.selectedIndex].value);
	
		
	var dtOutDay = frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value
	var dtOutMth = frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value
	var dtOutYr = frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value
	
	
	
	//if chOneWay is "" then deal with return
	if(window.document.frmFlightSearch.ckOneWay.value == '')
	{
		var dtOut = new Date(frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value + " " + frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value + " " + frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value);
		var dtIn = new Date(frm.dtInbDay.options[frm.dtInbDay.selectedIndex].value + " " + frm.dtInbMth.options[frm.dtInbMth.selectedIndex].value + " " + frm.dtInbYr.options[frm.dtInbYr.selectedIndex].value);
	
		var dtInDay = frm.dtInbDay.options[frm.dtInbDay.selectedIndex].value
		var dtInMth = frm.dtInbMth.options[frm.dtInbMth.selectedIndex].value
		var dtInYr = frm.dtInbYr.options[frm.dtInbYr.selectedIndex].value
		
		if(IsDate(dtInDay,dtInMth,dtInYr)==false)
			szError+="\n - Inbound flight date must be valid";
		
			
		if(DaysDelta(dtOut,dtIn)>0)
			szError+="\n - Inbound flight date must be after outbound flight date";
	}

	if(IsDate(dtOutDay,dtOutMth,dtOutYr)==false)
		szError+="\n - Outbound flight date must be valid";


	if(DaysDelta(dtNow,dtOut)>=1)
		szError+="\n - Departure date must be in the future";
	if(frm.cboBoard.selectedIndex == 0)
		szError+="\n - Boarding City must be selected";
	if(frm.cboArriv.selectedIndex == 0)
		szError+="\n - Arrival City must be selected";
	if(lInfants > lAdults)
		szError+="\n - Number of infants can not outnumber the number of adults";
	if((lChildren + lAdults) > 9)
		szError+="\n - Number of adults and children can not exceed 9, to book more than 9 people call reservations or goto Group Travel";
	if(szError!="")
	{
		alert("Some of the fields have not been completed correctly, they are as follows:\n" + szError);
		return;
	}

	//window.document.frmFlightSearch.action = "charterflightresults.asp";
	window.document.frmFlightSearch.action = "charterflightresults.asp";
	window.document.frmFlightSearch.submit();
}

function holidayChange(selectBox)
{
	if(selectBox.options[selectBox.selectedIndex].value=="")
		return;
	
	window.location = 'main.asp?holidayselected=' + selectBox.options[selectBox.selectedIndex].value;
}


function resortChange(selectBox)
{
	if(selectBox.options[selectBox.selectedIndex].value=="")
		return;
	
	window.location = 'main.asp?resortselected=' + selectBox.options[selectBox.selectedIndex].value;
}

function IsDate(dtDay,dtMth,dtYr)
{
	var dtDate = new Date(dtDay + " " + dtMth + " " + dtYr);
		if (dtDate.getDate() != dtDay)
			return false;
		else
			return true;
}

