/*
* Require jQuery JavaScript Library v1.3.2
* and
* jQuery Form Plugin version: 2.18
*
* Examples and documentation at: http://malsup.com/jquery/form/
*/
function ajaxFileUpload(url, fileField, options)
{
  // Declaring the form id and the file field id to be used
  var fileFormId = 'add_file_form';
  var fileFieldId = 'file';
  
  // Let's change the attributes of our field received as a parameter
  fileField.attr({id:fileFieldId, name:fileFieldId});
  
  // Let's check if this function was called previously and the file form already exists in our document
  if ( jQuery('#'+fileFormId).length > 0 ) {
    var fileForm = jQuery('#'+fileFormId);
    fileForm.empty();
    fileForm.append(fileField);
  } else {
    // Creating element form and adding the element file received as a parameter
    var fileForm = new Element('form', {id:fileFormId, name:fileFormId, method:'post', style:'display:none;', enctype:'multipart/form-data'}).update(fileField.get(0));
    
    // Adding the file form to the document
    document.body.appendChild(fileForm);
    
    // Wrapping the file form element created above with jQuery to get access to jQuery functions
    fileForm = jQuery(fileForm);
  }
  
  // Setting the url
  fileForm.attr({action:url});
  
  // Submitting the form
  fileForm.ajaxSubmit(options);
}