function trimString(theString) {
	while (theString.charAt(0) == " ") {
		theString = theString.substring(1,theString.length);
	}
	while (theString.charAt(theString.length - 1) == " ") {
		theString = theString.substring(0,theString.length - 1);
	}
	return theString;
}
function checkForm() {

	var errorStr = "";
	var ret = true;
	if (trimString(document.contactform.Name.value).length < 1){
			errorStr += "- You have not entered your name\n"
		}
	
	
	if (trimString(document.contactform.Mailfrom.value).length < 1) {
		errorStr += "\n- You have not entered your email address"
	}
	else {
		var s = document.contactform.Mailfrom.value;
		var posAt = s.indexOf('@');
		if (s.indexOf(' ') > -1 ) {
			errorStr += "\n- There must be no spaces in your email address";
			ret = false;
		}
		if (s.indexOf("'") > -1 ) {
			errorStr += "\n- There must be no apostrophes in your email address";
			ret = false;
		}
		if (ret) {
			if (posAt == 0) {
				errorStr += "\n- There must be a name before the @ symbol in your email address";
				ret = false;
			}
		}
		if (ret) {
			if (posAt == -1) {
				errorStr +="\n- There must be an @ symbol in your email address";
				ret = false;
			}
		}
		if (ret) {
			if (s.indexOf('@', posAt +1) > -1) {
				errorStr +="\n- There must only be one @ symbol in your email address";
				ret = false;
			}
		}
		if (ret) {
			if (posAt == s.length -1) {
				errorStr +="\n- Something must follow the @ symbol in your email address";
				ret = false;
			}
		}
		var posDot = s.indexOf('.', posAt);
		if (ret) {
			if (posDot == -1) {
				errorStr += "\n- There must be a host containing a dot following the @ symbol in your email address";
				ret = false;
			}
		}
		if (ret) {
			if (posDot == posAt + 1) {
				errorStr += "\n- There must be a name between the @ and . symbols in your email address";
				ret = false;
			}
		}
		if (ret) {
			if (posDot == s.length-1) {
				errorStr += "\n- A dot cannot be the last character in your email address";
				ret = false;
			}
		}
	}


		
	
	if (errorStr == "")	{
		
		return true;
	}
	else {
	
		alert ("Error: " + errorStr)
		return false;
	}
}

