var PasswordMeter = new Class({
    Implements: [Options,Events],
	
	options: {
	  /*
	  onValue: $empty,
	  */
	  id	 : null
	},
	
	initialize : function(options){
	  this.setOptions(options);
	  
	  this.el = $(this.options.id);
	  this.el.addEvent('keyup',this.updateMeter.bindWithEvent(this));
	},
		
	updateMeter : function(e){
	  var score = 0 
	  var p 	= e.target.value;
		
	  var nScore = Math.round(this.calcStrength(p)*2);
	  
	  if(nScore > 100) {
		nScore = 100;
	  }
	  
	  this.fireEvent('value',nScore);
	},

	calcStrength: function(p) {
		var intScore = 0;

		// PASSWORD LENGTH
		intScore += p.length;
		
		if(p.length > 0 && p.length <= 4) {                    // length 4 or less
			intScore += p.length;
		}
		else if (p.length >= 5 && p.length <= 7) {	// length between 5 and 7
			intScore += 4;
		}
		else if (p.length >= 8 && p.length <= 15) {	// length between 8 and 15
			intScore += 10;
		}
		else if (p.length >= 16) {               // length 16 or more
			intScore += 15;
		}
		
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (p.match(/[a-z]/)) {              // [verified] at least one lower case letter
			intScore += 1;
		}
		if (p.match(/[A-Z]/)) {              // [verified] at least one upper case letter
			intScore += 5;
		}
		// NUMBERS
		if (p.match(/\d/)) {             	// [verified] at least one number
			intScore += 5;
		}
		if (p.match(/.*\d.*\d.*\d/)) {            // [verified] at least three numbers
			intScore += 5;
		}
		
		// SPECIAL CHAR
		if (p.match(/[!,@,#,$,%,^,&,*,?,_,~]/)) {           // [verified] at least one special character
			intScore += 5;
		}
		// [verified] at least two special characters
		if (p.match(/.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~]/)) {
			intScore += 10;
		}
		
		// COMBOS
		if (p.match(/(?=.*[a-z])(?=.*[A-Z])/)) {        // [verified] both upper and lower case
			intScore += 5;
		}
		if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/)) { // [verified] both letters and numbers
			intScore += 5;
		}
		// [verified] letters, numbers, and special characters
		if (p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!,@,#,$,%,^,&,*,?,_,~])/)) {
			intScore += 5;
		}
		return intScore;
	}
});
