// this function is here to check to see that the password is at least 4 characters long
function _at_least_4_char(obj) {
	if (obj.value.length < 4)
		return false;
	else
		return true;
}

function _CF_onError(form_object, input_object, object_value, error_message) {
		alert(error_message);
		return false;
	}

function _CF_hasValue(obj, obj_type) {
	if (obj_type == "TEXT") {
		if (obj.value.length == 0) {
			return false;
		} else {
			return true;
		}
	} else if (obj_type == "SELECT") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[obj.selectedIndex].value == "00")
				return false;
			}
		return true;
	}
}
function checkMyForm(theForm) {
	if  (!_CF_hasValue(theForm.old_password, "TEXT" )) {
		if  (!_CF_onError(theForm, theForm.old_password, theForm.old_password.value, "You must enter the current password to continue.")) {
			theForm.old_password.focus();
			return false;
		}
	}

	if  (!_CF_hasValue(theForm.new_password1, "TEXT" )) {
		if  (!_CF_onError(theForm, theForm.new_password1, theForm.new_password1.value, "You must enter the new password to continue.")) {
			theForm.new_password1.focus();
			return false;
		}
	}

	if  (!_CF_hasValue(theForm.new_password2, "TEXT" )) {
		if  (!_CF_onError(theForm, theForm.new_password2, theForm.new_password2.value, "You must confirm the new password to continue.")) {
			theForm.new_password2.focus();
			return false;
		}
	}

	// check to see that password is at least 4 characters
	if (!_at_least_4_char(theForm.new_password1)) {
		alert("Passwords must contain at least 4 characters and may NOT contain spaces, hyphens or other special characters.");
		theForm.new_password1.value = '';
		theForm.new_password2.value = '';
		theForm.new_password1.focus();
		return false;

	// check for spaces
	} else if (theForm.new_password1.value.indexOf(' ') > 1) {
		alert("Passwords may NOT contain spaces. Please try again.");
		theForm.new_password1.value = '';
		theForm.new_password2.value = '';
		theForm.new_password1.focus();
		return false
	}

	// check password confirmation
	if (theForm.new_password2.value != theForm.new_password1.value) {
		alert("Password confirmation failed. Please try again");
		theForm.new_password1.value = '';
		theForm.new_password2.value = '';
		theForm.new_password1.focus();
		return false;
	}
	return true;
}
