// 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["Name"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Name supplied.";
		}
		
		//Check Email
		if (isEmpty(objForm.elements["Email"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Email supplied.";
		}		
		
		//Check Tel
		if (isEmpty(objForm.elements["Tel"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No Telephone number supplied.";
		}				
		
		//Check State
		if (isEmpty(objForm.elements["State"].value)) {
			completed = false;
			errorCount++;
			errorsArray[errorCount] = "No State supplied.";
		}				

	}
			
	if (errorsArray.length > 0) {
		var strErrorString = "Unable to submit registration, the following errors occurred:\n";
				
		for (i=0; i<errorsArray.length; i++) {
			strErrorString += "\t" +errorsArray[i] +"\n";
		}
		//Display the alert
		alert(strErrorString);
	}
	return completed;
}


