jQuery.fn.blindFadeToggle = function(speed, easing, callback) {
  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
}

jQuery.fn.flashMessage = function(style_class, message, duration) {
  return this.hide()
  .removeClass("error highlight notice")
  .addClass(style_class)
  .html(message)
  .blindFadeToggle()
  .animate({opacity: 1.0}, duration)
  .blindFadeToggle();
}

function select_first_field() {
  $(":text:first").select();
}

function disable_form() {
  $("fieldset input").attr("disabled", "disabled");
  $("fieldset select").attr("disabled", "disabled");
  $("fieldset textarea").attr("disabled", "disabled");
}

function enable_form() {
  $("fieldset input").removeAttr("disabled");
  $("fieldset select").removeAttr("disabled");
  $("fieldset textarea").removeAttr("disabled");
}

function pre_request(formData, jqForm, options) {
  $("div.form_message").removeClass("error highlight notice").html("").hide();
  disable_form();
  return true; // returning anything other than false will allow the form submit to continue 
}

function post_request(json, statusText) { 
  $("div.form_message").flashMessage(json.type, json.msg, 9000);
  if ( json.type == "notice" && json.redirect != "" )
  	setTimeout("window.location.replace('"+json.redirect+"?type="+json.type+"&msg="+json.msg+"')", 9000);
  else
	enable_form();
}
