function validate_passwords(field1, field2, alerttxt){ 
	if (field1.value == field2.value) {
		return true;
	} else {
		alert(alerttxt);
		return false;
	}
}

function validateNotNull(field, name) {
	if (field.value == null || field.value == "") {
		alert("The " + name + " field is empty!");
		return false;
	} else {
		return true;
	}
}

function validFieldLength(field, length, name) {
	if (field.value.length < length) {
		alert("The " + name + " field needs to be more than " + length + " characters.");
		return false;
	} else {
		return true;
	}
}

function validateUserRegistrationForm(thisForm){
	var alert_bg = "#ffc887";
	var orig_bg = "#e2f1fb";
	with (thisForm) {
		if (validate_required(addUserName, "You must enter a username.") == false){
			addUserName.focus();

			addUserName.style.background=alert_bg;
			addUserPassword.style.background=orig_bg;
			addUserPasswordVerf.style.background=orig_bg;
			addUserFirstName.style.background=orig_bg;
			addUserLastName.style.background=orig_bg;
			return false;
		} else if (validate_required(addUserPassword, "You must enter a password.") == false){
			addUserPassword.focus();

			addUserName.style.background=orig_bg;
			addUserPassword.style.background=alert_bg;
			addUserPasswordVerf.style.background=orig_bg;
			addUserFirstName.style.background=orig_bg;
			addUserLastName.style.background=orig_bg;
			return false;
		} else if (validate_required(addUserPasswordVerf, "You must enter the password again for verification.") == false){
			addUserPasswordVerf.focus();

			addUserName.style.background=orig_bg;
			addUserPassword.style.background=orig_bg;
			addUserPasswordVerf.style.background=alert_bg;
			addUserFirstName.style.background=orig_bg;
			addUserLastName.style.background=orig_bg;
			return false;
		} else if (validate_required(addUserFirstName, "You must enter a first name.") == false){
			addUserFirstName.focus();

			addUserName.style.background=orig_bg;
			addUserPassword.style.background=orig_bg;
			addUserPasswordVerf.style.background=orig_bg;
			addUserFirstName.style.background=alert_bg;
			addUserLastName.style.background=orig_bg;
			return false;
		} else if (validate_required(addUserLastName, "You must enter a last name.") == false){
			addUserLastName.focus();

			addUserName.style.background=orig_bg;
			addUserPassword.style.background=orig_bg;
			addUserPasswordVerf.style.background=orig_bg;
			addUserFirstName.style.background=orig_bg;
			addUserLastName.style.background=alert_bg;
			return false;
		} else if (validate_passwords(addUserPassword, addUserPasswordVerf, "The passwords do not match!") == false){
			addUserName.style.background=orig_bg;
			addUserPassword.style.background=orig_bg;
			addUserPasswordVerf.style.background=orig_bg;
			addUserFirstName.style.background=orig_bg;
			addUserLastName.style.background=orig_bg;
			return false;
		}
		return true;
	}
}

function validateUserLoginForm(thisForm){
	var alert_bg = "#ffc887";
	var orig_bg = "#e2f1fb";
	with (thisForm) {
		if (validate_required(loginUserName, "You must enter a username.") == false){
			loginUserName.focus();
			loginUserName.style.background=alert_bg;
			loginUserPassword.style.background=orig_bg;
			return false;
		} else if (validate_required(loginUserPassword, "You must enter a password.") == false){
			loginUserPassword.focus();
			loginUserName.style.background=orig_bg;
			loginUserPassword.style.background=alert_bg;
			return false;
		}
		return true;
	}
}