function validateEmail (email) {
	// adapted from http://www.devarticles.com/c/a/JavaScript/Regular-expressions-in-JavaScript/8/
	// not the strictest around but decent enough
	//
	emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
	return emailpat.test(email);
}
//
function doUpdatePhone (id) {
	// this function updates the data for 'id' with data
	//
	var f = document.reservations;
	var val = f[id].value;
	val = val.replace(/([^0-9])/g,"");
	if (val!="") {
		if (parseInt(val)==0) val = 0;
	}
	f[id].value = val;
}
//
function doUpdate (id) {
	// this function updates the data for 'id' with data
	//
	var f = document.reservations;
	var val = f[id].value;
	val = val.replace(/([^0-9])/g,"");
	if (val!="") {
		if (parseInt(val)==0) val = 0;
		val = Math.min(6,val);
	}
	f[id].value = val;
}
//
function checkReservation () {
	// this form checks the filled in data and submits if necessary
	//
	var f = document.reservations;
	var isFilled = true;
	var isPhone = true;
	var isEmail = true;
	var isTicket = false;
	var returnValue = false;
	// mandatory fields
	// filled in fields
	if (f.firstname.value==""||f.lastname.value==""||f.city.value=="") isFilled = false;
	// filled in email
	if (isFilled&&(f.email.value==""||!validateEmail(f.email.value))) isEmail = false;
	// filled in phonenumber
	if (isFilled&&isEmail&&f.phone.value.length<6) isPhone = false;
	// ordered at least 1 ticket
	if (isFilled&&isEmail&&isPhone) {
		// friday
		if (f.fridayticket.value!=""||f.fridayhousing.value!="") isTicket = true;
		else if (f.saturdayticket.value!=""||f.saturdayhousing.value!="") isTicket = true;
		else if (f.sundayticket.value!=""||f.sundayhousing.value!="") isTicket = true;
		else if (f.alldaysticket.value!=""||f.alldayshousing.value!="") isTicket = true;
	}
	//
	if (isFilled&&isEmail&&isPhone&&isTicket) {
		f.action = "reservations.php";
		//
		returnValue = true;
	} else if (!isFilled) {
		var wrn = "You need to fill in all fields marked with * correctly.";
		alert(wrn);
	} else if (!isEmail) {
		var wrn = "You need to fill in a correct e-mail address.";
		alert(wrn);
	} else if (!isPhone) {
		var wrn = "You need to fill in a correct telephone-number.";
		alert(wrn);
	} else {
		var wrn = "You need to order at least 1 ticket.";
		alert(wrn);
	}
	//
	return returnValue;
}
