Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 539)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 569)
@@ -412,4 +412,5 @@
 		$return['Size'] = $header->Size;
 		$return['reply_toaddress'] = $header->reply_toaddress;
+		$return['reuse_border'] = $params['reuse_border'];
 		
 		return $return;
Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 372)
+++ /trunk/expressoMail1_2/js/search.js	(revision 569)
@@ -301,5 +301,6 @@
 					var mailbox = aux[0];
 					var uid_msg = aux[5];
-					tr.id = mailbox + ";" + uid_msg;
+					tr.id = uid_msg;
+					tr.name = mailbox;
 					var td = document.createElement("TD");					
 					
@@ -308,5 +309,5 @@
 						td.style.width = "1%";					
 						var subject_encode = url_encode(aux[2]);
-						var td1 = '<input type="checkbox" id="check_box_message_'+tr.id.substr(tr.id.indexOf(';')+1)+'"></input>';
+						var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
 					}
 					if( j == 1){
@@ -350,5 +351,5 @@
 				}
 			}
-			aux.splice(0,(aux.length));	
+			aux.splice(0,(aux.length));
 
 		subject = tr.firstChild;
Index: /trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- /trunk/expressoMail1_2/js/common_functions.js	(revision 566)
+++ /trunk/expressoMail1_2/js/common_functions.js	(revision 569)
@@ -111,4 +111,5 @@
 	remove_className(tr_message, 'selected_msg');
 	add_className(tr_message, 'tr_msg_read');
+	purgeCache();
 	return true;
 }
@@ -520,7 +521,6 @@
 }  
 
-
-function Element(element){
-	return document.getElementById(element);
+function Element (el) {
+	return	document.getElementById(el);
 }
 
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 565)
+++ /trunk/expressoMail1_2/js/main.js	(revision 569)
@@ -118,5 +118,6 @@
 
 		//Change msg class to read.
-		set_msg_as_read(msg_info['msg_number'], true);
+		if (msg_info.Unseen == 'U')
+			set_msg_as_read(msg_info['msg_number'], true);
 		
 		if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
@@ -162,4 +163,6 @@
 			update_quota(get_current_folder());
 			}
+			 if(data.new_msgs > 0 || data.msgs_to_delete.length > 0)
+				purgeCache();
 		}
 		update_menu();
@@ -271,5 +274,5 @@
 				write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
 		}
-	
+
 		selected_messages = selected_messages.split(",");
 		for (i = 0; i < selected_messages.length; i++){
@@ -280,4 +283,18 @@
 
 	if (selected_messages){
+		var selected_param = "";
+		if (selected_messages.indexOf(',') != -1)
+		{
+			selected_msg_array = selected_messages.split(",");
+			for (i = 0; i < selected_msg_array.length; i++){
+				var tr = Element(selected_msg_array[i]);
+			        selected_param += ','+tr.name+';'+tr.id;
+			}
+		}
+		else
+		{
+			var tr=Element(selected_messages);
+			selected_param=tr.name+';'+tr.id;
+		}
 		var params = "";
 		if (!new_folder && parseInt(preferences.save_deleted_msg)){ 
@@ -286,5 +303,6 @@
 			params = "&delete=true";
 		}			
-		params += "&selected_messages="+url_encode(selected_messages);
+		
+		params += "&selected_messages="+url_encode(selected_param);
 		if(new_folder) {
 			params += "&new_folder="+url_encode(new_folder);
@@ -406,16 +424,7 @@
 	for (j; j<(main_list.length); j++)
 	{
-	if (main_list[j].id.indexOf(';') == -1)
-	{
-		check_box = Element("check_box_message_"+main_list[j].id);
-		if ( (check_box) && (check_box.checked) )
-			selected_messages += main_list[j].id + ',';
-	}
-	else
-	{ // Message from search tab
-		check_box = Element("check_box_message_"+main_list[j].id.substr(main_list[j].id.indexOf(';')+1));
-		if ( (check_box) && (check_box.checked) )
-			selected_messages += main_list[j].id.substr(main_list[j].id.indexOf(';')+1) + ',';
-	}
+	check_box = Element("check_box_message_"+main_list[j].id);
+	if ( (check_box) && (check_box.checked) )
+		selected_messages += main_list[j].id + ',';
 		
 		if (preferences.use_shortcuts == '1')
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 470)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 569)
@@ -39,5 +39,5 @@
 			}
 		}
