(function() {
	if (typeof wp === 'undefined' || typeof wp.passwordStrength === 'undefined') {
		return;
	}

	var labels = window.sitefortPasswordChangeLabels || {};
	var pass1 = document.getElementById('pass1');
	var pass2 = document.getElementById('pass2');
	var result = document.getElementById('pass-strength-result');
	if (!pass1 || !pass2 || !result) {
		return;
	}

	function check() {
		var strength = wp.passwordStrength.meter(pass1.value, wp.passwordStrength.userInputDisallowedList(), pass2.value);
		result.className = 'hide-if-no-js';

		switch (strength) {
			case -1:
				result.textContent = '';
				break;
			case 2:
				result.textContent = labels.weak || 'Weak';
				result.className += ' bad';
				break;
			case 3:
				result.textContent = labels.medium || 'Medium';
				result.className += ' good';
				break;
			case 4:
				result.textContent = labels.strong || 'Strong';
				result.className += ' strong';
				break;
			default:
				result.textContent = labels.veryWeak || 'Very weak';
				result.className += ' short';
				break;
		}
	}

	pass1.addEventListener('input', check);
	pass2.addEventListener('input', check);
}());
