Index: /trunk/expressoMail1_2/js/search.js
===================================================================
--- /trunk/expressoMail1_2/js/search.js	(revision 128)
+++ /trunk/expressoMail1_2/js/search.js	(revision 156)
@@ -39,5 +39,5 @@
 			var call_form_search = EsearchE.mount_form();
 			div_form_search.appendChild(call_form_search);
-			form_search.appendChild(div_form_search);	
+			form_search.appendChild(div_form_search);
 
 		}	
@@ -159,25 +159,107 @@
 
 	}
+	//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 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 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 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 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;
+	}
+
 	// Form resultado;
-	searchE.prototype.mount_result = function(data){
-		//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;
-		}
-
+	searchE.prototype.mount_result = function(data,sort_type){
 		var nw_array = new Array;
-		data = data.substr(2, data.length - 4);
-		var var_tmp  = data.split("####");
+		var var_tmp = data.substr(2, data.length - 4);
+		var_tmp  = var_tmp.split("####");
 		var cont = parseInt(0);
-		var_tmp.sort(date_comp);
+		if (sort_type == 'SORTDATE')
+			var_tmp.sort(date_comp);
+		if (sort_type == 'SORTBOX')
+			var_tmp.sort(box_comp);	
+		if (sort_type == 'SORTSUBJECT')
+			var_tmp.sort(subject_comp);	
+		if (sort_type == 'SORTWHO')
+			var_tmp.sort(who_comp);	
+		if (sort_type == 'SORTSIZE')
+			var_tmp.sort(size_comp);	
+		
 		for(var i=0; i < var_tmp.length; i++){
 			if(var_tmp[i] != ""){
@@ -186,7 +268,9 @@
 			}
 		}
+		search_tabs += 1;
+		var border_id = create_border(get_lang("Search Results"), "search_" + search_tabs);
 		var table = document.createElement("TABLE");
-			table.id    = "table_result";
-			table.width = "100%";
+		table.id    = "table_result_" + search_tabs;
+		table.width = "100%";
 
 /*		if(is_ie){
@@ -226,5 +310,4 @@
 			var aux = nw_array[i].split("--");
 			}
-			
 			for(var j=0 ; j < aux.length ; j++){
 					var mailbox = aux[0];
@@ -232,7 +315,12 @@
 					var td = document.createElement("TD");					
 					
-				if( j <= 4){
+				if( j <= 5){
 					if( j == 0){
-						td.style.width = "20%";					
+						td.style.width = "1%";					
+						var subject_encode = url_encode(aux[2]);
+						var td1 = '<input type="checkbox" id="check_box_message_'+aux[5]+'" name="teste"></input>';
+					}
+					if( j == 1){
+						td.style.width = "19%";					
 						var nm_box = aux[0].split(cyrus_delimiter);
 						var td1 = nm_box.pop();
@@ -243,10 +331,10 @@
 						}
 					}
-					if( j == 1){
+					if( j == 2){
 						var subject_encode = url_encode(aux[2]);
 						td.width = "20%";					
 						var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
 					}
-					if( j == 2){
+					if( j == 3){
 						var subject_encode = url_encode(aux[2]);
 						td.width = "40%";					
@@ -254,10 +342,10 @@
 
 					}
-					if( j == 3){
+					if( j == 4){
 						td.width = "10%";					
 						td.align = "center";
 						var td1  = aux[3];
 					}
-					if( j == 4){
+					if( j == 5){
 						td.width = "10%";
 						td.align = "center";
@@ -274,6 +362,4 @@
 		table.appendChild(tbody);
 		
-		search_tabs += 1;
-		var border_id = create_border(get_lang("Search Results"), "search_" + search_tabs);
 		var content = document.getElementById('content_id_' + "search_" + search_tabs);	
 		if(is_ie)
@@ -288,25 +374,53 @@
 		tr_element = document.createElement("TR");
 		tr_element.className = "message_header";
+		td_element0 = document.createElement("TD");
+		td_element0.setAttribute("width", "1%");
+		chk_box_element = document.createElement("INPUT");
+		chk_box_element.id  = "chk_box_select_all_messages";
+		chk_box_element.setAttribute("type", "checkbox");
+		chk_box_element.className = "checkbox";
+		chk_box_element.onclick = function(){select_all_search_messages(this.checked,content);};
+		chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
+		chk_box_element.onkeydown = function (e){
+			if (is_ie)
+			{
+				if ((window.event.keyCode) == 46)
+					delete_msgs(get_current_folder(),'selected','null');
+			}
+			else
+			{
+				if ((e.keyCode) == 46)
+					delete_msgs(get_current_folder(),'selected','null');
+			}
+		};
+		
+		td_element0.appendChild(chk_box_element);
 		td_element1 = document.createElement("TD");
-		td_element1.setAttribute("width", "20%");
+		td_element1.setAttribute("width", "19%");
 		td_element1.align = "left";
+		td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
 		td_element1.innerHTML = get_lang("Folder");
 		td_element2 = document.createElement("TD");
 		td_element2.setAttribute("width", "20%");
 		td_element2.align = "left";
+		td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
 		td_element2.innerHTML = get_lang("Who");
 		td_element3 = document.createElement("TD");
 		td_element3.setAttribute("width", "40%");
 		td_element3.align = "left";
+		td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
 		td_element3.innerHTML = get_lang("Subject");
 		td_element4 = document.createElement("TD");
 		td_element4.setAttribute("width", "10%");
 		td_element4.align = "center";
+		td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
 		td_element4.innerHTML = get_lang("Date");
 		td_element5 = document.createElement("TD");
 		td_element5.setAttribute("width", "10%");
 		td_element5.align = "center";
+		td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
 		td_element5.innerHTML = get_lang("Size");
 	
+		tr_element.appendChild(td_element0);
 		tr_element.appendChild(td_element1);
 		tr_element.appendChild(td_element2);
@@ -318,6 +432,10 @@
 		content.appendChild(table_element);
 		/*end of "put header"*/
-		
+
+		var span_options = document.getElementById("span_options");
+		if (span_options)
+			span_options.innerHTML = '<span title="'+get_lang("Delete")+'" style="margin-left:8px" class="message_options" onclick=delete_search_msgs('+content.id+')>'+get_lang("Delete")+'</span>';
 		content.appendChild(table);
+		content.parentNode.appendChild(span_options);	
 	}
 
