﻿var MonthLengthList = '31,29,31,30,31,30,31,31,30,31,30,31';

function setDate(type, action){
	var BookingForm = document.onlineBooking;
	var TodayDate = new Date();
	var Today = TodayDate.getDate();
	var Month = TodayDate.getMonth();
	var Year = TodayDate.getFullYear();
	if(type == 14 || type == 15){
		var SelectedDay = BookingForm.day.options[BookingForm.day.selectedIndex].value;
		var SelectedMonth = BookingForm.month.options[BookingForm.month.selectedIndex].value;
		var SelectedYear = BookingForm.year.options[BookingForm.year.selectedIndex].value;
		var SelectedDate = new Date(SelectedYear, SelectedMonth-1, SelectedDay);
		var TodayDate = new Date();
		if(Math.ceil((SelectedDate.getTime()-TodayDate.getTime())/(1000*60*60*24)) < 2){				
			var MonthLength = MonthLengthList.split(',');
			var ThisMonthLength = MonthLength[Month];
			if(Math.round(Today+2) > ThisMonthLength){
				var DayDifference = (Today+2) - ThisMonthLength;
				alert(DayDifference);
				if(DayDifference == 0){ AddDays = 2 } else { AddDays = DayDifference }
				Today = AddDays;
				Month += 1;
				(Month == 12) ? Month = 0 : Month = Month;
				if(Month == 11){
					Year += 1;
				}
			} else {
				Today += 2;
			}
			BookingForm.day.options[Today].selected = true;
			BookingForm.month.options[Month+1].selected = true;
			BookingForm.year.options[Year-2004].selected = true;
		}
	} else {
		if(action == 'load'){
			BookingForm.day.options[Today].selected = true;
			BookingForm.month.options[Month+1].selected = true;
			BookingForm.year.options[Year-2004].selected = true;
		}
	}
}

function validateBookingDate(lcid){
var BookingForm = document.onlineBooking;
var Day = BookingForm.day.options[BookingForm.day.selectedIndex].value;
var Month = BookingForm.month.options[BookingForm.month.selectedIndex].value;
var Year = BookingForm.year.options[BookingForm.year.selectedIndex].value;
var SelectedDate = new Date(Year, Month-1, Day);
if(BookingForm.grouptypes.value == 14 || BookingForm.grouptypes.value == 15){
	var TodayDate = new Date();
	if(Math.ceil((SelectedDate.getTime()-TodayDate.getTime())/(1000*60*60*24)) < 2){
		if(lcid == 1030){
			alert('Det er nøvendigt, at booke mindst 2 dage før ankomst,\nnår du vælger "Privat overnatning" eller "Lejlighed".\n\nDu bedes ændre den valgte ankomstdato.');
		} else {
			alert('When choosing "Bed & Breakfast" or "Apartment"\nyou have to book at least two days in advance!\n\nPlease change the selected date of arrival!');
		}
		return false;
	}
}
return true;
}

function addDays(dtmDate, lngNumberOfDays){
var dtmNewDate = new Date(dtmDate.getTime() + (lngNumberOfDays*24*60*60*1000));
return dtmNewDate;
}