Index: /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.css
===================================================================
--- /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.css	(revision 5341)
+++ /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.css	(revision 6107)
@@ -1,5 +1,5 @@
 @charset 'UTF-8';
 /*
- * jQuery File Upload UI Plugin CSS 5.0.6
+ * jQuery File Upload UI Plugin CSS 6.3
  * https://github.com/blueimp/jQuery-File-Upload
  *
@@ -8,8 +8,14 @@
  *
  * Licensed under the MIT license:
- * http://creativecommons.org/licenses/MIT/
+ * http://www.opensource.org/licenses/MIT
  */
 
-.fileupload-buttonbar .ui-button input {
+.fileinput-button {
+  position: relative;
+  overflow: hidden;
+  float: left;
+  margin-right: 4px;
+}
+.fileinput-button input {
   position: absolute;
   top: 0;
@@ -20,81 +26,59 @@
   opacity: 0;
   filter: alpha(opacity=0);
-  -o-transform: translate(250px, -50px) scale(1);
   -moz-transform: translate(-300px, 0) scale(4);
   direction: ltr;
   cursor: pointer;
 }
-
-.fileinput-button {
-  overflow: hidden;
+.fileupload-buttonbar .btn,
+.fileupload-buttonbar .toggle {
+  margin-bottom: 5px;
+}
+.files .progress {
+  width: 200px;
+}
+.progress-animated .bar {
+  background: url(../img/progressbar.gif) !important;
+  filter: none;
+}
+.fileupload-loading {
+  position: absolute;
+  left: 50%;
+  width: 128px;
+  height: 128px;
+  background: url(../img/loading.gif) center no-repeat;
+  display: none;
+}
+.fileupload-processing .fileupload-loading {
+  display: block;
 }
 
 /* Fix for IE 6: */
 *html .fileinput-button {
-  padding: 2px 0;
+  line-height: 22px;
+  margin: 1px -3px 0 0;
 }
 
 /* Fix for IE 7: */
 *+html .fileinput-button {
-  padding: 2px 0;
+  margin: 1px 0 0 0;
 }
 
-.fileupload-buttonbar {
-  padding: 0.2em 0.4em;
+@media (max-width: 480px) {
+  .files .btn span {
+    display: none;
+  }
+  .files .preview * {
+    width: 40px;
+  }
+  .files .name * {
+    width: 80px;
+    display: inline-block;
+    word-wrap: break-word;
+  }
+  .files .progress {
+    width: 20px;
+  }
+  .files .delete {
+    width: 60px;
+  }
 }
-
-.fileupload-buttonbar .ui-button {
-  vertical-align: middle;
-}
-
-.fileupload-content {
-  padding: 0.2em 0.4em;
-  border-top-width: 0;
-}
-
-.fileupload-content .ui-progressbar {
-  width: 200px;
-  height: 20px;
-}
-
-.fileupload-content .ui-progressbar-value {
-  background: url(pbar-ani.gif);
-}
-
-.fileupload-content .fileupload-progressbar {
-  width: 400px;
-  margin: 10px 0;
-}
-
-.files {
-  margin: 10px 0;
-  border-collapse: collapse;
-}
-
-.files td {
-  padding: 5px;
-  border-spacing: 5px;
-}
-
-.files img {
-  border: none;
-}
-
-.files .name {
-  padding: 0 10px;
-}
-
-.files .size {
-  padding: 0 10px 0 0;
-  text-align: right;
-  white-space: nowrap;
-}
-
-.ui-state-disabled .ui-state-disabled {
-  opacity: 1;
-  filter: alpha(opacity=100);
-}
-
-.ui-state-disabled input {
-  cursor: default;
-}
Index: /trunk/prototype/plugins/fileupload/jquery.iframe-transport.js
===================================================================
--- /trunk/prototype/plugins/fileupload/jquery.iframe-transport.js	(revision 5341)
+++ /trunk/prototype/plugins/fileupload/jquery.iframe-transport.js	(revision 6107)
@@ -1,4 +1,4 @@
 /*
- * jQuery Iframe Transport Plugin 1.2.2
+ * jQuery Iframe Transport Plugin 1.4
  * https://github.com/blueimp/jQuery-File-Upload
  *
@@ -7,11 +7,20 @@
  *
  * Licensed under the MIT license:
- * http://creativecommons.org/licenses/MIT/
+ * http://www.opensource.org/licenses/MIT
  */
 
-/*jslint unparam: true */
-/*global jQuery */
+/*jslint unparam: true, nomen: true */
+/*global define, window, document */
 
-(function ($) {
+(function (factory) {
+    'use strict';
+    if (typeof define === 'function' && define.amd) {
+        // Register as an anonymous AMD module:
+        define(['jquery'], factory);
+    } else {
+        // Browser globals:
+        factory(window.jQuery);
+    }
+}(function ($) {
     'use strict';
 
@@ -22,14 +31,15 @@
     // options.fileInput: a jQuery collection of file input fields
     // options.paramName: the parameter name for the file form data,
-    //  overrides the name property of the file input field(s)
+    //  overrides the name property of the file input field(s),
+    //  can be a string or an array of strings.
     // options.formData: an array of objects with name and value properties,
     //  equivalent to the return data of .serializeArray(), e.g.:
-    //  [{name: a, value: 1}, {name: b, value: 2}]
-    $.ajaxTransport('iframe', function (options, originalOptions, jqXHR) {
-        if (options.type === 'POST' || options.type === 'GET') {
+    //  [{name: 'a', value: 1}, {name: 'b', value: 2}]
+    $.ajaxTransport('iframe', function (options) {
+        if (options.async && (options.type === 'POST' || options.type === 'GET')) {
             var form,
                 iframe;
             return {
-                send: function (headers, completeCallback) {
+                send: function (_, completeCallback) {
                     form = $('<form style="display:none;"></form>');
                     // javascript:false as initial iframe src
@@ -42,5 +52,7 @@
                             (counter += 1) + '"></iframe>'
                     ).bind('load', function () {
-                        var fileInputClones;
+                        var fileInputClones,
+                            paramNames = $.isArray(options.paramName) ?
+                                    options.paramName : [options.paramName];
                         iframe
                             .unbind('load')
@@ -93,6 +105,9 @@
                             });
                             if (options.paramName) {
-                                options.fileInput.each(function () {
-                                    $(this).prop('name', options.paramName);
+                                options.fileInput.each(function (index) {
+                                    $(this).prop(
+                                        'name',
+                                        paramNames[index] || options.paramName
+                                    );
                                 });
                             }
@@ -116,5 +131,5 @@
                         }
                     });
-                    form.append(iframe).appendTo('body');
+                    form.append(iframe).appendTo(document.body);
                 },
                 abort: function () {
@@ -140,17 +155,17 @@
         converters: {
             'iframe text': function (iframe) {
-                return iframe.text();
+                return $(iframe[0].body).text();
             },
             'iframe json': function (iframe) {
-                return $.parseJSON(iframe.text());
+                return $.parseJSON($(iframe[0].body).text());
             },
             'iframe html': function (iframe) {
-                return iframe.find('body').html();
+                return $(iframe[0].body).html();
             },
             'iframe script': function (iframe) {
-                return $.globalEval(iframe.text());
+                return $.globalEval($(iframe[0].body).text());
             }
         }
     });
 
-}(jQuery));
+}));
Index: /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.js
===================================================================
--- /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.js	(revision 5341)
+++ /trunk/prototype/plugins/fileupload/jquery.fileupload-ui.js	(revision 6107)
@@ -1,4 +1,4 @@
 /*
- * jQuery File Upload User Interface Plugin 5.0.16
+ * jQuery File Upload User Interface Plugin 6.7
  * https://github.com/blueimp/jQuery-File-Upload
  *
@@ -7,18 +7,36 @@
  *
  * Licensed under the MIT license:
- * http://creativecommons.org/licenses/MIT/
+ * http://www.opensource.org/licenses/MIT
  */
 
 /*jslint nomen: true, unparam: true, regexp: true */
-/*global window, document, URL, webkitURL, FileReader, jQuery */
-
-(function ($) {
+/*global define, window, document, URL, webkitURL, FileReader */
+
+(function (factory) {
     'use strict';
-    
-    // The UI version extends the basic fileupload widget and adds
-    // a complete user interface based on the given upload/download
-    // templates.
-    $.widget('blueimpUI.fileupload', $.blueimp.fileupload, {
-        
+    if (typeof define === 'function' && define.amd) {
+        // Register as an anonymous AMD module:
+        define([
+            'jquery',
+            'tmpl',
+            'load-image',
+            './jquery.fileupload-fp'
+        ], factory);
+    } else {
+        // Browser globals:
+        factory(
+            window.jQuery,
+            window.tmpl,
+            window.loadImage
+        );
+    }
+}(function ($, tmpl, loadImage) {
+    'use strict';
+
+    // The UI version extends the FP (file processing) version or the basic
+    // file upload widget and adds complete user interface interaction:
+    var parentWidget = ($.blueimpFP || $.blueimp).fileupload;
+    $.widget('blueimpUI.fileupload', parentWidget, {
+
         options: {
             // By default, files added to the widget are uploaded as soon
@@ -32,5 +50,5 @@
             maxFileSize: undefined,
             // The minimum allowed file size:
-            minFileSize: 1,
+            minFileSize: undefined,
             // The regular expression for allowed file types, matches
             // against either file type or file name:
@@ -38,5 +56,7 @@
             // The regular expression to define for which files a preview
             // image is shown, matched against the file type:
-            previewFileTypes: /^image\/(gif|jpeg|png)$/,
+            previewSourceFileTypes: /^image\/(gif|jpeg|png)$/,
+            // The maximum file size of images that are to be displayed as preview:
+            previewSourceMaxFileSize: 5000000, // 5MB
             // The maximum width of the preview images:
             previewMaxWidth: 80,
@@ -47,36 +67,50 @@
             // to always display preview images as img elements:
             previewAsCanvas: true,
-            // The file upload template that is given as first argument to the
-            // jQuery.tmpl method to render the file uploads:
-            uploadTemplate: $('#template-upload'),
-            // The file download template, that is given as first argument to the
-            // jQuery.tmpl method to render the file downloads:
-            downloadTemplate: $('#template-download'),
+            // The ID of the upload template:
+            uploadTemplateId: 'template-upload',
+            // The ID of the download template:
+            downloadTemplateId: 'template-download',
+            // The container for the list of files. If undefined, it is set to
+            // an element with class "files" inside of the widget element:
+            filesContainer: undefined,
+            // By default, files are appended to the files container.
+            // Set the following option to true, to prepend files instead:
+            prependFiles: false,
             // The expected data type of the upload response, sets the dataType
             // option of the $.ajax upload requests:
             dataType: 'json',
-            
+
             // The add callback is invoked as soon as files are added to the fileupload
             // widget (via file input selection, drag & drop or add API call).
             // See the basic file upload widget for more information:
             add: function (e, data) {
-                var that = $(this).data('fileupload');
-                that._adjustMaxNumberOfFiles(-data.files.length);
-                data.isAdjusted = true;
-                data.isValidated = that._validate(data.files);
-                data.context = that._renderUpload(data.files)
-                    .appendTo($(this).find('.files')).fadeIn(function () {
-                        // Fix for IE7 and lower:
-                        $(this).show();
-                    }).data('data', data);
-                if ((that.options.autoUpload || data.autoUpload) &&
-                        data.isValidated) {
-                    data.jqXHR = data.submit();
-                }
+                var that = $(this).data('fileupload'),
+                    options = that.options,
+                    files = data.files;
+                $(this).fileupload('process', data).done(function () {
+                    that._adjustMaxNumberOfFiles(-files.length);
+                    data.isAdjusted = true;
+                    data.files.valid = data.isValidated = that._validate(files);
+                    data.context = that._renderUpload(files).data('data', data);
+                    options.filesContainer[
+                        options.prependFiles ? 'prepend' : 'append'
+                    ](data.context);
+                    that._renderPreviews(files, data.context);
+                    that._forceReflow(data.context);
+                    that._transition(data.context).done(
+                        function () {
+                            if ((that._trigger('added', e, data) !== false) &&
+                                    (options.autoUpload || data.autoUpload) &&
+                                    data.autoUpload !== false && data.isValidated) {
+                                data.submit();
+                            }
+                        }
+                    );
+                });
             },
             // Callback for the start of each file upload request:
             send: function (e, data) {
+                var that = $(this).data('fileupload');
                 if (!data.isValidated) {
-                    var that = $(this).data('fileupload');
                     if (!data.isAdjusted) {
                         that._adjustMaxNumberOfFiles(-data.files.length);
@@ -91,13 +125,20 @@
                     // In lack of an indeterminate progress bar, we set
                     // the progress to 100%, showing the full animated bar:
-                    data.context.find('.ui-progressbar').progressbar(
-                        'value',
-                        parseInt(100, 10)
-                    );
-                }
+                    data.context
+                        .find('.progress').addClass(
+                            !$.support.transition && 'progress-animated'
+                        )
+                        .find('.bar').css(
+                            'width',
+                            parseInt(100, 10) + '%'
+                        );
+                }
+                return that._trigger('sent', e, data);
             },
             // Callback for successful uploads:
             done: function (e, data) {
-                var that = $(this).data('fileupload');
+                var that = $(this).data('fileupload'),
+                    template,
+                    preview;
                 if (data.context) {
                     data.context.each(function (index) {
@@ -107,56 +148,80 @@
                             that._adjustMaxNumberOfFiles(1);
                         }
-                        $(this).fadeOut(function () {
-                            that._renderDownload([file])
-                                .css('display', 'none')
-                                .replaceAll(this)
-                                .fadeIn(function () {
-                                    // Fix for IE7 and lower:
-                                    $(this).show();
-                                });
-                        });
+                        that._transition($(this)).done(
+                            function () {
+                                var node = $(this);
+                                template = that._renderDownload([file])
+                                    .css('height', node.height())
+                                    .replaceAll(node);
+                                that._forceReflow(template);
+                                that._transition(template).done(
+                                    function () {
+                                        data.context = $(this);
+                                        that._trigger('completed', e, data);
+                                    }
+                                );
+                            }
+                        );
                     });
                 } else {
-                    that._renderDownload(data.result)
-                        .css('display', 'none')
-                        .appendTo($(this).find('.files'))
-                        .fadeIn(function () {
-                            // Fix for IE7 and lower:
-                            $(this).show();
-                        });
+                    template = that._renderDownload(data.result)
+                        .appendTo(that.options.filesContainer);
+                    that._forceReflow(template);
+                    that._transition(template).done(
+                        function () {
+                            data.context = $(this);
+                            that._trigger('completed', e, data);
+                        }
+                    );
                 }
             },
             // Callback for failed (abort or error) uploads:
             fail: function (e, data) {
-                var that = $(this).data('fileupload');
+                var that = $(this).data('fileupload'),
+                    template;
                 that._adjustMaxNumberOfFiles(data.files.length);
                 if (data.context) {
                     data.context.each(function (index) {
-                        $(this).fadeOut(function () {
-                            if (data.errorThrown !== 'abort') {
-                                var file = data.files[index];
-                                file.error = file.error || data.errorThrown
-                                    || true;
-                                that._renderDownload([file])
-                                    .css('display', 'none')
-                                    .replaceAll(this)
-                                    .fadeIn(function () {
-                                        // Fix for IE7 and lower:
-                                        $(this).show();
-                                    });
-                            } else {
-                                data.context.remove();
-                            }
-                        });
+                        if (data.errorThrown !== 'abort') {
+                            var file = data.files[index];
+                            file.error = file.error || data.errorThrown ||
+                                true;
+                            that._transition($(this)).done(
+                                function () {
+                                    var node = $(this);
+                                    template = that._renderDownload([file])
+                                        .replaceAll(node);
+                                    that._forceReflow(template);
+                                    that._transition(template).done(
+                                        function () {
+                                            data.context = $(this);
+                                            that._trigger('failed', e, data);
+                                        }
+                                    );
+                                }
+                            );
+                        } else {
+                            that._transition($(this)).done(
+                                function () {
+                                    $(this).remove();
+                                    that._trigger('failed', e, data);
+                                }
+                            );
+                        }
                     });
                 } else if (data.errorThrown !== 'abort') {
                     that._adjustMaxNumberOfFiles(-data.files.length);
                     data.context = that._renderUpload(data.files)
-                        .css('display', 'none')
-                        .appendTo($(this).find('.files'))
-                        .fadeIn(function () {
-                            // Fix for IE7 and lower:
-                            $(this).show();
-                        }).data('data', data);
+                        .appendTo(that.options.filesContainer)
+                        .data('data', data);
+                    that._forceReflow(data.context);
+                    that._transition(data.context).done(
+                        function () {
+                            data.context = $(this);
+                            that._trigger('failed', e, data);
+                        }
+                    );
+                } else {
+                    that._trigger('failed', e, data);
                 }
             },
@@ -164,7 +229,7 @@
             progress: function (e, data) {
                 if (data.context) {
-                    data.context.find('.ui-progressbar').progressbar(
-                        'value',
-                        parseInt(data.loaded / data.total * 100, 10)
+                    data.context.find('.progress .bar').css(
+                        'width',
+                        parseInt(data.loaded / data.total * 100, 10) + '%'
                     );
                 }
@@ -172,17 +237,27 @@
             // Callback for global upload progress events:
             progressall: function (e, data) {
-                $(this).find('.fileupload-progressbar').progressbar(
-                    'value',
-                    parseInt(data.loaded / data.total * 100, 10)
+                $(this).find('.fileupload-buttonbar .progress .bar').css(
+                    'width',
+                    parseInt(data.loaded / data.total * 100, 10) + '%'
                 );
             },
             // Callback for uploads start, equivalent to the global ajaxStart event:
-            start: function () {
-                $(this).find('.fileupload-progressbar')
-                    .progressbar('value', 0).fadeIn();
+            start: function (e) {
+                var that = $(this).data('fileupload');
+                that._transition($(this).find('.fileupload-buttonbar .progress')).done(
+                    function () {
+                        that._trigger('started', e);
+                    }
+                );
             },
             // Callback for uploads stop, equivalent to the global ajaxStop event:
-            stop: function () {
-                $(this).find('.fileupload-progressbar').fadeOut();
+            stop: function (e) {
+                var that = $(this).data('fileupload');
+                that._transition($(this).find('.fileupload-buttonbar .progress')).done(
+                    function () {
+                        $(this).find('.bar').css('width', '0%');
+                        that._trigger('stopped', e);
+                    }
+                );
             },
             // Callback for file deletion:
@@ -190,102 +265,13 @@
                 var that = $(this).data('fileupload');
                 if (data.url) {
-                    $.ajax(data)
-                        .success(function () {
-                            that._adjustMaxNumberOfFiles(1);
-                            $(this).fadeOut(function () {
-                                $(this).remove();
-                            });
-                        });
-                } else {
-                    that._adjustMaxNumberOfFiles(1);
-                    data.context.fadeOut(function () {
+                    $.ajax(data);
+                }
+                that._adjustMaxNumberOfFiles(1);
+                that._transition(data.context).done(
+                    function () {
                         $(this).remove();
-                    });
-                }
-            }
-        },
-
-        // Scales the given image (img HTML element)
-        // using the given options.
-        // Returns a canvas object if the canvas option is true
-        // and the browser supports canvas, else the scaled image:
-        _scaleImage: function (img, options) {
-            options = options || {};
-            var canvas = document.createElement('canvas'),
-                scale = Math.min(
-                    (options.maxWidth || img.width) / img.width,
-                    (options.maxHeight || img.height) / img.height
+                        that._trigger('destroyed', e, data);
+                    }
                 );
-            if (scale >= 1) {
-                scale = Math.max(
-                    (options.minWidth || img.width) / img.width,
-                    (options.minHeight || img.height) / img.height
-                );
-            }
-            img.width = parseInt(img.width * scale, 10);
-            img.height = parseInt(img.height * scale, 10);
-            if (!options.canvas || !canvas.getContext) {
-                return img;
-            }
-            canvas.width = img.width;
-            canvas.height = img.height;
-            canvas.getContext('2d')
-                .drawImage(img, 0, 0, img.width, img.height);
-            return canvas;
-        },
-
-        _createObjectURL: function (file) {
-            var undef = 'undefined',
-                urlAPI = (typeof window.createObjectURL !== undef && window) ||
-                    (typeof URL !== undef && URL) ||
-                    (typeof webkitURL !== undef && webkitURL);
-            return urlAPI ? urlAPI.createObjectURL(file) : false;
-        },
-        
-        _revokeObjectURL: function (url) {
-            var undef = 'undefined',
-                urlAPI = (typeof window.revokeObjectURL !== undef && window) ||
-                    (typeof URL !== undef && URL) ||
-                    (typeof webkitURL !== undef && webkitURL);
-            return urlAPI ? urlAPI.revokeObjectURL(url) : false;
-        },
-
-        // Loads a given File object via FileReader interface,
-        // invokes the callback with a data url:
-        _loadFile: function (file, callback) {
-            if (typeof FileReader !== 'undefined' &&
-                    FileReader.prototype.readAsDataURL) {
-                var fileReader = new FileReader();
-                fileReader.onload = function (e) {
-                    callback(e.target.result);
-                };
-                fileReader.readAsDataURL(file);
-                return true;
-            }
-            return false;
-        },
-
-        // Loads an image for a given File object.
-        // Invokes the callback with an img or optional canvas
-        // element (if supported by the browser) as parameter:
-        _loadImage: function (file, callback, options) {
-            var that = this,
-                url,
-                img;
-            if (!options || !options.fileTypes ||
-                    options.fileTypes.test(file.type)) {
-                url = this._createObjectURL(file);
-                img = $('<img>').bind('load', function () {
-                    $(this).unbind('load');
-                    that._revokeObjectURL(url);
-                    callback(that._scaleImage(img[0], options));
-                });
-                if (url) {
-                    img.prop('src', url);
-                } else {
-                    this._loadFile(file, function (url) {
-                        img.prop('src', url);
-                    });
-                }
             }
         },
@@ -296,6 +282,5 @@
             var link = $(this),
                 url = link.prop('href'),
-                name = decodeURIComponent(url.split('/').pop())
-                    .replace(/:/g, '-'),
+                name = link.prop('download'),
                 type = 'application/octet-stream';
             link.bind('dragstart', function (e) {
@@ -320,15 +305,15 @@
         },
 
-        _formatFileSize: function (file) {
-            if (typeof file.size !== 'number') {
+        _formatFileSize: function (bytes) {
+            if (typeof bytes !== 'number') {
                 return '';
             }
-            if (file.size >= 1000000000) {
-                return (file.size / 1000000000).toFixed(2) + ' GB';
-            }
-            if (file.size >= 1000000) {
-                return (file.size / 1000000).toFixed(2) + ' MB';
-            }
-            return (file.size / 1000).toFixed(2) + ' KB';
+            if (bytes >= 1000000000) {
+                return (bytes / 1000000000).toFixed(2) + ' GB';
+            }
+            if (bytes >= 1000000) {
+                return (bytes / 1000000).toFixed(2) + ' MB';
+            }
+            return (bytes / 1000).toFixed(2) + ' KB';
         },
 
@@ -373,106 +358,96 @@
         },
 
-        _uploadTemplateHelper: function (file) {
-            file.sizef = this._formatFileSize(file);
-            return file;
-        },
-
-        _renderUploadTemplate: function (files) {
-            var that = this;
-            return $.tmpl(
-                this.options.uploadTemplate,
-                $.map(files, function (file) {
-                    return that._uploadTemplateHelper(file);
-                })
-            );
-        },
-
-        _renderUpload: function (files) {
+        _renderTemplate: function (func, files) {
+            if (!func) {
+                return $();
+            }
+            var result = func({
+                files: files,
+                formatFileSize: this._formatFileSize,
+                options: this.options
+            });
+            if (result instanceof $) {
+                return result;
+            }
+            return $(this.options.templatesContainer).html(result).children();
+        },
+
+        _renderPreview: function (file, node) {
             var that = this,
                 options = this.options,
-                tmpl = this._renderUploadTemplate(files),
-                isValidated = this._validate(files);
-            if (!(tmpl instanceof $)) {
-                return $();
-            }
-            tmpl.css('display', 'none');
-            // .slice(1).remove().end().first() removes all but the first
-            // element and selects only the first for the jQuery collection:
-            tmpl.find('.progress div').slice(
-                isValidated ? 1 : 0
-            ).remove().end().first()
-                .progressbar();
-            tmpl.find('.start button').slice(
-                this.options.autoUpload || !isValidated ? 0 : 1
-            ).remove().end().first()
-                .button({
-                    text: false,
-                    icons: {primary: 'ui-icon-circle-arrow-e'}
-                });
-            tmpl.find('.cancel button').slice(1).remove().end().first()
-                .button({
-                    text: false,
-                    icons: {primary: 'ui-icon-cancel'}
-                });
-            tmpl.find('.preview').each(function (index, node) {
-                that._loadImage(
-                    files[index],
-                    function (img) {
-                        $(img).hide().appendTo(node).fadeIn();
-                    },
-                    {
-                        maxWidth: options.previewMaxWidth,
-                        maxHeight: options.previewMaxHeight,
-                        fileTypes: options.previewFileTypes,
-                        canvas: options.previewAsCanvas
+                dfd = $.Deferred();
+            return ((loadImage && loadImage(
+                file,
+                function (img) {
+                    node.append(img);
+                    that._forceReflow(node);
+                    that._transition(node).done(function () {
+                        dfd.resolveWith(node);
+                    });
+                    if (!$.contains(document.body, node[0])) {
+                        // If the element is not part of the DOM,
+                        // transition events are not triggered,
+                        // so we have to resolve manually:
+                        dfd.resolveWith(node);
                     }
-                );
+                },
+                {
+                    maxWidth: options.previewMaxWidth,
+                    maxHeight: options.previewMaxHeight,
+                    canvas: options.previewAsCanvas
+                }
+            )) || dfd.resolveWith(node)) && dfd;
+        },
+
+        _renderPreviews: function (files, nodes) {
+            var that = this,
+                options = this.options;
+            nodes.find('.preview span').each(function (index, element) {
+                var file = files[index];
+                if (options.previewSourceFileTypes.test(file.type) &&
+                        ($.type(options.previewSourceMaxFileSize) !== 'number' ||
+                        file.size < options.previewSourceMaxFileSize)) {
+                    that._processingQueue = that._processingQueue.pipe(function () {
+                        var dfd = $.Deferred();
+                        that._renderPreview(file, $(element)).done(
+                            function () {
+                                dfd.resolveWith(that);
+                            }
+                        );
+                        return dfd.promise();
+                    });
+                }
             });
-            return tmpl;
-        },
-
-        _downloadTemplateHelper: function (file) {
-            file.sizef = this._formatFileSize(file);
-            return file;
-        },
-
-        _renderDownloadTemplate: function (files) {
-            var that = this;
-            return $.tmpl(
+            return this._processingQueue;
+        },
+
+        _renderUpload: function (files) {
+            return this._renderTemplate(
+                this.options.uploadTemplate,
+                files
+            );
+        },
+
+        _renderDownload: function (files) {
+            return this._renderTemplate(
                 this.options.downloadTemplate,
-                $.map(files, function (file) {
-                    return that._downloadTemplateHelper(file);
-                })
-            );
-        },
-        
-        _renderDownload: function (files) {
-            var tmpl = this._renderDownloadTemplate(files);
-            if (!(tmpl instanceof $)) {
-                return $();
-            }
-            tmpl.css('display', 'none');
-            tmpl.find('.delete button').button({
-                text: false,
-                icons: {primary: 'ui-icon-trash'}
-            });
-            tmpl.find('a').each(this._enableDragToDesktop);
-            return tmpl;
-        },
-        
+                files
+            ).find('a[download]').each(this._enableDragToDesktop).end();
+        },
+
         _startHandler: function (e) {
             e.preventDefault();
-            var tmpl = $(this).closest('.template-upload'),
-                data = tmpl.data('data');
-            if (data && data.submit && !data.jqXHR) {
-                data.jqXHR = data.submit();
-                $(this).fadeOut();
-            }
-        },
-        
+            var button = $(this),
+                template = button.closest('.template-upload'),
+                data = template.data('data');
+            if (data && data.submit && !data.jqXHR && data.submit()) {
+                button.prop('disabled', true);
+            }
+        },
+
         _cancelHandler: function (e) {
             e.preventDefault();
-            var tmpl = $(this).closest('.template-upload'),
-                data = tmpl.data('data') || {};
+            var template = $(this).closest('.template-upload'),
+                data = template.data('data') || {};
             if (!data.jqXHR) {
                 data.errorThrown = 'abort';
@@ -482,5 +457,5 @@
             }
         },
-        
+
         _deleteHandler: function (e) {
             e.preventDefault();
@@ -489,57 +464,41 @@
                 context: button.closest('.template-download'),
                 url: button.attr('data-url'),
-                type: button.attr('data-type'),
+                type: button.attr('data-type') || 'DELETE',
                 dataType: e.data.fileupload.options.dataType
             });
         },
-        
-        _initEventHandlers: function () {
-            $.blueimp.fileupload.prototype._initEventHandlers.call(this);
-            var filesList = this.element.find('.files'),
-                eventData = {fileupload: this};
-            filesList.find('.start button')
-                .live(
-                    'click.' + this.options.namespace,
-                    eventData,
-                    this._startHandler
-                );
-            filesList.find('.cancel button')
-                .live(
-                    'click.' + this.options.namespace,
-                    eventData,
-                    this._cancelHandler
-                );
-            filesList.find('.delete button')
-                .live(
-                    'click.' + this.options.namespace,
-                    eventData,
-                    this._deleteHandler
-                );
-        },
-        
-        _destroyEventHandlers: function () {
-            var filesList = this.element.find('.files');
-            filesList.find('.start button')
-                .die('click.' + this.options.namespace);
-            filesList.find('.cancel button')
-                .die('click.' + this.options.namespace);
-            filesList.find('.delete button')
-                .die('click.' + this.options.namespace);
-            $.blueimp.fileupload.prototype._destroyEventHandlers.call(this);
-        },
-
-        _initFileUploadButtonBar: function () {
+
+        _forceReflow: function (node) {
+            this._reflow = $.support.transition &&
+                node.length && node[0].offsetWidth;
+        },
+
+        _transition: function (node) {
+            var that = this,
+                dfd = $.Deferred();
+            if ($.support.transition && node.hasClass('fade')) {
+                node.bind(
+                    $.support.transition.end,
+                    function (e) {
+                        // Make sure we don't respond to other transitions events
+                        // in the container element, e.g. from button elements:
+                        if (e.target === node[0]) {
+                            node.unbind($.support.transition.end);
+                            dfd.resolveWith(node);
+                        }
+                    }
+                ).toggleClass('in');
+            } else {
+                node.toggleClass('in');
+                dfd.resolveWith(node);
+            }
+            return dfd;
+        },
+
+        _initButtonBarEventHandlers: function () {
             var fileUploadButtonBar = this.element.find('.fileupload-buttonbar'),
-                filesList = this.element.find('.files'),
+                filesList = this.options.filesContainer,
                 ns = this.options.namespace;
-            fileUploadButtonBar
-                .addClass('ui-widget-header ui-corner-top');
-            this.element.find('.fileinput-button').each(function () {
-                var fileInput = $(this).find('input:file').detach();
-                $(this).button({icons: {primary: 'ui-icon-plusthick'}})
-                    .append(fileInput);
-            });
             fileUploadButtonBar.find('.start')
-                .button({icons: {primary: 'ui-icon-circle-arrow-e'}})
                 .bind('click.' + ns, function (e) {
                     e.preventDefault();
@@ -547,5 +506,4 @@
                 });
             fileUploadButtonBar.find('.cancel')
-                .button({icons: {primary: 'ui-icon-cancel'}})
                 .bind('click.' + ns, function (e) {
                     e.preventDefault();
@@ -553,98 +511,132 @@
                 });
             fileUploadButtonBar.find('.delete')
-                .button({icons: {primary: 'ui-icon-trash'}})
                 .bind('click.' + ns, function (e) {
                     e.preventDefault();
-                    filesList.find('.delete button').click();
+                    filesList.find('.delete input:checked')
+                        .siblings('button').click();
+                    fileUploadButtonBar.find('.toggle')
+                        .prop('checked', false);
                 });
-        },
-        
-        _destroyFileUploadButtonBar: function () {
-            this.element.find('.fileupload-buttonbar')
-                .removeClass('ui-widget-header ui-corner-top');
-            this.element.find('.fileinput-button').each(function () {
-                var fileInput = $(this).find('input:file').detach();
-                $(this).button('destroy')
-                    .append(fileInput);
-            });
+            fileUploadButtonBar.find('.toggle')
+                .bind('change.' + ns, function (e) {
+                    filesList.find('.delete input').prop(
+                        'checked',
+                        $(this).is(':checked')
+                    );
+                });
+        },
+
+        _destroyButtonBarEventHandlers: function () {
             this.element.find('.fileupload-buttonbar button')
-                .unbind('click.' + this.options.namespace)
-                .button('destroy');
+                .unbind('click.' + this.options.namespace);
+            this.element.find('.fileupload-buttonbar .toggle')
+                .unbind('change.' + this.options.namespace);
+        },
+
+        _initEventHandlers: function () {
+            parentWidget.prototype._initEventHandlers.call(this);
+            var eventData = {fileupload: this};
+            this.options.filesContainer
+                .delegate(
+                    '.start button',
+                    'click.' + this.options.namespace,
+                    eventData,
+                    this._startHandler
+                )
+                .delegate(
+                    '.cancel button',
+                    'click.' + this.options.namespace,
+                    eventData,
+                    this._cancelHandler
+                )
+                .delegate(
+                    '.delete button',
+                    'click.' + this.options.namespace,
+                    eventData,
+                    this._deleteHandler
+                );
+            this._initButtonBarEventHandlers();
+        },
+
+        _destroyEventHandlers: function () {
+            var options = this.options;
+            this._destroyButtonBarEventHandlers();
+            options.filesContainer
+                .undelegate('.start button', 'click.' + options.namespace)
+                .undelegate('.cancel button', 'click.' + options.namespace)
+                .undelegate('.delete button', 'click.' + options.namespace);
+            parentWidget.prototype._destroyEventHandlers.call(this);
         },
 
         _enableFileInputButton: function () {
-            this.element.find('.fileinput-button input:file:disabled')
-                .each(function () {
-                    var fileInput = $(this),
-                        button = fileInput.parent();
-                    fileInput.detach().prop('disabled', false);
-                    button.button('enable').append(fileInput);
-                });
+            this.element.find('.fileinput-button input')
+                .prop('disabled', false)
+                .parent().removeClass('disabled');
         },
 
         _disableFileInputButton: function () {
-            this.element.find('.fileinput-button input:file:enabled')
-                .each(function () {
-                    var fileInput = $(this),
-                        button = fileInput.parent();
-                    fileInput.detach().prop('disabled', true);
-                    button.button('disable').append(fileInput);
-                });
+            this.element.find('.fileinput-button input')
+                .prop('disabled', true)
+                .parent().addClass('disabled');
         },
 
         _initTemplates: function () {
-            // Handle cases where the templates are defined
-            // after the widget library has been included:
-            if (this.options.uploadTemplate instanceof $ &&
-                    !this.options.uploadTemplate.length) {
-                this.options.uploadTemplate = $(
-                    this.options.uploadTemplate.selector
-                );
-            }
-            if (this.options.downloadTemplate instanceof $ &&
-                    !this.options.downloadTemplate.length) {
-                this.options.downloadTemplate = $(
-                    this.options.downloadTemplate.selector
-                );
-            }
+            var options = this.options;
+            options.templatesContainer = document.createElement(
+                options.filesContainer.prop('nodeName')
+            );
+            if (tmpl) {
+                if (options.uploadTemplateId) {
+                    options.uploadTemplate = tmpl(options.uploadTemplateId);
+                }
+                if (options.downloadTemplateId) {
+                    options.downloadTemplate = tmpl(options.downloadTemplateId);
+                }
+            }
+        },
+
+        _initFilesContainer: function () {
+            var options = this.options;
+            if (options.filesContainer === undefined) {
+                options.filesContainer = this.element.find('.files');
+            } else if (!(options.filesContainer instanceof $)) {
+                options.filesContainer = $(options.filesContainer);
+            }
+        },
+
+        _initSpecialOptions: function () {
+            parentWidget.prototype._initSpecialOptions.call(this);
+            this._initFilesContainer();
+            this._initTemplates();
         },
 
         _create: function () {
-            $.blueimp.fileupload.prototype._create.call(this);
-            this._initTemplates();
-            this.element
-                .addClass('ui-widget');
-            this._initFileUploadButtonBar();
-            this.element.find('.fileupload-content')
-                .addClass('ui-widget-content ui-corner-bottom');
-            this.element.find('.fileupload-progressbar')
-                .hide().progressbar();
-        },
-        
-        destroy: function () {
-            this.element.find('.fileupload-progressbar')
-                .progressbar('destroy');
-            this.element.find('.fileupload-content')
-                .removeClass('ui-widget-content ui-corner-bottom');
-            this._destroyFileUploadButtonBar();
-            this.element.removeClass('ui-widget');
-            $.blueimp.fileupload.prototype.destroy.call(this);
-        },
-        
+            parentWidget.prototype._create.call(this);
+            this._refreshOptionsList.push(
+                'filesContainer',
+                'uploadTemplateId',
+                'downloadTemplateId'
+            );
+            if (!$.blueimpFP) {
+                this._processingQueue = $.Deferred().resolveWith(this).promise();
+                this.process = function () {
+                    return this._processingQueue;
+                };
+            }
+        },
+
         enable: function () {
-            $.blueimp.fileupload.prototype.enable.call(this);
-            this.element.find(':ui-button').not('.fileinput-button')
-                .button('enable');
+            parentWidget.prototype.enable.call(this);
+            this.element.find('input, button').prop('disabled', false);
             this._enableFileInputButton();
         },
-        
+
         disable: function () {
-            this.element.find(':ui-button').not('.fileinput-button')
-                .button('disable');
+            this.element.find('input, button').prop('disabled', true);
             this._disableFileInputButton();
-            $.blueimp.fileupload.prototype.disable.call(this);
+            parentWidget.prototype.disable.call(this);
         }
 
     });
 
-}(jQuery));
+}));
Index: /trunk/prototype/plugins/fileupload/jquery.fileupload.js
===================================================================
--- /trunk/prototype/plugins/fileupload/jquery.fileupload.js	(revision 5341)
+++ /trunk/prototype/plugins/fileupload/jquery.fileupload.js	(revision 6107)
@@ -1,4 +1,4 @@
 /*
- * jQuery File Upload Plugin 5.2
+ * jQuery File Upload Plugin 5.10.1
  * https://github.com/blueimp/jQuery-File-Upload
  *
@@ -7,23 +7,41 @@
  *
  * Licensed under the MIT license:
- * http://creativecommons.org/licenses/MIT/
+ * http://www.opensource.org/licenses/MIT
  */
 
 /*jslint nomen: true, unparam: true, regexp: true */
-/*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */
-
-(function ($) {
+/*global define, window, document, Blob, FormData, location */
+
+(function (factory) {
     'use strict';
-
-    // The fileupload widget listens for change events on file input fields
-    // defined via fileInput setting and drop events of the given dropZone.
+    if (typeof define === 'function' && define.amd) {
+        // Register as an anonymous AMD module:
+        define([
+            'jquery',
+            'jquery.ui.widget'
+        ], factory);
+    } else {
+        // Browser globals:
+        factory(window.jQuery);
+    }
+}(function ($) {
+    'use strict';
+
+    // The FileReader API is not actually used, but works as feature detection,
+    // as e.g. Safari supports XHR file uploads via the FormData API,
+    // but not non-multipart XHR file uploads:
+    $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
+    $.support.xhrFormDataFileUpload = !!window.FormData;
+
+    // The fileupload widget listens for change events on file input fields defined
+    // via fileInput setting and paste or drop events of the given dropZone.
     // In addition to the default jQuery Widget methods, the fileupload widget
-    // exposes the "add" and "send" methods, to add or directly send files
-    // using the fileupload API.
-    // By default, files added via file input selection, drag & drop or
+    // exposes the "add" and "send" methods, to add or directly send files using
+    // the fileupload API.
+    // By default, files added via file input selection, paste, drag & drop or
     // "add" method are uploaded immediately, but it is possible to override
     // the "add" callback option to queue file uploads.
     $.widget('blueimp.fileupload', {
-        
+
         options: {
             // The namespace used for event handler binding on the dropZone and
@@ -46,5 +64,6 @@
             // The parameter name for the file form data (the request argument name).
             // If undefined or empty, the name property of the file input field is
-            // used, or "files[]" if the file input name property is also empty:
+            // used, or "files[]" if the file input name property is also empty,
+            // can be a string or an array of strings:
             paramName: undefined,
             // By default, each file of a selection is uploaded using an individual
@@ -63,4 +82,13 @@
             // Set the following option to true to force iframe transport uploads:
             forceIframeTransport: false,
+            // Set the following option to the location of a redirect url on the
+            // origin server, for cross-domain iframe transport uploads:
+            redirect: undefined,
+            // The parameter name for the redirect url, sent as part of the form
+            // data and set to 'redirect' if this option is empty:
+            redirectParamName: undefined,
+            // Set the following option to the location of a postMessage window,
+            // to enable postMessage transport uploads:
+            postMessage: undefined,
             // By default, XHR file uploads are sent as multipart/form-data.
             // The iframe transport is always using multipart/form-data.
@@ -82,5 +110,5 @@
             // prevent recalculating the global progress data:
             recalculateProgress: true,
-            
+
             // Additional form data to be sent along with the file uploads can be set
             // using this option, which accepts an array of objects with name and
@@ -91,7 +119,7 @@
                 return form.serializeArray();
             },
-            
+
             // The add callback is invoked as soon as files are added to the fileupload
-            // widget (via file input selection, drag & drop or add API call).
+            // widget (via file input selection, drag & drop, paste or add API call).
             // If the singleFileUploads option is enabled, this callback will be
             // called once for each file in the selection for XHR file uplaods, else
@@ -108,6 +136,8 @@
                 data.submit();
             },
-            
+
             // Other callbacks:
+            // Callback for the submit event of each file upload:
+            // submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
             // Callback for the start of each file upload request:
             // send: function (e, data) {}, // .bind('fileuploadsend', func);
@@ -128,9 +158,11 @@
             // Callback for change events of the fileInput collection:
             // change: function (e, data) {}, // .bind('fileuploadchange', func);
+            // Callback for paste events to the dropZone collection:
+            // paste: function (e, data) {}, // .bind('fileuploadpaste', func);
             // Callback for drop events of the dropZone collection:
             // drop: function (e, data) {}, // .bind('fileuploaddrop', func);
             // Callback for dragover events of the dropZone collection:
             // dragover: function (e) {}, // .bind('fileuploaddragover', func);
-            
+
             // The plugin options are used as settings object for the ajax calls.
             // The following are jQuery ajax settings required for the file uploads:
@@ -139,13 +171,18 @@
             cache: false
         },
-        
+
         // A list of options that require a refresh after assigning a new value:
-        _refreshOptionsList: ['namespace', 'dropZone', 'fileInput'],
+        _refreshOptionsList: [
+            'namespace',
+            'dropZone',
+            'fileInput',
+            'multipart',
+            'forceIframeTransport'
+        ],
 
         _isXHRUpload: function (options) {
-            var undef = 'undefined';
             return !options.forceIframeTransport &&
-                typeof XMLHttpRequestUpload !== undef && typeof File !== undef &&
-                (!options.multipart || typeof FormData !== undef);
+                ((!options.multipart && $.support.xhrFileUpload) ||
+                $.support.xhrFormDataFileUpload);
         },
 
@@ -204,8 +241,13 @@
             // Accesss to the native XHR object is required to add event listeners
             // for the upload progress event:
-            if (xhr.upload && xhr.upload.addEventListener) {
-                xhr.upload.addEventListener('progress', function (e) {
+            if (xhr.upload) {
+                $(xhr.upload).bind('progress', function (e) {
+                    var oe = e.originalEvent;
+                    // Make sure the progress event properties get copied over:
+                    e.lengthComputable = oe.lengthComputable;
+                    e.loaded = oe.loaded;
+                    e.total = oe.total;
                     that._onProgress(e, options);
-                }, false);
+                });
                 options.xhr = function () {
                     return xhr;
@@ -216,6 +258,9 @@
         _initXHRData: function (options) {
             var formData,
-                file = options.files[0];
-            if (!options.multipart || options.blob) {
+                file = options.files[0],
+                // Ignore non-multipart setting if not supported:
+                multipart = options.multipart || !$.support.xhrFileUpload,
+                paramName = options.paramName[0];
+            if (!multipart || options.blob) {
                 // For non-multipart uploads and chunked uploads,
                 // file meta data is not part of the request body,
@@ -233,5 +278,5 @@
                     options.contentType = file.type;
                     options.data = file;
-                } else if (!options.multipart) {
+                } else if (!multipart) {
                     // Chunked non-multipart upload:
                     options.contentType = 'application/octet-stream';
@@ -239,24 +284,49 @@
                 }
             }
-            if (options.multipart && typeof FormData !== 'undefined') {
-                if (options.formData instanceof FormData) {
-                    formData = options.formData;
+            if (multipart && $.support.xhrFormDataFileUpload) {
+                if (options.postMessage) {
+                    // window.postMessage does not allow sending FormData
+                    // objects, so we just add the File/Blob objects to
+                    // the formData array and let the postMessage window
+                    // create the FormData object out of this array:
+                    formData = this._getFormData(options);
+                    if (options.blob) {
+                        formData.push({
+                            name: paramName,
+                            value: options.blob
+                        });
+                    } else {
+                        $.each(options.files, function (index, file) {
+                            formData.push({
+                                name: options.paramName[index] || paramName,
+                                value: file
+                            });
+                        });
+                    }
                 } else {
-                    formData = new FormData();
-                    $.each(this._getFormData(options), function (index, field) {
-                        formData.append(field.name, field.value);
-                    });
-                }
-                if (options.blob) {
-                    formData.append(options.paramName, options.blob);
-                } else {
-                    $.each(options.files, function (index, file) {
-                        // File objects are also Blob instances.
-                        // This check allows the tests to run with
-                        // dummy objects:
-                        if (file instanceof Blob) {
-                            formData.append(options.paramName, file);
-                        }
-                    });
+                    if (options.formData instanceof FormData) {
+                        formData = options.formData;
+                    } else {
+                        formData = new FormData();
+                        $.each(this._getFormData(options), function (index, field) {
+                            formData.append(field.name, field.value);
+                        });
+                    }
+                    if (options.blob) {
+                        formData.append(paramName, options.blob, file.name);
+                    } else {
+                        $.each(options.files, function (index, file) {
+                            // File objects are also Blob instances.
+                            // This check allows the tests to run with
+                            // dummy objects:
+                            if (file instanceof Blob) {
+                                formData.append(
+                                    options.paramName[index] || paramName,
+                                    file,
+                                    file.name
+                                );
+                            }
+                        });
+                    }
                 }
                 options.data = formData;
@@ -265,5 +335,5 @@
             options.blob = null;
         },
-        
+
         _initIframeSettings: function (options) {
             // Setting the dataType to iframe enables the iframe transport:
@@ -271,6 +341,14 @@
             // The iframe transport accepts a serialized array as form data:
             options.formData = this._getFormData(options);
-        },
-        
+            // Add redirect url to form data on cross-domain uploads:
+            if (options.redirect && $('<a></a>').prop('href', options.url)
+                    .prop('host') !== location.host) {
+                options.formData.push({
+                    name: options.redirectParamName || 'redirect',
+                    value: options.redirect
+                });
+            }
+        },
+
         _initDataSettings: function (options) {
             if (this._isXHRUpload(options)) {
@@ -281,9 +359,37 @@
                     this._initProgressListener(options);
                 }
+                if (options.postMessage) {
+                    // Setting the dataType to postmessage enables the
+                    // postMessage transport:
+                    options.dataType = 'postmessage ' + (options.dataType || '');
+                }
             } else {
-                this._initIframeSettings(options);
-            }
-        },
-        
+                this._initIframeSettings(options, 'iframe');
+            }
+        },
+
+        _getParamName: function (options) {
+            var fileInput = $(options.fileInput),
+                paramName = options.paramName;
+            if (!paramName) {
+                paramName = [];
+                fileInput.each(function () {
+                    var input = $(this),
+                        name = input.prop('name') || 'files[]',
+                        i = (input.prop('files') || [1]).length;
+                    while (i) {
+                        paramName.push(name);
+                        i -= 1;
+                    }
+                });
+                if (!paramName.length) {
+                    paramName = [fileInput.prop('name') || 'files[]'];
+                }
+            } else if (!$.isArray(paramName)) {
+                paramName = [paramName];
+            }
+            return paramName;
+        },
+
         _initFormSettings: function (options) {
             // Retrieve missing options from the input field and the
@@ -292,8 +398,5 @@
                 options.form = $(options.fileInput.prop('form'));
             }
-            if (!options.paramName) {
-                options.paramName = options.fileInput.prop('name') ||
-                    'files[]';
-            }
+            options.paramName = this._getParamName(options);
             if (!options.url) {
                 options.url = options.form.prop('action') || location.href;
@@ -306,5 +409,5 @@
             }
         },
-        
+
         _getAJAXSettings: function (data) {
             var options = $.extend({}, this.options, data);
@@ -365,5 +468,9 @@
             if (ub >= fs) {
                 file.error = 'uploadedBytes';
-                return this._getXHRPromise(false);
+                return this._getXHRPromise(
+                    false,
+                    options.context,
+                    [null, 'error', file.error]
+                );
             }
             // n is the number of blobs to upload,
@@ -373,5 +480,5 @@
             upload = function (i) {
                 if (!i) {
-                    return that._getXHRPromise(true);
+                    return that._getXHRPromise(true, options.context);
                 }
                 // Upload the blobs in sequential order:
@@ -402,6 +509,6 @@
                                 }), o);
                             }
-                            options.uploadedBytes = o.uploadedBytes
-                                += o.chunkSize;
+                            options.uploadedBytes = o.uploadedBytes +=
+                                o.chunkSize;
                         });
                     return jqXHR;
@@ -459,10 +566,14 @@
         },
 
-        _onAlways: function (result, textStatus, jqXHR, errorThrown, options) {
+        _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
             this._active -= 1;
-            options.result = result;
             options.textStatus = textStatus;
-            options.jqXHR = jqXHR;
-            options.errorThrown = errorThrown;
+            if (jqXHRorError && jqXHRorError.always) {
+                options.jqXHR = jqXHRorError;
+                options.result = jqXHRorResult;
+            } else {
+                options.jqXHR = jqXHRorResult;
+                options.errorThrown = jqXHRorError;
+            }
             this._trigger('always', null, options);
             if (this._active === 0) {
@@ -492,11 +603,12 @@
                     }).fail(function (jqXHR, textStatus, errorThrown) {
                         that._onFail(jqXHR, textStatus, errorThrown, options);
-                    }).always(function (a1, a2, a3) {
+                    }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
                         that._sending -= 1;
-                        if (a3 && a3.done) {
-                            that._onAlways(a1, a2, a3, undefined, options);
-                        } else {
-                            that._onAlways(undefined, a2, a1, a3, options);
-                        }
+                        that._onAlways(
+                            jqXHRorResult,
+                            textStatus,
+                            jqXHRorError,
+                            options
+                        );
                         if (options.limitConcurrentUploads &&
                                 options.limitConcurrentUploads > that._sending) {
@@ -543,26 +655,43 @@
             return send();
         },
-        
+
         _onAdd: function (e, data) {
             var that = this,
                 result = true,
                 options = $.extend({}, this.options, data),
-                fileSet = data.files,
                 limit = options.limitMultiFileUploads,
+                paramName = this._getParamName(options),
+                paramNameSet,
+                paramNameSlice,
+                fileSet,
                 i;
             if (!(options.singleFileUploads || limit) ||
                     !this._isXHRUpload(options)) {
-                fileSet = [fileSet];
+                fileSet = [data.files];
+                paramNameSet = [paramName];
             } else if (!options.singleFileUploads && limit) {
                 fileSet = [];
+                paramNameSet = [];
                 for (i = 0; i < data.files.length; i += limit) {
                     fileSet.push(data.files.slice(i, i + limit));
-                }
-            }
-            $.each(fileSet, function (index, file) {
-                var files = $.isArray(file) ? file : [file],
-                    newData = $.extend({}, data, {files: files});
+                    paramNameSlice = paramName.slice(i, i + limit);
+                    if (!paramNameSlice.length) {
+                        paramNameSlice = paramName;
+                    }
+                    paramNameSet.push(paramNameSlice);
+                }
+            } else {
+                paramNameSet = paramName;
+            }
+            data.originalFiles = data.files;
+            $.each(fileSet || data.files, function (index, element) {
+                var newData = $.extend({}, data);
+                newData.files = fileSet ? element : [element];
+                newData.paramName = paramNameSet[index];
                 newData.submit = function () {
-                    return that._onSend(e, newData);
+                    newData.jqXHR = this.jqXHR =
+                        (that._trigger('submit', e, this) !== false) &&
+                        that._onSend(e, this);
+                    return this.jqXHR;
                 };
                 return (result = that._trigger('add', e, newData));
@@ -570,5 +699,5 @@
             return result;
         },
-        
+
         // File Normalization for Gecko 1.9.1 (Firefox 3.5) support:
         _normalizeFile: function (index, file) {
@@ -585,4 +714,6 @@
             // without loosing the file input value:
             input.after(inputClone).detach();
+            // Avoid memory leaks with the detached file input:
+            $.cleanData(input.unbind('remove'));
             // Replace the original file input element in the fileInput
             // collection with the clone, which has been copied including
@@ -594,6 +725,11 @@
                 return el;
             });
-        },
-        
+            // If the widget has been initialized on the file input itself,
+            // override this.element with the file input clone:
+            if (input[0] === this.element[0]) {
+                this.element = inputClone;
+            }
+        },
+
         _onChange: function (e) {
             var that = e.data.fileupload,
@@ -609,11 +745,4 @@
                 data.files = [{name: e.target.value.replace(/^.*\\/, '')}];
             }
-            // Store the form reference as jQuery data for other event handlers,
-            // as the form property is not available after replacing the file input: 
-            if (data.form.length) {
-                data.fileInput.data('blueimp.fileupload.form', data.form);
-            } else {
-                data.form = data.fileInput.data('blueimp.fileupload.form');
-            }
             if (that.options.replaceFileInput) {
                 that._replaceFileInput(data.fileInput);
@@ -624,5 +753,22 @@
             }
         },
-        
+
+        _onPaste: function (e) {
+            var that = e.data.fileupload,
+                cbd = e.originalEvent.clipboardData,
+                items = (cbd && cbd.items) || [],
+                data = {files: []};
+            $.each(items, function (index, item) {
+                var file = item.getAsFile && item.getAsFile();
+                if (file) {
+                    data.files.push(file);
+                }
+            });
+            if (that._trigger('paste', e, data) === false ||
+                    that._onAdd(e, data) === false) {
+                return false;
+            }
+        },
+
         _onDrop: function (e) {
             var that = e.data.fileupload,
@@ -640,5 +786,5 @@
             e.preventDefault();
         },
-        
+
         _onDragOver: function (e) {
             var that = e.data.fileupload,
@@ -652,10 +798,13 @@
             e.preventDefault();
         },
-        
+
         _initEventHandlers: function () {
-            var ns = this.options.namespace || this.name;
-            this.options.dropZone
-                .bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
-                .bind('drop.' + ns, {fileupload: this}, this._onDrop);
+            var ns = this.options.namespace;
+            if (this._isXHRUpload(this.options)) {
+                this.options.dropZone
+                    .bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
+                    .bind('drop.' + ns, {fileupload: this}, this._onDrop)
+                    .bind('paste.' + ns, {fileupload: this}, this._onPaste);
+            }
             this.options.fileInput
                 .bind('change.' + ns, {fileupload: this}, this._onChange);
@@ -663,49 +812,44 @@
 
         _destroyEventHandlers: function () {
-            var ns = this.options.namespace || this.name;
+            var ns = this.options.namespace;
             this.options.dropZone
                 .unbind('dragover.' + ns, this._onDragOver)
-                .unbind('drop.' + ns, this._onDrop);
+                .unbind('drop.' + ns, this._onDrop)
+                .unbind('paste.' + ns, this._onPaste);
             this.options.fileInput
                 .unbind('change.' + ns, this._onChange);
         },
-        
-        _beforeSetOption: function (key, value) {
-            this._destroyEventHandlers();
-        },
-        
-        _afterSetOption: function (key, value) {
-            var options = this.options;
-            if (!options.fileInput) {
-                options.fileInput = $();
-            }
-            if (!options.dropZone) {
-                options.dropZone = $();
-            }
-            this._initEventHandlers();
-        },
-        
+
         _setOption: function (key, value) {
             var refresh = $.inArray(key, this._refreshOptionsList) !== -1;
             if (refresh) {
-                this._beforeSetOption(key, value);
+                this._destroyEventHandlers();
             }
             $.Widget.prototype._setOption.call(this, key, value);
             if (refresh) {
-                this._afterSetOption(key, value);
-            }
-        },
-
-        _create: function () {
+                this._initSpecialOptions();
+                this._initEventHandlers();
+            }
+        },
+
+        _initSpecialOptions: function () {
             var options = this.options;
             if (options.fileInput === undefined) {
                 options.fileInput = this.element.is('input:file') ?
-                    this.element : this.element.find('input:file');
-            } else if (!options.fileInput) {
-                options.fileInput = $();
-            }
-            if (!options.dropZone) {
-                options.dropZone = $();
-            }
+                        this.element : this.element.find('input:file');
+            } else if (!(options.fileInput instanceof $)) {
+                options.fileInput = $(options.fileInput);
+            }
+            if (!(options.dropZone instanceof $)) {
+                options.dropZone = $(options.dropZone);
+            }
+        },
+
+        _create: function () {
+            var options = this.options;
+            // Initialize options set via HTML5 data-attributes:
+            $.extend(options, $(this.element[0].cloneNode(false)).data());
+            options.namespace = options.namespace || this.widgetName;
+            this._initSpecialOptions();
             this._slots = [];
             this._sequence = this._getXHRPromise(true);
@@ -713,5 +857,5 @@
             this._initEventHandlers();
         },
-        
+
         destroy: function () {
             this._destroyEventHandlers();
@@ -723,5 +867,5 @@
             this._initEventHandlers();
         },
-        
+
         disable: function () {
             this._destroyEventHandlers();
@@ -740,5 +884,5 @@
             this._onAdd(null, data);
         },
-        
+
         // This method is exposed to the widget API and allows sending files
         // using the fileupload API. The data parameter accepts an object which
@@ -755,6 +899,6 @@
             return this._getXHRPromise(false, data && data.context);
         }
-        
+
     });
-    
-}(jQuery));
+
+}));
Index: /trunk/prototype/modules/mail/templates/attachment.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 6071)
+++ /trunk/prototype/modules/mail/templates/attachment.ejs	(revision 6107)
@@ -1,19 +1,18 @@
 <div id="fileupload_msg<%=data.ID%>" class="fileupload" style="margin : 15px 0px -15px -10px;">
-  <div class="row fileupload-buttonbar">
-      <div class="button-files-upload">
-	      <span class="button small btn-success fileinput-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button">
-		  <span class="ui-button-text" title="Clique para anexar um arquivo ou arraste diretamente o arquivo sobre este botão">
-		      <span><i class="icon-plus icon-white"></i>Anexar arquivos</span>
-		      <input type="file" name="files[]" multiple="">
-		  </span>
-	      </span> 
-      </div>	
-
-     <span tabindex="-1" class="message-attach-link button small ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"><span class="icon-plus ui-button-text">Anexar mensagens</span></span>
-    </div>
-     
-         <div class="files-list">
-            <ul class="attachments-list"></ul>
-         </div>
-        <br />
+	<div class="row fileupload-buttonbar">
+		<div class="button-files-upload">
+			<<%= is_webkit ? 'button' : 'span style="height: 22px;"' %>  class="fileinput-button button small">
+				<span style="margin-top: 4px;">Anexar arquivos</span>
+				<INPUT type="file" id="fileInput<%=data.ID%>" name="files[]" multiple style="cursor:pointer;"></INPUT>
+			</<%= is_webkit ? 'button' : 'span' %>>
+			<button class="message-attach-link button small">
+				<span>Anexar mensagens</span>
+			</button>
+		</div>
+	</div>
+	<br />
+	<div class="files-list" style="margin: 5px; padding: 5px;">
+		<ul class="attachments-list"></ul>
+	</div>
+	<br />
 </div>
Index: /trunk/prototype/modules/mail/templates/attachment_add_itemlist.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/attachment_add_itemlist.ejs	(revision 5767)
+++ /trunk/prototype/modules/mail/templates/attachment_add_itemlist.ejs	(revision 6107)
@@ -1,6 +1,7 @@
+<li style="list-style : none;">
 	<p class="input-group archive-info" style="margin: 0px 0 !important; height: 17px">		
 		<span title="<%=data.file.fullFileName%>" class="archive-attach name"><%=data.file.fileName%></span>
 		<span class="archive-attach size"><%=data.file.fileSize%></span>
-		<button type="button" class="button close tiny upload delete-upload" title="Deletar">Deletar</button>
+		<button type="button" style="margin-bottom: -4px;" class="button close tiny upload delete-upload" title="Deletar">Deletar</button>
 		<span class="status-upload"></span>
 		<%if(data.file.error){%>
@@ -14,2 +15,3 @@
 		
     </p>
+</li>
Index: /trunk/prototype/modules/mail/templates/new_message.ejs
===================================================================
--- /trunk/prototype/modules/mail/templates/new_message.ejs	(revision 6060)
+++ /trunk/prototype/modules/mail/templates/new_message.ejs	(revision 6107)
@@ -119,5 +119,5 @@
 				</td>
 				<td class="value">
-					<div id="message-attach-dialog" title="'<%=get_lang("Select messages to attach...")%>" style="clear: both;")>&nbsp;</div>
+					<div id="message-attach-dialog" title="'<%=get_lang("Select messages to attach...")%>" style="clear: both; display:none;")>&nbsp;</div>
 				</td>
 			</tr>
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 6106)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 6107)
@@ -1701,9 +1701,9 @@
 				headers_msgs.followupflagged.id = DataLayer.put('followupflagged', headers_msgs.followupflagged);
 				DataLayer.commit(false, false, function(data){
-				var fail = false;
+					var fail = false;
 					$.each(data, function(index, value) {
-						fail = false;
-						if(typeof value != 'object' || !(value['id'])){
+						if(typeof value != 'object'){
 							fail = true;
+							alert(value);
 						}
 					});
@@ -1720,5 +1720,4 @@
 						$('#td_message_followup_' + messageClickedId + ', ' + 
 						'tr[role="'+messageClickedId+'_'+msg_folder+'"] #td_message_followup_search_' + messageClickedId).find(".flag-edited").css("background", "#CCCCCC");
-						alert("Não foi possível sinalizar esta mensagem. \nDetalhes do erro: mensagem não contém o atributo message-id.");
 					}
 				});
@@ -3017,5 +3016,5 @@
 		//TODO Mudar quando API abstrair atualizações no cache
 		DataLayer.remove('labeled', false);
-		//DataLayer.get('labeled');
+		DataLayer.get('labeled');
 		var labels = DataLayer.get("labeled", {filter: [
 				'AND',
@@ -3044,6 +3043,6 @@
 				var id_labeled = $(event.target).attr("id");
 				//TODO Mudar quando API abstrair atualizações no cache
-				//DataLayer.remove('labeled', false);
-				//DataLayer.get('labeled');
+				DataLayer.remove('labeled', false);
+				DataLayer.get('labeled');
 				DataLayer.remove('labeled', id_labeled);
 				DataLayer.commit(false, false, function(){
@@ -3678,11 +3677,17 @@
 	var fileUploadMSG = $('#fileupload_msg'+ID);
 	var maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
-
-	fileUploadMSG.find(".button-files-upload").fileupload({
+	
+	fileUploadMSG.find(".button").button().filter(".fileinput-button").find("input:file").fileupload({
+		//singleFileUploads : true,
+		sequentialUploads: true, 
 		type: 'post',
 		dataType : 'json',
 		url: "../prototype/post.php",
-		forceIframeTransport: true,
+		forceIframeTransport: false,
+		dropZone : fileUploadMSG,
 		formData: function(form) {
+			$.each(this.files, function(index, value){
+				
+			}); 
 			return [
 				{
@@ -3699,48 +3704,50 @@
 				}
 			];
-		},
+		},	
 		add: function (e, data) {
-			
 			if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
 				setTimeout(function() {
                     $('#attDisposition'+ID).val('attachment');
 					if(!data.fileInput){
-						$(fileUploadMSG).find("input")[0].files = data.files;
-						data['fileInput'] = $(fileUploadMSG).find("input");
+						data.fileInput = fileUploadMSG.find("input:file");
+						
+						//fileUploadMSG.find("input:file").trigger("change.undefined");
 					}
-					if(!data.form)
-						data['form'] = fileUploadMSG.parents("form:first");
 					data.submit();
 				}, 3000);
-			}		
-			var attach = {};
-			attach.fullFileName = data.files[0].name;
-			attach.fileName = data.files[0].name;
-			if(data.files[0].name.length > 50)
-				attach.fileName = data.files[0].name.substr(0, 32) + " ... " + data.files[0].name.substr(data.files[0].name.length-9, data.files[0].name.length);
-			attach.fileSize = formatBytes(data.files[0].size);
-			data.files[0].size = 300;
-			if(maxAttachmentSize && data.files[0].size > maxAttachmentSize)
-				attach.error = 'Tamanho de arquivo nao permitido!!!'
-
-			var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));				
-			upload.find('.button.close').button({
-				icons: {
-					primary: "ui-icon-close"
-				},
-				text: false
-			}).click(function(){
-				var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
-				fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]').remove();
-				delAttachment(ID, idAttach)
-				$(this).parent().remove();
+			}
+			$.each(data.files, function (index, file) {
+				var attach = {};
+				attach.fullFileName = file.name;
+				attach.fileName = file.name;
+				if(file.name.length > 50)
+					attach.fileName = file.name.substr(0, 32) + " ... " + file.name.substr(file.name.length-9, file.name.length);
+				attach.fileSize = formatBytes(file.size);
+				if(maxAttachmentSize && file.size > maxAttachmentSize)
+					attach.error = 'Tamanho de arquivo nao permitido!!'
+				
+                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));				
+				upload.find('.button.close').button({
+					icons: {
+						primary: "ui-icon-close"
+					},
+					text: false
+				}).click(function(){
+					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+					fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]').remove();
+                                        delAttachment(ID, idAttach)
+					$(this).parent().remove();
+				});
+                                
+                                fileUploadMSG.find('.attachments-list').append(upload);
+
+				if(!maxAttachmentSize || file.size < maxAttachmentSize){
+					if(data.fileInput){
+						fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
+						fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
+					}
+				}else
+					fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
 			});
-
-			fileUploadMSG.find('.attachments-list').append(upload);
-
-			if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize)
-			    fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
-			else
-			    fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
 		},
 		done: function(e, data){
@@ -3764,6 +3771,163 @@
             fileUploadMSG.find(' .in-progress:first').remove();
 		}
-	}).find('[name="files[]"]').css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "-moz-transform" : "none","-o-transform" : 'none'});
-
+	}).css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "-moz-transform" : "none","-o-transform" : 'none'})
+	.end().end().filter(".message-attach-link").click(function(){
+		jQuery('#message-attach-dialog').html(DataLayer.render("../prototype/modules/attach_message/attach_message.ejs", {}));
+		$( "#mailpreview_container span.ui-icon-close" ).click();
+		jQuery('#message-attach-dialog').dialog({
+			width:920,
+			height:550,
+			resizable:false,
+			modal: true,
+			closeOnEscape:true,
+			close:function(event, ui) {event.stopPropagation(); },
+			autoOpen:false
+		});
+		
+		
+		jQuery.getScript("../prototype/modules/attach_message/attach_message.js", function(){
+			jQuery('#message-attach-dialog').dialog('open');
+			jQuery('#message-attach-attach-btn').unbind('click');
+			jQuery('#message-attach-attach-btn').click(function(event){
+				jQuery.each(selectedMessages, function(folder_name, messages) {
+					jQuery.each(selectedMessages[folder_name], function(message_number, message) { 
+						if (message) {
+							var att = new Object();
+							att.folder = folder_name;
+							att.uid = message_number;
+							att.type = 'imapMSG';
+							att.name = onceOpenedMessages[folder_name][message_number].subject + '.eml';
+							var idATT = JSON.stringify(att);
+							addAttachment( ID , idATT);                        
+							var attach = {};
+							attach.fileName = att.name
+							if(attach.fileName.length > 45)
+									attach.fileName = attach.fileName.substr(0, 32) + " ... " + attach.fileName.substr(attach.fileName.length-9, attach.fileName.length);
+
+							attach.fileSize = formatBytes(onceOpenedMessages[folder_name][message_number].size);
+							var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
+							upload.find('.status-upload').addClass('ui-icon ui-icon-check');
+							upload.find('.in-progress').remove(); 
+							upload.append('<input type="hidden" name="fileId[]" value=\''+idATT+'\'/>');
+							
+							upload.find('.button.close').button({
+								icons: {
+												primary: "ui-icon-close"
+										},
+										text: false
+								}).click(function(){
+										var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+										fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]');
+										delAttachment(ID,idAttach); 
+										$(this).parent().remove();
+							});	
+							
+							fileUploadMSG.find('.attachments-list').append(upload);   
+						}
+					});
+				});
+				
+				jQuery('#message-attach-dialog').dialog('close');
+				
+			});
+			jQuery('#message-attach-cancel-btn').click(function(event){
+				jQuery('#message-attach-dialog').dialog('close');
+			});			
+		});
+	});
+	/*
+	content.find('[name="files[]"]').fileupload({
+		sequentialUploads: true, 
+		limitConcurrentUploads: 1,
+		type: 'post',
+		dataType : 'json',
+		url: "../prototype/post.php",
+		forceIframeTransport: true,
+		dropZone : fileUploadMSG.find(".button").filter(".fileinput-button"),
+		formData: function(form) {
+			return [
+				{
+					name : "mailAttachment[0][source]",
+					value : "files0"
+				},
+				{
+					name : "mailAttachment[0][disposition]",
+					value : $(form[0]['attDisposition'+$(form[0]['abaID']).val()]).val()
+				},
+				{
+					name: "MAX_FILE_SIZE",
+					value : maxAttachmentSize
+				}
+			];
+		},		
+		add: function (e, data) {
+			if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
+				setTimeout(function() {
+                    $('#attDisposition'+ID).val('attachment');
+					if(!data.fileInput){
+						data.fileInput = fileUploadMSG.find("input:file");
+						
+						//fileUploadMSG.find("input:file").trigger("change.undefined");
+					}
+					data.submit();
+				}, 3000);
+			}
+		},
+		done: function(e, data){
+			if(!!data.result && data.result != "[]" ){
+				var newAttach = data.result;                             
+				if(!newAttach.mailAttachment.error){
+					if(newAttach.rollback !== false)
+					{
+						fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check');
+						addAttachment(ID,newAttach['mailAttachment'][0][0].id);
+					}
+					else                             
+						fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');   
+				}else{
+					fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append(newAttach.mailAttachment.error).addClass('message-attach-error');   
+				}
+                                
+			}else {
+				fileUploadMSG.find(' .progress.on-complete:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');
+			}
+            fileUploadMSG.find(' .in-progress:first').remove();
+		},
+		change: function (e, data) {
+			$.each(data.files, function (index, file) {
+				var attach = {};
+				attach.fullFileName = file.name;
+				attach.fileName = file.name;
+				if(file.name.length > 50)
+					attach.fileName = file.name.substr(0, 32) + " ... " + file.name.substr(file.name.length-9, file.name.length);
+				attach.fileSize = formatBytes(file.size);
+				if(maxAttachmentSize && file.size > maxAttachmentSize)
+					attach.error = 'Tamanho de arquivo nao permitido!!'
+				
+                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));				
+				upload.find('.button.close').button({
+					icons: {
+						primary: "ui-icon-close"
+					},
+					text: false
+				}).click(function(){
+					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
+					fileUploadMSG.find(' .attachments-list').find('input[value="'+idAttach+'"]').remove();
+                                        delAttachment(ID, idAttach)
+					$(this).parent().remove();
+				});
+                                
+                                fileUploadMSG.find('.attachments-list').append(upload);
+
+				if(!maxAttachmentSize || file.size < maxAttachmentSize){
+					fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
+					fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');	
+				}else
+					fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
+
+		})}
+	})
+	fileUploadMSG.find('[name="files[]"]').css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "-moz-transform" : "none","-o-transform" : 'none'});
+	//fileUploadMSG.unbind('dragover.undefined');
 		
        fileUploadMSG.find("span.message-attach-link").click(function(event){
@@ -3833,4 +3997,5 @@
 
 	});
+	*/
 //   style="width: 100px; height: 20px;"/   
 	//$('[name="files[]"]').css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "cursor" : "pointer"});// "display": "none"
