/* these are various utility functions */

/* Send a proper DELETE verb to server */
$(function(){

  rebind_delete_links();

});

function rebind_delete_links() {
  $('.delete').unbind('click');
  $('.delete').bind('click', function(){
    msg = $(this).attr('rel');
    action = $(this).attr('href');

    var no_redirect = $(this).hasClass('remove');
    var remove_element_id = $(this).attr('rev');

    if (confirm(msg)) {
      $.ajax({
        type: "DELETE",
        url: action,
        complete: function(xhttp) {
          if (no_redirect) {
            $('#upload_' + remove_element_id).fadeOut('fast');
            return false;
          }
          else {
            window.location = xhttp.responseText;
          }
        }
      });
      return false;
    }
    else {
      return false;
    }
  });
}





