function CheckRoomLayoutAccom(cboPassengerCount)
{
	var lAdultsAlloc = 0,lChildrenAlloc = 0;
	var i = 0;
	var el;
	
	//var lPassengers = <%=iif(Request.Form("cboPassengerCount")="",1,Request.Form("cboPassengerCount"))%>;
	
	if(cboPassengerCount=='')
		var lPassengers = 1;
	else
		var lPassengers = cboPassengerCount;
	
		
	for(i=0;i<window.document.frmHolidayCrit.elements.length;i++)
	{
		el = window.document.frmHolidayCrit.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.");

		//alert("Le nombre de bebes ne peut exceder\nle nombre de personnes " + lPassengers.toString() + " passengers.");
		return false;
	}

	//Set adults and children
	window.document.frmHolidayCrit.cboAdults.value = lAdultsAlloc;
	window.document.frmHolidayCrit.cboChildren.value = lChildrenAlloc;
	return true;
}


function Next_Accom()
{
		var frm = window.document.frmHolidayCrit;
		var szError = "";

		var dtChkIn = new Date(frm.dtChkInDay.options[frm.dtChkInDay.selectedIndex].value + " " + frm.dtChkInMth.options[frm.dtChkInMth.selectedIndex].value + " " + frm.dtChkInYr.options[frm.dtChkInYr.selectedIndex].value);
		var dtChkOut = new Date(frm.dtChkOutDay.options[frm.dtChkOutDay.selectedIndex].value + " " + frm.dtChkOutMth.options[frm.dtChkOutMth.selectedIndex].value + " " + frm.dtChkOutYr.options[frm.dtChkOutYr.selectedIndex].value);
		var dtNow = new Date();
		var lPassengers = new Number(frm.cboPassengerCount.options[frm.cboPassengerCount.selectedIndex].value);
		var lInfants = new Number(frm.cboInfant.options[frm.cboInfant.selectedIndex].value);

		var dtOutDay = frm.dtChkOutDay.options[frm.dtChkOutDay.selectedIndex].value
		var dtOutMth = frm.dtChkOutMth.options[frm.dtChkOutMth.selectedIndex].value
		var dtOutYr = frm.dtChkOutYr.options[frm.dtChkOutYr.selectedIndex].value
	
		var dtInDay = frm.dtChkInDay.options[frm.dtChkInDay.selectedIndex].value
		var dtInMth = frm.dtChkInMth.options[frm.dtChkInMth.selectedIndex].value
		var dtInYr = frm.dtChkInYr.options[frm.dtChkInYr.selectedIndex].value
		
		if (IsDateAccom(dtOutDay,dtOutMth,dtOutYr)==false)
			szError+="\n - La date en partance doit être valide";
			
		if (IsDateAccom(dtInDay,dtInMth,dtInYr)==false)
			szError+="\n - La date d'arrivee est incorrecte";
		
		if(DaysDelta(dtNow,dtChkIn)>=0)
			szError+="\n - La date d'arrivee est incorrecte";
		if(DaysDelta(dtChkIn,dtChkOut)>=0)
			szError+="\n - La date d'arrivee doit preceder la date de depart";
		if(lInfants > lPassengers)
			szError+="\n - Le nombre de bebes ne peut exceder le nombre de personnes";
			
		if(szError!="")
		{
			alert("Les champs suivants n'ont pas ete rempli correctement:\n" + szError);
			return;
		}
	
	if(!CheckRoomLayoutAccom(lPassengers))
		return;
	
	window.document.frmHolidayCrit.action = "accomodation_results.asp";
	window.document.frmHolidayCrit.submit();
}

function changeSelectionAccom(source,target)
{
	target.selectedIndex = source.selectedIndex;
	updateDaysAccom();
}
function updateDaysAccom()
{
	//update day of week
	var days = new Array("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	var dtOut = new Date(window.document.frmHolidayCrit.dtChkOutDay.options[window.document.frmHolidayCrit.dtChkOutDay.selectedIndex].value + " " + window.document.frmHolidayCrit.dtChkOutMth.options[window.document.frmHolidayCrit.dtChkOutMth.selectedIndex].value + " " + window.document.frmHolidayCrit.dtChkOutYr.options[window.document.frmHolidayCrit.dtChkOutYr.selectedIndex].value);
	var dtIn = new Date(window.document.frmHolidayCrit.dtChkInDay.options[window.document.frmHolidayCrit.dtChkInDay.selectedIndex].value + " " + window.document.frmHolidayCrit.dtChkInMth.options[window.document.frmHolidayCrit.dtChkInMth.selectedIndex].value + " " + window.document.frmHolidayCrit.dtChkInYr.options[window.document.frmHolidayCrit.dtChkInYr.selectedIndex].value);

	window.lblOutDay.innerText = '(' + days[dtOut.getDay()] + ')';
	window.lblInDay.innerText = '(' + days[dtIn.getDay()] + ')';
}

function IsDateAccom(dtDay,dtMth,dtYr)
{
	var dtDate = new Date(dtDay + " " + dtMth + " " + dtYr);
		if (dtDate.getDate() != dtDay)
			return false;
		else
			return true;
}

function RefreshPageAccom()
{
	window.document.frmHolidayCrit.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.");

		//alert("Le nombre de bebes ne peut exceder le nombre de personnes " + lPassengers.toString() + " passengers.");
		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 (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 - The date must be valid";
		
		var lPassengers = new Number(frm.cboPassengerCount.options[frm.cboPassengerCount.selectedIndex].value);
		var lInfants = new Number(frm.cboInfant.options[frm.cboInfant.selectedIndex].value);
		
		if(window.document.frmHoliday.cboBoard.selectedIndex == 0)
			szError+="\n - La ville de depart doit être selectionnee";
		
		
		//'alert(dtChkDate.valueOf();
		
		if(DaysDelta(dtNow,dtChkIn)>=0)
			szError+="\n - La date d'arrivee est incorrecte";
		
		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 de personnes";
			
		if(szError!="")
		{
			alert("Les champs suivants n'ont pas ete rempli 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;
}
