
function checkDate(dayId, monthId, yearId) {

	var day = document.getElementById(dayId).value;
   var month = document.getElementById(monthId).value - 1;
   var year = document.getElementById(yearId).value;

	current_date = new Date();
	form_date = new Date(year, month, day);

   while (day != form_date.getDate()) {
   	
		document.getElementById(dayId).selectedIndex = document.getElementById(dayId).selectedIndex - 1;
   	day = document.getElementById(dayId).value;
   	form_date = new Date(year, month, day);
      
   }
   
	/*if (current_date>form_date) {
		document.getElementById(dayId).selectedIndex = current_date.getDate()-1;
		document.getElementById(monthId).selectedIndex = current_date.getMonth();
	}*/
	
}

function checkForm1() {

	var checkin_day = document.getElementById('checkin_day').value;
   var checkin_month = document.getElementById('checkin_month').value - 1;
   var checkin_year = document.getElementById('checkin_year').value;

	checkin_date = new Date(checkin_year, checkin_month, checkin_day);
	
	var checkout_day = document.getElementById('checkout_day').value;
   var checkout_month = document.getElementById('checkout_month').value - 1;
   var checkout_year = document.getElementById('checkout_year').value;

	checkout_date = new Date(checkout_year, checkout_month, checkout_day);
	
	var tdate = new Date();
	var current_date = new Date(tdate.getFullYear(), tdate.getMonth(), tdate.getDate());

	if (checkin_date<current_date) {
		alert ("UWAGA:\nWybrano nieprawidłową datę przyjazdu");
		return false;
	} else if (checkout_date<current_date) {
		alert ("UWAGA:\nWybrano nieprawidłową datę wyjazdu");
		return false;
	} else if (checkin_date>checkout_date) {
		alert ("UWAGA:\nWybrano datę wyjazdu poprzedzającą datę przyjazdu");
		return false;
	} else if (checkin_date.toString() == checkout_date.toString()) {
		alert ("UWAGA:\nWybrana data wyjazdu pokrywa się z datą przyjazdu");
		return false;
	}
	
	return true;
}

function checkForm2(formName) {

	fields = document.getElementById(formName).elements;
	flag = false;

	for (i = 0; i < fields.length; i++) {
	
		if ((fields[i].type=='checkbox')&&(fields[i].checked)) {
			flag = true;
		}
	
	}
	
	if (flag) {
	
		return true;
		
	} else {
	
		return false;
		
	}
	
}

function checkForm3() {

	firstname = document.getElementById('firstname').value;
	surname = document.getElementById('surname').value;
	phone = document.getElementById('phone').value;
	email = document.getElementById('email').value;
	rules = document.getElementById('rules_check').value;
	
	reg = new RegExp("^[0-9a-zA-Z]+([\-_\\.]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+([\-\\.]?[0-9a-zA-Z]+)*\\.[a-zA-Z]{2,6}$");

	if (firstname=='') {
		alert("UWAGA:\nNie wypełniono wymaganego pola 'Imię'");
		return false;
	} else if (surname=='') {
		alert("UWAGA:\nNie wypełniono wymaganego pola 'Nazwisko'");
		return false;
	} else if (phone=='') {
		alert("UWAGA:\nNie wypełniono wymaganego pola 'Telefon'");
		return false;
	} else if (phone.length<7) {
		alert("UWAGA:\nPodany w polu 'Telefon' numer jest za krótki");
		return false;
	} else if (email=='') {
		alert("UWAGA:\nNie wypełniono wymaganego pola 'Email'");
		return false;
	} else if (!reg.test(email)){
		alert("UWAGA:\nPodany adres w polu 'Email' jest niepoprawny");
		return false;
	} else if (!document.getElementById('rules_check').checked) {
		alert("UWAGA:\nWymagana akceptacja regulaminu rezerwacji");
		return false;
	}
	
	return true;
	
}