PStrength =
{
	init: function()
	{
		len = document.getElementById('UserNewPassword').style.width;
		len = len.replace("px","");
		len = len - 0;
		len = len + 4;
		document.getElementById('ps_heatbar').style.width = len + "px";
		
		PStrength.Input = document.getElementById('UserNewPassword');
		
		if(!PStrength.Input)
		{
			alert('Error loading the javascript file pstrength.js. Please make sure the file exist');
			return;
		}
		
		PStrength.Input.select();
		
		PStrength.Input.onkeyup = function()
		{
			PStrength.getStrength();
		}
		
		document.getElementById('ps_heatbar').style.visibility = "visible";
		document.getElementById('ps_pointer').style.visibility = "visible";		
	},
	
	getStrength: function()
	{
		var hasN = false;
		var hasC = false;
		var hasLC = false;
		var hasUC = false;
	
		var lvl = 0;
		var szInput = PStrength.Input.value;
		var pP = document.getElementById('ps_pointer');
		var l = szInput.length;
		
		for(i = 0; i < l; i++)
		{
			var c = szInput.charCodeAt(i);
			
			if(c >= 65 && c <= 90)
			{
				lvl += 5;
				if(hasLC) lvl += 5; else lvl -= 1;
				if(hasN) lvl += 5; else lvl -= 1;
				if(hasC) lvl += 10; else lvl -= 1;
				
				hasUC = true;
				continue;
			}
			
			if(c >= 97 && c <= 122)
			{
				lvl += 5;
				if(hasUC) lvl += 5; else lvl -= 1;
				if(hasN) lvl += 5; else lvl -= 1;
				if(hasC) lvl += 10; else lvl -= 1;
				
				hasLC = true;
				continue;
			}
			
			if(c >= 48 && c <= 57)
			{
				lvl += 5;
				if(hasUC) lvl += 5; else lvl -= 1;
				if(hasLC) lvl += 5; else lvl -= 1;
				if(hasC) lvl += 10; else lvl -= 1;
				
				hasN = true;
				continue;
			}
			
			lvl += 10;
			if(hasUC) lvl += 5;
			if(hasLC) lvl += 5;
			if(hasN) lvl += 5;
			
			hasC = true;
			
		}
		
		lvl += l;


		len = document.getElementById('UserNewPassword').style.width;
		len = len.replace("px","");
		proc = 296 / len;
		lvl=lvl / proc;		
		if(lvl > 98/proc) lvl = 98/proc;
				
		pP.style.marginLeft = lvl * 3 + 'px';
	}
}
