/*
 * CODE TO PREVENT MULTIUPLOAD FILES IN THE WEBSITE
 */
$("input[value='Upload']:submit" ).click(function(){
	$("input[value='Upload']:submit").fadeOut(500);
});

/**
 * Handler for the form redirection completion.
 */
Drupal.jsUpload.prototype.oncomplete = function (data) {
	// Remove old form
	  Drupal.freezeHeight(); // Avoid unnecessary scrolling
	  $(this.wrapper).html('');

	  // Place HTML into temporary div
	  var div = document.createElement('div');
	  $(div).html(data);

	  // If uploading the first attachment fade in everything
	  if ($('tr', div).size() == 2) {
	    // Replace form and re-attach behaviour
	    $(div).hide();
	    $(this.wrapper).append(div);
	    $(div).fadeIn('slow');
	    Drupal.uploadAutoAttach();
	  }
	  // Else fade in only the last table row
	  else {
	    // Hide form and last table row
	    $('table tr:last-child td', div).hide();

	    // Note: workaround because jQuery's #id selector does not work outside of 'document'
	    // Should be: $(this.hide, div).hide();
	    var hide = this.hide;
	    $('div', div).each(function() {
	      if (('#'+ this.id) == hide) {
	        this.style.display = 'none';
	      }
	    });

	    // Replace form, fade in items and re-attach behaviour
	    $(this.wrapper).append(div);
	    $('table tr:last-child td', div).fadeIn('slow');
	    $(this.hide, div).fadeIn('slow');
	    Drupal.uploadAutoAttach();
	  }
	  Drupal.unfreezeHeight();

	  //the buttons fadeOut previously need to reappear with a fadeIn
	  $("input[value='Upload']:submit").fadeIn(500);

	  //Refresh DOM event
	  $("input[value='Upload']:submit" ).click(function(){
		  $("input[value='Upload']:submit").fadeOut(500);
	  });
}