/**********                **********
 ********** Util functions **********
 **********                **********/

/// Display then fade out an element (usually an errorlist)
function show_errors(obj) {
  obj
    .fadeIn('fast')
    .animate({opacity: 1.0}, 3000) // Pause for 3 seconds
    .fadeOut('slow', function() {
        $(this).html("");
      });
}

/// Displays a hidden element with the 'yellow flash' technique
function show_with_flash(obj, fadeout_color) {
  if(fadeout_color == null) {
    fadeout_color = '#fbf2dc';
  }

  obj.css('background-color', '#ff5');

  if(obj.is("span")) {
    obj.show();
  } else {
    obj.show('slow');
  }

  obj.animate({'backgroundColor': fadeout_color}, 2000, 'linear', function() {
      $(this).css('background-color', 'transparent');
    });
}

function pause_fadeout(obj) {
  obj
    .animate({opacity: 1.0}, 3000) // Pause for 3 seconds
    .animate({opacity: 0.0}, 2000, function() { // Fade out over 2 seconds
        $(this).hide('slow');
      });
}

/// Show/hide the ajax loading indicator
function show_loading_indicator() {
  $(".ajax-load").addClass('ajax-load-enabled');
}

function hide_loading_indicator() {
  $(".ajax-load").removeClass('ajax-load-enabled');
}
