function setupForm(form) {
  $(form).validate({
    focusInvalid: false,
    focusCleanup: true,
    onkeyup: false,
    ignoreTitle: true,
    errorPlacement: function(error, element) {
      element.parent().children("div.input-info").children("div.input-description").hide();
      error.appendTo(element.parent().children("div.input-info"));
    }
  })
  /* Remove the real labels of inputs with placeholders
     from our input fields as otherwise we have 2
     for each once jquery.placeholder has added new ones */
  //$(form+" input[placeholder],textarea[placeholder]").parent().children(form+" label").not(".error").remove();
  $(form+" input[placeholder],textarea[placeholder]").placeholder();
  $(form+" div.input-description").hide();
  // Set the width of the .input-info div so that it fills the space to the
  // right of the input element.
  $(form+" .field-wrapper:has(input)").each(function() {
    $(this).children(".input-info").first().width($(this).width() 
              - $(this).children("input").first().width() - 30);
  });
  $(form+" .field-wrapper:has(textarea)").each(function() {
    $(this).children(".input-info").first().width($(this).width() 
              - $(this).children("textarea").first().width() - 30);
  });
  // Apply active classes on form
  $(form+" :input").focus(function() {
    $(this).addClass("active");
    $(this).parent().children("div.input-info").children("div.input-description").show();
    //$(this).parent().children("div.input-info").children("label.error").hide();
  });
  $(form=" :input").blur(function() {
    $(this).removeClass("active");
    $(this).parent().children("div.input-info").children("div.input-description").hide();
  });
};

function ajaxifyForm(form, target) {
  if (target === undefined) {
    target = form
  }
  // Setup the form for AJAX submission
  var options = { 
    target: target,
    success: function() {
      $.colorbox.resize();
    },
    beforeSubmit: function() {
      $.colorbox.resize();
    }
  }
  $(form).ajaxForm(options);
};

