Index: branches/2.2.0.1/expressoMail1_2/js/main.js
===================================================================
--- branches/2.2.0.1/expressoMail1_2/js/main.js	(revision 4683)
+++ branches/2.2.0.1/expressoMail1_2/js/main.js	(revision 4686)
@@ -616,5 +616,6 @@
 		}
 		connector.purgeCache();
-                refresh();
+
+		EsearchE.refresh();
 	}
 
Index: branches/2.2.0.1/expressoMail1_2/js/search.js
===================================================================
--- branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4680)
+++ branches/2.2.0.1/expressoMail1_2/js/search.js	(revision 4686)
@@ -374,6 +374,194 @@
 	}
 	
+	searchE.prototype.make_tr_message = function(aux,border_id,i) {
+		var tr = document.createElement("TR");
+		if(typeof(preferences.line_height) != 'undefined')
+			tr.style.height = preferences.line_height;
+
+		var mailbox = aux.boxname;
+		var uid_msg = aux.uid;
+		var subject = aux.subject;
+
+		tr.id = uid_msg+"_s"+numBox;
+
+		// Keep the two lines together please
+		tr.setAttribute('name',mailbox);
+		tr.name = mailbox;
+
+		if ( aux.flag.match("U") )
+			add_className(tr,'tr_msg_unread');
+
+		add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
+
+		var _onclick = function()
+		{
+			proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);
+		};
+
+		for(var j=0 ; j <= 10 ; j++)
+		{
+			var td = document.createElement("TD");
+			if (j == 0)
+			{
+				td.setAttribute("width", colSizes[1][0]);
+				var chk_onclick;
+				if (is_ie)
+					chk_onclick = "changeBgColor(window.event,"+uid_msg+");";
+				else
+					chk_onclick = "changeBgColor(event,"+uid_msg+");";
+				var td1 = '<input type="checkbox" onclick="' + chk_onclick + '" id="' + border_id + '_check_box_message_'+uid_msg+'"></input>';
+
+			}
+			if (j == 1)
+			{
+				td.setAttribute("width", colSizes[1][1]);
+				if (aux.flag.match('T'))
+				{
+					attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
+					td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
+				}
+				else
+					td1 = '';
+			}
+			if (j == 2)
+			{
+				td.setAttribute("width", colSizes[1][2]);
+				td.id = "td_message_answered_"+uid_msg;
+				if (aux.flag.match('X'))
+					td1 = '<img src=templates/'+template+'/images/forwarded.gif title="'+get_lang('Forwarded')+'">';
+				else
+					if (aux.flag.match('A'))
+						td1 = '<img src=templates/'+template+'/images/answered.gif title="'+get_lang('Answered')+'">';
+					else
+						td1 = '';
+			}
+			if (j == 3)
+			{
+				td.setAttribute("width", colSizes[1][3]);
+				td.id = "td_message_important_"+uid_msg;
+				if (aux.flag.match("F"))
+				{
+					add_className(tr, 'flagged_msg');
+					td1 = "<img src='templates/"+template+"/images/important.gif' title='"+get_lang('Flagged')+"'>";
+				}
+				else
+					td1 = '';
+			}
+			if (j == 4)
+			{
+				td.setAttribute("width", colSizes[1][4]);
+				td.id = "td_message_sent_"+uid_msg;
+				td1 = '';
+			}
+
+			if ( j == 5 )
+			{
+				td.setAttribute("width", colSizes[1][5]);
+				td.className = "td_resizable";
+				td.onclick = _onclick;
+				var nm_box = aux.boxname.split(cyrus_delimiter);
+				var td1 = nm_box.pop();
+				td.setAttribute("NoWrap","true");
+				td.style.overflow = "hidden";
+				td.style.color = "#42795b";
+				td.style.fontWeight = "bold";
+
+				var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
+
+									td1 = translateFolder(td1);
+
+
+				if( proxy_mensagens.is_local_folder(td1))
+				{
+					var td1 = this.aux_local_folder_display(td1);
+				}
+			}
+
+			if( j == 6 )
+			{
+				if (aux.from.length > 29)
+					aux.from = aux.from.substr(0,29) + "...";
+
+				td.setAttribute("width", colSizes[1][6]);
+				td.className = "td_resizable";
+				td.onclick = _onclick;
+				td.setAttribute("NoWrap","true");
+									td.style.overflow = "hidden";
+				var td1  =  '<div style="width:100%;overflow:hidden">'+aux.from+"</div>";
+			}
+
+			if( j == 7 )
+			{
+				var subject_encode = url_encode(subject);
+
+				if (! subject_encode)
+					aux.subject = get_lang("no subject") + "...";
+				if (aux.subject.length > 70)
+					aux.subject = aux.subject.substr(0,70) + "...";
+
+				td.setAttribute("width", colSizes[1][7]);
+				td.className = "td_resizable";
+				td.onclick = _onclick;
+				td.setAttribute("NoWrap","true");
+				td.style.overflow = "hidden";
+
+				var td1  = aux.subject;
+			}
+
+			if( j == 8 )
+			{
+				td.setAttribute("width", colSizes[1][8]);
+				td.className = "td_resizable";
+				td.align		= "center";
+				td.onclick		= _onclick;
+
+				if( validate_date( aux.udate ) )
+				{
+					var td1 = aux.udate;
+				}
+				else
+				{
+					var dt	= new Date( aux.udate * 1000 );
+					var td1	 = dt.getDate() + "/";
+
+					if( !( dt.getMonth() + 1 ).toString().match(/\d{2}/) )
+						td1 += "0"+( dt.getMonth() + 1 ) + "/";
+					else
+						td1 += ( dt.getMonth() + 1 ) + "/";
+
+					td1 += dt.getFullYear();
+				}
+			}
+
+			if( j == 9 )
+			{
+				td.setAttribute("width", colSizes[1][9]);
+				td.className = "td_resizable";
+				td.align = "center";
+				td.onclick = _onclick;
+				var td1  = borkb(aux.size);
+			}
+
+			if( j == 10 )
+			{
+				if (aux.flag.match("U"))
+					add_className(tr, 'tr_msg_unread');
+				if (aux.flag.match("F"))
+					add_className(tr, 'flagged_msg');
+				var td1 = '';
+			}
+			if (j<10) {
+				td.innerHTML = td1;
+				tr.appendChild(td);
+			}
+		}
+
+		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
+
+		return tr;
+	}
+
 	// Form resultado
