Index: /trunk/expressoMail1_2/setup/phpgw_es-es.lang
===================================================================
--- /trunk/expressoMail1_2/setup/phpgw_es-es.lang	(revision 4830)
+++ /trunk/expressoMail1_2/setup/phpgw_es-es.lang	(revision 4843)
@@ -596,4 +596,5 @@
 zip mails to import	expressoMail1_2	es-es	Archivo .zip o .eml:
 Show TO: in place of FROM: only in Automatic SEND folder	expressoMail1_2	es-es	Cambiar remitente por destinatário en la columna QIUEM solamente en la carpeta Enviado
+You cant manipulate messages from multiple folders on search	expressoMail1_2	es-es	Imposible manipular mensajes de varias carpetas a partir de una busqueda.
 View the user name in the header of the messages printed?	expressoMail1_2	es-es	Ver el nombre de usuario en el encabezado de los mensajes impresos?	
 Displays the user name in the header print email	expressoMail1_2	es-es	Muestra el nombre de usuario en el correo electrónico imprimir el encabezado 	
Index: /trunk/expressoMail1_2/setup/phpgw_en.lang
===================================================================
--- /trunk/expressoMail1_2/setup/phpgw_en.lang	(revision 4302)
+++ /trunk/expressoMail1_2/setup/phpgw_en.lang	(revision 4843)
@@ -447,4 +447,5 @@
 Valid Until	expressoMail1_2	en	Valid Until
 Serial Number	expressoMail1_2	en	Serial Number
-Send this mail as text plain	expressoMail1_2	en	Send this mail as text plain 
-The text format will be lost    expressoMail1_2 en	The text format will be lost 
+Send this mail as text plain	expressoMail1_2	en	Send this mail as text plain
+The text format will be lost	expressoMail1_2	en	The text format will be lost
+You cant manipulate messages from multiple folders on search	expressoMail1_2	en	You cant manipulate messages from multiple folders on search
Index: /trunk/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- /trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 4832)
+++ /trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 4843)
@@ -669,4 +669,5 @@
 Error exporting messages, try again latter	expressoMail1_2	pt-br	Não foi possível exportar as mensagens selecionadas.
 Exporting selected messages, this can take some time.	expressoMail1_2	pt-br	Exportando mensagens, isso pode levar algum tempo.