-		cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, update_tree_folders);
+		cExecute ("$this.imap_functions.get_folders_list", update_tree_folders);
 		return;
 	}
@@ -757,5 +757,33 @@
 	img_next_msg.title = get_lang('Next');
 	img_next_msg.style.cursor = 'pointer';
-	img_next_msg.onclick = function () {cExecute ("$this.imap_functions.get_info_next_msg&msg_number="+ info_msg.msg_number + "&msg_folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type +  "&search_box_type="+ search_box_type +"&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)};
+
+	// Old
+	//img_next_msg.onclick = function () {cExecute ("$this.imap_functions.get_info_next_msg&msg_number="+ info_msg.msg_number + "&msg_folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type +  "&search_box_type="+ search_box_type +"&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)};
+	var folder = document.getElementById(ID.substr(0, ID.indexOf('_')));
+	if (!folder)
+	        delete_border(ID);
+	if (folder.nextSibling)
+	{
+		var inbox = folder.nextSibling.name;
+	        if (inbox)
+	                info_msg.msg_folder = inbox;
+
+		var next_msg = folder.nextSibling.id;
+		img_next_msg.onclick = function()
+		{
+			cExecute("$this.imap_functions.get_info_msg&msg_number="+next_msg+"&msg_folder=" + info_msg.msg_folder+"&reuse_border="+ID, show_msg);
+		};
+	}
+	else
+		img_next_msg.onclick = function()
+		{
+			current_page++;
+			msg_range_end = (current_page*preferences.max_email_per_page);
+			msg_range_begin = (msg_range_end-(preferences.max_email_per_page)+1);
+			kill_current_box();
+			cExecute ('$this.imap_functions.get_range_msgs2&folder='+get_current_folder()+'&msg_range_begin='+msg_range_begin+'&msg_range_end='+msg_range_end+'&sort_box_reverse=1', function handler(data){draw_box(data, get_current_folder());})
+			delete_border(ID);
+		};
+
 	var img_space = document.createElement("SPAN");
 	img_space.innerHTML = "&nbsp;";
@@ -765,5 +793,28 @@
 	img_previous_msg.title = get_lang('Previous');
 	img_previous_msg.style.cursor = 'pointer';
-	img_previous_msg.onclick = function () {cExecute ("$this.imap_functions.get_info_previous_msg&msgs_number="+ info_msg.msg_number + "&folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type+ "&search_box_type="+ search_box_type + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)}
+
+	//Old
+	//img_previous_msg.onclick = function () {cExecute ("$this.imap_functions.get_info_previous_msg&msgs_number="+ info_msg.msg_number + "&folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type+ "&search_box_type="+ search_box_type + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)}
+	folder = document.getElementById(ID.substr(0, ID.indexOf('_')));
+	if (!folder)
+	        delete_border(ID);
+	if (folder.previousSibling)
+	{
+		var inbox = folder.previousSibling.name;
+		if (inbox)
+			info_msg.msg_folder = inbox;
+
+		var previous_msg = folder.previousSibling.id;
+		img_previous_msg.onclick = function()
+		{
+			cExecute("$this.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + info_msg.msg_folder+"&reuse_border="+ID, show_msg);			
+		};
+	}
+	else
+		img_previous_msg.onclick = function()
+		{
+			delete_border(ID);
+		};
+
 	next_previous_msg_td.appendChild(img_previous_msg);
 	next_previous_msg_td.appendChild(img_space);
Index: /trunk/expressoMail1_2/js/connector.js
===================================================================
--- /trunk/expressoMail1_2/js/connector.js	(revision 446)
+++ /trunk/expressoMail1_2/js/connector.js	(revision 569)
@@ -154,5 +154,5 @@
 					return null;
 			}
-	
+
 			return str_data;
 		}
@@ -268,5 +268,4 @@
 					break;
 			}
-			
 			return data;
 		}
@@ -345,6 +344,7 @@
 									document.getElementById("debug_controller").innerHTML += oxmlhttp.responseText;
 									document.getElementById("debug_controller").innerHTML += "<br>-------------------------------------------------------------------------------------<br>";
-								}									
+								}
 								handler(data);
+								addToCache(id,data);
 								delete _thisObject.requests[id];								
 								_thisObject.requests[id] = null;
@@ -475,4 +475,71 @@
 	var id = null;
 
