$(function()
{
  // initialize form validation
  $("form").validate({
    mapURL: "/includes/xml/validation.xml",
    onAfterValidate: function()
    {
      var el = this.is(":checkbox, :radio") ? this.parents("div") : this;
      el.css("background-image", "none");
    },
    onBeforeValidate: function()
    {
      var el = this;
      var pos = "top right";
      
      if (el.is(":checkbox, :radio"))
      {
        el = this.parents("div");
        pos = "top right";
      }
      
      el.css({
        backgroundImage: "url(/images/common/validation-loader.gif)",
        backgroundPosition: pos,
        backgroundRepeat: "no-repeat"
      });
    },
    onError: function(errors)
    {
      $("#errors-" + this.attr("name")).html(errors.join('<br />')).show();
    },
    onSuccess: function()
    {
      $("#errors-" + this.attr("name")).hide();
    },
    scriptURL: "/includes/asp/validate-ajax.asp"
  });
});