window.onload = function() { getDate(); }

function validate() {
	var ref_month = document.getElementById('sel_month');
	var ref_duration = document.getElementById('sel_duration');
	
	if (ref_month.selectedIndex == 0 || ref_duration.selectedIndex == 0) {
		alert('Choose month and trip duration!');
		return false;
	}

	return true;
}

function daysInMonth(iMonth, iYear) {
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function getDate() {
	var curDate = new Date();
	var ref = document.getElementById('sel_month');
	var select_depart = document.getElementById('sel_depart');
	select_depart.options.length = 0;
	var year = ref.value.substr(0,4);
	var month = parseInt(ref.value.substr(4,2), 10)-1;

	if (ref.value > 0) {
		var tmpDate = new Date();
		
		var dim = daysInMonth(month, year);
		
		for (i=1; i<=dim; i++) {
			tmpDate.setFullYear(year, month, i);
			if (year == curDate.getFullYear() && month == curDate.getMonth() && i<curDate.getDate()) {
			}
			else {
				if (tmpDate.getDay() == 6) {
					var myval = i+". "+ (month+1) + ". " + year;
					select_depart.options[select_depart.options.length] = new Option(myval, myval);
				}
			}
		}
	}
	else {
		select_depart.options[select_depart.options.length] = new Option('Monat wähle ...', 0);
	}
}