/*
function BookHolidayNow(resort_id,resort,country_code,flying_from,dtDate,nights)
{
	document.frmHolidayearch.cboBoard.value = flying_from;
	document.frmHolidayearch.txtResort.value = resort;
	document.frmHolidayearch.cboCountries.value = country_code;
	document.frmHolidayearch.cboResort.value = resort_id;
	document.frmHolidayearch.dtDate.value = dtDate;
	document.frmHolidayearch.cboDuration.value = nights;
	document.frmHolidayearch.submit();
}
*/

function cboCountriesHoliday_onchange() {
	var szSelected = window.document.frmHoliday.cboCountries.options[window.document.frmHoliday.cboCountries.selectedIndex].value;

	if(szSelected!='$$NULL$$')
	{
		if(szSelected=='$$OTHER$$'){
			//window.open('http://tawl.holiday.co.uk/default.asp?WebsiteGUID={7fc411e5-ce5d-43de-97fb-faa9def4d5ef}');
			window.document.frmHoliday.method = "GET";
			window.document.frmHoliday.action = "frameset.html";
			window.document.frmHoliday.submit();
			return;
		}
		window.document.frmHoliday.action = "main.asp?searchmode=holidays";
		window.document.frmHoliday.submit();
	}
	else
	{
		window.document.frmHoliday.action = "main.asp?searchmode=holidays";
		window.document.frmHoliday.submit();
	}
}

function cboResortHoliday_onchange() {
	var szSelected = window.document.frmHoliday.cboResort.options[window.document.frmHoliday.cboResort.selectedIndex].value;

	if(szSelected!='$$NULL$$')
	{
		//if(szSelected=='$$OTHER$$'){
		//	window.open('http://tawl.holiday.co.uk/default.asp?WebsiteGUID={7fc411e5-ce5d-43de-97fb-faa9def4d5ef}');
		//	return;
		//}

		window.document.frmHoliday.txtResort.value = window.document.frmHoliday.cboResort.options[window.document.frmHoliday.cboResort.selectedIndex].text;
		//window.document.frmHoliday.action = "holidays_criteria.asp";
		window.document.frmHoliday.action = "main.asp?searchmode=holidays";
		window.document.frmHoliday.submit();
	}
	else
	{
		alert("Selectionner une ville");
	}
}


/*
function Next_Holiday()
{
	var szSelected = window.document.frmHoliday.cboResort.options[window.document.frmHoliday.cboResort.selectedIndex].value;

	if(szSelected=='$$NULL$$')
	{
		szSelected = window.document.frmHoliday.cboCountries.options[window.document.frmHoliday.cboCountries.selectedIndex].value;

		if(szSelected=='$$OTHER$$')
			cboCountriesHoliday_onchange();
		else
			cboResortHoliday_onchange();
	}
	else
		cboResortHoliday_onchange();
}
*/

function getHotelInfoHoliday()
{
	szSelected = window.document.frmHoliday.cboCountries.options[window.document.frmHoliday.cboCountries.selectedIndex].value;

	if(null==szSelected ||
		szSelected=='$$OTHER$$' ||
		szSelected == '$$NULL$$' ||
		szSelected == '')
	{
		alert("Merci de selectionner un pays");
		return;
	}

	window.document.frmHoliday.action = "Resort-02.asp"//"hotel_list.asp?cboCountries=" + szSelected;
	window.document.frmHoliday.submit();
}

function getResortInfoHoliday()
{
	//resort_list.asp
	szSelected = window.document.frmHoliday.cboCountries.options[window.document.frmHoliday.cboCountries.selectedIndex].value;

	if(null==szSelected ||
		szSelected=='$$OTHER$$' ||
		szSelected == '$$NULL$$' ||
		szSelected == '')
	{
		alert("Merci de selectionner un pays");
		return;
	}

	window.document.frmHoliday.action = "resort_list.asp?cboCountries=" + szSelected;
	window.document.frmHoliday.submit();
}


// Holidays_Criteria.asp
function CheckRoomLayoutHoliday(lPassengers)
{
	var lAdultsAlloc = 0,lChildrenAlloc = 0;
	//var lPassengers = <%=iif(Request.Form("cboPassengerCount")="",1,Request.Form("cboPassengerCount"))%>;
	var i = 0;
	var el;

	for(i=0;i<window.document.frmHoliday.elements.length;i++)
	{
		el = window.document.frmHoliday.elements[i];

		if (el.type == 'select-one')
		{
			if(el.options[el.selectedIndex].value == 'A')
				lAdultsAlloc++;
			if(el.options[el.selectedIndex].value == 'C')
				lChildrenAlloc++;
		}
	}

	if((lAdultsAlloc + lChildrenAlloc) != lPassengers)
	{
		alert("Le nombre d adultes et d enfants dans la chambre est incorrect.\nVous devez indiquer " + lPassengers.toString() + " passagers.");
		return false;
	}

	//Set adults and children
	window.document.frmHoliday.cboAdults.value = lAdultsAlloc;
	window.document.frmHoliday.cboChildren.value = lChildrenAlloc;
	return true;
}

