// JavaScript Document
// whole form check
function checkBooking(theForm) {
    var why = "";
	why += checkName(theForm.name.value);
	why += checkEmail(theForm.email.value);
	why += checkEmail2(theForm.confirm_email.value, theForm.email.value);
	why += checkPhone(theForm.phone.value);	
	why += checkMobilePhone(theForm.phone_mobile.value);	
	
	for (i=0, n=theForm.availability_checkbox.length; i<n; i++) {
		if (theForm.availability_checkbox[i].checked) {
			var checkLocale = theForm.availability_checkbox[i].value;
			break;
		} 
	}
	why += checkLocation(checkLocale);	
	why += checkComment(theForm.note_narrow.value);
	if (why != "") {
		alert("There was a problem with your booking enquiry:\n\n"+ why);
		return false; 
	}
return true;
}


function checkSeminar(theForm) {
    var why = "";
	why += checkName(theForm.name.value);
	why += checkEmail(theForm.email.value);
	why += checkEmail2(theForm.confirm_email.value, theForm.email.value);
	why += checkComment(theForm.note_narrow.value);
	why += checkBHPhone(theForm.bh_phone.value);
	if (why != "") {
		alert("There was a problem with your booking enquiry:\n\n"+ why);
		return false; 
	}
return true;
}


// individual validation routines
function checkName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
	}
return error;
}

function checkEmail (strng) {
var error = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (strng =="") {
		error = "You didn't enter an email address.\n";
		return error;
	} 
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid email address.\n";
	}
return error;
}

function checkEmail2 (strng, strng2) {
var error = "";
var emailFilter=/^.+@.+\..{2,3}$/;
	if (strng =="") {
		error = "You didn't confirm your email address.\n";
		return error;
	} 
	if (!(strng == strng2)) { 
		error = "Your confirmed email address doesn't match.\n";
	}
return error;
}

function checkLocation(checkvalue)  {
var error = "";
   if (!(checkvalue)) {
       error = "You didn't enter your preferred location.\n";
    }
return error;    
}

function checkComment(checkvalue)  {
var error = "";
   if (checkvalue.length> 250) {
       error = "Please limit your comments to under 250 characters.\n";
    }
return error;    
}

function checkBHPhone(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your business hours telephone number.\n";
	}
return error;
}

function checkPhone(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your telephone number.\n";
	}
return error;
}

function checkMobilePhone(strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter your mobile telephone number.\n";
	}
return error;
}

