Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2684)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2714)
@@ -2983,5 +2983,5 @@
 		{
 			$params['status'] = 'false';
-			$params['command_to_exec'] = "delete_border('". $reuse_border ."');";
+			$params['delete_border'] = $reuse_border;
 			return $params;
 		}
@@ -3020,5 +3020,5 @@
 		{
 			$params['status'] = 'false';
-			$params['command_to_exec'] = "delete_border('". $reuse_border ."');";
+			$params['delete_border'] = $reuse_border;
 			return $params;
 		}
Index: /trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2699)
+++ /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2714)
@@ -1036,5 +1036,5 @@
     td_element3.setAttribute("width", "20%");
     var _onclick = function(){
-	InfoContact.hide();proxy_mensagens.get_msg(headers_msgs.msg_number, msg_folder,true, show_msg);
+	InfoContact.hide();proxy_mensagens.get_msg(headers_msgs, msg_folder,true, show_msg);
     };
     td_element3.onclick = _onclick;
@@ -1140,5 +1140,5 @@
 }
 
-
+folderHeaders = [];
 // Draw the inbox and another folders
 function draw_box(headers_msgs, msg_folder, alternate){
@@ -1155,4 +1155,5 @@
     openTab.imapBox[numBox] = msg_folder;
     openTab.type[numBox] = 0;
+    folderHeaders[msg_folder] = headers_msgs;
 
     table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
@@ -1363,6 +1364,5 @@
     }
     else if(msg_folder && msg_number){
-	expresso.connector.cacheNextRequest();
-	cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), show_msg);
+	proxy_mensagens.get_msg(headers_msgs, url_encode(msg_folder),true, show_msg);
 	Element('msg_folder').value = '';
 	Element('msg_number').value = '';