+	var connectorCache = {
+		'valid' : [],
+		'result' : []
+	};
+	var acertos = 0;
+	var naoacertos = 0;
+	var expurgatedCache = new Array(); // Data to purge from cache
+
+	function queryConnectorCache(url,handler){
+		if (connectorCache.valid[url])
+		{
+			handler(connectorCache.result[url]);
+			return true;
+		}
+		else
+			return false;
+	}
+	function purgeCache(){
+		var i;
+		for (i=0; i<= expurgatedCache.length; i++)
+		{
+			connectorCache.valid[expurgatedCache[i]] = false;
+	   		delete connectorCache.result[expurgatedCache[i]];
+		}
+	}
+	function addToCache(id,data){
+		if (preferences.use_cache != 'True')
+			return false;
+		var func = id.substr(id.lastIndexOf('.')+1);
+		if (func.indexOf('&') > 0)
+			func = func.substr(0,func.indexOf('&'));
+		switch (func){
+			// functions that enters in cache
+			case 'get_preferences':
+			case 'getSharedUsersFrom':
+			case 'get_organizations':
+			case 'get_catalogs':
+			case 'get_dropdown_contacts':
+			case 'get_cc_contacts':
+			case 'get_cc_groups':
+			case 'get_info_msg':
+			case 'getUsersByEmail':
+			case 'br':
+			case 'search_for':
+			case 'quicksearch':
+				connectorCache.valid[id] = true;
+				connectorCache.result[id] = data;
+				break;
+			// function that needs expire
+			case 'get_range_msgs2':
+			case 'get_folders_list':
+			case 'search_msg':
+				connectorCache.valid[id] = true;
+                                connectorCache.result[id] = data;
+				var i = expurgatedCache.length;
+				expurgatedCache[i+1] = id;
+				break;
+			//functions that expires the cache
+			case 'move_messages':
+			case 'getReturnExecuteForm':
+			case 'set_messages_flag':
+				purgeCache();
+			default: // no cache
+				break;
+		}
+	}
+
 	// 	Function executes AJAX
 	// 	cExecute (url, handler, params)
@@ -490,18 +557,20 @@
 			return;
 		}
-		
+
 		url = DEFAULT_URL + url;
-			
-		if(params)		 
+
+		if (queryConnectorCache(url,handler))
+			return;
+
+		if(params)
 			method = "POST";
-			 	
-		 else 
+		else
 			method = "GET";
-			 
-		 id = url;
+
+		id = url;
 		connector.newRequest(id, url, method, handler, params);
 	}
-	
-	// This function executes submit values to Controller (POST)
+
+// This function executes submit values to Controller (POST)
 	// The return is void.
 	// 	cExecuteForm (url, form)
Index: /trunk/expressoMail1_2/index.php
===================================================================
--- /trunk/expressoMail1_2/index.php	(revision 564)
+++ /trunk/expressoMail1_2/index.php	(revision 569)
@@ -95,5 +95,8 @@
     		'auto_save_draft'					=> $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['auto_save_draft'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['auto_save_draft'] : "0",
    			'use_dynamic_contacts' 				=> $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts'] : "0",
-   			'number_of_contacts' 				=> $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0"
+			'number_of_contacts' 				=> $current_config['expressoMail_Number_of_dynamic_contacts'] ? $current_config['expressoMail_Number_of_dynamic_contacts'] : "0",
+		'use_cache' 						=> $current_config['expressoMail_enable_cache']
+
+
     		
 	);
@@ -128,4 +131,5 @@
     
     $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] = $current_config['expressoMail_enable_log_messages'];
+	
     // Begin Set Anti-Spam options.
     $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] = $current_config['expressoMail_command_for_ham'];
Index: /trunk/expressoMail1_2/templates/default/config.tpl
===================================================================
--- /trunk/expressoMail1_2/templates/default/config.tpl	(revision 413)
+++ /trunk/expressoMail1_2/templates/default/config.tpl	(revision 569)
@@ -21,4 +21,13 @@
      </select>&nbsp;&nbsp;&nbsp;path: /home/expresso/mail_senders.log
     </td>
+   </tr>
+   <tr bgcolor="{row_on}">
+   <td>{lang_Do_you_want_to_cache_php_requests_in_javascript?}</td>
+   <td>
+   <select name="newsettings[expressoMail_enable_cache]">
+   <option value=""{selected_expressoMail_enable_cache_False}>{lang_No}</option>
+   <option value="True"{selected_expressoMail_enable_cache_True}>{lang_Yes}</option>
+   </select>
+   </td>
    </tr>
    <tr bgcolor="{row_off}">
