$(document).ready(function() {
	$("input.pw").keyup(function() {
		var passtemp = $('#passwortSite').val();
		$("#passwrap input:not(.pw)").val(passtemp);
		
		ratePW("#passwortSite");
	});
	
	$("input.pwHeader").keyup(function() {
		var passtemp = $('#passwortHeader').val();
		$("#passwrap input:not(.pwHeader)").val(passtemp);
		
		ratePW("#passwortHeader");
	});
	
	function runde(zahl) {
	  var rzahl = (Math.round(zahl * 10) / 10).toString();
	  rzahl += (rzahl.indexOf('.') == -1)? '.0' : '0';
	  return rzahl.substring(0, rzahl.indexOf('.') + 2);
	}
	
	function ratePW(passfield) 
	{
	var strength = 0,
	klein = 0,
	cap = 0,
	zahl = 0,
	zeichen = 0;
	
	var passlength = $(passfield).val().length;
	var input = $(passfield).val();
	

	for(var i=0,l=passlength;i<l;i++)
	{
	var x = input.charCodeAt(i);
	if ( x >= 97 && x <= 122 ) {
		klein += 1;
		if ( klein > 4 ) {
			strength += 0.2;
		} else {
			strength += 1;
		}
		} else if ( x >= 65 && x <= 90 ) {
			cap += 1;
			if ( cap > 4 ) {
				strength += 0.6;
			} else {
				strength += 2;
			}
			} else if ( x >= 48 && x <= 57 ) {
				zahl += 1;
				if ( zahl > 4 ) {
					strength += 1;
				} else {
					strength += 3;
				}
				} else if ( x >= 32 && x <= 47 || x >= 123 && x <= 126 || x >= 91 && x <= 96 || x >= 58 && x <= 64  ) {
					zeichen += 1;
					if ( zeichen > 4 ) {
						strength += 2;
					} else {
						strength += 4;
					}
					} else {
						strength+=1;
						}
	}
	
	var rstrength = runde(strength);
	if (passfield == '#passwortSite') {
		if (rstrength == 0.0) { 
			$("#cover").css({'width':'208px','left':'1px'});
		} else if (rstrength > 0.0 && rstrength <= 4.0) {
			$("#cover").css({'width':'173px','left':'35px'});
			} else if (rstrength > 3.0 && rstrength <= 8.0) {
				$("#cover").css({'width':'139px','left':'69px'});
				} else if (rstrength > 6.0 && rstrength <= 12.0) {
					$("#cover").css({'width':'105px','left':'103px'});
					} else if (rstrength > 9.0 && rstrength <= 16.0) {
						$("#cover").css({'width':'71px','left':'137px'});
						} else if (rstrength > 12.0 && rstrength <= 20.0) {
							$("#cover").css({'width':'37px','left':'171px'});
							} else if (rstrength > 15.0) {
								$("#cover").css({'display':'none'});
								} 
	} else {
		if (rstrength == 0.0) { 
			$("#coverHeader").css({'width':'208px','left':'1px'});
		} else if (rstrength > 0.0 && rstrength <= 4.0) {
			$("#coverHeader").css({'width':'173px','left':'35px'});
			} else if (rstrength > 3.0 && rstrength <= 8.0) {
				$("#coverHeader").css({'width':'139px','left':'69px'});
				} else if (rstrength > 6.0 && rstrength <= 12.0) {
					$("#coverHeader").css({'width':'105px','left':'103px'});
					} else if (rstrength > 9.0 && rstrength <= 16.0) {
						$("#coverHeader").css({'width':'71px','left':'137px'});
						} else if (rstrength > 12.0 && rstrength <= 20.0) {
							$("#coverHeader").css({'width':'37px','left':'171px'});
							} else if (rstrength > 15.0) {
								$("#coverHeader").css({'display':'none'});
								} 
	}
	$(".strength").val(rstrength);	
	};

}); 