Index: /trunk/expressoMail1_2/js/jscode/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/abas.js	(revision 2642)
+++ /trunk/expressoMail1_2/js/jscode/abas.js	(revision 2714)
@@ -1,2 +1,22 @@
+var openTab = {
+	'type' : [], // 8 types of tabs, further info. see expressolivre.org/dev/wiki/mail/Documentacao
+	'content_id' : [],
+	'imapUid' : [], // Stores the imap email number of current tab
+	'countFile' : [0,0,0,0,0,0,0,0,0,0], // Stores the number of files attached in current tab
+	'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
+};
+var tabTypes = {
+	'new':4,
+	'forward':6,
+	'reply_with_history':7,
+	'reply_to_all_with_history':7,
+	'reply_without_history':7,
+	'reply_to_all_without_history':7,
+	'edit':5
+};
+var currentTab,numBox = 0; // Open Tab and num of mailboxes opened at context
+
 function setBorderAttributes(ID)
 {
Index: /trunk/expressoMail1_2/js/jscode/filters.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/filters.js	(revision 2673)
+++ /trunk/expressoMail1_2/js/jscode/filters.js	(revision 2714)
@@ -74,5 +74,5 @@
 
 	cfilterSh.prototype.list_rules = function(){
-		if(filter.criticalError || filter.rulest.length == 0)
+		if(filter.criticalError)
 			return false;
 		else
Index: /trunk/expressoMail1_2/js/jscode/main.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/main.js	(revision 2656)
+++ /trunk/expressoMail1_2/js/jscode/main.js	(revision 2714)
@@ -290,5 +290,5 @@
 	if (typeof(msg_info) != 'object')
 		alert(get_lang("Error in show_msg param is not object"));
-	
+
 	if (msg_info.status_get_msg_info == 'false')
 	{
@@ -296,5 +296,4 @@
 		return;
 	}
-	
 	var handler_sendNotification = function(data){
 		if (data)
@@ -303,46 +302,39 @@
 			write_msg(get_lang("Error in SMTP sending read confirmation."));
 	};
-    
+
 	if(msg_info.source)
 	{
-        // Abrindo um e-mail criptografado
-        // Verifica se existe o objeto applet
-        if (!Element('cert_applet')){
-            // se não existir, mostra mensagem de erro.
-            write_msg(get_lang('The preference "%1" isn\'t enabled.', get_lang('Enable digitally sign/cipher the message?')));
-        } else {
-            // se existir prepara os dados para serem enviados e chama a
-            // operação na applet
-
-            expresso.connector.showProgressBar();
-
-           // if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
-            /*	var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), "");
-                if (confNotification)*/
-            //        cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
-           // }
-
-            Element('cert_applet').doButtonClickAction('decript',
-                                                        msg_info.msg_number,
-                                                        msg_info.source,
-                                                        msg_info.msg_folder); // Passa os dados para a applet
-        }
+		// Abrindo um e-mail criptografado
+		// Verifica se existe o objeto applet
+		if (!Element('cert_applet')){
+			// se não existir, mostra mensagem de erro.
+			write_msg(get_lang('The preference "%1" isn\'t enabled.', get_lang('Enable digitally sign/cipher the message?')));
+		} else {
+			// se existir prepara os dados para serem enviados e chama a
+			// operação na applet
+
+			expresso.connector.showProgressBar();
+
+			// if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
+			/*	var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), "");
+				if (confNotification)*/
+			//        cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
+			// }
+
+			Element('cert_applet').doButtonClickAction('decript',
+					msg_info.msg_number,
+					msg_info.source,
+					msg_info.msg_folder); // Passa os dados para a applet
+		}
 		return;
 
 	}
 
-
-	if (msg_info.status_get_msg_info == 'false')
-	{
-		write_msg(get_lang("Problems reading your message")+ ".");
-		return;
-	}
-
 	if (msg_info.status == 'false'){
-		eval(msg_info.command_to_exec);
+		delete_border(msg_info.reuse_border);
 	}
 	else{
-        var ID = msg_info.original_ID ? msg_info.original_ID : msg_info.msg_number;
-        var id_msg_read = ID+"_r";
+		var ID = msg_info.original_ID ? msg_info.original_ID : msg_info.msg_number;
+		var id_msg_read = ID+"_r";
 
 		if (preferences.use_shortcuts == '1')
@@ -350,40 +342,30 @@
 		// Call function to draw message
 		// If needed, delete old border
-		if (openTab.type[currentTab] == 2 || openTab.type[currentTab] == 3)
-			delete_border(currentTab,'false');
-
-		
-		if(Element("border_id_" + id_msg_read)) 
-			alternate_border(id_msg_read);		
-		else {
-			var border_id = create_border(msg_info.subject, id_msg_read);
-			if(border_id)
+		if(currentTab)
+		{
+			draw_message(msg_info,currentTab);
+			var unseen_sort = document.getElementById('span_flag_UNSEEN').getAttribute('onclick');
+			unseen_sort = unseen_sort.toString();
+			if ( !(unseen_sort.indexOf("'UNSEEN' == 'UNSEEN'") < 0) )
 			{
-				openTab.type[border_id] = 2;
-				draw_message(msg_info,border_id);
-				var unseen_sort = document.getElementById('span_flag_UNSEEN').getAttribute('onclick');
-				unseen_sort = unseen_sort.toString();
-				if ( !(unseen_sort.indexOf("'UNSEEN' == 'UNSEEN'") < 0) )
-				{
-					var sort_type = sort_box_type;
-					sort_box_type = null;
-					sort_box('UNSEEN', sort_type);
-				}
-			}
-			else
-				return;
-		}
+				var sort_type = sort_box_type;
+				sort_box_type = null;
+				sort_box('UNSEEN', sort_type);
+			}
+		}
+		else
+			return;
 
 		var domains = "";
 		if ((msg_info.DispositionNotificationTo) && (!msg_is_read(ID) || (msg_info.Recent == 'N')))
-		{			
+		{
 			if (preferences.notification_domains != undefined && preferences.notification_domains != "")
-            {
+			{
 				domains = preferences.notification_domains.split(',');
-            }
+			}
 			else
-			{				
+			{
 				var confNotification = true;
-			 }
+			}
 			for (var i = 0; i < domains.length; i++)
 				if (msg_info.DispositionNotificationTo.match(domains[i]+">"))
@@ -392,7 +374,6 @@
 					break;
 				}
-				if (confNotification == undefined)
-					var confNotification = confirm(get_lang("The sender:\n%1\nwaits your notification of reading. Do you want to confirm this?",msg_info.DispositionNotificationTo), "");
-
+			if (confNotification == undefined)
+				var confNotification = confirm(get_lang("The sender:\n%1\nwaits your notification of reading. Do you want to confirm this?",msg_info.DispositionNotificationTo), "");
 			if (confNotification)
 				cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), handler_sendNotification);
@@ -401,10 +382,10 @@
 		if (!msg_is_read(ID))
 		{
-            set_msg_as_read(ID, true);
+			set_msg_as_read(ID, true);
 			if (msg_info.cacheHit || (!proxy_mensagens.is_local_folder(get_current_folder()) && msg_info.original_ID))
-            {
+			{
 				set_message_flag(ID, "seen"); // avoid caducous (lazy) data
-            }
-        }
+			}
+		}
 	}
 }