-	searchE.prototype.mount_result = function( Data, sort_type )
+	searchE.prototype.mount_result = function( Data, sort_type, keep_border )
 	{
 		var data = ( Data['data'] ) ? Data['data'] : Data['data_gears'];
@@ -389,12 +577,17 @@
 			sort_type = this.sort_type;
 
-		numBox++;
-
-		if( Data['data'] )
-			var border_id = create_border(get_lang("Server Results"), "search_" + numBox);
-		
-		if( Data['data_gears'])
-			var border_id = create_border(get_lang("Local Results"), "search_local_msg" + numBox);
-			
+		if ( keep_border ) {
+			var border_id = currentTab;
+		}
+		else {
+			numBox++;
+
+			if( Data['data'] )
+				var border_id = create_border(get_lang("Server Results"), "search_" + numBox);
+
+			if( Data['data_gears'])
+				var border_id = create_border(get_lang("Local Results"), "search_local_msg" + numBox);
+		}
+
 		if (!border_id)
             return;
@@ -403,5 +596,12 @@
         openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
         openTab.type[currentTab] = 1;
-        
+		openTab.condition[currentTab] = this.condition;
+
+		if ( keep_border ) {
+			var content_search =  Element('content_id_' + border_id);
+			var div_scroll_result = Element("divScrollMain_"+numBox);
+			content_search.removeChild(div_scroll_result);
+		}
+
 		var table = document.createElement("TABLE");
 			table.id    = "table_resultsearch_" + numBox;
@@ -417,188 +617,6 @@
 		for( var i=0; i < data.length; i++)
 		{
-			var tr = document.createElement("TR");
-			if(typeof(preferences.line_height) != 'undefined')
-				tr.style.height = preferences.line_height;
-			
-			var aux = data[i];
-			var mailbox = aux.boxname; 
-			var uid_msg = aux.uid; 
-			var subject = aux.subject; 
-			
-			tr.id = uid_msg+"_s"+numBox;
-
-			// Keep the two lines together please
-			tr.setAttribute('name',mailbox);
-			tr.name = mailbox;
-
-			if ( aux.flag.match("U") )
-				add_className(tr,'tr_msg_unread');
-			
-			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
-			
-			var _onclick = function()
-			{
-				proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);
-			};
-			
-            for(var j=0 ; j <= 10 ; j++)
-			{
-				var td = document.createElement("TD");
-				if (j == 0)
-				{
-					td.setAttribute("width", colSizes[1][0]);
-					var chk_onclick;
-					if (is_ie)
-						chk_onclick = "changeBgColor(window.event,"+uid_msg+");";
-					else
-						chk_onclick = "changeBgColor(event,"+uid_msg+");";
-					var td1 = '<input type="checkbox" onclick="' + chk_onclick + '" id="' + border_id + '_check_box_message_'+uid_msg+'"></input>';
-					
-				}
-				if (j == 1)
-				{
-					td.setAttribute("width", colSizes[1][1]);
-					if (aux.flag.match('T'))
-					{
-						attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
-						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
-					}
-					else
-						td1 = '';
-				}
-				if (j == 2)
-				{
-					td.setAttribute("width", colSizes[1][2]);
-					td.id = "td_message_answered_"+uid_msg;
-					if (aux.flag.match('X'))
-						td1 = '<img src=templates/'+template+'/images/forwarded.gif title="'+get_lang('Forwarded')+'">';
-					else
-						if (aux.flag.match('A'))
-							td1 = '<img src=templates/'+template+'/images/answered.gif title="'+get_lang('Answered')+'">';
-						else
-							td1 = '';
-				}
-				if (j == 3)
-				{
-					td.setAttribute("width", colSizes[1][3]);
-					td.id = "td_message_important_"+uid_msg;
-					if (aux.flag.match("F"))
-					{
-						add_className(tr, 'flagged_msg');
-						td1 = "<img src='templates/"+template+"/images/important.gif' title='"+get_lang('Flagged')+"'>";
-					}
-					else
-						td1 = '';
-				}
-				if (j == 4)
-				{
-					td.setAttribute("width", colSizes[1][4]);
-					td.id = "td_message_sent_"+uid_msg;
-					td1 = '';
-				}
-				
-				if ( j == 5 )
-				{
-					td.setAttribute("width", colSizes[1][5]);
-					td.className = "td_resizable";
-					td.onclick = _onclick;
-					var nm_box = aux.boxname.split(cyrus_delimiter);
-					var td1 = nm_box.pop();
-					td.setAttribute("NoWrap","true");
-					td.style.overflow = "hidden";
-					td.style.color = "#42795b";
-					td.style.fontWeight = "bold";
-					
-					var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
-                    
-                                        td1 = translateFolder(td1);
-                    
-
-					if( proxy_mensagens.is_local_folder(td1))
-					{
-						var td1 = this.aux_local_folder_display(td1);
-					}
-				}
-				
-				if( j == 6 )
-				{
-					if (aux.from.length > 29)
-						aux.from = aux.from.substr(0,29) + "...";
-					
-					td.setAttribute("width", colSizes[1][6]);
-					td.className = "td_resizable";
-					td.onclick = _onclick;
-					td.setAttribute("NoWrap","true");
-                                        td.style.overflow = "hidden";
-					var td1  =  '<div style="width:100%;overflow:hidden">'+aux.from+"</div>";
-				}
-				
-				if( j == 7 )
-				{
-					var subject_encode = url_encode(subject);
-					
-					if (! subject_encode)
-						aux.subject = get_lang("no subject") + "...";
-					if (aux.subject.length > 70)
-						aux.subject = aux.subject.substr(0,70) + "...";
-					
-					td.setAttribute("width", colSizes[1][7]);
-					td.className = "td_resizable";
-					td.onclick = _onclick;
-					td.setAttribute("NoWrap","true");
-                    td.style.overflow = "hidden";
-
-                    var td1  = aux.subject;
-				}
-				
-				if( j == 8 )
-				{
-					td.setAttribute("width", colSizes[1][8]);
-					td.className = "td_resizable";
-					td.align		= "center";
-					td.onclick		= _onclick;
-
-					if( validate_date( aux.udate ) )
-					{
-						var td1 = aux.udate;
-					}
-					else
-					{
-						var dt	= new Date( aux.udate * 1000 );
-	                    var td1	 = dt.getDate() + "/";
-	                    
-	                    if( !( dt.getMonth() + 1 ).toString().match(/\d{2}/) )
-	                    	td1 += "0"+( dt.getMonth() + 1 ) + "/";
-	                    else
-	                    	td1 += ( dt.getMonth() + 1 ) + "/";
-	                    
-	                    td1 += dt.getFullYear();
-					}
-				}
-
-				if( j == 9 )
-				{
-					td.setAttribute("width", colSizes[1][9]);
-					td.className = "td_resizable";
-					td.align = "center";
-					td.onclick = _onclick;
-					var td1  = borkb(aux.size);
-				}
-				
-				if( j == 10 )
-				{
-					if (aux.flag.match("U"))
-						add_className(tr, 'tr_msg_unread');
-					if (aux.flag.match("F"))
-						add_className(tr, 'flagged_msg');
-					var td1 = '';
-				}
-				if (j<10) {
-				td.innerHTML = td1;
-				tr.appendChild(td);
-			    }
-			}
-		
-            _dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
+			var tr = EsearchE.make_tr_message(data[i],border_id,i);
+
             tbody.appendChild(tr);
 		}
