Index: branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3365)
+++ branches/2.2/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3380)
@@ -307,4 +307,6 @@
 More	expressoMail1_2	pt-br	Mais
 More options	expressoMail1_2	pt-br	Mais opções
+More than %1 results. Please, try to refine your search.	expressoMail1_2	pt-br	Mais que %1 resultados foram encontrados. Tente refinar sua pesquisa.
+More than %1 results were found	expressoMail1_2	pt-br	Mais de %1 resultados foram encontrados
 Move	expressoMail1_2	pt-br	Mover
 Move to	expressoMail1_2	pt-br	Mover para
@@ -390,5 +392,4 @@
 Result of the search	expressoMail1_2	pt-br	Resultado da busca
 results found	expressoMail1_2	pt-br	resultados encontrados
-no results found	expressoMail1_2	pt-br	Nenhum resultado encontrado
 Return receipt	expressoMail1_2	pt-br	Conf. de Leitura
 REVOKED Certificate.	expressoMail1_2	pt-br	CERTIFICADO REVOGADO.
Index: branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3369)
+++ branches/2.2/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3380)
@@ -721,6 +721,6 @@
 
 		$return = ""; 
-		if( (!isset($this->prefs['preview_msg_subject']) || ($this->prefs['preview_msg_subject'] != "1")) &&  
-			(!isset($this->prefs['preview_msg_tip']    ) || ($this->prefs['preview_msg_tip']     != "1")) ) 
+		if( (!isset($this->preferences['preview_msg_subject']) || ($this->preferences['preview_msg_subject'] != "1")) &&  
+			(!isset($this->preferences['preview_msg_tip']    ) || ($this->preferences['preview_msg_tip']     != "1")) ) 
 		{ 
 			$return['body'] = ""; 
@@ -3191,148 +3191,134 @@
 
 	function search_msg($params = ''){
-            $mbox_stream = "";
-            if(strpos($params['condition'],"#")===false) { //local messages? It shouldn't be necessary, should it? FIXME
-                    $search=false;
-            }
-            else {
-                    $search = explode(",",$params['condition']);
-	    }
-	    $params['page'] = $params['page']*1;
-
-	    if(is_array($search)){
-		$search = array_unique($search); // Remove duplicated folders
-                $search_criteria = '';
-                $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'];
-                foreach($search as $tmp)
+		$retorno = "";
+		$mbox_stream = "";
+		if(strpos($params['condition'],"#")===false) { //local messages
+			$search=false;
+		}
+		else {
+			$search = explode(",",$params['condition']);
+		}
+
+		if($search){
+			$search_criteria = '';
+                        $search_result_number = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['search_result_number'];
+                        foreach($search as $tmp)
+			{
+				$tmp1 = explode("##",$tmp);
+                                $sum = 0;
+				$name_box = $tmp1[0];
+				unset($filter);
+				foreach($tmp1 as $index => $criteria)
+				{
+                                    if ($index != 0 && strlen($criteria) != 0)
+                                    {
+                                        $filter_array = explode("<=>",html_entity_decode(rawurldecode($criteria)));
+                                        $filter .= " ".$filter_array[0];
+                                        if (strlen($filter_array[1]) != 0){
+                                            if (trim($filter_array[0]) != 'BEFORE' &&
+                                                trim($filter_array[0]) != 'SINCE' &&
+                                                trim($filter_array[0]) != 'ON')
+                                            {
+                                                // Remove accents from criteria, because method remove accents is broken.
+                                                $filter .= '"'.strtr($filter_array[1],
+                                                    "áàâãäéèêëíìîïóòôõöúùûüçÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ",
+                                                    "aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC").'"';
+                                            }
+                                            else {
+                                                $filter .= '"'.$this->make_search_date($filter_array[1]).'"';
+                                            }
+                                        }
+                                    }
+				}
+				$name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
+
+                                //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name
+				if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user')
+				{
+					$folder_name = explode($this->imap_delimiter,$name_box);
+					$this->ldap = new ldap_functions();
+					if ($cn = $this->ldap->uid2cn($folder_name[1]))
+					{
+						$folder_name[1] = $cn;
+					}
+					$folder_name = implode($this->imap_delimiter,$folder_name);
+				}
+				else
+					$folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
+
+				if(!is_resource($mbox_stream))
+					$mbox_stream = $this->open_mbox($name_box);
+				else
+					imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box);
+
+                                if (preg_match("/^.?\bALL\b/", $filter)){ // Quick Search, note: this ALL isn't the same ALL from imap_search
+
+					$all_criterias = array ("TO","SUBJECT","FROM","CC");
+
+					foreach($all_criterias as $criteria_fixed)
+					{
+						$_filter = $criteria_fixed . substr($filter,4);
+
+						$search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
+						// Testa aqui
+						if($search_criteria) // && count($search_criteria) < $search_result_number)
+						{
+							foreach($search_criteria as $new_search){
+                                                                if ($search_result_number != '65536' && $sum == $search_result_number)
+                                                                {
+                                                                  return $retorno ? $sum . "=sumResults=" . $retorno : "none";
+                                                                }
+
+								$m_token = trim("##". mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n");
+								if(!@strstr($retorno,$m_token))
+                                                                {
+                                                                    $retorno .= $m_token;
+                                                                    $sum++;
+                                                                }
+							}
+						}
+					}
+				}
+				else {
+					$search_criteria = imap_search($mbox_stream, $filter, SE_UID);
+					if( is_array( $search_criteria) )
+					{
+						foreach($search_criteria as $new_search)
+                                                {
+                                                    if ($search_result_number != '65536' && $sum == $search_result_number)
+                                                    {
+                                                        return $retorno ? $sum . "=sumResults=" . $retorno : "none";
+                                                    }
+                                                    $retorno .= trim("##". mb_convert_encoding( $folder_name, "ISO_8859-1", "UTF7-IMAP" ) . "--" . mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ) . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--" . $new_search."##"."\n");
+                                                    $sum++;
+                                                }
+					}
+				}
+
+//                                $acumulated_results += $sum;
+//
+//                                if ($search_result_number != '65536' && $acumulated_results >= $search_result_number)
+//                                {
+//                                    return "many results";
+//                                }
+			}
+		}
+		if($mbox_stream)
+			imap_close($mbox_stream);
+
+                if ($retorno){
+                    return $retorno;
+                }
+                else
                 {
-                    $tmp1 = explode("##",$tmp);
-                    $sum = 0;
-                    $name_box = $tmp1[0];
-                    unset($filter);
-                    foreach($tmp1 as $index => $criteria)
-                    {
-                        if ($index != 0 && strlen($criteria) != 0)
-                        {
-                            $filter_array = explode("<=>",rawurldecode($criteria));
-                            $filter .= " ".$filter_array[0];
-                            if (strlen($filter_array[1]) != 0){
-                                if (trim($filter_array[0]) != 'BEFORE' &&
-                                    trim($filter_array[0]) != 'SINCE' &&
-                                    trim($filter_array[0]) != 'ON')
-                                {
-                                    $filter .= '"'.$filter_array[1].'"';
-                                }
-                                else
-                                    {
-                                        $filter .= '"'.$this->make_search_date($filter_array[1]).'"';
-                                    }
-                            }
-                        }
-                    }
-                    $name_box = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
-                    $filter = $this->remove_accents($filter);
-                    //Este bloco tem a finalidade de transformar o login (quando numerico) das pastas compartilhadas em common name
-                    if ($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['uid2cn'] && substr($name_box,0,4) == 'user')
-                    {
-                        $folder_name = explode($this->imap_delimiter,$name_box);
-                        $this->ldap = new ldap_functions();
-                        if ($cn = $this->ldap->uid2cn($folder_name[1]))
-                        {
-                            $folder_name[1] = $cn;
-                        }
-                        $folder_name = implode($this->imap_delimiter,$folder_name);
-                    }
-                    else
-                    {
-                        $folder_name = mb_convert_encoding(utf8_decode($name_box), "UTF7-IMAP", "ISO_8859-1" );
-                    }
-
-                    if(!is_resource($mbox_stream))
-                    {
-                        $mbox_stream = $this->open_mbox($name_box);
-                    }
-                    else
-                        {
-                            imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box);
-                        }
-
-                    if (preg_match("/^.?\bALL\b/", $filter))
-                    { // Quick Search, note: this ALL isn't the same ALL from imap_search
-
-                        $all_criterias = array ("TO","SUBJECT","FROM","CC");
-                        foreach($all_criterias as $criteria_fixed)
-                        {
-                            $_filter = $criteria_fixed . substr($filter,4);
-
-                            $search_criteria = imap_search($mbox_stream, $_filter, SE_UID);
-
-                            if(is_array($search_criteria))
-                            {
-                                foreach($search_criteria as $new_search)
-                                {
-				    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 
-				    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 
-				    $elem['uid'] = $new_search; 
-				    $retorno[] = $elem; 
-				}
-			    }
-                        }
-                    }
-                    else {
-                        $search_criteria = imap_search($mbox_stream, $filter, SE_UID);
-                        if( is_array( $search_criteria) )
-                        {
-                            foreach($search_criteria as $new_search)
-			    {
-				    $elem = $this->get_msg_detail($new_search,$name_box,$mbox_stream); 
-				    $elem['boxname'] = mb_convert_encoding( $name_box, "ISO_8859-1", "UTF7-IMAP" ); 
-				    $elem['uid'] = $new_search; 
-				    $retorno[] = $elem;
-                            }
-                        }
-		    }
+                    return 'none';
                 }
-            }
-            if($mbox_stream)
-            {
-                imap_close($mbox_stream);
-	    }
-	    $num_msgs = count($retorno);
-
-	    /* Comparison functions, descendent is ascendent with parms inverted */
-	    function SORTDATE($a, $b) { return ($a['udate'] < $b['udate']); }
-	    function SORTDATE_REVERSE($b, $a) { return SORTDATE($a,$b); }
-
-	    function SORTWHO($a, $b) { return (strtoupper($a['from']) > strtoupper($b['from'])); }
-	    function SORTWHO_REVERSE($b, $a) { return SORTWHO($a,$b); }
-
-	    function SORTSUBJECT($a, $b) { return (strtoupper($a['subject']) > strtoupper($b['subject'])); }
-	    function SORTSUBJECT_REVERSE($b, $a) { return SORTSUBJECT($a,$b); }
-
-	    function SORTBOX($a, $b) { return ($a['boxname'] > $b['boxname']); }
-	    function SORTBOX_REVERSE($b, $a) { return SORTBOX($a,$b); }
-
-	    function SORTSIZE($a, $b) { return ($a['size'] > $b['size']); }
-	    function SORTSIZE_REVERSE($b, $a) { return SORTSIZE($a,$b); }
-
-	    usort($retorno, $params['sort_type']);
-	    $pageret = array_slice($retorno, $params['page'] * $this->prefs['max_email_per_page'], $this->prefs['max_email_per_page']);
-	    $arrayRetorno['num_msgs'] =  $num_msgs;
-	    $arrayRetorno['data'] =  $pageret;
-
-            if ($pageret)
-            {
-                return $arrayRetorno;
-            }
-            else
-            {
-                return 'none';
-            }
-	}
-
-	function get_msg_detail($uid_msg,$name_box, $mbox_stream )
+		//return $retorno ? $retorno : "none";
+	}
+
+	function get_msg($uid_msg,$name_box, $mbox_stream )
 	{
 		$header = $this->get_header($uid_msg);
-		require_once("class.imap_attachment.inc.php");
+		include_once("class.imap_attachment.inc.php");
 		$imap_attachment = new imap_attachment();
 		$attachments =  $imap_attachment->get_attachment_headerinfo($mbox_stream, $uid_msg);
@@ -3351,11 +3337,18 @@
 		if($header->from[0]->personal != "")
 			$from = $header->from[0]->personal;
-		$ret_msg['from'] = $this->decode_string($from); 
-		$ret_msg['subject'] = $subject; 
-		$ret_msg['udate'] = $header ->udate; 
-		$ret_msg['size'] = $header->Size; 
-		$ret_msg['flag'] = $flag; 
+		$ret_msg = $this->decode_string($from) . "--" . $subject . "--". gmdate("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size) ."--". $flag;
 		return $ret_msg;
 	}
+
+
+	function size_msg($size){
+		$var = floor($size/1024);
+		if($var >= 1){
+			return $var." kb";
+		}else{
+			return $size ." b";
+		}
+	}
+	
 	function ob_array($the_object)
 	{
Index: branches/2.2/expressoMail1_2/js/common_functions.js
===================================================================
--- branches/2.2/expressoMail1_2/js/common_functions.js	(revision 3369)
+++ branches/2.2/expressoMail1_2/js/common_functions.js	(revision 3380)
@@ -187,8 +187,9 @@
 
 function show_hide_span_paging(ID){
-	if (Element("span_paging"+ID))
-		Element("span_paging"+ID).style.display = '';
-	if (Element("span_paging"+currentTab))
-		Element("span_paging"+currentTab).style.display = 'none';
+	if ((ID != "0") && Element("span_paging")) 
+		Element("span_paging").style.display = 'none';
+	else
+		if (Element("span_paging"))
+			Element("span_paging").style.display = '';
 }
 
Index: branches/2.2/expressoMail1_2/js/search.js
===================================================================
--- branches/2.2/expressoMail1_2/js/search.js	(revision 3223)
+++ branches/2.2/expressoMail1_2/js/search.js	(revision 3380)
@@ -1,11 +1,8 @@
 /**************************************************************************\
- 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;
@@ -15,5 +12,5 @@
                 this.selectFields = new Array("flagged", "seen", "answered", "recent");
 	}
-	
+
 	//Monta os forms dentro da janela;
 	searchE.prototype.showForms = function(value){
@@ -25,7 +22,7 @@
 			form_search.style.left = '0px';
 			form_search.id = "window_search";
-			document.body.appendChild(form_search);			
-		}
-		
+			document.body.appendChild(form_search);
+		}
+
 		// Pesquisa
 		if(!Element("div_form_search")){
@@ -35,4 +32,7 @@
 			div_form_search.style.left = "10px";
 			div_form_search.style.top  = "10px";
+			div_form_search.style.borderStyle = "outset";
+			div_form_search.style.borderColor = "black";
+			div_form_search.style.borderWidth = "1px";
 			div_form_search.style.width = "784px";
 			div_form_search.style.height = "418px";
@@ -66,6 +66,6 @@
                         });
 
-		}	
-		
+		}
+
 		if(!Element("div_button_search")){
 			var div_button_search    = document.createElement("DIV");
@@ -85,12 +85,12 @@
 				form_search.appendChild(div_button_search);
 		}
-		
+
 		if(!Element("table_layer")){
 			var table_layer    = "";
 		}
-		
+
 		if(value == "")
 			EsearchE.showWindow(Element("window_search"));
-	
+
 		// Cria as caixas postais;
 		EsearchE.mount_folders();
@@ -103,5 +103,10 @@
 
 	}
-	
+
+        searchE.validate_date_field = function(date)
+        {
+
+        }
+
 	//Form
 	searchE.prototype.mount_form = function(value){
@@ -109,5 +114,5 @@
 		form_sch.id  = "form_sch";
 
-		form_sch.innerHTML =  '<fieldset style="width:400px; text-align:right; padding: 5px; position:absolute;">'
+                form_sch.innerHTML =  '<fieldset style="width:400px; text-align:right; padding: 5px; position:absolute;">'
 							+ '	<legend>'+get_lang('Inform your search in the text fields')+'</legend>'
 							+ '	<label>'+get_lang("From")+':</label>'
@@ -124,5 +129,5 @@
 							+ '	<br style="margin-bottom:15px"/>'
 							+ '	<label>'+get_lang('Message body')+':</label>'
-                                                        + '	<input style="margin-left: 6px;" type="text" id="txt_body" size="39">'
+							+ '	<input style="margin-left: 6px;" type="text" id="txt_body" size="39">'
 
 							+ '	<br style="margin-bottom:30px"/>'
@@ -165,5 +170,5 @@
                                                         + '     </select>'
 
-							+ '	<br style="margin-bottom:60px"/>'
+                                                        + '	<br style="margin-bottom:60px"/>'
 							+ '</fieldset>'
 							+ '<fieldset style="width:350px; padding: 5px; position:absolute; margin-left: 414px">'
@@ -175,5 +180,5 @@
 							+ '		<input type="button" id="excluir" name="excluir" value="<<" onclick="EsearchE.del_mailboxes()">'
 							+ '	</div>'
-							+ ' <div style="float:left;">'	
+							+ ' <div style="float:left;">'
 							+ '	 <select multiple id="sel_search_nm_box1" name="sel_search_nm_box1" style="width:140px;height:150px;"></select>'
 							+ ' </div>'
@@ -182,5 +187,5 @@
 							+ '	<b>'+get_lang('In all the folders')+'</b>'
 							+ '</fieldset>';
-		
+
 		return form_sch;
 	}
@@ -203,81 +208,169 @@
 				var dest_div = Element("folders");
 				dest_div.appendChild(div_folders);
-		}		
+		}
 		ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
 	}
-	function openpage(data){
-		delete_border(currentTab,false);
-		EsearchE.mount_result(data);
-	}
-
-	searchE.prototype.show_paging = function(size){
-		if (size > preferences.max_email_per_page)
+
+	//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;
+	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].toLowerCase();
+	var temp=compare[0];
+	compare[1] = b.substr(b.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].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 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)
 		{
-			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)
+			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] != "")
 			{
-				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
-			sort_type = this.sort_type;
+				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'));
+                }
 
 		numBox++;
@@ -289,6 +382,5 @@
 		currentTab = border_id;
                 openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
-		openTab.type[currentTab] = 1;
-
+                openTab.type[currentTab] = 1;
 		var table = document.createElement("TABLE");
 		table.id    = "table_resultsearch_" + numBox;
@@ -301,12 +393,36 @@
 		var tbody = document.createElement("TBODY");
 		tbody.id    = "tbody_box_" + numBox;
-		for( var i=0; i < data.length; i++){
+
+		for( var i=0; i < nw_array.length; i++){
 			var tr = document.createElement("TR");
 			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;
+
+			if (false && nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
+			{
+				var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\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 = [];
+				aux[0] = 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);
+			}
+			else
+			{
+				var aux = nw_array[i].split("--");
+				aux.splice(4,0,aux[1]);
+				var mailbox = aux.shift();
+				aux.splice(0,1,mailbox);
+			}
+
+			var mailbox_name = aux[0];
+			var mailbox_id = aux[3];
+			var uid_msg = aux[7];
+			var subject = aux[2];
+			tr.id = uid_msg;
 
 			// Keep the two lines together please
@@ -314,5 +430,5 @@
 			tr.name = mailbox;
 
-			if (aux.flag.match("U"))
+			if (aux[5].match("U"))
 				add_className(tr,'tr_msg_unread');
 			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
@@ -324,13 +440,13 @@
 				{
 					td.style.width = "1%";
-					var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
-					
+					var td1 = '<input type="checkbox" id="'+ border_id +'_check_box_message_'+uid_msg+'"></input>';
+
 				}
 				if (j == 1)
 				{
 					td.style.width = "2%";
-					if (aux.flag.match('T'))
+					if (aux[6].match('T'))
 					{
-						attachNum = parseInt(aux.flag.substr(aux.flag.indexOf('T')+1));
+						attachNum = parseInt(aux[6].substr(aux[6].indexOf('T')+1));
 						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
 					}
@@ -342,8 +458,8 @@
 					td.style.width = "1%";
 					td.id = "td_message_answered_"+uid_msg;
-					if (aux.flag.match('X'))
+					if (aux[6].match('X'))
 						td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
 					else
-						if (aux.flag.match('A'))
+						if (aux[6].match('A'))
 							td1 = '<img src=templates/'+template+'/images/answered.gif>';
 						else
@@ -354,5 +470,5 @@
 					td.style.width = "1%";
 					td.id = "td_message_important_"+uid_msg;
-					if (aux.flag.match("F"))
+					if (aux[6].match("F"))
 					{
 						add_className(tr, 'flagged_msg');
@@ -370,7 +486,7 @@
 				if (j == 5)
 				{
-					td.style.width = "14%";
+					td.style.width = "20%";
 					td.onclick = _onclick;
-					var nm_box = aux.boxname.split(cyrus_delimiter);
+					var nm_box = aux[0].split(cyrus_delimiter);
 					var td1 = nm_box.pop();
 					td.setAttribute("NoWrap","true");
@@ -378,10 +494,19 @@
 					td.style.color = "#42795b";
 					td.style.fontWeight = "bold";
-					
-					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)) {
+						var td1 = this.aux_local_folder_display(td1);
+						aux[2] = 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);
+					}
 
 					if(proxy_mensagens.is_local_folder(td1)) {
@@ -391,11 +516,11 @@
 				if( j == 6)
 				{
-					if (aux.from.length > 29)
-						aux.from = aux.from.substr(0,29) + "...";
+					if (aux[1].length > 20)
+						aux[1] = aux[1].substr(0,20) + "...";
 					td.style.width = "20%";
 					td.onclick = _onclick;
 					td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  =  '<div style="width:100%;overflow:hidden">'+aux.from+"</div>";
+					var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
 				}
 				if( j == 7)
@@ -403,21 +528,19 @@
 					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) + "...";
+						aux[2] = get_lang("no subject") + "...";
+					if ( subject.length > 45)
+						aux[2] = subject.substr(0,45) + "...";
 					td.style.width = "35%";
 					td.onclick = _onclick;
                                         td.setAttribute("NoWrap","true");
                                         td.style.overflow = "hidden";
-					var td1  = aux.subject;
-
+					var td1  = aux[2];
 				}
 				if( j == 8)
 				{
-					td.style.width = "15%";
+					td.style.width = "13%";
 					td.align = "center";
 					td.onclick = _onclick;
-					var _dat = new Date(aux.udate*1000); 
-                                        var td1 = _dat.getDate()+"/"+(_dat.getMonth()+1)+"/"+_dat.getFullYear(); 
+					var td1  = aux[4];
 				}
 				if( j == 9)
@@ -426,11 +549,12 @@
 					td.align = "center";
 					td.onclick = _onclick;
-					var td1  = borkb(aux.size);
+                                        td.setAttribute("NoWrap","true");
+					var td1  = aux[5];
 				}
 				if (j == 10)
 				{
-					if (aux.flag.match("U"))
+					if (aux[6].match("U"))
 						add_className(tr, 'tr_msg_unread');
-					if (aux.flag.match("F"))
+					if (aux[7].match("F"))
 						add_className(tr, 'flagged_msg');
 					var td1 = '';
@@ -441,9 +565,7 @@
 			aux.splice(0,(aux.length));
 
-		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
+		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox_id);
 		tbody.appendChild(tr);
 		}
-		global_search++; //Tabs from search must not have the same id on its tr's
-		
 		table.appendChild(tbody);
 
@@ -452,8 +574,8 @@
 	div_scroll_result.id = "divScrollMain_"+numBox;
 	div_scroll_result.style.overflow = "auto";
-	
+
 		if(is_ie)
 			Element("border_table").width = "99.5%";
-		
+
 		// Put header
 		var table_element = document.createElement("TABLE");
@@ -464,5 +586,5 @@
 		tr_element.className = "message_header";
 		td_element0 = document.createElement("TD");
-		td_element0.setAttribute("width", "1%");
+		td_element0.setAttribute("width", "7%");
 		chk_box_element = document.createElement("INPUT");
 		chk_box_element.id  = "chk_box_select_all_messages";
@@ -483,5 +605,5 @@
 			}
 		};
-		
+
 		td_element0.appendChild(chk_box_element);
 		td_element1 = document.createElement("TD");
@@ -490,20 +612,10 @@
 		if (sort_type == 'SORTBOX')
 		{
-			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.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
 			td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			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);
-			};
+			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
 			if  (sort_type == 'SORTBOX_REVERSE')
 				td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -516,20 +628,10 @@
 		if (sort_type == 'SORTWHO')
 		{
-			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.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
 			td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			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);
-			};
+			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
 			if  (sort_type == 'SORTWHO_REVERSE')
 				td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -542,20 +644,10 @@
 		if (sort_type == 'SORTSUBJECT')
 		{
-			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.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
 			td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			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);
-			};
+			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
 			if  (sort_type == 'SORTSUBJECT_REVERSE')
 				td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -564,24 +656,14 @@
 		}
 		td_element4 = document.createElement("TD");
-		td_element4.setAttribute("width", "15%");
+		td_element4.setAttribute("width", "12%");
 		td_element4.align = "center";
 		if (sort_type == 'SORTDATE')
 		{
-			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.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
 			td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			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);
-			};
+			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
 			if  (sort_type == 'SORTDATE_REVERSE')
 				td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -590,24 +672,14 @@
 		}
 		td_element5 = document.createElement("TD");
-		td_element5.setAttribute("width", "10%");
+		td_element5.setAttribute("width", "8%");
 		td_element5.align = "center";
 		if (sort_type == 'SORTSIZE')
 		{
-			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.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
 			td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
 		}
 		else
 		{
-			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);
-			};
+			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
 			if  (sort_type == 'SORTSIZE_REVERSE')
 				td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
@@ -625,8 +697,8 @@
 		content_search.appendChild(table_element);
 		/*end of "put header"*/
-		
+
 		if (!expresso_offline) {
 /*			var span_options = document.createElement("SPAN");
-			if (span_options) 
+			if (span_options)
 				span_options.innerHTML = '<span title="' + get_lang("Delete") + '" style="margin-top:3px;margin-left:8px" class="message_options" onclick="javascript:move_search_msgs(\'' + content_search.id + '\');">' + get_lang("Delete") + '</span> | ' +
 				'<span title="' +
@@ -639,5 +711,5 @@
 			div_scroll_result.appendChild(table);
 			content_search.appendChild(div_scroll_result);
-			/*if (span_options) 
+			/*if (span_options)
 				content_search.appendChild(span_options);*/
 		}
@@ -647,9 +719,7 @@
 		}
 		resizeWindow();
-		EsearchE.show_paging(Rdata['num_msgs']);
-
-	}
-
-	searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
+	}
+
+	searchE.prototype.open_msg = function(mailbox_id, uid_msg, subject){
 		var handler_get_msg = function(data){
 			if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
@@ -657,5 +727,5 @@
 			//set_msg_as_read(msgs_to_set[i], false);
 		}
-		proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
+		proxy_mensagens.get_msg(uid_msg,mailbox_id,false,handler_get_msg);
 		/*var args   = "$this.imap_functions.get_info_msg";
 		var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
@@ -675,5 +745,5 @@
 				name_box_def = name_box[(name_box.length-1)];
 			}else{
-				name_box_def = get_lang("Inbox");		
+				name_box_def = get_lang("Inbox");
 			}
 		}
@@ -683,8 +753,4 @@
 			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_'
@@ -712,5 +778,5 @@
 			}
 		}
-	
+
 	}
 	// todas as caixas
@@ -720,5 +786,5 @@
 		if(value){
 			if(EsearchE.all_boxes.length > 0){
-				EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));			
+				EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
 			}
 			for(var i=0; i < folders.length; i++){
@@ -736,22 +802,22 @@
 			// Verifica se os campos estão preenchidos;
 			if(trim(Element("txt_ass").value) != ""){
-				fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
+				fields += "SUBJECT " +  "<=>" +encodeURIComponent(Element("txt_ass").value) + "##";
 			}
 			if(trim(Element("txt_body").value) != ""){
-				fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
+				fields += "BODY " + "<=>" + encodeURIComponent(Element("txt_body").value) + "##";
 			}
 			if(trim(Element("txt_de").value) != ""){
-				fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
+				fields += "FROM " + "<=>" + encodeURIComponent(Element("txt_de").value) + "##";
 			}
 			if(trim(Element("txt_para").value) != ""){
-				fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
+				fields += "TO " + "<=>" + encodeURIComponent(Element("txt_para").value) + "##";
 			}
 			if(trim(Element("txt_cc").value) != ""){
-				fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
+				fields += "CC " + "<=>" + encodeURIComponent(Element("txt_cc").value) + "##";
 			}
                         if (trim(Element("since_date").value) != ""){
                             if (validate_date(Element("since_date").value))
                             {
-                                fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##";
+                                fields += "SINCE " + "<=>" + encodeURIComponent(Element("since_date").value) + "##";
                             }
                             else
@@ -764,5 +830,5 @@
                             if (validate_date(Element("before_date").value))
                             {
-                                fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##";
+                                fields += "BEFORE " + "<=>" + encodeURIComponent(Element("before_date").value) + "##";
                             }
                             else
@@ -775,5 +841,5 @@
                             if (validate_date(Element("on_date").value))
                             {
-                                fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##";
+                                fields += "ON " + "<=>" + encodeURIComponent(Element("on_date").value) + "##";
                             }
                             else
@@ -801,4 +867,16 @@
                         }
                         if(trim(Element("answered").options[Element("answered").selectedIndex].value) != ""){
+                            //switch (Element("answered").options[Element("answered").selectedIndex].value){
+                            //    case "FORWARDED":
+                            //        fields += "ANSWERED##DRAFT##";
+                            //        break;
+                            //    case "ANSWERED":
+                            //        fields += "ANSWERED##UNDRAFT";
+                            //        break;
+                            //    case "UNFORWARDED":
+                            //        fields += "UNDRAFT##";
+                            //    case "UNANSWERED":
+                            //        fields += "UNANSWERED##";
+                            //}
                             if (Element("answered").options[Element("answered").selectedIndex].value == "ANSWERED"){
                                 fields += "ANSWERED##";
@@ -817,5 +895,5 @@
                         }
 			if(value) {
-				fields = "##ALL " +  "<=>" +url_encode(value) + "##";
+				fields = "##ALL " +  "<=>" +encodeURIComponent(value) + "##";
 			}
 
@@ -826,5 +904,5 @@
 		var local_folders = new Array();
 		var temp;
-		
+
 		if(Element("check_all_msg").checked){
 			this.all_mailboxes();
@@ -846,5 +924,5 @@
 				return false;
 			}
-			
+
 			for(var i=0; i < sel_combo.options.length; i++){
 				sel_combo.options[i].selected = true;
@@ -860,16 +938,30 @@
 		}
 		var handler = function(data){
-			if (data == "none")
-	                        alert(get_lang('no results found'));
-			else
-				EsearchE.mount_result(data,'SORTDATE');
+			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);
+                        }
 
 		}
 		var args   = "$this.imap_functions.search_msg";
-		this.condition = nm_box;
-		var params = "condition=" + nm_box+
-			"&page=0"+
-			"&sort_type=SORTDATE";
-		this.page = 0;
+		var params = "condition=" + nm_box;
 		if(expresso_offline)
 			handler('none');
@@ -880,15 +972,15 @@
 	searchE.prototype.func_clean = function(){
 		// Limpa os campos;
-            for(var i=0; i < this.txtfields.length; i++){
-                    if(Element(this.txtfields[i]) != null){Element(this.txtfields[i]).value = "";}
-            }
-
-            for(i = 0; i < this.selectFields.length; i++)
-            {
-                if (Element(this.selectFields[i]))
+		for(var i=0; i < this.txtfields.length; i++){
+			if(Element(this.txtfields[i]) != null){Element(this.txtfields[i]).value = "";}
+		}
+
+                for(i = 0; i < this.selectFields.length; i++)
                 {
-                    Element(this.selectFields[i]).selectedIndex = 0;
+                    if (Element(this.selectFields[i]))
+                    {
+                        Element(this.selectFields[i]).selectedIndex = 0;
+                    }
                 }
-            }
 	    if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
 
@@ -928,5 +1020,5 @@
 				button_y_img: '../phpgwapi/images/win_min.gif',
 				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true });
+				border: true});
 			this.searchW[div.id] = win;
 			win.draw();
@@ -939,5 +1031,5 @@
 		win.open();	
 	}
-	
+
 	searchE.prototype.aux_local_folder_display = function(folder) {
 		if(!expresso_offline)
@@ -946,5 +1038,5 @@
 			return lang_folder(folder.substr(6));
 	}
-	
+
 // Cria o objeto
 	var EsearchE;
Index: branches/2.2/expressoMail1_2/js/local_messages.js
===================================================================
--- branches/2.2/expressoMail1_2/js/local_messages.js	(revision 3373)
+++ branches/2.2/expressoMail1_2/js/local_messages.js	(revision 3380)
@@ -927,5 +927,5 @@
 	if (cond == "SINCE" || cond == "BEFORE" | cond == "ON"){
 
-	    tmpDate = url_decode(friendly_filters[z][1]).split('/');
+	    tmpDate = friendly_filters[z][1].replace(/\%2F/g,"/").split('/');
 
 	    // Date = url_decode(friendly_filters[z][1]);
@@ -946,5 +946,5 @@
     while(rs.isValidRow()) {
 	var header = connector.unserialize(rs.field(0));
-	retorno+="##"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##";
+	retorno+="##"+"local_"+rs.field(1)+"--"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##";
 	rs.next();
     }
@@ -966,7 +966,8 @@
 	
 local_messages.prototype.aux_convert_filter_field = function(filter,date) {
+
+var dateObj;
     if (typeof date != 'undefined'){
-	var dateObj=new Date();
-	dateObj.setFullYear(date[2],date[1]-1,date[0]);
+	dateObj=new Date(date[2],date[1]-1,date[0]);
     }
 
Index: branches/2.2/expressoMail1_2/js/draw_api.js
===================================================================
--- branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3369)
+++ branches/2.2/expressoMail1_2/js/draw_api.js	(revision 3380)
@@ -540,13 +540,13 @@
 
 	if(total_pages == 1) {
-		if(span_paging = document.getElementById("span_paging0")) {
+		if(span_paging = document.getElementById("span_paging")) {
 			span_paging.parentNode.removeChild(span_paging);
 		}
 		return;
 	}
-  	span_paging = document.getElementById("span_paging0");
+  	span_paging = document.getElementById("span_paging");
 	if(!span_paging){
 		span_paging = document.createElement("DIV");
-		span_paging.id = "span_paging0";
+		span_paging.id = "span_paging";
 		span_paging.className = "boxHeaderText";
 		span_paging.align="right";