Index: /trunk/expressoMail1_2/js/jscode/messages_controller.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2676)
+++ /trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2714)
@@ -20,14 +20,24 @@
 	};
 
-	messages_proxy.prototype.get_msg = function(msg_number,msg_folder,set_flag,call_back) {
+	messages_proxy.prototype.get_msg = function(header,msg_folder,set_flag,call_back,deleteTab) {
 		if(this.is_local_folder(msg_folder)) {
 			if(set_flag)
 //				expresso_local_messages.set_messages_flag(msg_number,"seen");
-			var data = expresso_local_messages.get_local_mail(msg_number);	
+			var data = expresso_local_messages.get_local_mail(header.msg_number);	
 
 			eval("call_back(data)");
 		}else {
 			expresso.connector.cacheNextRequest();
-			cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), call_back);
+			cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+ header.msg_number + "&msg_folder=" + current_folder, call_back);
+			var id_msg_read = header.msg_number+"_r";
+
+			if (openTab.type[deleteTab] == 2)
+				delete_border(deleteTab);
+			currentTab = create_border(header.subject, id_msg_read);
+			if(currentTab)
+			{
+				openTab.type[currentTab] = 2;
+				draw_message_header(header,currentTab);
+			}
 		}
 	};
Index: /trunk/expressoMail1_2/js/jscode/draw_api_messages.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2708)
+++ /trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2714)
@@ -1,22 +1,2 @@
-var openTab = {
-	'type' : [], // 8 types of tabs, further info. see expressolivre.org/dev/wiki/mail/Documentacao
-	'content_id' : [],
-	'imapUid' : [], // Stores the imap email number of current tab
-	'countFile' : [0,0,0,0,0,0,0,0,0,0], // Stores the number of files attached in current tab
-	'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
-};
-var tabTypes = {
-	'new':4,
-	'forward':6,
-	'reply_with_history':7,
-	'reply_to_all_with_history':7,
-	'reply_without_history':7,
-	'reply_to_all_without_history':7,
-	'edit':5
-};
-var currentTab,numBox = 0; // Open Tab and num of mailboxes opened at context
-
 // Objeto Map, talvez o ideal fosse adicionar este objeto Ã  Api do egroupware, e carregÃ¡-lo
 // aqui no expressoMail.
@@ -80,5 +60,5 @@
 }
 