@@ -1270,4 +1288,40 @@
 	}
 
+	searchE.prototype.refresh = function(alert_new_msg){
+		var handler_refresh = function(data){
+			var allMsg 	= [3];
+			var count  	= ( data['num_msgs'] ) ?  data['num_msgs'] : "0";
+
+			if( data['num_msgs'] )
+			{
+				allMsg['data'] 		= data['data'];
+				allMsg['num_msgs']	= data['num_msgs'];
+			}
+
+			if( ( data['num_msgs'] ) == 0 )
+			{
+				alert( get_lang("None result was found.") );
+			}
+			else
+			{
+				if( data['num_msgs'] )
+				{
+					write_msg( count + " " + get_lang("results found") );
+					EsearchE.mount_result( allMsg, 'SORTDATE', true );
+				}
+			}
+		}
+
+		this.condition	= openTab.condition[currentTab];
+
+		var sort_type = (this.sort_type ? this.sort_type : 'SORTDATE');
+
+		if( expresso_offline )
+			handler('none');
+		else
+			cExecute( "$this.imap_functions.search_msg", handler_refresh, "condition="+openTab.condition[currentTab]+"&page="+EsearchE.page+"&sort_type="+sort_type);
+	}
+
+
 // Cria o objeto
 	var EsearchE;
Index: branches/2.2.0.1/expressoMail1_2/js/draw_api.js
===================================================================
--- branches/2.2.0.1/expressoMail1_2/js/draw_api.js	(revision 4683)
+++ branches/2.2.0.1/expressoMail1_2/js/draw_api.js	(revision 4686)
@@ -6,5 +6,6 @@
 	'imapBox' : [], // Stores the folder name
 	'toPreserve' : [], // Check if the message should be removed from draft after send
-	'autosave_timer' : [] // The timeout timer for autosave function
+	'autosave_timer' : [], // The timeout timer for autosave function
+	'condition' : [] // Will store the search condition if the tab is the result of a search
 };
 var tabTypes = {
