var PasswordChecker = Class.create({
	
	width : 0,
	intScore : 0,
	
	initialize : function() {
		$('password').onkeyup = function() {
			Checker.updateStrength();
		}
	},
	
	updateStrength : function() {
		var password = $('password').value;
		this.intScore = 0;
		this.getStrength(password);
		this.width = (100/32) * this.intScore;
		new Effect.Morph('passwordStrength', {
			style : 'width:'+this.width+'px',
			duration : '0.4'
		});
	},
	
	getStrength : function(password) {
		if (password.match(/[a-z]/)) {
			this.intScore += 1;
		}
		if (password.match(/[A-Z]/)) {
			this.intScore += 5; 
		}
		if (password.match(/\d+/)) {
			this.intScore += 5;
		}
		if (password.match(/(\d.*\d.\d)/)) {
			this.intScore += 5;
		}
		if (password.match(/[!,@#$%^&*?_~]/)) {
			this.intScore += 5;
		}
		if (password.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) {
			this.intScore += 5;
		}
		if (password.match(/[a-z]/) && password.match(/[A-Z]/)) {
			this.intScore += 2;
		}
		if (password.match(/\d/) && password.match(/\D/)) {
			this.intScore += 2;
		}
		if (password.match(/[a-z]/) && password.match(/[A-Z]/) && password.match(/\d/) && password.match(/[!,@#$%^&*?_~]/)) {
			this.intScore += 2;
		}
	}
});
