Index: trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2597)
+++ trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 2676)
@@ -461,5 +461,5 @@
 			imap_close($this->mbox);
 			$this->mbox=false;
-			array_push($return,serialize($msg_info));
+			array_push($return,$msg_info);
 
 			if($msg_info['Unseen'] == "U" || $msg_info['Recent'] == "N"){
Index: trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2642)
+++ trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2676)
@@ -6,31 +6,1189 @@
 
 function draw_quota(data){
+    build_quota(data);
+}
+
+function update_quota(folder_id){
+    cExecute ("expressoMail1_2.imap_functions.get_quota&folder_id="+folder_id,build_quota);
+}
+
+function draw_search(headers_msgs){
+    Element("border_id_0").innerHTML = "&nbsp;&nbsp;" + get_lang('Search Result') + "&nbsp;&nbsp;";
+
+    var tbody = Element('tbody_box');
+    for (var i=0; i<(headers_msgs.length); i++){
+	var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
+	if (tr)
+	    tbody.appendChild(tr);
+    }
+}
+
+function draw_search_header_box(){
+    var table_message_header_box = Element("table_message_header_box");
+    table_message_header_box.parentNode.removeChild(table_message_header_box);
+
+    var content_id_0 = Element("content_id_0");
+    var table_element = document.createElement("TABLE");
+    var tbody_element = document.createElement("TBODY");
+    table_element.setAttribute("id", "table_message_header_box");
+    table_element.className = "table_message_header_box";
+    tr_element = document.createElement("TR");
+    tr_element.className = "message_header";
+    td_element1 = document.createElement("TD");
+    td_element1.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_messages(this.checked);
+    };
+    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_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
+	else
+	{
+	    if ((e.keyCode) == 46)
+	    {
+		//delete_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
+    };
+
+    td_element1.appendChild(chk_box_element);
+    td_element2 = document.createElement("TD");
+    td_element2.setAttribute("width", "3%");
+    td_element3 = document.createElement("TD");
+    td_element3.setAttribute("width", "30%");
+    td_element3.id = "message_header_SORTFROM";
+    td_element3.align = "left";
+    td_element3.innerHTML = get_lang("From");
+    td_element4 = document.createElement("TD");
+    td_element4.setAttribute("width", "49%");
+    td_element4.id = "message_header_SORTSUBJECT";
+    td_element4.align = "left";
+    td_element4.innerHTML = get_lang("Subject");
+    td_element5 = document.createElement("TD");
+    td_element5.setAttribute("width", "10%");
+    td_element5.id = "message_header_SORTARRIVAL";
+    td_element5.align = "center";
+    td_element5.innerHTML = "<B>"+get_lang("Date")+"</B>";
+    td_element5.innerHTML += '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/arrow_descendant.gif">';
+    td_element6 = document.createElement("TD");
+    td_element6.setAttribute("width", "10%");
+    td_element6.id = "message_header_SORTSIZE";
+    td_element6.align = "right";
+    td_element6.innerHTML = get_lang("Size");
+    tr_element.appendChild(td_element1);
+    tr_element.appendChild(td_element2);
+    tr_element.appendChild(td_element3);
+    tr_element.appendChild(td_element4);
+    tr_element.appendChild(td_element5);
+    tr_element.appendChild(td_element6);
+
+    tbody_element.appendChild(tr_element);
+    table_element.appendChild(tbody_element);
+    content_id_0.appendChild(table_element);
+}
+
+function draw_search_division(msg){
+    var tbody = Element('tbody_box');
+    var tr = document.createElement("TR");
+    var td = document.createElement("TD");
+    td.colSpan = '7';
+    td.width = '100%';
+
+    var action_info_table = document.createElement("TABLE");
+    var action_info_tbody = document.createElement("TBODY");
+
+    action_info_table.className = "action_info_table";
+    action_info_table.width = "100%";
+
+    var action_info_tr = document.createElement("TR");
+
+    var action_info_th1 = document.createElement("TH");
+    action_info_th1.width = "40%";
+    action_info_th1.innerHTML = "&nbsp;";
+
+    var action_info_th2 = document.createElement("TH");
+
+    action_info_th2.innerHTML = msg;
+    action_info_th2.className = "action_info_th";
+    action_info_th2.setAttribute("noWrap", "true");
+
+    var action_info_th3 = document.createElement("TH");
+    action_info_th3.width = "40%";
+    action_info_th3.innerHTML = "&nbsp;";
+
+    action_info_tr.appendChild(action_info_th1);
+    action_info_tr.appendChild(action_info_th2);
+    action_info_tr.appendChild(action_info_th3);
+    action_info_tbody.appendChild(action_info_tr);
+    action_info_table.appendChild(action_info_tbody);
+
+    td.appendChild(action_info_table);
+    tr.appendChild(td);
+    tbody.appendChild(tr);
+}
+
+function draw_search_box(){
+    var content_id_0 = Element("content_id_0");
+    var table = document.createElement("TABLE");
+    table.id = "table_box";
+    table.width = 'auto';
+    var tbody = document.createElement("TBODY");
+    tbody.id = "tbody_box";
+
+    table.className = "table_box";
+    table.setAttribute("frame", "below");
+    table.setAttribute("rules", "none");
+    table.setAttribute("cellpadding", "0");
+    table.onkeydown = function (e){
+	if (is_ie)
+	{
+	    if ((window.event.keyCode) == 46)
+	    {
+		//delete_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
+	else
+	{
+	    if ((e.keyCode) == 46)
+	    {
+		//delete_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
+    };
+    if (is_ie)
+	table.style.cursor = "hand";
+
+    table.appendChild(tbody);
+    content_id_0.appendChild(table);
+}
+var idx_cc = 0;
+function draw_plugin_cc(ID, addrs)
+{
+    expresso.connector.loadScript("jscode/ccQuickAdd");
+
+    var array_addrs = '';
+    var array_name 	= '';
+    var cc_data = new Array();
+    if(typeof(addrs.name) != 'undefined') {
+	array_name 	= LTrim(addrs.name).split(" ");
+	array_addrs = new Array(addrs.email);
+    }
+    else {
+	array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
+	array_name 	= LTrim(array_addrs[0]).replace('"','').split(" ");
+    }
+
+    var _split = array_name[0].split('@');
+    cc_data[0] = _split[0];
+    cc_data[1] = _split[0];
+    cc_data[2] = '';
+
+    for (i=1; i < array_name.length; i++)
+	cc_data[2] += array_name[i] + " ";
+
+
+    if(array_addrs.length > 1)
+	cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';
+    else
+	cc_data[3] = array_addrs[0];
+
+    var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
+    '" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/user_card.png">';
+    var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
+    to_addybook_add += addrs;
+    to_addybook_add +=  sm_envelope_img1;
+    idx_cc++;
+    to_addybook_add += "</SPAN>";
+    return to_addybook_add;
+}
+
+function build_quota(data){
+    id = "content_quota";
+    q_limit = data['quota_limit'];
+    var div	= document.getElementById(id);
+    if(!q_limit){
+	div.innerHTML = '<span><font size="2" style="color:red"><strong>'+get_lang("Without Quota")+'</strong></font></span>';
+    }
+    else{
+	if(div)
+	{
+	    div.innerHTML = '';
+	    value = data['quota_percent'];
+	    q_used = data['quota_used'];
+	    table = document.getElementById("table_quota");
+	    if(table)
+		table.parentNode.removeChild(table);
+	    table = document.createElement("TABLE");
+	    tbody = document.createElement("TBODY");
+	    table.appendChild(tbody);
+	    table.id = "table_quota";
+	    table.width="102";
+	    table.border="0";
+	    table.cellSpacing = 0;
+	    table.cellPadding = 0;
+
+	    //tr1 = document.createElement("TR");
+	    td11 = document.createElement("TD");
+	    td11.align="center";
+	    td11.setAttribute("noWrap","true");
+	    td11.innerHTML += '&nbsp;<span class="boxHeaderText">' + value+"% ("+q_used+"M/"+q_limit+"M)</span>";
+	    //tr1.appendChild(td11);
+
+	    tr2 = document.createElement("TR");
+	    td21 = document.createElement("TD");
+	    td21.setAttribute("noWrap","true");
+	    td21.height="15";
+	    td22 = document.createElement("TD");
+	    td21.setAttribute("background", URL_SERVER + 'phpgwapi/templates/' + template + '/images/dsunused.gif');
+	    table221 = document.createElement("TABLE");
+	    tbody221 = document.createElement("TBODY");
+	    table221.appendChild(tbody221);
+	    table221.style.width=value+"%";
+	    td21.width="102";
+	    table221.border="0";
+	    table221.cellSpacing = 0;
+	    table221.cellPadding = 0;
+	    tr221 = document.createElement("TR");
+	    td221 = document.createElement("TD");
+	    td221.height="15";
+	    if(value > 90) {
+		if(value >= 100)
+		    write_msg(get_lang("Your Mailbox is 100% full! You must free more space or will not receive messages."));
+		else
+		    write_msg(get_lang("Warning: Your Mailbox is almost full!"));
+		td221.setAttribute("background","templates/"+template+"/images/dsalert.gif");
+	    }
+	    else if(value > 80)
+		td221.setAttribute("background", URL_SERVER + 'expressoMail1_2/templates/' + template + '/images/dswarn.gif');
+	    else
+		td221.className = 'dsused';
+
+	    tr221.appendChild(td221);
+	    tbody221.appendChild(tr221);
+	    td21.appendChild(table221);
+	    tr2.appendChild(td21);
+	    tr2.appendChild(td11);
+
+	    //tr2.appendChild(td1);
+
+	    tbody.appendChild(tr2); //Desenho
+	    //tbody.appendChild(tr1); //Letras
+	    div.appendChild(table);
+	}
+    }
+}
+
+function draw_paging(num_msgs){	
+    num_msgs = parseInt(num_msgs);
+    total_pages = 1;
+
+    if(last_folder != current_folder){
+	lastPage = 1;
+	current_page = 1;
+	last_folder = current_folder;
+    }
+
+    if(num_msgs > parseInt(preferences.max_email_per_page)) {
+	total_pages = parseInt(num_msgs/preferences.max_email_per_page);
+	if((num_msgs/preferences.max_email_per_page) > total_pages)
+	    total_pages++;
+    }
+
+    if(total_pages == 1) {
+	if(span_paging = document.getElementById("span_paging")) {
+	    span_paging.parentNode.removeChild(span_paging);
+	}
+	return;
+    }
+
+    span_paging = document.getElementById("span_paging");
+    if(!span_paging){
+	span_paging = document.createElement("DIV");
+	span_paging.id = "span_paging";
+	span_paging.className = "boxHeaderText";
+	span_paging.align="right";
+	var div_menu_c3 = document.getElementById("div_menu_c3");
+	if ( div_menu_c3 )
+	    div_menu_c3.appendChild(span_paging);
+    }
+    span_paging.style.width="100%";
+    span_paging.innerHTML="";
+    msg_range_begin = 1;
+    msg_range_end = preferences.max_email_per_page;
+    if(current_page != 1) {
+	lnk_page = document.createElement("A");
+	lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+    }
+    else {
+	lnk_page = document.createElement("SPAN");
+    }
+    span_paging.appendChild(lnk_page);
+
+    lnk_page.innerHTML = "&lt;&lt;";
+    lnk_page.title = get_lang("First");
+    span_paging.innerHTML += "&nbsp;";
+
+    if(current_page == lastPage + numPages)
+	lastPage = current_page - 1;
+    else if((lastPage != 1 && lastPage == current_page) || current_page == total_pages)
+	lastPage = current_page - (numPages - 1);
+    else if(current_page == 1)
+	lastPage = 1;
+
+    if(lastPage < 1)
+	lastPage = 1;
+    else if(lastPage > 1 && (lastPage > (total_pages -(numPages - 1))))
+	lastPage = total_pages -(numPages - 1);
+
+    var	hasMarked = false;
+
+    for(i = lastPage; i <= total_pages; i++) {
+
+	if(current_page == i || (i == total_pages && !hasMarked)) {
+	    lnk_page = document.createElement("SPAN");
+	    span_paging.appendChild(lnk_page);
+	    lnk_page.innerHTML = "&nbsp;<b>"+i+"</b>&nbsp;";
+	    hasMarked = true;
+	    continue;
+	}
+	else{
+	    lnk_page = document.createElement("A");
+	    span_paging.appendChild(lnk_page);
+	    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+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+	}
+
+	lnk_page.innerHTML = "&nbsp;...&nbsp;";
+
+	if(i == (lastPage + numPages))
+	    break;
+	else if(lastPage == 1 || i != lastPage)
+	    lnk_page.innerHTML = "&nbsp;"+i+"&nbsp;";
+
+	span_paging.innerHTML += "&nbsp;";
+    }
+
+    if(current_page != total_pages) {
+	lnk_page = document.createElement("A");
+	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+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+    }
+    else {
+	lnk_page = document.createElement("SPAN");
+    }
+    span_paging.innerHTML += "&nbsp;";
+    span_paging.appendChild(lnk_page);
+
+    lnk_page.title = get_lang("Last");
+    lnk_page.innerHTML = "&gt;&gt;";
+}
+
+
+function draw_tree_local_folders() {
+    /**
+	 * Pastas locais
+	 */
+    if(preferences.use_local_messages==1 || expresso_offline) {
+	var local_folders = expresso_local_messages.list_local_folders();
+	var has_changes = false;
+	for (var i in local_folders) { //Coloca as pastas locais.
+	    if(!isNaN(i)){
+		var new_caption = local_folders[i][0];
+		if(local_folders[i][0].indexOf("/")!="-1") {
+		    final_pos = local_folders[i][0].lastIndexOf("/");
+		    new_caption = local_folders[i][0].substr(final_pos+1);
+		}
+
+		var folder_unseen = Element('dftree_local_'+local_folders[i][0]+'_unseen');
+
+		if ((folder_unseen) && (local_folders[i][1] > 0))
+		{
+		    folder_unseen.innerHTML = local_folders[i][1];
+		    has_changes = true;
+		}
+		else if (local_folders[i][1] > 0)
+		{
+		    tree_folders.getNodeById("local_"+local_folders[i][0]).alter({
+			caption:lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="dftree_local_'+local_folders[i][0]+'_unseen" style=color:red>'+local_folders[i][1]+'</span><font style=color:red>)</font>'
+			});
+		    tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
+		    has_changes = true;
+		}
+		else if (local_folders[i][1] <= 0)
+		{
+		    tree_folders.getNodeById("local_"+local_folders[i][0]).alter({
+			caption:lang_folder(new_caption)
+			});
+		    tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
+		    has_changes = true;
+		}
+
+		if("local_"+local_folders[i][0] == 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 < local_folders[i][1]){
+			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(local_folders[i][1])-old_new_m);
+		    }
+		    Element('new_m').innerHTML = local_folders[i][1] ? '<font color="RED">'+local_folders[i][1]+'</font>' : 0;
+		    draw_paging(Element('tot_m').innerHTML);
+		    has_changes = true;
+		}
+	    }
+	}
+	if(has_changes)
+	    tree_folders.getNodeById("local_root").open();
+
+    }
+}
+
+function draw_tree_folders(folders){
+    // Check if the tree folders alredy exist.
+    translatedFolders = new Map();
+    if (Element('dftree_tree_folders')){
+	if (!expresso_offline) {
+	    var update_tree_folders = function(data){
+		build_quota(data);
+		var unseen_in_mailbox = 0;
+		var unseen_in_shared_folders = 0;
+		for (var i=0; i<data.length; i++){
+		    if ( data[i].folder_unseen > 0 )
+		    {
+			unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
+			if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+			    unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
+		    }
+
+		    var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
+
+		    if ((folder_unseen) && (data[i].folder_unseen > 0))
+		    {
+			folder_unseen.innerHTML = data[i].folder_unseen;
+		    }
+		    else if (data[i].folder_unseen > 0)
+		    {
+			tree_folders.getNodeById(data[i].folder_id).alter({
+			    caption:lang_folder(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:lang_folder(data[i].folder_name)
+			    });
+			tree_folders.getNodeById(data[i].folder_id)._refresh();
+		    }
+
+		    if(data[i].folder_id == 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);
+		    }
+		}
+
+		var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+		//if ( unseen_in_mailbox )
+		//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
+		//else
+		display_unseen_in_mailbox.alter({
+		    caption:get_lang("My Folders")
+		    });
+		display_unseen_in_mailbox._refresh();
+
+		var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
+		if ( display_unseen_in_shared_folders )
+		{
+		    if ( unseen_in_shared_folders )
+			display_unseen_in_shared_folders.alter({
+			    caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")
+			    });
+		    else
+			display_unseen_in_shared_folders.alter({
+			    caption:get_lang("Shared folders")
+			    });
+		    display_unseen_in_shared_folders._refresh();
+		}
+	    };
+	    expresso.connector.cacheNextRequest(1);
+	    cExecute ("expressoMail1_2.imap_functions.get_folders_list&folder=INBOX", update_tree_folders);
+	}
+
+	return;
+    }
+    else{
+	if (!expresso_offline) {
+	    tree_folders = new dFTree({
+		name: 'tree_folders'
+	    });
+
+	    var n_root = new dNode({
+		id:'root',
+		caption: get_lang("My Folders")
+		});
+	    tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
+
+	    var unseen_in_mailbox = 0;
+	    var unseen_in_shared_folders = 0;
+	    for (var i=0; i<folders.length; i++){
+		if (folders[i].folder_unseen > 0)
+		{
+		    unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
+		    if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+			unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
+
+		    var nn = new dNode({
+			id:folders[i].folder_id,
+			caption:lang_folder(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
+			});
+
+		    if( folders[i].folder_name.toLowerCase() == 'inbox' )
+			Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
+		}
+		else
+		    var nn = new dNode({
+			id:folders[i].folder_id,
+			caption:lang_folder(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 == '')
+		    folders[i].folder_parent = 'root';
+		else if (folders[i].folder_parent == 'user'){
+
+		    if (!tree_folders.getNodeById('user')){
+			tmpFolderId = folders[i].folder_id.split(cyrus_delimiter).pop();
+			if (tmpFolderId != folders[i].folder_name)
+			{
+			    translatedFolders.add(tmpFolderId, folders[i].folder_name);
+			}
+			var n_root_shared_folders = new dNode({
+			    id:'user',
+			    caption:get_lang("Shared folders"),
+			    plusSign:true
+			});
+			tree_folders.add(n_root_shared_folders,'root');
+		    }
+		}
+		tree_folders.add(nn,folders[i].folder_parent);
+	    }
+	}
+	//tree_local_folders = new dFTree({name: 'tree_local_folders'});
+	/**
+		 * Pastas locais
+		 */
+	if (preferences.use_local_messages==1 || expresso_offline) {
+	    if (!window.google || !google.gears) {
+		if (!expresso_local_messages.installGears())
+		    preferences.use_local_messages=0;
+	    }
+	    else{
+		if (!window.google || !google.gears) {
+		    temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
+		    if (temp) {
+			location.href = "http://gears.google.com/?action=install&message="+
+			"Para utilizar o recurso de mensagens locais, instale o google gears&return=" +
+			document.location.href;
+		    }
+		    else {
+			preferences.use_local_messages=0;
+		    }
+		}
+		else{
+		    if (expresso_offline)
+			tree_folders = new dFTree({
+			    name: 'tree_folders'
+			});
+		    var root_local = new dNode({
+			id: "local_root",
+			caption: get_lang('local folders')
+		    });
+		    tree_folders.add(root_local, "root"); //coloca root local
+		    var local_folders = expresso_local_messages.list_local_folders();
+		    for (var i in local_folders) { //Coloca as pastas locais.
+			if(!isNaN(i)){
+			    var node_root = "local_root";
+			    var new_caption = local_folders[i][0];
+			    if (local_folders[i][0].indexOf("/") != "-1") {
+				final_pos = local_folders[i][0].lastIndexOf("/");
+				node_root = "local_" + local_folders[i][0].substr(0, final_pos);
+				new_caption = local_folders[i][0].substr(final_pos + 1);
+			    }
+			    if (local_folders[i][1] > 0)
+				var nodeLocal = new dNode({
+				    id: "local_" + local_folders[i][0],
+				    caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
+				    onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
+				    plusSign: local_folders[i][2]
+				});
+			    else
+				var nodeLocal = new dNode({
+				    id: "local_" + local_folders[i][0],
+				    caption: lang_folder(new_caption),
+				    onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
+				    plusSign: local_folders[i][2]
+			    });
+			    tree_folders.add(nodeLocal, node_root);
+			}
+		    }
+		}
+	    }
+	}
+
+	tree_folders.draw(Element('content_folders'));
+	if (!expresso_offline) {
+	    n_root.changeState();
+	    folder_select = (current_folder ? current_folder:"INBOX");
+	    if (typeof(tree_folders.getNodeById(folder_select)) == 'undefined')
+		return false;
+	    tree_folders.getNodeById(folder_select)._select();
+	}
+	else {
+	    root_local.changeState();
+	    tree_folders.getNodeById('local_Inbox')._select();
+	}
+
+	var trash_span=document.getElementById('lINBOX/'+trashfolder+'tree_folders');
+	var draft_span=document.getElementById('lINBOX/'+draftsfolder+'tree_folders');
+	var sent_span=document.getElementById('lINBOX/'+sentfolder+'tree_folders');
+	var spam_span=document.getElementById('lINBOX/'+spamfolder+'tree_folders');
+
+	if (trash_span)
+	    trash_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_trash.png)";
+
+	if (draft_span)
+	    draft_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_draft.png)";
+
+	if (sent_span)
+	    sent_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_sent.png)";
+
+	if (spam_span)
+	    spam_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_spam.png)";
+
+
+	draw_paging(Element('tot_m').innerHTML);
+	if(document.getElementById("nINBOX/"+trashfolder+"tree_folders"))
+	{
+	    var trash = document.createElement("SPAN");
+	    trash.id = 'empty_trash';
+	    trash.className = 'clean_folder';
+	    trash.style.cursor = 'pointer';
+	    trash.onclick = function () {
+		empty_trash_imap();
+	    };
+	    trash.innerHTML = "["+get_lang("Clean")+"]";
+	    trash.title=get_lang("Empty trash");
+	    trash.onmouseover = function() {
+		trash.style.color="red";
+	    };
+	    trash.onmouseout= function() {
+		trash.style.color="#666666";
+	    };
+	    document.getElementById("nINBOX/"+trashfolder+"tree_folders").appendChild(trash);
+	}
+	if(document.getElementById("nINBOX/"+spamfolder+"tree_folders"))
+	{
+	    var spam = document.createElement("SPAN");
+	    spam.id = 'empty_spam';
+	    spam.className = 'clean_folder';
+	    spam.style.cursor = 'pointer';
+	    spam.style.padding = '0 0 0 6px';
+	    spam.onclick = function () {
+		empty_spam_imap();
+	    };
+	    spam.innerHTML = "["+get_lang("Clean")+"]";
+	    spam.title=get_lang("Empty Spam Folder");
+	    spam.onmouseover = function() {
+		spam.style.color="red";
+	    };
+	    spam.onmouseout= function() {
+		spam.style.color="#666666";
+	    };
+	    document.getElementById("nINBOX/"+spamfolder+"tree_folders").appendChild(spam);
+	}
+
+	// Draw right menu folders.
+	/*
+   var treeroot = document.getElementById('chroottree_folders'); 
+   for (var linkBox = treeroot.firstChild; linkBox != null; linkBox = linkBox.nextSibling)
+   _dragArea.makeMenuBox(linkBox);
+   */
+
+	if(!expresso_offline)
+	    var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+	else
+	    var display_unseen_in_mailbox = tree_folders.getNodeById( 'local_root' );
+	//if ( unseen_in_mailbox )
+	//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
+	//else
+	display_unseen_in_mailbox.alter({
+	    caption:get_lang("My Folders")
+	    });
+	display_unseen_in_mailbox._refresh();
+
+	var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
+	if ( display_unseen_in_shared_folders )
+	{
+	    if ( unseen_in_shared_folders )
+		display_unseen_in_shared_folders.alter({
+		    caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")
+		    });
+	    else
+		display_unseen_in_shared_folders.alter({
+		    caption:get_lang("Shared folders")
+		    });
+	    display_unseen_in_shared_folders._refresh();
+	}
+    }
+
+    if (!expresso_offline) {
+	var folder_create = "";
+	var nm1 = "";
+	if(tree_folders._folderPr.length > 0){
+	    var nm_folder = "";
+	    for(var i=0; i < tree_folders._folderPr.length; i++){
+		nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
+		if(nm_folder[0] == "INBOX"){
+		    if(nm1 == ""){
+			nm1 = nm_folder[1];
+			folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+		    }else{
+			if( nm1 != nm_folder[1]){
+			    folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+			    nm1 = nm_folder[1];
+			}
+		    }
+		}
+	    }
+	}
+	if(folder_create != ""){
+	    if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
+		var handler_correct_folders = function(data){
+		    //Timeout to release HTTPRequest , loadScript and update tree folders.
+		    if(data)
+			setTimeout("expresso.connector.loadScript('jscode/TreeShow');ttreeBox.update_folder();",500);
+		};
+		cExecute("expressoMail1_2.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
+	    }
+	}
+    }
+}
+
+
+function update_menu(data){
+    /*
+	 * @AUTHOR Rodrigo Souza dos Santos
+	 * @DATE 2008/09/15
+	 * @BRIEF When occurs a error in imap server show the message that is in file "error.html".
+	 */
+    if ( data && data.imap_error )
+    {
+	if(preferences.use_local_messages==1 && expresso_local_messages.is_offline_installed){
+	    conf = confirm(get_lang("The expresso imap server is currently down, expresso noticed you have offline mail module installed, would you like to use it?"));
+	    if(conf) {
+		window.onresize = function() {
+		    var target = document.getElementById('divAppbox');
+		    target.style.height= document.body.clientHeight - 83;
+		};
+		var target = document.getElementById('divAppbox');
+		document.getElementById("divAppboxHeader").innerHTML="";
+		target.style.height= document.body.clientHeight - 83;
+		expresso_local_messages.set_as_logged(account_id,0,true);
+		target.innerHTML = "<iframe src='offline.php?inside=1' width='100%' height='100%' frameBorder='0'></iframe>";
+		return false;
+	    }
+	}
+	expresso.connector.newRequest('error.html', URL_SERVER + 'expressoMail1_2/templates/'+template+'/error.html', 'GET',
+	    function(data)
+	    {
+		var target = document.getElementById('divAppbox');
+		if ( target )
+		    target.innerHTML = data;
+	    }
+	    );
+	return false;
+    }
+
+    draw_tree_folders(data);
+    if(data) {
 	build_quota(data);
-}
-
-function update_quota(folder_id){
-	cExecute ("expressoMail1_2.imap_functions.get_quota&folder_id="+folder_id,build_quota);
-}
-
-function draw_search(headers_msgs){
-	Element("border_id_0").innerHTML = "&nbsp;&nbsp;" + get_lang('Search Result') + "&nbsp;&nbsp;";
-
-	var tbody = Element('tbody_box');
-	for (var i=0; i<(headers_msgs.length); i++){
-		var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
-		if (tr)
-			tbody.appendChild(tr);
-	}
-}
-
-function draw_search_header_box(){
-	var table_message_header_box = Element("table_message_header_box");
-	table_message_header_box.parentNode.removeChild(table_message_header_box);
-
-	var content_id_0 = Element("content_id_0");
+	var f_unseen = Element('dftree_'+current_folder+'_unseen');
+	if(f_unseen && f_unseen.innerHTML)
+	    Element('new_m').innerHTML = '<font face="Verdana" size="1" color="RED">'+f_unseen.innerHTML+'</font>';
+	else
+	{
+	    if( parseInt(Element('new_m').innerHTML) == 0 )
+		Element('new_m').innerHTML = 0;
+	}
+	folders = data;
+    }
+}
+
+var handler_draw_box = function(data){
+    draw_box( expresso.connector.unserialize( data ), 'INBOX', true);
+//alternate_border(0);
+};
+
+// Action on change folders.
+function change_folder(folder, folder_name){
+    if (openTab.imapBox[0] != folder)
+    {
+	current_folder = folder;
+	var handler_draw_box = function(data)
+	{
+	    alternate_border(0);
+	    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>';
+	    draw_box(data, folder, true);
+	    draw_paging(data.num_msgs);
+	    Element("tot_m").innerHTML = data.num_msgs;
+	    update_menu();
+	    return true;
+	};
+	proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
+    //		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+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
+	alternate_border(0);
+}
+
+function open_folder(folder, folder_name){
+    if (current_folder!= folder) {
+	current_folder = folder;
+	var handler_draw_box = function(data){
+	    numBox++;
+	    create_border(folder_name,numBox.toString());
+	    draw_box(data, current_folder, false);
+	    alternate_border(numBox);
+	    return true;
+	};
+	cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+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
+	alternate_border(numBox);
+    return true;
+}
+
+function sort_box(search, sort){
+    var message_header = Element("message_header_"+search);
+    var handler_draw_box = function(data){
+	draw_box(data, current_folder,true);
+	draw_paging(Element('tot_m').innerHTML);
+	//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
+	var msgs_unseen = 0;
+	for(i in data){
+	    if(data[i].Unseen == 'U')
+		msgs_unseen++;
+	}
+	Element("new_m").innerHTML = '<font style="color:'+(msgs_unseen == 0 ? '': 'red')+'">' + msgs_unseen + '</font>';
+    };
+
+    if(sort_box_type == sort && search_box_type == search){
+	sort_box_reverse = sort_box_reverse ? 0 : 1;
+    }
+    else if(sort_box_type != sort){
+	if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
+	    sort_box_reverse = 0;
+	else
+	    sort_box_reverse = 1;
+    }
+
+    // Global variable.
+    sort_box_type = sort;
+    search_box_type = search;
+
+    proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
+    current_page = 1;
+//Comentado para nao sobrepor o numero de msgs nao lidas ao utilizar os filtros
+//update_menu();
+}
+
+function make_tr_message(headers_msgs, msg_folder)
+{
+    if ( InfoContact == null )
+	InfoContact = new emInfoContact();
+
+    var tr_element = document.createElement('tr');
+    tr_element.style.height = preferences.line_height;
+    tr_element.id = headers_msgs.msg_number;
+
+    tr_element.msg_sample = "";
+    //if(headers_msgs.msg_sample && headers_msgs.msg_sample.preview_msg_subject != "")
+    if(headers_msgs.msg_sample && preferences.preview_msg_subject == "1")
+    {
+	tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,120) + "..."; //trecho do body que sera exibido com o assunto;
+    }
+
+    tr_element.tip = "";
+    if(headers_msgs.msg_sample && preferences.preview_msg_tip == "1")
+    {
+	tr_element.tip = headers_msgs.msg_sample.body.substr(3,300) + "..."; //trecho do body que sera exibido no tool-tip;
+    }
+
+    if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N')){
+	if ((headers_msgs.Flagged == 'F') || (headers_msgs.Importance.toLowerCase().indexOf("high")!=-1 && parseInt(preferences.use_important_flag)))
+	    add_className(tr_element, 'flagged_msg');
+	add_className(tr_element, 'tr_msg_unread');
+    }
+    else{
+	if ((headers_msgs.Flagged == 'F') || (headers_msgs.Importance.toLowerCase().indexOf("high")!=-1 && parseInt(preferences.use_important_flag)))
+	    add_className(tr_element,'flagged_msg');
+    }
+
+    if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N'))
+	add_className(tr_element, 'tr_msg_unread');
+
+    if (headers_msgs.Flagged == 'F')
+	add_className(tr_element,'flagged_msg');
+
+    td_element1 = document.createElement("TD");
+    td_element1.className = "td_msg";
+    td_element1.setAttribute("width", "1%");
+    chk_box_element = document.createElement("INPUT");
+    chk_box_element.setAttribute("type", "checkbox");
+    chk_box_element.className = "checkbox";
+    chk_box_element.setAttribute("id", "check_box_message_"+headers_msgs.msg_number);
+    chk_box_element.onclick = function(e){
+	if (is_ie)
+	    changeBgColor(window.event,headers_msgs.msg_number);
+	else
+	    changeBgColor(e,headers_msgs.msg_number);
+    };
+    td_element1.appendChild(chk_box_element);
+
+    td_element2 = document.createElement("TD");
+    td_element2.className = "td_msg";
+    td_element2.setAttribute("width", "2%");
+    if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)
+	td_element2.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/clip.gif" title="' + url_decode(headers_msgs.attachment.names) + '">';
+
+    td_element21 = document.createElement("TD");
+    td_element21.className = "td_msg";
+    td_element21.setAttribute("width", "1%");
+    td_element21.id = "td_message_answered_"+headers_msgs.msg_number;
+
+    if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {
+	attach_name = headers_msgs.attachment.names.split(", ");
+	for(var item in attach_name)
+	{
+	    if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){
+		td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/clip.gif" title="' + url_decode(attach_name[item]) + '">';
+		break;
+	    }
+	}
+    }
+
+    if ((headers_msgs.Forwarded == 'F')  || (headers_msgs.Draft == 'X' && headers_msgs.Answered == 'A')){
+	td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/forwarded.gif" title="'+get_lang('Forwarded')+'">';
+	headers_msgs.Draft = '';
+	headers_msgs.Answered = '';
+	headers_msgs.Forwarded = 'F';
+    }
+    else if (headers_msgs.Draft == 'X')
+	td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/draft.gif" title="'+get_lang('Draft')+'">';
+    else if (headers_msgs.Answered == 'A')
+	td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/answered.gif" title="'+get_lang('Answered')+'">';
+    else
+	td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
+
+    td_element22 = document.createElement("TD");
+    td_element22.className = "td_msg";
+    td_element22.setAttribute("width", "1%");
+    td_element22.id = "td_message_signed_"+headers_msgs.msg_number;
+
+    //td_element23 = document.createElement("TD");
+    //td_element23.setAttribute("width", "1%");
+    //td_element23.id = "td_message_signed_"+headers_msgs.msg_number;
+    switch(headers_msgs.ContentType)
+    {
+	case "signature":
+	{
+	    td_element22.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/signed_msg.gif" title="' + get_lang('Signed message') + '">';
+	    break;
+	}
+	case "cipher":
+	{
+	    td_element22.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/lock.gif" title="' + get_lang('Crypted message') + '">';
+	    break;
+	}
+	default:
+	{
+	    break;
+	}
+    };
+
+    td_element23 = document.createElement("TD");
+    td_element23.className = "td_msg";
+    td_element23.setAttribute("width", "1%");
+    td_element23.id = "td_message_important_"+headers_msgs.msg_number;
+
+    if (headers_msgs.Flagged == 'F' || (headers_msgs.Importance.toLowerCase().indexOf("high") != -1 && parseInt(preferences.use_important_flag)))
+    {
+	td_element23.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/important.gif" title="'+get_lang('Important')+'">';
+    }
+    else
+	td_element23.innerHTML = "&nbsp;&nbsp;&nbsp;";
+
+    td_element24 = document.createElement("TD");
+    td_element24.className = "td_msg";
+    td_element24.setAttribute("width", "1%");
+    td_element24.id = "td_message_sent_"+headers_msgs.msg_number;
+    td_element24.innerHTML = "&nbsp;&nbsp;&nbsp;";
+    // preload image
+    var _img_sent = new Image();
+    _img_sent.src 	 = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif';
+
+    td_element3 = document.createElement("TD");
+    td_element3.className = "td_msg";
+    td_element3.id = "td_who_"+ headers_msgs.msg_number;
+    td_element3.setAttribute("width", "20%");
+    var _onclick = function(){
+	InfoContact.hide();proxy_mensagens.get_msg(headers_msgs.msg_number, msg_folder,true, show_msg);
+    };
+    td_element3.onclick = _onclick;
+    td_element3.innerHTML = '&nbsp;';
+
+    if (typeof(headers_msgs.from) == 'undefined')
+	return false;
+    if(headers_msgs.from.email.toLowerCase() == Element("user_email").value)
+    {
+	td_element3.onmouseover = function () {
+	    this.title=headers_msgs.to.email;
+	};
+	if (headers_msgs.Draft == 'X')
+	    td_element3.innerHTML += "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
+	else{
+	    if(headers_msgs.to.email != null && headers_msgs.to.email.toLowerCase() != Element("user_email").value)
+		td_element24.innerHTML = '<img valign="center" src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif" title="'+get_lang('Sent')+'">';
+
+	    if ((headers_msgs.to)&&(headers_msgs.to.name != null))
+		td_element3.innerHTML += headers_msgs.to.name;
+	    else if (headers_msgs.to){
+		td_element3.innerHTML += headers_msgs.to.email;
+	    }
+	}
+    }
+    else{
+	if (headers_msgs.Draft == 'X'){
+	    td_element3.innerHTML = "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
+	}
+	else{
+	    var spanSender = document.createElement("SPAN");
+	    spanSender.onmouseover = function (event) {
+		this.style.textDecoration = "underline";try {
+		    InfoContact.begin(this,headers_msgs.from.email)
+		    } catch(e){};
+	    };
+	    spanSender.onmouseout = function (){
+		try {
+		    this.style.textDecoration = "none"; clearTimeout(InfoContact.timeout);
+		} catch(e){}
+		};
+	    spanSender.innerHTML =  headers_msgs.from.name != null ? headers_msgs.from.name : headers_msgs.from.email;
+	    if (spanSender.innerHTML.indexOf(" ") == '-1' && spanSender.innerHTML.length > 25){
+		spanSender.innerHTML = spanSender.innerHTML.substring(0,25) + "...";
+	    }
+	    else if (spanSender.innerHTML.length > 40 ){
+		spanSender.innerHTML = spanSender.innerHTML.substring(0,40) + "...";
+	    }
+	    td_element3.appendChild(spanSender);
+	}
+    }
+    td_element4 = document.createElement("TD");
+    td_element4.className = "td_msg";
+    td_element4.setAttribute("width", "50%");
+    td_element4.onclick = _onclick;
+    //		td_element4.setAttribute("style","white-space:nowrap;");
+    td_element4.innerHTML = !is_ie ? "<a nowrap id='a_message_"+tr_element.id+"'>&nbsp;" : "&nbsp;";
+
+    if ((headers_msgs.subject)&&(headers_msgs.subject.length > 50))
+    {
+	//			if( (headers_msgs.subject.length+tr_element.msg_sample.length)>
+	td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
+    }
+    else
+    {
+	td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample + "</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
+    }
+
+    td_element4.title=tr_element.tip;
+    if(!is_ie){
+	td_element4.innerHTML += "</a>";
+    }
+
+
+    td_element5 = document.createElement("TD");
+    td_element5.className = "td_msg";
+    td_element5.setAttribute("width", "14%");
+    td_element5.onclick = _onclick;
+    td_element5.setAttribute("align", "center");
+    td_element5.innerHTML = headers_msgs.udate;
+
+    td_element6 = document.createElement("TD");
+    td_element6.className = "td_msg";
+    td_element6.setAttribute("width", "14%");
+    td_element6.onclick = _onclick;
+    td_element6.setAttribute("noWrap","true");
+    td_element6.setAttribute("align", "center");
+
+    td_element6.innerHTML = borkb(headers_msgs.Size);
+
+    tr_element.appendChild(td_element1);
+    tr_element.appendChild(td_element2);
+    tr_element.appendChild(td_element21);
+    tr_element.appendChild(td_element22);
+    tr_element.appendChild(td_element23);
+    tr_element.appendChild(td_element24);
+    tr_element.appendChild(td_element3);
+    tr_element.appendChild(td_element4);
+    tr_element.appendChild(td_element5);
+    tr_element.appendChild(td_element6);
+    return tr_element;
+}
+
+
+// Draw the inbox and another folders
+function draw_box(headers_msgs, msg_folder, alternate){
+    if ( _dragArea == null )
+	_dragArea = new DragArea( );
+
+    if (alternate)
+	kill_current_box();
+
+    if(is_ie)
+	document.getElementById("border_table").width = "99.5%";
+
+    openTab.content_id[numBox] = document.getElementById("content_id_"+numBox);
+    openTab.imapBox[numBox] = msg_folder;
+    openTab.type[numBox] = 0;
+
+    table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
+    if (table_message_header_box == null){
 	var table_element = document.createElement("TABLE");
 	var tbody_element = document.createElement("TBODY");
-	table_element.setAttribute("id", "table_message_header_box");
+	table_element.setAttribute("id", "table_message_header_box_"+numBox);
 	table_element.className = "table_message_header_box";
+
 	tr_element = document.createElement("TR");
 	tr_element.className = "message_header";
@@ -41,1300 +1199,224 @@
 	chk_box_element.setAttribute("type", "checkbox");
 	chk_box_element.className = "checkbox";
-	chk_box_element.onclick = function(){select_all_messages(this.checked);};
-	chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
+	chk_box_element.onclick = function(){
+	    select_all_messages(this.checked);
+	};
+	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_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-		else
-		{
-			if ((e.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
+	    if (is_ie)
+	    {
+		if ((window.event.keyCode) == 46)
+		    proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	    else
+	    {
+		if ((e.keyCode) == 46)
+		    proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
 	};
 
 	td_element1.appendChild(chk_box_element);
+
 	td_element2 = document.createElement("TD");
-	td_element2.setAttribute("width", "3%");
+	td_element2.setAttribute("width", "7%");
 	td_element3 = document.createElement("TD");
-	td_element3.setAttribute("width", "30%");
-	td_element3.id = "message_header_SORTFROM";
+	td_element3.setAttribute("width", "29%");
+	td_element3.onclick = function () {
+	    sort_box(search_box_type,'SORTFROM');
+	};
+	td_element3.id = "message_header_SORTFROM_"+numBox;
 	td_element3.align = "left";
-	td_element3.innerHTML = get_lang("From");
+	td_element3.innerHTML = get_lang("Who");
+
 	td_element4 = document.createElement("TD");
-	td_element4.setAttribute("width", "49%");
-	td_element4.id = "message_header_SORTSUBJECT";
+	td_element4.setAttribute("width", "38%");
+	td_element4.onclick = function () {
+	    sort_box(search_box_type,'SORTSUBJECT');
+	};
+	td_element4.id = "message_header_SORTSUBJECT_"+numBox;
 	td_element4.align = "left";
-	td_element4.innerHTML = get_lang("Subject");	
+	td_element4.innerHTML = get_lang("Subject");
+
 	td_element5 = document.createElement("TD");
-	td_element5.setAttribute("width", "10%");
-	td_element5.id = "message_header_SORTARRIVAL";
+	td_element5.setAttribute("width", "14%");
+	td_element5.onclick = function () {
+	    sort_box(search_box_type,'SORTARRIVAL');
+	};
+	td_element5.id = "message_header_SORTARRIVAL_"+numBox;
 	td_element5.align = "center";
-	td_element5.innerHTML = "<B>"+get_lang("Date")+"</B>";	
-	td_element5.innerHTML += '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/arrow_descendant.gif">';
+	td_element5.innerHTML = get_lang("Date");
 	td_element6 = document.createElement("TD");
-	td_element6.setAttribute("width", "10%");
-	td_element6.id = "message_header_SORTSIZE";
-	td_element6.align = "right";
+	td_element6.setAttribute("width", "14%");
+	td_element6.onclick = function () {
+	    sort_box(search_box_type,'SORTSIZE');
+	};
+	td_element6.id = "message_header_SORTSIZE_"+numBox;
+	td_element6.align = "left";
 	td_element6.innerHTML = get_lang("Size");
+
 	tr_element.appendChild(td_element1);
 	tr_element.appendChild(td_element2);
+	var td_element21 = document.createElement("TD");
+	td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
+	var td_element22 = document.createElement("TD");
+	td_element22.innerHTML = "&nbsp;&nbsp;&nbsp;";
+	var td_element23 = document.createElement("TD");
+	td_element23.innerHTML = "&nbsp;&nbsp;";
+	tr_element.appendChild(td_element21);
+	tr_element.appendChild(td_element22);
+	tr_element.appendChild(td_element23);
 	tr_element.appendChild(td_element3);
 	tr_element.appendChild(td_element4);
 	tr_element.appendChild(td_element5);
 	tr_element.appendChild(td_element6);
-
 	tbody_element.appendChild(tr_element);
 	table_element.appendChild(tbody_element);
-	content_id_0.appendChild(table_element);
-}
-
-function draw_search_division(msg){
-	var tbody = Element('tbody_box');
-	var tr = document.createElement("TR");
-	var td = document.createElement("TD");
-	td.colSpan = '7';
-	td.width = '100%';
-
-	var action_info_table = document.createElement("TABLE");
-	var action_info_tbody = document.createElement("TBODY");
-
-	action_info_table.className = "action_info_table";
-	action_info_table.width = "100%";
-
-	var action_info_tr = document.createElement("TR");
-
-	var action_info_th1 = document.createElement("TH");
-	action_info_th1.width = "40%";
-	action_info_th1.innerHTML = "&nbsp;";
-
-	var action_info_th2 = document.createElement("TH");
-
-	action_info_th2.innerHTML = msg;
-	action_info_th2.className = "action_info_th";
-	action_info_th2.setAttribute("noWrap", "true");
-
-	var action_info_th3 = document.createElement("TH");
-	action_info_th3.width = "40%";
-	action_info_th3.innerHTML = "&nbsp;";
-
-	action_info_tr.appendChild(action_info_th1);
-	action_info_tr.appendChild(action_info_th2);
-	action_info_tr.appendChild(action_info_th3);
-	action_info_tbody.appendChild(action_info_tr);
-	action_info_table.appendChild(action_info_tbody);
-
-	td.appendChild(action_info_table);
-	tr.appendChild(td);
-	tbody.appendChild(tr);
-}
-
-function draw_search_box(){
-	var content_id_0 = Element("content_id_0");
-	var table = document.createElement("TABLE");
-	table.id = "table_box";
-	table.width = 'auto';
-	var tbody = document.createElement("TBODY");
-	tbody.id = "tbody_box";
-
-	table.className = "table_box";
-	table.setAttribute("frame", "below");
-	table.setAttribute("rules", "none");
-	table.setAttribute("cellpadding", "0");
-	table.onkeydown = function (e){
-		if (is_ie)
-		{
-			if ((window.event.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-		else
-		{
-			if ((e.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-	};
+	openTab.content_id[numBox].appendChild(table_element);
+    }
+    draw_header_box();
+    var table_element = document.createElement("TABLE");
+    var tbody_element = document.createElement("TBODY");
+    table_element.id = "table_box";
+    table_element.className = "table_box";
+    table_element.borderColorDark = "#bbbbbb";
+    table_element.frame = "void";
+    table_element.rules = "rows";
+    table_element.cellPadding = "0";
+    table_element.cellSpacing = "0";
+
+    table_element.onkeydown = function (e){
 	if (is_ie)
-		table.style.cursor = "hand";
-
-	table.appendChild(tbody);
-	content_id_0.appendChild(table);
-}
-var idx_cc = 0;
-function draw_plugin_cc(ID, addrs)
-{
-	expresso.connector.loadScript("jscode/ccQuickAdd");
-
-	var array_addrs = '';
-	var array_name 	= '';	
-	var cc_data = new Array();
-	if(typeof(addrs.name) != 'undefined') {	
-		array_name 	= LTrim(addrs.name).split(" ");
-		array_addrs = new Array(addrs.email);		
-	}
-	else {
-		array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
-		array_name 	= LTrim(array_addrs[0]).replace('"','').split(" ");	
-	}
-
-	var _split = array_name[0].split('@');
-	cc_data[0] = _split[0];
-	cc_data[1] = _split[0];
-	cc_data[2] = '';
-
-	for (i=1; i < array_name.length; i++)
-		cc_data[2] += array_name[i] + " ";			
-
-
-	if(array_addrs.length > 1)			
-		cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';		
+	{
+	    if ((window.event.keyCode) == 46)
+	    {
+		//delete_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
 	else
-		cc_data[3] = array_addrs[0];
-
-	var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
-		'" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/user_card.png">';
-	var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
-	to_addybook_add += addrs;
-	to_addybook_add +=  sm_envelope_img1;
-	idx_cc++;
-	to_addybook_add += "</SPAN>";
-	return to_addybook_add;
-}
-
-function build_quota(data){
-	id = "content_quota";
-	q_limit = data['quota_limit'];
-	var div	= document.getElementById(id);
-	if(!q_limit){
-		div.innerHTML = '<span><font size="2" style="color:red"><strong>'+get_lang("Without Quota")+'</strong></font></span>';
-	}
-	else{
-		if(div)
-		{
-			div.innerHTML = '';
-			value = data['quota_percent'];
-			q_used = data['quota_used'];
-			table = document.getElementById("table_quota");
-			if(table)
-				table.parentNode.removeChild(table);
-			table = document.createElement("TABLE");	
-			tbody = document.createElement("TBODY");	
-			table.appendChild(tbody);
-			table.id = "table_quota";
-			table.width="102";
-			table.border="0";
-			table.cellSpacing = 0;
-			table.cellPadding = 0;
-
-			//tr1 = document.createElement("TR");
-			td11 = document.createElement("TD");
-			td11.align="center";
-			td11.setAttribute("noWrap","true");
-			td11.innerHTML += '&nbsp;<span class="boxHeaderText">' + value+"% ("+q_used+"M/"+q_limit+"M)</span>";
-			//tr1.appendChild(td11);
-
-			tr2 = document.createElement("TR");
-			td21 = document.createElement("TD");
-			td21.setAttribute("noWrap","true");
-			td21.height="15";
-			td22 = document.createElement("TD");	
-			td21.setAttribute("background", URL_SERVER + 'phpgwapi/templates/' + template + '/images/dsunused.gif');
-			table221 = document.createElement("TABLE");
-			tbody221 = document.createElement("TBODY");
-			table221.appendChild(tbody221);
-			table221.style.width=value+"%";	
-			td21.width="102";
-			table221.border="0";
-			table221.cellSpacing = 0;
-			table221.cellPadding = 0;
-			tr221 = document.createElement("TR");
-			td221 = document.createElement("TD");
-			td221.height="15";
-			if(value > 90) {
-				if(value >= 100)
-					write_msg(get_lang("Your Mailbox is 100% full! You must free more space or will not receive messages."));
-				else
-					write_msg(get_lang("Warning: Your Mailbox is almost full!"));
-				td221.setAttribute("background","templates/"+template+"/images/dsalert.gif");
-			}
-			else if(value > 80)
-				td221.setAttribute("background", URL_SERVER + 'expressoMail1_2/templates/' + template + '/images/dswarn.gif');
-			else
-				td221.className = 'dsused';
-
-			tr221.appendChild(td221);
-			tbody221.appendChild(tr221);
-			td21.appendChild(table221);	
-			tr2.appendChild(td21);
-			tr2.appendChild(td11);
-
-			//tr2.appendChild(td1);
-
-			tbody.appendChild(tr2); //Desenho
-			//tbody.appendChild(tr1); //Letras
-			div.appendChild(table);
-		}
-	}
-}
-
-function draw_paging(num_msgs){	
-	num_msgs = parseInt(num_msgs);
-	total_pages = 1;
-
-	if(last_folder != current_folder){
-		lastPage = 1;
-		current_page = 1;
-		last_folder = current_folder;
-	}
-
-	if(num_msgs > parseInt(preferences.max_email_per_page)) {	
-		total_pages = parseInt(num_msgs/preferences.max_email_per_page);
-		if((num_msgs/preferences.max_email_per_page) > total_pages)
-			total_pages++;			
-	}
-
-	if(total_pages == 1) {
-		if(span_paging = document.getElementById("span_paging")) {
-			span_paging.parentNode.removeChild(span_paging);
-		}
-		return;
-	}
-
-	span_paging = document.getElementById("span_paging");
-	if(!span_paging){
-		span_paging = document.createElement("DIV");
-		span_paging.id = "span_paging";
-		span_paging.className = "boxHeaderText";
-		span_paging.align="right";
-		var div_menu_c3 = document.getElementById("div_menu_c3");
-		if ( div_menu_c3 )
-			div_menu_c3.appendChild(span_paging);	
-	}
-	span_paging.style.width="100%";		  	 		
-	span_paging.innerHTML="";
-	msg_range_begin = 1;
-	msg_range_end = preferences.max_email_per_page;
-	if(current_page != 1) {
-		lnk_page = document.createElement("A");
-		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-	}
-	else {
-		lnk_page = document.createElement("SPAN");
-	}
-	span_paging.appendChild(lnk_page);
-
-	lnk_page.innerHTML = "&lt;&lt;";
-	lnk_page.title = get_lang("First");
-	span_paging.innerHTML += "&nbsp;";
-
-	if(current_page == lastPage + numPages)
-		lastPage = current_page - 1;  		
-	else if((lastPage != 1 && lastPage == current_page) || current_page == total_pages)  		
-		lastPage = current_page - (numPages - 1);
-	else if(current_page == 1)
-		lastPage = 1;
-
-	if(lastPage < 1)
-		lastPage = 1;
-	else if(lastPage > 1 && (lastPage > (total_pages -(numPages - 1))))
-		lastPage = total_pages -(numPages - 1);
-
-	var	hasMarked = false;
-
-	for(i = lastPage; i <= total_pages; i++) {
-
-		if(current_page == i || (i == total_pages && !hasMarked)) {	  		
-			lnk_page = document.createElement("SPAN");
-			span_paging.appendChild(lnk_page);
-			lnk_page.innerHTML = "&nbsp;<b>"+i+"</b>&nbsp;";
-			hasMarked = true;
-			continue;
-		}
-		else{	  		
-			lnk_page = document.createElement("A");
-			span_paging.appendChild(lnk_page);
-			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+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-		}
-
-		lnk_page.innerHTML = "&nbsp;...&nbsp;";
-
-		if(i == (lastPage + numPages))
-			break;	  		
-		else if(lastPage == 1 || i != lastPage)	  			  			
-			lnk_page.innerHTML = "&nbsp;"+i+"&nbsp;";
-
-		span_paging.innerHTML += "&nbsp;";	  			  			  			  			  			  			  		
-	}
-
-	if(current_page != total_pages) {
-		lnk_page = document.createElement("A");
-		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+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-	}
-	else {
-		lnk_page = document.createElement("SPAN");
-	}
-	span_paging.innerHTML += "&nbsp;";
-	span_paging.appendChild(lnk_page);
-
-	lnk_page.title = get_lang("Last");
-	lnk_page.innerHTML = "&gt;&gt;";
-}
-
-
-function draw_tree_local_folders() {
-	/**
-	 * Pastas locais
-	 */
-	if(preferences.use_local_messages==1 || expresso_offline) {
-		var local_folders = expresso_local_messages.list_local_folders();
-		var has_changes = false;
-		for (var i in local_folders) { //Coloca as pastas locais.
-
-			var new_caption = local_folders[i][0];
-			if(local_folders[i][0].indexOf("/")!="-1") {
-				final_pos = local_folders[i][0].lastIndexOf("/");
-				new_caption = local_folders[i][0].substr(final_pos+1);
-			}
-
-			var folder_unseen = Element('dftree_local_'+local_folders[i][0]+'_unseen');
-
-			if ((folder_unseen) && (local_folders[i][1] > 0))
-			{
-				folder_unseen.innerHTML = local_folders[i][1];
-				has_changes = true;
-			}
-			else if (local_folders[i][1] > 0)
-			{
-				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="dftree_local_'+local_folders[i][0]+'_unseen" style=color:red>'+local_folders[i][1]+'</span><font style=color:red>)</font>'});
-				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
-				has_changes = true;
-			}
-			else if (local_folders[i][1] <= 0)
-			{
-				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption)});
-				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
-				has_changes = true;
-			}
-
-			if("local_"+local_folders[i][0] == 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 < local_folders[i][1]){
-					Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(local_folders[i][1])-old_new_m);
-				}
-				Element('new_m').innerHTML = local_folders[i][1] ? '<font color="RED">'+local_folders[i][1]+'</font>' : 0;
-				draw_paging(Element('tot_m').innerHTML);
-				has_changes = true;
-			}
-		}
-		if(has_changes)
-			tree_folders.getNodeById("local_root").open();
-
-	}	
-}
-
-function draw_tree_folders(folders){
-	// Check if the tree folders alredy exist.
-	translatedFolders = new Map();
-	if (Element('dftree_tree_folders')){
-		if (!expresso_offline) {
-			var update_tree_folders = function(data){
-				build_quota(data);
-				var unseen_in_mailbox = 0;
-				var unseen_in_shared_folders = 0;
-				for (var i=0; i<data.length; i++){
-					if ( data[i].folder_unseen > 0 )
-					{
-						unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
-						if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-							unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
-					}
-
-					var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
-
-					if ((folder_unseen) && (data[i].folder_unseen > 0))
-					{
-						folder_unseen.innerHTML = data[i].folder_unseen;
-					}
-					else if (data[i].folder_unseen > 0)
-					{
-						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(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:lang_folder(data[i].folder_name)});
-						tree_folders.getNodeById(data[i].folder_id)._refresh();
-					}
-
-					if(data[i].folder_id == 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);
-					}
-				}
-
-				var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
-				//if ( unseen_in_mailbox )
-				//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
-				//else
-				display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
-				display_unseen_in_mailbox._refresh();
-
-				var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
-				if ( display_unseen_in_shared_folders )
-				{
-					if ( unseen_in_shared_folders )
-						display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
-					else
-						display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
-					display_unseen_in_shared_folders._refresh();
-				}
-			};
-			expresso.connector.cacheNextRequest(1);
-			cExecute ("expressoMail1_2.imap_functions.get_folders_list&folder=INBOX", update_tree_folders);
-		}
-
-		return;
-	}
-	else{
-		if (!expresso_offline) {
-			tree_folders = new dFTree({name: 'tree_folders'});
-
-			var n_root = new dNode({id:'root', caption: get_lang("My Folders")});
-			tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
-
-			var unseen_in_mailbox = 0;
-			var unseen_in_shared_folders = 0;
-			for (var i=0; i<folders.length; i++){
-				if (folders[i].folder_unseen > 0)
-				{
-					unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
-					if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-						unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
-
-					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(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}); 
-
-					if( folders[i].folder_name.toLowerCase() == 'inbox' )
-						Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
-				}
-				else
-					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(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 == '')
-					folders[i].folder_parent = 'root';
-				else if (folders[i].folder_parent == 'user'){	
-
-					if (!tree_folders.getNodeById('user')){
-						tmpFolderId = folders[i].folder_id.split(cyrus_delimiter).pop();
-						if (tmpFolderId != folders[i].folder_name)
-						{
-							translatedFolders.add(tmpFolderId, folders[i].folder_name);
-						}
-						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared folders"), plusSign:true}); 
-						tree_folders.add(n_root_shared_folders,'root');
-					}
-				}
-				tree_folders.add(nn,folders[i].folder_parent);
-			}
-		}
-		//tree_local_folders = new dFTree({name: 'tree_local_folders'});
-		/**
-		 * Pastas locais
-		 */
-		if (preferences.use_local_messages==1 || expresso_offline) {
-			if (!window.google || !google.gears) {
-				if (!expresso_local_messages.installGears())
-					preferences.use_local_messages=0;
-			}
-			else{
-				if (!window.google || !google.gears) {
-					temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
-					if (temp) {
-						location.href = "http://gears.google.com/?action=install&message="+
-							"Para utilizar o recurso de mensagens locais, instale o google gears&return=" +
-							document.location.href;
-					}
-					else {
-						preferences.use_local_messages=0;
-					}
-				}
-				else{
-					if (expresso_offline) 
-						tree_folders = new dFTree({
-name: 'tree_folders'
-});
-var root_local = new dNode({
-id: "local_root",
-caption: get_lang('local folders')
-});
-tree_folders.add(root_local, "root"); //coloca root local
-var local_folders = expresso_local_messages.list_local_folders();
-for (var i in local_folders) { //Coloca as pastas locais.
-	var node_root = "local_root";
-	var new_caption = local_folders[i][0];
-	if (local_folders[i][0].indexOf("/") != "-1") {
-		final_pos = local_folders[i][0].lastIndexOf("/");
-		node_root = "local_" + local_folders[i][0].substr(0, final_pos);
-		new_caption = local_folders[i][0].substr(final_pos + 1);
-	}
-	if (local_folders[i][1] > 0) 
-		var nodeLocal = new dNode({
-id: "local_" + local_folders[i][0],
-caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
-onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-plusSign: local_folders[i][2]
-});
-else 
-var nodeLocal = new dNode({
-id: "local_" + local_folders[i][0],
-caption: lang_folder(new_caption),
-onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-plusSign: local_folders[i][2]
-});
-tree_folders.add(nodeLocal, node_root);
-}
-}
-}		
-}
-
-tree_folders.draw(Element('content_folders'));
-if (!expresso_offline) {
-	n_root.changeState();
-	folder_select = (current_folder ? current_folder:"INBOX");
-	if (typeof(tree_folders.getNodeById(folder_select)) == 'undefined')
-		return false;
-	tree_folders.getNodeById(folder_select)._select();
-}
-else {
-	root_local.changeState();
-	tree_folders.getNodeById('local_Inbox')._select();
-}
-
-var trash_span=document.getElementById('lINBOX/'+trashfolder+'tree_folders');
-var draft_span=document.getElementById('lINBOX/'+draftsfolder+'tree_folders');
-var sent_span=document.getElementById('lINBOX/'+sentfolder+'tree_folders');
-var spam_span=document.getElementById('lINBOX/'+spamfolder+'tree_folders');
-
-if (trash_span)
-	trash_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_trash.png)";
-
-if (draft_span)
-	draft_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_draft.png)";
-
-if (sent_span)
-	sent_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_sent.png)";
-
-if (spam_span)
-	spam_span.style.backgroundImage="url(" + URL_SERVER + "phpgwapi/templates/"+template+"/images/foldertree_spam.png)";
-
-
-	draw_paging(Element('tot_m').innerHTML);
-	if(document.getElementById("nINBOX/"+trashfolder+"tree_folders"))
-{
-	var trash = document.createElement("SPAN");
-	trash.id = 'empty_trash';
-	trash.className = 'clean_folder';
-	trash.style.cursor = 'pointer';
-	trash.onclick = function () {empty_trash_imap();};
-	trash.innerHTML = "["+get_lang("Clean")+"]";
-	trash.title=get_lang("Empty trash");
-	trash.onmouseover = function() {trash.style.color="red";};
-	trash.onmouseout= function() {trash.style.color="#666666";};
-	document.getElementById("nINBOX/"+trashfolder+"tree_folders").appendChild(trash);
-}
-if(document.getElementById("nINBOX/"+spamfolder+"tree_folders"))
-{
-	var spam = document.createElement("SPAN");
-	spam.id = 'empty_spam';
-	spam.className = 'clean_folder';
-	spam.style.cursor = 'pointer';
-	spam.style.padding = '0 0 0 6px';
-	spam.onclick = function () {empty_spam_imap();};
-	spam.innerHTML = "["+get_lang("Clean")+"]";
-	spam.title=get_lang("Empty Spam Folder");
-	spam.onmouseover = function() {spam.style.color="red";};
-	spam.onmouseout= function() {spam.style.color="#666666";};
-	document.getElementById("nINBOX/"+spamfolder+"tree_folders").appendChild(spam);
-}
-
-// Draw right menu folders.
-/*
-   var treeroot = document.getElementById('chroottree_folders'); 
-   for (var linkBox = treeroot.firstChild; linkBox != null; linkBox = linkBox.nextSibling)
-   _dragArea.makeMenuBox(linkBox);
-   */
-
-if(!expresso_offline)
-	var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
-	else
-	var display_unseen_in_mailbox = tree_folders.getNodeById( 'local_root' );
-	//if ( unseen_in_mailbox )
-	//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
-	//else
-	display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
-	display_unseen_in_mailbox._refresh();
-
-	var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
-if ( display_unseen_in_shared_folders )
-{
-	if ( unseen_in_shared_folders )
-		display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
-	else
-		display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
-	display_unseen_in_shared_folders._refresh();
-}
-}
-
-if (!expresso_offline) {
-	var folder_create = "";
-	var nm1 = "";
-	if(tree_folders._folderPr.length > 0){
-		var nm_folder = "";
-		for(var i=0; i < tree_folders._folderPr.length; i++){
-			nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
-			if(nm_folder[0] == "INBOX"){
-				if(nm1 == ""){
-					nm1 = nm_folder[1];
-					folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
-				}else{
-					if( nm1 != nm_folder[1]){
-						folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
-						nm1 = nm_folder[1];
-					}
-				}
-			}
-		}
-	}
-	if(folder_create != ""){
-		if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
-			var handler_correct_folders = function(data){
-				//Timeout to release HTTPRequest , loadScript and update tree folders.
-				if(data)
-					setTimeout("expresso.connector.loadScript('jscode/TreeShow');ttreeBox.update_folder();",500);
-			};
-			cExecute("expressoMail1_2.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
-		}
-	}
-}
-}
-
-
-function update_menu(data){
-	/*
-	 * @AUTHOR Rodrigo Souza dos Santos
-	 * @DATE 2008/09/15
-	 * @BRIEF When occurs a error in imap server show the message that is in file "error.html".
-	 */
-	if ( data && data.imap_error )
-	{
-		if(preferences.use_local_messages==1 && expresso_local_messages.is_offline_installed){
-			conf = confirm(get_lang("The expresso imap server is currently down, expresso noticed you have offline mail module installed, would you like to use it?"));
-			if(conf) {
-				window.onresize = function() {
-					var target = document.getElementById('divAppbox');
-					target.style.height= document.body.clientHeight - 83;
-				};
-				var target = document.getElementById('divAppbox');
-				document.getElementById("divAppboxHeader").innerHTML="";
-				target.style.height= document.body.clientHeight - 83;
-				expresso_local_messages.set_as_logged(account_id,0,true);
-				target.innerHTML = "<iframe src='offline.php?inside=1' width='100%' height='100%' frameBorder='0'></iframe>";
-				return false;
-			}
-		}
-		expresso.connector.newRequest('error.html', URL_SERVER + 'expressoMail1_2/templates/'+template+'/error.html', 'GET',
-				function(data)
-				{
-				var target = document.getElementById('divAppbox');
-				if ( target )
-				target.innerHTML = data;
-				}
-				);
-		return false;
-	}
-
-	draw_tree_folders(data);
-	if(data) {
-		build_quota(data);			
-		var f_unseen = Element('dftree_'+current_folder+'_unseen');
-		if(f_unseen && f_unseen.innerHTML)
-			Element('new_m').innerHTML = '<font face="Verdana" size="1" color="RED">'+f_unseen.innerHTML+'</font>';
-		else
-		{
-			if( parseInt(Element('new_m').innerHTML) == 0 )
-				Element('new_m').innerHTML = 0;			
-		}
-		folders = data;
-	}
-}
-
-var handler_draw_box = function(data){
-	draw_box( expresso.connector.unserialize( data ), 'INBOX', true);
-	//alternate_border(0);
+	{
+	    if ((e.keyCode) == 46)
+	    {
+		//delete_all_selected_msgs_imap();
+		proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+	    }
+	}
+    };
+    if (is_ie)
+	table_element.style.cursor = "hand";
+
+    tbody_element.setAttribute("id", "tbody_box");
+    table_element.appendChild(tbody_element);
+
+    var _divScroll = document.getElementById("divScrollMain_"+numBox);
+
+    var bar = document.getElementById("toolbar");
+    var offset = 0;
+
+    if(!_divScroll){
+	_divScroll = document.createElement("DIV");
+	_divScroll.id = "divScrollMain_"+numBox;
+    }
+
+    _divScroll.style.overflowY = "auto";
+    _divScroll.style.overflowX = "hidden";
+    _divScroll.style.width	="100%";
+
+    if (is_mozilla){
+	_divScroll.style.overflow = "-moz-scrollbars-vertical";
+	_divScroll.style.width	="99.3%";
+    }
+    // Inicio: Redimensiona DIV SCROLL
+    var bar = Element("toolbar");
+    var offset = 0;
+    if(bar.style.visibility != 'hidden')
+	offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);
+    var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
+    var defaultHeight = screenHeight - offset;
+    _divScroll.style.height 	= defaultHeight - 110;
+    Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
+    // Fim: Redimensiona DIV SCROLL
+    _divScroll.appendChild(table_element);
+    openTab.content_id[numBox].appendChild(_divScroll);
+
+    var f_unseen = 0;
+
+    if (headers_msgs.num_msgs == 0){
+	var tr_info = document.createElement("TR");
+	var td_info = document.createElement("TD");
+	td_info.setAttribute("colspan", "10");
+	td_info.setAttribute("background", "#FFF");
+	tr_info.setAttribute("id", "msg_info");
+	td_info.align = "center";
+	td_info.style.padding = "25px";
+	td_info.style.fontWeight = "bold";
+	td_info.style.fontSize = "11pt";
+	td_info.innerHTML = get_lang("This mail box is empty");
+	tr_info.appendChild(td_info);
+	tbody_element.appendChild(tr_info);
+    }
+
+
+    for (var i=0; i < headers_msgs.length; i++){
+	if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
+	    f_unseen++;
+	tr_element = make_tr_message(headers_msgs[i], msg_folder);
+	if (tr_element){
+	    tbody_element.appendChild(tr_element);
+	    add_className(tr_element, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
+	}
+	_dragArea.makeDragged(tr_element, headers_msgs[i].msg_number, headers_msgs[i].subject, true);
+    }
+
+    if ((preferences.use_shortcuts == '1') && (headers_msgs[0]))
+	select_msg(headers_msgs[0].msg_number, 'null', true);
+
+    var tdFolders  =  Element("folderscol");
+    tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
+    if ( !currentTab )
+	alternate_border(numBox);
+    draw_footer_box(headers_msgs.num_msgs);
+    Element('main_table').style.display = '';
+    if(debug) {
+	var _eTime = new Date();
+	_eTime = _eTime.getTime();
+	alert("Carregou em "+(_eTime - _bTime)+" ms");
+    }
+    var msg_folder = Element('msg_folder').value;
+    var msg_number = Element('msg_number').value;
+    if(!msg_folder && msg_number) {
+	new_message('new','null');
+    }
+    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);
+	Element('msg_folder').value = '';
+	Element('msg_number').value = '';
+    }
+
+    if(!is_ie) {
+	var scripts = new Array("jscode/ccQuickAdd",
+	    "jscode/color_palette",
+	    "jscode/filter",
+	    "jscode/filters",
+	    "jscode/html2xhtml",
+	    "jscode/preferences",
+	    "jscode/QuickCatalogSearch",
+	    "jscode/QuickSearchUser",
+	    "jscode/rich_text_editor",
+	    "jscode/sharemailbox",
+	    "jscode/search",
+	    "jscode/TreeS",
+	    "jscode/TreeShow");
+
+	expresso.connector.loadAllScripts(scripts);
+    }
+    // Loading Quota View Folder Component (if exists...)
+    if(Element("table_quota"))
+	expresso.connector.loadScript("jscode/InfoQuota");
 };
 
