var firstError = null;
var errorstring = '';
var validForm = true;
var reqFields = {
	'surname' : 'your surname',
	'firstname' : 'your firstname',
	'city' : 'your city',
	'street' : 'your street',
	'country' : 'your country',
	'zip_code' : 'your zip code',
	'email' : 'your email address',
	'phone_cell' : 'your cell phone number',
	'phone_home' : 'your home phone number',
	'check_in' : 'your check in date',
	'check_out' : 'your check out date',
	'occupancy' : 'your occupancy',
};

window.onload = function () {
	document.forms['frm_reservation'].onsubmit = function () {
		return validate();
	}
}

function validate() {
	validForm = true;
	firstError = null;
	errorstring = '';
	var x = document.forms['frm_reservation'].elements;
	for (var key in reqFields) {
		if (!x[key].value)
			writeError(x[key],'Please provide ' + reqFields[key]);
	}
	if (x['email'].value.indexOf('@') == -1)
		writeError(x['email'], 'Email address is not valid!');
	if (!validForm)
		alert('Please correct the following:\n\n' + errorstring);
	if (firstError)
		firstError.focus();
	return validForm;
}

function writeError(obj, message) {
	validForm = false;
	if (obj.hasError) return;
	errorstring += '* ' + message + '\n';
	obj.hasError = true;
	if (!firstError) firstError = obj;
}
 