(function(a) {

    function ck(f) {
        if(f >= 48 && f <= 57) {
            return 1
        }
        if(f >= 65 && f <= 90) {
            return 2
        }
        if(f >= 97 && f <= 122) {
            return 4
        } else {
            return 8
        }
    }
	


    function cck(a){
        var b = 0;
        for (i = 0; i < a.length; i++) {
            var singleChar = a.charCodeAt(i);
            //满足只是一个数字
            if ((b & 1) != 1 && (ck(singleChar) & 1) == 1) {
                b |= 1;
                continue;
            }
            if ((b & 2) != 2 && (ck(singleChar) & 2) == 2) {
                b |= 2;
                continue;
            }
            if ((b & 4) != 4 && (ck(singleChar) & 4) == 4) {
                b |= 4;
                continue;
            }
            if ((b & 8) != 8 && (ck(singleChar) & 8) == 8) {
                b |= 8;
            }
        }
        var passArr = [14,13,11,7,15];
        for (i = 0; i < passArr.length; i++) {
            if(b==passArr[i]){
                return 1;
            }
        }
        return 0;
    }
	
    function k(a) {
		var flag = $("#sfcyxmmkl").val();
		var min = $("#min").val();
		var max = $("#max").val();
		var yhm=$("#yhm").val().toLowerCase();
		if(flag==1){
            if (a == null || a.length < min || a.length > max) {
                return 1;
            } else if (a.toLowerCase().indexOf(yhm) > -1) {
                return 1;
            } else if (checkKeyBoardChar(a.toLowerCase())) {
                return 1;
            } else if(cck(a)==0) {
                return 1;
            }else{
                return 3;
            }
		}else if(flag == 2) {
            if (a == null || a.length < 8 || a.length > 15) {
                return 0;
            }
            var b = 0;
            for (i = 0; i < a.length; i++) {
                var singleChar = a.charCodeAt(i);
                //满足只是一个数字
                if ((b & 1) != 1 && (ck(singleChar) & 1) == 1) {
                    b |= 1;
                }
                if ((b & 2) != 2 && (ck(singleChar) & 2) == 2) {
                    b |= 2;
                }
                if ((b & 4) != 4 && (ck(singleChar) & 4) == 4) {
                    b |= 4;
                }
            }
            return (b & 7) == 7 ? 3 : 0;

        }else{
			if (6 > a.length)
            return 0;
			var b = 0;
			var regu = /^(\d{5})(x|X)$/;
			var regu1 = /^zfsoft123$/;
			if (regu1.test(a)) {
				b = 1;
			} else {
				if (regu.test(a)) {
					b = 1;
				} else {
					for (i = 0; i < a.length; i++)
						var c = a.charCodeAt(i)
						  , b = b | (48 <= c && 57 >= c ? 1 : 65 <= c && 90 >= c ? 2 : 97 <= c && 122 >= c ? 4 : 8);
				}
			}
			a = b;
			for (c = b = 0; 4 > c; c++)
				a & 1 && b++,
				a >>>= 1;
			return b
		}
    }
	
	function checkKeyBoardChar(str) {
				var c1 = [
					['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+'],
					['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|'],
					['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"'],
					['z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?']
				];
				var c2 = [
					['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '='],
					['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],
					['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\''],
					['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/']
				];
				str = str.split("");
				//获取坐标位置
				var y = [];
				var x = [];
				for (var c = 0; c < str.length; c++) {
					y[c] = 0;//当做~`键处理
					x[c] = -1;
					for (var i = 0; i < c1.length; i++) {
						for (var j = 0; j < c1[i].length; j++) {
							if (str[c] == c1[i][j]) {
								y[c] = i;
								x[c] = j;
							}
						}
					}
					if (x[c] != -1) continue;
					for (var i = 0; i < c2.length; i++) {
						for (var j = 0; j < c2[i].length; j++) {
							if (str[c] == c2[i][j]) {
								y[c] = i;
								x[c] = j;
							}
						}
					}
				}
				//匹配坐标连线
				for (var c = 1; c < str.length - 1; c++) {
					if (y[c - 1] == y[c] && y[c] == y[c + 1]) {
						if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) {
							return true;
						}
					} else if (x[c - 1] == x[c] && x[c] == x[c + 1]) {
						if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) {
							return true;
						}
					}
				}
				return false;
			}
				
    a.bootui = a.bootui || {};
    a.bootui.widget = a.bootui.widget || {};
    a.bootui.widget.Strength = function(a, b) {
        this.initialize.call(this, a, b)
    }
    ;
    a.bootui.widget.Strength.prototype = {
        options: {
            version: "1.0.0",
            target: "",
            strongKey: "",
            afterRender: a.noop
        },
        initialize: function(e, b) {
            var c = this;
            a.extend(!0, c.options, b || {}, {});
            a.extend(!0, c, {
                getContainer: function() {
                    var d = [];
                    d.push('\x3ctable cellSpacing\x3d"0" cellPadding\x3d"0" border\x3d"0" class\x3d"resetCss" style\x3d"float: left;"\x3e');
                    d.push("\x3ctbody\x3e\x3ctr\x3e");
                    d.push('\x3ctd style\x3d"padding: 3px 0;"\x3e' + a.i18n.zftal.utils.strength.label + "\uff1a\x3c/td\x3e");
                    d.push('\x3ctd style\x3d"color: #808080; font-weight: bold"\x3e\x3cfont id\x3d"passwdRating"\x3e\x3c/font\x3e\x3c/td\x3e');
                    d.push('\x3c/tr\x3e\x3ctr\x3e\x3ctd colSpan\x3d"2"\x3e');
                    d.push('\x3ctable id\x3d"passwdBar" cellSpacing\x3d"0" cellPadding\x3d"0" width\x3d"160" bgColor\x3d"#ffffff" border\x3d"0"\x3e');
                    d.push('\x3ctbody\x3e\x3ctr\x3e\x3ctd id\x3d"posBar" width\x3d0% bgColor\x3d"#e0e0e0" height\x3d"4"\x3e\x3c/td\x3e');
                    d.push('\x3ctd id\x3d"negBar" width\x3d"100%;" bgColor\x3d"#e0e0e0" height\x3d"4"\x3e\x3c/td\x3e\x3c/tr\x3e\x3c/tbody\x3e\x3c/table\x3e');
                    d.push("\x3c/td\x3e\x3c/tr\x3e\x3c/tbody\x3e\x3c/table\x3e");
                    return d.join("")
                },
                gff: function(a, b) {
                    var d = a.indexOf(b);
                    return -1 == d || (d = parseFloat(a.substring(d + b.length)),
                    isNaN(d)) ? null : d
                },
                compatible: function() {
                    var a = navigator.userAgent.toLowerCase()
                      , b = -1 != a.indexOf("opera")
                      , e = -1 != a.indexOf("msie") && document.all && !b
                      , m = -1 != a.indexOf("mac")
                      , n = -1 != a.indexOf("gecko")
                      , g = -1 != a.indexOf("safari");
                    if (e && !b && !m && (b = c.gff(a, "msie "),
                    null != b))
                        return 6 <= b;
                    if (n && !g) {
                        b = c.gff(a, "rv:");
                        if (null != b)
                            return 1.4 <= b;
                        b = c.gff(a, "galeon/");
                        if (null != b)
                            return 1.3 <= b
                    }
                    return g && (b = c.gff(a, "applewebkit/"),
                    null != b) ? 124 <= b : !1
                }
            });
            this.buildComponents.call(this, e);
            this.renderComponents.call(this, e);
            this.options.afterRender.call(this)
        },
        buildComponents: function(e) {
            var b = this;
            a(e).each(function(c, d) {
                0 < a.trim(b.options.target).length ? a(b.options.target).append(b.getContainer.call(b)) : a(d).after(b.getContainer.call(b))
            })
        },
        renderComponents: function(e) {
            function b(b) {
                var c = a("#posBar")
                  , e = a("#negBar")
                  , f = a("#passwdBar").outerWidth();
                0 <= b && 4 >= b ? 0 == b ? (c.width(f / 4 + "px"),
                e.width(f / 4 * (3 - b) + "px")) : (c.width(f / 4 * b + "px"),
                e.width(f / 4 * (4 - b) + "px")) : (c.width("0px"),
                e.width(f + "px"),
                b = 5);
                c.css("background", l[b]);
                a("#passwdRating").html("\x3cfont color\x3d'" + h[b] + "'\x3e" + d[b] + "\x3c/font\x3e");
                a("#strongKey").val(b)
            }
            var c = this.compatible()
              , d = a.i18n.zftal.utils.strength.ratings
              , h = "#aa0033 #aa0033 #6699cc #093 #093 #676767".split(" ")
              , l = "#aa0033 #aa0033 #6699cc #093 #093 #676767".split(" ");
            a(e).each(function(d, e) {
                a(e).keyup(function(d) {
                    if (c) {
                        if (!a(this).val())
                            return !1;
						/*
                        if (6 > a(this).val().length)
                            if (0 < a(this).val().length)
                                b.call(e, 0);
                            else {
                                d = getElement("posBar");
                                var f = getElement("negBar")
                                  , g = getElement("passwdRating")
                                  , h = getElement("passwdBar").width;
                                d.style.width = "0px";
                                f.style.width = h + "px";
                                g.innerHTML = ""
                            }
                        else
							*/
                            rating = k(a(this).val()),
                            b.call(e, rating)
                    }
                })
            })
        }
    };
    a.fn.extend({
        strength: function(e) {
            var b = a.trim(e.strongKey || "yhmmdj");
            a(this).after('\x3cinput type\x3d"hidden" name\x3d"' + b + '" id\x3d"strongKey" /\x3e');
            return new a.bootui.widget.Strength(this,e)
        },
        pwdStrong: function() {
            var e = a.trim(a(this).val());
            return e && 0 < e.length ? k(e) : "1"
        }
    })
}
)(jQuery);
