var monthObject;
var dayObject;

function OpenCalendar(month, day, lang) {
	monthObject = month;
	dayObject = day;
	var url = '?lang='+lang;
	if (month.value!='') url += '&start_date='+month.value;
	openwindow('http://booking.budapest-hotel-guide.hu/calendar.php'+url, 266, 185, 'CalendarFrame');
}

function setDateObjects(month, day) {
	// hónap beállítása
	for (var i=0; i<monthObject.options.length; i++){
		if (monthObject.options[i].value == month) {
			monthObject.options[i].selected = true;
			break;
		}
	}
	// nap beállítása
	for (var i=0; i<dayObject.options.length; i++){
		if (dayObject.options[i].value == day) {
			dayObject.options[i].selected = true;
			break;
		}
	}
	checkDate();
}

function checkDate() {
	var start = document.SearchForm.yearmonth.value+'-'+document.SearchForm.day.value;
	var end = document.SearchForm.dyearmonth.value+'-'+document.SearchForm.dday.value;
	if (start>=end) {
		var DayIndex = document.SearchForm.day.selectedIndex;
		var YearIndex = document.SearchForm.yearmonth.selectedIndex;
		if ((DayIndex+1)>30){
			if (YearIndex==document.SearchForm.dyearmonth.options.length-1){
				var newDayIndex = DayIndex;
				var newYearIndex = YearIndex;
			}else{
				var newDayIndex = 0;
				var newYearIndex = YearIndex+1;
			}
		}else{
			var newDayIndex = DayIndex+1;
			var newYearIndex = YearIndex;
		}
		document.SearchForm.dday.selectedIndex = newDayIndex;
		document.SearchForm.dyearmonth.selectedIndex = newYearIndex;
	}
}

function checkDate_() {
	var start = document.csop_form.yearmonth2.value+'-'+document.csop_form.day2.value;
	var end = document.csop_form.dyearmonth2.value+'-'+document.csop_form.dday2.value;
	if (start>=end) {
		var DayIndex = document.csop_form.day2.selectedIndex;
		var YearIndex = document.csop_form.yearmonth2.selectedIndex;
		if ((DayIndex+1)>30){
			if (YearIndex==document.csop_form.yearmonth2.options.length-1){
				var newDayIndex = DayIndex;
				var newYearIndex = YearIndex;
			}else{
				var newDayIndex = 0;
				var newYearIndex = YearIndex+1;
			}
		}else{
			var newDayIndex = DayIndex+1;
			var newYearIndex = YearIndex;
		}
		document.csop_form.dday2.selectedIndex = newDayIndex;
		document.csop_form.dyearmonth2.selectedIndex = newYearIndex;
	}
}