(function($) { // hide the namespace
    /**
     * Author: Sean Thompson
     * This jQuery function $().strengthMeter() will evaluate the strength of the password per keypress
     * it will return a value from 1 to 5, 1 being no password to 5 being a strong password
     */
    $.fn.strengthMeter = function () {
        return this.each(function() {
            // Create the image
            var img = $('<p class="strengh-meter">Strength:</p><img class="strengh-meter" />').insertAfter(this);

            // Listen to key strokes
            $(this).keyup(function() {
                var strength = 0;

                // length
                if ( this.value.length >= 6 )
                    strength++;

                // contains lowercase characters
                if ( this.value.match(/[a-z]+/) )
                    strength++;

                // contains digits
                if ( this.value.match(/[0-9]+/) )
                    strength++;

                // contains uppercase characters
                if ( this.value.match(/[A-Z]+/) )
                    strength++;

                img.attr('src', '/img/en-gb/password/strength.' + strength + '.png')
            })
            // Init the indicator
            .keyup();
        });
    };

	$(function () {
        $('form .element.strength input').strengthMeter();
    });
})(jQuery);

