/* jQuery Password Strength Plugin (pstrength) - A jQuery plugin to provide accessibility functions
 * Author: Tane Piper (digitalspaghetti@gmail.com) 
 * Website: http://digitalspaghetti.me.uk
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 * Version 1.1 (20/08/2007)
 */
(function(Y) {
    Y.fn.pstrength = function(c) {
        var c = Y.extend({
            verdects : [ "Muito Fraco", "Fraco", "M&eacute;dio", "Forte", "Muito Forte" ],
            scores : [ 16, 25, 35, 45 ],
            common : [ "123", "123456", "senha", "123mudar", "admin", "adm", "restrito", "1@cobra." ],
            minchar : 5
        }, c);
        return this
        .each(function() {
            var u = Y(this).attr("id");
            Y(this).after("<div id=\"" + u + "_text\"></div>");
            Y(this)
            .after(
                "<div id=\""
                + u
                + "_bar\" style=\"height: 2px; width: 0px; margin-top: 2px;\"></div>");
            Y(this).keyup(function() {
                Y.fn.runPassword(Y(this).val(), u, c);
            });
        });
    };
    Y.fn.runPassword = function(l, C, s) {
        nPerc = Y.fn.checkPassword(l, s);
        var c = "#" + C + "_bar";
        var u = "#" + C + "_text";
        var k = Math.round(nPerc * 2.2);
        if (k < (l.length * 5)) {
            k += l.length * 5;
        }
        if (k > 100) {
            k = 100;
        }
        Y(c).css({
            width : k + "%"
        });
        if (nPerc <= s.scores[0]) {
            strColor = "#676767";
            strText = s.verdects[0];
        } else {
            if (nPerc > s.scores[0] && nPerc <= s.scores[1]) {
                strColor = "#f5ac00";
                strText = s.verdects[1];
            } else {
                if (nPerc > s.scores[1] && nPerc <= s.scores[2]) {
                    strColor = "#6699cc";
                    strText = s.verdects[2];
                } else {
                    if (nPerc > s.scores[2] && nPerc <= s.scores[3]) {
                        strColor = "#079f07";
                        strText = s.verdects[3];
                    } else {
                        strColor = "#0b6e0b";
                        strText = s.verdects[4];
                    }
                }
            }
        }
        Y(c).css({
            backgroundColor : strColor
        });
        Y(u)
        .html(
            "<span style='color: " + strColor + "; font-size: 10px;'>" + strText
            + "</span>");
    };
    Y.fn.checkPassword = function(C, l) {
        var u = 0;
        var c = l.verdects[0];
        if (C.length < 5) {
            u = (u + 3);
        } else {
            if (C.length > 4 && C.length < 8) {
                u = (u + 6);
            } else {
                if (C.length > 7 && C.length < 16) {
                    u = (u + 12);
                } else {
                    if (C.length > 15) {
                        u = (u + 18);
                    }
                }
            }
        }
        if (C.match(/[a-z]/)) {
            u = (u + 1);
        }
        if (C.match(/[A-Z]/)) {
            u = (u + 5);
        }
        if (C.match(/\d+/)) {
            u = (u + 5);
        }
        if (C.match(/(.*[0-9].*[0-9].*[0-9])/)) {
            u = (u + 5);
        }
        if (C.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) {
            u = (u + 5);
        }
        if (C.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) {
            u = (u + 5);
        }
        if (C.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
            u = (u + 2);
        }
        if (C.match(/([a-zA-Z])/) && C.match(/([0-9])/)) {
            u = (u + 2);
        }
        if (C
            .match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) {
            u = (u + 2);
        }
        return u;
    };
})(jQuery);
