
function submitBooking() {
	var form = window.document.manage;

	form.action.value= 'send';

	form.sys_sub_category.value = "Messages";
	form.sys_title.value = "Details Saved";

	if (validateBooking()) form.submit();
}

function submitRegistration() {
	var form = window.document.manage;
	form.action.value= 'saveRegistration';
	form.sys_sub_category.value = "Registration";
	form.sys_title.value = "Details Saved";
	if (validateRegistration()) form.submit();
}

function clickCancel() {
	var form = window.document.manage;
	form.sys_sub_category.value = "Messages";
	form.sys_title.value = "Details Cancelled";
	form.submit();
}


function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported)
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


function validateObject(control) {
	control.style.backgroundColor = '#ffffff';
	if (control.value == '') {
		control.style.backgroundColor = '#ce7b6b';
		control.focus();
		confirm("Please fill in all mandatory fields, which are highlighted in red.");
		return false;
	}
    return true;
}

function validateRegistration(action) {

	var form = window.document.manage;

	if (!validateObject(form.frm_name)) return false;
	if (!validateObject(form.frm_phone)) return false;
	
	form.frm_email.style.backgroundColor = '#ffffff';
	if (!validateObject(form.frm_email) || !isEmail(form.frm_email.value)) {
		form.frm_email.style.backgroundColor = '#ce7b6b';
		form.frm_email.focus();
		confirm("Please enter a valid email address.");
		return false;
	}
	form.frm_validated.value = "yes";

	return true;
}

function validateBooking(action) {

	var form = window.document.manage;

	if (!validateObject(form.frm_name)) return false;
	if (!validateObject(form.frm_phone)) return false;
	if (!validateObject(form.frm_mobile)) return false;
	if (!validateObject(form.frm_arrival_day)) return false;
	if (!validateObject(form.frm_arrival_month)) return false;
	if (!validateObject(form.frm_arrival_year)) return false;
	if (!validateObject(form.frm_depart_day)) return false;
	if (!validateObject(form.frm_depart_month)) return false;
	if (!validateObject(form.frm_depart_year)) return false;
	
	if (!validateObject(form.frm_number_guests)) return false;

	form.frm_email.style.backgroundColor = '#ffffff';
	if (!validateObject(form.frm_email) || !isEmail(form.frm_email.value)) {
		form.email.style.backgroundColor = '#ce7b6b';
		form.email.focus();
		confirm("Please enter a valid email address.");
		return false;
	}
	form.frm_validated.value = "yes";

	return true;
}

