Index: branches/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- branches/2.2/expressoMail1_2/js/draw_api.js	(revision 4048)
+++ branches/2.2/expressoMail1_2/js/draw_api.js	(revision 4079)
@@ -559,5 +559,5 @@
   	if(current_page != 1) {
 	  	lnk_page = document.createElement("A");
-		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){ Element(\"border_id_0\").innerHTML = \"&nbsp;\" + lang_folder(data['folder']) + \"&nbsp;<font face='Verdana' size='1' color='#505050'>[<span id='new_m'>&nbsp;</span> / <span id='tot_m'></span>]</font>\"; current_folder = data['folder']; alternate_border(0); draw_box(data, get_current_folder());});");
+		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
   	}
   	else {
@@ -598,5 +598,5 @@
   			msg_range_begin = ((i*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
 			msg_range_end = (i*preferences.max_email_per_page);
-			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){Element(\"border_id_0\").innerHTML = \"&nbsp;\" + lang_folder(data['folder']) + \"&nbsp;<font face='Verdana' size='1' color='#505050'>[<span id='new_m'>&nbsp;</span> / <span id='tot_m'></span>]</font>\"; current_folder = data['folder']; alternate_border(0); draw_box(data, get_current_folder());});");
+			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
   		}
   		lnk_page.innerHTML = "&nbsp;...&nbsp;";
@@ -612,5 +612,5 @@
   		msg_range_begin = ((total_pages*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
 		msg_range_end = (total_pages*preferences.max_email_per_page);
-		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){Element(\"border_id_0\").innerHTML = \"&nbsp;\" + lang_folder(data['folder']) + \"&nbsp;<font face='Verdana' size='1' color='#505050'>[<span id='new_m'>&nbsp;</span> / <span id='tot_m'></span>]</font>\"; current_folder = data['folder']; alternate_border(0); draw_box(data, get_current_folder());});");
+		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
 	}
 	else {
@@ -627,4 +627,31 @@
 // Draw the inbox and another folders
 function draw_box(headers_msgs, msg_folder, alternate){
+	
+	/* 
+	 * When the paging response is not in the correct folder you need to change folder
+	 * This occurs when the Ajax response is not fast enough and the user click in outher 
+	 * folder before finishing the Ajax request
+	 */
+	if (msg_folder != headers_msgs['folder']) {	
+		
+		if (headers_msgs['folder']) {
+			array_folder = headers_msgs['folder'].split('/');
+			
+			if (array_folder.length > 1) {
+				name_folder = array_folder[1];
+			}
+			else {
+				name_folder = headers_msgs['folder'];
+			}
+			current_folder = headers_msgs['folder'];
+			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(name_folder) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+
+			Element('new_m').innerHTML = headers_msgs['tot_unseen'] ? '<font color="RED">'+headers_msgs['tot_unseen']+'</font>' : 0;
+			Element("tot_m").innerHTML = headers_msgs['num_msgs'];
+
+			tree_folders.getNodeById(headers_msgs['folder'])._select();
+		}
+	}
+	/* --- */
 	
 	if (alternate)
@@ -2218,5 +2245,9 @@
 		if(!expresso_offline)
 			var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
-		else
+		else			alternate_border(0);
+			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+			draw_box(data, folder, true);
+			draw_paging(data.num_msgs);
+			Element("tot_m").innerHTML = data.num_msgs;
 			var option_send_and_file='';
 	}
