Index: branches/2.2/expressoMail1_2/js/main.js
===================================================================
--- branches/2.2/expressoMail1_2/js/main.js	(revision 4591)
+++ branches/2.2/expressoMail1_2/js/main.js	(revision 4596)
@@ -660,140 +660,195 @@
 }
 
-function move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,show_success_msg){
-	if (! folder || folder == 'null')
-		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : (openTab.imapBox[currentTab] ? openTab.imapBox[currentTab]:get_current_folder());
-	if(openTab.type[currentTab] == 1)
-		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
-
-	var handler_move_msgs = function(data){
-		if(typeof(data) == 'string')
-			if (data.match(/^(.*)TRYCREATE(.*)$/)){
-				connector.loadScript('TreeS');
-				var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : trashfolder;
-				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.', move_to_folder));
-				connector.loadScript('TreeShow');
-				ttree.FOLDER = 'root';
-				ttreeBox.new_past(move_to_folder);
-				return false;
-			}else{
-				alert(get_lang('Error moving message.')+":\n"+data);
-				return false;
-			}
-		//Este bloco verifica as permissoes ACL sobre pastas compartilhadas
-		if(data.status == false){
-			alert(get_lang("You don't have permission for this operation in this shared folder!"));
-			return false;
-		}
-		mail_msg = ( Element("divScrollMain_"+numBox) ) ? Element("divScrollMain_"+numBox).firstChild.firstChild : Element("divScrollMain_0").firstChild.firstChild;
-		if (data.msgs_number.length == 1)
-			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
-		else
-			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-
-		if (openTab.type[currentTab] > 1){
-			msg_to_delete = Element(msgs_number);
-			if (parseInt(preferences.delete_and_show_previous_message) && msg_to_delete)
-			{
-				if (msg_to_delete.previousSibling){
-					var previous_msg = msg_to_delete.previousSibling.id;
-					//cExecute("$this.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + current_folder, show_msg);
-					cExecute("$this.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(folder), show_msg);
-				}
-				else
-					delete_border(currentTab,'false');
-			}
-			else
-				delete_border(currentTab,'false');
-			if(msg_to_delete)
-				mail_msg.removeChild(msg_to_delete);
-
-			// Update Box BgColor
-			var box = Element("tbody_box");
-			if(box.childNodes.length > 0){
-				updateBoxBgColor(box.childNodes);
-			}
-			return;
-		}
-
-		Element('chk_box_select_all_messages').checked = false;
-		if (! mail_msg)
-				mail_msg = Element("tbody_box");
-		data.msgs_number = data.msgs_number.split(",");
-
-		var msg_to_delete;
-		if( typeof(msgs_number) == 'string' )
-			all_search_msg = msgs_number.split(',');
-		else if( typeof(msgs_number) == 'number')
-			all_search_msg = msgs_number;
-
-		for (var i=0; i <= all_search_msg.length; i++)
-		{
-			msg_to_delete = Element(folder+';'+all_search_msg[i]);
-			if (msg_to_delete)
-				msg_to_delete.parentNode.removeChild(msg_to_delete);
-		}
-
-		if ( preferences.use_shortcuts == '1') {
-			var all_messages = Element('tbody_box').childNodes;
-
-			//Last msg is selected
-			if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') ) {
-				select_msg('null', 'up', true);
-			}
-			else {
-				if (!select_msg('null', 'down', true)) {
-					select_msg('null', 'up', true);
-				}
-			}
-		}
-		for (var i=0; i<data.msgs_number.length; i++)
-		{
-			msg_to_delete = Element(data.msgs_number[i]);
-			if (msg_to_delete)
-				mail_msg.removeChild(msg_to_delete);
-		}
-
-
-		if (data.msgs_number.length == 1)
-			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
-		else
-			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-		if (data.border_ID.indexOf('r') != -1){
-			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder()){
-				delete_border(data.border_ID,'false');
-				show_msg(data.previous_msg);
-				}
-			else
-				delete_border(data.border_ID,'false');
-		}
-		if(folder == get_current_folder())
-			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
-
-		refresh();
-	}
-
-	if (folder == new_folder){
-		write_msg(get_lang('The origin folder and the destination folder are the same.'));
-		return;
-	}
-
-	if (msgs_number == 'selected'){
-		msgs_number = get_selected_messages();
-		}
-
-	if(openTab.type[currentTab] == 1){
-		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
-		}
-
-	if(currentTab.toString().indexOf("_r") != -1){
-		msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
-	}
-
-	if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
-		cExecute ("$this.imap_functions.move_messages&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message, handler_move_msgs);
-	else
-		write_msg(get_lang('No selected message.'));
-
-}
+function move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,show_success_msg)
+{
+    if (! folder || folder == 'null')
+        folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : (openTab.imapBox[currentTab] ? openTab.imapBox[currentTab]:get_current_folder());
+    if(openTab.type[currentTab] == 1)
+        return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
+
+    var handler_move_msgs = function(data)
+    {
+        if(typeof(data) == 'string')
+        {    
+            if (data.match(/^(.*)TRYCREATE(.*)$/))
+            {
+                connector.loadScript('TreeS');
+                var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : trashfolder;
+                alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.', move_to_folder));
+                connector.loadScript('TreeShow');
+                ttree.FOLDER = 'root';
+                ttreeBox.new_past(move_to_folder);
+                return false;
+            }
+            else
+            {
+                alert(get_lang('Error moving message.')+":\n"+data);
+                return false;
+            }
+        }
+        
+        //Este bloco verifica as permissoes ACL sobre pastas compartilhadas
+        if( data.status == false )
+        {
+            alert(get_lang("You don't have permission for this operation in this shared folder!"));
+            return false;
+        }
+        
+        mail_msg = ( Element("divScrollMain_"+numBox) ) ? Element("divScrollMain_"+numBox).firstChild.firstChild : Element("divScrollMain_0").firstChild.firstChild;
+        
+        if ( data.msgs_number.length == 1 )
+        {    
+            write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
+        }
+        else
+        {    
+            write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
+        }
+
+        if ( openTab.type[currentTab] > 1 )
+        {
+            msg_to_delete = Element( data.msgs_number );
+            
+            if ( parseInt(preferences.delete_and_show_previous_message) && msg_to_delete )
+            {
+                if ( msg_to_delete.previousSibling )
+                {
+                    var previous_msg = msg_to_delete.previousSibling.id;
+                    cExecute("$this.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(folder), show_msg);
+                }
+                else
+                {    
+                    delete_border( data.border_ID, 'false' );
+                }
+            }
+            else
+            {    
+                delete_border( data.border_ID, 'false' );
+            }
+            
+            if( msg_to_delete != null )
+            {    
+                msg_to_delete.parentNode.removeChild( msg_to_delete );
+                //mail_msg.removeChild(msg_to_delete);
+            }
+            
+            if( data.border_ID.toString().indexOf("_r") > -1 )
+            {
+                var _msgSearch = data.border_ID.toString();
+                    _msgSearch = _msgSearch.substr(0, _msgSearch.indexOf("_r") );
+                
+                if( Element(_msgSearch) != null )
+                {
+                    Element(_msgSearch).parentNode.removeChild( Element(_msgSearch) );
+                }    
+            }    
+
+            // Update Box BgColor
+            if( Element("tbody_box") != null )
+            {
+                var box = Element("tbody_box");
+
+                if( box.childNodes.length > 0)
+                {
+                    updateBoxBgColor(box.childNodes);
+                }
+            }    
+        }
+        else
+        {
+            Element('chk_box_select_all_messages').checked = false;
+            if (! mail_msg)
+                mail_msg = Element("tbody_box");
+            data.msgs_number = data.msgs_number.split(",");
+
+            var msg_to_delete;
+            if( typeof(msgs_number) == 'string' )
+                all_search_msg = msgs_number.split(',');
+            else if( typeof(msgs_number) == 'number')
+                all_search_msg = msgs_number;
+
+            for (var i=0; i <= all_search_msg.length; i++)
+            {
+                msg_to_delete = Element(folder+';'+all_search_msg[i]);
+                if (msg_to_delete)
+                    msg_to_delete.parentNode.removeChild(msg_to_delete);
+            }
+
+            if ( preferences.use_shortcuts == '1') {
+                var all_messages = Element('tbody_box').childNodes;
+
+                //Last msg is selected
+                if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') ) {
+                    select_msg('null', 'up', true);
+                }
+                else {
+                    if (!select_msg('null', 'down', true)) {
+                        select_msg('null', 'up', true);
+                    }
+                }
+            }
+            for (var i=0; i<data.msgs_number.length; i++)
+            {
+                msg_to_delete = Element(data.msgs_number[i]);
+                if (msg_to_delete)
+                    mail_msg.removeChild(msg_to_delete);
+            }
+
+
+            if (data.msgs_number.length == 1)
+                write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
+            else
+                write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
+            if (data.border_ID.indexOf('r') != -1){
+                if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder()){
+                    delete_border(data.border_ID,'false');
+                    show_msg(data.previous_msg);
+                }
+                else
+                    delete_border(data.border_ID,'false');
+            }
+            if(folder == get_current_folder())
+                Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
+
+            refresh();
+        }   
+        
+    }// END VAR HANDLER_MOVE_MSG
+
+    if (msgs_number == 'selected')
+    {
+        msgs_number = get_selected_messages();
+    }
+
+    if(openTab.type[currentTab] == 1)
+    {
+        return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
+    }
+
+    if(currentTab.toString().indexOf("_r") != -1)
+    {
+        msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
+        border_ID   = currentTab.toString();
+    }
+
+    if( msgs_number.toString().indexOf("_s") != -1 )
+    {    
+        folder = Element(msgs_number).getAttribute("name");
+        msgs_number = msgs_number.toString().substr(0 ,msgs_number.toString().indexOf("_s") );
+    }
+    
+    if ( folder == new_folder )
+    {
+        write_msg(get_lang('The origin folder and the destination folder are the same.'));
+        return;
+    }
+
+    if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
+        cExecute ("$this.imap_functions.move_messages&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message, handler_move_msgs);
+    else
+        write_msg(get_lang('No selected message.'));
+
+}
+
 
 function move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name) {
