function check_from_to_date(date_from_str, date_to_str) { // sprawdzenie czy data jest wczesniej niz date_to
	var from = date_from_str;
	var from_year = parseInt(from.substring(0,4), 10);
	var from_month = parseInt(from.substring(5,7), 10) -1; // 0..11
	var from_day = parseInt(from.substring(8,10), 10); // 1..31

	var date_to = date_to_str;
	var to_year = parseInt(date_to.substring(0,4), 10);
	var to_month = parseInt(date_to.substring(5,7), 10) -1; // 0..11
	var to_day = parseInt(date_to.substring(8,10), 10); // 1..31

	//alert(from_day+'-'+to_day);
    if (to_year < from_year) return true;
	if (to_year == from_year && to_month < from_month) return true;
	if (to_year == from_year && to_month == from_month && to_day <= from_day) return true;
	return false;
}

function check_from_to_date_byid(date_from_myear_id, date_from_day_id, date_to_myear_id, date_to_day_id) { // sprawdzenie czy data jest wczesniej niz date_to
	var date_from_myear_str =	document.getElementById(date_from_myear_id).options[document.getElementById(date_from_myear_id).selectedIndex].value;
	var date_from_day_str =		document.getElementById(date_from_day_id).options[document.getElementById(date_from_day_id).selectedIndex].value;
	var date_to_myear_str =		document.getElementById(date_to_myear_id).options[document.getElementById(date_to_myear_id).selectedIndex].value;
	var date_to_day_str =		document.getElementById(date_to_day_id).options[document.getElementById(date_to_day_id).selectedIndex].value;

	if (check_from_to_date(date_from_myear_str+'-'+date_from_day_str, date_to_myear_str+'-'+date_to_day_str)) {
		if (date_from_day_str == '31') {
			if (document.getElementById(date_from_myear_id).options.length > document.getElementById(date_from_myear_id).selectedIndex+1)	{
				document.getElementById(date_to_myear_id).options[document.getElementById(date_from_myear_id).selectedIndex+1].selected = true;
				document.getElementById(date_to_day_id).options[0].selected = true;
			} else {
				document.getElementById(date_to_myear_id).options[document.getElementById(date_from_myear_id).selectedIndex].selected = true;
				document.getElementById(date_to_day_id).options[document.getElementById(date_from_day_id).selectedIndex].selected = true;
				document.getElementById(date_from_day_id).options[document.getElementById(date_from_day_id).selectedIndex-1].selected = true;
			}
		} else {
			document.getElementById(date_to_myear_id).options[document.getElementById(date_from_myear_id).selectedIndex].selected = true;
			document.getElementById(date_to_day_id).options[document.getElementById(date_from_day_id).selectedIndex+1].selected = true;
		}
		//alert('Data zakończenia pobytu nie może być wcześniejsza i identyczna jak data rozpoczęcia pobytu. Wybierz późniejszą datę zakończenia pobytu.');
	} 
	//alert(date_from_myear_str+'-'+date_from_day_str+'---'+date_to_myear_str+'-'+date_to_day_str);

}

/* ustawienie daty dla obiektu kalendarza  cal */
function setdate(cal) {
		if (check_from_to_date(document.getElementById("date_from").value, document.getElementById("date_to").value)) {
			document.getElementById("date_to").value = document.getElementById("date_from").value;
		}
}
