function passwordStrength(){
	this.minLength = 4;
	this.maxLength = 15;

	this.maxPoints = 20;
	this.enoughPoints = 4;

	this.points = 0;
	this.modPoints = 1;
	this.features = null;
	this.maxIndicatorWidth = 136;

}
passwordStrength.prototype.reset = function(){
	this.psIndicator.style.width = '0px';
	this.psNameEl = 'brak';
	this.password2.disabled = true;
}

passwordStrength.prototype.check = function(password, login){

	if(!password)
		return {status:"EMPTYPASS"};

	this.points = password.length;
	this.modPoints = 1;
	this.features = new Array();

	if (password.length<this.minLength){
		return {status:"TOOSHORT"};
	}
	if (password.length>this.maxLength){
		return {status:"TOOLONG"};
	}

	if(password.match(/(^\!)|(^\?)|(\s)/g)){
		return {status:"INVALIDCHARS"};
	}

	// NAGRODY
	var digits = password.match(/\d/g);
	if(digits){
		if(digits.length==1){
			this.modPoints *= 1.25;
			this.features.push("ONEDIGIT");
		}else if(digits.length>1){
			this.modPoints *= 1.5;
			this.features.push("MULTIDIGITS");
		}
	}

	var specialChars = password.match(/\!|\@|\#|\$|\%|\&|\*|\^|\(|\)|\~|\`/g);
	if(specialChars){
		if(specialChars.length==1){
			this.modPoints *= 1.25;
			this.features.push("ONESPECIALCHAR");
		}else if(specialChars.length>1){
			this.modPoints *= 1.5;
			this.features.push("MULTISPECIALCHARS");
		}
	}

	var lCase = password.match(/[a-z]/g);
	var uCase = password.match(/[A-Z]/g);
	if (lCase && uCase){
		if(lCase.length == 1 || uCase.length == 1){
			this.modPoints *= 1.25;
			this.features.push("SIMPLECASEMIX");
		}else if (lCase.length > 1 && uCase.length >1){
			this.modPoints *= 1.5;
			this.features.push("COMPLEXCASEMIX");
		}
	}

	// KARY
	if(login){
		firstLetters = login.substr(0,6);
		if(password.match(firstLetters)){
			this.modPoints *= 0.5;
			this.features.push("PASSWORDCONSISTLOGIN");
		}
	}

	var cr = password.match(/.*?(.).*?\1/g);
	if (cr){
		this.modPoints *= 0.8;
		this.features.push("CHARREPEAT:"+cr.join("-"));
	}

	var dumbPasswords = ["qwe", "qwerty", "qweasd", "qazwsx", "123456", "123qwe", "asdfgh", "zxcvbn", "abc"];
	for(var v in dumbPasswords){
		if(password.match(dumbPasswords[v])){
			this.modPoints *= 0.8;
			this.features.push("DUMBPASSWORD <"+dumbPasswords[v]+">");
		}
	}


	ret = {status:(this.points*this.modPoints>this.enoughPoints?"OK":"TRYING"), points:this.points*this.modPoints, features:this.features.join(', '), toString:function(){return "status:"+this.status+"; points:"+this.points+"; features:"+this.features;}};

	if(window.console)
		console.log(ret);
	return ret;
}

passwordStrength.prototype.fieldAction = function (evt){
	evt["target"]? target = evt["target"]:  target = evt["srcElement"];
	var passCheck = this.check(target.value, this.username.value);

	switch(passCheck.status){
		case "OK":
		case "TRYING":
			this.psIndicator.style.width = Math.min(Math.round(((passCheck.points?passCheck.points:0))/20*this.maxIndicatorWidth), this.maxIndicatorWidth)+"px";
			var points = passCheck.points;
			if(points>16){
				this.psIndicator.style.backgroundColor = "#00FF00";
				this.psNameEl.innerHTML = "silne";
			}else if(points>12){
				this.psIndicator.style.backgroundColor = "#FFFF00";
				this.psNameEl.innerHTML = "średnie";
			}else if(points>8){
				this.psIndicator.style.backgroundColor = "#FF8040";
				this.psNameEl.innerHTML = "słabe";
			}else{
				this.psIndicator.style.backgroundColor = "#FF0000";
				this.psNameEl.innerHTML = "niedostateczne";
			}
			break;
		case "TOOSHORT":
				this.psIndicator.style.backgroundColor = "#FF0000";
				this.psNameEl.innerHTML = "zbyt krótkie";
			break;
		case "TOOLONG":
				this.psIndicator.style.backgroundColor = "#FF0000";
				this.psNameEl.innerHTML = "zbyt długie";
			break;
		case "INVALIDCHARS":
				this.psIndicator.style.backgroundColor = "#FF0000";
				this.psNameEl.innerHTML = "niedozwolone znaki";
			break;
	}

	if(passCheck.status != "OK"){
		this.password2.disabled = true;
	}else{
		this.password2.disabled = false;
	}
}
