(function(root) {

  'use strict';

  var availity = root.availity;

  availity.core.value('avValConfig', {
    classes: {
      valid: 'ng-valid',
      invalid: 'ng-invalid',
      dirty: 'ng-dirty',
      pristine: 'ng-pristine',
      touched: 'ng-touched',
      untouched: 'ng-untouched',
      submitted: 'ng-submitted'
    },
    validators: [
      'avValPattern',
      'avValSize',
      'avValRequired',
      'avValDateRange',
      'avValDate'
    ]
  });

  availity.core.constant('AV_VAL', {
    EVENTS: {
      REVALIDATE: 'av:val:revalidate',
      SUBMITTED: 'av:val:submitted',
      FAILED: 'av:val:failed',
      RESET: 'av:val:reset'
    },
    DEBOUNCE: 500,
    DATE_FORMAT: {
      SIMPLE: 'MM/DD/YYYY'
    },
    PATTERNS: {
      ALPHA_ONLY: /[^A-Za-z]+/g,
      NUMERIC_ONLY: /[^0-9]+/g
    }
  });

  availity.core.provider('avVal', function() {

    var that = this;

    var validators = [];

    this.rules = {};

    this.addRules = function(rules) {
      this.rules = angular.extend(this.rules, rules);
    };

    this.addValidators = function(rules) {
      this.rules = angular.extend(this.rules, rules);
    };

    this.$get = function($injector, $rootScope, $http, $log, avValConfig, AV_VAL) {

      var AvValidation = function() {
        this.rules = that.rules;
        this.initValidators();
      };

      var proto = AvValidation.prototype;

      proto.initValidators = function() {
        var self = this;

        validators = avValConfig.validators.concat(validators);

        angular.forEach(validators, function(name) {
          self.addValidator(name);
        });
      };

      proto.clearAll = function() {
        // this.validators.splice(0, this.validators.length);
        // this.rules = {};
      };

      proto.addRules = function(rules) {
        this.rules = angular.extend(this.rules, rules);
        $rootScope.$broadcast(AV_VAL.EVENTS.REVALIDATE);
      };

      proto.addValidator = function(name) {
        var validator = $injector.get(name);
        validators[validator.name] = validator;
      };

      proto.validate = function(key, element, value, ruleName) {

        var rules = this.rules[key];
        if(!rules) {
          $log.error('Failed to get rules key [' + key + '].  Forms must be tagged with a rules set name for validation to work.');
          return;
        }

        var contraints = rules[ruleName];
        if(!contraints) {
          $log.info('Rule named [' + ruleName + '] could not be found in the current schema.');
          contraints = [];
        }

        var el = element[0];
        var results  = [];
        var violations = [];
        var _valid = true;

        angular.forEach(contraints, function(rule, contraintName) {

          if(!rule) {
            // when extended rule sets, a user can pass nulls to cancel out a rule so if
            // one doesn't exist just continue
            return;
          }

          var validator = validators[contraintName];

          if(angular.isUndefined(validator)) {
            $log.warn('No validator defined for `' + name + '`');
            return;
          }

          var valid = validator.validate(value, rule);

          var validationResult = {
            valid: valid,
            ruleName: ruleName,
            contraintName: contraintName,
            value: value,
            message: rule.message,
            field: el.name || el.id
          };

          var result = angular.extend({}, rule, validationResult);

          results.push(result);
          if(!valid) {
            violations.push(validationResult);
          }
          _valid = _valid && valid;
        });

        return {
          isValid: _valid,
          all: results, // all the constraint results
          violations: violations
        };

      };

      return new AvValidation();

    };

  });
})(window);

@@ -874,30 +874,8 @@
  %7B%0A%0A
-    var that = this;%0A%0A
     
@@ -895,26 +895,24 @@
 s = %5B%5D;%0A
-%0A
     
-this.
+var 
 rules = 
@@ -937,32 +937,33 @@
 ules = function(
+_
 rules) %7B%0A      t
@@ -953,37 +953,32 @@
 _rules) %7B%0A      
-this.
 rules = angular.
@@ -980,36 +980,36 @@
 ular.extend(
-this.
+%7B%7D, 
 rules, 
+_
 rules);%0A    
@@ -1038,36 +1038,41 @@
 tors = function(
-rule
+validator
 s) %7B%0A      this.
@@ -1070,52 +1070,48 @@
     
-this.rules = angular.extend(this.rules, rule
+validators = validators.concat(validator
 s);%0A
@@ -1245,41 +1245,8 @@
 ) %7B%0A
-        this.rules = that.rules;%0A
     
@@ -1732,24 +1732,25 @@
  = function(
+_
 rules) %7B%0A   
@@ -1754,21 +1754,16 @@
         
-this.
 rules = 
@@ -1781,20 +1781,20 @@
 end(
-this.
+%7B%7D, 
 rules, 
+_
 rule
@@ -2097,17 +2097,17 @@
 rule
-s = this.
+Config = 
 rule
@@ -2126,25 +2126,30 @@
     if(!rule
-s
+Config
 ) %7B%0A        
@@ -2330,17 +2330,22 @@
 s = rule
-s
+Config
 %5BruleNam

refactor global rules config object in provider