Index: branches/2.2/expressoMail1_2/js/search.js
===================================================================
--- branches/2.2/expressoMail1_2/js/search.js	(revision 3722)
+++ branches/2.2/expressoMail1_2/js/search.js	(revision 3802)
@@ -1,8 +1,11 @@
 /**************************************************************************\
- Início
+ Início 
 \**************************************************************************/
 	function searchE()
 	{
 		this.searchW   = new Array;
+		this.condition = "";
+		this.sort_type = "";
+		this.page = 0;
 		this.name_box_search = "";
 		this.all_boxes = new Array;
@@ -103,10 +106,5 @@
 
 	}
-
-        searchE.validate_date_field = function(date)
-        {
-
-        }
-
+	
 	//Form
 	searchE.prototype.mount_form = function(value){
@@ -211,192 +209,78 @@
 		ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
 	}
-
-	//This func returns the most recent date
-	function date_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data1 = data1[0].substr(0, data1[0].indexOf('--'))
-		with ( data1 )
-			data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data2 = data2[0].substr(0, data2[0].indexOf('--'))
-		with ( data2 )
-			data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		return data2 - data1;
-	}
-	
-	function date_comp_reverse(a,b)
-	{
-		return date_comp(b,a);
-	}
-
-	function box_comp(a,b)
-	{
-		var compare = [];
-			compare[0] = a.substr(0, a.indexOf('--'));
-			compare[0] = compare[0].toLowerCase();
-		
-		var temp=compare[0];
-			compare[1] = b.substr(0, b.indexOf('--'))
-			compare[1] = compare[1].toLowerCase();
-		
-		compare.sort();
-		
-		if (temp != compare[0])
-			return +1;
+	function openpage(data){
+		delete_border(currentTab,false);
+		EsearchE.mount_result(data);
+	}
+
+	searchE.prototype.show_paging = function(size){
+		if (size > preferences.max_email_per_page)
+		{
+			if (Element("span_paging"+currentTab)){
+				Element("span_paging"+currentTab).style.display = '';
+				Element("span_paging"+currentTab).innerHTML = "";
+			}
+			else{
+				var span_paging = document.createElement('SPAN');
+				span_paging.id = "span_paging"+currentTab;
+				Element("div_menu_c3").appendChild(span_paging);
+			}
+			if(this.page > 1){
+				var fLink = document.createElement('A');
+				fLink.innerHTML = '&lt; &lt;';
+				fLink.href = 'javascript:EsearchE.page=0;'+
+					'cExecute("$this.imap_functions.search_msg",openpage,'+
+					'"condition='+this.condition+'&sort_type='+this.sort_type+'&page=0");';
+				Element("span_paging"+currentTab).appendChild(fLink);
+			}
+			if(this.page > 2){
+				var prevLink = document.createElement('A');
+				prevLink.innerHTML = '...';
+				prevLink.href = 'javascript:EsearchE.page='+
+					(this.page-1)+';'+
+					'cExecute("$this.imap_functions.search_msg",openpage,'+
+					'"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+(this.page-1)+'");';
+				Element("span_paging"+currentTab).appendChild(prevLink);
+			}
+			for (var i=(this.page > 2 ? this.page-2 : 0); i <= parseInt(this.page)+4; i+= 1){
+				if (i*preferences.max_email_per_page > size)
+					break;
+				if (this.page == i)
+					Element("span_paging"+currentTab).innerHTML += "<b> "+(this.page+1)+" </b>";
+				else
+				{
+					var pageLink = document.createElement('A');
+					pageLink.innerHTML = (i+1)+" ";
+					pageLink.href = 'javascript:EsearchE.page='+i+';'+
+						'cExecute("$this.imap_functions.search_msg",openpage,'+
+						'"condition='+this.condition+'&sort_type='+this.sort_type+'&page='+this.page+'");';
+					Element("span_paging"+currentTab).appendChild(pageLink);
+				}
+			}
+			if (size > preferences.max_email_per_page)
+			{
+				var lLink = document.createElement('A');
+				lLink.innerHTML = '&gt; &gt;';
+				lLink.href = 'javascript:EsearchE.page='+parseInt(size/preferences.max_email_per_page)+';'+
+					'cExecute("$this.imap_functions.search_msg",openpage,'+
+					'"condition='+this.condition+'&sort_type='+this.sort_type+'&page=0");';
+				Element("span_paging"+currentTab).appendChild(lLink);
+			}
+		}
+
+	}
+	// Form resultado
+	searchE.prototype.mount_result = function(Rdata,sort_type){
+		var data = Rdata['data'];
+		if (data == undefined)
+			return;
+		if(this.page == 0)
+			write_msg(Rdata['num_msgs']+" "+get_lang("results found"));
+		var cont = parseInt(0);
+
+		if (typeof(sort_type) != 'undefined')
+			this.sort_type = sort_type;
 		else
-			return -1;
-	}
-	
-	function box_comp_reverse(a,b)
-	{
-		return box_comp(b,a);
-	}
-
-	function who_comp(a,b)
-	{
-		var compare = [];
-			compare[0] = a.substr(a.indexOf('--')+2);
-			compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
-			compare[0] = compare[0].toLowerCase();
-		
-		var temp = compare[0];
-			compare[1] = b.substr(b.indexOf('--')+2);
-			compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
-			compare[1] = compare[1].toLowerCase();
-		
-		compare.sort();
-		
-		if (temp != compare[0])
-			return +1;
-		else
-			return -1;
-	}
-	
-	function who_comp_reverse(a,b)
-	{
-		return who_comp(b,a);
-	}
-
-	function subject_comp(a,b)
-	{
-		var compare = [];
-			compare[0] = a.substr(a.indexOf('--')+2);
-			compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
-			compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
-			compare[0] = compare[0].toLowerCase();
-		var temp=compare[0];
-			compare[1] = b.substr(b.indexOf('--')+2);
-			compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
-			compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
-			compare[1] = compare[1].toLowerCase();
-		
-		compare.sort();
-		
-		if (temp != compare[0])
-			return +1;
-		else
-			return -1;
-	}
-	
-	function subject_comp_reverse(a,b)
-	{
-		return subject_comp(b,a);
-	}
-
-	function size_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-			data1 = data1[0].substr(data1[0].indexOf('--')+2)
-			data1 = data1.substr(0,data1.indexOf('--'))
-		var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
-		
-		if (data1.match("k"))
-			size_a = size_a * 1024;
-		else
-			if (data1.match("m"))
-				size_a = size_a * 1048576;
-		
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-			data2 = data2[0].substr(data2[0].indexOf('--')+2)
-			data2 = data2.substr(0,data2.indexOf('--'))
-		var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
-		
-		if (data2.match("k"))
-			size_b = size_b * 1024;
-		else
-			if (data2.match("m"))
-				size_b = size_b * 1048576;
-		return size_b - size_a;
-	}
-	
-	function size_comp_reverse(a,b)
-	{
-		return size_comp(b,a);
-	}
-
-	// Form resultado
-	searchE.prototype.mount_result = function( data, sort_type)
-	{
-		var nw_array = new Array;
-		var var_tmp = data.substr(2, data.length - 4);
-			var_tmp  = var_tmp.split("####");
-				
-		var cont = parseInt(0);
-		
-		switch (sort_type)
-		{
-			case 'SORTDATE':
-				var_tmp.sort(date_comp);
-				break;
-			case 'SORTDATE_REVERSE':
-				var_tmp.sort(date_comp_reverse);
-				break;
-			case 'SORTBOX':
-				var_tmp.sort(box_comp);
-				break;
-			case 'SORTBOX_REVERSE':
-				var_tmp.sort(box_comp_reverse);
-                break;
-			case 'SORTSUBJECT':
-				var_tmp.sort(subject_comp);
-				break;
-			case 'SORTSUBJECT_REVERSE':
-                                var_tmp.sort(subject_comp_reverse);
-				break;
-			case 'SORTWHO':
-				var_tmp.sort(who_comp);
-				break;
-			case 'SORTWHO_REVERSE':
-				var_tmp.sort(who_comp_reverse);
-				break;
-			case 'SORTSIZE':
-				var_tmp.sort(size_comp);
-				break;
-			case 'SORTSIZE_REVERSE':
-				var_tmp.sort(size_comp_reverse);
-				break;
-			default:
-				var showMsg = 1;
-		}
-
-		for(var i=0; i < var_tmp.length; i++)
-		{
-			if(var_tmp[i] != "")
-			{
-				nw_array[cont] = var_tmp[i];
-				cont++;
-			}
-		}
-
-        if( ( preferences.search_result_number != '65536') && (nw_array.length > 0) && (nw_array.length >= preferences.search_result_number) )
-        {
-            nw_array.length = preferences.search_result_number;
-            write_msg(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
-        }
-        else
-        {
-                write_msg(nw_array.length + " "+ get_lang('results found'));
-        }
+			sort_type = this.sort_type;
 
 		numBox++;
@@ -423,36 +307,11 @@
 			tbody.id	= "tbody_box_" + numBox;
 
-		for( var i = 0; i < nw_array.length; i++)
-		{
+		for( var i=0; i < data.length; i++){
 			var tr = document.createElement("TR");
-				tr.style.height = preferences.line_height;
-			nw_array[i] = url_decode(unescape(nw_array[i]));
-			
-			var aux1;
-			aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-			/*
-			 * E-mails do dia estão vindo com o horário em mensagens locais. 
-			 * Caso isso seja "corrigido" essa condicional não será mais necessária
-			 */
-			if(aux1==null) 
-				aux1 = nw_array[i].match(/\d{2}:\d{2}--\d+? \w*b--.*--\d*$/g);
-			aux1 = aux1[0].split("--");
-			nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
-			
-			var aux 	= [];
-			var mailbox = "";
-			aux[0] = mailbox = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-			nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-			aux[3] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-			nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-			aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-			aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-			aux = aux.concat(aux1);
-
-			
-			var mailbox_name = aux[0];
-			var mailbox_id = aux[3];
-			var uid_msg = aux[7];
-			var subject = aux[2];
+			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"+global_search;
 
@@ -461,5 +320,5 @@
 			tr.name = mailbox;
 
-			if (aux[5].match("U"))
+			if (aux.flag.match("U"))
 				add_className(tr,'tr_msg_unread');
 			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
@@ -471,13 +330,13 @@
 				{
 					td.style.width = "1%";
-					var td1 = '<input type="checkbox" id="'+ border_id +'_check_box_message_'+uid_msg+'"></input>';
-
+					var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
+					
 				}
 				if (j == 1)
 				{
 					td.style.width = "2%";
-					if (aux[6].match('T'))
+					if (aux.flag.match('T'))
 					{
-						attachNum = parseInt(aux[6].substr(aux[6].indexOf('T')+1));
+						attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
 						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
 					}
@@ -489,8 +348,8 @@
 					td.style.width = "1%";
 					td.id = "td_message_answered_"+uid_msg;
-					if (aux[6].match('X'))
+					if (aux.flag.match('X'))
 						td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
 					else
-						if (aux[6].match('A'))
+						if (aux.flag.match('A'))
 							td1 = '<img src=templates/'+template+'/images/answered.gif>';
 						else
@@ -501,5 +360,5 @@
 					td.style.width = "1%";
 					td.id = "td_message_important_"+uid_msg;
-					if (aux[6].match("F"))
+					if (aux.flag.match("F"))
 					{
 						add_className(tr, 'flagged_msg');
@@ -519,5 +378,5 @@
 					td.style.width = "20%";
 					td.onclick = _onclick;
-					var nm_box = aux[0].split(cyrus_delimiter);
+					var nm_box = aux.boxname.split(cyrus_delimiter);
 					var td1 = nm_box.pop();
 					td.setAttribute("NoWrap","true");
@@ -525,25 +384,10 @@
 					td.style.color = "#42795b";
 					td.style.fontWeight = "bold";
-					if(proxy_mensagens.is_local_folder(td1))
-					{
-						var td1 = this.aux_local_folder_display(td1);
-						tr.name = aux[0]; // precisa trocar pelo nome real no banco do gears.
-					}
-					else
-					{
-						if(td1 == "INBOX")
-						{
-							var td1  = get_lang("Inbox");
-						}
-						else if (nm_box[0] == 'user')
-						{
-							if (nm_box.length > 1)
-								var td1 = nm_box[1] + '/' + lang_folder(td1);
-							else
-								var td1 = td1;
-						}
-						else
-							var td1 = lang_folder(td1);
-					}
+					
+					var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
+                                        if ((tmp = translatedFolders.get(td1)))
+                                        {
+                                            td1 = tmp;
+                                        }
 
 					if( proxy_mensagens.is_local_folder(td1))
@@ -554,11 +398,11 @@
 				if( j == 6)
 				{
-					if (aux[1].length > 20)
-						aux[1] = aux[1].substr(0,20) + "...";
+					if (aux.from.length > 29)
+						aux.from = aux.from.substr(0,29) + "...";
 					td.style.width = "20%";
 					td.onclick = _onclick;
 					td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
+					var td1  =  '<div style="width:100%;overflow:hidden">'+aux.from+"</div>";
 				}
 				if( j == 7)
@@ -566,12 +410,13 @@
 					var subject_encode = url_encode(subject);
 					if (! subject_encode)
-						aux[2] = get_lang("no subject") + "...";
-					if ( subject.length > 45)
-						aux[2] = subject.substr(0,45) + "...";
+						aux.subject = get_lang("no subject") + "...";
+					if (aux.subject.length > 45)
+						aux.subject = aux.subject.substr(0,45) + "...";
 					td.style.width = "35%";
 					td.onclick = _onclick;
                                         td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  = aux[2];
+					var td1  = aux.subject;
+
 				}
 				if( j == 8)
@@ -580,5 +425,6 @@
 					td.align = "center";
 					td.onclick = _onclick;
-					var td1  = aux[4];
+					var _dat = new Date(aux.udate*1000); 
+                                        var td1 = _dat.getDate()+"/"+(_dat.getMonth()+1)+"/"+_dat.getFullYear(); 
 				}
 				if( j == 9)
@@ -587,12 +433,11 @@
 					td.align = "center";
 					td.onclick = _onclick;
-                                        td.setAttribute("NoWrap","true");
-					var td1  = aux[5];
+					var td1  = borkb(aux.size);
 				}
 				if (j == 10)
 				{
-					if (aux[6].match("U"))
+					if (aux.flag.match("U"))
 						add_className(tr, 'tr_msg_unread');
-					if (aux[7].match("F"))
+					if (aux.flag.match("F"))
 						add_className(tr, 'flagged_msg');
 					var td1 = '';
@@ -603,7 +448,9 @@
 			aux.splice(0,(aux.length));
 
-		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox_id);
+		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
 		tbody.appendChild(tr);
 		}
+		global_search++; //Tabs from search must not have the same id on its tr's
+		
 		table.appendChild(tbody);
 
@@ -650,10 +497,20 @@
 		if (sort_type == 'SORTBOX')
 		{
-			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
+			td_element1.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTBOX_REVERSE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTBOX_REVERSE";
+				cExecute(args,handler,params);
+			};
 			td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
+			td_element1.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTBOX'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTBOX";
+				cExecute(args,handler,params);
+			};
 			if  (sort_type == 'SORTBOX_REVERSE')
 				td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -666,10 +523,20 @@
 		if (sort_type == 'SORTWHO')
 		{
-			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
+			td_element2.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTWHO_REVERSE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTWHO_REVERSE";
+				cExecute(args,handler,params);
+			};
 			td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
+			td_element2.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTWHO'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTWHO";
+				cExecute(args,handler,params);
+			};
 			if  (sort_type == 'SORTWHO_REVERSE')
 				td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -682,10 +549,20 @@
 		if (sort_type == 'SORTSUBJECT')
 		{
-			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
+			td_element3.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTSUBJECT_REVERSE";
+				cExecute(args,handler,params);
+			};
 			td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