Index: /trunk/expressoMail1_2/js/abas.js
===================================================================
--- /trunk/expressoMail1_2/js/abas.js	(revision 125)
+++ /trunk/expressoMail1_2/js/abas.js	(revision 156)
@@ -68,4 +68,20 @@
 	}
 	Element("footer_menu").style.display = ID ? 'none' : '';
+	
+	var span_options = document.getElementById("span_options");	
+	if ((span_options) && (ID == 0)){
+		var span_D = Element("span_D");
+		span_options.innerHTML = 
+		'<span title="'+get_lang("Delete")+'" style="margin-left:8px;" class="message_options" onclick=delete_msgs(\'null\',\'selected\',\'null\')>'+get_lang("Delete")+'</span> | '+
+		'<span title="'+get_lang("Move")+'" class="message_options" onclick=wfolders.makeWindow(\"\",\"move_to\")>'+get_lang("Move")+'</span> | '+
+   		'<span title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span> | '+
+	   	'<span title="'+get_lang("Export")+'" class="message_options" onclick="export_all_selected_msgs()">'+get_lang("Export")+'</span>';	
+	   	span_options.setAttribute('style',"font-size:5px;");
+		span_D.parentNode.insertBefore(span_options,span_D);	
+	} else
+		if ((span_options) && (ID != 0)){		
+			span_options.innerHTML = '<span title="'+get_lang("Delete")+'" style="margin-left:8px" class="message_options" onclick=delete_search_msgs(content_id_'+ID+')>'+get_lang("Delete")+'</span>';
+	   	}
+	
 	return ID;
 }
Index: /trunk/expressoMail1_2/js/main.js
===================================================================
--- /trunk/expressoMail1_2/js/main.js	(revision 139)
+++ /trunk/expressoMail1_2/js/main.js	(revision 156)
@@ -129,7 +129,34 @@
 		
 	string_msgs_in_main = tmp.substring(0,(tmp.length-1));
