Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 46)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 51)
@@ -1,13 +1,6 @@
-// Draw mdenu for boxes
-function draw_menu(){
-	cExecute ("$this.imap_functions.get_folders_list", update_menu);
-}
-
 function draw_tree_folders(folders){
 	// Check if the tree folders alredy exist.
-	var defaultFolders = new Array("Trash","INBOX", "Sent", "Drafts");	
-	
+
 	if (Element('dftree_tree_folders')){
-
 		var update_tree_folders = function(data){
 			for (var i=0; i<data.length; i++){
@@ -20,23 +13,19 @@
 				else if (data[i].folder_unseen > 0)
 				{
-					tree_folders.getNodeById(data[i].folder_id).alter({caption:(array_search(data[i].folder_name, defaultFolders) ? get_lang(data[i].folder_name) : data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
+					tree_folders.getNodeById(data[i].folder_id).alter({caption: data[i].folder_name + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
 					tree_folders.getNodeById(data[i].folder_id)._refresh();
 				}
 				else if (data[i].folder_unseen <= 0)
 				{
-					tree_folders.getNodeById(data[i].folder_id).alter({caption:(array_search(data[i].folder_name, defaultFolders) ? get_lang(data[i].folder_name) : data[i].folder_name)});
+					tree_folders.getNodeById(data[i].folder_id).alter({caption: data[i].folder_name});
 					tree_folders.getNodeById(data[i].folder_id)._refresh();
 				}
 
-				if(data[i].folder_id == get_current_folder()){
-					var old_new_m = 0;
-					
-					if(Element('new_m')){
-						old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
-						Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
-					}
+				if(data[i].folder_id == get_current_folder()){					
+					var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
 					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
 						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
 					}
+					Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
 					draw_paging(Element('tot_m').innerHTML);
 				}
@@ -51,11 +40,10 @@
 		var n_root = new dNode({id:'root', caption:'Minhas Pastas'});
 		tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
-
+	
 		for (var i=0; i<folders.length; i++){
-						
 			if (folders[i].folder_unseen > 0)
-				var nn = new dNode({id:folders[i].folder_id, caption:(array_search(folders[i].folder_name, defaultFolders) ? get_lang(folders[i].folder_name) : folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+				var nn = new dNode({id:folders[i].folder_id, caption:folders[i].folder_name + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
 			else
-				var nn = new dNode({id:folders[i].folder_id, caption:(array_search(folders[i].folder_name, defaultFolders) ? get_lang(folders[i].folder_name) : folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+				var nn = new dNode({id:folders[i].folder_id, caption:folders[i].folder_name, onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
 			
 			if (folders[i].folder_parent == '')
@@ -110,6 +98,6 @@
 function update_menu(data){
 		draw_tree_folders(data);
-		update_quota();		
 		if(data) {
+			build_quota(data);
 			var f_unseen = Element('dftree_'+get_current_folder()+'_unseen');
 			if(f_unseen && f_unseen.innerHTML)
@@ -135,5 +123,5 @@
 			if(!verify_session(data))
 				return;
-			//Element("border_id_0").innerHTML = "&nbsp;" + folder_name + '&nbsp;<font face="Verdana" size="1" color="#505050">[ '+ (sort_box_type == 'SORTARRIVAL' ? '<span id="new_m">0</span> /' : '') + ' <span id="tot_m">0</span> ]</font>';
+			Element("border_id_0").innerHTML = "&nbsp;" + 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, get_current_folder());
 			draw_paging(data.num_msgs);
@@ -142,5 +130,5 @@
 			alternate_border(0);
 		}
-		cExecute ("$this.imap_functions.get_range_msgs2&folder="+get_current_folder()+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
+		cExecute ("$this.imap_functions.get_range_msgs2&folder="+get_current_folder()+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
 	}
 	else
@@ -187,5 +175,5 @@
   	if(current_page != 1) {
 	  	lnk_page = document.createElement("A");
-		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
+		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
   	}
   	else {
@@ -226,5 +214,5 @@
   			msg_range_begin = ((i*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
 			msg_range_end = (i*preferences.max_email_per_page);
-			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
+			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
   		}
   		
@@ -243,5 +231,5 @@
   		msg_range_begin = ((total_pages*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
 		msg_range_end = (total_pages*preferences.max_email_per_page);  		
-		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
+		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); 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_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"', function handler(data){draw_box(data, get_current_folder());})");
 	}
 	else {
@@ -258,5 +246,4 @@
 // Draw the inbox and another folders
 function draw_box(headers_msgs, msg_folder){
-	Element("border_id_0").innerHTML = "&nbsp;" + msg_folder + '&nbsp;<font face="Verdana" size="1" color="#505050">[ '+ (sort_box_type == 'SORTARRIVAL' ? '<span id="new_m">0</span> /' : '') + ' <span id="tot_m">0</span> ]</font>';
 	kill_current_box();
 	
@@ -304,5 +291,5 @@
 		td_element3 = document.createElement("TD");
 		td_element3.setAttribute("width", "30%");
-		td_element3.onclick = function () {sort_box('SORTFROM');};
+		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
 		td_element3.id = "message_header_SORTFROM";
 		td_element3.align = "left";
@@ -311,5 +298,5 @@
 		td_element4 = document.createElement("TD");
 		td_element4.setAttribute("width", "40%");
-		td_element4.onclick = function () {sort_box('SORTSUBJECT');};
+		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
 		td_element4.id = "message_header_SORTSUBJECT";
 		td_element4.align = "left";
@@ -318,5 +305,5 @@
 		td_element5 = document.createElement("TD");
 		td_element5.setAttribute("width", "14%");
-		td_element5.onclick = function () {sort_box('SORTARRIVAL');};
+		td_element5.onclick = function () {sort_box(search_box_type,'SORTARRIVAL');};
 		td_element5.id = "message_header_SORTARRIVAL";
 		td_element5.align = "center";
@@ -324,5 +311,5 @@
 		td_element6 = document.createElement("TD");
 		td_element6.setAttribute("width", "14%");
-		td_element6.onclick = function () {sort_box('SORTSIZE');}
+		td_element6.onclick = function () {sort_box(search_box_type,'SORTSIZE');}
 		td_element6.id = "message_header_SORTSIZE";
 		td_element6.align = "left";
@@ -413,12 +400,9 @@
 			_dragArea.makeDragged(tr_element, headers_msgs[i].msg_number, headers_msgs[i].subject, true);
 	}
-	if(!headers_msgs.length) {
-		write_msg( get_lang("No messages found."));
-	}
 
 	var tdFolders  =  Element("folderscol");
 	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
 	alternate_border(0);
-	resizeWindow();
+	resizeWindow();	
 	draw_footer_box(headers_msgs.num_msgs);	
 	Element('main_table').style.display = '';
@@ -438,5 +422,4 @@
 		Element('msg_number').value = '';
 	}
-
 
 	if(!is_ie) {
@@ -455,7 +438,6 @@
 							"TreeShow");
 							
-		connector.loadAllScripts(scripts);	
-	}
-
+		connector.loadAllScripts(scripts);
+	}
 }
 
@@ -559,5 +541,5 @@
 		}
 		else{
-			td_element3.onmouseover = function () {try {InfoContact.begin(this,headers_msgs.from.email)} catch(e){};};
+			td_element3.onmouseover = function (event) {try {InfoContact.begin(this,headers_msgs.from.email)} catch(e){};};
 			td_element3.onmouseout = function (){ try {clearTimeout(InfoContact.timeout);} catch(e){}};
 			if (headers_msgs.Draft == 'X'){
@@ -630,7 +612,6 @@
 }
 
-function sort_box(type){
-	var message_header = Element("message_header_"+type);
-	
+function sort_box(search, sort){
+	var message_header = Element("message_header_"+search);
 	var handler_draw_box = function(data){
 		draw_box(data, get_current_folder());
@@ -638,13 +619,16 @@
 	}
 
-	if(sort_box_type == type)
+	if(sort_box_type == sort && search_box_type == search){
 		sort_box_reverse = sort_box_reverse ? 0 : 1;
-	else
-		sort_box_reverse = 0;
+	}
+	else if(sort_box_type != sort){
+		sort_box_reverse = 1;
+	}
 		
 	// Global variable.
-	sort_box_type = type;
-
-	cExecute ("$this.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+type+"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
+	sort_box_type = sort;
+	search_box_type = search;
+
+	cExecute ("$this.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&search_box_type="+search+"&sort_box_type="+sort+"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
 	current_page = 1;
 	update_menu();
@@ -692,5 +676,5 @@
 	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 + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)};
+	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 img_space = document.createElement("SPAN");
 	img_space.innerHTML = "&nbsp;";
@@ -699,5 +683,5 @@
 	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 + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)}
+	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)}
 	next_previous_msg_td.appendChild(img_previous_msg);
 	next_previous_msg_td.appendChild(img_space);
@@ -2116,5 +2100,4 @@
 	div_address_full.style.display='';
 }
-
 function draw_footer_box(num_msgs){
 	var span_T = document.createElement("TABLE");
@@ -2145,9 +2128,9 @@
 	span_D.innerHTML = 
    	 get_lang("List")+': '+
-   	'<span id="span_flag_SORTARRIVAL" style="'+(sort_box_type == 'SORTARRIVAL' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("All")+'" class="message_options" onclick="sort_box(\'SORTARRIVAL\')">'+get_lang("all")+'</span>, '+
-   	'<span id="span_flag_UNSEEN" style="'+(sort_box_type == 'UNSEEN' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Unseen")+'" class="message_options" onclick="sort_box(\'UNSEEN\',this)">'+get_lang("Unseen")+'s</span>, '+
-  	'<span id="span_flag_SEEN" style="'+(sort_box_type == 'SEEN' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Seen")+'" class="message_options" onclick="sort_box(\'SEEN\',this)">'+get_lang("Seen")+'s</span>, '+
-   	'<span id="span_flag_ANSWERED" style="'+(sort_box_type == 'ANSWERED' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Answered")+'" class="message_options" onclick="sort_box(\'ANSWERED\',this)">'+get_lang("answered").toLowerCase()+'s</span>, '+
-   	'<span id="span_flag_FLAGGED" style="'+(sort_box_type == 'FLAGGED' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Flagged")+'" class="message_options" onclick="sort_box(\'FLAGGED\',this)">'+get_lang("important")+'s</span>&nbsp;&nbsp;';
+   	'<span id="span_flag_SORTARRIVAL" style="'+(search_box_type == 'ALL' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("All")+'" class="message_options" onclick="if(\'ALL\' == \''+search_box_type+'\') return false;sort_box(\'ALL\',\''+sort_box_type+'\')">'+get_lang("all")+'</span>, '+
+   	'<span id="span_flag_UNSEEN" style="'+(search_box_type == 'UNSEEN' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Unseen")+'" class="message_options" onclick="if(\'UNSEEN\' == \''+search_box_type+'\') return false;sort_box(\'UNSEEN\',\''+sort_box_type+'\')">'+get_lang("Unseen")+'s</span>, '+
+  	'<span id="span_flag_SEEN" style="'+(search_box_type == 'SEEN' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Seen")+'" class="message_options" onclick="if(\'SEEN\' == \''+search_box_type+'\') return false;sort_box(\'SEEN\',\''+sort_box_type+'\')">'+get_lang("Seen")+'s</span>, '+
+   	'<span id="span_flag_ANSWERED" style="'+(search_box_type == 'ANSWERED' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("Answered")+'" class="message_options" onclick="if(\'ANSWERED\' == \''+search_box_type+'\') return false;sort_box(\'ANSWERED\',\''+sort_box_type+'\')">'+get_lang("answered").toLowerCase()+'s</span>, '+
+   	'<span id="span_flag_FLAGGED" style="'+(search_box_type == 'FLAGGED' ? 'font-weight:bold;text-decoration:underline' : '')+'" title="'+get_lang("important")+'" class="message_options" onclick="if(\'FLAGGED\' == \''+search_box_type+'\') return false;sort_box(\'FLAGGED\',\''+sort_box_type+'\')">'+get_lang("important")+'s</span>&nbsp;&nbsp;';
 
 	span_R.appendChild(span_options);
