//  functions to validate forms
//
// A utility function that returns true if a string contains only 
// whitespace characters.
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

	function checkEmail(checkStr,verbose) {
		rgxp = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if(checkStr.search(rgxp)) {
			if(verbose) {
				alert("Please enter a valid email address");
			}
			return false;
		}
		else {
			return true;
		}
	}
	function checkLength(checkStr,length,strText,verbose) {
		if(checkStr.length<length) {
			if(verbose) {
				alert("Please enter a valid " + strText);
			}
			return false;
		}
		else {
			return true;
		}
	}
//	function checkTel(checkStr,verbose) {
//		rgxp = /[0-9]/g;
//		alert(checkStr.search(rgxp));
//	}
	function checkAll(thisform) {
		blnError = false;
		strAlert = "To continue, please enter the following details:\n";
		//title
		if(!checkLength(thisform.title.value,1,false)) {
			strAlert+=" - Title\n";
			blnError=true;
		}
/*
		//first name
		if(!checkLength(thisform.firstname.value,1,false)) {
			strAlert+=" - First name\n";
			blnError=true;
		}
*/
		//'last name
		if(!checkLength(thisform.surname.value,1,false)) {
			strAlert+=" - Surname\n";
			blnError=true;
		}
/*
		//'address
		if(!checkLength(thisform.address.value,4,false)) {
			strAlert+=" - Address\n";
			blnError=true;
		}
		//town
		if(!checkLength(thisform.town.value,1,false)) {
			strAlert+=" - Town/City\n";
			blnError=true;
		}

		//postcode
		if(!checkLength(thisform.postcode.value,3,false)) {
			strAlert+=" - Postcode\n";
			blnError=true;
		}
*/
		//telephone
		if(!checkLength(thisform.phonenumber.value,6,false)) {
			strAlert+=" - Telephone/Mobile No\n";
			blnError=true
		}
		//email address
//		if(!thisform.declinemail.checked) {
			if(!checkLength(thisform.email.value,9,false)) {
				strAlert+=" - Email address\n";
				blnError=true;
			}
//		}

/*		if(thisform.HowDidYouHear.selectedIndex < 1) {
			strAlert+=" - How Did You Hear about us\n";
			blnError=true
		}
*/		
		if(blnError) {
			alert(strAlert);
			
			return false;
		}
		else if(!checkEmail(thisform.email.value,true)){
			return false;
		}
		else {
			return true;
		}
	}

	function checkCallback(thisform) {
		blnError = false;
		strAlert = "To continue, please enter the following details:\n";
		//first name
		if(!checkLength(thisform.Name.value,1,false)) {
			strAlert+=" - Name\n";
			blnError=true;
		}

		//telephone
		if(!checkLength(thisform.PhoneNumber.value,6,false)) {
			strAlert+=" - Telephone/Mobile No\n";
			blnError=true
		}
/*		//email address
		if(!thisform.declinemail.checked) {
			if(!checkEmail(thisform.email.value,false)) {
				strAlert+=" - Email address\n";
				blnError=true;
			}
		}
*/
		if(thisform.HowDidYouHear.selectedIndex < 1) {
			strAlert+=" - How Did You Hear about us\n";
			blnError=true
		}
		
		if(blnError) {
			alert(strAlert);
			
			return false;
		}
		else {
			return true;
		}
	}

