var passwordIsValid = false;
var confirmPasswordIsValid = false;

setMessage = function(id, text, img, error) {
	if (error) {
		text = text.fontcolor("Red");
		document.getElementById(img).src = '/img/exclamation.png';
	}
	else {
		document.getElementById(img).src = '/img/accept.png';
	}
	document.getElementById(id).innerHTML = text;
}

validatePassword = function(password) {
	if (password == '') {
		setMessage('passwordMessage', 'Please enter a valid password', 'passwordImg', true);
		passwordIsValid = false;
	}
	else if (password.length < 6) {
		setMessage('passwordMessage', 'Must be at least 6 characters', 'passwordImg', true);
		passwordIsValid = false;
	}
	else {
		setMessage('passwordMessage', '', 'passwordImg', false);
		passwordIsValid = true;
	}

	validateConfirmPassword(document.getElementById('confirmPassword').value);
	
	validateFields();
}		

validateConfirmPassword = function(confirmPassword) {
	if (confirmPassword != document.getElementById('password').value) {
		setMessage('confirmPasswordMessage', 'Passwords do not match', 'confirmPasswordImg', true);
		confirmPasswordIsValid = false;
	}
	else {
		setMessage('confirmPasswordMessage', 'Passwords match', 'confirmPasswordImg', false);
		confirmPasswordIsValid = true;
	}
	
	validateFields();
}		

validateFields = function() {
	if (passwordIsValid && confirmPasswordIsValid) {
		document.getElementById('submitButton').style.display = 'block';
	}
	else {
		document.getElementById('submitButton').style.display = 'none';
	}
}