+You cant manipulate messages from multiple folders on search	expressoMail1_2	pt-br	Impossível manipular mensagens de múltiplas pastas a partir de uma busca.
 Report error    expressoMail1_2 pt-br   Reportar erro 
 Describe the problem to report to technical support (optional)  expressoMail1_2 pt-br   Descreva o problema para reportar para a equipe de suporte técnico (opcional) 
Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4832)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 4843)
@@ -3091,9 +3091,20 @@
 	{
 		$folder = $params['folder'];
-		$msgs_to_set = $params['msgs_to_set'];
+		$rowids_to_set = $params['msgs_to_set']; // contains the row ids
 		$flag = $params['flag'];
 		$return = array();
+		$return["rowids_to_set"] = $rowids_to_set;
+		$return["flag"] = $flag;
+
+		$msgs_to_set = '';
+		foreach (explode(',',$rowids_to_set) as $msg) {//extracting message ids
+			$pos = strpos($msg,'_');
+			if ($pos===false)
+				$msgs_to_set .= ','.$msg;
+			else
+				$msgs_to_set .= ','.substr($msg,0,$pos);
+		}
+		$msgs_to_set = substr($msgs_to_set,1);
 		$return["msgs_to_set"] = $msgs_to_set;
-		$return["flag"] = $flag;
 
 		if(!$this->mbox && !is_resource($this->mbox))
Index: /trunk/expressoMail1_2/js/drag_area.js
===================================================================
--- /trunk/expressoMail1_2/js/drag_area.js	(revision 4810)
+++ /trunk/expressoMail1_2/js/drag_area.js	(revision 4843)
@@ -63,7 +63,5 @@
 	
 		if(_button == 2 || _button == 3) {
-			var _checkb = Element("check_box_message_"+ msg_number);
-
-			var _checkb = Element(getTabPrefix() + "check_box_message_" + msg_number);
+			var _checkb = Element("check_box_message_" + msg_number + getTabSufix());
 
 			if(_checkb) {
@@ -98,5 +96,5 @@
 
 	var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
-	var _checkbox_element = Element(getTabPrefix()+"check_box_message_"+msg_number);
+	var _checkbox_element = Element("check_box_message_"+msg_number+getTabSufix());
 	if(_dragArea.from_list) {
 
@@ -180,5 +178,4 @@
 	var	_target = is_ie ? _event.srcElement : _event.target;
 	var _button = is_ie ? _event.button : _event.which;
-	var _tab_prefix = getTabPrefix();
 	var _msg_id;
 
@@ -195,5 +192,5 @@
 				for(var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++) {			
 					_msg_id = getMessageIdFromRowId(id_messages_to_drag[i]);
-					Element(_tab_prefix+"check_box_message_"+_msg_id).checked = false;
+					Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
 					changeBgColor(_event ,_msg_id);
 				}
@@ -247,5 +244,5 @@
 				for(var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++) {				
 					_msg_id = getMessageIdFromRowId(id_messages_to_drag[i]);
-					Element(_tab_prefix+"check_box_message_"+_msg_id).checked = false;
+					Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
 					changeBgColor(_event ,_msg_id);
 				}
Index: /trunk/expressoMail1_2/js/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/abas.js	(revision 4807)
+++ /trunk/expressoMail1_2/js/abas.js	(revision 4843)
@@ -383,11 +383,4 @@
 }
 
-function getTabPrefix() { // define o prefixo para os checkboxes das mensagens
-	if (typeof(currentTab)!='number')
-		return currentTab+"_";
-	else
-		return "";
-}
-
 function getMessageIdFromRowId(row_id) { // extrai o id da mensagem do id da linha
 	var p = row_id.search("_s");
@@ -407,2 +400,9 @@
 	}
 }
+
+function getTabSufix() {
+	if (typeof(currentTab)=='number')
+		return '';
+	else
+		return '_s' + numBox.toString();
+}
Index: /trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- /trunk/expressoMail1_2/js/common_functions.js	(revision 4822)
+++ /trunk/expressoMail1_2/js/common_functions.js	(revision 4843)
@@ -144,4 +144,5 @@
 	remove_className(tr_message, 'selected_msg');
 	add_className(tr_message, 'tr_msg_unread');
+	if( document.getElementById("td_message_unseen_"+msg_number) != null )
 	Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/unseen.gif' title='"+get_lang('Unseen')+"'>";
 }
@@ -151,4 +152,5 @@
 	remove_className(msg, 'selected_msg');
 	add_className(msg, 'flagged_msg');
+	if( document.getElementById("td_message_important_"+msg_number) != null )
 	Element("td_message_important_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
 }
@@ -158,4 +160,5 @@
 	remove_className(msg, 'selected_msg');
 	remove_className(msg, 'flagged_msg');
+	if( document.getElementById("td_message_important_"+msg_number) != null )
 	Element("td_message_important_"+msg_number).innerHTML = "&nbsp;&nbsp;&nbsp;";
 }
@@ -960,5 +963,6 @@
 		{
 			Element("check_box_message_"+main_list[i].id).checked = true;
-			add_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
+			add_className(Element(main_list[i].id), 'selected_msg'); // one by one to add only if does not exist yet
+			add_className(Element(main_list[i].id), 'selected_shortcut_msg'); // one by one to add only if does not exist yet
 		}
 	}
@@ -968,5 +972,6 @@
 		{
 			Element("check_box_message_"+main_list[i].id).checked = false;
-			remove_className(Element(main_list[i].id), 'selected_msg selected_shortcut_msg');
+			remove_className(Element(main_list[i].id), 'selected_msg'); // one by one to remove
+			remove_className(Element(main_list[i].id), 'selected_shortcut_msg'); // one by one to remove
 		}
 	}
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 4840)
+++ /trunk/expressoMail1_2/js/main.js	(revision 4843)
@@ -855,5 +855,5 @@
 	var main_list = main.childNodes;
 
-	var _tab_prefix = getTabPrefix();
+	var _check_box;
 	var selected_messages = '';
 	var selected_messages_by_shortcuts = '';
@@ -861,9 +861,8 @@
 	for (j; j<(main_list.length); j++)
 	{
-
-	check_box = Element(_tab_prefix + "check_box_message_" + getMessageIdFromRowId(main_list[j].id));
-	
-	if ( (check_box) && (check_box.checked) )
-		selected_messages += main_list[j].id + ',';
+		_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')
@@ -894,4 +893,42 @@
 	else
 		return selected_messages;
+}
+
+function get_selected_messages_folder(){
+	var _main;
+	var _main_list;
+	try{
+		_main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
+	}catch(e){
+	};
+
+	if (! _main)
+		_main = Element("tbody_box_"+numBox);
+
+	if (! _main)
+		_main = Element("tbody_box");
+
+	// Get all TR (messages) in tBody.
+	_main_list = _main.childNodes;
+
+	var _check_box;
+	var selected_messages_folder;
+//	var selected_messages_by_shortcuts = '';
+	var j = 0;
+	for (j; j<(_main_list.length); j++)
+	{
+
+		_check_box = Element("check_box_message_" + _main_list[j].id);
+
+		if ( (_check_box) && (_check_box.checked) && (_main_list[j].name) ) {
+			if (!selected_messages_folder)
+				selected_messages_folder = _main_list[j].name;
+			else {
+				if (selected_messages_folder!=_main_list[j].name)
+					return false;
+			}
+		}
+	}
+	return selected_messages_folder;
 }
 