-	update_quota();
+// It creates a problem in email notification
+//	update_quota();
 	cExecute ("$this.imap_functions.refresh&folder="+current_folder+"&msgs_existent="+string_msgs_in_main+"&msg_range_begin="+msg_range_begin+"&msg_range_end="+msg_range_end+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse, handler_refresh);
 }
+
+function delete_search_msgs(search_num){
+	search_box = Element("table_result_"+search_num.id.substr(18)).firstChild;
+	var felement = search_box.firstChild;
+	var removedList = new Array();
+	var counter = 0;
+	while(felement)
+	{
+		if (felement.firstChild.firstChild.checked)
+			{
+			var folder = felement.firstChild.nextSibling.innerHTML
+			if (folder == 'Caixa de Entrada')
+				folder = 'INBOX';
+			else
+				folder = 'INBOX'+cyrus_delimiter+folder;
+			delete_msgs(folder, felement.firstChild.firstChild.id.substr(18), null);
+			removedList[counter] = felement;
+			counter++;
+			}
+		felement = felement.nextSibling;
+	}
+	for (var i = 0; i <= counter; i++)
+		Element("table_result_"+search_num.id.substr(18)).firstChild.removeChild(removedList[i]);
+	
+}
+
 
 function delete_msgs(folder, msgs_number, border_ID)
@@ -175,5 +202,4 @@
 	if (msgs_number == 'selected')
 		msgs_number = get_selected_messages();
-	
 	if (msgs_number.length > 0 || parseInt(msgs_number) > 0)
 		cExecute ("$this.imap_functions.delete_msgs&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&get_previous_msg="+preferences.delete_and_show_previous_message, handler_delete_msgs);
@@ -838,4 +864,17 @@
 }
 
+function select_all_search_messages(select, aba){
+	search_box = Element("table_result_" + aba.id.substr(18)).firstChild;
+	var felement = search_box.firstChild;
+	while(felement)
+	{
+	if (select)
+		felement.firstChild.firstChild.checked = true;
+	else
+		felement.firstChild.firstChild.checked = false;
+	felement = felement.nextSibling;
+	}
+}
+
 function select_all_messages(select){
 	var main = Element("tbody_box");
Index: /trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- /trunk/expressoMail1_2/js/draw_api.js	(revision 139)
+++ /trunk/expressoMail1_2/js/draw_api.js	(revision 156)
@@ -124,5 +124,5 @@
 			if(!verify_session(data))
 				return;
-			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m">0</span>]</font>';
 			draw_box(data, current_folder);
 			draw_paging(data.num_msgs);
@@ -261,4 +261,5 @@
 		table_element.className = "table_message_header_box";
 		
+		
 		tr_element = document.createElement("TR");
 		tr_element.className = "message_header";
@@ -287,8 +288,8 @@
 		
 		td_element2 = document.createElement("TD");
-		td_element2.setAttribute("width", "4%");
+		td_element2.setAttribute("width", "2%");
 	
 		td_element3 = document.createElement("TD");
-		td_element3.setAttribute("width", "30%");
+		td_element3.setAttribute("width", "31%");
 		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
 		td_element3.id = "message_header_SORTFROM";
@@ -297,5 +298,5 @@
 		
 		td_element4 = document.createElement("TD");
-		td_element4.setAttribute("width", "40%");
+		td_element4.setAttribute("width", "41%");
 		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
 		td_element4.id = "message_header_SORTSUBJECT";
@@ -638,10 +639,7 @@
 	}
 	else if(sort_box_type != sort){
-		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
-			sort_box_reverse = 0;
-		else
-			sort_box_reverse = 1;
-	}
-
+		sort_box_reverse = 1;
+	}
+		
 	// Global variable.
 	sort_box_type = sort;
@@ -1807,5 +1805,5 @@
 		{
 			case 'tr_msg_read':
-				actual_tr.className = "selected_seen_msg_bg";
+				actual_tr.className = " _seen_msg_bg";
 				break;
 			case 'tr_msg_unread':
