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("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	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()] + ')';
}

//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("Vous ne pouvez pas selctionner ce trajet des offres speciales car vous avez deja selectionne un trajet.\n\nVoulez vous quand meme essayer?\n\nCliquez sur OK pour essayer, cliquez sur annuler et choisissez votre trajet vous memes."))
			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","Fev","Mar","Avr","Mai","Jun","Jui","Aou","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("Selectionner votre date de retour, le genre de billet souhaite et le nombre de personnes. Puis cliquer sur 'Chercher'.");
}

//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 - La date d'arrivée du vol est incorrecte.";
			
		if(DaysDelta(dtOut,dtIn)>0)
			szError+="\n - La date d'arrivée du vol doit etre posterieure a la date de depart.";
	}

	if(IsDate(dtOutDay,dtOutMth,dtOutYr)==false)
		szError+="\n - La date de depart est incorrecte";

	if(DaysDelta(dtNow,dtOut)>=1)
		szError+="\n - La date de depart est incorrecte";
	if(frm.cboBoard.selectedIndex == 0)
		szError+="\n - Selectionner la ville de depart";
	if(frm.cboArriv.selectedIndex == 0)
		szError+="\n - Selectionner la ville d arrivee";
	if(lInfants > lAdults)
		szError+="\n - Le nombre de bebes ne peut exceder le nombre de personnes";
	if((lChildren + lAdults) > 9)
		szError+="\n - Le nombre d adultes et d enfants ne peut exceder 9, pour reserver plus de 9 personnes contactez notre Centrale de reservations ou aller sur Groupes";
	if(szError!="")
	{
		alert("Les champs suivants n'ont pas ete rempli correctement:\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;
}

