
// id="srfeuserregister-submit" button id

function testPassword(passwd, passwd_again) {
	// password field is empty -> diplay weak-password message
	if(passwd.length == 0) {
		// password field empty
		if(document.getElementById('srfeuserregister_submit'))
			document.getElementById('srfeuserregister_submit').setAttribute("disabled", "disabled");

		passwordWeak();
		charactersOk();
		compareNone();
		return;
	}

	var intScore   = 0;
	var strVerdict = "weak";
	var strLog     = "";

	// 8 = strong, <8 = weak
	var strength = 0;
	if(passwd.length >= 8) {
		strength++;
	}
	if (passwd.match(/[a-z]/)) {
		strength++;
	}
	if (passwd.match(/[A-Z]/)) {
		strength++;
	}
	if (passwd.match(/[0-9]/)) {
		strength++;
	}
	// allowed
	var allowed = 1;
	var match = passwd.match(/[a-zA-Z0-9]*/);
	if(match != passwd && match != null) allowed = 0;
	
	// only possible combination, when the password is correct
	if((allowed == 1 && strength >= 4) || passwd.length == 32) {
		passwordStrong();
		charactersOk();
		if(passwd == passwd_again) {
			compareOk();
			if(document.getElementById('srfeuserregister_submit'))
				document.getElementById('srfeuserregister_submit').removeAttribute("disabled");
		} else {
			compareNot();
			if(document.getElementById('srfeuserregister_submit'))
				document.getElementById('srfeuserregister_submit').setAttribute("disabled", "disabled");
		}
	} else {
		passwordWeak();
		compareNone();
		if(allowed == 0) charactersWrong();
		else charactersOk();
		if(document.getElementById('srfeuserregister_submit'))
			document.getElementById('srfeuserregister_submit').setAttribute("disabled", "disabled");
	}
}

// helping functions

function charactersWrong() {
	document.getElementById('password_alert').className = "password-alert-alert";
	document.getElementById('password_alert').alt = strengthInfo[2];
	document.getElementById('password_alert').title = strengthInfo[2];
	document.getElementById('password_alert_text').innerHTML = strengthInfo[2];
	document.getElementById('password_alert_text').className = "password-error";
}

function charactersOk() {
	document.getElementById('password_alert').className = "password-alert-none";
	document.getElementById('password_alert').alt = "";
	document.getElementById('password_alert').title = "";
	document.getElementById('password_alert_text').innerHTML = "";
	document.getElementById('password_alert_text').className = "";
}

function passwordNone() {
	document.getElementById('password_strength').className = "";
	document.getElementById('password_strength').alt = "";
	document.getElementById('password_strength').title = "";
	document.getElementById('password_strength_text').innerHTML = "";
	document.getElementById('password_strength_text').className = "";
}

function passwordStrong() {
	document.getElementById('password_strength').className = "password-strength-strong";
	document.getElementById('password_strength').alt = strengthInfo[0];
	document.getElementById('password_strength').title = strengthInfo[0];
	document.getElementById('password_strength_text').innerHTML = strengthInfo[0];
	document.getElementById('password_strength_text').className = "";
}

function passwordWeak() {
	document.getElementById('password_strength').className = "password-strength-weak";
	document.getElementById('password_strength').alt = strengthInfo[1];
	document.getElementById('password_strength').title = strengthInfo[1];
	document.getElementById('password_strength_text').innerHTML = strengthInfo[1];
	document.getElementById('password_strength_text').className = "password-error";
}

function compareNone() {
	document.getElementById('password_compare').className = "password-compare-none";
	document.getElementById('password_compare').alt = "";
	document.getElementById('password_compare').title = "";
	document.getElementById('password_compare_text').innerHTML = "";
	document.getElementById('password_compare_text').className = "";
}

function compareOk() {
	document.getElementById('password_compare').className = "password-compare-ok";
	document.getElementById('password_compare').alt = compareInfo[0];
	document.getElementById('password_compare').title = compareInfo[0];
	document.getElementById('password_compare_text').innerHTML = compareInfo[0];
	document.getElementById('password_compare_text').className = "";
}

function compareNot() {
	document.getElementById('password_compare').className = "password-compare-not";
	document.getElementById('password_compare').alt = compareInfo[1];
	document.getElementById('password_compare').title = compareInfo[1];
	document.getElementById('password_compare_text').innerHTML = compareInfo[1];
	document.getElementById('password_compare_text').className = "password-error";
}


