
jQuery(function($){
  
  $('#merchant_billing_information_ad_plans_list').parents('form').validate({
    rules: {
        
        'merchant_billing_information[ad_plans_list]': {
                              
        }    },    
    messages: {
              'merchant_billing_information[ad_plans_list]': {
                              
        }        
    },
    wrapper: 'div class="merchant-txt-box"',
    errorElement: 'div',

    success:  function(label) {
      
      label.parents('.merchant-input-area').find('.merchant-tick-box img').attr('src', "/images/tick.gif");
    },

    
    failure: function(label) {
    
      label.parents('.merchant-input-area').find('.merchant-tick-box img').attr('src', "/images/minus-bt-big.gif");
    },
    
    
    errorPlacement: function(error, element) 
    {
      var inputDiv = null;
    
      inputDiv =  element.parents('.merchant-input-area');
      if (inputDiv.find('.merchant-txt-box')) {
      
        inputDiv.find('.merchant-txt-box').remove();
      }
      
      if (inputDiv.find('.for-error').length) {
        error.appendTo(inputDiv.find('.for-error'));
      }
      else {
        error.appendTo( inputDiv);
      }
       
    }
  
  });
  
  
});

/* for some reason the jQuery Validate plugin does not incluce a generic regex method */
jQuery.validator.addMethod(
  "regex",
  function(value, element, regexp) {
      if (regexp.constructor != RegExp)
          regexp = new RegExp(regexp);
      else if (regexp.global)
          regexp.lastIndex = 0;
      return this.optional(element) || regexp.test(value);
  },
  "Invalid."
);