
function checkWholeForm(theForm) {
    var exp = new Date();
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31));
	var vfname=theForm.info[first_name].value;
	var why = "";
    why += checkFName(theForm.info[first_name].value);
    why += checkLName(theForm.info[last_name].value);
	why += checkEmail(theForm.info[email].value);
    why += checkComments(theForm.info[comments].value); 
	if (why != "") {
       alert(why);
	return false;
    }
	setCookie ("Visitor", vfname, exp);
	return true;
}


//=================================================
function checkFName(strng) {
	var illegalChars = /[^A-Za-z\.\W{1,2}]/; // allow only letters, dot, 1 or 2 spaces
	error = "";
	if (isWhitespace(strng))
		{error = "You have not entered a First Name.\n";}
    else if (illegalChars.test(strng)) 
		{error = "The First Name contains illegal characters.\n"};
return error;
}

//=================================================
function checkLName(strng) {
	var illegalChars = /[^A-Za-z\.\W{1,2}]/; // allow only letters, dot, 1 or 2 spaces
	error = "";
	if (isWhitespace(strng))
		{error = "You have not entered a Last Name.\n";}
    else if (illegalChars.test(strng)) 
		{error = "The Last Name contains illegal characters.\n";}
return error;
}

//=================================================
function checkEmail(strng) {
	var emailFilter=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	error="";	
	if (!(emailFilter.test(strng))) 
       {error = "Please enter a valid email address.\n";}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) 
		{error = "The email address contains illegal characters.\n";}
return error;
}

//=================================================
function checkComments(strng) {
	error = "";
	if (isWhitespace(strng))
		{error = "You have not entered your Text Message.\n";}
return error;
}


//=======Check whether string s is empty.===========================
function isEmpty(s){
return ((s == null) || (s.length == 0));
}

//=================================================
// whitespace characters
var whitespace = " \t\n\r";

function isWhitespace (s) {
     var i;
		// Is s empty?
     if (isEmpty(s)) return true;
		// Search through string's characters one by one
		// until we find a non-whitespace character.
		// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
           {var c = s.charAt(i);
			if (whitespace.indexOf(c) == -1) return false;
           }
           // IF all characters are whitespace.
return true;
      }

