Index: /trunk/library/ckeditor/plugins/expresso/plugin.js
===================================================================
--- /trunk/library/ckeditor/plugins/expresso/plugin.js	(revision 6074)
+++ /trunk/library/ckeditor/plugins/expresso/plugin.js	(revision 6410)
@@ -63,10 +63,10 @@
 		CKEDITOR.dialog.add( 'imgDialog', function( api )
 		{
-                        var ID = currentTab;
+            var ID = currentTab;
 			// CKEDITOR.dialog.definition
 			var dialogDefinition =
 			{
 				
-                                title : 'Inserir Imagem',
+                title : 'Inserir Imagem',
 				minWidth : 400,
 				minHeight : 70,
@@ -82,5 +82,5 @@
 							{
 								type : 'html',
-								html :  '<form id="fileupload_img'+ID+'" class="fileupload" action="mailAttachment:img" method="POST">    <input type="file" name="files[]" multiple="" onclick="bindFileUpload();" style="margin-left:10px"></form>' 
+								html :  '<form id="fileupload_img'+ID+'" class="fileupload" action="mailAttachment:img" method="POST">    <input type="file" name="files[]"  onclick="bindFileUpload(this);" style="margin-left:10px"></form>' 
 							}
 						]
@@ -100,6 +100,5 @@
 function bindFileUpload(e) {
 	var ID = currentTab;
-	var newImageId = new Date().getTime();
-	var fileUploadIMG = $('#fileupload_img'+ID);
+	var fileUploadIMG = $(e).parents('form');
 	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;
@@ -133,7 +132,5 @@
 				}, 5000);
 			}
-                        
-		},
-		change: function (e, data) {
+
 			$.each(data.files, function (index, file) {	
 				var attach = {};
@@ -146,15 +143,7 @@
 					attach.error = 'Tamanho de arquivo nao permitido!!'
 								
-				fileUploadMSG.find('.attachments-list').append(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
-
-				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(' .attachments-list').find('.button.close').button({
+				var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));	
+
+				upload.find('.button.close').button({
 					icons: {
 						primary: "ui-icon-close"
@@ -164,25 +153,36 @@
 					var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
 			
-                                        var content_body = RichTextEditor.getData('body_'+ID);
-                                        var imagens = content_body.match(/<img[^>]*>/g);
+                    var content_body = RichTextEditor.getData('body_'+ID);
+                    var imagens = content_body.match(/<img[^>]*>/g);
        
-                                        if(imagens != null)
-                                            for (var x = 0; x < imagens.length; x++)
-                                                if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1)
-                                                        content_body = content_body.replace(imagens[x],'');
+                    if(imagens != null)
+                        for (var x = 0; x < imagens.length; x++)
+                            if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1)
+                                content_body = content_body.replace(imagens[x],'');
          
-                                        RichTextEditor.setData('body_'+ID,content_body);   
+                    RichTextEditor.setData('body_'+ID,content_body);   
                                        	
-                                        $('.attachments-list').find('input[value="'+idAttach+'"]').remove();
-                                        delAttachment(ID, idAttach);
+                    $('.attachments-list').find('input[value="'+idAttach+'"]').remove();
+                    delAttachment(ID, idAttach);
 					$(this).parent().remove();
 				});
                                 
-                                CKEDITOR.instances['body_'+ID].insertHtml('<img id="'+newImageId+'" src=""/>');
-
-		});
+            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');
+				                                
+                CKEDITOR.instances['body_'+ID].insertHtml('<img src=""/>');
+
+			});
                 
-                    CKEDITOR.dialog.getCurrent().hide();
-                },
+            CKEDITOR.dialog.getCurrent().hide();	
+                        
+		},
 		done: function(e, data){
 			if(!!data.result && data.result != "[]"){
@@ -194,5 +194,5 @@
 						addAttachment(ID,newAttach['mailAttachment'][0][0].id);
 						var content_body  = RichTextEditor.getData('body_'+ID);
-						var rex = new RegExp('<img id="'+newImageId+'" src="" [^\/>]*\/>', 'i'); 
+						var rex = new RegExp('<img src="" [^\/>]*\/>', 'i'); 
 						var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />'; 
 						content_body = content_body.replace(rex,newImg); 
@@ -204,6 +204,7 @@
 					fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append(newAttach.mailAttachment.error).addClass('message-attach-error');   
 				}
-			}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('Erro ao fazer upload!').addClass('message-attach-error');   
 			}
 			fileUploadMSG.find('.in-progress:first').remove();