-// Action on change folders.
-	function change_folder(folder, folder_name){
-		if (openTab.imapBox[0] != folder)
-		{
-			current_folder = folder;
-			var handler_draw_box = function(data)
-			{
-				alternate_border(0);
-				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>';
-				draw_box(data, folder, true);
-				draw_paging(data.num_msgs);
-				Element("tot_m").innerHTML = data.num_msgs;
-				update_menu();
-				return true;
-			};
-			proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
-			//		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+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
-			alternate_border(0);
-	}
-
-function open_folder(folder, folder_name){
-	if (current_folder!= folder) {
-		current_folder = folder;
-		var handler_draw_box = function(data){
-			numBox++;
-			create_border(folder_name,numBox.toString());
-			draw_box(data, current_folder, false);
-			alternate_border(numBox);
-			return true;
-		};
-		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+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
-		alternate_border(numBox);
-	return true;
-}
-
-function sort_box(search, sort){
-	var message_header = Element("message_header_"+search);
-	var handler_draw_box = function(data){
-		draw_box(data, current_folder,true);
-		draw_paging(Element('tot_m').innerHTML);
-		//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
-		var msgs_unseen = 0;
-		for(i in data){
-			if(data[i].Unseen == 'U')
-				msgs_unseen++;
-		}
-		Element("new_m").innerHTML = '<font style="color:'+(msgs_unseen == 0 ? '': 'red')+'">' + msgs_unseen + '</font>';
-	};
-
-	if(sort_box_type == sort && search_box_type == search){
-		sort_box_reverse = sort_box_reverse ? 0 : 1;
-	}
-	else if(sort_box_type != sort){
-		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
-			sort_box_reverse = 0;
-		else
-			sort_box_reverse = 1;
-	}
-
-	// Global variable.
-	sort_box_type = sort;
-	search_box_type = search;
-
-	proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
-	current_page = 1;
-	//Comentado para nao sobrepor o numero de msgs nao lidas ao utilizar os filtros
-	//update_menu();
-}
-
-function make_tr_message(headers_msgs, msg_folder)
-{
-	if ( InfoContact == null )
-		InfoContact = new emInfoContact();
-
-	var tr_element = document.createElement('tr');
-	tr_element.style.height = preferences.line_height;		
-	tr_element.id = headers_msgs.msg_number;
-
-	tr_element.msg_sample = "";
-	//if(headers_msgs.msg_sample && headers_msgs.msg_sample.preview_msg_subject != "")
-	if(headers_msgs.msg_sample && preferences.preview_msg_subject == "1")
-	{
-		tr_element.msg_sample = headers_msgs.msg_sample.body.substr(0,120) + "..."; //trecho do body que sera exibido com o assunto;
-	}
-
-	tr_element.tip = "";
-	if(headers_msgs.msg_sample && preferences.preview_msg_tip == "1")
-	{
-		tr_element.tip = headers_msgs.msg_sample.body.substr(3,300) + "..."; //trecho do body que sera exibido no tool-tip;
-	}
-
-	if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N')){
-		if ((headers_msgs.Flagged == 'F') || (headers_msgs.Importance.toLowerCase().indexOf("high")!=-1 && parseInt(preferences.use_important_flag)))
-			add_className(tr_element, 'flagged_msg');
-		add_className(tr_element, 'tr_msg_unread');
-	}
-	else{
-		if ((headers_msgs.Flagged == 'F') || (headers_msgs.Importance.toLowerCase().indexOf("high")!=-1 && parseInt(preferences.use_important_flag)))
-			add_className(tr_element,'flagged_msg');
-	}
-
-	if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N'))
-		add_className(tr_element, 'tr_msg_unread');
-
-	if (headers_msgs.Flagged == 'F')
-		add_className(tr_element,'flagged_msg');
-
-	td_element1 = document.createElement("TD");
-	td_element1.className = "td_msg";
-	td_element1.setAttribute("width", "1%");
-	chk_box_element = document.createElement("INPUT");
-	chk_box_element.setAttribute("type", "checkbox");
-	chk_box_element.className = "checkbox";
-	chk_box_element.setAttribute("id", "check_box_message_"+headers_msgs.msg_number);
-	chk_box_element.onclick = function(e){
-		if (is_ie)
-			changeBgColor(window.event,headers_msgs.msg_number);
-		else
-			changeBgColor(e,headers_msgs.msg_number);
-	};
-	td_element1.appendChild(chk_box_element);
-
-	td_element2 = document.createElement("TD");
-	td_element2.className = "td_msg";
-	td_element2.setAttribute("width", "2%");
-	if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)
-		td_element2.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/clip.gif" title="' + url_decode(headers_msgs.attachment.names) + '">';			
-
-	td_element21 = document.createElement("TD");
-	td_element21.className = "td_msg";
-	td_element21.setAttribute("width", "1%");
-	td_element21.id = "td_message_answered_"+headers_msgs.msg_number;
-
-	if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {
-		attach_name = headers_msgs.attachment.names.split(", ");
-		for(var item in attach_name)
-		{
-			if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){
-				td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/clip.gif" title="' + url_decode(attach_name[item]) + '">';
-				break;
-			}
-		}
-	}
-
-	if ((headers_msgs.Forwarded == 'F')  || (headers_msgs.Draft == 'X' && headers_msgs.Answered == 'A')){
-		td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/forwarded.gif" title="'+get_lang('Forwarded')+'">';
-		headers_msgs.Draft = '';
-		headers_msgs.Answered = '';
-		headers_msgs.Forwarded = 'F';
-	}
-	else if (headers_msgs.Draft == 'X')
-		td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/draft.gif" title="'+get_lang('Draft')+'">';
-	else if (headers_msgs.Answered == 'A')
-		td_element21.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/answered.gif" title="'+get_lang('Answered')+'">';
-	else
-		td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
-
-	td_element22 = document.createElement("TD");
-	td_element22.className = "td_msg";
-	td_element22.setAttribute("width", "1%");
-	td_element22.id = "td_message_signed_"+headers_msgs.msg_number;
-
-	//td_element23 = document.createElement("TD");
-	//td_element23.setAttribute("width", "1%");
-	//td_element23.id = "td_message_signed_"+headers_msgs.msg_number;
-	switch(headers_msgs.ContentType)
-	{
-		case "signature":
-		{
-			td_element22.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/signed_msg.gif" title="' + get_lang('Signed message') + '">';
-			break;
-		}
-		case "cipher":
-		{
-			td_element22.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/lock.gif" title="' + get_lang('Crypted message') + '">';
-			break;
-		}
-		default:
-		{
-			break;
-		}
-	};
-
-	td_element23 = document.createElement("TD");
-	td_element23.className = "td_msg";
-	td_element23.setAttribute("width", "1%");
-	td_element23.id = "td_message_important_"+headers_msgs.msg_number;
-
-	if (headers_msgs.Flagged == 'F' || (headers_msgs.Importance.toLowerCase().indexOf("high") != -1 && parseInt(preferences.use_important_flag)))
-	{
-		td_element23.innerHTML = '<img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/important.gif" title="'+get_lang('Important')+'">';
-	}
-	else
-		td_element23.innerHTML = "&nbsp;&nbsp;&nbsp;";
-
-	td_element24 = document.createElement("TD");
-	td_element24.className = "td_msg";
-	td_element24.setAttribute("width", "1%");
-	td_element24.id = "td_message_sent_"+headers_msgs.msg_number;
-	td_element24.innerHTML = "&nbsp;&nbsp;&nbsp;";
-	// preload image
-	var _img_sent = new Image();
-	_img_sent.src 	 = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif';
-
-	td_element3 = document.createElement("TD");
-	td_element3.className = "td_msg";
-	td_element3.id = "td_who_"+ headers_msgs.msg_number;
-	td_element3.setAttribute("width", "20%");
-	var _onclick = function(){InfoContact.hide();proxy_mensagens.get_msg(headers_msgs.msg_number, msg_folder,true, show_msg);};
-	td_element3.onclick = _onclick;
-	td_element3.innerHTML = '&nbsp;';
-
-	if (typeof(headers_msgs.from) == 'undefined')
-		return false;
-	if(headers_msgs.from.email.toLowerCase() == Element("user_email").value)
-	{ 
-		td_element3.onmouseover = function () {this.title=headers_msgs.to.email;};
-		if (headers_msgs.Draft == 'X')
-			td_element3.innerHTML += "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
-		else{				
-			if(headers_msgs.to.email != null && headers_msgs.to.email.toLowerCase() != Element("user_email").value)
-				td_element24.innerHTML = '<img valign="center" src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif" title="'+get_lang('Sent')+'">';
-
-			if ((headers_msgs.to)&&(headers_msgs.to.name != null))
-				td_element3.innerHTML += headers_msgs.to.name;
-			else if (headers_msgs.to){
-				td_element3.innerHTML += headers_msgs.to.email;
-			}
-		}
-	}
-	else{
-		if (headers_msgs.Draft == 'X'){
-			td_element3.innerHTML = "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
-		}
-		else{				
-			var spanSender = document.createElement("SPAN");
-			spanSender.onmouseover = function (event) {this.style.textDecoration = "underline";try {InfoContact.begin(this,headers_msgs.from.email)} catch(e){};};
-			spanSender.onmouseout = function (){ try {this.style.textDecoration = "none"; clearTimeout(InfoContact.timeout);} catch(e){}};
-			spanSender.innerHTML =  headers_msgs.from.name != null ? headers_msgs.from.name : headers_msgs.from.email;
-			if (spanSender.innerHTML.indexOf(" ") == '-1' && spanSender.innerHTML.length > 25){
-				spanSender.innerHTML = spanSender.innerHTML.substring(0,25) + "...";
-			}
-			else if (spanSender.innerHTML.length > 40 ){
-				spanSender.innerHTML = spanSender.innerHTML.substring(0,40) + "...";
-			}				
-			td_element3.appendChild(spanSender);				
-		}
-	}			
-	td_element4 = document.createElement("TD");
-	td_element4.className = "td_msg";
-	td_element4.setAttribute("width", "50%");
-	td_element4.onclick = _onclick;
-	//		td_element4.setAttribute("style","white-space:nowrap;");
-	td_element4.innerHTML = !is_ie ? "<a nowrap id='a_message_"+tr_element.id+"'>&nbsp;" : "&nbsp;";
-
-	if ((headers_msgs.subject)&&(headers_msgs.subject.length > 50))
-	{
-		//			if( (headers_msgs.subject.length+tr_element.msg_sample.length)>
-		td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
-	}
-	else
-	{
-		td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample + "</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
-	}
-
-	td_element4.title=tr_element.tip;
-	if(!is_ie){
-		td_element4.innerHTML += "</a>";
-	}
-
-
-	td_element5 = document.createElement("TD");
-	td_element5.className = "td_msg";
-	td_element5.setAttribute("width", "14%");
-	td_element5.onclick = _onclick;
-	td_element5.setAttribute("align", "center");
-	td_element5.innerHTML = headers_msgs.udate;
-
-	td_element6 = document.createElement("TD");
-	td_element6.className = "td_msg";
-	td_element6.setAttribute("width", "14%");
-	td_element6.onclick = _onclick;
-	td_element6.setAttribute("noWrap","true");
-	td_element6.setAttribute("align", "center");
-
-	td_element6.innerHTML = borkb(headers_msgs.Size);
-
-	tr_element.appendChild(td_element1);
-	tr_element.appendChild(td_element2);
-	tr_element.appendChild(td_element21);
-	tr_element.appendChild(td_element22);
-	tr_element.appendChild(td_element23);
-	tr_element.appendChild(td_element24);
-	tr_element.appendChild(td_element3);
-	tr_element.appendChild(td_element4);
-	tr_element.appendChild(td_element5);
-	tr_element.appendChild(td_element6);
-	return tr_element;
-}
-
-
-// Draw the inbox and another folders
-	function draw_box(headers_msgs, msg_folder, alternate){
-		if ( _dragArea == null )
-			_dragArea = new DragArea( );
-
-		if (alternate)
-			kill_current_box();
-
-		if(is_ie)
-			document.getElementById("border_table").width = "99.5%";
-
-		openTab.content_id[numBox] = document.getElementById("content_id_"+numBox);	
-		openTab.imapBox[numBox] = msg_folder;
-		openTab.type[numBox] = 0;
-
-		table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
-		if (table_message_header_box == null){
-			var table_element = document.createElement("TABLE");
-			var tbody_element = document.createElement("TBODY");
-			table_element.setAttribute("id", "table_message_header_box_"+numBox);
-			table_element.className = "table_message_header_box";
-
-			tr_element = document.createElement("TR");
-			tr_element.className = "message_header";
-			td_element1 = document.createElement("TD");
-			td_element1.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_messages(this.checked);};
-			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)
-						proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-				}
-				else
-				{
-					if ((e.keyCode) == 46)
-						proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-				}
-			};
-
-			td_element1.appendChild(chk_box_element);
-
-			td_element2 = document.createElement("TD");
-			td_element2.setAttribute("width", "7%");
-			td_element3 = document.createElement("TD");
-			td_element3.setAttribute("width", "29%");
-			td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
-			td_element3.id = "message_header_SORTFROM_"+numBox;
-			td_element3.align = "left";
-			td_element3.innerHTML = get_lang("Who");
-
-			td_element4 = document.createElement("TD");
-			td_element4.setAttribute("width", "38%");
-			td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
-			td_element4.id = "message_header_SORTSUBJECT_"+numBox;
-			td_element4.align = "left";
-			td_element4.innerHTML = get_lang("Subject");
-
-			td_element5 = document.createElement("TD");
-			td_element5.setAttribute("width", "14%");
-			td_element5.onclick = function () {sort_box(search_box_type,'SORTARRIVAL');};
-			td_element5.id = "message_header_SORTARRIVAL_"+numBox;
-			td_element5.align = "center";
-			td_element5.innerHTML = get_lang("Date");
-			td_element6 = document.createElement("TD");
-			td_element6.setAttribute("width", "14%");
-			td_element6.onclick = function () {sort_box(search_box_type,'SORTSIZE');};
-			td_element6.id = "message_header_SORTSIZE_"+numBox;
-			td_element6.align = "left";
-			td_element6.innerHTML = get_lang("Size");
-
-			tr_element.appendChild(td_element1);
-			tr_element.appendChild(td_element2);		
-			var td_element21 = document.createElement("TD");
-			td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
-			var td_element22 = document.createElement("TD");
-			td_element22.innerHTML = "&nbsp;&nbsp;&nbsp;";
-			var td_element23 = document.createElement("TD");
-			td_element23.innerHTML = "&nbsp;&nbsp;";
-			tr_element.appendChild(td_element21);
-			tr_element.appendChild(td_element22);
-			tr_element.appendChild(td_element23);
-			tr_element.appendChild(td_element3);
-			tr_element.appendChild(td_element4);
-			tr_element.appendChild(td_element5);
-			tr_element.appendChild(td_element6);
-			tbody_element.appendChild(tr_element);
-			table_element.appendChild(tbody_element);
-			openTab.content_id[numBox].appendChild(table_element);
-		}
-		draw_header_box();
-		var table_element = document.createElement("TABLE");
-		var tbody_element = document.createElement("TBODY");	
-		table_element.id = "table_box";
-		table_element.className = "table_box";
-		table_element.borderColorDark = "#bbbbbb";
-		table_element.frame = "void";
-		table_element.rules = "rows";
-		table_element.cellPadding = "0";
-		table_element.cellSpacing = "0";
-
-		table_element.onkeydown = function (e){
-			if (is_ie)
-			{
-				if ((window.event.keyCode) == 46)
-				{
-					//delete_all_selected_msgs_imap();
-					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-				}
-			}
-			else
-			{
-				if ((e.keyCode) == 46)
-				{
-					//delete_all_selected_msgs_imap();
-					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-				}
-			}
-		};
-		if (is_ie)
-			table_element.style.cursor = "hand";
-
-		tbody_element.setAttribute("id", "tbody_box");
-		table_element.appendChild(tbody_element);
-
-		var _divScroll = document.getElementById("divScrollMain_"+numBox);
-
-		var bar = document.getElementById("toolbar");
-		var offset = 0;
-
-		if(!_divScroll){		
-			_divScroll = document.createElement("DIV");
-			_divScroll.id = "divScrollMain_"+numBox;
-		}
-
-		_divScroll.style.overflowY = "auto";								
-		_divScroll.style.overflowX = "hidden";
-		_divScroll.style.width	="100%";
-
-		if (is_mozilla){
-			_divScroll.style.overflow = "-moz-scrollbars-vertical";
-			_divScroll.style.width	="99.3%";
-		}
-		// Inicio: Redimensiona DIV SCROLL
-		var bar = Element("toolbar");
-		var offset = 0;
-		if(bar.style.visibility != 'hidden') 
-			offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);		
-		var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
-		var defaultHeight = screenHeight - offset;		
-		_divScroll.style.height 	= defaultHeight - 110;
-		Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
-		// Fim: Redimensiona DIV SCROLL
-		_divScroll.appendChild(table_element);
-		openTab.content_id[numBox].appendChild(_divScroll);
-
-		var f_unseen = 0;
-
-		if (headers_msgs.num_msgs == 0){
-			var tr_info = document.createElement("TR");
-			var td_info = document.createElement("TD");
-			td_info.setAttribute("colspan", "10");
-			td_info.setAttribute("background", "#FFF");
-			tr_info.setAttribute("id", "msg_info");
-			td_info.align = "center";
-			td_info.style.padding = "25px";
-			td_info.style.fontWeight = "bold";
-			td_info.style.fontSize = "11pt";
-			td_info.innerHTML = get_lang("This mail box is empty");
-			tr_info.appendChild(td_info);
-			tbody_element.appendChild(tr_info);
-		}
-
-
-		for (var i=0; i < headers_msgs.length; i++){
-			if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
-				f_unseen++;				
-			tr_element = make_tr_message(headers_msgs[i], msg_folder);
-			if (tr_element){
-				tbody_element.appendChild(tr_element);
-				add_className(tr_element, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');				
-			}
-			_dragArea.makeDragged(tr_element, headers_msgs[i].msg_number, headers_msgs[i].subject, true);
-		}
-
-		if ((preferences.use_shortcuts == '1') && (headers_msgs[0]))
-			select_msg(headers_msgs[0].msg_number, 'null', true);
-
-		var tdFolders  =  Element("folderscol");
-		tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
-		if ( !currentTab )
-			alternate_border(numBox);
-		draw_footer_box(headers_msgs.num_msgs);	
-		Element('main_table').style.display = '';
-		if(debug) {
-			var _eTime = new Date();
-			_eTime = _eTime.getTime();
-			alert("Carregou em "+(_eTime - _bTime)+" ms");
-		}
-		var msg_folder = Element('msg_folder').value;
-		var msg_number = Element('msg_number').value;	
-		if(!msg_folder && msg_number) {
-			new_message('new','null');
-		}
-		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);
-			Element('msg_folder').value = '';
-			Element('msg_number').value = '';
-		}
-
-		if(!is_ie) {
-			var scripts = new Array("jscode/ccQuickAdd",
-					"jscode/color_palette",
-					"jscode/filter",
-					"jscode/filters",
-					"jscode/html2xhtml",
-					"jscode/preferences",
-					"jscode/QuickCatalogSearch",
-					"jscode/QuickSearchUser",
-					"jscode/rich_text_editor",
-					"jscode/sharemailbox",
-					"jscode/search",
-					"jscode/TreeS",
-					"jscode/TreeShow");
-
-			expresso.connector.loadAllScripts(scripts);
-		}
-		// Loading Quota View Folder Component (if exists...)
-		if(Element("table_quota"))
-			expresso.connector.loadScript("jscode/InfoQuota");	
-	};
-
-
-
+
+
Index: trunk/expressoMail1_2/js/jscode/messages_controller.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2642)
+++ trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2676)
@@ -23,5 +23,5 @@
 		if(this.is_local_folder(msg_folder)) {
 			if(set_flag)
-				expresso_local_messages.set_messages_flag(msg_number,"seen");
+//				expresso_local_messages.set_messages_flag(msg_number,"seen");
 			var data = expresso_local_messages.get_local_mail(msg_number);	
 
Index: trunk/expressoMail1_2/js/jscode/mail_sync.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/mail_sync.js	(revision 2579)
+++ trunk/expressoMail1_2/js/jscode/mail_sync.js	(revision 2676)
@@ -154,4 +154,5 @@
 		
 		var start_sync_mails = function(data) {
+		        data =  expresso.connector.unserialize( data );
 			expresso_mail_sync.messages=data;
 			if(expresso_mail_sync.is_auto)
@@ -166,5 +167,12 @@
 		if (folder_to_sync[3]) {
 			document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages");
-			cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails);
+			_connector.cache();
+			_connector.go( {
+				"access" : "expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2],
+				"cache" : true,
+				"handler" : start_sync_mails
+			} );
+
+			//cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails);
 			this.is_auto = false;
 		}
@@ -172,5 +180,12 @@
 			document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder")+" "+lang_folder(folder_to_sync[1]);
 			var params = "folder="+folder_to_sync[0]+"&mails="+folder_to_sync[2];
-			cExecute("expressoMail1_2.imap_functions.msgs_to_archive", start_sync_mails,params);
+			_connector.cache();
+			_connector.go( {
+				"access" : "expressoMail1_2.imap_functions.msgs_to_archive"+params,
+				"cache" : true,
+				"handler" : start_sync_mails
+			} );
+
+			//cExecute("expressoMail1_2.imap_functions.msgs_to_archive", start_sync_mails,params);
 			this.is_auto = true;
 		}
