Index: /branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3547)
+++ /branches/2.0/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 3676)
@@ -420,4 +420,11 @@
 		$return = array();
 		$msg_number = $params['msg_number'];
+		if(preg_match('(.+)(_[a-zA-Z0-9]+)',$msg_number,$matches)) { //Verifies if it comes from a tab diferent of the main one.
+			$msg_number = $matches[1];
+			$plus_id = $matches[2];
+		}
+		else {
+			$plus_id = '';
+		}
 		$msg_folder = urldecode($params['msg_folder']);
 		
@@ -476,5 +483,5 @@
 		}
 
-		$return['msg_number'] = $msg_number;
+		$return['msg_number'] = $msg_number.$plus_id;
 		$return['msg_folder'] = $msg_folder;
 	
Index: /branches/2.0/expressoMail1_2/js/main.js
===================================================================
--- /branches/2.0/expressoMail1_2/js/main.js	(revision 3522)
+++ /branches/2.0/expressoMail1_2/js/main.js	(revision 3676)
@@ -582,5 +582,5 @@
 				}
 				trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
-			        selected_param += ','+trfolder+';'+tr.id;
+			        selected_param += ','+trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
 			}
 		}
@@ -594,5 +594,5 @@
 			}
 			trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
-			selected_param=trfolder+';'+tr.id;
+			selected_param=trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
 		}
 		var params = "";
Index: /branches/2.0/expressoMail1_2/js/search.js
===================================================================
--- /branches/2.0/expressoMail1_2/js/search.js	(revision 2780)
+++ /branches/2.0/expressoMail1_2/js/search.js	(revision 3676)
@@ -221,5 +221,5 @@
 			var uid_msg = aux.uid;
 			var subject = aux.subject;
-			tr.id = uid_msg;
+			tr.id = uid_msg+"_s"+global_search;
 
 			// Keep the two lines together please
@@ -354,4 +354,5 @@
 		tbody.appendChild(tr);
 		}
+		global_search++; //Tabs from search must not have the same id on its tr's
 		table.appendChild(tbody);
 
Index: /branches/2.0/expressoMail1_2/js/local_messages.js
===================================================================
--- /branches/2.0/expressoMail1_2/js/local_messages.js	(revision 1381)
+++ /branches/2.0/expressoMail1_2/js/local_messages.js	(revision 3676)
@@ -130,6 +130,34 @@
 	}
 	
+	/**
+	 * check if ID is no from main tab, if it's from main returns false, else 
+	 * returns an array with all string in position 0, the mail id in position 1 
+	 * and the part of string relative to tab in position 2
+	 * @param {Object} id_mail
+	 */
+	local_messages.prototype.parse_id_mail = function(id_mail) { 
+		if (this.isInt(id_mail))
+			return false;
+		
+		var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/);
+		return matches;
+	}
+	
+	local_messages.prototype.isInt = function(x) {
+		var y=parseInt(x);
+		if (isNaN(y)) return false;
+		return x==y && x.toString()==y.toString();
+	} 
+	
 	local_messages.prototype.get_local_mail = function(id_mail) {
 		this.init_local_messages();
+
+		var plus_id = '';
+		var matches = '';
+		if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab.
+			id_mail = matches[1];
+			plus_id = matches[2];
+		}
+
 		var rs = this.dbGears.execute("select mail.rowid,mail.mail,mail.ffrom,mail.subject,mail.body,mail.fto,mail.cc,folder.folder,mail.original_id from mail inner join folder on mail.id_folder=folder.rowid  where mail.rowid="+id_mail);
 		var retorno = null;
@@ -143,5 +171,5 @@
         if (typeof(retorno.source) == 'string')
         {
-            retorno.msg_number=rs.field(0);
+            retorno.msg_number=rs.field(0)+plus_id;
             retorno.original_ID=rs.field(8);
             retorno.msg_folder=rs.field(7);
@@ -186,5 +214,5 @@
             retorno['local_message'] = true;
             retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder
-            retorno['msg_number'] = rs.field(0); //the message number is the rowid
+            retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid
 
         }
@@ -289,5 +317,8 @@
 	local_messages.prototype.get_url_anexo = function(msg_number,pid) {
 		this.init_local_messages();
-
+		var matches = '';
+		if(matches = this.parse_id_mail(msg_number)) {
+			msg_number = matches[1];
+		}
 		var retorno;
 		var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'");
@@ -372,5 +403,10 @@
 		}
 		for (var i in msgs_to_set) {
-		
+			
+			var matches = '';//Messages comming from other tabs.
+			if(matches = this.parse_id_mail(msgs_to_set[i])) { 
+				msgs_to_set[i] = matches[1];
+			}
+			
 			var rs = this.dbGears.execute("select header,unseen from mail where rowid=" + msgs_to_set[i]);
 			header = connector.unserialize(rs.field(0));
Index: /branches/2.0/expressoMail1_2/js/globals.js
===================================================================
--- /branches/2.0/expressoMail1_2/js/globals.js	(revision 1402)
+++ /branches/2.0/expressoMail1_2/js/globals.js	(revision 3676)
@@ -20,4 +20,5 @@
 var tree_folders = '';
 var folders = new Array();
+var global_search = 1;
 var title_app_menu = '<table height="16px" align=center border=0 width=100% cellspacing=0 cellpadding=2>'+
 	'<tr><td align=left height=16px width="1%" nowrap class="table_top">&nbsp;'+
Index: /branches/2.0/expressoMail1_2/js/draw_api.js
===================================================================
--- /branches/2.0/expressoMail1_2/js/draw_api.js	(revision 3522)
+++ /branches/2.0/expressoMail1_2/js/draw_api.js	(revision 3676)
@@ -1028,5 +1028,5 @@
                 currentTab = ID;
                 openTab.type[ID] = 2;
-                            proxy_mensagens.get_msg(parseInt(folder.nextSibling.id),nextMsgBox,true,show_msg);
+                            proxy_mensagens.get_msg(folder.nextSibling.id,nextMsgBox,true,show_msg);
                 //cExecute("$this.imap_functions.get_info_msg&msg_number="+folder.nextSibling.id+"&msg_folder="+nextMsgBox, show_msg);
             };
@@ -1084,5 +1084,5 @@
                 openTab.type[ID] = 2;
                 //cExecute("$this.imap_functions.get_info_msg&msg_number="+folder.previousSibling.id+"&msg_folder=" + previousMsgBox, show_msg);
-                            proxy_mensagens.get_msg(parseInt(folder.previousSibling.id),previousMsgBox,true,show_msg);
+                            proxy_mensagens.get_msg(folder.previousSibling.id,previousMsgBox,true,show_msg);
             };
         }