-function createNxtPrevButtons(info_msg,ID,folder_id){
+function createNxtPrevButtons(msg_folder,ID,folder_id){
 	var next_previous_msg_td = createAndSet("TD",[ "noWrap", "align", "width" ], [ "true", "right", "40px"]);
 	var img_next_msg = createAndSet("IMG", [ 'id', 'src', 'title' ], [
@@ -91,5 +71,5 @@
 	if (folder){ // mensagem local criptografada nao tem ID da pasta local
 		if (folder.nextSibling){
-			var nextMsgBox = folder.nextSibling.name?folder.nextSibling.name:info_msg.msg_folder;
+			var nextMsgBox = folder.nextSibling.name?folder.nextSibling.name:msg_folder;
 
 			if (nextMsgBox == "INBOX/decifradas")// teste para ver se a mensagem vem da pasta oculta decifradas
@@ -98,7 +78,14 @@
 			img_next_msg.onclick = function()
 			{
-				currentTab = ID;
-				openTab.type[ID] = 2;
-				proxy_mensagens.get_msg(folder.nextSibling.id,nextMsgBox,true,show_msg);
+				openTab.type[currentTab] = 2;
+				if ( nextMsgBox == undefined )
+				       nextMsgBox = current_folder;
+				var allHeaders = folderHeaders[nextMsgBox];
+				for (i in allHeaders)
+					if (allHeaders[i].msg_number == folder.nextSibling.id){
+						var nextHeader = allHeaders[i];
+						break;
+					}
+				proxy_mensagens.get_msg(nextHeader,nextMsgBox,true,show_msg,currentTab);
 			};
 		}
@@ -107,5 +94,4 @@
 			img_next_msg.src = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/down.gray.button.png';
 			img_next_msg.style.cursor = 'default';
-
 		}
 	}
@@ -114,5 +100,5 @@
 		img_next_msg.src = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/down.gray.button.png';
 		img_next_msg.style.cursor = 'default';
-		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
+		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
 		{
 			img_next_msg.onclick = function()
@@ -137,5 +123,5 @@
 		if (folder.previousSibling)
 		{
-			var previousMsgBox = folder.previousSibling.name?folder.previousSibling.name:info_msg.msg_folder;
+			var previousMsgBox = folder.previousSibling.name?folder.previousSibling.name:msg_folder;
 
 			if (previousMsgBox == "INBOX/decifradas") // teste para ver se a mensagem vem da pasta oculta decifradas
@@ -144,7 +130,14 @@
 			img_previous_msg.onclick = function()
 			{
-				currentTab = ID;
-				openTab.type[ID] = 2;
-				proxy_mensagens.get_msg(folder.previousSibling.id,previousMsgBox,true,show_msg);
+				openTab.type[currentTab] = 2;
+				if ( previousMsgBox == undefined )
+				       previousMsgBox = current_folder;
+				var allHeaders = folderHeaders[previousMsgBox];
+				for (i in allHeaders)
+					if (allHeaders[i].msg_number == folder.previousSibling.id){
+						var previousHeader = allHeaders[i];
+						break;
+					}
+				proxy_mensagens.get_msg(previousHeader,previousMsgBox,true,show_msg,currentTab);
 			};
 		}
@@ -159,5 +152,5 @@
 		img_previous_msg.src = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/up.gray.button.png';
 		img_previous_msg.style.cursor = 'default';
-		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
+		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
 		{
 			img_previous_msg.onclick = function()
@@ -282,5 +275,5 @@
 	}
 
-	var next_previous_msg_td = createNxtPrevButtons(info_msg,ID,folder_id);
+	var next_previous_msg_td = createNxtPrevButtons(info_msg.msg_folder,ID,folder_id);
 	if (typeof(next_previous_msg_td) == 'undefined')
 		return false;
@@ -298,7 +291,7 @@
 		_name = info_msg.from.email.length > _maxChar ? info_msg.from.email.substring(0,_maxChar) + "..." : info_msg.from.email;
 
-	td.innerHTML = _name.bold() + ', ' + info_msg.smalldate;
-	if (info_msg.attachments.length > 0)
-		td.innerHTML += "&nbsp<img style='cursor:pointer' onclick='javascript:Element(\"option_hide_more_"+ID+"\").onclick()' src ='" + URL_SERVER + "expressoMail1_2/templates/"+template+"/images/clip.gif' title='"+info_msg.attachments.names+"'>";
+	td.innerHTML = _name.bold() + ', ' + info_msg.udate;
+	if (info_msg.attachment.names.length > 0)
+		td.innerHTML += "&nbsp<img style='cursor:pointer' onclick='javascript:Element(\"option_hide_more_"+ID+"\").onclick()' src ='" + URL_SERVER + "expressoMail1_2/templates/"+template+"/images/clip.gif' title='"+info_msg.attachment.names+"'>";
 
 	if (typeof(info_msg.signature) == 'string')
@@ -321,5 +314,10 @@
 		var option_hide_more = createAndSet("SPAN",['class','value','id'],['message_options','more_options','option_hide_more_'+ID],get_lang('show details'));
 		option_hide_more.onclick = function(){
-			var _height = Element("div_message_scroll_"+ID).style.height;
+			try{
+				var _height = Element("div_message_scroll_"+ID).style.height;
+			}
+			catch(e){
+				return;
+			}
 			_height = parseInt(_height.replace("px",""));
 			var _offset = 35;
@@ -464,17 +462,30 @@
 	return true;
 }
-function draw_message(info_msg, ID){
-	var content = document.getElementById('content_id_' + ID);
+
+function draw_message_header(header,border_id){
 	var defaultWidth = document.body.offsetWidth - 37;
 	if(Element("folderscol").style.display != 'none')
 		defaultWidth -= Element("folderscol").offsetWidth;
 
-
-	var table_message = createAndSet("TABLE",['border','width'],["0",defaultWidth]);
+	var table_message = createAndSet("TABLE",['id','border','width'],['table_message_'+border_id,"0",defaultWidth]);
+	table_message.id = 'table_message_'+border_id;
 	var tbody_message = document.createElement("TBODY");
-
-	if (!make_options_message(info_msg,tbody_message))
+	if (!make_options_message(header,tbody_message))
 		return;
 
+	table_message.appendChild(tbody_message);
+	var content = document.getElementById('content_id_' + border_id);
+	content.appendChild(table_message);
+	loading_img = content.appendChild(loading_img);
+}
+
+
+function draw_message(info_msg, ID){
+	var defaultWidth = document.body.offsetWidth - 37;
+	if(Element("folderscol").style.display != 'none')
+		defaultWidth -= Element("folderscol").offsetWidth;
+
+	var table_message = Element('table_message_'+ID);
+	var tbody_message = table_message.childNodes[0];
 
 	var tbody_message_others_options = document.createElement("TBODY");
@@ -658,5 +669,4 @@
 	div.style.background = 'WHITE';
 	div.style.height = document.body.clientHeight - offset - 125;
-	content.style.height = document.body.clientHeight - offset - 90;
 	div.style.overflow = "auto";
 	div.style.width = defaultWidth - (is_ie ? 5 : 0);
@@ -714,7 +724,9 @@
 	}
 
-	table_message.appendChild(tbody_message);
-	content.appendChild(table_message);
+
 	var msg_number = createAndSet("INPUT",['id','type','value'],["msg_number_" + ID, "hidden", info_msg.msg_number]);
+	var content = document.getElementById('content_id_' + ID);
+	loading_img = content.removeChild( loading_img );
+	content.style.height = document.body.clientHeight - offset - 90;
 	content.appendChild(msg_number);
 	//////////////////////////////////////////////////////////////////////////////////////////////////////
Index: /trunk/expressoMail1_2/js/jscode/globals.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/globals.js	(revision 2712)
+++ /trunk/expressoMail1_2/js/jscode/globals.js	(revision 2714)
@@ -70,2 +70,5 @@
 var wfolders;
 var use_spam_filter;
+
+var loading_img = document.createElement( 'center' );
+loading_img.appendChild( createAndSet("IMG",['src','style'],[URL_SERVER+'phpgwapi/templates/'+template+'/images/loading.gif','padding-top: 20px']) );