+			td_element3.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTSUBJECT'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTSUBJECT";
+				cExecute(args,handler,params);
+			};
 			if  (sort_type == 'SORTSUBJECT_REVERSE')
 				td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -698,10 +575,20 @@
 		if (sort_type == 'SORTDATE')
 		{
-			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
+			td_element4.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTDATE_REVERSE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTDATE_REVERSE";
+				cExecute(args,handler,params);
+			};
 			td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
+			td_element4.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTDATE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTDATE";
+				cExecute(args,handler,params);
+			};
 			if  (sort_type == 'SORTDATE_REVERSE')
 				td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -714,10 +601,20 @@
 		if (sort_type == 'SORTSIZE')
 		{
-			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
+			td_element5.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTSIZE_REVERSE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTSIZE_REVERSE";
+				cExecute(args,handler,params);
+			};
 			td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
+			td_element5.onclick = function () {
+				var handler = function(data){ delete_border(border_id,false); EsearchE.mount_result(data,'SORTSIZE'); };
+				var args   = "$this.imap_functions.search_msg";
+				var params = "condition="+EsearchE.condition+"&page="+EsearchE.page+"&sort_type=SORTSIZE";
+				cExecute(args,handler,params);
+			};
 			if  (sort_type == 'SORTSIZE_REVERSE')
 				td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -757,7 +654,9 @@
 		}
 		resizeWindow();