function RefreshPageHoliday()
{
	window.document.frmHoliday.submit();
}

function Next_Holiday(szDirectPage)
{
	
		var frm = window.document.frmHoliday;
		var szError = "";
		
		var dtChkIn = 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 dtInDay = frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value
		var dtInMth = frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value
		var dtInYr = frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value
		
		
		if (IsDateHoliday(dtInDay,dtInMth,dtInYr)==false)
			szError+="\n - La date doit être correcte";
		
		if (IsDateHoliday(frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value,frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value,frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value)==false)
			szError+="\n - La date doit être correcte";
			
		//if (CheckDate(frm.dtOutDay.options[frm.dtOutDay.selectedIndex].value + " " + frm.dtOutMth.options[frm.dtOutMth.selectedIndex].value + " " + frm.dtOutYr.options[frm.dtOutYr.selectedIndex].value)==false)
		//	szError+="\n - La date doit être correcte";
		
		var lPassengers = new Number(frm.cboPassengerCount.options[frm.cboPassengerCount.selectedIndex].value);
		var lInfants = new Number(frm.cboInfant.options[frm.cboInfant.selectedIndex].value);
		
		var szSelected = window.document.frmHoliday.cboResort.options[window.document.frmHoliday.cboResort.selectedIndex].value;

		if(window.document.frmHoliday.cboBoard.selectedIndex == 0)
			szError+="\n - La ville de depart doit être selectionnee";
		
		if(szSelected=='$$NULL$$')
		{
			szSelected = window.document.frmHoliday.cboCountries.options[window.document.frmHoliday.cboCountries.selectedIndex].value;

			if(szSelected=='$$OTHER$$')
				cboCountriesHoliday_onchange();
			else
				cboResortHoliday_onchange();
		}
		else
			cboResortHoliday_onchange();
		
		//'alert(dtChkDate.valueOf();
		
		if(DaysDelta(dtNow,dtChkIn)>=0)
			szError+="\n - La date de depart n'est pas correcte";
		
		var szDuration = window.document.frmHoliday.cboDuration.options[window.document.frmHoliday.cboDuration.selectedIndex].value;
		if(szDuration=='$$NULL$$')
			szError+="\n - Veuillez choisir la durée";
		
		if(lInfants > lPassengers)
			szError+="\n - Le nombre de bebes ne peut exceder le nombre d'adultes";
			
		var szResort = window.document.frmHoliday.cboResort.options[window.document.frmHoliday.cboResort.selectedIndex].value;
		if(szResort=='$$NULL$$')
			szError+="\n - Selectionner une ville";
			
		if(szError!="")
		{
			alert("Certains des champs ne sont pas remplis correctement:\n" + szError);
			return;
		}
	
	if(!CheckRoomLayoutHoliday(lPassengers))
		return;
	
	//szDirectPage contains the page of the package type results
	//dynamicpkg_results.asp
	//holidays_results.asp
	
	window.document.frmHoliday.action = szDirectPage;//"packagedirect.asp";	
	window.document.frmHoliday.submit();		
}

function changeSelectionHoliday(source,target)
{
	target.selectedIndex = source.selectedIndex;
	updateDaysHoliday();
}

function updateDaysHoliday()
{
	//update day of week
	var days = new Array("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	//var dtOut = new Date(window.document.frmHoliday.dtChkOutDay.options[window.document.frmHoliday.dtChkOutDay.selectedIndex].value + " " + window.document.frmHoliday.dtChkOutMth.options[window.document.frmHoliday.dtChkOutMth.selectedIndex].value + " " + window.document.frmHoliday.dtChkOutYr.options[window.document.frmHoliday.dtChkOutYr.selectedIndex].value);
	var dtIn = new Date(window.document.frmHoliday.dtOutDay.options[window.document.frmHoliday.dtOutDay.selectedIndex].value + " " + window.document.frmHoliday.dtOutMth.options[window.document.frmHoliday.dtOutMth.selectedIndex].value + " " + window.document.frmHoliday.dtOutYr.options[window.document.frmHoliday.dtOutYr.selectedIndex].value);
	//window.lblOutDay.innerText = '(' + days[dtOut.getDay()] + ')';
	window.lblOutDay.innerText = '(' + days[dtIn.getDay()] + ')';
	window.document.frmHoliday.submit();
}

function IsDateHoliday(dtDay,dtMth,dtYr)
{
	var dtDate = new Date(dtDay + " " + dtMth + " " + dtYr);
		if (dtDate.getDate() != dtDay)
			return false;
		else
			return true;
}
