$(document).ready(function(){
  // Sterretjes achter verplichte velden
  $(".required:not(:radio):not(:checkbox)").each(function(){
    $("label[for='" + $(this).attr("id") + "']").append('<span style="color: red"> *&nbsp;</span>');
  });

  $("div.question").each(function(){
    $(this).find(".required:radio:first, .required:checkbox:first").prev("br").before('<span style="color: red"> *</span>');
    $(this).find(".required:radio:first, .required:checkbox:first").parents("table").prev("br").before('<span style="color: red"> *</span>');
  });
  
  // validatie
  jQuery.validator.messages.required = "<img style='float: left' src='../../_includes/images/wrong.gif' />";
  var validator = $("#form").validate({
    rules: {
      email: "required",
      email2: {
        equalTo: "#email"
      }
    },
    errorPlacement: function(error, element) {
      error.insertBefore( element.parents(".question") );
    },
    success: function(label){
      label.append("<img style='float: left' src='../../_includes/images/correct.gif' />");
    },
    errorContainer: "#error",
    showErrors: function(errorMap, errorList) {
      $("#error").html("<p><b>Su formulario contiene " + this.numberOfInvalids() + " vea abajo los detalles.</b></p>");
      this.defaultShowErrors();
    }
  });
});