-	}
-
-	searchE.prototype.open_msg = function(mailbox_id, uid_msg, subject){
+		EsearchE.show_paging(Rdata['num_msgs']);
+
+	}
+
+	searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
 		var handler_get_msg = function(data){
 			if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
@@ -765,5 +664,5 @@
 			//set_msg_as_read(msgs_to_set[i], false);
 		}
-		proxy_mensagens.get_msg(uid_msg,mailbox_id,false,handler_get_msg);
+		proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
 		/*var args   = "$this.imap_functions.get_info_msg";
 		var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
@@ -791,4 +690,8 @@
 			if(this.name_box_search=='local_Inbox')
 				name_box_def = get_lang("Inbox");
+			else if(this.name_box_search.indexOf("/")!="-1") {
+				final_pos = this.name_box_search.lastIndexOf("/");
+				name_box_def = this.name_box_search.substr(final_pos+1);
+			}
 			else
 				name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
@@ -840,22 +743,22 @@
 			// Verifica se os campos estão preenchidos;
 			if(trim(Element("txt_ass").value) != ""){
-				fields += "SUBJECT " +  "<=>" +encodeURIComponent(Element("txt_ass").value) + "##";
+				fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
 			}
 			if(trim(Element("txt_body").value) != ""){
-				fields += "BODY " + "<=>" + encodeURIComponent(Element("txt_body").value) + "##";
+				fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
 			}
 			if(trim(Element("txt_de").value) != ""){
-				fields += "FROM " + "<=>" + encodeURIComponent(Element("txt_de").value) + "##";
+				fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
 			}
 			if(trim(Element("txt_para").value) != ""){
-				fields += "TO " + "<=>" + encodeURIComponent(Element("txt_para").value) + "##";
+				fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
 			}
 			if(trim(Element("txt_cc").value) != ""){
-				fields += "CC " + "<=>" + encodeURIComponent(Element("txt_cc").value) + "##";
+				fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
 			}
                         if (trim(Element("since_date").value) != ""){
                             if (validate_date(Element("since_date").value))
                             {
-                                fields += "SINCE " + "<=>" + encodeURIComponent(Element("since_date").value) + "##";
+                                fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##";
                             }
                             else
@@ -868,5 +771,5 @@
                             if (validate_date(Element("before_date").value))
                             {
-                                fields += "BEFORE " + "<=>" + encodeURIComponent(Element("before_date").value) + "##";
+                                fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##";
                             }
                             else
@@ -879,5 +782,5 @@
                             if (validate_date(Element("on_date").value))
                             {
-                                fields += "ON " + "<=>" + encodeURIComponent(Element("on_date").value) + "##";
+                                fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##";
                             }
                             else
@@ -933,5 +836,5 @@
                         }
 			if(value) {
-				fields = "##ALL " +  "<=>" +encodeURIComponent(value) + "##";
+				fields = "##ALL " +  "<=>" +url_encode(value) + "##";
 			}
 
@@ -976,30 +879,16 @@
 		}
 		var handler = function(data){
-			var tmp;
-			var countTmp= new Array();
-
-                        var dataTemp = data.split('=sumResults=');
-                        var sumResults = dataTemp[0];
-
-                        var data = dataTemp[1] ? dataTemp[1] : dataTemp[0];
-
-			if (local_folders.length > 0) {
-				tmp = expresso_local_messages.search(local_folders, fields);
-				if (tmp!=false) {
-					var tmp2 = tmp.substr(2, data.length - 4);
-					countTmp = tmp.split('####');
-				}
-			}
-                        if ((sumResults == "none") && (countTmp.length==0)){
-                            alert(get_lang("None result was found."));
-                        }
-                        else
-                        {
-                            EsearchE.mount_result((sumResults=='none')?tmp:(countTmp.length==0)?data:data+tmp);
-                        }
+			if (data == "none")
+	                        alert(get_lang('no results found'));
+			else
+				EsearchE.mount_result(data,'SORTDATE');
 
 		}
 		var args   = "$this.imap_functions.search_msg";
-		var params = "condition=" + nm_box;
+		this.condition = nm_box;
+		var params = "condition=" + nm_box+
+			"&page=0"+
+			"&sort_type=SORTDATE";
+		this.page = 0;
 		if(expresso_offline)
 			handler('none');
