// This function returns true if a string is empty, 
// (i.e. contains only whitespace)
function isEmpty(strIn) {
	//Assume the string is empty
	var empty = true;
			
	//Handle zero-length string
	if (strIn != null) {
		//For each character in the string
		for (i=0; i<strIn.length; i++) {
			//If the character is not a whitespace, then the string is not empty
			if (strIn.charAt(i) != " " && strIn.charAt(i) != "\t" && strIn.charAt(i) != "\n") {
				empty = false;
			}
		}
	}			
	//Return the end value
	return empty;
}
// This function returns true if the form is complete,
// (i.e. all required fields have non-whitespace characters in them).
function validateForm(objForm) {
		
	var completed = true;
	var errorsArray = new Array();
	var errorCount = -1;
			
	if (objForm == "") {
		completed = false;
		errorCount++;
		errorsArray[errorCount] = "No form supplied.";
	}
	else {
	
		//Check name
		if (isEmpty(objForm.elements["firstname"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No First Name supplied.";
		}

		//Check name
		if (isEmpty(objForm.elements["surname"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Surname supplied.";
		}
		
		//Check email
		if (isEmpty(objForm.elements["email"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Email supplied.";
		}		

		if (isEmpty(objForm.elements["CaptchaBox"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Security Check supplied.";
		}		
		
	}
			
	if (errorsArray.length > 0) {
		var strErrorString = "Unable to submit your message, please correct the following errors:\n";
				
		for (i=0; i<errorsArray.length; i++) {
			strErrorString += "\t" +errorsArray[i] +"\n";
		}
		//Display the alert
		alert(strErrorString);
	}
	return completed;
}