@@ -192,5 +207,5 @@
 		new_value = parseInt(new_value) + 1;
 		document.getElementById('main_title').innerHTML = document.getElementById('main_title').innerHTML.replace(value_to_change,new_value+" /");
-		msg_to_sync = expresso.connector.unserialize(msg_to_sync);
+		//msg_to_sync = expresso.connector.unserialize(msg_to_sync);
 		
 		var source_msg = new Array();
@@ -387,6 +402,13 @@
 				expresso_mail_sync.remove_archived_mails();
 			}
-			
-			cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs, handler_delete_msgs);
+
+			_connector.cache();
+			_connector.go( {
+				"access" : "expressoMail1_2.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs,
+				"cache" : true,
+				"handler" : handler_delete_msgs
+			} );
+			
+			//cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs, handler_delete_msgs);
 			this.dbGears.execute("delete from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]);
 			this.dbGears.close();
Index: trunk/expressoMail1_2/js/jscode/local_messages.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/local_messages.js	(revision 2642)
+++ trunk/expressoMail1_2/js/jscode/local_messages.js	(revision 2676)
@@ -373,4 +373,5 @@
             for (i in anexos)
             {
+		if(!isNaN(i)){
                 nomeArquivo = anexos[i]['name'].substring(0,anexos[i]['name'].length - 4);
                 if(nomeArquivo.match('jpg')||anexos[i]['name'].match('gif')||anexos[i]['name'].match('png'))
@@ -389,4 +390,5 @@
                         }
                     }
+		}
             }
 
