
jQuery(function($){
  
  $('#contact_name').parents('form').validate({
    rules: {"contact[name]":{"required":true,"maxlength":255},"contact[email]":{"required":true,"maxlength":255,"email":true},"contact[message]":{"required":true}},
    wrapper: 'ul class=error_list',
    errorElement: 'li',
    errorPlacement: function(error, element) 
    {
     if(element.parents('.radio_list').is('*') || element.parents('.checkbox_list').is('*'))
     {
       error.prependTo( element.parent().parent().parent() );
     }
     else
     {
       error.appendTo( element.parent() );
     }
   }
  
  });
  
  
});

/* 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."
);