@@ -2055,7 +2092,11 @@
 function set_messages_flag(flag, msgs_to_set){
 	var handler_set_messages_flag = function (data){
+		var _tab_sufix = getTabSufix();
+		var _chk_box;
+		var _fld_box;
 		if(!verify_session(data))
 			return;
-		var msgs_to_set = data.msgs_to_set.split(",");
+		var msgs_to_set = data.msgs_to_set.split(","); // messages ids
+		var rowids_to_set = data.rowids_to_set.split(","); // rows ids
 
 		if(!data.status) {
@@ -2063,6 +2104,6 @@
 			Element('chk_box_select_all_messages').checked = false;
 			for (var i = 0; i < msgs_to_set.length; i++) {
-				Element("check_box_message_" + msgs_to_set[i]).checked = false;
-				remove_className(Element(msgs_to_set[i]), 'selected_msg');
+				Element("check_box_message_" + rowids_to_set[i]).checked = false;
+				remove_className(Element(rowids_to_set[i]), 'selected_msg');
 			}
 			if(!data.msgs_unflageds)
@@ -2094,24 +2135,33 @@
 				}
 				proxy_mensagens.get_msg(msgs_to_set[i],current_folder, false, setFlag);
-
-
-			}
-			if(Element("check_box_message_" + msgs_to_set[i])){
+			}
+
+			_chk_box = Element("check_box_message_" + rowids_to_set[i]);
+			_fld_box = (_tab_sufix ? Element("check_box_message_" + msgs_to_set[i]) : null);
+			if(_chk_box){
 				switch(data.flag){
 					case "unseen":
-						set_msg_as_unread(msgs_to_set[i]);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						set_msg_as_unread(rowids_to_set[i]);
+						if (_fld_box)
+						    set_msg_as_unread(msgs_to_set[i]);
+						_chk_box.checked = false;
 						break;
 					case "seen":
-						set_msg_as_read(msgs_to_set[i], false);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						set_msg_as_read(rowids_to_set[i], false);
+						if (_fld_box)
+							set_msg_as_read(msgs_to_set[i]);
+						_chk_box.checked = false;
 						break;
 					case "flagged":
-						set_msg_as_flagged(msgs_to_set[i]);
-						document.getElementById("check_box_message_" + msgs_to_set[i]).checked = false;
+						set_msg_as_flagged(rowids_to_set[i]);
+						if (_fld_box)
+						    set_msg_as_flagged(msgs_to_set[i]);
+						_chk_box.checked = false;
 						break;
 					case "unflagged":
-						set_msg_as_unflagged(msgs_to_set[i]);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						set_msg_as_unflagged(rowids_to_set[i]);
+						if (_fld_box)
+						    set_msg_as_unflagged(msgs_to_set[i]);
+						_chk_box.checked = false;
 						break;
 				}
@@ -2122,10 +2172,21 @@
 
 	var folder = get_current_folder();
-	if (msgs_to_set == 'get_selected_messages')
+	if (msgs_to_set == 'get_selected_messages') {
 		var msgs_to_set = this.get_selected_messages();
+		if ( (msgs_to_set) && (msgs_to_set.match(/_s/)) ) {
+			folder = get_selected_messages_folder();
+			if (!folder) {
+				alert(get_lang("You cant manipulate messages from multiple folders on search"));
+				return;
+			}
+		}
+	}
 	else
 		folder = Element("input_folder_"+msgs_to_set+"_r").value;
 
 	if (msgs_to_set)
+		if (folder && proxy_mensagens.is_local_folder(folder))
+			expresso_local_messages.set_messages_flag(msgs_to_set, flag); //expresso_local_messages.set_messages_flag(msgs_to_set.replace(/_s[^,]*/g,""), flag);
+		else
 		cExecute ("$this.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, handler_set_messages_flag);
 	else
Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 4834)
+++ /trunk/expressoMail1_2/js/search.js	(revision 4843)
@@ -475,5 +475,5 @@
 				else
 					chk_onclick = "changeBgColor(event,"+uid_msg+");";
-				var td1 = '<input type="checkbox" onclick="' + chk_onclick + '" id="' + border_id + '_check_box_message_'+uid_msg+'"></input>';
+				var td1 = '<input type="checkbox" onclick="' + chk_onclick + '" id="check_box_message_'+tr.id+'"></input>';
 
 			}
@@ -504,5 +504,5 @@
 			{
 				td.setAttribute("width", colSizes[1][3]);
-				td.id = "td_message_important_"+uid_msg;
+				td.id = "td_message_important_"+tr.id;
 				if (aux.flag.match("F"))
 				{
Index: /trunk/expressoMail1_2/js/local_messages.js
===================================================================
--- /trunk/expressoMail1_2/js/local_messages.js	(revision 4827)
+++ /trunk/expressoMail1_2/js/local_messages.js	(revision 4843)
@@ -634,19 +634,25 @@
     this.init_local_messages();
 	var no_errors = true;
-    var msgs_to_set;
+	var rowids_to_set; // rows ids
+    var msgs_to_set; // messages ids
 	var one_message = false;
     if (msgs_number == 'get_selected_messages') {
-		var msgs_to_set = get_selected_messages();
-		msgs_to_set= msgs_to_set.split(",");
-    }
-    else { //Just one message
+		msgs_to_set = get_selected_messages();
+		rowids_to_set = msgs_to_set.split(",");
+		msgs_to_set = msgs_to_set.replace(/_s[^,]*/g,"").split(",");
+    }
+    else {
+		//message(s) sent to function
+		rowids_to_set = msgs_number.split(",");
+		msgs_to_set = msgs_number.replace(/_s[^,]*/g,"").split(",");
+		if (msgs_to_set.length==1) {
+			//Just one message
 	    one_message = true;
-		msgs_to_set = new Array();
-		msgs_to_set[0] = msgs_number;
+        }
     }
     for (var i in msgs_to_set) {
 			
 	var matches = '';//Messages comming from other tabs.
-	if(matches = this.parse_id_mail(msgs_to_set[i])) {
+	if(matches === this.parse_id_mail(msgs_to_set[i])) {
 	    msgs_to_set[i] = matches[1];
 	}
@@ -660,5 +666,5 @@
 	switch(flag) {
 	    case "unseen":
-			set_msg_as_unread(msgs_to_set[i]);
+			set_msg_as_unread(rowids_to_set[i]);
 			header["Unseen"] = "U";
 			mail["Unseen"] = "U";
@@ -667,5 +673,5 @@
 			break;
 	    case "flagged":
-			set_msg_as_flagged(msgs_to_set[i]);
+			set_msg_as_flagged(rowids_to_set[i]);
 			header["Flagged"] = "F";
 			mail["Flagged"] = "F";
@@ -677,5 +683,5 @@
 				no_errors = false;
 			else {
-			    set_msg_as_unflagged(msgs_to_set[i]);
+			    set_msg_as_unflagged(rowids_to_set[i]);
 			    header["Flagged"] = "N";
 				mail["Flagged"] = "N";
@@ -688,5 +694,5 @@
 			mail["Unseen"] = "N";
 			mail["header"]["Unseen"] = "N";
-			set_msg_as_read(msgs_to_set[i],true);
+			set_msg_as_read(rowids_to_set[i],true);
 			unseen = 0;
 			break;
@@ -715,6 +721,6 @@
 	rs.close();
 			
-	if(Element("check_box_message_" + msgs_to_set[i]))
-	    Element("check_box_message_" + msgs_to_set[i]).checked = false;
+	if(Element("check_box_message_" + rowids_to_set[i]))
+	    Element("check_box_message_" + rowids_to_set[i]).checked = false;
         var smail=connector.serialize(mail);
         smail =smail.replace(/([^'])'([^'])('?)/g,"$1''$2$3$3");
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 4839)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 4843)
@@ -3431,11 +3431,8 @@
 
 function changeBgColorToON(all_messages, begin, end){
-	var _tab_prefix = getTabPrefix();
-	var _msg_id;
 	for (begin; begin<=end; begin++)
 	{
-		_msg_id = getMessageIdFromRowId(all_messages[begin].id);
 		add_className(all_messages[begin], 'selected_msg');
-		Element(_tab_prefix + "check_box_message_" + _msg_id).checked = true;
+		Element("check_box_message_" + all_messages[begin].id).checked = true;
 	}
 }
@@ -3484,5 +3481,5 @@
 	else{
 		//if ( exist_className(actual_tr, 'selected_msg') )
-		if ( Element(getTabPrefix()+'check_box_message_' + msg_number).checked )
+		if ( Element('check_box_message_' + _element_id).checked )
 			add_className(actual_tr, 'selected_msg');
 		else
