function strip(inStr) {
   	while (inStr.substring(0, 1) == ' ') // If first char a space...
		inStr = inStr.substring(1); // ...remove it.
   	while (inStr.substring(inStr.length-1, inStr.length) == ' ') // If last char a space...
		inStr = inStr.substring(0, inStr.length-1); // ...remove it.
   	return inStr;
}

function validateFields(userForm) {
	var validNameChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-'";
	var validSecChars = "0123456789" + validNameChars.substr(0, 52);
	var userID = userForm.userId.value;
	if (document.getElementById) {
		node = document.getElementById('errMsg').childNodes[0];
		if (userID == "") {
			node.nodeValue = "Error: User ID is blank";
			return false;
		}
		for (i = 0; i < userID.length; i++) {
			if (validSecChars.indexOf(userID.substr(i, 1)) == -1) {
				node.nodeValue = "Error: User Id contains invalid characters, must be 0-9, a-z or A-Z";
				return false;
			}
		}
	}
	return true;
}

function processForm(userForm) {
	userForm.userId.value = strip(userForm.userId.value);
	return (validateFields(userForm));
}