Index: trunk/expressoMail1_2/js/jscode/TreeS.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/TreeS.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/TreeS.js	(revision 2676)
@@ -178,26 +178,27 @@
 			var local_folders = expresso_local_messages.list_local_folders();
 			for (var i in local_folders) { //Coloca as pastas locais.
-			
-				var node_parent = "local_root";
-				var new_caption = local_folders[i][0];
-				if(local_folders[i][0].indexOf("/")!="-1") {
-					final_pos = local_folders[i][0].lastIndexOf("/");
-					node_parent = "local_"+local_folders[i][0].substr(0,final_pos);
-					new_caption = local_folders[i][0].substr(final_pos+1);
+				if(!isNaN(i)){
+				    var node_parent = "local_root";
+				    var new_caption = local_folders[i][0];
+				    if(local_folders[i][0].indexOf("/")!="-1") {
+					    final_pos = local_folders[i][0].lastIndexOf("/");
+					    node_parent = "local_"+local_folders[i][0].substr(0,final_pos);
+					    new_caption = local_folders[i][0].substr(final_pos+1);
+				    }
+
+				    if (local_folders[i][1] > 0)
+					    var nodeLocal = new dNode({
+						    id: "local_" + local_folders[i][0],
+						    caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
+						    plusSign: local_folders[i][2]
+					    });
+				    else
+					    var nodeLocal = new dNode({
+						    id: "local_" + local_folders[i][0],
+						    caption: lang_folder(new_caption),
+						    plusSign: local_folders[i][2]
+					    });
+				    folders_tree.add(nodeLocal, node_parent);
 				}
-				
-				if (local_folders[i][1] > 0) 
-					var nodeLocal = new dNode({
-						id: "local_" + local_folders[i][0],
-						caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
-						plusSign: local_folders[i][2]
-					});
-				else 
-					var nodeLocal = new dNode({
-						id: "local_" + local_folders[i][0],
-						caption: lang_folder(new_caption),
-						plusSign: local_folders[i][2]
-					});
-				folders_tree.add(nodeLocal, node_parent);
 			}
 		}
