(function($){

  $.fn.checkPassword = function(passHint, passWrong, passMiddle, passSecure){
    this.keyup(function(e){
      var self = $(e.target);
      var pattern = /^[a-zA-Z0-9_\-\!\@\#\$\%\^\&\*\(\)\+\=\{\}\[\]\;\:\.\>\<\,\`\~]{0,}$/;
      var testedValue = self.val();
      result = pattern.test(testedValue);
      var hintId = "hint_"+ self.attr("id");
      var passId = "pass_"+ self.attr("id");
      if (result||(testedValue == '')) {
        $("p#" + hintId).remove();
        self.css("border", "1px solid #6699CC");
        if (testedValue == '') {
          $("p#" + passId).remove();
        }

        if (typeof(passWrong) != 'undefined') {
          if (testedValue.length > 0 && testedValue.length < 6) {
            if ($("p#" + passId).length == 0){
              self.after("<p id=\""+passId+"\" class=\"passSecure\">"+passWrong+"</p>");
            }
            else {
              $("p#" + passId).text(passWrong).css("color","#DC3D3D");
            }
          }
        }
        if (typeof(passMiddle) != 'undefined') {
          if (testedValue.length >= 6 && testedValue.length < 10) {
            if (testedValue.match(/^[a-z]{0,}$/) || testedValue.match(/^[A-Z]{0,}$/) || testedValue.match(/^[0-9]{0,}$/)){
              $("p#" + passId).text(passMiddle).css("color","#3399cc");

            }
            else {
              $("p#" + passId).text(passSecure).css("color","#00cc00");
            }
          }
        }
        if (typeof(passSecure) != 'undefined') {
          if (testedValue.length >= 10) {
            $("p#" + passId).text(passSecure).css("color","#00cc00");
          }
        }
      }
      else {
        self.css("border", "1px solid #cc0000");
        if ($("p#" + hintId).length == 0)  {
          self.after("<p id=\""+hintId+"\" class=\"passHint\">"+passHint+"</p>");
        }
      }
    })
  }

})(jQuery);