Index: trunk/expressoMail1_2/js/jscode/InfoContact.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/InfoContact.js	(revision 2683)
+++ trunk/expressoMail1_2/js/jscode/InfoContact.js	(revision 3073)
@@ -174,3 +174,3 @@
 };
 /* Build the Object */
-var emInfoContact;
+var InfoContact = new emInfoContact();
Index: trunk/expressoMail1_2/js/jscode/messages_controller.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2929)
+++ trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 3073)
@@ -333,3 +333,7 @@
 		}
 	};
-
+proxy_mensagens = new messages_proxy();
+if (preferences.use_local_messages == 1 && window.google && google.gears){
+	expresso_local_messages = new local_messages();
+	expresso_local_messages.create_objects();
+}
Index: trunk/expressoMail1_2/js/jscode/draw_api_messages.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2800)
+++ trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 3073)
@@ -1,36 +1,2 @@
-// Objeto Map, talvez o ideal fosse adicionar este objeto Ã  Api do egroupware, e carregÃ¡-lo
-// aqui no expressoMail.
-function Map()
-{
-	this.keys = new Array();
-	this.values = new Array();
-}
-
-Map.prototype.add = function(key, value)
-{
-	this.keys.push(key);
-	this.values.push(value);
-};
-
-Map.prototype.get = function(key)
-{
-	result = new Array();
-	for (i = 0; i < this.keys.length; i++)
-	{
-		if (this.keys[i] == key)
-		{
-			result.push(this.values[i]);
-		}
-	}
-
-	if (result.length == 0)
-	{
-		return null;
-	}
-
-	return result;
-};
-
-var translatedFolders = new Map();
 
 function changeLinkState(el,state){
@@ -810,56 +776,3 @@
 	div_address_full.style.display='';
 }
-function draw_footer_box(num_msgs){
-	folder = get_current_folder();
-	var span_R = Element("table_message");	
-	var span_options = Element("span_options");	
-	if(!span_options) {
-		span_options = document.createElement("TD");	
-		span_options.style.fontSize = "12";
-		span_options.id = "span_options";
-		span_R.appendChild(span_options);
-	}
-
-	var change_font_color = 'onmouseover="var last_class = this.className;'+
-		'if (this.className != \'message_options_over\')'+
-				'this.className=\'message_options_active\'; '+
-				'this.onmouseout=function(){this.className=last_class;}"';
-
-				span_options.innerHTML =
-				'<span class="message_options_trash"><span ' + change_font_color + ' title="'+get_lang("Delete")+'" class="message_options" onclick=proxy_mensagens.delete_msgs(\'null\',\'selected\',\'null\')>'+get_lang("Delete")+'</span></span>'+
-				'<span class="message_options_move"><span ' + change_font_color + ' title="'+get_lang("Move")+'" class="message_options" onclick=wfolders.makeWindow(\"\",\"move_to\")>'+get_lang("Move")+'</span></span>'+
-				((expresso_offline)?" ":'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>')+
-				//		'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>'+
-				((expresso_offline)?" ":'<span class="message_options_export"><span ' + change_font_color + ' title="'+get_lang("Export")+'" class="message_options" onclick="proxy_mensagens.export_all_messages()">'+get_lang("Export")+'</span></span>') +
-				((expresso_offline)?" ":'<span class="message_options_import"><span ' + change_font_color + ' title="'+get_lang("Import")+'" class="message_options" onclick="import_window()">'+get_lang("Import")+'</span></span>');
-				if(preferences.use_local_messages==1 && !expresso_offline)
-				if(proxy_mensagens.is_local_folder(current_folder))
-				span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
-				else
-				span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null)">'+get_lang("Archive")+'</span>';
-				if (use_spam_filter) {
-				if ( current_folder == 'INBOX'+cyrus_delimiter+'Spam' )	{
-				span_options.innerHTML += ' | <span ' + change_font_color + ' title="'+get_lang("Not Spam")+'" class="message_options" onclick="nospam(\'selected\',\'null\',\'null\')">'+get_lang("Not Spam")+'</span>';
-				}
-				else {
-					span_options.innerHTML += ' | <span ' + change_font_color + ' title="'+get_lang("Mark as Spam")+'" class="message_options" onclick="spam(\'null\', \'selected\',\'null\')">'+get_lang("Mark as Spam")+'</span>';
-				}
-				}
-				var span_D = Element("span_D");	
-				if(!span_D){
-					span_D = document.createElement("TD");	
-					span_D.align = "right";
-					span_D.style.fontSize = "12";
-					span_D.id = "span_D";
-					span_R.appendChild(span_D);
-				}
-				span_D.innerHTML = 
-					get_lang("List")+': '+
-					'<span ' + change_font_color + ' id="span_flag_SORTARRIVAL" class="'+(search_box_type == 'ALL' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("All")+'" onclick="if(\'ALL\' == \''+search_box_type+'\') return false;sort_box(\'ALL\',\''+sort_box_type+'\')">'+get_lang("All")+'</span>, '+
-					'<span ' + change_font_color + ' id="span_flag_UNSEEN" class="'+(search_box_type == 'UNSEEN' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_unseen")+'" onclick="if(\'UNSEEN\' == \''+search_box_type+'\') return false;sort_box(\'UNSEEN\',\''+sort_box_type+'\')">'+get_lang("l_unseen")+'</span>, '+
-					'<span ' + change_font_color + ' id="span_flag_SEEN" class="'+(search_box_type == 'SEEN' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_seen")+'" onclick="if(\'SEEN\' == \''+search_box_type+'\') return false;sort_box(\'SEEN\',\''+sort_box_type+'\')">'+get_lang("l_seen")+'</span>, '+
-					'<span ' + change_font_color + ' id="span_flag_ANSWERED" class="'+(search_box_type == 'ANSWERED' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_answered")+'" onclick="if(\'ANSWERED\' == \''+search_box_type+'\') return false;sort_box(\'ANSWERED\',\''+sort_box_type+'\')">'+get_lang("l_answered")+'</span>, '+
-					'<span ' + change_font_color + ' id="span_flag_FLAGGED" class="'+(search_box_type == 'FLAGGED' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_important")+'" onclick="if(\'FLAGGED\' == \''+search_box_type+'\') return false;sort_box(\'FLAGGED\',\''+sort_box_type+'\')">'+get_lang("l_important")+'</span>&nbsp;&nbsp;';
-				draw_paging(num_msgs);
-				Element("tot_m").innerHTML = num_msgs;	
-};
+
Index: trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 3058)
+++ 	(revision )
@@ -1,1343 +1,0 @@
-
-
-var lastPage = 1;
-var numPages = 5;
-var last_folder = 'INBOX';
-
-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_header_box(){
-	switch(sort_box_type){
-		case 'SORTFROM':
-			type_name = get_lang("Who");
-			break;
-		case 'SORTSUBJECT':
-			type_name = get_lang("Subject");
-			break;
-		case 'SORTARRIVAL':
-			type_name = get_lang("Date");
-			break;
-		case 'SORTSIZE':
-			type_name = get_lang("Size");
-			break; 
-		default:
-			type_name = get_lang("Date");
-			break;
-	}
-	document.getElementById("_msgheadSORTFROM_"+numBox).innerHTML 	= get_lang("Who");
-	document.getElementById("_msgheadSORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
-	document.getElementById("_msgheadSORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
-	document.getElementById("_msgheadSORTSIZE_"+numBox).innerHTML	= get_lang("Size");	
-	var elHead = document.getElementById("_msghead"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox );
-	if(elHead != null)
-		elHead.innerHTML = "<B>"+type_name+'</B><img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/arrow_'+(sort_box_reverse == 1 ? 'desc' : 'asc')+'endant.gif">';
-}
-
-function draw_search_header_box(){
-	var _tbl_msghead_bx = Element("_tbl_msghead_bx");
-	_tbl_msghead_bx.parentNode.removeChild(_tbl_msghead_bx);
-
-	var content_id_0 = Element("content_id_0");
-	var table_element = document.createElement("TABLE");
-	var tbody_element = document.createElement("TBODY");
-	table_element.setAttribute("id", "_tbl_msghead_bx");
-	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  = "chkbox_sel_allmsg";
-	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 = "_msgheadSORTFROM";
-	td_element3.align = "left";
-	td_element3.innerHTML = get_lang("From");
-	td_element4 = document.createElement("TD");
-	td_element4.setAttribute("width", "49%");
-	td_element4.id = "_msgheadSORTSUBJECT";
-	td_element4.align = "left";
-	td_element4.innerHTML = get_lang("Subject");
-	td_element5 = document.createElement("TD");
-	td_element5.setAttribute("width", "10%");
-	td_element5.id = "_msgheadSORTARRIVAL";
-	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 = "_msgheadSORTSIZE";
-	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);
-}
-
-function build_quota(data){
-	id = "content_quota";
-	q_limit = data['quota_limit']*1024;
-	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']*1024;
-			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+"% ("+borkb(q_used)+"/"+borkb(q_limit)+")</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.draw_newBox(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.draw_newBox(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.draw_newBox(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.
-	if ( ! Element( 'dftree_tree_folders' ) )
-	{
-		translatedFolders = new Map( );
-		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' && ( ! 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 );
-			}
-		}
-
-		/**
-		 * 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 ) ) != 'function' )
-				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' );
-
-		var folder_img = URL_SERVER + "phpgwapi/templates/" +template + "/images/foldertree_";
-
-		if ( trash_span )
-			trash_span.style.backgroundImage = "url(" + folder_img + "trash.png)";
-
-		if ( draft_span )
-			draft_span.style.backgroundImage = "url(" + folder_img + "draft.png)";
-
-		if ( sent_span )
-			sent_span.style.backgroundImage = "url(" + folder_img + "sent.png)";
-
-		if ( spam_span )
-			spam_span.style.backgroundImage = "url(" + folder_img + "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 );
-		}
-
-		if ( ! expresso_offline )
-			var _disp_unseen_mb = tree_folders.getNodeById( 'root' );
-		else
-			var _disp_unseen_mb = tree_folders.getNodeById( 'local_root' );
-
-		_disp_unseen_mb.alter( {
-			"caption" : get_lang( "My Folders" )
-		} );
-
-		_disp_unseen_mb._refresh( );
-
-		var _dip_unseen_shardfolder = tree_folders.getNodeById( 'user' );
-
-		if ( _dip_unseen_shardfolder )
-		{
-			if ( unseen_in_shared_folders )
-				_dip_unseen_shardfolder.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
-				_dip_unseen_shardfolder.alter( {
-					"caption" : get_lang( "Shared folders" )
-				} );
-
-			_dip_unseen_shardfolder._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 );
-			}
-		}
-	}
-
-	Element( 'main_table' ).style.display = '';
-	draw_box.prepare_box( false );
-	resizeWindow( );
-}
-
-
-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.draw_newBox( expresso.connector.unserialize( data ), 'INBOX', true);
-//alternate_border(0);
-};
-
-// Action on change folders.
-function change_folder(folder, folder_name){
-    alternate_border(numBox);
-    if (openTab.imapBox[numBox] != folder)
-    {
-	current_folder = folder;
-	draw_box.prepare_box(true);
-	Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">0</span> / <span id="tot_m">0</span>]</font>';
-	var handler_draw_box = function(data)
-	{
-		draw_box.headers_msgs = data;
-		draw_box.draw_box_messages(data, folder, true);
-		draw_paging(data.num_msgs);
-		Element("tot_m").innerHTML = data.num_msgs;
-		Element("new_m").innerHTML = '<font style="color:'+(data.num_unseen > 0 ? 'red': '')+'">' + data.num_unseen + '</font>';
-		folder_unseen = Element('dftree_'+current_folder+'_unseen');
-		var num_unseen = data.num_unseen;
-		if (folder_unseen)
-			num_unseen -= folder_unseen.innerHTML;
-		increment_folder_unseen(num_unseen);
-		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);
-    }
-}
-
-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.draw_newBox(data, current_folder);
-	    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.headers_msgs = data;
-	draw_box.draw_box_messages(current_folder);
-
-	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;
-
-    draw_box.prepare_box(true);
-    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 = createAndSet("TD",['class','width'],['td_msg','1%']);
-	_chkbox = createAndSet("INPUT", ['type','class','id'], ['checkbox','checkbox',"check_box_message_"+headers_msgs.msg_number]);
-	_chkbox.onclick = function(e){
-		if (is_ie)
-			changeBgColor(window.event,headers_msgs.msg_number);
-		else
-			changeBgColor(e,headers_msgs.msg_number);
-	};
-	td_element1.appendChild(_chkbox);
-
-	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=0; item < attach_name.length; item++)
-		{
-			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 = '';
-	}
-	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;
-
-	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' || (parseInt(preferences.use_important_flag) && headers_msgs.Importance.toLowerCase().indexOf("high") != -1))
-	{
-		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 images
-	var _img_sent = new Image();
-	_img_sent.src 	= URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif';
-	var _img_unseen = new Image();
-	_img_unseen.src = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/unseen.gif';
-
-	var td_element25 = document.createElement("TD");
-	td_element25.className = "td_msg";
-	td_element25.setAttribute("width", "1%");
-	td_element25.id = "td_message_unseen_"+headers_msgs.msg_number;
-	if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N'))
-		td_element25.innerHTML = "<img src ='"+_img_unseen.src+"' title='"+get_lang('Unseen')+"'>";
-	else
-		td_element25.innerHTML = "<img src ='"+URL_SERVER +"expressoMail1_2/templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
-
-	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_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 && 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");
-	var norm = function (arg) {return (arg < 10 ? '0'+arg : arg);};
-	var weekDays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
-	var date_msg = new Date(headers_msgs.udate*1000);
-	var today = new Date();
-	if (today.getTime() - date_msg.getTime() < 86400000)
-		td_element5.innerHTML = norm(date_msg.getHours()) + ':' + norm(date_msg.getMinutes());
-	else
-		if (today.getTime() - date_msg.getTime() < 172800000)
-			td_element5.innerHTML = get_lang('Yesterday');
-		else
-			if (today.getTime() - date_msg.getTime() < 259200000)
-				td_element5.innerHTML = get_lang(weekDays[date_msg.getDay()]);
-			else
-				td_element5.innerHTML = norm(date_msg.getDate()) + '/' + norm(date_msg.getMonth()+1) + '/' +date_msg.getFullYear();
-	td_element5.title = norm(date_msg.getDate()) + '/' + norm(date_msg.getMonth()+1) + '/' +date_msg.getFullYear();
-	td_element5.alt = td_element5.title;
-
-	td_element6 = document.createElement("TD");
-	td_element6.className = "td_msg";
-	td_element6.setAttribute("width", "14%");
-	td_element6.setAttribute("noWrap","true");
-	td_element6.setAttribute("align", "center");
-	td_element6.onclick = _onclick;
-
-	td_element6.innerHTML = borkb(headers_msgs.Size);
-
-	return appendChilds(tr_element,td_element1,td_element2,td_element21,td_element22,td_element23,td_element24,td_element25,td_element3,td_element4,td_element5,td_element6);
-}
-function draw_folder(){
-}
-
-draw_folder.prototype.draw_newBox = function(headers_msgs,msg_folder,alternate){
-	this.headers_msgs = headers_msgs;
-	this.prepare_box( alternate );
-	this.draw_box_messages(headers_msgs,msg_folder);
-};
-
-draw_folder.prototype.prepare_box = function(alternate){
-	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.type[numBox] = 0;
-	_tbl_msghead_bx = Element("_tbl_msghead_bx_"+numBox);
-	if (_tbl_msghead_bx == null){
-		var table_element = document.createElement("TABLE");
-		table_element.setAttribute("id", "_tbl_msghead_bx_"+numBox);
-		table_element.setAttribute('class',  "table_message_header_box");
-
-		var tbody_element = document.createElement("TBODY");
-
-		tr_element = createAndSet("TR",['class'],['message_header']);
-		td_element1 = createAndSet("TD",['width'],['1%']);
-		_chkbox_element = createAndSet("INPUT",['id','type','class'],["chkbox_sel_allmsg","checkbox","checkbox"]);
-		_chkbox_element.onclick = function(){
-			select_all_messages(this.checked);
-		};
-		_chkbox_element.onmouseover = function () {
-			this.title=get_lang('Select all messages.');
-		};
-		_chkbox_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(_chkbox_element);
-
-		td_element2 = document.createElement("TD");
-		td_element2.setAttribute("width", "7%");
-		td_element3 = createAndSet("TD",['width','id','align'],['29%',"_msgheadSORTFROM_"+numBox,'left'],get_lang("Who"));
-		td_element3.onclick = function () {
-			sort_box(search_box_type,'SORTFROM');
-		};
-		td_element4 = createAndSet("TD",['width','id','align'],['38%',"_msgheadSORTSUBJECT_"+numBox,"left"],get_lang("Subject"));
-		td_element4.onclick = function () {
-			sort_box(search_box_type,'SORTSUBJECT');
-		};
-		td_element5 = createAndSet("TD",['width','id','align'],["14%","_msgheadSORTARRIVAL_"+numBox,"center"],get_lang("Date"));
-		td_element5.onclick = function () {
-			sort_box(search_box_type,'SORTARRIVAL');
-		};
-		td_element6 = createAndSet("TD",['width','id','align'],["14%","_msgheadSORTSIZE_"+numBox,"left"],get_lang("Size"));
-		td_element6.onclick = function () {
-			sort_box(search_box_type,'SORTSIZE');
-		};
-		appendChilds(tr_element,td_element1,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;";
-
-		tbody_element.appendChild(appendChilds(tr_element,td_element21,td_element22,td_element23,td_element3,td_element4,td_element5,td_element6));
-		table_element.appendChild(tbody_element);
-		openTab.content_id[numBox].appendChild(table_element);
-	}
-	draw_header_box();
-	var _divScroll = document.getElementById("divScrollMain_"+numBox);
-	if(!_divScroll){
-		_divScroll = document.createElement("DIV");
-		_divScroll.id = "divScrollMain_"+numBox;
-	}
-
-	_divScroll.style.overflowY = "auto";
-	_divScroll.style.overflowX = "hidden";
-	_divScroll.style.width	="100%";
-
-	var _t_element = createAndSet("TABLE",['id','class','borderColorDark','frame','rules','cellPadding','cellSpacing'],["table_box","table_box","#bbbbbb","void","rows","0","0"]);
-	_t_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)
-		_t_element.style.cursor = "hand";
-
-	var _tbody_element = document.createElement("TBODY");
-	_tbody_element.setAttribute("id", "tbody_box");
-	_t_element.appendChild(_tbody_element);
-
-        _divScroll.appendChild(_t_element);
-
-	openTab.content_id[numBox].appendChild(_divScroll);
-	if (alternate)
-		_divScroll.appendChild(loading_img);
-};
-
-draw_folder.prototype.draw_box_messages = function(msg_folder){
-	openTab.content_id[numBox] = document.getElementById("content_id_"+numBox);
-	var _divScroll = document.getElementById("divScrollMain_"+numBox);
-	try{
-		loading_img = _divScroll.removeChild( loading_img );
-	}
-	catch(e){ }
-	var tbody_element = _divScroll.firstChild.firstChild;
-
-	var f_unseen = 0;
-	openTab.imapBox[numBox] = msg_folder;
-	if (this.headers_msgs.num_msgs == 0){
-		var tr_info = document.createElement("TR");
-		var td_info = createAndSet("TD",['colspan','background','align','style'],
-				['10','#FFF','center','padding-top: 25px;font-weight:bold;font-size:11pt;'],get_lang("This mail box is empty"));
-		tr_info.setAttribute("id", "msg_info");
-		tr_info.appendChild(td_info);
-		tbody_element.appendChild(tr_info);
-	}
-
-
-	for (var i=0; i < this.headers_msgs.length; i++){
-		if ((this.headers_msgs[i].Unseen == 'U') || (this.headers_msgs[i].Recent == 'N'))
-			f_unseen++;
-		tr_element = make_tr_message(this.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');
-		}
-		if ( _dragArea == null )
-			_dragArea = new DragArea( );
-		_dragArea.makeDragged(tr_element, this.headers_msgs[i].msg_number, this.headers_msgs[i].subject, true);
-	}
-
-	if ((preferences.use_shortcuts == '1') && (this.headers_msgs[0]))
-		select_msg(this.headers_msgs[0].msg_number, 'null', true);
-
-	var tdFolders  =  Element("folderscol");
-	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
-	draw_footer_box(this.headers_msgs.num_msgs);
-	Element('main_table').style.display = '';
-	if(is_ie6)	// Stupid Fixing on IE6.
-		setTimeout("resizeWindow()",1);
-	else
-		resizeWindow();	
-	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){
-		proxy_mensagens.get_msg(this.headers_msgs, url_encode(msg_folder),true, 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");
-	alternate_border(numBox);
-};
-
-draw_box = new draw_folder();
Index: trunk/expressoMail1_2/js/jscode/drag_area.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/drag_area.js	(revision 2929)
+++ 	(revision )
@@ -1,256 +1,0 @@
-function DragArea()
-{
-	this.msg_number = false;
-	this.subject	= false;
-	this.folder		= '';
-	this.color_dd	= 'red';
-	this.from_list	= false;
-	this._mousemove = document.onmousemove;
-	this._mouseup = document.onmouseup;
-	this.div_dd = document.createElement("DIV");
-	this.id_messages_to_drag = new Array();
-	this.div_dd.style.position = 'absolute';
-	this.div_dd.style.zIndex = '15';
-	this.div_dd.style.border = '1px solid black';
-	this.div_dd.style.background ="#EEEEEE";
-	var value = "8.5";
-	this.div_dd.style.opacity = value/10;
-	this.div_dd.style.filter = 'alpha(opacity=' + value*10 + ')';	
-	this.div_dd.id = 'div_sel_messages';
-	this.div_dd.style.padding = "3px";
-	this.div_dd.style.width = "0px";
-	this.div_dd.style.height = "0px";
-	this.div_dd.style.display ='none';
-	this.envelope = new Image();
-	this.envelope.src = URL_SERVER + "expressoMail1_2/templates/"+template+"/images/envelope.png";
-	document.body.appendChild(this.div_dd);
-
-	XEvents.add( document, 'onmousemove', function( e )
-	{
-		var	_target = is_ie ? window.event.srcElement : e.target;
-		//if(_dragArea._mousemove)
-		//	_dragArea._mousemove(e);
-
-		//else
-			if( _dragArea && _dragArea.msg_number && _target.type != 'checkbox')
-			{
-				_dragArea.mouseMoveDrag( e );
-			}
-	} );
-
-	XEvents.add( document, 'onmouseup', function( e )
-	{
-		var	_event  = is_ie ? window.event : e;
-		var	_target = is_ie ? _event.srcElement : _event.target;
-		var _button = is_ie ? _event.button : _event.which;
-
-		if(_button != 2 && _button != 3) {		
-
-			if ( Element("div_rightbutton") && Element("div_rightbutton").style.display != 'none' )
-			{
-				if ( ! _target.id.match( /link_rightbutton_(.*)$/ ) )
-				{
-					var id_messages_to_drag = get_selected_messages();
-					id_messages_to_drag = id_messages_to_drag ? id_messages_to_drag.split(',') : id_messages_to_drag;
-
-					for(var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++)
-					{
-						Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
-						changeBgColor(_event ,id_messages_to_drag[i]);
-					}
-					Element("chkbox_sel_allmsg").checked = false;
-					Element('div_rightbutton').style.display = 'none';
-					_dragArea.msg_number = false;
-					_dragArea.div_dd.style.display ='none';
-					return false;
-				}
-			}
-			if(is_ie)
-				_dragArea.onSelectStart(true);
-
-			if ( Element("div_rightbutton_folder") && Element("div_rightbutton_folder").style.display != 'none' )
-			{
-				Element('div_rightbutton_folder').style.display = 'none';
-			}
-
-		}
-
-
-		if(_dragArea.msg_number)
-		{
-			var reg = /^((n|l)(?!root))(.*)tree_folders$/;
-			var new_folder;
-
-			if ( reg.test(_target.parentNode.id) )
-			{
-				new_folder = _target.parentNode.id.substring(1,_target.parentNode.id.length).replace('tree_folders','');
-				new_folder_name = new_folder.replace("INBOX"+cyrus_delimiter, "");
-				if(new_folder_name == 'INBOX')
-					new_folder_name = get_lang("Inbox");
-				if ( _dragArea.from_list )
-				{
-					if (numBox != 0)
-						move_search_msgs("content_id_search_" + numBox, new_folder, new_folder_name);
-					else
-						proxy_mensagens.proxy_move_messages("null", 'selected', 0, new_folder, new_folder_name);
-				}
-				else
-				{
-					var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
-					proxy_mensagens.proxy_move_messages("null", msg_number, msg_number + "_r", new_folder, new_folder_name);
-				}
-			}
-
-			else
-				if ( _dragArea.from_list && _target.type != 'checkbox' && _dragArea.div_dd.style.display !='none' )
-				{
-					var id_messages_to_drag = get_selected_messages( );
-					if( id_messages_to_drag )
-					{
-						id_messages_to_drag = id_messages_to_drag.split(',');
-
-						for ( var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++ )
-						{
-							Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
-							changeBgColor(_event ,id_messages_to_drag[i]);
-						}
-						Element("chkbox_sel_allmsg").checked = false;	
-					}
-				}
-
-			_dragArea.msg_number = false;
-			_dragArea.div_dd.style.display ='none';
-			if(is_ie)
-				_dragArea.onSelectStart(true);
-		}
-
-	} );
-}
-
-DragArea.prototype.makeMenuBox = function(element){
-
-	element.oncontextmenu = function(e)
-	{
-		return false;
-	};
-	
-	var _this = this;
-	
-	element.onmousedown = function (e)
-	{
-		var _button = is_ie ? window.event.button : e.which;
-
-		if(_button == 2 || _button == 3)
-		{
-			var boxFolder = element.id.substr(1,element.id.indexOf('tree_folders')-1);
-			var boxName = element.firstChild.nextSibling.innerHTML;
-			ConstructBoxMenu(is_ie ? window.event : e,boxName,boxFolder);
-		}
-				
-		return true;
-	};	
-	
-};
-
-DragArea.prototype.makeDragged = function(element, msg_number, subject, from_list, folder){
-	element.oncontextmenu = function(e) {
-		return false;
-	};
-	var _this = this;
-	element.onmousedown = function (e){
-
-		var _button = is_ie ? window.event.button : e.which;
-	
-		if(_button == 2 || _button == 3) {
-			var _checkb = Element("check_box_message_"+ msg_number);
-
-			if(_checkb) {
-				if(!_checkb.checked) {
-					changeBgColor(is_ie ? window.event : e, msg_number);
-					_checkb.checked = true;
-				}
-				ConstructRightMenu(is_ie ? window.event : e);
-			}			
-			return false;
-		}
-
-		if(!_this.msg_number) {
-			_this.msg_number = msg_number;
-
-			if(!subject)
-				_this.subject = get_lang("No Subject");
-			//else if(subject.length > 40)
-			//	_this.subject = subject.substring(0,40) + '...';				
-			else
-				_this.subject	 = subject;
-
-			_this.from_list  = from_list;
-			_this.div_dd.style.width = "auto";
-			_this.div_dd.style.height = "auto";			
-			_this.folder = folder;
-		}
-		return true;
-	};	
-};
-DragArea.prototype.showLayerDrag = function(e){
-
-	var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
-	if(_dragArea.from_list) {
-
-		if((Element("check_box_message_"+msg_number)) && (! Element("check_box_message_"+msg_number).checked)) {
-			if (is_ie)
-				changeBgColor(window.event,msg_number);
-			else
-				changeBgColor(e,msg_number);
-			Element("check_box_message_"+ msg_number).checked = true;	
-		}
-		id_messages_to_drag = get_selected_messages();
-		id_messages_to_drag = id_messages_to_drag ? id_messages_to_drag.split(',') : new Array();
-	
-		if(id_messages_to_drag.length > 1)
-			this.subject = id_messages_to_drag.length +" mensagens selecionadas";
-	}
-
-	this.div_dd.innerHTML = "<img align='center' src='"+this.envelope.src+"'>&nbsp;<span id='content_dd'><font color='red' weight='bold'><b>"+this.subject+"</b></span></font>";
-	this.div_dd.style.display ='';
-};
-
-DragArea.prototype.onSelectStart = function(value){
-	if(!value) {
-		document.body.onselectstart = function (e){return false;};
-		document.body.ondragstart = function (e){return false;};
-	}
-	else {
-		document.body.onselectstart = function (e){return true;};
-		document.body.ondragstart = function (e){return true;};
-	}
-};
-
-DragArea.prototype.mouseMoveDrag = function(e){		
-	
-	var	e  = is_ie ? window.event : e;
-	var	_target = is_ie ? e.srcElement : e.target;
-	if(is_ie)
-		this.onSelectStart(false);
-
-	this.div_dd.style.left	= e.clientX + 5 + document.body.scrollLeft;
-	this.div_dd.style.top 	= e.clientY + 10 + document.body.scrollTop;		
-
-	if(this.div_dd.style.display == 'none')
-		this.showLayerDrag(e);
-	
-	var reg = /^((n|l)(?!root))(.*)tree_folders$/;
-	var _color = this.color_dd;
-
-	if(reg.test(_target.parentNode.id) )
-		_color ='green';
-	else
-		_color ='red';
-	
-	if(this.color_dd != _color) {
-		Element('content_dd').innerHTML = "<font color='"+_color+"' weight='bold'><b>"+this.subject+"</b></font>";
-		this.color_dd = _color;
-	}
-
-	return false;
-};
Index: trunk/expressoMail1_2/js/jscode/abas.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/abas.js	(revision 2800)
+++ 	(revision )
@@ -1,283 +1,0 @@
-var openTab = {
-	'type' : [], // 8 types of tabs, further info. see expressolivre.org/dev/wiki/mail/Documentacao
-	'content_id' : [],
-	'imapUid' : [], // Stores the imap email number of current tab
-	'countFile' : [0,0,0,0,0,0,0,0,0,0], // Stores the number of files attached in current tab
-	'imapBox' : [], // Stores the folder name
-	'toPreserve' : [], // Check if the message should be removed from draft after send
-	'autosave_timer' : [] // The timeout timer for autosave function
-};
-var tabTypes = {
-	'new':4,
-	'forward':6,
-	'reply_with_history':7,
-	'reply_to_all_with_history':7,
-	'reply_without_history':7,
-	'reply_to_all_without_history':7,
-	'edit':5
-};
-var currentTab,numBox = 0; // Open Tab and num of mailboxes opened at context
-
-function setBorderAttributes(ID)
-{
-	this.border_id = "border_id_"+ID;
-	this.sequence = ID; 
-}
-
-
-function alternate_border(ID)
-{
-	if (! Element('border_id_'+ID))
-		return false; // Not possible to alternate
-	show_hide_span_paging(ID);
-	spanD = Element("span_D");
-	if (spanD)
-		spanD.style.display = (openTab.type[ID] == 0 ? '' : 'none');
-
-	var footer_menu = Element("footer_menu");	
-	if (footer_menu) {
-		footer_menu.style.display = (openTab.type[ID] != 4 ? '' : 'none');
-	}
-
-	var len = BordersArray.length;
-	for (var i=0; i < len; i++)
-	{
-		m = document.getElementById(BordersArray[i].border_id);
-		if ((m)&&(m.className == 'menu-sel'))
-		{
-			m.className = 'menu';
-			c = document.getElementById("content_id_"+BordersArray[i].sequence);
-			c.style.display = 'none';
-			if(Element("font_border_id_"+BordersArray[i].sequence))
-				Element("font_border_id_"+BordersArray[i].sequence).className = 'font-menu';	
-			var body = Element('body_'+BordersArray[i].sequence);
-			if (body)
-			{
-				try
-				{
-					if (Element('viewsource_rt_checkbox').checked)
-					{  
-						expresso.connector.loadScript("jscode/rich_text_editor");
-						RichTextEditor.viewsource(false);
-					}
-				}
-				catch(e)
-				{
-					//alert(e.message)
-				}
-			}
-		}
-	}
-
-	m = Element("border_id_"+ID);
-	if (m)
-		m.className = 'menu-sel';
-	if(Element("font_border_id_" + ID))
-		Element("font_border_id_" + ID).className = 'font-menu-sel';
-	var c = Element("content_id_"+ID);
-	if (c)
-		c.style.display = '';
-
-	body = document.getElementById('body_'+ ID);
-	if (body){
-		try{
-			if(ID){
-				expresso.connector.loadScript("jscode/rich_text_editor");
-				RichTextEditor.loadEditor(ID);
-			}
-			body.contentWindow.document.designMode="on";
-		}
-		catch(e){
-			//alert(e.message);
-		};
-	}
-
-	// hide the DropDrowContact, if necessary
-	window_DropDownContacts = Element('tipDiv');
-	if ((window_DropDownContacts)&&(window_DropDownContacts.style.visibility != 'hidden')){
-		window_DropDownContacts.style.visibility = 'hidden';
-	}
-
-	if (typeof(ID) == 'number')
-	{
-        numBox=ID;
- 	}
-	else
-		if (ID.match("search_"))
-			numBox=ID.substr(7);
-
-	currentTab=ID;
-	return ID;
-}
-
-function create_border(borderTitle, id_value)
-{
-	if ( _dragArea == null )
-		_dragArea = new DragArea( );
-
-	var resize = false;
-	var offWidth = Element('border_blank').offsetWidth ? Element('border_blank').offsetWidth : Element('border_blank').clientWidth;
-	if (offWidth < 200) {
-		resize = resize_borders();
-		if (!resize){
-			alert(get_lang('Reached maximum tab limit'));
-			return false;
-		}
-	}
-	
-	if (! id_value) // Is new message?
-		var ID = parseInt(BordersArray[(BordersArray.length-1)].sequence) + 1;
-	else
-	{
-                if (Element("border_id_"+id_value)) // It's opened already!
-			return alternate_border(id_value);
-		var ID = id_value;
-		openTab.imapBox[ID] = current_folder;
-	}
-	td = document.createElement("TD");
-	td.id="border_id_" + ID;
-	if(resize) {
-		td.setAttribute("width", parseInt(resize)+"px");
-		td.style.width = parseInt(resize)+"px";
-	}
-	else
-		td.setAttribute("width", "200px");
-
-	td.setAttribute("align", "right");	
-	td.onclick = function(){alternate_border(ID);resizeWindow()}; 
-	td.setAttribute("noWrap","true");
-        td.alt = borderTitle;
-        td.title = borderTitle;
-	borderTitle = borderTitle ?  borderTitle : id_value ? get_lang("No Subject") : "&nbsp;"	;
-	td.value = borderTitle;
-	if (borderTitle.length > 21)
-		borderTitle = borderTitle.substring(0,21) + "...";
-
-	if (resize)
-		borderTitle = borderTitle.substring(0, resize*0.08);
-
-	td.innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + ID+" class='font-menu' width=*>" + borderTitle + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/close_button.gif'></td></tr></table>";
-
-	bb = document.getElementById("border_blank");
-	parent_bb = bb.parentNode; //Pego o tbody
-	parent_bb.insertBefore(td, bb);
-
-	if(! Element("border_id_"+id_value+"_r") ||((typeof(id_value) == 'string') && id_value.match(/_r$/)))
-		_dragArea.makeDragged(td, id_value,td.value);
-
-	BordersArray[BordersArray.length] = new setBorderAttributes(ID);
-
-	var div = document.createElement("DIV");
-	div.id = "content_id_" + ID;
-	div.className = "conteudo";
-	div.style.display='';
-
-	div.style.overflow = "hidden";
-	Element("exmail_main_body").insertBefore(div,Element("footer_menu"));
-	alternate_border(ID);
-	return ID;
-}
-
-function resize_borders()
-{
-	var children;
-	var	numBorders = 0;	
-	var widthTD = 0;
-	var newWidthTD = 0;		
-	children = Element('border_tr').childNodes;	
-	for (var i=0; i<children.length; i++) {
-		if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')) {
-			numBorders++;
-			if(!widthTD)
-				widthTD = children[i].clientWidth;				
-		}
-	}
-	if (numBorders > 8)
-		return false;
-	
-	newWidthTD = ((numBorders*widthTD)+(Element("border_blank").clientWidth-44))/(numBorders+1);
-	for (var i=0; i<children.length; i++) {
-		if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')){
-			children[i].style.width = newWidthTD;
-			Element("font_"+children[i].id).innerHTML = Element("font_"+children[i].id).innerHTML.substring(0, newWidthTD*0.08);
-		}
-	}
-	return newWidthTD;
-}
-
-function delete_border(ID, msg_sent)
-{
-	var borderElem = Element("border_id_" + ID);
-	if (borderElem)
-		borderElem.onclick = null; // It's avoid a FF3 bug
-	else
-		return false;
-
-	if (msg_sent == 'false')
-	{
-		var body = document.getElementById('body_'+ ID);
-		if (body)
-		{
-				var save_link = Element("save_message_options_"+ID);
-				if (openTab.toPreserve[ID] == undefined);
-					openTab.toPreserve[ID] = false;
-				if ((! openTab.toPreserve[ID] && ! ID.toString().match("_r")) || ((body.contentWindow) == 'object' && body.contentWindow.document.designMode.toLowerCase() == 'on') && (save_link.onclick != ''))
-				{
-					var discard_msg = confirm(get_lang("Your message has not been sent. Discard your message?"), "");
-					if (!discard_msg)
-					{
-						Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
-						return;
-					}
-					else
-					{
-						if (openTab.imapBox[ID] &&  openTab.imapUid[ID] && !openTab.toPreserve[ID]){
-							delete_msgs(openTab.imapBox[ID], openTab.imapUid[ID].toString(), 0);
-							openTab.toPreserve[ID] = false;
-							}
-						delete(openTab.imapBox[ID]);	
-							// Element('to_'+ID).focus(); It crash on IE
-					}
-				}
-		}
-	}
-
-	openTab.toPreserve[ID] = false;
-	openTab.imapUid[ID] = 0;
-
-	if (preferences.auto_save_draft == 1)
-	{
-		if (openTab.autosave_timer[ID])
-			clearTimeout(openTab.autosave_timer[ID]);
-		openTab.autosave_timer[ID] = false;
-	}
-
-	expresso.connector.hold_session = false;
-	if (exist_className(Element('border_id_'+ID),'menu-sel'))
-	{
-		if (BordersArray[BordersArray.length-2].sequence == ID)
-			this.alternate_border(0);
-		else
-			this.alternate_border(BordersArray[BordersArray.length-2].sequence);
-	}
-
-	// Remove TD, title
-	border = Element('border_id_' + ID);
-	border.parentNode.removeChild(border);
-	var j=0;
-	var new_BordersArray = new Array();
-	for (i=0;i<BordersArray.length;i++)
-		if (document.getElementById(BordersArray[i].border_id) != null){
-			new_BordersArray[j] = BordersArray[i];
-			j++;
-		}
-	if(j == 1)
-		Element("footer_menu").style.display = '';
-	BordersArray = new_BordersArray;
-
-	// Remove Div Content
-	content = Element('content_id_' + ID);
-	content.parentNode.removeChild(content);
-	resizeWindow();
-	return true;
-};
Index: trunk/expressoMail1_2/js/jscode/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/common_functions.js	(revision 2930)
+++ 	(revision )
@@ -1,684 +1,0 @@
-if (!expresso_offline) {
-	var _showBar = showBar;
-	var _hideBar = hideBar;
-}
-
-function __showBar(){
-	_showBar();
-	resizeWindow();
-}
-
-function __hideBar(){
-	_hideBar();
-	resizeWindow();
-}
-showBar = __showBar;
-hideBar = __hideBar;
-
-XEvents.add( window, 'onresize', resizeWindow );
-// BEGIN: FUNCTION RESIZE WINDOW 
-function resizeWindow(){
-
-	var divScrollMain = Element("divScrollMain_"+numBox);
-	var table_message = Element("table_message");
-	var content_folders = Element("content_folders");
-	var clientHeight = ((window.innerHeight ? window.innerHeight : document.body.offsetHeight) - 8);
-	var clientWidth = ((window.innerWidth ? window.innerWidth : document.body.offsetWidth) - 17);
-  
-	if(divScrollMain){ 
-		divScrollMain.style.height = (clientHeight - (findPosY(divScrollMain) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px"; 
-	}
-
-	if(typeof(BordersArray) != 'undefined') {
-		for(var i = 1; BordersArray.length > 1 && i < BordersArray.length;i++) {
-			var div_scroll = Element("div_message_scroll_"+BordersArray[i].sequence);
-			var div = Element("content_id_"+BordersArray[i].sequence);
-
-			if(div){
-			 	div.style.height = (clientHeight - (findPosY(div) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+2)) + "px";
-			 	div.style.width = (clientWidth - (findPosX(div)+10)) + "px"; 
-			}
-			if(div_scroll){
-				div_scroll.style.height = (clientHeight - (findPosY(div_scroll) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px";
-				div_scroll.style.width = (clientWidth - (findPosX(div_scroll)+10)) + "px";
-			}
-		} 
-	} 
-			 		 
- 	if(content_folders){ 
- 		var search_div = Element("search_div");
- 		var contentFoldersY = findPosY(content_folders);
- 		content_folders.style.height = (clientHeight - (contentFoldersY + (contentFoldersY > findPosY(search_div) ? 0 : (search_div.clientHeight ? search_div.clientHeight : search_div.offsetHeight) + 5))) + "px";
- 	} 
-}
-// END: FUNCTION RESIZE WINDOW
-
-var _beforeunload_ = window.onbeforeunload;
-
-window.onbeforeunload = function()
-{
-	return unloadMess();
-};
-
-function unloadMess(){
-	if (typeof(expresso_mail_sync) != "undefined" && expresso_mail_sync.working) {
-		var mess = get_lang("You're about archiving your e-mails from server. Do you really want to stop this action?");
-		return mess;
-	}
-	else {
-		var mess = get_lang("Your message has not been sent and will be discarted.");
-		for (var i = 0; i < BordersArray.length; i++) {
-			var body = Element('body_' + BordersArray[i].sequence);
-			if (body && body.contentWindow && body.contentWindow.document.designMode.toLowerCase() == 'on') {
-				return mess;
-			}
-		}
-	}
-}
-
-// Change the class of message.
-// In refresh, the flags UnRead and UnSeen don't exist anymore. 
-function set_msg_as_read(msg_number, selected){
-	tr_message = Element(msg_number);
-	if (exist_className(tr_message, 'tr_msg_unread'))
-		decrement_folder_unseen(1);
-	remove_className(tr_message, 'tr_msg_unread');
-	remove_className(tr_message, 'selected_msg');
-	Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
-	return true;
-}
-
-function msg_is_read(msg_number, selected){
-	tr_message = Element(msg_number);
-	return !(tr_message && LTrim(tr_message.className).match('tr_msg_unread'));
-}
-
-function set_msg_as_unread(msg_number){
-	tr_message = Element(msg_number);
-	if ((exist_className(tr_message, 'tr_msg_read') || exist_className(tr_message, 'tr_msg_read2')) && (!exist_className(tr_message, 'tr_msg_unread')))
-		increment_folder_unseen(1);
-	remove_className(tr_message, 'selected_msg');
-	add_className(tr_message, 'tr_msg_unread');
-	Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/unseen.gif' title='"+get_lang('Unseen')+"'>";
-}
-
-function set_msg_as_flagged(msg_number){
-	var msg = Element(msg_number);
-	remove_className(msg, 'selected_msg');
-	add_className(msg, 'flagged_msg');
-	Element("td_message_important_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
-}
-
-function set_msg_as_unflagged(msg_number){
-	var msg = Element(msg_number);
-	remove_className(msg, 'selected_msg');
-	remove_className(msg, 'flagged_msg');
-	Element("td_message_important_"+msg_number).innerHTML = "&nbsp;&nbsp;&nbsp;";
-}
-
-
-function get_current_folder(){
-	return current_folder;
-}
-
-// Kill current box (folder or page).
-function kill_current_box(){
-	var box = document.getElementById("table_box");
-	if (box != null)
-		box.parentNode.removeChild(box);
-	else
-		return false;
-}
-
-// Kill current paging.
-function kill_current_paging(){
-	var paging = Element("span_paging");
-	if (paging != null)
-		paging.parentNode.removeChild(paging);
-}
-
-function show_hide_span_paging(ID){
-	if ((ID != "0") && Element("span_paging")) 
-		Element("span_paging").style.display = 'none';
-	else
-		if (Element("span_paging"))
-			Element("span_paging").style.display = '';
-}
-
-function download_local_attachment(url) {
-	if (div_attachment == null){
-		var div_attachment = document.createElement("DIV");
-		div_attachment.id="id_div_attachment";
-		document.body.appendChild(div_attachment);
-	}
-	div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='"+url+"'></iframe>";
-}
-
-function download_attachments(msg_folder, msg_number, idx_file, msg_part, encoding, new_file_name, show_iframe){
-	div_attachment = document.getElementById("id_div_attachment");
-	var params = '';
-	
-	if (div_attachment == null){
-		var div_attachment = document.createElement("DIV");
-		div_attachment.id="id_div_attachment";
-		document.body.appendChild(div_attachment);
-	}
-	if(new_file_name)
-		params = "&newfilename="+escape(new_file_name);
-	if(encoding)
-		params += "&encoding="+encoding;
-
-	div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='expressoMail1_2/inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params+"'></iframe>";
-}
-
-function download_all_attachments(msg_folder, msg_number){
-	var handler_source = function(data){		
-		download_attachments(null, null, data, null,null,'anexos.zip');
-	};
-	cExecute("expressoMail1_2.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
-}
-//ADD forwarded files
-function addForwardedFile(id_border,file_name,link){
-	divFiles = document.getElementById("divFiles_"+id_border);
-
-	if (! divFiles)
-		return false;
-	
-	if (divFiles.lastChild)
-		var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
-
-	if (! countDivFiles)
-		var countDivFiles = 1;
-	
-	divFile = document.createElement('DIV');
-	
-
-	if (!expresso_offline) {
-		if (!is_ie) {
-			var inputFile = document.createElement("INPUT");
-			
-			var tmp_id_border = document.createAttribute('id_border');
-			tmp_id_border.value = id_border;
-			
-			inputFile.setAttributeNode(tmp_id_border);
-			inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
-			inputFile.type = 'file';
-			inputFile.size = 50;
-			inputFile.maxLength = 255;
-			inputFile.name = 'file_' + countDivFiles;
-			inputFile.style.display = "none";
-		}
-		else {
-			var inputFile = document.createElement("link");
-			
-			var tmp_id_border = document.createAttribute('id_border');
-			tmp_id_border.value = id_border;
-			
-			inputFile.setAttributeNode(tmp_id_border);
-			inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
-			inputFile.name = 'file_' + countDivFiles;
-			
-			
-		}
-		
-	}
-	else {
-		var inputFile = document.createElement("input");
-		inputFile.type = 'hidden';
-		inputFile.name = 'offline_forward_' + countDivFiles;
-	}	
-	divFile.appendChild(inputFile);
-
-	var a_tmp = new Array();
-	a_tmp[0] = "local_";
-	a_tmp[1] = 'file_' + countDivFiles;
-	a_tmp[2] = file_name;
-	s_tmp = escape(expresso.connector.serialize(a_tmp));
-	var checkbox = document.createElement("INPUT");
-	checkbox.type = "checkbox";
-	checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
-	checkbox.name = "local_attachments[]";
-	
-	checkbox.value = s_tmp;
-	divFile.appendChild(checkbox);
-	
-	var link_attachment = document.createElement("A");
-	link_attachment.setAttribute("href", link);
-	
-	link_attachment.innerHTML = file_name;
-	divFile.appendChild(link_attachment);
-	
-	countDivFiles++;
-	divFile.id = "divFile_"+id_border+"_"+countDivFiles;	
-	divFiles.appendChild(divFile);
-
-	checkbox.checked = true; //IncrÃ­vel, mas no Internet Explorer o checked sÃ³ funciona efetivamente se o elemente jÃ¡ estiver renderizado... por isso sÃ³ aqui eu seleciono ele...
-	return inputFile;
-}
-
-// Add Input File Dynamically.
-function addFile(id_border){
-	divFiles = document.getElementById("divFiles_"+id_border);
-	if (! divFiles)
-		return false;
-	
-	if (divFiles.lastChild)
-		var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
-
-	if (! countDivFiles)
-		var countDivFiles = 1;
-	
-	divFile = document.createElement('DIV');
-	
-	
-	divFile.innerHTML = "<input type='file' id_border='"+id_border+"' size='50' maxLength='255' onchange=\"function () {validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));};\" id='"+"inputFile_"+id_border+"_"+countDivFiles+"' name='file_"+countDivFiles+"'>";
-
-	
-	var linkFile = document.createElement("A");
-	linkFile.id = "linkFile_"+id_border+"_"+countDivFiles;
-	linkFile.href='javascript:void(0)';
-	linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
-	linkFile.innerHTML=get_lang("Remove");	
-	//divFile.innerHTML += "&nbsp;&nbsp;";
-	divFile.appendChild(linkFile);
-	divFile.id = "divFile_"+id_border+"_"+countDivFiles;	
-	divFiles.appendChild(divFile);
-
-	
-
-	return document.getElementById("inputFile_"+id_border+"_"+countDivFiles);
-}
-
-var setTimeout_write_msg = 0;
-var old_msg = false;
-// Funcao usada para escrever mensagem
-// notimeout = True : mensagem nao apaga
-function write_msg(msg, notimeout){	
-	
-	if (setTimeout_write_msg)
-		clearTimeout(setTimeout_write_msg);
-	
-	var msg_div = Element('em_div_write_msg');
-	var old_divStatusBar = Element("divStatusBar");
-
-	if(!msg_div) {
-		msg_div = document.createElement('DIV');
-		msg_div.id = 'em_div_write_msg';
-		msg_div.className = 'em_div_write_msg';
-		old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
-	}
-	
-	if( document.getElementById('JabberMessenger'))
-		loadscript.adIcon();
-
-	msg_div.innerHTML = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><th width="40%"></th><th noWrap class="action_info_th">'+msg+'</th><th width="40%"></th></tr></tbody></table>';
-
-	old_divStatusBar.style.display = 'none';
-	msg_div.style.display = '';	
-	// Nao ponha var na frente!! jakjr
-	handle_write_msg = function(){
-		try{
-			if(!old_msg)
-				clean_msg();
-			else
-				write_msg(old_msg, true);			
-		}
-		catch(e){}
-	};
-	if(notimeout)
-		old_msg = msg;
-	else
-		setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
-}
-// Funcao usada para apagar mensagem sem timeout
-function clean_msg(){
-	old_msg = false;
-	var msg_div = Element('em_div_write_msg');
-	var old_divStatusBar = Element("divStatusBar");
-	if(msg_div)
-		msg_div.style.display = 'none';
-	old_divStatusBar.style.display = '';	
-}
-
-function make_body_reply(body, to, date_day, date_hour){
-	to = to.replace("<","&lt;");
-	to = to.replace(">","&gt;");
-	block_quoted_body ="<br><br>";
-	block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
-	block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
-	block_quoted_body += body;
-	block_quoted_body += "</blockquote>";
-	return block_quoted_body;
-}
-
-function make_forward_body(body, from, date, subject, to, cc){
-	from = from.replace(/</g,"&lt;");
-	from = from.replace(/>/g,"&gt;");
-	to = to.replace(/</g,"&lt;");
-	to = to.replace(/>/g,"&gt;");
-	var forward_body = '<BR><BR>---------- ' + get_lang('Forwarded message') + ' ----------<BR>';
-	forward_body += get_lang('From') + ': ' + from + '<BR>';
-	forward_body += get_lang('Date') + ': ' + date + '<BR>';
-	forward_body += get_lang('Subject') + ': ' + subject + '<BR>';
-	forward_body += get_lang('To') + ': ' + to+ '<BR>';
-	if(cc != undefined){
-		cc = cc.replace(/</g,"&lt;");
-		cc = cc.replace(/>/g,"&gt;");
-		forward_body += get_lang('CC') + ': ' + cc+ '<BR><BR>';
-	}
-	forward_body += body;
-	return forward_body;
-}
-
-function emMessageSearch(e,value){
-	var	e  = is_ie ? window.event : e;
-	if(e.keyCode == 13) {
-		search_emails(value);
-	}
-}
-
-function emQuickSearch(emailList, field, ID){
-	var quickSearchKeyBegin;
-	var quickSearchKeyEnd;
-	if(expresso_offline) {
-		alert(get_lang('Not allowed in offline mode'));
-		return;
-	}
-		
-	var handler_emQuickSearch = function(data)
-	{
-		window_DropDownContacts = Element('tipDiv');
-		if (window_DropDownContacts.style.visibility != 'hidden'){
-			window_DropDownContacts.style.visibility = 'hidden';
-		}
-		
-		if ((!data.status) && (data.error == "many results")){
-			alert(get_lang('More than %1 results. Please, try to refine your search.',200));
-			return false;
-		}
-			
-		if (data.length > 0){
-			if ((field != 'null') && (ID != 'null'))
-			{
-				expresso.connector.loadScript("jscode/QuickCatalogSearch");
-				QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
-			}
-			else
-			{
-				expresso.connector.loadScript("jscode/QuickSearchUser");
-				QuickSearchUser.showList(data);
-			}
-		}
-		else
-			alert(get_lang('None result was found.'));
-		return true;
-	};
-	
-	if ((field != 'null') && (ID != 'null'))
-	{
-		Element(field +'_'+ ID).focus(); //It requires for IE.
-		var i = getPosition(Element(field +'_'+ ID)); //inputBox.selectionStart;
-		var j = --i;
-
-		// Acha o inicio
-    	while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
-	    quickSearchKeyBegin = ++j;
-
-	    // Acha o final
-    	while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
-	    quickSearchKeyEnd = i;
-
-	    // A Chave da Pesquisa
-    	var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
-	}
-	else
-		var search_for = emailList;
-	
-	if (search_for.length < preferences.search_characters_number){
-            alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
-            return false;
-	}
-	
-	cExecute ("expressoMail1_2.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
-}
-
-function folderbox(){
-	expresso.connector.loadScript("jscode/TreeS");
-	ttree.make_Window();
-}
-
-function filterbox(){
-	expresso.connector.loadScript("jscode/filter");
-	expresso.connector.loadScript("jscode/filters");
-	filters.Forms();
-}
-
-function sharebox(){
-	var handler_imap_getacl = function(data)
-	{
-		var options = '';
-		for (var x in data)
-		{
-			options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
-		}
-		expresso.connector.loadScript("jscode/sharemailbox");
-		sharemailbox.makeWindow(options);
-	};
-	cExecute ("expressoMail1_2.imap_functions.getacl", handler_imap_getacl);
-}
-
-function preferences_mail(){
-	location.href="../preferences/preferences.php?appname=expressoMail1_2";
-}
-
-function search_emails(value){
-	expresso.connector.loadScript("jscode/search");
-	EsearchE.showForms(value);
-}
-
-function source_msg(id_msg,folder){
-	var num_msg = id_msg.substr(0,(id_msg.length - 2));
-	var handler_source = function(data){
-		download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
-	};
-	cExecute("expressoMail1_2.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
-}
-
-function Element (el) {
-	return	document.getElementById(el);
-}
-
-function getPosition(obj)
-{
-	if(typeof obj.selectionStart != "undefined")
-	{
-    	return obj.selectionStart;
-	}
-	else if(document.selection && document.selection.createRange)
-	{
-		var M = document.selection.createRange();
-		try
-		{
-			var Lp = M.duplicate();
-			Lp.moveToElementText(obj);
-		}
-		catch(e)
-		{
-			var Lp=obj.createTextRange();
-		}
-		
-		Lp.setEndPoint("EndToStart",M);
-		var rb=Lp.text.length;
-		
-		if(rb > obj.value.length)
-		{
-			return -1;
-		}
-		return rb;
-	}
-};
-
-function increment_folder_unseen(num){
-	if (num < 0)
-		return decrement_folder_unseen(num*-1);
-	else if(num == 0)
-		return;
-	var folder_id = get_current_folder();
-
-	var folder_unseen = Element('dftree_'+folder_id+'_unseen');
-	var abas_unseen = Element('new_m').innerHTML;
-        abas_unseen = abas_unseen.match(/[0-9]+/);
-
-	if (folder_unseen)
-	{
-		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + num);
-	}
-	else
-	{
-		tree_folders.getNodeById(folder_id).alter({caption: tree_folders.getNodeById(current_folder).caption + '<font style=color:red>&nbsp(</font><span id="dftree_'+current_folder+'_unseen" style=color:red>'+num+'</span><font style=color:red>)</font>'});
-		tree_folders.getNodeById(folder_id)._refresh();
-	}
-	if (abas_unseen)
-	{
-		abas_unseen = parseInt(abas_unseen) + num;
-		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
-	}
-	else{
-		abas_unseen = Element('new_m').innerHTML;
-		abas_unseen = abas_unseen.match( /[0-9]+/);
-		abas_unseen = parseInt(abas_unseen) + num;
-		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
-	}
-	if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
-	{
-		var _disp_unseenshfolder = Element('dftree_user_unseen');
-		if ( _disp_unseenshfolder )
-			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( _disp_unseenshfolder.innerHTML) + num ) + '</span><font style=color:red>]</font>' + get_lang("Shared folders")});
-		else
-			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">1</span><font style=color:red>]</font>' + get_lang("Shared folders")});
-		tree_folders.getNodeById( 'user' )._refresh();
-	}
-	var _disp_unseen_mb = Element('dftree_root_unseen');
-	if(!expresso_offline)
-		var node_to_refresh = 'root';
-	else
-		var node_to_refresh = 'local_root';
-	tree_folders.getNodeById( node_to_refresh )._refresh();
-}
-function decrement_folder_unseen(num){
-	var folder_id = get_current_folder();
-
-	var folder_unseen = Element('dftree_'+folder_id+'_unseen');
-	var abas_unseen = Element('new_m').innerHTML;
-        abas_unseen = abas_unseen.match( /[0-9]+/);
-
-	if(!folder_unseen || !abas_unseen)
-		return;
-
-	if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > num))
-	{
-		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - num);
-	}
-	else if (parseInt(folder_unseen.innerHTML) <= num)
-	{
-		var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
-		var folder_name = tmp_folder_name[0];
-		tree_folders.getNodeById(folder_id).alter({caption: folder_name});
-		tree_folders.getNodeById(folder_id)._refresh();
-	}
-	if ((abas_unseen) && (parseInt(abas_unseen) > num))
-        {
-	        abas_unseen = (parseInt(abas_unseen) - num);
-	        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
-	}
-	else if (parseInt(abas_unseen) <= 1)
-	{
-		Element('new_m').innerHTML = '0';
-	}
-	if ( current_folder.indexOf( 'INBOX' ) !== 0 )
-	{
-		var _disp_unseenshfolder = Element('dftree_user_unseen');
-		if ( _disp_unseenshfolder )
-		{
-			var _useen_shfolder = parseInt( _disp_unseenshfolder.innerHTML );
-			_useen_shfolder--;
-			if ( _useen_shfolder > 0 )
-				tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + _useen_shfolder + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
-			else
-				tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
-			tree_folders.getNodeById( 'user' )._refresh();
-		}
-	}
-	var _disp_unseen_mb = Element('dftree_root_unseen');
-	if ( _disp_unseen_mb )
-	{
-		var unseen_in_mailbox = parseInt( _disp_unseen_mb.innerHTML );
-		unseen_in_mailbox--;
-		//if ( unseen_in_mailbox > 0 )
-		//	tree_folders.getNodeById( 'root' ).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
-		if(!expresso_offline)
-			var node_to_refresh = 'root';
-		else
-			var node_to_refresh = 'local_root';
-		tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
-		tree_folders.getNodeById( node_to_refresh )._refresh();
-	}
-}
-
-//changes MENU background color.
-function set_menu_bg(menu)
-{
-	menu.style.backgroundColor = 'white';
-	menu.style.border = '1px solid black';
-	menu.style.padding = '0px 0px';
-}
-//changes MENU background color.
-function unset_menu_bg(menu)
-{
-	menu.style.backgroundColor = '';
-	menu.style.border = '0px';
-	menu.style.padding = '1px 0px';
-}
-
-function array_search(needle, haystack) {
-	var n = haystack.length;
-	for (var i=0; i<n; i++) {
-		if (haystack[i]==needle) {
-			return true;
-		}
-	}
-	return false;
-}
-
-function lang_folder(fn) {
- 	if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
- 	if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
- 		return get_lang(special_folders[fn]);
- 	}
- 	return fn;
-}
-
-function select_all_messages(select)
-{
-	var main = Element("tbody_box");
-	var main_list = main.childNodes;
-	var len_main_list = main_list.length;
-	
-	if (select)
-	{
-		for (i=0; i<len_main_list; i++)
-		{
-			Element("check_box_message_"+main_list[i].id).checked = true;
-			add_className(Element(main_list[i].id), 'selected_msg');
-		}
-	}
-	else
-	{
-		for (i=0; i<len_main_list; i++)
-		{
-			Element("check_box_message_"+main_list[i].id).checked = false;
-			remove_className(Element(main_list[i].id), 'selected_msg');
-		}
-	}
-};
Index: trunk/expressoMail1_2/js/jscode/main.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/main.js	(revision 3063)
+++ 	(revision )
@@ -1,2570 +1,0 @@
-// Tempo do auto refresh (em milisegundos)
-var time_refresh = 300000;
-// tempo do auto save (em milisegundos)
-// 20000 = 20 segundos
-var autosave_time = 20000;
-
-function init(){
-	BordersArray[0] = new setBorderAttributes(0);
-	expresso_local_messages = new local_messages();
-	expresso_local_messages.create_objects();
-	proxy_mensagens = new messages_proxy();
-	wfolders = new cWFolders();
-
-	current_folder = "INBOX";
-	if (!is_ie)
-		if ( Element('tableDivAppbox') )
-			Element('tableDivAppbox').width = '100%';
-	
-	var save_contacts = function(data){
-		contacts = expresso.connector.unserialize( data );
-		if (preferences.use_local_messages == 1 && window.google && google.gears) 
-			if (expresso_local_messages.is_offline_installed()) 
-				expresso_local_messages.capt_url('controller.php?action=expressoMail1_2.db_functions.get_dropdown_contacts_to_cache');
-
-	};
-	var save_preferences = function(data)
-	{
-		preferences = data.JSON( );
-		_connector.cache();
-		_connector.go( {
-			"access" : "expressoMail1_2.imap_functions.get_range_msgs2&folder=INBOX&msg_range_begin=1&msg_range_end="
-						+ preferences.max_email_per_page + "&sort_box_type=SORTARRIVAL&search_box_type=ALL&sort_box_reverse=1",
-			"cache" : true,
-			"handler" : handler_draw_box
-		} );
-
-		if(preferences.hide_folders == "1")
-			Element('divAppboxHeader').innerHTML =  title_app_menu;
-		
-		if (preferences.delete_trash_messages_after_n_days != 0)
-			_connector.go( {
-				"access" : "expressoMail1_2.imap_functions.automatic_trash_cleanness&before_date="
-					+ preferences.delete_trash_messages_after_n_days + "&cyrus_delimiter=" + cyrus_delimiter,
-				"handler" : _hand_automtrash_clean
-			} );
-		
-		if(preferences.outoffice == "1")
-			write_msg(get_lang("Attention, you are in out of office mode."), true);
-
-		if ((preferences.use_local_messages==1) && (!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;
-			}
-		}
-		
-		ConstructMenuTools();
-
-		if (preferences.use_local_messages==1) {
-			expresso.connector.loadScript('jscode/mail_sync');
-			if (is_ie)
-				expresso.connector.loadScript('jscode/TreeShow');
-			setTimeout('auto_archiving()', 30000);
-			if (expresso_local_messages.is_offline_installed()) {
-				check_mail_in_queue();
-			}
-		}
-
-        // Insere a applet de criptografia
-        if (preferences.use_signature_digital_cripto == '1'){
-            loadApplet();
-        }
-        // Fim da inserção da applet
-
-		_connector.cache();
-		_connector.go( { //Save contacts needs preferences.
-			"access" : "expressoMail1_2.db_functions.get_dropdown_contacts",
-			"cache" : true,
-			"handler" : save_contacts
-		} );
-		_connector.cache();
-		_connector.go( {
-			"access" : "expressoMail1_2.imap_functions.get_folders_list&onload=true",
-			"cache" : true,
-			"handler" : function( data )
-			{
-				update_menu( expresso.connector.unserialize( data ) );
-			}
-		} );
-		
-	};
-	var _hand_automtrash_clean = function(data){
-		data = expresso.connector.unserialize( data );
-		if (data != false){
-			write_msg(data.length +' '+ Element('txt_clear_trash').value);
-		}
-	};
-	
-	// Versão
-	if ( Element('divAppboxHeader') )
-		Element('divAppboxHeader').innerHTML = title_app;
-	_connector.cache();
-	_connector.go( {
-		"access" : "expressoMail1_2.functions.get_preferences",
-		"handler" : save_preferences
-	} );
-	setTimeout('auto_refresh()', time_refresh);
-
-	refresh(preferences.alert_new_msg);
-}
-
-function init_offline(){
-	if (account_id != null) {
-		if (!is_ie) 
-			Element('tableDivAppbox').width = '100%';
-		else
-			expresso.connector.createXMLHTTP();
-		Element('divStatusBar').innerHTML = '<table height="16px" border=0 width=100% cellspacing=0 cellpadding=2>' +
-		'<tr>' +
-		'<td style="padding-left:17px" width=33% id="content_quota" align=left></td>' +
-		'<td width=33% height=16px align=center nowrap><font face=Verdana, Arial, Helvetica, sans-serif color=#000066 size=2>' +
-		'<b>ExpressoMail Offline</b><font size=1><b> - Versão 1.0</b></font></td>' +
-		'<td width=33% id="div_menu_c3" align=right></td>' +
-		'</tr></table>';
-			
-		ConstructMenuTools();
-
-		draw_tree_folders();
-				
-		proxy_mensagens.messages_list('local_Inbox', 1, preferences.max_email_per_page, 'SORTARRIVAL', null, 1,1,1, function handler(data){
-			draw_box.draw_newBox(data, 'local_Inbox');
-		});
-		
-		// Get cyrus delimiter
-	cyrus_delimiter = Element('cyrus_delimiter').value;
-	
-	cExecute ("expressoMail1_2.db_functions.get_dropdown_contacts_to_cache", function(data) {contacts = data;});
-	//cExecute ("expressoMail1_2.functions.get_preferences", save_preferences);
-	}
-}
-/**
- * Carrega a applet java no objeto search_div
- * @author Mário César Kolling <mario.kolling@serpro.gov.br>
- */
-
-function loadApplet(){
-
-    var search_div = Element('search_div');
-    var applet = null;
-    if (navigator.userAgent.match('MSIE')){
-        applet = document.createElement('<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" ' +
-            'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"></object>');
-
-        //applet = document.createElement('object');
-        //var attributes = {
-        //    style:'display:yes;width:0;height:0;vertical-align:bottom;',
-        //    id:'cert_applet',
-        //    classid:'clsid:8AD9C840-044E-11D1-B3E9-00805F499D93'
-        //}
-
-        var parameters = {
-            type:'application/x-java-applet;version=1.5',
-            code:'ExpressoSmimeApplet',
-            codebase:'/security/',
-            mayscript:'true',
-            token: token_param,
-            locale: locale,
-            archive:'ExpressoCertMail.jar,' +
-                'ExpressoCert.jar,' +
-                'bcmail-jdk15-142.jar,' +
-                'mail.jar,' +
-                'activation.jar,' +
-                'bcprov-jdk15-142.jar,' +
-                'commons-codec-1.3.jar,' +
-                'commons-httpclient-3.1.jar,' +
-                'commons-logging-1.1.1.jar'
-            //debug:'true'
-        };
-
-        //for (var attribute in attributes){
-        //    applet.setAttribute(attribute, attributes[attribute]);
-        //}
-
-        if (parameters != 'undefined' && parameters != null){
-            for (var parameter in parameters) {
-                var param = document.createElement("PARAM");
-                param.setAttribute("name",parameter);
-                param.setAttribute("value",parameters[parameter]);
-                applet.appendChild(param);
-            }
-        }
-        search_div.appendChild(applet);
-        //alert(search_div.innerHTML);
-        //alert(window.);
-    }
-    else {
-        applet = document.createElement('embed');
-        applet.innerHTML = '<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" code="ExpressoSmimeApplet.class" ' +
-            'codebase="/security/" locale="'+locale+'"'+
-            'archive="ExpressoCertMail.jar,ExpressoCert.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar,commons-codec-1.3.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar" ' +
-            'token="' + token_param + '" ' +
-            'type="application/x-java-applet;version=1.5" mayscript > ' +
-            //'type="application/x-java-applet;version=1.5" debug="true" mayscript > ' +
-            '<noembed> ' +
-            'No Java Support. ' +
-            '</noembed> ' +
-            '</embed> ';
-        search_div.appendChild(applet);
-    }
-}
-
-function disable_field(field,condition) {
-	var comando = "if ("+condition+") { document.getElementById('"+field.id+"').disabled=true;} else { document.getElementById('"+field.id+"').disabled=false; }";
-	eval(comando);
-}
-/*
-	função que remove todos os anexos...
-*/
-function remove_all_attachments(folder,msg_num) {
-
-	var call_back = function(data) {
-		if(!data.status) {
-			alert(data.msg);
-		}
-		else {
-			msg_to_delete = Element(msg_num);
-			change_tr_properties(msg_to_delete, data.msg_no);
-			msg_to_delete.childNodes[1].innerHTML = "";
-			write_msg(get_lang("Attachments removed"));
-			delete_border(msg_num+'_r','false'); //close email tab
-		}
-	};
-	if (confirm(get_lang("delete all attachments confirmation")))
-		cExecute ("expressoMail1_2.imap_functions.remove_attachments&folder="
-				+folder+"&msg_num="+msg_num, call_back);
-}
-function watch_changes_in_msg(border_id)
-{
-	if (document.getElementById('border_id_'+border_id))
-	{	
-		function keypress_handler ()
-		{
-			away=false;
-			var save_link = Element("save_message_options_"+border_id);
-			save_link.onclick = function onclick(event) { openTab.toPreserve[border_id] = true; save_msg(border_id); } ;
-			save_link.className = 'message_options';
-		};
-		
-		var obj = document.getElementById('body_'+border_id).contentWindow.document;
-		if ( obj.addEventListener )
-				obj.addEventListener('keypress', keypress_handler, false);
-		else if ( obj.attachEvent )
-			obj.attachEvent('onkeypress', keypress_handler);
-			
-		var subject_obj = document.getElementById('subject_'+border_id);
-		if ( subject_obj.addEventListener )
-				subject_obj.addEventListener('keypress', keypress_handler, false);
-		else if ( subject_obj.attachEvent )
-			subject_obj.attachEvent('onkeypress', keypress_handler);
-			
-		var to_obj = document.getElementById('to_'+border_id);
-		if ( to_obj.addEventListener )
-				to_obj.addEventListener('keypress', keypress_handler, false);
-		else if ( to_obj.attachEvent )
-			to_obj.attachEvent('onkeypress', keypress_handler);
-		
-	}
-}
-
-function show_msg_img(msg_number,folder){
-    var call_back = function(data){
-       data.showImg = true;
-       var table_message = Element('table_message_'+data.msg_number+'_r');
-       var tbody_message = table_message.childNodes[0];
-       if(tbody_message.childNodes.length > 1)
-	       tbody_message.removeChild(tbody_message.lastChild);
-
-       if (!Element(data.msg_number)){
-	       trElement = document.createElement('DIV');
-	       trElement.id = data.msg_number;
-	       Element("tbody_box").appendChild(trElement);
-       }
-       show_msg(data);
-    };
-    for (var i=0; i < draw_box.headers_msgs.length; i++)
-	    if (draw_box.headers_msgs[i].msg_number == msg_number){
-		    var info_msg = draw_box.headers_msgs[i];
-		    break;
-	    }
-    proxy_mensagens.get_msg(info_msg,folder,null,call_back);
-}
-
-function show_msg(msg_info){
-	if (typeof(msg_info) != 'object')
-		alert(get_lang("Error in show_msg param is not object"));
-
-	if (msg_info.status_get_msg_info == 'false')
-	{
-		write_msg(get_lang("Problems reading your message")+ ".");
-		return;
-	}
-	var _hand_sendnotif = function(data){
-		if (data)
-			write_msg(get_lang("A read confirmation was sent."));
-		else
-			write_msg(get_lang("Error in SMTP sending read confirmation."));
-	};
-
-	if(msg_info.source)
-	{
-		// Abrindo um e-mail criptografado
-		// Verifica se existe o objeto applet
-		if (!Element('cert_applet')){
-			// se não existir, mostra mensagem de erro.
-			write_msg(get_lang('The preference "%1" isn\'t enabled.', get_lang('Enable digitally sign/cipher the message?')));
-		} else {
-			// se existir prepara os dados para serem enviados e chama a
-			// operação na applet
-
-			expresso.connector.showProgressBar();
-
-			// if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
-			/*	var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), "");
-				if (confNotification)*/
-			//        cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), _hand_sendnotif);
-			// }
-
-			Element('cert_applet').doButtonClickAction('decript',
-					msg_info.msg_number,
-					msg_info.source,
-					msg_info.msg_folder); // Passa os dados para a applet
-		}
-		return;
-
-	}
-
-	if (msg_info.status == 'false'){
-		delete_border(msg_info.reuse_border);
-	}
-	else{
-		var ID = msg_info.original_ID ? msg_info.original_ID : msg_info.msg_number;
-		var id_msg_read = ID+"_r";
-
-		if (preferences.use_shortcuts == '1')
-			select_msg(ID, 'null');
-		// Call function to draw message
-		// If needed, delete old border
-		if(currentTab)
-		{
-			draw_msg.draw_message_body(msg_info,currentTab);
-			var unseen_sort = document.getElementById('span_flag_UNSEEN').getAttribute('onclick');
-			unseen_sort = unseen_sort.toString();
-			if ( !(unseen_sort.indexOf("'UNSEEN' == 'UNSEEN'") < 0) )
-			{
-				var sort_type = sort_box_type;
-				sort_box_type = null;
-				sort_box('UNSEEN', sort_type);
-			}
-		}
-		else{
-			/* No tab avaliable, the draw_message_header hasn't finished?! */
-			setTimeout('expresso.connector.cacheNextRequest(); cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number='+ ID +'&msg_folder=' + current_folder+'", show_msg)',100);
-		}
-
-		var domains = "";
-		if ((msg_info.DispositionNotificationTo) && (!msg_is_read(ID) || (msg_info.Recent == 'N')))
-		{
-			if (preferences.notification_domains != undefined && preferences.notification_domains != "")
-			{
-				domains = preferences.notification_domains.split(',');
-			}
-			else
-			{
-				var confNotification = true;
-			}
-			for (var i = 0; i < domains.length; i++)
-				if (msg_info.DispositionNotificationTo.match(domains[i]+">"))
-				{
-					var confNotification = true;
-					break;
-				}
-			if (confNotification == undefined)
-				var confNotification = confirm(get_lang("The sender:\n%1\nwaits your notification of reading. Do you want to confirm this?",msg_info.DispositionNotificationTo), "");
-			if (confNotification)
-				cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), _hand_sendnotif);
-		}
-		//Change msg class to read.
-		if (!msg_is_read(ID))
-		{
-			set_msg_as_read(ID, true);
-			if (msg_info.cacheHit || (!proxy_mensagens.is_local_folder(get_current_folder()) && msg_info.original_ID))
-			{
-				set_message_flag(ID, "seen"); // avoid caducous (lazy) data
-			}
-		}
-	}
-	resizeWindow();
-}
-
-function auto_refresh(){
-	refresh(preferences.alert_new_msg);
-	setTimeout('auto_refresh()', time_refresh);
-}
-
-function auto_archiving() {
-	expresso_mail_sync.start_sync();
-	setTimeout('auto_archiving()',600000);
-}
-
-function refresh(alert_new_msg){
-	var handler_refresh = function(data){
-		var box = Element("tbody_box");
-		if (box.childNodes.length == 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);
-			box.appendChild(tr_info);
-		}
-
-		if (data.length > 0){
-			var msg_info = document.getElementById('msg_info');
-			if (msg_info != null)
-				main.removeChild(msg_info);
-
-			table_element = Element("table_box");
-			var box = Element("tbody_box");
-			table_element.appendChild(box);
-
-			if (data[0].msg_folder != current_folder) // Bad request
-				return false;
-
-			for (var i=0; i<data.length; i++){
-				var existent = document.getElementById(data[i].msg_number);
-				if (!existent)
-				{
-					var new_msg = this.make_tr_message(data[i], current_folder);
-					_dragArea.makeDragged(new_msg, data[i].msg_number, data[i].subject, true);
-					eval(data[i].command);
-				}
-			}
-			if (! typeof(data.msgs_to_delete) == 'undefined')
-				for (var i=0; i<data.msgs_to_delete.length; i++){
-					var remove_msg = document.getElementById(data.msgs_to_delete[i]);
-					if (remove_msg)
-						remove_msg.parentNode.removeChild(remove_msg);
-				}
-
-			if(parseInt(alert_new_msg) && data.new_msgs > 0)
-				alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!");
-			if(data.new_msgs > 0){
-				Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + parseInt(data.new_msgs); //refresh tab title
-				update_quota(get_current_folder());
-			}						
-		};
-		// Update Box BgColor
-		var box = Element("tbody_box");
-		if(box.childNodes.length > 1){
-			updateBoxBgColor(box.childNodes);
-		}
-		update_menu();
-	};
-
-	msg_range_end = (current_page*preferences.max_email_per_page);
-	msg_range_begin = (msg_range_end-(preferences.max_email_per_page)+1);
-	
-	
-	//Get element tBody.
-	main = Element("tbody_box");
-	if(!main)
-		return;	
-
-	// Get all TR (messages) in tBody.
-	main_list = main.childNodes;
-	var tmp = '';
-	var string_msgs_in_main = '';
-
-	var len = main_list.length; 
-	for (var j=0; j < len; j++)
-		tmp += main_list[j].id + ',';
-		
-	string_msgs_in_main = tmp.substring(0,(tmp.length-1));
-	if(!expresso_offline)
-		cExecute ("expressoMail1_2.imap_functions.refresh&folder="+current_folder+"&msgs_existent="+string_msgs_in_main+"&msg_range_begin="+msg_range_begin+"&msg_range_end="+msg_range_end+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse, handler_refresh);
-}
-
-function delete_msgs(folder, msgs_number, border_ID, show_success_msg,archive)
-{
-	if (arguments.length < 4){
-		show_success_msg = true;
-	}
-
-	if (folder == 'null')
-		folder = current_folder;
-
-	if(openTab.type[currentTab] == 1)
-		return move_search_msgs('content_id_'+currentTab,'INBOX'+cyrus_delimiter+trashfolder,trashfolder);
-
-	if(currentTab.toString().indexOf("_r") != -1){
-			msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
-	}
-
-	if (!archive && (parseInt(preferences.save_deleted_msg)) && (folder!='INBOX'+cyrus_delimiter+trashfolder)){
-		move_msgs2(folder, msgs_number, border_ID, 'INBOX'+cyrus_delimiter+trashfolder,trashfolder,show_success_msg );
-		return;
-	}
-	
-	var handler_delete_msgs = function(data){
-		
-		Element('chkbox_sel_allmsg').checked = false;
-		if (currentTab)
-			mail_msg = Element("tbody_box_"+currentTab);
-		else
-			mail_msg = Element("tbody_box");
-	
-		if ( preferences.use_shortcuts == '1') {
-				//Last msg is selected
-				if (mail_msg && exist_className(mail_msg.childNodes[mail_msg.childNodes.length-1], 'selected_shortcut_msg') ) {
-					select_msg('null', 'up', true);
-				}
-				else {
-					if (!select_msg('null', 'down', true)) {
-						select_msg('null', 'up', true);
-					}
-				}
-			}
-		
-		if (show_success_msg) {
-			if (data.msgs_number.length == 1)
-				write_msg(get_lang("The message was deleted."));
-			else
-				write_msg(get_lang("The messages were deleted."));
-		}
-		if (openTab.type[currentTab] > 1){
-			var msg_to_delete = Element(msgs_number);
-			if (parseInt(preferences.delete_and_show_previous_message) && msg_to_delete) {
-				if (msg_to_delete.previousSibling){
- 	         		   	var previous_msg = msg_to_delete.previousSibling.id;
-					expresso.connector.cacheNextRequest();
- 	         		   	cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(current_folder), show_msg);
- 		 	           } 	            
-				else
-					delete_border(currentTab,'false');
-			}
-			else
-				delete_border(currentTab,'false');
-		}
-        for (var i=0; i<data.msgs_number.length; i++){
-                var msg_to_delete = Element(data.msgs_number[i]);
-                if (msg_to_delete){
-                        removeAll(msg_to_delete.id);
-                }
-        }
-	Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
-	refresh();	
-	};
-
-	if (msgs_number == 'selected')
-		msgs_number = get_selected_messages();
-	if (msgs_number.length > 0 || parseInt(msgs_number) > 0)
-	{
-		cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse, handler_delete_msgs);
-	}
-	else
-		write_msg(get_lang('No selected message.'));		
-}
-
-
-function move_search_msgs(border_id, new_folder, new_folder_name){
-	var selected_messages = '';
-	var temp_msg;
-	var main_list = Element("tbody_box_"+currentTab.substr(7)).childNodes;
-	for (j = 0; j < main_list.length; j++)	{
-		var check_box = main_list[j].firstChild.firstChild; 
-		if(check_box && check_box.checked) {
-			if (proxy_mensagens.is_local_folder(main_list[j].getAttribute('name'))) {
-				alert(get_lang("You cant manipulate local messages on search"));
-				return;
-			}
-			selected_messages += main_list[j].id + ',';
-		}
-	}
-	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
-	var _hand_mvsearchmsg = function(data){
-		if(!data || !data.msgs_number)
-			return;
-		else if(data.deleted) {			
-			if (data.msgs_number.length == 1)
-				write_msg(get_lang("The message was deleted."));
-			else
-				write_msg(get_lang("The messages were deleted."));			
-		}
-		else{
-			if (data.msgs_number.length == 1)
-				write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
-			else
-				write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-		}
-
-		selected_messages = selected_messages.split(",");
-		for (i = 0; i < selected_messages.length; i++){
-			removeAll(selected_messages[i]);
-		}
-		// Update Box BgColor
-		var box = Element("tbody_box_"+currentTab.substr(7)).childNodes;
-		if(main_list.length > 1){
-			updateBoxBgColor(box);
-		}
-	};
-
-	if (selected_messages){
-		var selected_param = "";
-		if (selected_messages.indexOf(',') != -1)
-		{
-			selected_msg_array = selected_messages.split(",");
-			for (i = 0; i < selected_msg_array.length; i++){
-				var tr = Element(selected_msg_array[i]);
-				if (tr.getAttribute('name') == new_folder)
-				{
-					write_msg(get_lang('At least one message have the same origin'));
-					return false;
-				}
-				trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
-			        selected_param += ','+trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
-			}
-		}
-		else
-		{
-			var tr=Element(selected_messages);
-			if (tr.getAttribute('name') == new_folder)
-			{
-				write_msg(get_lang('The origin folder and the destination folder are the same.'));
-				return false;
-			}
-			trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
-			selected_param=trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
-		}
-		var params = "";
-		if (!new_folder && parseInt(preferences.save_deleted_msg)){ 
-			new_folder = 'INBOX'+cyrus_delimiter+trashfolder;
-			new_folder_name = trashfolder;
-			params = "&delete=true";
-		}
-
-		params += "&selected_messages="+url_encode(selected_param);
-		if(new_folder) {
-			params += "&new_folder="+url_encode(new_folder);
-			params += "&new_folder_name="+url_encode(new_folder_name);
-		}
-		cExecute ("expressoMail1_2.imap_functions.move_search_messages", _hand_mvsearchmsg, params);
-	}
-	else
-		write_msg(get_lang('No selected message.'));		
-}
-
-function move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,show_success_msg){
-
-	if (! folder || folder == 'null')
-		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : (openTab.imapBox[currentTab] ? openTab.imapBox[currentTab]:get_current_folder());
-
-	if(openTab.type[currentTab] == 1)
-		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
-
-	var handler_move_msgs = function(data){
-		if(typeof(data) == 'string')
-			if (data.match(/^(.*)TRYCREATE(.*)$/)){
-				expresso.connector.loadScript('jscode/TreeS');
-				var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : trashfolder;
-				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.', move_to_folder));
-				expresso.connector.loadScript('jscode/TreeShow');
-				ttree.FOLDER = 'root';
-				ttreeBox.new_past(move_to_folder);
-				return false;
-			}else{
-				alert(get_lang('Error moving message.')+":\n"+data);
-				return false;
-			}
-		//Este bloco verifica as permissoes ACL sobre pastas compartilhadas
-		if(data.status == false){
-			alert(get_lang("You don't have permission for this operation in this shared folder!"));
-			return false;
-		}
-		mail_msg = ( Element("divScrollMain_"+numBox) ) ? Element("divScrollMain_"+numBox).firstChild.firstChild : Element("divScrollMain_0").firstChild.firstChild;
-		if (data.msgs_number.length == 1)
-			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
-		else
-			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-
-		if (openTab.type[currentTab] > 1){
-			msg_to_delete = Element(msgs_number);
-			if (parseInt(preferences.delete_and_show_previous_message) && msg_to_delete)
-			{
-				if (msg_to_delete.previousSibling){
-					var previous_msg = msg_to_delete.previousSibling.id;
-					//cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + current_folder, show_msg);
-					expresso.connector.cacheNextRequest();
-					cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(folder), show_msg);
-				}
-				else
-					delete_border(currentTab,'false');
-			}
-			else
-				delete_border(currentTab,'false');
-			if(msg_to_delete)
-				mail_msg.removeChild(msg_to_delete);
-
-			// Update Box BgColor
-			var box = Element("tbody_box");
-			if(box.childNodes.length > 0){
-				updateBoxBgColor(box.childNodes);
-			}
-			return;
-		}
-
-		Element('chkbox_sel_allmsg').checked = false;
-		if (! mail_msg)
-				mail_msg = Element("tbody_box");
-		data.msgs_number = data.msgs_number.split(",");
-
-		var msg_to_delete;
-		if( typeof(msgs_number) == 'string' )
-			all_search_msg = msgs_number.split(',');
-		else if( typeof(msgs_number) == 'number')
-			all_search_msg = msgs_number;
-		
-		for (var i=0; i <= all_search_msg.length; i++)
-		{
-			msg_to_delete = Element(folder+';'+all_search_msg[i]); 
-			if (msg_to_delete)
-				msg_to_delete.parentNode.removeChild(msg_to_delete);
-		}
-
-		if ( preferences.use_shortcuts == '1') {
-			var all_messages = Element('tbody_box').childNodes;
-
-			//Last msg is selected
-			if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') ) {
-				select_msg('null', 'up', true);
-			}
-			else {
-				if (!select_msg('null', 'down', true)) {
-					select_msg('null', 'up', true);
-				}
-			}
-		}
-		for (var i=0; i<data.msgs_number.length; i++)
-		{
-			msg_to_delete = Element(data.msgs_number[i]);
-			if (msg_to_delete)
-				mail_msg.removeChild(msg_to_delete);
-		}	
-		
-		
-		if (data.msgs_number.length == 1)
-			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
-		else
-			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
-		if (data.border_ID.indexOf('r') != -1){
-			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder()){
-				delete_border(data.border_ID,'false');
-				show_msg(data.previous_msg);
-				}
-			else
-				delete_border(data.border_ID,'false');
-		}
-		if(folder == get_current_folder())
-			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;			
-		
-		refresh();
-	};
-
-	if (folder == new_folder){
-		write_msg(get_lang('The origin folder and the destination folder are the same.'));
-		return;
-	}
-
-	if (msgs_number == 'selected'){
-		msgs_number = get_selected_messages();
-		}
-
-	if(openTab.type[currentTab] == 1){
-		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
-		}
-
-	if(currentTab.toString().indexOf("_r") != -1){
-		msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
-	}
-
-	if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
-	{
-		cExecute ("expressoMail1_2.imap_functions.move_messages&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message, handler_move_msgs);
-	}
-	else
-		write_msg(get_lang('No selected message.'));		
-		
-}
-
-function move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name) {
-	move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,true);
-}
-
-function archive_msgs(folder,folder_dest,id_msgs) {
-	if(proxy_mensagens.is_local_folder(folder)) {
-		write_msg(get_lang("You cant archive local mails"));
-		return;
-	}
-
-	if(!id_msgs)
-		id_msgs = get_selected_messages();
-	
-	if(folder_dest=='local_root' || folder_dest==null) //Caso seja o primeiro arquivamento...
-		folder_dest = 'local_Inbox';
-	
-	if (parseInt(id_msgs) > 0 || id_msgs.length > 0)
-		expresso_mail_sync.archive_msgs(folder,folder_dest,id_msgs); 
-		//cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , _hand_arqmsg);
-	else 
-		write_msg(get_lang('No selected message.'));
-	/*var has_local_messages_before = expresso_local_messages.has_local_mails(); //vejo se já tinha mensagens locais
-	var _hand_arqmsg = function(data) {
-		var sucess = true;
-		var temp;
-		var msgs_to_remove = new Array();
-		var update_tree;
-		for (var i = 0; i < data.length; i++) {
-			msg_info = expresso.connector.unserialize(data[i]);
-                        if ( folder == 'INBOX/Lixeira/tmpMoveToLocal' ){
-				msg_info.msg_folder += (Date.parse(new Date));
-			}
-			temp = expresso_local_messages.insert_mail(msg_info, msg_info['header'],msg_info['array_attach'],folder_dest );
-			if ( Element("check_box_message_" + msg_info.msg_number) )
-				Element("check_box_message_" + msg_info.msg_number).checked = false;
-
-			if(!temp)
-				sucess = false;
-			else
-				msgs_to_remove.push(msg_info.msg_number);//As mensagens arquivadas devem ser removidas, caso o usuario tenha isso configurado.
-
-			if ( Element(msg_info.msg_number) )
-				remove_className(Element(msg_info.msg_number), 'selected_msg');
-                       if ( tree_folders._selected.id.indexOf( 'local_' ) == 0 || folder.indexOf( 'INBOX/Lixeira/tmpMoveToLocal' ) == 0 )
-			{
-				openTab.imapBox[0] = '';
-				tree_folders.getNodeById( 'local_Inbox' )._select( );
-				change_folder('local_Inbox','Inbox')
-			}
-
-		}
-		
-		if (preferences.keep_archived_messages == 0) { //Remove as mensagens
-				delete_msgs(folder,msgs_to_remove,'null',false,true);
-		}
-		update_tree=(!has_local_messages_before) && expresso_local_messages.has_local_mails();
-		
-		Element('chkbox_sel_allmsg').checked = false;
-		if(update_tree)
-			ttreeBox.update_folder();
-		else
-			update_menu();
-		if(sucess) 
-			write_msg(get_lang("selected messages have been archived"));
-		else
-			write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later"));
-
-	}	
-	if(!id_msgs)
-		id_msgs = get_selected_messages();
-	if (parseInt(id_msgs) > 0 || id_msgs.length > 0) 
-		cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , _hand_arqmsg);
-	else 
-		write_msg(get_lang('No selected message.'));*/
-	
-}
-
-function get_selected_messages(){
-	try { main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
-	}catch(e){
-	};
-	if (! main)
-		main = Element("tbody_box");
-
-	// Get all TR (messages) in tBody.
-	main_list = main.childNodes;
-
-	var selected_messages = '';
-	var _sel_msgbyshrtcut = '';
-	var j = 0;
-	for (j; j<(main_list.length); j++)
-	{
-	check_box = Element("check_box_message_"+main_list[j].id);
-	if ( (check_box) && (check_box.checked) )
-		selected_messages += main_list[j].id + ',';
-		
-		if (preferences.use_shortcuts == '1')
-		{
-			if ( exist_className(Element(main_list[j].id), 'selected_shortcut_msg') )
-			{
-				_sel_msgbyshrtcut += main_list[j].id + ',';
-			}
-		}
-	}
-	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
-	
-	if (preferences.use_shortcuts == '1')
-	{
-		_sel_msgbyshrtcut = _sel_msgbyshrtcut.substring(0,(_sel_msgbyshrtcut.length-1));
-		
-		var _arr_sel_msgbyshrtcut = _sel_msgbyshrtcut.split(",");
-		var _arr_selected_messages = selected_messages.split(",");
-		
-		if ((_arr_selected_messages.length <= 1) && (_arr_sel_msgbyshrtcut.length > 1))
-		{
-			return _sel_msgbyshrtcut;
-		}
-	}
-	
-	if (selected_messages == '')
-		return false;
-	else
-		return selected_messages;
-}
-
-function new_message_to(email) {
-	var new_border_ID = new_message('new','null');
-	document.getElementById("to_" + new_border_ID).value=email;
-}
-
-function new_message(type, border_ID){
-	if ( RichTextEditor == null )
-		RichTextEditor = new cRichTextEditor( );
-
-        if (Element('show_img_link_'+border_ID))
-        {
-            show_msg_img(border_ID.match(/^\d*/)[0], Element('input_folder_'+border_ID).value);
-        }
-	var new_border_ID = draw_new_message(parseInt(border_ID));
-	if (new_border_ID == false)
-		return false;	
-        openTab.type[new_border_ID] = tabTypes[type];
-
-	// Salva a pasta da mensagem respondida ou encaminhada:
-	var folder_message = Element("input_folder_"+border_ID);
-	if(folder_message) {
-		var input_current_folder = document.createElement('input');	
-		input_current_folder.id = "new_input_folder_"+border_ID;
-		input_current_folder.name = "input_folder";
-		input_current_folder.type = "hidden";
-		input_current_folder.value = folder_message.value;
-		Element("content_id_" + new_border_ID).appendChild(input_current_folder);
-	}//Fim.
-	var title = '';
-	data = [];
-	if (Element("from_" + border_ID)){
-			if (document.getElementById("reply_to_" + border_ID)){
-				data.to = document.getElementById("reply_to_values_" + border_ID).value;
-				data.to = data.to.replace(/&lt;/gi,"<");
-				data.to = data.to.replace(/&gt;/gi,">");
-		}
-		else {
-			if (document.getElementById("from_values_" + border_ID))
-			{
-				data.to = document.getElementById("from_values_" + border_ID).value;
-				data.to = data.to.replace(/&lt;/gi,"<");
-				data.to = data.to.replace(/&gt;/gi,">");
-			}
-		}	
-		
-		if (document.getElementById("to_values_" + border_ID)){
-			data.to_all = document.getElementById("to_values_" + border_ID).value;
-			data.to_all = data.to_all.replace(/\n/gi," ");		
-			data.to_all = data.to_all.replace(/&lt;/gi,"<");
-			data.to_all = data.to_all.replace(/&gt;/gi,">");
-			var _array_to_all = data.to_all.split(",");
-		}	
-	}
-	
-	if (document.getElementById("cc_" + border_ID)){
-		data.cc = document.getElementById("cc_values_" + border_ID).value;
-		data.cc = data.cc.replace(/&lt;/gi,"<");
-		data.cc = data.cc.replace(/&gt;/gi,">");
-	}
-	if (document.getElementById("cco_" + border_ID)){
-		data.cco = document.getElementById("cco_values_" + border_ID).value;
-		data.cco = data.cco.replace(/&lt;/gi,"<");
-		data.cco = data.cco.replace(/&gt;/gi,">");
-	}
-	if (document.getElementById("subject_" + border_ID))
-		data.subject = document.getElementById("subject_" + border_ID).innerHTML;
-	if (document.getElementById("body_" + border_ID))
-		data.body = document.getElementById("body_" + border_ID).innerHTML;
-	
-	if (Element('date_' + border_ID)){
-		data.date = Element('date_' + border_ID).innerHTML;
-	}
-	
-	if (Element('date_day_' + border_ID)){
-		data.date_day = Element('date_day_' + border_ID).value;
-	}
-	if (Element('date_hour_' + border_ID)){
-		data.date_hour = Element('date_hour_' + border_ID).value;
-	}
-	if(typeof(preferences.signature) == 'undefined')
-		preferences.signature = "";
-	var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
-	switch(type){
-		case "reply_without_history":			
-			Element("to_" + new_border_ID).value = data.to;
-			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;			
-			useOriginalAttachments(new_border_ID,border_ID);
-			var body = Element("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1"){ 
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
-			}
-			else{ 
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			//Focus
-			if (is_ie)
-				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
-			else
-				body.contentWindow.focus();
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			msg_reply_from = document.createElement('input');
-			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
-			msg_reply_from.type = "hidden";
-			msg_reply_from.value = Element("msg_number_" + border_ID).value;
-			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
-			break;
-		case "reply_with_history":
-			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
-			Element("to_" + new_border_ID).value = data.to;
-			useOriginalAttachments(new_border_ID,border_ID);
-			block_quoted_body = make_body_reply(data.body, data.to, data.date_day, data.date_hour);
-			var body = Element("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1") {
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + block_quoted_body + "</body></html>");
-			}
-			else {
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+block_quoted_body+"</body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			//Focus
-			if (is_ie)
-				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
-			else
-				body.contentWindow.focus();
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			msg_reply_from = document.createElement('input');
-			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
-			msg_reply_from.type = "hidden";
-			msg_reply_from.value = Element("msg_number_" + border_ID).value;
-			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
-			break;
-		case "reply_to_all_without_history":
-			// delete user email from to_all array.
-			data.to_all = new Array();
-			var j = 0;
-			for(i = 0; i < _array_to_all.length; i++) {			
-				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
-					data.to_all[j++] = _array_to_all[i];
-				}
-			}
-			data.to_all = data.to_all.join(",");
-
-			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
-			Element("to_" + new_border_ID).value = data.to;
-			Element("to_" + new_border_ID).value += ', ' + data.to_all;
-			if (data.cc){
-				Element("cc_" + new_border_ID).value = data.cc;
-				Element("a_cc_link_" + new_border_ID).style.display='none';
-				Element("tr_cc_" + new_border_ID).style.display='';
-				Element('space_link_' + new_border_ID).style.display='none';
-			}
-			useOriginalAttachments(new_border_ID,border_ID);
-			var body = Element("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1") {
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
-			}
-			else {
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			//Focus
-			if (is_ie)
-				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
-			else
-				body.contentWindow.focus();
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			msg_reply_from = document.createElement('input');
-			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
-			msg_reply_from.type = "hidden";
-			msg_reply_from.value = Element("msg_number_" + border_ID).value;
-			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
-			break;
-		case "reply_to_all_with_history":
-			// delete user email from to_all array.
-			data.to_all = new Array();
-			var j = 0;
-				for(i = 0; i < _array_to_all.length; i++) {			
-				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
-					data.to_all[j++] = _array_to_all[i];
-				}
-			}
-			data.to_all = data.to_all.join(",");
-			title = "Re: " + data.subject;
-			Element("to_" + new_border_ID).value = data.to;
-			Element("to_" + new_border_ID).value += ', ' + data.to_all;
-			if (data.cc){
-				document.getElementById("cc_" + new_border_ID).value = data.cc;
-				document.getElementById("a_cc_link_" + new_border_ID).style.display='none';
-				document.getElementById("tr_cc_" + new_border_ID).style.display='';
-				document.getElementById('space_link_' + new_border_ID).style.display='none';
-			}
-			document.getElementById("subject_" + new_border_ID).value = "Re: " + data.subject;
-			useOriginalAttachments(new_border_ID,border_ID);
-			block_quoted_body = make_body_reply(data.body, data.to, data.date_day, data.date_hour);
-			var body = document.getElementById("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1") {
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + block_quoted_body + "</body></html>");
-			}
-			else {
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+block_quoted_body+"</body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			//Focus
-			if (is_ie)
-				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
-			else
-				body.contentWindow.focus();
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			msg_reply_from = document.createElement('input');
-			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
-			msg_reply_from.type = "hidden";
-			msg_reply_from.value = Element("msg_number_" + border_ID).value;
-			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
-			break;
-		case "forward":
-			data.is_local_message = (document.getElementById("is_local_"+border_ID).value=="1")?true:false;
-			msg_forward_from = document.createElement('input');
-			msg_forward_from.id = "msg_forward_from_" + new_border_ID;
-			msg_forward_from.type = "hidden";
-			msg_forward_from.value = Element("msg_number_" + border_ID).value;
-			Element("content_id_" + new_border_ID).appendChild(msg_forward_from);			
-			title = "Fw: " + data.subject;
-			document.getElementById("subject_" + new_border_ID).value = "Fw: " + data.subject;
-			var divFiles = Element("divFiles_"+new_border_ID);
-			var campo_arquivo;
-			if (Element("attachments_" + border_ID)){
-				var attachments = document.getElementById("attachments_" + border_ID).childNodes;
-				for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
-					if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") ||
-							((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
-						continue; 
-					var link_attachment = document.createElement("A");
-					link_attachment.setAttribute("href", attachments[i].href);
-					link_attachment.innerHTML = attachments[i].innerHTML;
-					if (data.is_local_message) {//Local messages
-						document.getElementById("is_local_forward"+new_border_ID).value = "1";
-						var tmp = link_attachment.href.substring(link_attachment.href.indexOf("(") + 2);//Pula o parenteses e a aspas
-						tmp = tmp.substring(0, tmp.length - 2);//corta a aspas e o parenteses
-						tmp = replaceAll(tmp,"%20"," ");
-						var tempNomeArquivo = tmp.split("/");
-						var nomeArquivo = tempNomeArquivo[tempNomeArquivo.length-1];
-						nomeArquivo = nomeArquivo.substring(0,nomeArquivo.length - 4); //Anexos no gears são todos com extensão .php. tenho que tirar a extensão para ficar o nome real do arquivo.
-						campo_arquivo = addForwardedFile(new_border_ID,nomeArquivo,link_attachment.href);
-						if(!expresso_offline)
-							expresso_local_messages.getInputFileFromAnexo(campo_arquivo, tmp);
-						else //To offline, you just set the url on value of a hidden input.
-							campo_arquivo.value = tmp;
-						
-					}
-					else {
-						var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
-						var a_tmp = tmp.split(',');
-						tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
-						a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
-						s_tmp = escape(expresso.connector.serialize(a_tmp));
-
-						divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
-						divFiles.innerHTML += "<link style='border:0' name='file_"+i+"' id='inputFile_"+border_ID+i+"'/>";
-						divFiles.appendChild(link_attachment);
-					}
-				}
-			}
-			var body = Element("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1") {
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + make_forward_body(data.body, data.to, data.date, data.subject, data.to_all, data.cc) + "</body></html>");
-			}
-			else {
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+make_forward_body(data.body, data.to, data.date, data.subject, data.to_all, data.cc)+"</body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			Element("to_" + new_border_ID).focus();
-			break;
-		case "new":
-			title = get_lang("New Message");
-			if(Element('msg_number').value) {
-				var _to = Element('msg_number').value;
-				var reEmail = /^[A-Za-z\d_-]+(\.[A-Za-z\d_-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;				
-				if(!reEmail.test(_to)){
-					var array_contacts = contacts.split(',');
-					for(i = 0; i < array_contacts.length;i++) {
-						if(array_contacts[i].lastIndexOf(_to) != "-1"){
-							var _group = array_contacts[i].split(";");
-							_to = '"'+_group[0]+'" <'+_group[1]+'>';
-							break;
-						}
-					}
-				}
-				Element("to_" + new_border_ID).value = _to +',';
-				Element('msg_number').value = '';
-			}
-			var body = document.getElementById("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1") {
-				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
-			}
-			else {
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
-			}
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			Element("to_" + new_border_ID).focus();
-			break;
-		case "edit":
-			openTab.imapBox[new_border_ID] = folder_message.value;
-			openTab.toPreserve[new_border_ID] = true;
-			openTab.imapUid[new_border_ID] = parseInt(border_ID.substr(0,border_ID.indexOf("_")));
-			document.getElementById('font_border_id_'+new_border_ID).innerHTML = data.subject;
-			data.to = Element("to_values_" + border_ID).value;
-			data.to = data.to.replace(/&lt;/gi,"<");
-			data.to = data.to.replace(/&gt;/gi,">");
-			title = "Edição: "+data.subject;
-			
-			Element("to_" + new_border_ID).value = data.to;
-			if (data.cc){
-				Element("cc_" + new_border_ID).value = data.cc;
-				Element("space_link_" + new_border_ID).style.display = 'none';
-				Element("a_cc_link_" + new_border_ID).style.display = 'none';
-				Element("tr_cc_"+ new_border_ID).style.display = '';
-			}
-			if (data.cco){
-				Element("cco_" + new_border_ID).value = data.cco;
-				Element("space_link_" + new_border_ID).style.display = 'none';
-				Element("a_cco_link_" + new_border_ID).style.display = 'none';
-				Element("tr_cco_"+ new_border_ID).style.display = '';
-			}
-			Element("subject_" + new_border_ID).value = data.subject;
-			
-			var divFiles = Element("divFiles_"+new_border_ID);
-			if (Element("attachments_" + border_ID)){
-				var attachments = document.getElementById("attachments_" + border_ID).childNodes;
-				for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
-					var link_attachment = document.createElement("A");
-					link_attachment.setAttribute("href", attachments[i].href);
-					link_attachment.innerHTML = attachments[i].innerHTML;
-					var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
-					var a_tmp = tmp.split(',');
-					tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
-					a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
-					s_tmp = escape(expresso.connector.serialize(a_tmp));
-					divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
-					divFiles.appendChild(link_attachment);
-				}
-			}
-			var body = Element("body_" + new_border_ID);
-			body.contentWindow.document.open();
-			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+data.body+"</body></html>");
-			body.contentWindow.document.close();
-			body.contentWindow.document.designMode = "on";
-			//Focus
-			if (is_ie)
-				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
-			else
-				body.contentWindow.focus();
-			config_events( body.contentWindow.document, 'onkeyup', function( e )
-			{
-				if ( e.keyCode == 13 )
-				{
-					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
-					for ( p = 0; p < paragraphs.length; p++ )
-						paragraphs.item( p ).style.margin = '0px';
-				}
-			});
-			break;
-		default:
-	}
-
-	// IM Module Enabled
-	if( window.parent.loadscript && loadscript.autoStatusIM )
-	{
-		config_events( body.contentWindow.document, "onkeypress", loadscript.autoStatusIM );	
-	}
-
-	if (preferences.auto_save_draft == 1)
-	{
-		openTab.autosave_timer[new_border_ID] = false;
-		var save_link = document.getElementById("save_message_options"+new_border_ID);
-
-        function auto_sav()
-			{
-				if (openTab.autosave_timer[new_border_ID])
-					clearTimeout(openTab.autosave_timer[new_border_ID]);
-
-				openTab.autosave_timer[new_border_ID] = setTimeout("save_msg("+new_border_ID+")", autosave_time);
-	}
-        config_events(body.contentWindow.document,'keypress', auto_sav);
-    }
-
-	//BEGIN Tab event
-	if (preferences.use_shortcuts == '1')
-	{
-		if (is_ie)
-		{
-			body.contentWindow.document.attachEvent('onkeydown', function(event) { if(event.keyCode==27){delete_border(new_border_ID,'false');} if(event.keyCode==9) { Element('to_'+new_border_ID).focus(); Element('send_button_'+new_border_ID).focus(); return false;} }, false);
-		}
-		else
-		{
-			body.contentWindow.document.addEventListener('keypress', function(event) { if(event.keyCode==27){delete_border(new_border_ID,'false');} if(event.keyCode==9) { Element('send_button_'+new_border_ID).focus(); event.preventDefault(); } }, false);
-		}
-	}
-	// END Tab event
-	
-	var offWidth = Element('border_blank').offsetWidth ? Element('border_blank').offsetWidth : Element('border_blank').clientWidth;
-	var resize = false;
-	
-	if (offWidth < 200) {
-		resize = Element("border_id_" + new_border_ID).style.width;
-	}
-
-	if (title.length > 21){
-		title = title.substring(0,21) + "...";
-	}
-	
-	if(resize)
-		title = title.substring(0, parseInt(resize)*0.08);
-
-	Element("border_id_" + new_border_ID).innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + new_border_ID +" class='font-menu' width=*>" +title + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + new_border_ID + "','false') src='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/close_button.gif'></td></tr></table>";
-	return new_border_ID; //Preciso retornar o ID da nova mensagem.
-}
-
-function useOriginalAttachments(new_id_border,old_id_border)
-{
-	var divFiles = Element("divFiles_"+new_id_border);
-	if (Element("attachments_" + old_id_border)) {
-		var areaOldAttachments = document.createElement("DIV");
-		areaOldAttachments.id = "area_div_attachments_"+new_id_border;
-		divFiles.appendChild(areaOldAttachments);
-		var optAttachments = document.createElement("A");
-		optAttachments.setAttribute("href","javascript:void(0)");
-		optAttachments.tabIndex = -1;
-		optAttachments.innerHTML = get_lang("Original attachments: add")+"</br>";
-		areaOldAttachments.appendChild(optAttachments);
-		var divOriginalAttachments = document.createElement("DIV");
-		divOriginalAttachments.id = "div_attachments_"+new_id_border;
-		optAttachments.onclick = function(){
-			if(document.getElementById('div_attachments_'+new_id_border))
-			{
-				areaOldAttachments.removeChild(document.getElementById('div_attachments_'+new_id_border));
-				optAttachments.innerHTML = get_lang("Original attachments: add")+"</br>";
-			}
-			else
-			{
-				areaOldAttachments.appendChild(divOriginalAttachments);
-				optAttachments.innerHTML = get_lang("Original attachments: remove")+"</br>";
-			}
-				return false;
-			};
-			var attachments = document.getElementById("attachments_" + old_id_border).childNodes;
-			for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
-				var link_attachment = document.createElement("A");
-				link_attachment.setAttribute("href", attachments[i].href);
-				link_attachment.innerHTML = attachments[i].innerHTML;
-				var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
-				var a_tmp = tmp.split(',');
-				tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
-				a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
-				s_tmp = escape(expresso.connector.serialize(a_tmp));
-				divOriginalAttachments.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
-				divOriginalAttachments.appendChild(link_attachment);
-			}
-	};
-}
-
-function send_message_return(data, ID){
-    watch_changes_in_msg(ID);
-
-    var sign = false;
-	var crypt = false;
-    if ((preferences.use_assinar_criptografar != '0') && (preferences.use_signature_digital_cripto != '0')){
-		var checkSign = document.getElementById('return_digital_'+ID);
-		if (checkSign.checked){
-			sign = true;
-		}
-
-		var checkCript = document.getElementById('return_cripto_'+ID);
-		if (checkCript.checked){
-			crypt = true;
-		}
-	}
-
-    if (typeof(data) == 'object' && !data.success)
-	{
-        connector = expresso.connector;
-        expresso.connector.showProgressBar();
-
-        if (sign || crypt){
-            var operation = '';
-			if (sign){
-				operation = 'sign';
-			}
-			else { // crypt
-                //TODO: Colocar mensagem de erro, e finalizar o método.
-				operation = 'nop';
-			}
-        }
-
-        if (data.body){
-            Element('cert_applet').doButtonClickAction(operation, ID, data.body);
-        }
-        else {
-			alert(data.error);
-		}
-
-		return;
-    }
-	if(data && data.success == true ){
-		// if send ok, set a flag as answered or forwarded
-		var msg_number_replied = Element('msg_reply_from_'+ID);
-		var msg_number_forwarded = Element('msg_forward_from_'+ID);
-
-		if (msg_number_replied){
-			proxy_mensagens.proxy_set_message_flag(msg_number_replied.value, 'answered');
-		}
-		else if (msg_number_forwarded){
-			proxy_mensagens.proxy_set_message_flag(msg_number_forwarded.value, 'forwarded');
-		}
-		if(expresso_offline){
-			write_msg(get_lang('Your message was sent to queue'));
-			delete_border(ID,'true');
-			return;
-		}else{
-			if (wfolders.alert) {
-				write_msg(get_lang('Your message was sent and save.'));
-				wfolders.alert = false;
-			}
-			else {
-				write_msg(get_lang('Your message was sent.'));
-			}
-		}
-		// If new dynamic contacts were added, update the autocomplete ....
-		if(data.new_contacts){
-			var ar_contacts = data.new_contacts.split(',;');
-			for(var j in ar_contacts){
-				// If the dynamic contact don't exist, update the autocomplete....
-				if((contacts+",").indexOf(";"+ar_contacts[j]+",") == -1)
-					contacts += ",;" + ar_contacts[j];
-			}
-		}
-		if ((! openTab.toPreserve[ID]) && (openTab.imapUid[ID] != 0))
-		{
-			cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+openTab.imapBox[ID]+"&msgs_number="+openTab.imapUid[ID],function(data){ return; });
-		}
-		delete_border(ID,'true'); // Becarefull: email saved automatically should be deleted. delete_border erase information about openTab
- 	}
-	else{
-		if(data == 'Post-Content-Length')
-			write_msg(get_lang('The size of this message has exceeded  the limit (%1B).',preferences.max_attachment_size ? preferences.max_attachment_size : Element('upload_max_filesize').value));
-		else if(data)
-			write_msg(data);
-		else
-			write_msg(get_lang("Connection failed with %1 Server. Try later.", "Web"));
-	}
-	if(!expresso_offline)
-		expresso.connector.hideProgressBar();
-}
-
-/**
- * Método chamado pela applet para retornar o resultado da assinatura/decifragem do e-mail.
- * para posterior envio ao servidor.
- * @author Mário César Kolling <mario.kolling@serpro.gov.br>, Bruno Vieira da Costa <bruno.vieira-costa@serpro.gov.br>
- * @param smime O e-mail decifrado/assinado
- * @param ID O ID do e-mail, para saber em que aba esse e-mail será mostrado.
- * @param operation A operação que foi realizada pela applet (assinatura ou decifragem)
- */
-function appletReturn(smime, ID, operation, folder){
-
-    if (!smime){ // Erro aconteceu ao assinar ou decifrar e-mail
-        connector = expresso.connector;
-        expresso.connector.hideProgressBar();
-        return;
-    }
-
-	if(operation=='decript')
-	{
-		var handler = function(data){
-
-			if(data.msg_day == '')
-			{
-                header=expresso_local_messages.get_msg_date(data.original_ID, proxy_mensagens.is_local_folder(get_current_folder()));
-
-				data.fulldate=header.fulldate;
-				data.smalldate=header.smalldate;
-				data.msg_day = header.msg_day;
-				data.msg_hour = header.msg_hour;
-
-			}
-			this.show_msg(data);
-		};
-		para="&source="+smime+"&ID="+ID+"&folder="+folder;
-		cExecute ("expressoMail1_2.imap_functions.show_decript&", handler, para);
-	}else
-	{
-        ID_tmp = ID;
-        // Lê a variável e chama a nova função cExecuteForm
-        // Processa e envia para o servidor web
-        // Faz o request do connector novamente. Talvez implementar no connector
-        // para manter coerência.
-
-        var handler_send_smime = function(data){
-            send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug
-        };
-
-        var textArea = document.createElement("TEXTAREA");
-        textArea.style.display='none';
-        textArea.id = 'smime';
-        textArea.name = "smime";
-        textArea.value += smime;
-
-        // Lê a variável e chama a nova função cExecuteForm
-        // Processa e envia para o servidor web
-        // Faz o request do connector novamente. Talvez implementar no connector
-        // para manter coerência.
-        if (is_ie){
-            var i = 0;
-            while (document.forms(i).name != "form_message_"+ID) { i++; }
-            form = document.forms(i);
-        }
-        else
-            form = document.forms["form_message_"+ID];
-
-        form.appendChild(textArea);
-
-        cExecuteForm ("expressoMail1_2.imap_functions.send_mail", form, handler_send_smime, ID);
-    }
-}
-
-function send_message(ID, folder, folder_name){
-	
-	//limpa autosave_timer[ID]; havia conflito quando uma mensagem ia ser enviada e nesse exato momento o autosave
-        //entrava em execucao (a aba de edicao da mensagem continuava aberta e a mensagem exibida era a de que a mensagem foi
-        //salva na pasta Rascunhos e nao que tinha sido enviada, como deveria);
-        if (preferences.auto_save_draft == 1)
-	{
-		if (openTab.autosave_timer[ID])
-		{
-			clearTimeout(openTab.autosave_timer[ID]);
-		}
-	}
-
-	if ( document.getElementById('viewsource_rt_checkbox').checked == true )
-		document.getElementById('viewsource_rt_checkbox').click();
-
-	var save_link = Element("save_message_options_"+ID);
-	save_link.onclick = '';
-	save_link.className = 'message_options_inactive';
-	
-	ID_tmp = ID;
-
-	var handler_send_message = function(data){
-		send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug
-	};
-		
-	var textArea = document.createElement("TEXTAREA");
-	textArea.style.display='none';
-	textArea.name = "body";
-	body = document.getElementById("body_"+ID);
-	textArea.value += '<body>\r\n';
-	textArea.value += body.contentWindow.document.body.innerHTML;
-	textArea.value += '\r\n</body>';
-	var input_folder = document.createElement("INPUT");
-	input_folder.style.display='none';
-	input_folder.name = "folder";
-	input_folder.value = folder;
-	var msg_id = document.createElement("INPUT");
-	msg_id.style.display='none';
-	msg_id.name = "msg_id";
-	msg_id.value = openTab.imapUid[ID];
-	
-	if (is_ie){
-		var i = 0;
-		while (document.forms(i).name != "form_message_"+ID) { i++; }
-		form = document.forms(i);
-	}
-	else
-		form = document.forms["form_message_"+ID];
-
-        // Evita que e-mails assinados sejam enviados quando o usuário tenta enviar um e-mail
-        // não assinado (desmarcou a opção) após tentar enviar um e-mail assinado que não passou
-        // no teste de validação.
-        var checkSign = document.getElementById('return_digital_'+ID);
-        if (checkSign && !checkSign.checked){
-            var smime = Element('smime');
-            if (smime)
-            {
-                var parent = smime.parentNode;
-                parent.removeChild(smime);
-            }
-         }
-
-	form.appendChild(textArea);
-	form.appendChild(input_folder);
-	form.appendChild(msg_id);
-
-	var _subject = trim(Element("subject_"+ID).value);
-	if((_subject.length == 0) && !confirm(get_lang("Send this message without a subject?"))) {
-		Element("subject_"+ID).focus();
-		return;
-	}
-	
-	if (expresso_offline) {		
-		stringEmail = Element("to_"+ID).value;
-		stringEmail += Element("cco_"+ID).value =='' ? "":", "+Element("cco_"+ID).value;
-		stringEmail += Element("cc_"+ID).value =='' ? "":", "+Element("cc_"+ID).value;
-		var invalidEmail = searchEmail(stringEmail);	 
-		if(Element("to_"+ID).value=="" && Element("cco_"+ID).value=="" && Element("cc_"+ID).value=="") {
-			write_msg(get_lang("message without receiver."));
-			return;
-		}else if(invalidEmail[0] == true){
-			write_msg("Os endereços de destinatário a seguir estão incorretos: "+invalidEmail[1]);
-			return;
-		}
-
-		sucess = expresso_local_messages.send_to_queue(form);
-		var data_return = new Array();
-		data_return.success = sucess;
-		handler_send_message(data_return,ID);
-	}
-	else 
-		cExecuteForm("expressoMail1_2.imap_functions.send_mail", form, handler_send_message, ID);
-}
-function change_tr_properties(tr_element, newUid, newSubject){
-	if (tr_element == null)
-		return false;
-	message_id=tr_element.id;
-	var td_who = document.getElementById('td_who_'+message_id);
-	if (typeof(newSubject) != 'undefined')
-		td_who.nextSibling.innerHTML = newSubject;
-	tr_element.id = newUid;
-
-	var openNewMessage = function () {
-		expresso.connector.cacheNextRequest();
-		cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+newUid
-				+"&msg_folder="+url_encode(current_folder),show_msg);
-	};
-	for (var i=2; i < 10; i++){
-		if (typeof(tr_element.childNodes[i].id) != "undefined")
-			tr_element.childNodes[i].id = tr_element.childNodes[i].id.replace(message_id,newUid);
-		tr_element.childNodes[i].onclick = openNewMessage;
-	}
-}
-
-function return_save(data,border_id,folder_name,folder_id,message_id)
-{
-	Element("send_button_"+border_id).style.visibility="visible";
-	var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg); };
-
-	if (data.append != true || !data)
-	{
-		RichTextEditor.saveFlag = -1;
-		if (! data.append)
-			write_msg('ERROR saving your message.');
-		else
-		{
-			if (data.append.match(/^(.*)TRYCREATE(.*)$/))
-			{
-				expresso.connector.loadScript('jscode/TreeS');
-				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.',draftsfolder));
-				expresso.connector.loadScript('jscode/TreeShow');
-				ttree.FOLDER = 'root';
-				ttreeBox.new_past(draftsfolder);
-				setTimeout('save_msg('+border_id+')',3000);
-			}
-			else
-				write_msg(data.append);
-		}
-	}
-	else
-	{
-		RichTextEditor.saveFlag = 1;
-		openTab.imapUid[border_id] = data.msg_no;
-		openTab.imapBox[border_id] = data.folder_id;
-		
-		var newTitle = document.getElementById('subject_'+border_id).value;
-		if (newTitle.length > 18)
-			newTitle = newTitle.substr(18) + '...';
-		else if (newTitle == '')
-				newTitle = get_lang("No subject");
-		document.getElementById('font_border_id_'+border_id).innerHTML = newTitle;
-		
-		// Replace the embedded images for new uids
-		var mainField = document.getElementById('body_'+border_id).contentWindow;
-		var content_body =  mainField.document.getElementsByTagName('body').item(0).innerHTML;
-		var body_images = content_body.match(/msg_num=\d*/g);
-		var images_part = content_body.match(/msg_part=\d*/g);
-		if (body_images)
-		{
-			for (var i=0; i<body_images.length; i++){
-				content_body = 	content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]);
-			}
-			var allImgs = new Array (images_part.length);
-				var j=-1;
-				for (var i in images_part){
-				
-					if (is_ie)
-						if (i == 0)
-							var image_number = parseInt(images_part[i].substr(9));
-						else
-							image_number = "null";
-					else
-						var image_number = parseInt(images_part[i].substr(9));
-					
-				if (! isNaN(image_number))
-					{
-						if (! allImgs[image_number])
-						{
-							allImgs[image_number] = true;
-							j--;					
-						}
-					content_body = content_body.replace(images_part[i],'msg_part='+j);
-					}
-				}
-			content_body = content_body.replace(/msg_part=-/g,'msg_part=');
-			
-			mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body;
-		}	
-				
-		//Replace all files to new files
-		var divFiles = Element("divFiles_"+border_id);
-		elFiles = divFiles.getElementsByTagName("input");
-		var countCheck =0;
-		for (var i=0; i<elFiles.length; i++) {
-			if(elFiles[i].value !=""){
-				if (elFiles[i].type == "checkbox") {
-					countCheck++;							
-				}
-				else {
-					elFiles[i].value ="";
-					parantNodeFile = elFiles[i].parentNode.parentNode;
-					parantNodeFile.removeChild(elFiles[i].parentNode);
-					i--;
-				}
-				
-			}
-		};		
-		
-		var attach_files = expresso.connector.unserialize(data.files);
-		if (attach_files != null) {
-			openTab.countFile[border_id] = attach_files.length;
-			att_index = countCheck;
-		for (att_index; att_index < attach_files.length; att_index++){
-	
-			var link_attachment = document.createElement("A");
-			var fileName = attach_files[att_index].substr(0,attach_files[att_index].indexOf('_SIZE_'));
-			var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].indexOf('_SIZE_')+6))/1024;
-			link_attachment.innerHTML = fileName + " ("+borkb((parseInt(fileSize)*1024))+")";
-
-			var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','"+(att_index+2)+"','base64'";
-
-			link_attachment.setAttribute("href", "javascript:download_attachments("+href+")");
-
-			var a_tmp = href.split(',');
-			a_tmp[2] = fileName;
-			s_tmp = escape(expresso.connector.serialize(a_tmp));
-					
-			var check_attachment = document.createElement("INPUT");
-			check_attachment.type = 'CHECKBOX';
-			check_attachment.name = 'forwarding_attachments[]';
-			check_attachment.value = s_tmp;
-
-			divFiles.insertBefore(document.createElement("BR"),divFiles.childNodes[0]);			
-			divFiles.insertBefore(link_attachment,divFiles.childNodes[0]);
-			divFiles.insertBefore(check_attachment,divFiles.childNodes[0]);
-
-			check_attachment.checked = true;
-		}
-	}
-		if (message_id)
-		{
-			cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
-			if (openTab.imapBox[0] == "INBOX/"+draftsfolder)
-			{
-				//Update mailbox
-		                var tr_msg = document.getElementById(message_id);
-				change_tr_properties(tr_msg, data.msg_no, data.subject);
-			}
-		
-		}
-		var save_link = Element("save_message_options_"+border_id);
-		save_link.onclick = '';
-		save_link.className = 'message_options_inactive';
-		watch_changes_in_msg(border_id);
-		write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder(folder_name)));
-	}		
-}
-
-function save_msg(border_id,withImage){
-	if (typeof(withImage) == 'undefined')
-		withImage = false;
-
-	var rt_checkbox = Element('viewsource_rt_checkbox');
-	if (rt_checkbox == null)
-		return false;
-	if (rt_checkbox.checked == true)
-		rt_checkbox.click();
-
-	var sendButton = Element("send_button_"+border_id);
-	if (sendButton)
-		sendButton.style.visibility="hidden";
-
-	if (openTab.imapBox[border_id] && openTab.type[border_id] != 6 && openTab.type[border_id] != 7) //Gets the imap folder
-		var folder_id = openTab.imapBox[border_id];
-	else
-		var folder_id = "INBOX/"+draftsfolder;
-
-	if (folder_id == 'INBOX') // and folder name from border
-		var folder_name = get_lang(folder_id);
-	else
-		var folder_name = folder_id.substr(6);
-		
-	// hack to avoid form connector bug,  escapes quotation. Please see #179
-	tmp_border_id=border_id;
-	tmp_folder_name=folder_name;
-	tmp_folder_id=folder_id;
-	message_id = openTab.imapUid[border_id];
-	var handler_save_msg = function(data){ return_save(data,this.tmp_border_id,this.tmp_folder_name,this.tmp_folder_id,this.message_id); };
-
-	var textArea = document.createElement("TEXTAREA");
-	textArea.style.display='none';
-	textArea.name = "body";
-	body = document.getElementById("body_"+border_id);
-	if (! body)
-		return;
-	textArea.value += '<body>\r\n';
-	textArea.value += body.contentWindow.document.body.innerHTML;
-	textArea.value += '\r\n</body>';
-	var input_folder = document.createElement("INPUT");
-	input_folder.style.display='none';
-	input_folder.name = "folder";
-	input_folder.value = folder_id;
-	var input_msgid = document.createElement("INPUT");
-	input_msgid.style.display='none';
-	input_msgid.name = "msg_id";
-	input_msgid.value = message_id;
-	var input_insertImg = document.createElement("INPUT");
-	input_insertImg.style.display='none';
-	input_insertImg.name = "insertImg";
-	input_insertImg.value = withImage;
-
-	
-	if (is_ie){
-		var i = 0;
-		while (document.forms(i).name != "form_message_"+border_id) { i++; }
-		form = document.forms(i);
-	}
-	else
-		form = document.forms["form_message_"+border_id];
-	form.appendChild(textArea);
-	form.appendChild(input_folder);
-	form.appendChild(input_msgid);
-	form.appendChild(input_insertImg);
-
-	cExecuteForm ("expressoMail1_2.imap_functions.save_msg", form, handler_save_msg,border_id);	
-}
-
-function return_saveas(data,border_id,folder_name)
-{
-	if (data.append)
-	{
-		delete_border(border_id,null);
-		write_msg(get_lang('Your message was save as draft in folder %1.', folder_name));
-	}
-	else
-		write_msg('ERROR saving your message.');					
-}
-
-function save_as_msg(border_id, folder_id, folder_name){
-	// hack to avoid form connector bug,  escapes quotation. Please see #179
-	tmp_border_id=border_id;
-	tmp_folder_name=folder_name;
-	var handler_save_msg = function(data){ return_saveas(data,this.tmp_border_id,this.tmp_folder_name); };
-	var textArea = document.createElement("TEXTAREA");
-	textArea.style.display='none';
-	textArea.name = "body";
-	body = document.getElementById("body_"+border_id);
-	textArea.value += '<body>\r\n';
-	textArea.value += body.contentWindow.document.body.innerHTML;
-	textArea.value += '\r\n</body>';
-	
-	var input_folder = document.createElement("INPUT");
-	input_folder.style.display='none';
-	input_folder.name = "folder";
-	input_folder.value = folder_id;
-	
-	if (is_ie){
-		var i = 0;
-		while (document.forms(i).name != "form_message_"+border_id){i++}
-		form = document.forms(i);
-	}
-	else
-		form = document.forms["form_message_"+border_id];
-	form.appendChild(textArea);
-	form.appendChild(input_folder);
-	
-	cExecuteForm ("expressoMail1_2.imap_functions.save_msg", form, handler_save_msg,border_id);
-}
-
-
-// Get checked messages
-function set_messages_flag(flag, msgs_to_set){
-	var _hand_setmsgflag = function (data){
-		
-		var msgs_to_set = data.msgs_to_set.split(",");
-
-		if(!data.status) {
-			alert(data.msg);
-			Element('chkbox_sel_allmsg').checked = false;
-			for (var i = 0; i < msgs_to_set.length; i++) {
-				Element("check_box_message_" + msgs_to_set[i]).checked = false;
-				remove_className(Element(msgs_to_set[i]), 'selected_msg');
-			}
-			if(!data.msgs_unflageds)
-				return;
-			else
-				msgs_to_set = data.msgs_unflageds.split(",");
-		}
-		
-
-		for (var i=0; i<msgs_to_set.length; i++){
-			if(Element("check_box_message_" + msgs_to_set[i])){
-				switch(data.flag){
-					case "unseen":
-						set_msg_as_unread(msgs_to_set[i]);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
-						break;
-					case "seen":
-						set_msg_as_read(msgs_to_set[i], false);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
-						break;
-					case "flagged":
-						set_msg_as_flagged(msgs_to_set[i]);
-						document.getElementById("check_box_message_" + msgs_to_set[i]).checked = false;
-						break;
-					case "unflagged":
-						set_msg_as_unflagged(msgs_to_set[i]);
-						Element("check_box_message_" + msgs_to_set[i]).checked = false;
-						break;
-				}
-			}
-		}
-		Element('chkbox_sel_allmsg').checked = false;
-	};
-	
-	var folder = get_current_folder();
-	if (msgs_to_set == 'get_selected_messages')
-		var msgs_to_set = this.get_selected_messages();
-	else
-		folder = Element("input_folder_"+msgs_to_set+"_r").value;
-	
-	if (msgs_to_set)
-	{
-		cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, _hand_setmsgflag);
-	}
-	else
-		write_msg(get_lang('No selected message.'));		
-}
-
-// By message number
-function set_message_flag(msg_number, flag){
-	var msg_number_folder = Element("new_input_folder_"+msg_number+"_r");
-	var _hand_setmsgflag = function (data){
-		if (data.status && Element("td_message_answered_"+msg_number)) {	
-			if(flag == 'answered')
-				Element("td_message_answered_"+msg_number).innerHTML = '<img src="'+URL_SERVER+'expressoMail1_2/templates/'+template+'/images/answered.gif" title="Respondida">';
-			else if(flag == 'forwarded')
-				Element("td_message_answered_"+msg_number).innerHTML = '<img src="'+URL_SERVER+'expressoMail1_2/templates/'+template+'/images/forwarded.gif" title="Encaminhada">';
-		}
-	};
-	cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+( msg_number_folder ?  msg_number_folder.value : get_current_folder() )+"&msgs_to_set="+msg_number+"&flag="+flag, _hand_setmsgflag);
-}
-
-function print_all(){
-	if (openTab.type[currentTab] == 2)
-		return print_msg(current_folder,currentTab.substr(0,currentTab.indexOf("_r")),currentTab);
-
-	var folder= Element('border_id_0').innerHTML;
-	var body = Element('divScrollMain_'+numBox).innerHTML;
-	var print_width = screen.width - 200;
-	var x = ((screen.width - print_width) / 2);
-	var y = ((screen.height - 400) / 2) - 35;
-	var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y);
-	var seekDot = /\<img /gi;
-	body = body.replace(seekDot, "<img style='display:none' ");
-	seekDot = /\<input /gi;
-	body = body.replace(seekDot, "<input style='display:none' ");
-	
-	while (1){
-		try{
-			var html = '<br>';
-			html += "<h4>ExpressoLivre - ExpressoMail</h4>";
-			html += folder+"<hr>";
-			
-			window_print.document.body.innerHTML = html + '<blockquote><font size="2">' +
-			'<table style="font-size:12" width="'+(is_ie ? "85%" : "99%" )+'"><TR><TD align="center" width="5%">&nbsp;</TD><TD width="30%" align="center">'+get_lang("Who")+'</TD><TD align="center" width="45%">'+get_lang("Subject")+'</TD><TD align="center" width="10%">'+get_lang("Date")+'</TD><TD width="10%">'+get_lang("Size")+'</TD></TR></table>'
-			+ body + '</font></blockquote>';
-			break;
-		}
-		catch(e){
-			//alert(e.message);
-		}
-	}
-	window_print.document.close();
-	window_print.print();
-}
-
-
-function print_msg(msg_folder, msg_number, border_ID){
-	var div_toaddress_full = Element("div_toaddress_full_"+border_ID);	
-	var div_ccaddress_full = Element("div_ccaddress_full_"+border_ID);
-	var printListTO = (div_toaddress_full && div_toaddress_full.style.display != 'none') || toaddress_array[border_ID].length == 1 ? true : false;	
-	var printListCC = (div_ccaddress_full && div_ccaddress_full.style.display != 'none') || !div_ccaddress_full ? true : false;	
-	var sender		= Element('sender_values_'+border_ID) ? Element('sender_values_'+border_ID).value : null;
-	var from		= Element('from_values_'+border_ID) ? Element('from_values_'+border_ID).value : null;
-	var to			= Element('to_values_'+border_ID) ? Element('to_values_'+border_ID).value :null;
-	var cc 			= Element('cc_values_'+border_ID) ? Element('cc_values_'+border_ID).value : null;		
-	var date		=  Element('date_'+border_ID);	
-	var subject		= Element('subject_'+border_ID);
-	var attachments	= Element('attachments_'+border_ID);
-	var body		= Element('body_'+border_ID);
-	
-	if (!is_ie) {//altera o link da imagem para renderização na tela de impressão no firefox
-		var link = location.href.replace(/\/expressoMail1_2\/(.*)/, "");
-		link = link.replace(/\/expressoMail1_2\/(.*)/, "");
-		body.innerHTML = body.innerHTML.replace(/\.(\/inc\/show_embedded_attach\.php)/, link + "/expressoMail1_2$1");
-		body.innerHTML = body.innerHTML.replace(/(tmpLclAtt\/)/, link + "/expressoMail1_2/$1");
-	}
-
-	var print_width = screen.width - 200;
-	var x = ((screen.width - print_width) / 2);
-	var y = ((screen.height - 400) / 2) - 35;
-	var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y);
-	if(window_print == null) {
-		alert(get_lang("The Anti Pop-Up is enabled. Allow this site (%1) for print.",document.location.hostname));
-		return;
-	}
-
-	//needed to get the names of the attachments... only.
-	if(attachments != null)
-	{
-		var a = attachments.childNodes;
-		var attachs = "";
-		var show_attachs = "";
-		for(i=0;i<a.length;i++)
-		{
-			if(a[i].tagName && a[i].tagName == "A")
-			{
-				attachs += a[i].innerHTML;
-			}
-		}
-		show_attachs = "<tr><td width=7%><font size='2'>" + get_lang('Attachments: ')+ " </font></td><td><font size='2'>"+attachs+"</font></td></tr>";
-	} else{
-		show_attachs = "";
-	}
-	
-	while (1){
-		try{
-			var html = '<br><br>';
-			//html += "<input type='button' value='Imprimir' onclick='javascript:window.print();'>";
-			html += "<h4>ExpressoLivre - ExpressoMail</h4><hr>";
-			html += '<table><tbody>';
-			if(sender)
-				html += "<tr><td width=7% noWrap><font size='2'>" + get_lang('Sent by') + ": </font></td><td><font size='2'>"+sender+"</font></td></tr>";
-			if(from)
-				html += "<tr><td width=7%><font size='2'>" + get_lang('From') + ": </font></td><td><font size='2'>"+from+"</font></td></tr>";
-			if(to) {
-				if(!printListTO)
-					to = 'Os destinatários não estão sendo exibidos para esta impressão';
-				html += "<tr><td width=7%><font size='2'>" + get_lang('To') + ": </font></td><td><font size='2'>"+to+"</font></td></tr>";
-			}			
-			if (cc) {
-				if(!printListCC)
-					cc = 'Os destinatários não estão sendo exibidos para esta impressão';
-				html += "<tr><td width=7%><font size='2'>" + get_lang('Cc') + ": </font></td><td><font size='2'>"+cc+"</font></td></tr>";
-			}
-			if(date)
-				html += "<tr><td width=7%><font size='2'>" + get_lang('Date') + ": </font></td><td><font size='2'>"+date.innerHTML+"</font></td></tr>";			
-			html += "<tr><td width=7%><font size='2'>" + get_lang('Subject')+ ": </font></td><td><font size='2'>"+subject.innerHTML+"</font></td></tr>";
-			html += show_attachs; //to show the names of the attachments
-			html += "</tbody></table><hr>";
-			window_print.document.body.innerHTML = html + '<blockquote><font size="2">' + body.innerHTML + '</font></blockquote>';
-			if(!is_ie){
-				var tab_tags = window_print.document.getElementsByTagName("IMG");			
-				for(var i = 0; i < tab_tags.length;i++){
-					var _img = document.createElement("IMG");
-					_img.src = tab_tags[i].src;
-					tab_tags[i].parentNode.replaceChild(_img,tab_tags[i]);
-				}
-			}
-			break;
-		}
-		catch(e){
-			//alert(e.message);
-		}
-	}
-	window_print.document.close();
-	window_print.print();
-}
-
-function empty_trash_imap(){
-	var handler_empty_trash = function(data){
-		Element('chkbox_sel_allmsg').checked = false;
-		tree_folders.getNodeById('INBOX'+cyrus_delimiter+trashfolder).alter({caption: get_lang("Trash")});
-		tree_folders.getNodeById('INBOX'+cyrus_delimiter+trashfolder)._refresh();
-		update_quota(get_current_folder());
-		if (data)
-		{
-			write_msg(get_lang('Your Trash folder was empty.'));
-			if (get_current_folder() == 'INBOX'+cyrus_delimiter+trashfolder){
-				draw_paging(0);
-				kill_current_box();				
-				Element('tot_m').innerHTML = 0;
-				Element('new_m').innerHTML = 0;
-			}
-		}
-		else 
-			write_msg(get_lang('ERROR emptying your Trash folder.'));
-	};
-	var realyEmptyTrash=confirm(get_lang('Do you really want to empty your trash folder?'));
-	if (realyEmptyTrash){
-		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultTrashFolder", handler_empty_trash);
-	}
-}
-
-function empty_spam_imap(){
-	var handler_empty_spam = function(data){
-		Element('chkbox_sel_allmsg').checked = false;
-		if (get_current_folder() == 'INBOX'+cyrus_delimiter+spamfolder){
-			draw_paging(0);
-			kill_current_box();
-		}
-		tree_folders.getNodeById('INBOX'+cyrus_delimiter+spamfolder).alter({caption: get_lang("Spam")});
-		tree_folders.getNodeById('INBOX'+cyrus_delimiter+spamfolder)._refresh();
-		update_quota(get_current_folder());
-		if (data)
-			write_msg(get_lang('Your Spam folder was empty.'));
-		else
-			write_msg(get_lang('ERROR emptying your Spam folder.'));
-	};
-	var realyEmptySpam=confirm(get_lang('Do you really want to empty your spam folder?'));
-	if (realyEmptySpam)
-		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultSpamFolder", handler_empty_spam);
-}
-
-
-function export_all_selected_msgs(){
-	if (openTab.type[currentTab] > 1){
-		source_msg(currentTab,current_folder);
-		return;
-	}
-	var msgs_to_export = this.get_selected_messages();
-	
-	var _hand_expallselmsg = function(data){
-	
-		if(!data){
-			write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'));
-		}
-		else
-			download_attachments(null, null, data, null,null,'mensagens.zip');
-	};
-	
-	if (msgs_to_export) {
-		cExecute ("expressoMail1_2.exporteml.makeAll", _hand_expallselmsg, "folder="+get_current_folder()+"&msgs_to_export="+msgs_to_export);
-		write_msg(get_lang('You must wait while the messages will be exported...'));
-	}
-	else
-		write_msg(get_lang('No selected message.'));
-}
-
-function select_all_search_messages(select, id){
-	var search_box = Element("table_resultsearch_" + id.substr(18)).firstChild;
-	var felement = search_box.firstChild;
-	while(felement)
-	{
-	if (select)
-		felement.firstChild.firstChild.checked = true;
-	else
-		felement.firstChild.firstChild.checked = false;
-	felement = felement.nextSibling;
-	}
-}
-
-// Save image file.
-function save_image(e,thumb,file_type){
-	file_type = file_type.replace("/",".");
-	thumb.oncontextmenu = function(e) {
-		return false;
-	};
-	var _button = is_ie ? window.event.button : e.which;
-	var	_target = is_ie ? event.srcElement : e.target;
-	
-	if(_button == 2 || _button == 3) {
-		var _params = _target.id.split(";;");
-		download_attachments(_params[0],_params[1],_params[2],_params[3],_params[4],file_type);
-	}
-}
-
-function nospam(msgs_number, border_ID, folder){
-	if (folder == 'null')
-		folder = get_current_folder();
-	var new_folder 	= 'INBOX';
-	var new_folder_name = get_lang('INBOX');
-	var handler_move_msgs = function(data){
-		if (msgs_number == 'selected')	
-			set_messages_flag("unseen", "get_selected_messages");
-		else
-			proxy_mensagens.proxy_set_message_flag(msgs_number, "unseen");
-   	    proxy_mensagens.proxy_move_messages(folder, msgs_number, border_ID, new_folder, new_folder_name);
-	};
-
-    if (msgs_number == 'selected')
-	   	msgs_number = get_selected_messages();
-       
-	if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
-		cExecute ("expressoMail1_2.imap_functions.spam&folder="+folder+"&spam=false"+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message+"&cyrus_delimiter="+cyrus_delimiter, handler_move_msgs);
-	else
-		write_msg(get_lang('No selected message.'));
-}
-
-function spam(folder, msgs_number, border_ID){
-	if (folder == 'null')
-		folder = get_current_folder();
-    var new_folder 		= 'INBOX'+cyrus_delimiter+'Spam';
-	var new_folder_name = 'Spam';
-	var handler_move_msgs = function(data){
-		// debug
-		// alert(data);
-		proxy_mensagens.proxy_move_messages(folder, msgs_number, border_ID, new_folder, new_folder_name);
-	};
-    if(msgs_number == 'selected')
-		msgs_number = get_selected_messages();
-	if(parseInt(msgs_number) > 0 || msgs_number.length > 0)
-		cExecute ("expressoMail1_2.imap_functions.spam&folder="+folder+"&spam=true"+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message+"&cyrus_delimiter="+cyrus_delimiter, handler_move_msgs);
-	else
-    	write_msg(get_lang('No selected message.'));
-}
-
-function import_window(){
-	var win = arrayJSWin["import_window"];
-	var form_upload = Element("form_upload");
-	if(!win) {
-		var form = document.createElement("DIV");
-		form.id  = "import_window";
-		form.style.visibility = "hidden";
-		form.style.position = "absolute";
-		form.style.background = "#eeeeee";
-		form.style.left = "0px";
-		form.style.top  = "0px"; 
-		form.style.width = "0px";
-		form.style.height = "0px";
-		document.body.appendChild(form);
-		form_upload = document.createElement("DIV");
-		form_upload.id = "form_upload";
-		form_upload.style.position = "absolute";
-		form_upload.style.top = "5px";
-		form_upload.style.left = "5px";
-		form_upload.name =  get_lang('zip mails to import');
-		form_upload.style.width = "450px";
-		form_upload.style.height = "75px";
-		form.appendChild(form_upload);	
-		form.style.width  =  form.firstChild.style.width;
-		form.style.height = form.firstChild.style.height;
-		form.style.zIndex = "10000";			
-		var title = form.firstChild.name;
-		var wHeight = form.offsetHeight + "px";
-		var wWidth =  form.offsetWidth   + "px";
-		form.style.width = form.offsetWidth - 5;
-		win = new dJSWin({
-			id: 'win_'+form.id,
-			content_id: form.id,
-			width: wWidth,
-			height: wHeight,
-			title_color: '#3978d6',
-			bg_color: '#eee',
-			title: title,
-			title_text_color: 'white',
-			button_x_img: '../phpgwapi/images/winclose.gif',
-			border: true });	
-		win.draw();
-	}
-	form_upload.innerHTML = '<form method="POST" name="form_import" enctype="multipart/form-data">'+get_lang('zip mails to import')+':<br>'+
-	'<input name="file_1" maxlength="255" size="50" id="file_1" type="file"><br>' +
-	'<input title="'+get_lang('Select a folder')+'"  value="' + get_lang('Select a folder') + '"' + 'type="button" onclick="javascript:select_import_folder()">&nbsp;' +
-	'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
-	' type="button" onclick="arrayJSWin[\'import_window\'].close()"></form>';	
-	win.open();
-}
-
-function import_msgs(wfolders_tree){
-	function handler(data){		
-		// Its necessary to encapsulate the data returned (IE bugfix)
-		return_import_msgs(data,wfolders_tree);		
-	}
-	var countFiles = document.form_import.countFiles;
-	if(!countFiles){
-		countFiles = document.createElement("INPUT");
-		countFiles.type = "hidden";
-		countFiles.name = "countFiles";
-		countFiles.value = "1";
-		document.form_import.appendChild(countFiles);
-	}
-	var folder = document.createElement("INPUT");
-	folder.type = "hidden";
-	folder.name = "folder";
-	folder.value = wfolders_tree._selected.id;
-	document.form_import.appendChild(folder);
-	write_msg(get_lang('You must wait while the messages will be imported...'));
-	
-	cExecuteForm('expressoMail1_2.imap_functions.import_msgs', document.form_import, handler);
-}
-function return_import_msgs(data, wfolders_tree){
-	if(data && data.error){
-		write_msg(data.error);
-	}
-	else{
-		if(data == 'Post-Content-Length')
-			write_msg(get_lang('The size of this message has exceeded  the limit (%1B).',Element('upload_max_filesize').value));
-		else {	/*
-			* @author Rommel Cysne (rommel.cysne@serpro.gov.br)
-			* @date 2009/05/15
-			* Foi colocado um teste para verificar se a pasta selecionada, passada como parametro,
-			* eh uma pasta local (qualquer uma)
-			*/
-			var er = /^local_/;
-			if ( er.test(wfolders_tree._selected.id) )
-			{
-				archive_msgs('INBOX/Lixeira/tmpMoveToLocal',wfolders_tree._selected.id,data);
-				cExecute('expressoMail1_2.imap_functions.delete_mailbox',function(){},'del_past=INBOX/Lixeira/tmpMoveToLocal');
-			}
-                         else{
-				write_msg(data);
-				arrayJSWin["import_window"].close();
-				if(openTab.imapBox[0] == wfolders_tree._selected.id)
-				{
-					openTab.imapBox[0] = '';
-					change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				} else{
-					refresh();
-				}
-			}
-	}
-    }
-
-}
-
-function select_import_folder(){
-	//Begin: Verify if the file extension is allowed.
-	var imgExtensions = new Array("eml","zip");
-	var inputFile = document.form_import.file_1;	
-	if(!inputFile.value){
-		alert(get_lang('File extension forbidden or invalid file') + '.');
-		return false;
-	}
-	var fileExtension = inputFile.value.split(".");
-	fileExtension = fileExtension[(fileExtension.length-1)];
-	var deniedExtension = true;
-	for(var i=0; i<imgExtensions.length; i++) {
-		if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) {
-			deniedExtension = false;
-			break;
-		}
-	}
-	if(deniedExtension) {
-		alert(get_lang('File extension forbidden or invalid file') + '.');
-		return false;
-	}
-	arrayJSWin['import_window'].close();
-	wfolders.makeWindow('null','import');
-}
-function import_calendar(data){
-	function handler_import_calendar(data){
-		if(data === true){
-			write_msg(get_lang("The event was imported successfully."));
-		}
-	}
-	if(confirm(get_lang("Do you confirm this import to your Calendar?"))){
-			cExecute('expressoMail1_2.db_functions.import_vcard&msg_folder='+data,handler_import_calendar);
-	}
-}
-function hack_sent_queue(data,rowid_message) {
-
-	if (data.success != true) {
-		queue_send_errors = true;
-		expresso_local_messages.set_problem_on_sent(rowid_message,data);
-	}
-	else {
-		expresso_local_messages.set_as_sent(rowid_message);
-		if(document.getElementById('_action')) { //Não posso manter esse elemento, pois o connector irá criar outro com o mesmo id para a próxima mensagem.
-			el =document.getElementById('_action');
-			father = el.parentNode;
-			father.removeChild(el);
-		}
-		send_mail_from_queue(false);
-	}
-}
-
-function send_mail_from_queue(first_pass) {
-	if(first_pass)
-		modal('send_queue');
-	var num_msgs = expresso_local_messages.get_num_msgs_to_send();
-	if (num_msgs <= 0) {
-		close_lightbox();
-		return;
-	}
-	document.getElementById('text_send_queue').innerHTML = get_lang('Number of messages to send:')+' '+num_msgs;	
-	var _hand_sendqueuemsg = function(data,rowid_message) {
-		hack_sent_queue(data,this.ID_tmp);
-	};
-	var msg_to_send = expresso_local_messages.get_form_msg_to_send();
-	if(!is_ie)
-		ID_tmp = msg_to_send.rowid.value;
-	else {//I.E kills me of shame...
-		for (var i=0;i<msg_to_send.length;i++) {
-			if(msg_to_send.elements[i].name=='rowid') {
-				ID_tmp = msg_to_send.elements[i].value;
-				break;
-			}
-		}
-	}
-
-	cExecuteForm("expressoMail1_2.imap_functions.send_mail", msg_to_send, _hand_sendqueuemsg,"queue_"+ID_tmp);
-}
-
-function check_mail_in_queue() {
-	var num_msgs = expresso_local_messages.get_num_msgs_to_send();
-	if(num_msgs>0) {
-		control = confirm(get_lang('You have messages to send. Want you to send them now?'));
-		if(control) {
-			send_mail_from_queue(true);
-		}
-		return true;
-	}
-	else {
-		return false;
-	}
-}
-
-function force_check_queue() {
-	if(!check_mail_in_queue()) {
-		write_msg(get_lang("No messages to send"));
-	}
-}
-
-function searchEmail(emailString){
-		var arrayInvalidEmails = new  Array();
-		arrayInvalidEmails[1] = '';		
-		var email;
-		var arrayEmailsFull = new Array();
-		arrayEmailsFull = emailString.split(',');
-		var er_Email =  new RegExp("<(.*?)>");
-		// TODO Use validateEmail of common functions	
-		var er_ValidaEmail = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$");
-
-		for (i=0; i < arrayEmailsFull.length; i++){
-			email = er_Email.exec(arrayEmailsFull[i]);
-			tempEmail = email == null  ? arrayEmailsFull[i]:email[1];
-			tempEmail = tempEmail.replace(/^\s+|\s+$/g,"");
-			if (tempEmail != '') {
-				singleEmail = er_ValidaEmail.exec(tempEmail);
-				
-				if (singleEmail == null) {
-					arrayInvalidEmails[0] = true;
-					arrayInvalidEmails[1] += (email == null ? arrayEmailsFull[i] : email[1]) + "; ";
-				}
-			}	
-		}
-		
-		return arrayInvalidEmails;
-};
Index: trunk/expressoMail1_2/js/jscode/globals.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/globals.js	(revision 3037)
+++ 	(revision )
@@ -1,74 +1,0 @@
-var debug = false;
-var _bTime = new Date();
-_bTime = _bTime.getTime();
-var queue_send_errors = false;
-var current_page = 1;
-var current_folder = '';
-var id_menu_folders = '';
-var preferences = '';
-var contacts = '';
-var search_box_type = 'ALL';
-var sort_box_type = 'SORTARRIVAL';
-var sort_box_reverse = 1;
-var last_message_selected = '';
-var cyrus_delimiter = '';
-var ccaddress_array = new Array();
-var ccoaddress_array = new Array();
-var toaddress_array = new Array();
-var tree_folders = '';
-var folders = new Array();
-var global_search = 1;
-var title_app_menu = '<table align=center border=0 width=100% cellspacing=0 cellpadding=2>'+
-	'<tr><td align=left height=16px width="1%" nowrap class="table_top">&nbsp;'+
-	'<a href=# onclick="javascript:new_message(\'new\',\'null\')" align=left>'+
-	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/createmail.gif">'+
-	'&nbsp;Novo</a>&nbsp;&nbsp;'+
-	'<a href="#" onclick="javascript:wfolders.makeWindow(\'\', \'change_folder\')" align=left>'+
-	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/editfolders.png">'+
-	'&nbsp;Trocar Pasta</a>&nbsp;&nbsp'+	
-	'<a href="#" onclick="javascript:refresh();" align=left>'+
-	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/checkmail.gif">'+
-	'&nbsp;Atualizar</a>&nbsp;&nbsp;'+
-	'<a id="link_tools" href="#" align=left>'+
-	'<img height="16px" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/tools.gif">'+
-	'&nbsp;Ferramentas...</a>&nbsp;&nbsp;</td><td style="padding-left:17px" width="1%" id="content_quota" align=left nowrap></td><td width=* id="div_menu_c3" align="right"></td></tr></table>';
-
-var title_app = '<table height="16px" border=0 width=100% cellspacing=0 cellpadding=2>'+
-	'<tr>'+
-	'<td style="padding-left:17px" width=33% id="content_quota" align=left></td>'+
-	'<td class="divAppboxHeader" width=33% id="main_title">Expresso Mail</td>'+
-	'<td width=33% id="div_menu_c3" align=right></td>'+
-	'</tr></table>';
-
-var divStatusBar = document.getElementById("divStatusBar");
-var denyFileExtensions = new Array('exe','com','reg','chm','cnf','hta','ins','jse','job','lnk','pif','src','scf','sct','shb','vbe','vbs','wsc','wsf','wsh','cer','its','mau','','mda','mar','mdz','prf','pst');
-
-var special_folders = new Array(4);
-special_folders[ 'Trash' ] = 'Trash';
-special_folders[ 'Drafts' ] = 'Drafts';
-special_folders[ 'Spam' ] = 'Spam';
-special_folders[ 'Sent' ] = 'Sent';
-var trashfolder = 'Trash';
-var draftsfolder = 'Drafts';
-var sentfolder = 'Sent';
-var spamfolder = 'Spam';
-var token_param = '';
-var expresso_offline = false;
-
-var RichTextEditor = null;
-var _dragArea = null;
-var InfoContact = null;
-
-var _connector = new XConnector( {
-	"path" : URL_SERVER,
-	"controller" : "controller.php?action="
-} );
-
-var BordersArray = new Array();
-var expresso_local_messages;
-var proxy_mensagens;
-var wfolders;
-var use_spam_filter;
-
-var loading_img = document.createElement( 'center' );
-loading_img.appendChild( createAndSet("IMG",['src','style'],[URL_SERVER+'phpgwapi/templates/'+template+'/images/loading.gif','padding-top: 20px']) );
Index: trunk/expressoMail1_2/js/jscode/wfolders.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/wfolders.js	(revision 2642)
+++ 	(revision )
@@ -1,161 +1,0 @@
-	function cWFolders()
-	{
-		this.arrayWin = new Array();
-		this.el;
-		this.alert = false;
-	}
-
-	cWFolders.prototype.makeWindowNew = function(border_id, type,from_search)
-	{ //Javascript doesn't seems to have polimorfism
-		_this = this;
-	
-		var el = document.createElement("DIV");
-		el.style.visibility = "hidden";
-		el.style.position = "absolute";
-		el.style.left = "0px";
-		el.style.top = "0px";
-		el.style.width = "0px";
-		el.style.height = "0px";
-		el.id = 'dJSWin_wfolders';
-		document.body.appendChild(el);
-		
-		el.innerHTML = "<table><tbody><tr><td>&nbsp</td><td>"+
-		"<div id='wfolders_content_tree' style='height:200px; width:250px; overflow:auto; background:#F7F7F7'></div>"+
-		"</td></tr></tbody></table>";
-
-		var space = document.createElement('SPAN');
-		space.innerHTML = "<BR>&nbsp;&nbsp;";
-		el.appendChild(space);
-
-		var butt = Element('dJSWin_wfolders_bok');
-		if (!butt){
-			butt = document.createElement('INPUT');
-			butt.id = 'dJSWin_wfolders_bok';
-			butt.type = 'button';
-			el.appendChild(butt);
-		}
-		if (type == 'save')
-				butt.value = get_lang('Save'); 
-		else if (type == 'send_and_file')
-                butt.value = get_lang('Send and file'); 
-		else if (type == 'move_to')
-			butt.value = get_lang('Move');
-		else if (type == 'change_folder')
-			butt.value = get_lang('Change folder');	
-		else //default value
-			butt.value = get_lang(type);
-
-		butt.onclick = function () {
-			wfolders.arrayWin[el.id].close();
-			if (type == 'save'){
-				save_as_msg(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption,true);
-			}
-			else if (type == 'send_and_file'){
-				send_message(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				wfolders.alert = true;
-			}
-			else if (type == 'move_to')	{
-				var msg_number =  (border_id ? border_id.replace('_r','') : 'selected');
-				if (border_id.match('search'))
-					move_search_msgs(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);	
-				else{
-					proxy_mensagens.proxy_move_messages('null',msg_number, border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
-					wfolders.alert = true;
-				}
-			}
-			else if (type == 'change_folder'){
-				change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				wfolders.alert = true;
-			}
-			else if (type == 'import'){
-				import_msgs(wfolders_tree);
-			}
-		};
-		if (type == 'save')
-			butt.value = get_lang('Save');
-		else if (type == 'send_and_file')
-			butt.value = get_lang('Send and file');
-
-		var space = document.createElement('SPAN');
-		space.innerHTML = "&nbsp;&nbsp;";
-		el.appendChild(space);
-
-		var butt = document.createElement('BUTTON');
-		var buttext = document.createTextNode(get_lang('Close'));
-		butt.appendChild(buttext);
-		butt.onclick = function () {wfolders.arrayWin[el.id].close();};
-		el.appendChild(butt);
-
-		wfolders_tree = new dFTree({name: 'wfolders_tree'});
-		if(!expresso_offline)
-			var n_root = new dNode({id:'root', caption:get_lang("My Folders")});
-		else
-			var n_root = new dNode({id:'local_root', caption:get_lang("local messages")});
-		wfolders_tree.add(n_root,'anything'); //Places the root; second argument can be anything.
-
-		var folders = tree_folders.getNodesList(cyrus_delimiter);
-		for (var i=1; i<folders.length; i++)
-		{
-			if (proxy_mensagens.is_local_folder(folders[i].id) && from_search) {
-				continue;
-			}
-			var nn = new dNode({
-				id: folders[i].id,
-				caption: lang_folder(folders[i].caption),
-				plusSign: folders[i].plusSign
-			});
-			wfolders_tree.add(nn, folders[i].parent);
-			
-		}
-		Element('wfolders_content_tree').innerHTML = ""; //As buscas nÃ£o podem incluir mover entre pastas locais, pelo menos por enquanto
-		wfolders_tree.draw(Element('wfolders_content_tree'));
-		n_root.changeState();
-		if(!expresso_offline)
-			wfolders_tree.getNodeById('INBOX')._select();
-		else
-			wfolders_tree.getNodeById('local_Inbox')._select();
-		_this.showWindow(el, type);
-	};
-
-	cWFolders.prototype.makeWindow = function(border_id, type)
-	{
-		this.makeWindowNew(border_id,type,false);
-	};
-	
-	cWFolders.prototype.showWindow = function (div, type)
-	{
-		if(! div) {
-			alert(get_lang("This list has no participants."));
-			return;
-		}
-		
-		if(! this.arrayWin[div.id]) {
-			div.style.width = "275px";
-			div.style.height = "250px";
-			var title = get_lang('Select a folder')+":";
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-			div.style.width = div.offsetWidth - 5;
-
-			win = new dJSWin({
-				id: 'win_'+div.id,
-				content_id: div.id,
-				width: wWidth,
-				height: wHeight,
-				title_color: '#3978d6',
-				bg_color: '#eee',
-				title: title,
-				title_text_color: 'white',
-				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true });
-			
-			this.arrayWin[div.id] = win;
-			win.draw();
-		}
-		else {
-			win = this.arrayWin[div.id];
-		}
-		win.open();
-	};
-	
-/* Build the Object */
Index: trunk/expressoMail1_2/js/jscode/doiMenuData.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/doiMenuData.js	(revision 2630)
+++ 	(revision )
@@ -1,285 +1,0 @@
-_icon_dir = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/';
-
-function ConstructMenuTools(){
-	// Layout padrão de menu = option1
-	var _divMenu = Element('menu_tools');
-	if(_divMenu)
-		return;
-	var _option1 = preferences.hide_folders == "1" ? false : true;
-								
-	if (!expresso_offline) {
-		var itens = new Array("preferences_mail()|" + get_lang("Preferences") + "|preferences.png",
-				"search_emails(\"\")|" + get_lang("Search") + "|search.png",
-				"filterbox()|" + get_lang("Edit filters") + "|filters.png",
-				"folderbox()|" + get_lang("Edit folders") + "|editfolders.png",
-				"sharebox()|" + get_lang("Share mailbox") + "|usersfolders.png",
-				"empty_trash_imap()|" + get_lang("Empty trash") + "|trash.png");
-		if(preferences.use_local_messages==1) {
-			if(expresso_local_messages.is_offline_installed()) {
-				itens.push("force_check_queue()|" + get_lang("Send from queue") + "|queue.jpg");
-			}
-		}
-	}
-	else {
-		var itens = new Array("search_emails(\"\")|" + get_lang("Search") + "|search.png",
-				"folderbox()|" + get_lang("Edit folders") + "|editfolders.png");	
-	}
-
-	var _link = Element('link_tools');
-	_divMenu = document.createElement("DIV");
-	_divMenu.id = "menu_tools";
-	_divMenu.style.position = "absolute";
-	_divMenu.style.top =  findPosY(_link) + (_option1 ? 19 : 14);
-	_divMenu.style.left = findPosX(_link) + (_option1 ? 22 : 22);
-	_divMenu.style.width = "auto";
-	_divMenu.style.height = "auto";
-	_divMenu.style.padding = "1px";
-	_divMenu.style.paddingTop = "0px";
-	_divMenu.style.zIndex = "10000";
-	_divMenu.style.backgroundColor = "WHITE";
-	_divMenu.style.border = "1px solid #999999";
-	_divMenu.style.borderTop = "0px solid #FFFFFF";
-	_divMenu.style.visibility = "hidden";
-	var _timeout = false;
-	_hideMenuTools = function () {		
-		Element('menu_tools').style.visibility = "hidden";	
-	};
-	_viewMenuTools = function () {
-		Element('menu_tools').style.visibility = "visible";
-	};
-
-	var _mouseover = _link.onmouseover;
-	
-	_link.onmouseover = function () {	
-		var _option1 = preferences.hide_folders == "1" ? false : true;
-		var _link = Element('link_tools');
-		Element('menu_tools').style.top =  findPosY(_link) + (_option1 ? 19 : 14);
-		if(_timeout) {
-			clearTimeout(_timeout);
-			_timeout=false;
-		}	
-		if(_mouseover) 
-			_mouseover(); 
-	
-		_timeout = setTimeout("_viewMenuTools();",500);
-	};
-	
-	_link.onmouseout  = function () {
-		if(_timeout) {
-			clearTimeout(_timeout);
-			_timeout=false;
-		}
-		if(_option1)
-			unset_menu_bg(Element("link_tools"));	
-		_timeout = setTimeout("_hideMenuTools();",500);
-	};
-
-	var _t = document.createElement("TABLE");
-	_t.cellPadding="0";
-	_t.cellSpacing="0";
-	_t.onmouseover = function () {	
-		if(_timeout) {
-			clearTimeout(_timeout);
-			_timeout=false;
-		}	
-		if(_mouseover) 
-			_mouseover(); 
-	
-		Element('menu_tools').style.visibility = "visible";
-	};
-	var _tbody = document.createElement("TBODY");
-	
-	var buildTr = function(value) {
-		var item = value.split('|');
-		var _tr = document.createElement("TR");
-		var _td = document.createElement("TD");
-		_td.innerHTML = '<img height="16px" src="' + _icon_dir + item[2]+'">&nbsp;'+item[1]+'&nbsp;';
-		_td.style.color = "DARKBLUE";
-		_td.style.cursor = "pointer";
-		if(_option1)
-			_td.style.border = '1px solid #f7f7f7';			
-		_td.onclick 	= function() { Element('menu_tools').style.visibility='hidden';eval(item[0]);};
-		_td.onmouseover = function () {
-			if(_timeout) {
-				clearTimeout(_timeout);
-				timeout=false;
-			}
-			
-			if(_option1)
-				set_menu_bg(this);
-			else {
-				this.style.textDecoration="underline";				
-				this.style.color = 'DARKORANGE';
-			}
-		};						
-		_td.onmouseout   = function () {
-			_timeout = setTimeout("_hideMenuTools();",500);
-			if(_option1){
-				unset_menu_bg(this);
-				unset_menu_bg(Element("link_tools"));
-			}else {		
-				this.style.backgroundColor = 'WHITE';
-				this.style.textDecoration="none";
-				this.style.color = 'DARKBLUE';
-			}
-		};		
-		_tr.appendChild(_td);
-		return _tr;
-	};
-	
-	for(i = 0; i < itens.length; i++)
-		_tbody.appendChild(buildTr(itens[i]));
-			
-	_t.appendChild(_tbody);
-	_divMenu.appendChild(_t);
-	document.body.appendChild(_divMenu);
-}
-
-function openListUsers(border_id) {
-	expresso.connector.loadScript("jscode/QuickCatalogSearch");
-	QuickCatalogSearch.showCatalogList(border_id);
-}
-
-function ConstructRightMenu(_event){
-
-	var div = Element("div_rightbutton");
-	if(!div){
-		div = document.createElement("DIV");
-		div.style.position = 'absolute';
-		div.style.zIndex = '15';
-
-		div.style.border = '1px outset BLACK';
-		div.style.background = "#EEEEE6";
-		div.id = 'div_rightbutton';
-		div.style.padding = "1px";
-		div.style.fontSize = is_ie || is_gecko1_5 || is_win ? "9pt" : "11pt";
-		div.style.width = "190px";
-		div.style.height = is_win && !is_ie ? "129px" : "139px";
-		div.style.display ='none';		
-		document.body.appendChild(div);
-		var _tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
-		var _sep = "<hr>";
-		var optionsMenu = new Array( 
-			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('seen')+'|'+"proxy_mensagens.proxy_set_messages_flag('seen','get_selected_messages')",
-			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('unseen')+'|'+"proxy_mensagens.proxy_set_messages_flag('unseen','get_selected_messages')",
-			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('important')+'|'+"proxy_mensagens.proxy_set_messages_flag('flagged','get_selected_messages')",
-			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('normal')+'|'+"proxy_mensagens.proxy_set_messages_flag('unflagged','get_selected_messages')",
-			_sep,
-			_tab + get_lang("Move to")+" ... |wfolders.makeWindow('', 'move_to')",
-			_tab + get_lang("Delete")+"|"+"proxy_mensagens.delete_msgs('null','selected','null')",
-			_tab + get_lang("Export")+"|"+"proxy_mensagens.export_all_messages()"
-		);
-
-		for(i = 0; i < optionsMenu.length; i++){
-			optionsMenu_l = optionsMenu[i].split('|');
-			var div_l = document.createElement("DIV");
-			div_l.style.padding = "1px";
-			div_l.style.width = "188px";
-			div_l.style.cursor = 'pointer';			
-			div_l.innerHTML = optionsMenu_l[0];
-			div_l.style.valign = 'top';
-			if(optionsMenu_l[0] != _sep) {
-				var attr = document.createAttribute('javascript');
-				attr.value = optionsMenu_l[1]+";Element('div_rightbutton').style.display = 'none';";
-				div_l.setAttributeNode(attr);
-				div_l.oncontextmenu = function(e) {	return false;};
-				div_l.onclick = function () {this.onmouseout();eval(this.getAttribute('javascript'));};
-				div_l.onmouseover = function () {this.style.color = 'WHITE';this.style.background = "#4a79cd";};
-				div_l.onmouseout = function ()  {this.style.color = 'BLACK';this.style.background = "#EEEEE6";};
-			}
-			else
-				div_l.style.height = "11px";
-				
-			div_l.id="link_rightbutton_"+i;
-			div.appendChild(div_l);
-		}
-	
-	}
-
-	var x = _event.clientX + document.body.scrollLeft +  2;
-	var y =  _event.clientY + document.body.scrollTop +  2;
-
-	var w_width  = is_ie ? document.body.clientWidth : window.innerWidth;
-	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
-
-	if(x + 218 > w_width)
-		div.style.left = w_width - (is_ie ? 198 : 218);	
-	else
-		div.style.left = x;
-	
-	if(y + 131 > w_height)
-		div.style.top =  w_height - (is_ie ? 125 : 131);	
-	else
-		div.style.top = y;	
-
-	div.style.display ='';
-} 
-
-function ConstructBoxMenu(_event,boxName,boxFolder){
-
-	var div = Element("div_rightbutton_folder");
-		if (div)
-			div.parentNode.removeChild(div);
-	
-		div = document.createElement("DIV");
-		div.style.position = 'absolute';
-		div.style.zIndex = '15';
-
-		div.style.border = '1px outset BLACK';
-		div.style.background = "#EEEEE6";
-		div.id = 'div_rightbutton_folder';
-		div.style.padding = "1px";
-		div.style.fontSize = is_ie || is_gecko1_5 || is_win ? "9pt" : "11pt";
-		div.style.width = "190px";
-		div.style.height = is_win && !is_ie ? "35px" : "33px";
-		div.style.display ='none';		
-		document.body.appendChild(div);
-		var _tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
-		var _sep = "<hr>";
-		var optionsMenu = new Array( 
-			_tab + get_lang("Open in new tab")+'|'+"open_folder('"+boxFolder+"', '"+boxName+"')",
-			_tab + get_lang("Edit folders")+'|'+"folderbox()"
-		);
-
-		for(i = 0; i < optionsMenu.length; i++){
-			optionsMenu_l = optionsMenu[i].split('|');
-			var div_l = document.createElement("DIV");
-			div_l.style.padding = "1px";
-			div_l.style.width = "188px";
-			div_l.style.cursor = 'pointer';			
-			div_l.innerHTML = optionsMenu_l[0];
-			div_l.style.valign = 'top';
-			if(optionsMenu_l[0] != _sep) {
-				var attr = document.createAttribute('javascript');
-				attr.value = optionsMenu_l[1]+";Element('div_rightbutton_folder').style.display = 'none';";
-				div_l.setAttributeNode(attr);
-				div_l.oncontextmenu = function(e) {	return false;};
-				div_l.onclick = function () {this.onmouseout();eval(this.getAttribute('javascript'));};
-				div_l.onmouseover = function () {this.style.color = 'WHITE';this.style.background = "#4a79cd";};
-				div_l.onmouseout = function ()  {this.style.color = 'BLACK';this.style.background = "#EEEEE6";};
-			}
-			else
-				div_l.style.height = "11px";
-				
-			div_l.id="link_rightbutton_folder"+i;
-			div.appendChild(div_l);
-		}
-
-	var x = _event.clientX + document.body.scrollLeft +  2;
-	var y =  _event.clientY + document.body.scrollTop +  2;
-
-	var w_width  = is_ie ? document.body.clientWidth : window.innerWidth;
-	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
-
-	if(x + 218 > w_width)
-		div.style.left = w_width - (is_ie ? 198 : 218);	
-	else
-		div.style.left = x;
-	
-	if(y + 131 > w_height)
-		div.style.top =  w_height - (is_ie ? 125 : 131);	
-	else
-		div.style.top = y;	
-
-	div.style.display ='';
-};
Index: trunk/expressoMail1_2/js/jscode/DropDownContacts.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/DropDownContacts.js	(revision 2895)
+++ 	(revision )
@@ -1,344 +1,0 @@
-/**********************************************************************************\
-* Written by Joao Alfredo Knopik Junior (JakJr) <joao.alfredo@gmail.com>          *
-* ------------------------------------------------------------------------------- *
-*  This program is free software; you can redistribute it and/or modify it        *
-*  under the terms of the GNU General Public License as published by the	      *
-*  Free Software Foundation; either version 2 of the License, or (at your option) * 
-*  any later version.                                                             *
-\**********************************************************************************/
-// variavel global que salva o contato atual selecionado.
-var actualSelectedContact = 0;
-var setTimeOutLayer = 0;
-var div_message_scroll = 0;
-var tst_i = 0;
-function search_contacts(key_pressed, fld_id)
-{
-	div_message_scroll = Element('div_message_scroll_'+ fld_id.substring(fld_id.length - 1, fld_id.length));
-
-	var string_contacts = contacts;
-	if (Element(fld_id))
-		var mail = Element(fld_id).value;
-	else
-		return;
-	
-	var array_contacts = string_contacts.split(",");
-	var tmp = mail.split(",");
-	mail = trim(tmp[tmp.length - 1]);
-	tmp_mail = mail;
-	
-	seekDot = /\./gi;
-	mail = mail.replace(seekDot, "[.]");
-	mail = mail.replace('"', "&quot;");
-	mail = mail.replace("\n", "");
-	mail = mail.replace("\r", "");
-	mail = mail.replace("\t", "");
-	posX = findPosX(document.getElementById(fld_id));
-	posY = findPosY(document.getElementById(fld_id));
-
-	if ((!string_contacts) || (string_contacts.length==0) || (mail.length==0)){
-		hideTip();
-		return;
-	}
-		
-	if (mail.length == 0){
-		hideTip();
-		return;
-	}
-	
-	var RegExp_name = new RegExp("\\b"+mail, "i");
-	var RegExp_mail = new RegExp("^"+mail, "i");
-
-	var match_contacts = new Array();
-	var match_index = 0;
-
-	for (var i=0; i<array_contacts.length; i++){
-		tmp = array_contacts[i].split(";");
-		if ( (RegExp_name.test(tmp[0])) || (RegExp_mail.test(tmp[1])) ){
-			if (tmp[1])
-			{
-				var _tmp1 = RegExp_mail.exec(tmp[1]);
-				if ( _tmp1 )
-					tmp[1] = tmp[1].replace(RegExp_mail, _tmp1[0].bold());
-				var _tmp0 = RegExp_name.exec(tmp[0]);
-				if ( _tmp0 )
-					tmp[0] = tmp[0].replace(RegExp_name, _tmp0[0].bold());
-				match_contacts[match_index] = '&quot;' + tmp[0] + '&quot; &lt;' + tmp[1] + '&gt;';
-				match_index++;
-			}
-		}
-	}
-
-	if (match_contacts.length == 0){
-		hideTip();
-		return;
-	}
-
-	var lines = document.createElement('TABLE');
-	lines.style.fontFamily='Arial';
-	lines.style.font='12pt';
-	lines.style.color='#0000CF';
-	lines.border='0';
-	lines.cellpadding='0';
-	lines.cellspacing='0';
-
-	var match_cont = "";
-	for (var i=0; i<match_contacts.length; i++)
-	{
-		match_contacts[i] = unescape(match_contacts[i]); 
-		match_cont += match_contacts[i];
-
-		var trElement = document.createElement('TR');
-		var tdElement = document.createElement('TD');
-		tdElement.id = 'td_DD_'+i;
-		tdElement.name = fld_id;
-		XEvents.add( tdElement, 'onmousedown', function ( )
-		{
-			hideTip();
-			makeMailList(this.innerHTML,this.name);
-			setTimeout('document.getElementById("'+this.name+'").focus()',300);
-		} );
-		XEvents.add( tdElement, 'onmouseover', function( )
-		{
-			selectContact(this.id.substr(6));
-		} );
-		tdElement.innerHTML = match_cont;
-		trElement.appendChild(tdElement);
-		lines.appendChild(trElement);
-		match_cont = "";
-	}
-
-	// treat especials keys
-	// key ENTER
-	if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility))
-	{
-		//Bug, sometimes the actualSelectedContact do not exist.
-		try{
-			makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id);
-			hideTip();
-		}
-		catch(e){}
-		return;
-	}
-	// key lostfocus
-	if ((key_pressed == 'lostfocus') && (document.getElementById('tipDiv').style.visibility)){
-		hideTip();
-		return;
-	}
-	// key DOWN
-	if ((key_pressed == 40) && (document.getElementById('tipDiv').style.visibility)){
-		if (actualSelectedContact != (match_contacts.length - 1)){
-			selectContact(actualSelectedContact + 1);
-		}
-		return;
-	}
-	// key UP
-	if ((key_pressed == 38) && (document.getElementById('tipDiv').style.visibility)){
-		if (actualSelectedContact != 0){			
-			selectContact(actualSelectedContact - 1);
-			return;
-		}
-	}
-	if (lines.childNodes.length > 0){
-		doTooltip(posX, posY, lines);
-	}
-	else
-		hideTip();
-		
-	return true;
-}
-
-function makeMailList(mail,fld_id)
-{
-	list = Element(fld_id);
-	for (var i = list.value.length; ((i!=0) && (list.value.substring(i-1,i)!=',')); i--) {  };
-	mail = mail.replace(/&lt;/g,"<");
-	mail = mail.replace(/&gt;/g,">");
-	mail = mail.replace(/<[bB]>/g,"");
-	mail = mail.replace(/<\/[bB]>/g,"");
-	if (i == 0)
-		list.value = list.value.substring(0,i) + mail + ', ';
-	else
-		list.value = list.value.substring(0,i) + ' ' + mail + ', ';
-}
-
-function selectContact(newContact){	
-	//Desabilitar o atual
-	var elAtual = document.getElementById('td_DD_' + actualSelectedContact);
-	if(elAtual)
-		elAtual.bgColor = "#efefef";	
-		
-	//Habilitar o novo.		
-	var elNew = document.getElementById('td_DD_' + newContact).bgColor = "#c0e0ff";
-	if(elNew)
-		elNew.bgColor = "#c0e0ff";
-
-	actualSelectedContact = newContact;
-}
-
-function doTooltip(x,y,msg) {
-	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
-	Tooltip.show(x,y,msg);
-}
-
-function hideTip() {
-	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
-	actualSelectedContact=0;
-	Tooltip.hide();
-}
-
-function findPosX(obj)
-{
-	var curleft = 0;
-	if (obj.offsetParent)
-	{
-		while (obj.offsetParent)
-		{
-			curleft += obj.offsetLeft;
-			obj = obj.offsetParent;
-		}
-	}
-	else if (obj.x)
-		curleft += obj.x;
-	return curleft;
-}
-
-function findPosY(obj)
-{
-	var curtop = 0;
-	if (obj.offsetParent)
-	{
-		while (obj.offsetParent)
-		{
-			curtop += obj.offsetTop;
-			obj = obj.offsetParent;
-		}
-	}
-	else if (obj.y)
-		curtop += obj.y;
-	return curtop;
-}
-
-function trim(inputString) {
-   if (typeof inputString != "string") 
-   	return inputString;
-      
-   var retValue = inputString;
-   var ch = retValue.substring(0, 1);
-   while (ch == " ") { 
-	  retValue = retValue.substring(1, retValue.length);
-	  ch = retValue.substring(0, 1);
-   }
-   ch = retValue.substring(retValue.length-1, retValue.length);
-   while (ch == " ") { 
-	  retValue = retValue.substring(0, retValue.length-1);
-	  ch = retValue.substring(retValue.length-1, retValue.length);
-   }
-   while (retValue.indexOf("  ") != -1) { 
-	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
-   }
-   return retValue; 
-}
-
-var Tooltip = {
-    overlaySelects: true,  // iframe shim for select lists (ie win)
-    offX: 0,
-    offY: 50,
-    tipID: "tipDiv",
-    showDelay: 0,
-    hideDelay: 0,
-    
-    ovTimer: 0, // for overlaySelects
-    ready:false, timer:null, tip:null, shim:null, supportsOverlay:false,
-  
-    init: function() {
-			if ( document.getElementById( this.tipID ) == null )
-			{
-				var el_dropdowncontact = document.createElement("DIV");
-				el_dropdowncontact.id = this.tipID;
-				document.body.appendChild(el_dropdowncontact);
-				this.supportsOverlay = this.checkOverlaySupport();
-				this.ready = true;
-			}
-    },
-    
-    show: function(x, y, msg) {
-        this.tip = document.getElementById( this.tipID );
-        this.writeTip(msg);
-        
-        this.positionTipStatic(x,y);
-   		this.handleOverlay(1, this.showDelay, x+this.offX,y+this.offY);
-		document.getElementById('td_DD_0').bgColor = "#c0e0ff";
-      	this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);
-    },
-    
-    writeTip: function(msg) {
-        if ( typeof this.tip != "undefined" ) {
-		this.tip.innerHTML = "";
-		this.tip.appendChild(msg);
-	}
-        this.tip.style.width = 'auto';
-    },
-    
-    positionTipStatic: function(x,y) {
-        if ( this.tip && this.tip.style ) {
-			this.tip.style.left = x + this.offX + "px";
-			this.tip.style.top = y + this.offY + "px";
-        }
-     },
-
-	scrollChanged: function() {
-		Element('tipDiv').style.visibility = 'hidden';
-		Tooltip.hide();
-	},
-
-    hide: function() {
-        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
-		this.handleOverlay(0, this.hideDelay);
-        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);
-        this.tip = null;  
-    },
-    
-  toggleVis: function(id, vis) { // to check for el_dropdowncontact, prevent (rare) error
-      var el_dropdowncontact = document.getElementById(id);
-      if (el_dropdowncontact) el_dropdowncontact.style.visibility = vis;
-  },
-
-	// check need for and support of iframe shim
-	checkOverlaySupport: function() {
-		return (is_ie);
-	}, 
-    
-	handleOverlay: function(bVis, d, x ,y) {
-		var _scrollY = div_message_scroll ? div_message_scroll.scrollTop : 0;
-        if(_scrollY > 0 && this.tip) {
-	        this.tip.style.top = (findPosY(this.tip) - _scrollY)+ "px";
-	    }
-		if ( this.overlaySelects && this.supportsOverlay ) {
-			if (this.ovTimer) { clearTimeout(this.ovTimer); this.ovTimer = 0; }
-			switch (bVis) {
-			case 1 :
-				if ( !document.getElementById('tipShim') ) 
-					document.body.insertAdjacentHTML("beforeEnd", '<iframe id="tipShim" src="about:blank" style="position:absolute; left:' + x + '; top:' + y + '; z-index:500; visibility:hidden" scrolling="no" frameborder="0"></iframe>');
-					this.shim = document.getElementById('tipShim'); 
-					if (this.shim && this.tip) {
-						this.shim.style.width = this.tip.offsetWidth + "px";
-                        this.shim.style.height = this.tip.offsetHeight + "px";
-                        this.shim.style.top = findPosY(this.tip)+ "px";
-					}
-					this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'visible')", d);
-				break;
-			case 0 :
-				this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'hidden')", d);
-				if (this.shim) this.shim = null;
-				break;
-			}
-		}
-	}
-};
-// Criar um estilo no html (tpl) com os seguintes parametros:
-//div#tipDiv {
-//  position:absolute; visibility:hidden; left:0; top:0; z-index:10000;
-//  background-color:#EFEFEF; border:1px solid #337;
-//  width:220px; padding:3px;
-//  color:#000; font-size:11px; line-height:1.2;
-//  cursor: default;
Index: trunk/expressoMail1_2/js/base/draw_api_folders.js
===================================================================
--- trunk/expressoMail1_2/js/base/draw_api_folders.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/draw_api_folders.js	(revision 3073)
@@ -0,0 +1,1419 @@
+
+
+var lastPage = 1;
+var numPages = 5;
+var last_folder = 'INBOX';
+
+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_header_box(){
+	switch(sort_box_type){
+		case 'SORTFROM':
+			type_name = get_lang("Who");
+			break;
+		case 'SORTSUBJECT':
+			type_name = get_lang("Subject");
+			break;
+		case 'SORTARRIVAL':
+			type_name = get_lang("Date");
+			break;
+		case 'SORTSIZE':
+			type_name = get_lang("Size");
+			break; 
+		default:
+			type_name = get_lang("Date");
+			break;
+	}
+	document.getElementById("_msgheadSORTFROM_"+numBox).innerHTML 	= get_lang("Who");
+	document.getElementById("_msgheadSORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
+	document.getElementById("_msgheadSORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
+	document.getElementById("_msgheadSORTSIZE_"+numBox).innerHTML	= get_lang("Size");	
+	var elHead = document.getElementById("_msghead"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox );
+	if(elHead != null)
+		elHead.innerHTML = "<B>"+type_name+'</B><img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/arrow_'+(sort_box_reverse == 1 ? 'desc' : 'asc')+'endant.gif">';
+}
+
+function draw_search_header_box(){
+	var _tbl_msghead_bx = Element("_tbl_msghead_bx");
+	_tbl_msghead_bx.parentNode.removeChild(_tbl_msghead_bx);
+
+	var content_id_0 = Element("content_id_0");
+	var table_element = document.createElement("TABLE");
+	var tbody_element = document.createElement("TBODY");
+	table_element.setAttribute("id", "_tbl_msghead_bx");
+	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  = "chkbox_sel_allmsg";
+	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 = "_msgheadSORTFROM";
+	td_element3.align = "left";
+	td_element3.innerHTML = get_lang("From");
+	td_element4 = document.createElement("TD");
+	td_element4.setAttribute("width", "49%");
+	td_element4.id = "_msgheadSORTSUBJECT";
+	td_element4.align = "left";
+	td_element4.innerHTML = get_lang("Subject");
+	td_element5 = document.createElement("TD");
+	td_element5.setAttribute("width", "10%");
+	td_element5.id = "_msgheadSORTARRIVAL";
+	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 = "_msgheadSORTSIZE";
+	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);
+}
+
+function build_quota(data){
+	id = "content_quota";
+	q_limit = data['quota_limit']*1024;
+	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']*1024;
+			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+"% ("+borkb(q_used)+"/"+borkb(q_limit)+")</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.draw_newBox(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.draw_newBox(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.draw_newBox(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.
+	if ( ! Element( 'dftree_tree_folders' ) )
+	{
+		translatedFolders = new Map( );
+		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' && ( ! 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 );
+			}
+		}
+
+		/**
+		 * 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 ) ) != 'function' )
+				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' );
+
+		var folder_img = URL_SERVER + "phpgwapi/templates/" +template + "/images/foldertree_";
+
+		if ( trash_span )
+			trash_span.style.backgroundImage = "url(" + folder_img + "trash.png)";
+
+		if ( draft_span )
+			draft_span.style.backgroundImage = "url(" + folder_img + "draft.png)";
+
+		if ( sent_span )
+			sent_span.style.backgroundImage = "url(" + folder_img + "sent.png)";
+
+		if ( spam_span )
+			spam_span.style.backgroundImage = "url(" + folder_img + "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 );
+		}
+
+		if ( ! expresso_offline )
+			var _disp_unseen_mb = tree_folders.getNodeById( 'root' );
+		else
+			var _disp_unseen_mb = tree_folders.getNodeById( 'local_root' );
+
+		_disp_unseen_mb.alter( {
+			"caption" : get_lang( "My Folders" )
+		} );
+
+		_disp_unseen_mb._refresh( );
+
+		var _dip_unseen_shardfolder = tree_folders.getNodeById( 'user' );
+
+		if ( _dip_unseen_shardfolder )
+		{
+			if ( unseen_in_shared_folders )
+				_dip_unseen_shardfolder.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
+				_dip_unseen_shardfolder.alter( {
+					"caption" : get_lang( "Shared folders" )
+				} );
+
+			_dip_unseen_shardfolder._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 );
+			}
+		}
+	}
+
+	Element( 'main_table' ).style.display = '';
+	draw_box.prepare_box( false );
+	resizeWindow( );
+}
+
+
+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.draw_newBox( expresso.connector.unserialize( data ), 'INBOX', true);
+//alternate_border(0);
+};
+
+// Action on change folders.
+function change_folder(folder, folder_name){
+    alternate_border(numBox);
+    if (openTab.imapBox[numBox] != folder)
+    {
+	current_folder = folder;
+	draw_box.prepare_box(true);
+	Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">0</span> / <span id="tot_m">0</span>]</font>';
+	var handler_draw_box = function(data)
+	{
+		draw_box.headers_msgs = data;
+		draw_box.draw_box_messages(data, folder, true);
+		draw_paging(data.num_msgs);
+		Element("tot_m").innerHTML = data.num_msgs;
+		Element("new_m").innerHTML = '<font style="color:'+(data.num_unseen > 0 ? 'red': '')+'">' + data.num_unseen + '</font>';
+		folder_unseen = Element('dftree_'+current_folder+'_unseen');
+		var num_unseen = data.num_unseen;
+		if (folder_unseen)
+			num_unseen -= folder_unseen.innerHTML;
+		increment_folder_unseen(num_unseen);
+		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);
+    }
+}
+
+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.draw_newBox(data, current_folder);
+	    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.headers_msgs = data;
+	draw_box.draw_box_messages(current_folder);
+
+	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;
+
+    draw_box.prepare_box(true);
+    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)
+{
+	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 = createAndSet("TD",['class','width'],['td_msg','1%']);
+	_chkbox = createAndSet("INPUT", ['type','class','id'], ['checkbox','checkbox',"check_box_message_"+headers_msgs.msg_number]);
+	_chkbox.onclick = function(e){
+		if (is_ie)
+			changeBgColor(window.event,headers_msgs.msg_number);
+		else
+			changeBgColor(e,headers_msgs.msg_number);
+	};
+	td_element1.appendChild(_chkbox);
+
+	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=0; item < attach_name.length; item++)
+		{
+			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 = '';
+	}
+	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;
+
+	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' || (parseInt(preferences.use_important_flag) && headers_msgs.Importance.toLowerCase().indexOf("high") != -1))
+	{
+		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 images
+	var _img_sent = new Image();
+	_img_sent.src 	= URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/sent.gif';
+	var _img_unseen = new Image();
+	_img_unseen.src = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/unseen.gif';
+
+	var td_element25 = document.createElement("TD");
+	td_element25.className = "td_msg";
+	td_element25.setAttribute("width", "1%");
+	td_element25.id = "td_message_unseen_"+headers_msgs.msg_number;
+	if ((headers_msgs.Unseen == 'U') || (headers_msgs.Recent == 'N'))
+		td_element25.innerHTML = "<img src ='"+_img_unseen.src+"' title='"+get_lang('Unseen')+"'>";
+	else
+		td_element25.innerHTML = "<img src ='"+URL_SERVER +"expressoMail1_2/templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
+
+	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_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 && 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");
+	var norm = function (arg) {return (arg < 10 ? '0'+arg : arg);};
+	var weekDays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
+	var date_msg = new Date(headers_msgs.udate*1000);
+	var today = new Date();
+	if (today.getTime() - date_msg.getTime() < 86400000)
+		td_element5.innerHTML = norm(date_msg.getHours()) + ':' + norm(date_msg.getMinutes());
+	else
+		if (today.getTime() - date_msg.getTime() < 172800000)
+			td_element5.innerHTML = get_lang('Yesterday');
+		else
+			if (today.getTime() - date_msg.getTime() < 259200000)
+				td_element5.innerHTML = get_lang(weekDays[date_msg.getDay()]);
+			else
+				td_element5.innerHTML = norm(date_msg.getDate()) + '/' + norm(date_msg.getMonth()+1) + '/' +date_msg.getFullYear();
+	td_element5.title = norm(date_msg.getDate()) + '/' + norm(date_msg.getMonth()+1) + '/' +date_msg.getFullYear();
+	td_element5.alt = td_element5.title;
+
+	td_element6 = document.createElement("TD");
+	td_element6.className = "td_msg";
+	td_element6.setAttribute("width", "14%");
+	td_element6.setAttribute("noWrap","true");
+	td_element6.setAttribute("align", "center");
+	td_element6.onclick = _onclick;
+
+	td_element6.innerHTML = borkb(headers_msgs.Size);
+
+	return appendChilds(tr_element,td_element1,td_element2,td_element21,td_element22,td_element23,td_element24,td_element25,td_element3,td_element4,td_element5,td_element6);
+}
+function draw_folder(){
+}
+
+draw_folder.prototype.draw_newBox = function(headers_msgs,msg_folder,alternate){
+	this.headers_msgs = headers_msgs;
+	this.prepare_box( alternate );
+	this.draw_box_messages(headers_msgs,msg_folder);
+};
+
+draw_folder.prototype.prepare_box = function(alternate){
+	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.type[numBox] = 0;
+	_tbl_msghead_bx = Element("_tbl_msghead_bx_"+numBox);
+	if (_tbl_msghead_bx == null){
+		var table_element = document.createElement("TABLE");
+		table_element.setAttribute("id", "_tbl_msghead_bx_"+numBox);
+		table_element.setAttribute('class',  "table_message_header_box");
+
+		var tbody_element = document.createElement("TBODY");
+
+		tr_element = createAndSet("TR",['class'],['message_header']);
+		td_element1 = createAndSet("TD",['width'],['1%']);
+		_chkbox_element = createAndSet("INPUT",['id','type','class'],["chkbox_sel_allmsg","checkbox","checkbox"]);
+		_chkbox_element.onclick = function(){
+			select_all_messages(this.checked);
+		};
+		_chkbox_element.onmouseover = function () {
+			this.title=get_lang('Select all messages.');
+		};
+		_chkbox_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(_chkbox_element);
+
+		td_element2 = document.createElement("TD");
+		td_element2.setAttribute("width", "7%");
+		td_element3 = createAndSet("TD",['width','id','align'],['29%',"_msgheadSORTFROM_"+numBox,'left'],get_lang("Who"));
+		td_element3.onclick = function () {
+			sort_box(search_box_type,'SORTFROM');
+		};
+		td_element4 = createAndSet("TD",['width','id','align'],['38%',"_msgheadSORTSUBJECT_"+numBox,"left"],get_lang("Subject"));
+		td_element4.onclick = function () {
+			sort_box(search_box_type,'SORTSUBJECT');
+		};
+		td_element5 = createAndSet("TD",['width','id','align'],["14%","_msgheadSORTARRIVAL_"+numBox,"center"],get_lang("Date"));
+		td_element5.onclick = function () {
+			sort_box(search_box_type,'SORTARRIVAL');
+		};
+		td_element6 = createAndSet("TD",['width','id','align'],["14%","_msgheadSORTSIZE_"+numBox,"left"],get_lang("Size"));
+		td_element6.onclick = function () {
+			sort_box(search_box_type,'SORTSIZE');
+		};
+		appendChilds(tr_element,td_element1,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;";
+
+		tbody_element.appendChild(appendChilds(tr_element,td_element21,td_element22,td_element23,td_element3,td_element4,td_element5,td_element6));
+		table_element.appendChild(tbody_element);
+		openTab.content_id[numBox].appendChild(table_element);
+	}
+	draw_header_box();
+	var _divScroll = document.getElementById("divScrollMain_"+numBox);
+	if(!_divScroll){
+		_divScroll = document.createElement("DIV");
+		_divScroll.id = "divScrollMain_"+numBox;
+	}
+
+	_divScroll.style.overflowY = "auto";
+	_divScroll.style.overflowX = "hidden";
+	_divScroll.style.width	="100%";
+
+	var _t_element = createAndSet("TABLE",['id','class','borderColorDark','frame','rules','cellPadding','cellSpacing'],["table_box","table_box","#bbbbbb","void","rows","0","0"]);
+	_t_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)
+		_t_element.style.cursor = "hand";
+
+	var _tbody_element = document.createElement("TBODY");
+	_tbody_element.setAttribute("id", "tbody_box");
+	_t_element.appendChild(_tbody_element);
+
+        _divScroll.appendChild(_t_element);
+
+	openTab.content_id[numBox].appendChild(_divScroll);
+	if (alternate)
+		_divScroll.appendChild(loading_img);
+};
+
+draw_folder.prototype.draw_box_messages = function(msg_folder){
+	openTab.content_id[numBox] = document.getElementById("content_id_"+numBox);
+	var _divScroll = document.getElementById("divScrollMain_"+numBox);
+	try{
+		loading_img = _divScroll.removeChild( loading_img );
+	}
+	catch(e){ }
+	var tbody_element = _divScroll.firstChild.firstChild;
+
+	var f_unseen = 0;
+	openTab.imapBox[numBox] = msg_folder;
+	if (this.headers_msgs.num_msgs == 0){
+		var tr_info = document.createElement("TR");
+		var td_info = createAndSet("TD",['colspan','background','align','style'],
+				['10','#FFF','center','padding-top: 25px;font-weight:bold;font-size:11pt;'],get_lang("This mail box is empty"));
+		tr_info.setAttribute("id", "msg_info");
+		tr_info.appendChild(td_info);
+		tbody_element.appendChild(tr_info);
+	}
+
+
+	for (var i=0; i < this.headers_msgs.length; i++){
+		if ((this.headers_msgs[i].Unseen == 'U') || (this.headers_msgs[i].Recent == 'N'))
+			f_unseen++;
+		tr_element = make_tr_message(this.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');
+		}
+		if ( _dragArea == null )
+			_dragArea = new DragArea( );
+		_dragArea.makeDragged(tr_element, this.headers_msgs[i].msg_number, this.headers_msgs[i].subject, true);
+	}
+
+	if ((preferences.use_shortcuts == '1') && (this.headers_msgs[0]))
+		select_msg(this.headers_msgs[0].msg_number, 'null', true);
+
+	var tdFolders  =  Element("folderscol");
+	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
+	draw_footer_box(this.headers_msgs.num_msgs);
+	Element('main_table').style.display = '';
+	resizeWindow();
+	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){
+		proxy_mensagens.get_msg(this.headers_msgs, url_encode(msg_folder),true, show_msg);
+		Element('msg_folder').value = '';
+		Element('msg_number').value = '';
+	}
+
+
+	var scripts = new Array("jscode/InfoContact",
+			"jscode/messages_controller",
+			"jscode/local_messages",
+			"jscode/draw_api_messages",
+			"jscode/draw_messages");
+	expresso.connector.loadAllScripts(scripts);
+
+	// Loading Quota View Folder Component (if exists...)
+	if(Element("table_quota"))
+		expresso.connector.loadScript("jscode/InfoQuota");
+	alternate_border(numBox);
+};
+
+function draw_footer_box(num_msgs){
+	folder = get_current_folder();
+	var span_R = Element("table_message");	
+	var span_options = Element("span_options");	
+	if(!span_options) {
+		span_options = document.createElement("TD");	
+		span_options.style.fontSize = "12";
+		span_options.id = "span_options";
+		span_R.appendChild(span_options);
+	}
+
+	var change_font_color = 'onmouseover="var last_class = this.className;'+
+		'if (this.className != \'message_options_over\')'+
+				'this.className=\'message_options_active\'; '+
+				'this.onmouseout=function(){this.className=last_class;}"';
+
+				span_options.innerHTML =
+				'<span class="message_options_trash"><span ' + change_font_color + ' title="'+get_lang("Delete")+'" class="message_options" onclick=proxy_mensagens.delete_msgs(\'null\',\'selected\',\'null\')>'+get_lang("Delete")+'</span></span>'+
+				'<span class="message_options_move"><span ' + change_font_color + ' title="'+get_lang("Move")+'" class="message_options" onclick=wfolders.makeWindow(\"\",\"move_to\")>'+get_lang("Move")+'</span></span>'+
+				((expresso_offline)?" ":'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>')+
+				//		'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>'+
+				((expresso_offline)?" ":'<span class="message_options_export"><span ' + change_font_color + ' title="'+get_lang("Export")+'" class="message_options" onclick="proxy_mensagens.export_all_messages()">'+get_lang("Export")+'</span></span>') +
+				((expresso_offline)?" ":'<span class="message_options_import"><span ' + change_font_color + ' title="'+get_lang("Import")+'" class="message_options" onclick="import_window()">'+get_lang("Import")+'</span></span>');
+				if(preferences.use_local_messages==1 && !expresso_offline)
+				if(proxy_mensagens.is_local_folder(current_folder))
+				span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
+				else
+				span_options.innerHTML += '&nbsp; <span title="'+get_lang("Archive")+'" class="message_options" onclick="archive_msgs(\''+folder+'\',null)">'+get_lang("Archive")+'</span>';
+				if (use_spam_filter) {
+				if ( current_folder == 'INBOX'+cyrus_delimiter+'Spam' )	{
+				span_options.innerHTML += ' | <span ' + change_font_color + ' title="'+get_lang("Not Spam")+'" class="message_options" onclick="nospam(\'selected\',\'null\',\'null\')">'+get_lang("Not Spam")+'</span>';
+				}
+				else {
+					span_options.innerHTML += ' | <span ' + change_font_color + ' title="'+get_lang("Mark as Spam")+'" class="message_options" onclick="spam(\'null\', \'selected\',\'null\')">'+get_lang("Mark as Spam")+'</span>';
+				}
+				}
+				var span_D = Element("span_D");	
+				if(!span_D){
+					span_D = document.createElement("TD");	
+					span_D.align = "right";
+					span_D.style.fontSize = "12";
+					span_D.id = "span_D";
+					span_R.appendChild(span_D);
+				}
+				span_D.innerHTML = 
+					get_lang("List")+': '+
+					'<span ' + change_font_color + ' id="span_flag_SORTARRIVAL" class="'+(search_box_type == 'ALL' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("All")+'" onclick="if(\'ALL\' == \''+search_box_type+'\') return false;sort_box(\'ALL\',\''+sort_box_type+'\')">'+get_lang("All")+'</span>, '+
+					'<span ' + change_font_color + ' id="span_flag_UNSEEN" class="'+(search_box_type == 'UNSEEN' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_unseen")+'" onclick="if(\'UNSEEN\' == \''+search_box_type+'\') return false;sort_box(\'UNSEEN\',\''+sort_box_type+'\')">'+get_lang("l_unseen")+'</span>, '+
+					'<span ' + change_font_color + ' id="span_flag_SEEN" class="'+(search_box_type == 'SEEN' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_seen")+'" onclick="if(\'SEEN\' == \''+search_box_type+'\') return false;sort_box(\'SEEN\',\''+sort_box_type+'\')">'+get_lang("l_seen")+'</span>, '+
+					'<span ' + change_font_color + ' id="span_flag_ANSWERED" class="'+(search_box_type == 'ANSWERED' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_answered")+'" onclick="if(\'ANSWERED\' == \''+search_box_type+'\') return false;sort_box(\'ANSWERED\',\''+sort_box_type+'\')">'+get_lang("l_answered")+'</span>, '+
+					'<span ' + change_font_color + ' id="span_flag_FLAGGED" class="'+(search_box_type == 'FLAGGED' ? 'message_options_over' : 'message_options')+'" title="'+get_lang("l_important")+'" onclick="if(\'FLAGGED\' == \''+search_box_type+'\') return false;sort_box(\'FLAGGED\',\''+sort_box_type+'\')">'+get_lang("l_important")+'</span>&nbsp;&nbsp;';
+				draw_paging(num_msgs);
+				Element("tot_m").innerHTML = num_msgs;	
+};
+
+// Objeto Map, talvez o ideal fosse adicionar este objeto Ã  Api do egroupware, e carregÃ¡-lo
+// aqui no expressoMail.
+function Map()
+{
+	this.keys = new Array();
+	this.values = new Array();
+}
+
+Map.prototype.add = function(key, value)
+{
+	this.keys.push(key);
+	this.values.push(value);
+};
+
+Map.prototype.get = function(key)
+{
+	result = new Array();
+	for (i = 0; i < this.keys.length; i++)
+	{
+		if (this.keys[i] == key)
+		{
+			result.push(this.values[i]);
+		}
+	}
+
+	if (result.length == 0)
+	{
+		return null;
+	}
+
+	return result;
+};
+
+var translatedFolders = new Map();
+
+
+draw_box = new draw_folder();
Index: trunk/expressoMail1_2/js/base/main.js
===================================================================
--- trunk/expressoMail1_2/js/base/main.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/main.js	(revision 3073)
@@ -0,0 +1,2567 @@
+// Tempo do auto refresh (em milisegundos)
+var time_refresh = 300000;
+// tempo do auto save (em milisegundos)
+// 20000 = 20 segundos
+var autosave_time = 20000;
+
+function init(){
+	BordersArray[0] = new setBorderAttributes(0);
+	wfolders = new cWFolders();
+
+	current_folder = "INBOX";
+	if (!is_ie)
+		if ( Element('tableDivAppbox') )
+			Element('tableDivAppbox').width = '100%';
+	
+	var save_contacts = function(data){
+		contacts = expresso.connector.unserialize( data );
+		if (preferences.use_local_messages == 1 && window.google && google.gears) 
+			if (expresso_local_messages.is_offline_installed()) 
+				expresso_local_messages.capt_url('controller.php?action=expressoMail1_2.db_functions.get_dropdown_contacts_to_cache');
+
+	};
+	var save_preferences = function(data)
+	{
+		preferences = data.JSON( );
+		_connector.cache();
+		_connector.go( {
+			"access" : "expressoMail1_2.imap_functions.get_range_msgs2&folder=INBOX&msg_range_begin=1&msg_range_end="
+						+ preferences.max_email_per_page + "&sort_box_type=SORTARRIVAL&search_box_type=ALL&sort_box_reverse=1",
+			"cache" : true,
+			"handler" : handler_draw_box
+		} );
+
+		if(preferences.hide_folders == "1")
+			Element('divAppboxHeader').innerHTML =  title_app_menu;
+		
+		if (preferences.delete_trash_messages_after_n_days != 0)
+			_connector.go( {
+				"access" : "expressoMail1_2.imap_functions.automatic_trash_cleanness&before_date="
+					+ preferences.delete_trash_messages_after_n_days + "&cyrus_delimiter=" + cyrus_delimiter,
+				"handler" : _hand_automtrash_clean
+			} );
+		
+		if(preferences.outoffice == "1")
+			write_msg(get_lang("Attention, you are in out of office mode."), true);
+
+		if ((preferences.use_local_messages==1) && (!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;
+			}
+		}
+		
+		ConstructMenuTools();
+
+		if (preferences.use_local_messages==1) {
+			expresso.connector.loadScript('jscode/mail_sync');
+			if (is_ie)
+				expresso.connector.loadScript('jscode/TreeShow');
+			setTimeout('auto_archiving()', 30000);
+			if (expresso_local_messages.is_offline_installed()) {
+				check_mail_in_queue();
+			}
+		}
+
+        // Insere a applet de criptografia
+        if (preferences.use_signature_digital_cripto == '1'){
+            loadApplet();
+        }
+        // Fim da inserção da applet
+
+		_connector.cache();
+		_connector.go( { //Save contacts needs preferences.
+			"access" : "expressoMail1_2.db_functions.get_dropdown_contacts",
+			"cache" : true,
+			"handler" : save_contacts
+		} );
+		_connector.cache();
+		_connector.go( {
+			"access" : "expressoMail1_2.imap_functions.get_folders_list&onload=true",
+			"cache" : true,
+			"handler" : function( data )
+			{
+				update_menu( expresso.connector.unserialize( data ) );
+			}
+		} );
+		
+	};
+	var _hand_automtrash_clean = function(data){
+		data = expresso.connector.unserialize( data );
+		if (data != false){
+			write_msg(data.length +' '+ Element('txt_clear_trash').value);
+		}
+	};
+	
+	// Versão
+	if ( Element('divAppboxHeader') )
+		Element('divAppboxHeader').innerHTML = title_app;
+	_connector.cache();
+	_connector.go( {
+		"access" : "expressoMail1_2.functions.get_preferences",
+		"handler" : save_preferences
+	} );
+	setTimeout('auto_refresh()', time_refresh);
+
+	refresh(preferences.alert_new_msg);
+}
+
+function init_offline(){
+	if (account_id != null) {
+		if (!is_ie) 
+			Element('tableDivAppbox').width = '100%';
+		else
+			expresso.connector.createXMLHTTP();
+		Element('divStatusBar').innerHTML = '<table height="16px" border=0 width=100% cellspacing=0 cellpadding=2>' +
+		'<tr>' +
+		'<td style="padding-left:17px" width=33% id="content_quota" align=left></td>' +
+		'<td width=33% height=16px align=center nowrap><font face=Verdana, Arial, Helvetica, sans-serif color=#000066 size=2>' +
+		'<b>ExpressoMail Offline</b><font size=1><b> - Versão 1.0</b></font></td>' +
+		'<td width=33% id="div_menu_c3" align=right></td>' +
+		'</tr></table>';
+			
+		ConstructMenuTools();
+
+		draw_tree_folders();
+				
+		proxy_mensagens.messages_list('local_Inbox', 1, preferences.max_email_per_page, 'SORTARRIVAL', null, 1,1,1, function handler(data){
+			draw_box.draw_newBox(data, 'local_Inbox');
+		});
+		
+		// Get cyrus delimiter
+	cyrus_delimiter = Element('cyrus_delimiter').value;
+	
+	cExecute ("expressoMail1_2.db_functions.get_dropdown_contacts_to_cache", function(data) {contacts = data;});
+	//cExecute ("expressoMail1_2.functions.get_preferences", save_preferences);
+	}
+}
+/**
+ * Carrega a applet java no objeto search_div
+ * @author Mário César Kolling <mario.kolling@serpro.gov.br>
+ */
+
+function loadApplet(){
+
+    var search_div = Element('search_div');
+    var applet = null;
+    if (navigator.userAgent.match('MSIE')){
+        applet = document.createElement('<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" ' +
+            'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"></object>');
+
+        //applet = document.createElement('object');
+        //var attributes = {
+        //    style:'display:yes;width:0;height:0;vertical-align:bottom;',
+        //    id:'cert_applet',
+        //    classid:'clsid:8AD9C840-044E-11D1-B3E9-00805F499D93'
+        //}
+
+        var parameters = {
+            type:'application/x-java-applet;version=1.5',
+            code:'ExpressoSmimeApplet',
+            codebase:'/security/',
+            mayscript:'true',
+            token: token_param,
+            locale: locale,
+            archive:'ExpressoCertMail.jar,' +
+                'ExpressoCert.jar,' +
+                'bcmail-jdk15-142.jar,' +
+                'mail.jar,' +
+                'activation.jar,' +
+                'bcprov-jdk15-142.jar,' +
+                'commons-codec-1.3.jar,' +
+                'commons-httpclient-3.1.jar,' +
+                'commons-logging-1.1.1.jar'
+            //debug:'true'
+        };
+
+        //for (var attribute in attributes){
+        //    applet.setAttribute(attribute, attributes[attribute]);
+        //}
+
+        if (parameters != 'undefined' && parameters != null){
+            for (var parameter in parameters) {
+                var param = document.createElement("PARAM");
+                param.setAttribute("name",parameter);
+                param.setAttribute("value",parameters[parameter]);
+                applet.appendChild(param);
+            }
+        }
+        search_div.appendChild(applet);
+        //alert(search_div.innerHTML);
+        //alert(window.);
+    }
+    else {
+        applet = document.createElement('embed');
+        applet.innerHTML = '<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" code="ExpressoSmimeApplet.class" ' +
+            'codebase="/security/" locale="'+locale+'"'+
+            'archive="ExpressoCertMail.jar,ExpressoCert.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar,commons-codec-1.3.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar" ' +
+            'token="' + token_param + '" ' +
+            'type="application/x-java-applet;version=1.5" mayscript > ' +
+            //'type="application/x-java-applet;version=1.5" debug="true" mayscript > ' +
+            '<noembed> ' +
+            'No Java Support. ' +
+            '</noembed> ' +
+            '</embed> ';
+        search_div.appendChild(applet);
+    }
+}
+
+function disable_field(field,condition) {
+	var comando = "if ("+condition+") { document.getElementById('"+field.id+"').disabled=true;} else { document.getElementById('"+field.id+"').disabled=false; }";
+	eval(comando);
+}
+/*
+	função que remove todos os anexos...
+*/
+function remove_all_attachments(folder,msg_num) {
+
+	var call_back = function(data) {
+		if(!data.status) {
+			alert(data.msg);
+		}
+		else {
+			msg_to_delete = Element(msg_num);
+			change_tr_properties(msg_to_delete, data.msg_no);
+			msg_to_delete.childNodes[1].innerHTML = "";
+			write_msg(get_lang("Attachments removed"));
+			delete_border(msg_num+'_r','false'); //close email tab
+		}
+	};
+	if (confirm(get_lang("delete all attachments confirmation")))
+		cExecute ("expressoMail1_2.imap_functions.remove_attachments&folder="
+				+folder+"&msg_num="+msg_num, call_back);
+}
+function watch_changes_in_msg(border_id)
+{
+	if (document.getElementById('border_id_'+border_id))
+	{	
+		function keypress_handler ()
+		{
+			away=false;
+			var save_link = Element("save_message_options_"+border_id);
+			save_link.onclick = function onclick(event) { openTab.toPreserve[border_id] = true; save_msg(border_id); } ;
+			save_link.className = 'message_options';
+		};
+		
+		var obj = document.getElementById('body_'+border_id).contentWindow.document;
+		if ( obj.addEventListener )
+				obj.addEventListener('keypress', keypress_handler, false);
+		else if ( obj.attachEvent )
+			obj.attachEvent('onkeypress', keypress_handler);
+			
+		var subject_obj = document.getElementById('subject_'+border_id);
+		if ( subject_obj.addEventListener )
+				subject_obj.addEventListener('keypress', keypress_handler, false);
+		else if ( subject_obj.attachEvent )
+			subject_obj.attachEvent('onkeypress', keypress_handler);
+			
+		var to_obj = document.getElementById('to_'+border_id);
+		if ( to_obj.addEventListener )
+				to_obj.addEventListener('keypress', keypress_handler, false);
+		else if ( to_obj.attachEvent )
+			to_obj.attachEvent('onkeypress', keypress_handler);
+		
+	}
+}
+
+function show_msg_img(msg_number,folder){
+    var call_back = function(data){
+       data.showImg = true;
+       var table_message = Element('table_message_'+data.msg_number+'_r');
+       var tbody_message = table_message.childNodes[0];
+       if(tbody_message.childNodes.length > 1)
+	       tbody_message.removeChild(tbody_message.lastChild);
+
+       if (!Element(data.msg_number)){
+	       trElement = document.createElement('DIV');
+	       trElement.id = data.msg_number;
+	       Element("tbody_box").appendChild(trElement);
+       }
+       show_msg(data);
+    };
+    for (var i=0; i < draw_box.headers_msgs.length; i++)
+	    if (draw_box.headers_msgs[i].msg_number == msg_number){
+		    var info_msg = draw_box.headers_msgs[i];
+		    break;
+	    }
+    proxy_mensagens.get_msg(info_msg,folder,null,call_back);
+}
+
+function show_msg(msg_info){
+	if (typeof(msg_info) != 'object')
+		alert(get_lang("Error in show_msg param is not object"));
+
+	if (msg_info.status_get_msg_info == 'false')
+	{
+		write_msg(get_lang("Problems reading your message")+ ".");
+		return;
+	}
+	var _hand_sendnotif = function(data){
+		if (data)
+			write_msg(get_lang("A read confirmation was sent."));
+		else
+			write_msg(get_lang("Error in SMTP sending read confirmation."));
+	};
+
+	if(msg_info.source)
+	{
+		// Abrindo um e-mail criptografado
+		// Verifica se existe o objeto applet
+		if (!Element('cert_applet')){
+			// se não existir, mostra mensagem de erro.
+			write_msg(get_lang('The preference "%1" isn\'t enabled.', get_lang('Enable digitally sign/cipher the message?')));
+		} else {
+			// se existir prepara os dados para serem enviados e chama a
+			// operação na applet
+
+			expresso.connector.showProgressBar();
+
+			// if ((msg_info.DispositionNotificationTo) && ((msg_info.Unseen == 'U') || (msg_info.Recent == 'N'))){
+			/*	var confNotification = confirm(get_lang("The sender waits your notification of reading. Do you want to confirm this?"), "");
+				if (confNotification)*/
+			//        cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), _hand_sendnotif);
+			// }
+
+			Element('cert_applet').doButtonClickAction('decript',
+					msg_info.msg_number,
+					msg_info.source,
+					msg_info.msg_folder); // Passa os dados para a applet
+		}
+		return;
+
+	}
+
+	if (msg_info.status == 'false'){
+		delete_border(msg_info.reuse_border);
+	}
+	else{
+		var ID = msg_info.original_ID ? msg_info.original_ID : msg_info.msg_number;
+		var id_msg_read = ID+"_r";
+
+		if (preferences.use_shortcuts == '1')
+			select_msg(ID, 'null');
+		// Call function to draw message
+		// If needed, delete old border
+		if(currentTab)
+		{
+			draw_msg.draw_message_body(msg_info,currentTab);
+			var unseen_sort = document.getElementById('span_flag_UNSEEN').getAttribute('onclick');
+			unseen_sort = unseen_sort.toString();
+			if ( !(unseen_sort.indexOf("'UNSEEN' == 'UNSEEN'") < 0) )
+			{
+				var sort_type = sort_box_type;
+				sort_box_type = null;
+				sort_box('UNSEEN', sort_type);
+			}
+		}
+		else{
+			/* No tab avaliable, the draw_message_header hasn't finished?! */
+			setTimeout('expresso.connector.cacheNextRequest(); cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number='+ ID +'&msg_folder=' + current_folder+'", show_msg)',100);
+		}
+
+		var domains = "";
+		if ((msg_info.DispositionNotificationTo) && (!msg_is_read(ID) || (msg_info.Recent == 'N')))
+		{
+			if (preferences.notification_domains != undefined && preferences.notification_domains != "")
+			{
+				domains = preferences.notification_domains.split(',');
+			}
+			else
+			{
+				var confNotification = true;
+			}
+			for (var i = 0; i < domains.length; i++)
+				if (msg_info.DispositionNotificationTo.match(domains[i]+">"))
+				{
+					var confNotification = true;
+					break;
+				}
+			if (confNotification == undefined)
+				var confNotification = confirm(get_lang("The sender:\n%1\nwaits your notification of reading. Do you want to confirm this?",msg_info.DispositionNotificationTo), "");
+			if (confNotification)
+				cExecute ("expressoMail1_2.imap_functions.send_notification&notificationto="+msg_info.DispositionNotificationTo+"&subject="+url_encode(msg_info.subject), _hand_sendnotif);
+		}
+		//Change msg class to read.
+		if (!msg_is_read(ID))
+		{
+			set_msg_as_read(ID, true);
+			if (msg_info.cacheHit || (!proxy_mensagens.is_local_folder(get_current_folder()) && msg_info.original_ID))
+			{
+				set_message_flag(ID, "seen"); // avoid caducous (lazy) data
+			}
+		}
+	}
+	resizeWindow();
+}
+
+function auto_refresh(){
+	refresh(preferences.alert_new_msg);
+	setTimeout('auto_refresh()', time_refresh);
+}
+
+function auto_archiving() {
+	expresso_mail_sync.start_sync();
+	setTimeout('auto_archiving()',600000);
+}
+
+function refresh(alert_new_msg){
+	var handler_refresh = function(data){
+		var box = Element("tbody_box");
+		if (box.childNodes.length == 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);
+			box.appendChild(tr_info);
+		}
+
+		if (data.length > 0){
+			var msg_info = document.getElementById('msg_info');
+			if (msg_info != null)
+				main.removeChild(msg_info);
+
+			table_element = Element("table_box");
+			var box = Element("tbody_box");
+			table_element.appendChild(box);
+
+			if (data[0].msg_folder != current_folder) // Bad request
+				return false;
+
+			for (var i=0; i<data.length; i++){
+				var existent = document.getElementById(data[i].msg_number);
+				if (!existent)
+				{
+					var new_msg = this.make_tr_message(data[i], current_folder);
+					_dragArea.makeDragged(new_msg, data[i].msg_number, data[i].subject, true);
+					eval(data[i].command);
+				}
+			}
+			if (! typeof(data.msgs_to_delete) == 'undefined')
+				for (var i=0; i<data.msgs_to_delete.length; i++){
+					var remove_msg = document.getElementById(data.msgs_to_delete[i]);
+					if (remove_msg)
+						remove_msg.parentNode.removeChild(remove_msg);
+				}
+
+			if(parseInt(alert_new_msg) && data.new_msgs > 0)
+				alert(data['new_msgs'] > 1 ? get_lang("You have %1 new messages", data['new_msgs']) + "!" : get_lang("You have 1 new message") +"!");
+			if(data.new_msgs > 0){
+				Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + parseInt(data.new_msgs); //refresh tab title
+				update_quota(get_current_folder());
+			}						
+		};
+		// Update Box BgColor
+		var box = Element("tbody_box");
+		if(box.childNodes.length > 1){
+			updateBoxBgColor(box.childNodes);
+		}
+		update_menu();
+	};
+
+	msg_range_end = (current_page*preferences.max_email_per_page);
+	msg_range_begin = (msg_range_end-(preferences.max_email_per_page)+1);
+	
+	
+	//Get element tBody.
+	main = Element("tbody_box");
+	if(!main)
+		return;	
+
+	// Get all TR (messages) in tBody.
+	main_list = main.childNodes;
+	var tmp = '';
+	var string_msgs_in_main = '';
+
+	var len = main_list.length; 
+	for (var j=0; j < len; j++)
+		tmp += main_list[j].id + ',';
+		
+	string_msgs_in_main = tmp.substring(0,(tmp.length-1));
+	if(!expresso_offline)
+		cExecute ("expressoMail1_2.imap_functions.refresh&folder="+current_folder+"&msgs_existent="+string_msgs_in_main+"&msg_range_begin="+msg_range_begin+"&msg_range_end="+msg_range_end+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse, handler_refresh);
+}
+
+function delete_msgs(folder, msgs_number, border_ID, show_success_msg,archive)
+{
+	if (arguments.length < 4){
+		show_success_msg = true;
+	}
+
+	if (folder == 'null')
+		folder = current_folder;
+
+	if(openTab.type[currentTab] == 1)
+		return move_search_msgs('content_id_'+currentTab,'INBOX'+cyrus_delimiter+trashfolder,trashfolder);
+
+	if(currentTab.toString().indexOf("_r") != -1){
+			msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
+	}
+
+	if (!archive && (parseInt(preferences.save_deleted_msg)) && (folder!='INBOX'+cyrus_delimiter+trashfolder)){
+		move_msgs2(folder, msgs_number, border_ID, 'INBOX'+cyrus_delimiter+trashfolder,trashfolder,show_success_msg );
+		return;
+	}
+	
+	var handler_delete_msgs = function(data){
+		
+		Element('chkbox_sel_allmsg').checked = false;
+		if (currentTab)
+			mail_msg = Element("tbody_box_"+currentTab);
+		else
+			mail_msg = Element("tbody_box");
+	
+		if ( preferences.use_shortcuts == '1') {
+				//Last msg is selected
+				if (mail_msg && exist_className(mail_msg.childNodes[mail_msg.childNodes.length-1], 'selected_shortcut_msg') ) {
+					select_msg('null', 'up', true);
+				}
+				else {
+					if (!select_msg('null', 'down', true)) {
+						select_msg('null', 'up', true);
+					}
+				}
+			}
+		
+		if (show_success_msg) {
+			if (data.msgs_number.length == 1)
+				write_msg(get_lang("The message was deleted."));
+			else
+				write_msg(get_lang("The messages were deleted."));
+		}
+		if (openTab.type[currentTab] > 1){
+			var msg_to_delete = Element(msgs_number);
+			if (parseInt(preferences.delete_and_show_previous_message) && msg_to_delete) {
+				if (msg_to_delete.previousSibling){
+ 	         		   	var previous_msg = msg_to_delete.previousSibling.id;
+					expresso.connector.cacheNextRequest();
+ 	         		   	cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(current_folder), show_msg);
+ 		 	           } 	            
+				else
+					delete_border(currentTab,'false');
+			}
+			else
+				delete_border(currentTab,'false');
+		}
+        for (var i=0; i<data.msgs_number.length; i++){
+                var msg_to_delete = Element(data.msgs_number[i]);
+                if (msg_to_delete){
+                        removeAll(msg_to_delete.id);
+                }
+        }
+	Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
+	refresh();	
+	};
+
+	if (msgs_number == 'selected')
+		msgs_number = get_selected_messages();
+	if (msgs_number.length > 0 || parseInt(msgs_number) > 0)
+	{
+		cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse, handler_delete_msgs);
+	}
+	else
+		write_msg(get_lang('No selected message.'));		
+}
+
+
+function move_search_msgs(border_id, new_folder, new_folder_name){
+	var selected_messages = '';
+	var temp_msg;
+	var main_list = Element("tbody_box_"+currentTab.substr(7)).childNodes;
+	for (j = 0; j < main_list.length; j++)	{
+		var check_box = main_list[j].firstChild.firstChild; 
+		if(check_box && check_box.checked) {
+			if (proxy_mensagens.is_local_folder(main_list[j].getAttribute('name'))) {
+				alert(get_lang("You cant manipulate local messages on search"));
+				return;
+			}
+			selected_messages += main_list[j].id + ',';
+		}
+	}
+	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
+	var _hand_mvsearchmsg = function(data){
+		if(!data || !data.msgs_number)
+			return;
+		else if(data.deleted) {			
+			if (data.msgs_number.length == 1)
+				write_msg(get_lang("The message was deleted."));
+			else
+				write_msg(get_lang("The messages were deleted."));			
+		}
+		else{
+			if (data.msgs_number.length == 1)
+				write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
+			else
+				write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
+		}
+
+		selected_messages = selected_messages.split(",");
+		for (i = 0; i < selected_messages.length; i++){
+			removeAll(selected_messages[i]);
+		}
+		// Update Box BgColor
+		var box = Element("tbody_box_"+currentTab.substr(7)).childNodes;
+		if(main_list.length > 1){
+			updateBoxBgColor(box);
+		}
+	};
+
+	if (selected_messages){
+		var selected_param = "";
+		if (selected_messages.indexOf(',') != -1)
+		{
+			selected_msg_array = selected_messages.split(",");
+			for (i = 0; i < selected_msg_array.length; i++){
+				var tr = Element(selected_msg_array[i]);
+				if (tr.getAttribute('name') == new_folder)
+				{
+					write_msg(get_lang('At least one message have the same origin'));
+					return false;
+				}
+				trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
+			        selected_param += ','+trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
+			}
+		}
+		else
+		{
+			var tr=Element(selected_messages);
+			if (tr.getAttribute('name') == new_folder)
+			{
+				write_msg(get_lang('The origin folder and the destination folder are the same.'));
+				return false;
+			}
+			trfolder = (tr.getAttribute('name') == null?get_current_folder():tr.getAttribute('name'));
+			selected_param=trfolder+';'+tr.id.replace(/_[a-zA-Z0-9]+/,"");
+		}
+		var params = "";
+		if (!new_folder && parseInt(preferences.save_deleted_msg)){ 
+			new_folder = 'INBOX'+cyrus_delimiter+trashfolder;
+			new_folder_name = trashfolder;
+			params = "&delete=true";
+		}
+
+		params += "&selected_messages="+url_encode(selected_param);
+		if(new_folder) {
+			params += "&new_folder="+url_encode(new_folder);
+			params += "&new_folder_name="+url_encode(new_folder_name);
+		}
+		cExecute ("expressoMail1_2.imap_functions.move_search_messages", _hand_mvsearchmsg, params);
+	}
+	else
+		write_msg(get_lang('No selected message.'));		
+}
+
+function move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,show_success_msg){
+
+	if (! folder || folder == 'null')
+		folder = Element("input_folder_"+msgs_number+"_r") ? Element("input_folder_"+msgs_number+"_r").value : (openTab.imapBox[currentTab] ? openTab.imapBox[currentTab]:get_current_folder());
+
+	if(openTab.type[currentTab] == 1)
+		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
+
+	var handler_move_msgs = function(data){
+		if(typeof(data) == 'string')
+			if (data.match(/^(.*)TRYCREATE(.*)$/)){
+				expresso.connector.loadScript('jscode/TreeS');
+				var move_to_folder = data.match(/^(.*)Spam(.*)$/) ? "Spam" : trashfolder;
+				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.', move_to_folder));
+				expresso.connector.loadScript('jscode/TreeShow');
+				ttree.FOLDER = 'root';
+				ttreeBox.new_past(move_to_folder);
+				return false;
+			}else{
+				alert(get_lang('Error moving message.')+":\n"+data);
+				return false;
+			}
+		//Este bloco verifica as permissoes ACL sobre pastas compartilhadas
+		if(data.status == false){
+			alert(get_lang("You don't have permission for this operation in this shared folder!"));
+			return false;
+		}
+		mail_msg = ( Element("divScrollMain_"+numBox) ) ? Element("divScrollMain_"+numBox).firstChild.firstChild : Element("divScrollMain_0").firstChild.firstChild;
+		if (data.msgs_number.length == 1)
+			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
+		else
+			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
+
+		if (openTab.type[currentTab] > 1){
+			msg_to_delete = Element(msgs_number);
+			if (parseInt(preferences.delete_and_show_previous_message) && msg_to_delete)
+			{
+				if (msg_to_delete.previousSibling){
+					var previous_msg = msg_to_delete.previousSibling.id;
+					//cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + current_folder, show_msg);
+					expresso.connector.cacheNextRequest();
+					cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+previous_msg+"&msg_folder=" + url_encode(folder), show_msg);
+				}
+				else
+					delete_border(currentTab,'false');
+			}
+			else
+				delete_border(currentTab,'false');
+			if(msg_to_delete)
+				mail_msg.removeChild(msg_to_delete);
+
+			// Update Box BgColor
+			var box = Element("tbody_box");
+			if(box.childNodes.length > 0){
+				updateBoxBgColor(box.childNodes);
+			}
+			return;
+		}
+
+		Element('chkbox_sel_allmsg').checked = false;
+		if (! mail_msg)
+				mail_msg = Element("tbody_box");
+		data.msgs_number = data.msgs_number.split(",");
+
+		var msg_to_delete;
+		if( typeof(msgs_number) == 'string' )
+			all_search_msg = msgs_number.split(',');
+		else if( typeof(msgs_number) == 'number')
+			all_search_msg = msgs_number;
+		
+		for (var i=0; i <= all_search_msg.length; i++)
+		{
+			msg_to_delete = Element(folder+';'+all_search_msg[i]); 
+			if (msg_to_delete)
+				msg_to_delete.parentNode.removeChild(msg_to_delete);
+		}
+
+		if ( preferences.use_shortcuts == '1') {
+			var all_messages = Element('tbody_box').childNodes;
+
+			//Last msg is selected
+			if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') ) {
+				select_msg('null', 'up', true);
+			}
+			else {
+				if (!select_msg('null', 'down', true)) {
+					select_msg('null', 'up', true);
+				}
+			}
+		}
+		for (var i=0; i<data.msgs_number.length; i++)
+		{
+			msg_to_delete = Element(data.msgs_number[i]);
+			if (msg_to_delete)
+				mail_msg.removeChild(msg_to_delete);
+		}	
+		
+		
+		if (data.msgs_number.length == 1)
+			write_msg(get_lang("The message was moved to folder ") + lang_folder(data.new_folder_name));
+		else
+			write_msg(get_lang("The messages were moved to folder ") + lang_folder(data.new_folder_name));
+		if (data.border_ID.indexOf('r') != -1){
+			if (parseInt(preferences.delete_and_show_previous_message) && folder == get_current_folder()){
+				delete_border(data.border_ID,'false');
+				show_msg(data.previous_msg);
+				}
+			else
+				delete_border(data.border_ID,'false');
+		}
+		if(folder == get_current_folder())
+			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;			
+		
+		refresh();
+	};
+
+	if (folder == new_folder){
+		write_msg(get_lang('The origin folder and the destination folder are the same.'));
+		return;
+	}
+
+	if (msgs_number == 'selected'){
+		msgs_number = get_selected_messages();
+		}
+
+	if(openTab.type[currentTab] == 1){
+		return move_search_msgs('content_id_'+currentTab,new_folder,new_folder_name);
+		}
+
+	if(currentTab.toString().indexOf("_r") != -1){
+		msgs_number = currentTab.toString().substr(0,currentTab.toString().indexOf("_r"));
+	}
+
+	if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
+	{
+		cExecute ("expressoMail1_2.imap_functions.move_messages&folder="+folder+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&search_box_type="+search_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message, handler_move_msgs);
+	}
+	else
+		write_msg(get_lang('No selected message.'));		
+		
+}
+
+function move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name) {
+	move_msgs2(folder, msgs_number, border_ID, new_folder, new_folder_name,true);
+}
+
+function archive_msgs(folder,folder_dest,id_msgs) {
+	if(proxy_mensagens.is_local_folder(folder)) {
+		write_msg(get_lang("You cant archive local mails"));
+		return;
+	}
+
+	if(!id_msgs)
+		id_msgs = get_selected_messages();
+	
+	if(folder_dest=='local_root' || folder_dest==null) //Caso seja o primeiro arquivamento...
+		folder_dest = 'local_Inbox';
+	
+	if (parseInt(id_msgs) > 0 || id_msgs.length > 0)
+		expresso_mail_sync.archive_msgs(folder,folder_dest,id_msgs); 
+		//cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , _hand_arqmsg);
+	else 
+		write_msg(get_lang('No selected message.'));
+	/*var has_local_messages_before = expresso_local_messages.has_local_mails(); //vejo se já tinha mensagens locais
+	var _hand_arqmsg = function(data) {
+		var sucess = true;
+		var temp;
+		var msgs_to_remove = new Array();
+		var update_tree;
+		for (var i = 0; i < data.length; i++) {
+			msg_info = expresso.connector.unserialize(data[i]);
+                        if ( folder == 'INBOX/Lixeira/tmpMoveToLocal' ){
+				msg_info.msg_folder += (Date.parse(new Date));
+			}
+			temp = expresso_local_messages.insert_mail(msg_info, msg_info['header'],msg_info['array_attach'],folder_dest );
+			if ( Element("check_box_message_" + msg_info.msg_number) )
+				Element("check_box_message_" + msg_info.msg_number).checked = false;
+
+			if(!temp)
+				sucess = false;
+			else
+				msgs_to_remove.push(msg_info.msg_number);//As mensagens arquivadas devem ser removidas, caso o usuario tenha isso configurado.
+
+			if ( Element(msg_info.msg_number) )
+				remove_className(Element(msg_info.msg_number), 'selected_msg');
+                       if ( tree_folders._selected.id.indexOf( 'local_' ) == 0 || folder.indexOf( 'INBOX/Lixeira/tmpMoveToLocal' ) == 0 )
+			{
+				openTab.imapBox[0] = '';
+				tree_folders.getNodeById( 'local_Inbox' )._select( );
+				change_folder('local_Inbox','Inbox')
+			}
+
+		}
+		
+		if (preferences.keep_archived_messages == 0) { //Remove as mensagens
+				delete_msgs(folder,msgs_to_remove,'null',false,true);
+		}
+		update_tree=(!has_local_messages_before) && expresso_local_messages.has_local_mails();
+		
+		Element('chkbox_sel_allmsg').checked = false;
+		if(update_tree)
+			ttreeBox.update_folder();
+		else
+			update_menu();
+		if(sucess) 
+			write_msg(get_lang("selected messages have been archived"));
+		else
+			write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later"));
+
+	}	
+	if(!id_msgs)
+		id_msgs = get_selected_messages();
+	if (parseInt(id_msgs) > 0 || id_msgs.length > 0) 
+		cExecute("expressoMail1_2.imap_functions.get_info_msgs&folder=" + folder + "&msgs_number=" + id_msgs , _hand_arqmsg);
+	else 
+		write_msg(get_lang('No selected message.'));*/
+	
+}
+
+function get_selected_messages(){
+	try { main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
+	}catch(e){
+	};
+	if (! main)
+		main = Element("tbody_box");
+
+	// Get all TR (messages) in tBody.
+	main_list = main.childNodes;
+
+	var selected_messages = '';
+	var _sel_msgbyshrtcut = '';
+	var j = 0;
+	for (j; j<(main_list.length); j++)
+	{
+	check_box = Element("check_box_message_"+main_list[j].id);
+	if ( (check_box) && (check_box.checked) )
+		selected_messages += main_list[j].id + ',';
+		
+		if (preferences.use_shortcuts == '1')
+		{
+			if ( exist_className(Element(main_list[j].id), 'selected_shortcut_msg') )
+			{
+				_sel_msgbyshrtcut += main_list[j].id + ',';
+			}
+		}
+	}
+	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
+	
+	if (preferences.use_shortcuts == '1')
+	{
+		_sel_msgbyshrtcut = _sel_msgbyshrtcut.substring(0,(_sel_msgbyshrtcut.length-1));
+		
+		var _arr_sel_msgbyshrtcut = _sel_msgbyshrtcut.split(",");
+		var _arr_selected_messages = selected_messages.split(",");
+		
+		if ((_arr_selected_messages.length <= 1) && (_arr_sel_msgbyshrtcut.length > 1))
+		{
+			return _sel_msgbyshrtcut;
+		}
+	}
+	
+	if (selected_messages == '')
+		return false;
+	else
+		return selected_messages;
+}
+
+function new_message_to(email) {
+	var new_border_ID = new_message('new','null');
+	document.getElementById("to_" + new_border_ID).value=email;
+}
+
+function new_message(type, border_ID){
+	if ( RichTextEditor == null )
+		RichTextEditor = new cRichTextEditor( );
+
+        if (Element('show_img_link_'+border_ID))
+        {
+            show_msg_img(border_ID.match(/^\d*/)[0], Element('input_folder_'+border_ID).value);
+        }
+	var new_border_ID = draw_new_message(parseInt(border_ID));
+	if (new_border_ID == false)
+		return false;	
+        openTab.type[new_border_ID] = tabTypes[type];
+
+	// Salva a pasta da mensagem respondida ou encaminhada:
+	var folder_message = Element("input_folder_"+border_ID);
+	if(folder_message) {
+		var input_current_folder = document.createElement('input');	
+		input_current_folder.id = "new_input_folder_"+border_ID;
+		input_current_folder.name = "input_folder";
+		input_current_folder.type = "hidden";
+		input_current_folder.value = folder_message.value;
+		Element("content_id_" + new_border_ID).appendChild(input_current_folder);
+	}//Fim.
+	var title = '';
+	data = [];
+	if (Element("from_" + border_ID)){
+			if (document.getElementById("reply_to_" + border_ID)){
+				data.to = document.getElementById("reply_to_values_" + border_ID).value;
+				data.to = data.to.replace(/&lt;/gi,"<");
+				data.to = data.to.replace(/&gt;/gi,">");
+		}
+		else {
+			if (document.getElementById("from_values_" + border_ID))
+			{
+				data.to = document.getElementById("from_values_" + border_ID).value;
+				data.to = data.to.replace(/&lt;/gi,"<");
+				data.to = data.to.replace(/&gt;/gi,">");
+			}
+		}	
+		
+		if (document.getElementById("to_values_" + border_ID)){
+			data.to_all = document.getElementById("to_values_" + border_ID).value;
+			data.to_all = data.to_all.replace(/\n/gi," ");		
+			data.to_all = data.to_all.replace(/&lt;/gi,"<");
+			data.to_all = data.to_all.replace(/&gt;/gi,">");
+			var _array_to_all = data.to_all.split(",");
+		}	
+	}
+	
+	if (document.getElementById("cc_" + border_ID)){
+		data.cc = document.getElementById("cc_values_" + border_ID).value;
+		data.cc = data.cc.replace(/&lt;/gi,"<");
+		data.cc = data.cc.replace(/&gt;/gi,">");
+	}
+	if (document.getElementById("cco_" + border_ID)){
+		data.cco = document.getElementById("cco_values_" + border_ID).value;
+		data.cco = data.cco.replace(/&lt;/gi,"<");
+		data.cco = data.cco.replace(/&gt;/gi,">");
+	}
+	if (document.getElementById("subject_" + border_ID))
+		data.subject = document.getElementById("subject_" + border_ID).innerHTML;
+	if (document.getElementById("body_" + border_ID))
+		data.body = document.getElementById("body_" + border_ID).innerHTML;
+	
+	if (Element('date_' + border_ID)){
+		data.date = Element('date_' + border_ID).innerHTML;
+	}
+	
+	if (Element('date_day_' + border_ID)){
+		data.date_day = Element('date_day_' + border_ID).value;
+	}
+	if (Element('date_hour_' + border_ID)){
+		data.date_hour = Element('date_hour_' + border_ID).value;
+	}
+	if(typeof(preferences.signature) == 'undefined')
+		preferences.signature = "";
+	var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
+	switch(type){
+		case "reply_without_history":			
+			Element("to_" + new_border_ID).value = data.to;
+			title = "Re: " + data.subject;
+			Element("subject_" + new_border_ID).value = "Re: " + data.subject;			
+			useOriginalAttachments(new_border_ID,border_ID);
+			var body = Element("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1"){ 
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
+			}
+			else{ 
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			//Focus
+			if (is_ie)
+				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
+			else
+				body.contentWindow.focus();
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			msg_reply_from = document.createElement('input');
+			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
+			msg_reply_from.type = "hidden";
+			msg_reply_from.value = Element("msg_number_" + border_ID).value;
+			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
+			break;
+		case "reply_with_history":
+			title = "Re: " + data.subject;
+			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
+			Element("to_" + new_border_ID).value = data.to;
+			useOriginalAttachments(new_border_ID,border_ID);
+			block_quoted_body = make_body_reply(data.body, data.to, data.date_day, data.date_hour);
+			var body = Element("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1") {
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + block_quoted_body + "</body></html>");
+			}
+			else {
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+block_quoted_body+"</body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			//Focus
+			if (is_ie)
+				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
+			else
+				body.contentWindow.focus();
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			msg_reply_from = document.createElement('input');
+			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
+			msg_reply_from.type = "hidden";
+			msg_reply_from.value = Element("msg_number_" + border_ID).value;
+			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
+			break;
+		case "reply_to_all_without_history":
+			// delete user email from to_all array.
+			data.to_all = new Array();
+			var j = 0;
+			for(i = 0; i < _array_to_all.length; i++) {			
+				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
+					data.to_all[j++] = _array_to_all[i];
+				}
+			}
+			data.to_all = data.to_all.join(",");
+
+			title = "Re: " + data.subject;
+			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
+			Element("to_" + new_border_ID).value = data.to;
+			Element("to_" + new_border_ID).value += ', ' + data.to_all;
+			if (data.cc){
+				Element("cc_" + new_border_ID).value = data.cc;
+				Element("a_cc_link_" + new_border_ID).style.display='none';
+				Element("tr_cc_" + new_border_ID).style.display='';
+				Element('space_link_' + new_border_ID).style.display='none';
+			}
+			useOriginalAttachments(new_border_ID,border_ID);
+			var body = Element("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1") {
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
+			}
+			else {
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			//Focus
+			if (is_ie)
+				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
+			else
+				body.contentWindow.focus();
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			msg_reply_from = document.createElement('input');
+			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
+			msg_reply_from.type = "hidden";
+			msg_reply_from.value = Element("msg_number_" + border_ID).value;
+			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
+			break;
+		case "reply_to_all_with_history":
+			// delete user email from to_all array.
+			data.to_all = new Array();
+			var j = 0;
+				for(i = 0; i < _array_to_all.length; i++) {			
+				if(_array_to_all[i].lastIndexOf(Element("user_email").value) == "-1"){
+					data.to_all[j++] = _array_to_all[i];
+				}
+			}
+			data.to_all = data.to_all.join(",");
+			title = "Re: " + data.subject;
+			Element("to_" + new_border_ID).value = data.to;
+			Element("to_" + new_border_ID).value += ', ' + data.to_all;
+			if (data.cc){
+				document.getElementById("cc_" + new_border_ID).value = data.cc;
+				document.getElementById("a_cc_link_" + new_border_ID).style.display='none';
+				document.getElementById("tr_cc_" + new_border_ID).style.display='';
+				document.getElementById('space_link_' + new_border_ID).style.display='none';
+			}
+			document.getElementById("subject_" + new_border_ID).value = "Re: " + data.subject;
+			useOriginalAttachments(new_border_ID,border_ID);
+			block_quoted_body = make_body_reply(data.body, data.to, data.date_day, data.date_hour);
+			var body = document.getElementById("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1") {
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + block_quoted_body + "</body></html>");
+			}
+			else {
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+block_quoted_body+"</body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			//Focus
+			if (is_ie)
+				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
+			else
+				body.contentWindow.focus();
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			msg_reply_from = document.createElement('input');
+			msg_reply_from.id = "msg_reply_from_" + new_border_ID;
+			msg_reply_from.type = "hidden";
+			msg_reply_from.value = Element("msg_number_" + border_ID).value;
+			Element("content_id_" + new_border_ID).appendChild(msg_reply_from);
+			break;
+		case "forward":
+			data.is_local_message = (document.getElementById("is_local_"+border_ID).value=="1")?true:false;
+			msg_forward_from = document.createElement('input');
+			msg_forward_from.id = "msg_forward_from_" + new_border_ID;
+			msg_forward_from.type = "hidden";
+			msg_forward_from.value = Element("msg_number_" + border_ID).value;
+			Element("content_id_" + new_border_ID).appendChild(msg_forward_from);			
+			title = "Fw: " + data.subject;
+			document.getElementById("subject_" + new_border_ID).value = "Fw: " + data.subject;
+			var divFiles = Element("divFiles_"+new_border_ID);
+			var campo_arquivo;
+			if (Element("attachments_" + border_ID)){
+				var attachments = document.getElementById("attachments_" + border_ID).childNodes;
+				for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
+					if((attachments[i].tagName=="SPAN") || (attachments[i].tagName=="IMG") ||
+							((attachments[i].href.indexOf("javascript:download_local_attachment")==-1)&&(attachments[i].href.indexOf("javascript:download_attachments")==-1)))
+						continue; 
+					var link_attachment = document.createElement("A");
+					link_attachment.setAttribute("href", attachments[i].href);
+					link_attachment.innerHTML = attachments[i].innerHTML;
+					if (data.is_local_message) {//Local messages
+						document.getElementById("is_local_forward"+new_border_ID).value = "1";
+						var tmp = link_attachment.href.substring(link_attachment.href.indexOf("(") + 2);//Pula o parenteses e a aspas
+						tmp = tmp.substring(0, tmp.length - 2);//corta a aspas e o parenteses
+						tmp = replaceAll(tmp,"%20"," ");
+						var tempNomeArquivo = tmp.split("/");
+						var nomeArquivo = tempNomeArquivo[tempNomeArquivo.length-1];
+						nomeArquivo = nomeArquivo.substring(0,nomeArquivo.length - 4); //Anexos no gears são todos com extensão .php. tenho que tirar a extensão para ficar o nome real do arquivo.
+						campo_arquivo = addForwardedFile(new_border_ID,nomeArquivo,link_attachment.href);
+						if(!expresso_offline)
+							expresso_local_messages.getInputFileFromAnexo(campo_arquivo, tmp);
+						else //To offline, you just set the url on value of a hidden input.
+							campo_arquivo.value = tmp;
+						
+					}
+					else {
+						var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
+						var a_tmp = tmp.split(',');
+						tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
+						a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
+						s_tmp = escape(expresso.connector.serialize(a_tmp));
+
+						divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
+						divFiles.innerHTML += "<link style='border:0' name='file_"+i+"' id='inputFile_"+border_ID+i+"'/>";
+						divFiles.appendChild(link_attachment);
+					}
+				}
+			}
+			var body = Element("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1") {
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>" + make_forward_body(data.body, data.to, data.date, data.subject, data.to_all, data.cc) + "</body></html>");
+			}
+			else {
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+make_forward_body(data.body, data.to, data.date, data.subject, data.to_all, data.cc)+"</body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			Element("to_" + new_border_ID).focus();
+			break;
+		case "new":
+			title = get_lang("New Message");
+			if(Element('msg_number').value) {
+				var _to = Element('msg_number').value;
+				var reEmail = /^[A-Za-z\d_-]+(\.[A-Za-z\d_-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;				
+				if(!reEmail.test(_to)){
+					var array_contacts = contacts.split(',');
+					for(i = 0; i < array_contacts.length;i++) {
+						if(array_contacts[i].lastIndexOf(_to) != "-1"){
+							var _group = array_contacts[i].split(";");
+							_to = '"'+_group[0]+'" <'+_group[1]+'>';
+							break;
+						}
+					}
+				}
+				Element("to_" + new_border_ID).value = _to +',';
+				Element('msg_number').value = '';
+			}
+			var body = document.getElementById("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			// Insert the signature automaticaly at message body if use_signature preference is set
+			if (preferences.use_signature == "1") {
+				body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>" + "<br>" + signature + "</body></html>");
+			}
+			else {
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'></body></html>");
+			}
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			Element("to_" + new_border_ID).focus();
+			break;
+		case "edit":
+			openTab.imapBox[new_border_ID] = folder_message.value;
+			openTab.toPreserve[new_border_ID] = true;
+			openTab.imapUid[new_border_ID] = parseInt(border_ID.substr(0,border_ID.indexOf("_")));
+			document.getElementById('font_border_id_'+new_border_ID).innerHTML = data.subject;
+			data.to = Element("to_values_" + border_ID).value;
+			data.to = data.to.replace(/&lt;/gi,"<");
+			data.to = data.to.replace(/&gt;/gi,">");
+			title = "Edição: "+data.subject;
+			
+			Element("to_" + new_border_ID).value = data.to;
+			if (data.cc){
+				Element("cc_" + new_border_ID).value = data.cc;
+				Element("space_link_" + new_border_ID).style.display = 'none';
+				Element("a_cc_link_" + new_border_ID).style.display = 'none';
+				Element("tr_cc_"+ new_border_ID).style.display = '';
+			}
+			if (data.cco){
+				Element("cco_" + new_border_ID).value = data.cco;
+				Element("space_link_" + new_border_ID).style.display = 'none';
+				Element("a_cco_link_" + new_border_ID).style.display = 'none';
+				Element("tr_cco_"+ new_border_ID).style.display = '';
+			}
+			Element("subject_" + new_border_ID).value = data.subject;
+			
+			var divFiles = Element("divFiles_"+new_border_ID);
+			if (Element("attachments_" + border_ID)){
+				var attachments = document.getElementById("attachments_" + border_ID).childNodes;
+				for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
+					var link_attachment = document.createElement("A");
+					link_attachment.setAttribute("href", attachments[i].href);
+					link_attachment.innerHTML = attachments[i].innerHTML;
+					var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
+					var a_tmp = tmp.split(',');
+					tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
+					a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
+					s_tmp = escape(expresso.connector.serialize(a_tmp));
+					divFiles.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
+					divFiles.appendChild(link_attachment);
+				}
+			}
+			var body = Element("body_" + new_border_ID);
+			body.contentWindow.document.open();
+			body.contentWindow.document.write("<html><body bgcolor='#FFFFFF'>"+data.body+"</body></html>");
+			body.contentWindow.document.close();
+			body.contentWindow.document.designMode = "on";
+			//Focus
+			if (is_ie)
+				window.setTimeout('document.getElementById("body_'+new_border_ID+'").contentWindow.focus();', 300);
+			else
+				body.contentWindow.focus();
+			config_events( body.contentWindow.document, 'onkeyup', function( e )
+			{
+				if ( e.keyCode == 13 )
+				{
+					var paragraphs = body.contentWindow.document.getElementsByTagName( 'p' );
+					for ( p = 0; p < paragraphs.length; p++ )
+						paragraphs.item( p ).style.margin = '0px';
+				}
+			});
+			break;
+		default:
+	}
+
+	// IM Module Enabled
+	if( window.parent.loadscript && loadscript.autoStatusIM )
+	{
+		config_events( body.contentWindow.document, "onkeypress", loadscript.autoStatusIM );	
+	}
+
+	if (preferences.auto_save_draft == 1)
+	{
+		openTab.autosave_timer[new_border_ID] = false;
+		var save_link = document.getElementById("save_message_options"+new_border_ID);
+
+        function auto_sav()
+			{
+				if (openTab.autosave_timer[new_border_ID])
+					clearTimeout(openTab.autosave_timer[new_border_ID]);
+
+				openTab.autosave_timer[new_border_ID] = setTimeout("save_msg("+new_border_ID+")", autosave_time);
+	}
+        config_events(body.contentWindow.document,'keypress', auto_sav);
+    }
+
+	//BEGIN Tab event
+	if (preferences.use_shortcuts == '1')
+	{
+		if (is_ie)
+		{
+			body.contentWindow.document.attachEvent('onkeydown', function(event) { if(event.keyCode==27){delete_border(new_border_ID,'false');} if(event.keyCode==9) { Element('to_'+new_border_ID).focus(); Element('send_button_'+new_border_ID).focus(); return false;} }, false);
+		}
+		else
+		{
+			body.contentWindow.document.addEventListener('keypress', function(event) { if(event.keyCode==27){delete_border(new_border_ID,'false');} if(event.keyCode==9) { Element('send_button_'+new_border_ID).focus(); event.preventDefault(); } }, false);
+		}
+	}
+	// END Tab event
+	
+	var offWidth = Element('border_blank').offsetWidth ? Element('border_blank').offsetWidth : Element('border_blank').clientWidth;
+	var resize = false;
+	
+	if (offWidth < 200) {
+		resize = Element("border_id_" + new_border_ID).style.width;
+	}
+
+	if (title.length > 21){
+		title = title.substring(0,21) + "...";
+	}
+	
+	if(resize)
+		title = title.substring(0, parseInt(resize)*0.08);
+
+	Element("border_id_" + new_border_ID).innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + new_border_ID +" class='font-menu' width=*>" +title + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + new_border_ID + "','false') src='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/close_button.gif'></td></tr></table>";
+	return new_border_ID; //Preciso retornar o ID da nova mensagem.
+}
+
+function useOriginalAttachments(new_id_border,old_id_border)
+{
+	var divFiles = Element("divFiles_"+new_id_border);
+	if (Element("attachments_" + old_id_border)) {
+		var areaOldAttachments = document.createElement("DIV");
+		areaOldAttachments.id = "area_div_attachments_"+new_id_border;
+		divFiles.appendChild(areaOldAttachments);
+		var optAttachments = document.createElement("A");
+		optAttachments.setAttribute("href","javascript:void(0)");
+		optAttachments.tabIndex = -1;
+		optAttachments.innerHTML = get_lang("Original attachments: add")+"</br>";
+		areaOldAttachments.appendChild(optAttachments);
+		var divOriginalAttachments = document.createElement("DIV");
+		divOriginalAttachments.id = "div_attachments_"+new_id_border;
+		optAttachments.onclick = function(){
+			if(document.getElementById('div_attachments_'+new_id_border))
+			{
+				areaOldAttachments.removeChild(document.getElementById('div_attachments_'+new_id_border));
+				optAttachments.innerHTML = get_lang("Original attachments: add")+"</br>";
+			}
+			else
+			{
+				areaOldAttachments.appendChild(divOriginalAttachments);
+				optAttachments.innerHTML = get_lang("Original attachments: remove")+"</br>";
+			}
+				return false;
+			};
+			var attachments = document.getElementById("attachments_" + old_id_border).childNodes;
+			for (var i = (attachments.length > 1 ? 1 : 0); i < attachments.length; i++){
+				var link_attachment = document.createElement("A");
+				link_attachment.setAttribute("href", attachments[i].href);
+				link_attachment.innerHTML = attachments[i].innerHTML;
+				var tmp = link_attachment.href.replace("javascript:download_attachments(", "").replace(")", "");
+				var a_tmp = tmp.split(',');
+				tmp = link_attachment.innerHTML.substring(0,link_attachment.innerHTML.lastIndexOf("("));
+				a_tmp[2] = "'"+tmp.substring(0,tmp.length-1)+"'";
+				s_tmp = escape(expresso.connector.serialize(a_tmp));
+				divOriginalAttachments.innerHTML += "<input style='border:0' type='CHECKBOX' name='forwarding_attachments[]' checked value=\""+s_tmp+"\"/>";
+				divOriginalAttachments.appendChild(link_attachment);
+			}
+	};
+}
+
+function send_message_return(data, ID){
+    watch_changes_in_msg(ID);
+
+    var sign = false;
+	var crypt = false;
+    if ((preferences.use_assinar_criptografar != '0') && (preferences.use_signature_digital_cripto != '0')){
+		var checkSign = document.getElementById('return_digital_'+ID);
+		if (checkSign.checked){
+			sign = true;
+		}
+
+		var checkCript = document.getElementById('return_cripto_'+ID);
+		if (checkCript.checked){
+			crypt = true;
+		}
+	}
+
+    if (typeof(data) == 'object' && !data.success)
+	{
+        connector = expresso.connector;
+        expresso.connector.showProgressBar();
+
+        if (sign || crypt){
+            var operation = '';
+			if (sign){
+				operation = 'sign';
+			}
+			else { // crypt
+                //TODO: Colocar mensagem de erro, e finalizar o método.
+				operation = 'nop';
+			}
+        }
+
+        if (data.body){
+            Element('cert_applet').doButtonClickAction(operation, ID, data.body);
+        }
+        else {
+			alert(data.error);
+		}
+
+		return;
+    }
+	if(data && data.success == true ){
+		// if send ok, set a flag as answered or forwarded
+		var msg_number_replied = Element('msg_reply_from_'+ID);
+		var msg_number_forwarded = Element('msg_forward_from_'+ID);
+
+		if (msg_number_replied){
+			proxy_mensagens.proxy_set_message_flag(msg_number_replied.value, 'answered');
+		}
+		else if (msg_number_forwarded){
+			proxy_mensagens.proxy_set_message_flag(msg_number_forwarded.value, 'forwarded');
+		}
+		if(expresso_offline){
+			write_msg(get_lang('Your message was sent to queue'));
+			delete_border(ID,'true');
+			return;
+		}else{
+			if (wfolders.alert) {
+				write_msg(get_lang('Your message was sent and save.'));
+				wfolders.alert = false;
+			}
+			else {
+				write_msg(get_lang('Your message was sent.'));
+			}
+		}
+		// If new dynamic contacts were added, update the autocomplete ....
+		if(data.new_contacts){
+			var ar_contacts = data.new_contacts.split(',;');
+			for(var j in ar_contacts){
+				// If the dynamic contact don't exist, update the autocomplete....
+				if((contacts+",").indexOf(";"+ar_contacts[j]+",") == -1)
+					contacts += ",;" + ar_contacts[j];
+			}
+		}
+		if ((! openTab.toPreserve[ID]) && (openTab.imapUid[ID] != 0))
+		{
+			cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+openTab.imapBox[ID]+"&msgs_number="+openTab.imapUid[ID],function(data){ return; });
+		}
+		delete_border(ID,'true'); // Becarefull: email saved automatically should be deleted. delete_border erase information about openTab
+ 	}
+	else{
+		if(data == 'Post-Content-Length')
+			write_msg(get_lang('The size of this message has exceeded  the limit (%1B).',preferences.max_attachment_size ? preferences.max_attachment_size : Element('upload_max_filesize').value));
+		else if(data)
+			write_msg(data);
+		else
+			write_msg(get_lang("Connection failed with %1 Server. Try later.", "Web"));
+	}
+	if(!expresso_offline)
+		expresso.connector.hideProgressBar();
+}
+
+/**
+ * Método chamado pela applet para retornar o resultado da assinatura/decifragem do e-mail.
+ * para posterior envio ao servidor.
+ * @author Mário César Kolling <mario.kolling@serpro.gov.br>, Bruno Vieira da Costa <bruno.vieira-costa@serpro.gov.br>
+ * @param smime O e-mail decifrado/assinado
+ * @param ID O ID do e-mail, para saber em que aba esse e-mail será mostrado.
+ * @param operation A operação que foi realizada pela applet (assinatura ou decifragem)
+ */
+function appletReturn(smime, ID, operation, folder){
+
+    if (!smime){ // Erro aconteceu ao assinar ou decifrar e-mail
+        connector = expresso.connector;
+        expresso.connector.hideProgressBar();
+        return;
+    }
+
+	if(operation=='decript')
+	{
+		var handler = function(data){
+
+			if(data.msg_day == '')
+			{
+                header=expresso_local_messages.get_msg_date(data.original_ID, proxy_mensagens.is_local_folder(get_current_folder()));
+
+				data.fulldate=header.fulldate;
+				data.smalldate=header.smalldate;
+				data.msg_day = header.msg_day;
+				data.msg_hour = header.msg_hour;
+
+			}
+			this.show_msg(data);
+		};
+		para="&source="+smime+"&ID="+ID+"&folder="+folder;
+		cExecute ("expressoMail1_2.imap_functions.show_decript&", handler, para);
+	}else
+	{
+        ID_tmp = ID;
+        // Lê a variável e chama a nova função cExecuteForm
+        // Processa e envia para o servidor web
+        // Faz o request do connector novamente. Talvez implementar no connector
+        // para manter coerência.
+
+        var handler_send_smime = function(data){
+            send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug
+        };
+
+        var textArea = document.createElement("TEXTAREA");
+        textArea.style.display='none';
+        textArea.id = 'smime';
+        textArea.name = "smime";
+        textArea.value += smime;
+
+        // Lê a variável e chama a nova função cExecuteForm
+        // Processa e envia para o servidor web
+        // Faz o request do connector novamente. Talvez implementar no connector
+        // para manter coerência.
+        if (is_ie){
+            var i = 0;
+            while (document.forms(i).name != "form_message_"+ID) { i++; }
+            form = document.forms(i);
+        }
+        else
+            form = document.forms["form_message_"+ID];
+
+        form.appendChild(textArea);
+
+        cExecuteForm ("expressoMail1_2.imap_functions.send_mail", form, handler_send_smime, ID);
+    }
+}
+
+function send_message(ID, folder, folder_name){
+	
+	//limpa autosave_timer[ID]; havia conflito quando uma mensagem ia ser enviada e nesse exato momento o autosave
+        //entrava em execucao (a aba de edicao da mensagem continuava aberta e a mensagem exibida era a de que a mensagem foi
+        //salva na pasta Rascunhos e nao que tinha sido enviada, como deveria);
+        if (preferences.auto_save_draft == 1)
+	{
+		if (openTab.autosave_timer[ID])
+		{
+			clearTimeout(openTab.autosave_timer[ID]);
+		}
+	}
+
+	if ( document.getElementById('viewsource_rt_checkbox').checked == true )
+		document.getElementById('viewsource_rt_checkbox').click();
+
+	var save_link = Element("save_message_options_"+ID);
+	save_link.onclick = '';
+	save_link.className = 'message_options_inactive';
+	
+	ID_tmp = ID;
+
+	var handler_send_message = function(data){
+		send_message_return(data, this.ID_tmp); // this is a hack to escape quotation form connector bug
+	};
+		
+	var textArea = document.createElement("TEXTAREA");
+	textArea.style.display='none';
+	textArea.name = "body";
+	body = document.getElementById("body_"+ID);
+	textArea.value += '<body>\r\n';
+	textArea.value += body.contentWindow.document.body.innerHTML;
+	textArea.value += '\r\n</body>';
+	var input_folder = document.createElement("INPUT");
+	input_folder.style.display='none';
+	input_folder.name = "folder";
+	input_folder.value = folder;
+	var msg_id = document.createElement("INPUT");
+	msg_id.style.display='none';
+	msg_id.name = "msg_id";
+	msg_id.value = openTab.imapUid[ID];
+	
+	if (is_ie){
+		var i = 0;
+		while (document.forms(i).name != "form_message_"+ID) { i++; }
+		form = document.forms(i);
+	}
+	else
+		form = document.forms["form_message_"+ID];
+
+        // Evita que e-mails assinados sejam enviados quando o usuário tenta enviar um e-mail
+        // não assinado (desmarcou a opção) após tentar enviar um e-mail assinado que não passou
+        // no teste de validação.
+        var checkSign = document.getElementById('return_digital_'+ID);
+        if (checkSign && !checkSign.checked){
+            var smime = Element('smime');
+            if (smime)
+            {
+                var parent = smime.parentNode;
+                parent.removeChild(smime);
+            }
+         }
+
+	form.appendChild(textArea);
+	form.appendChild(input_folder);
+	form.appendChild(msg_id);
+
+	var _subject = trim(Element("subject_"+ID).value);
+	if((_subject.length == 0) && !confirm(get_lang("Send this message without a subject?"))) {
+		Element("subject_"+ID).focus();
+		return;
+	}
+	
+	if (expresso_offline) {		
+		stringEmail = Element("to_"+ID).value;
+		stringEmail += Element("cco_"+ID).value =='' ? "":", "+Element("cco_"+ID).value;
+		stringEmail += Element("cc_"+ID).value =='' ? "":", "+Element("cc_"+ID).value;
+		var invalidEmail = searchEmail(stringEmail);	 
+		if(Element("to_"+ID).value=="" && Element("cco_"+ID).value=="" && Element("cc_"+ID).value=="") {
+			write_msg(get_lang("message without receiver."));
+			return;
+		}else if(invalidEmail[0] == true){
+			write_msg("Os endereços de destinatário a seguir estão incorretos: "+invalidEmail[1]);
+			return;
+		}
+
+		sucess = expresso_local_messages.send_to_queue(form);
+		var data_return = new Array();
+		data_return.success = sucess;
+		handler_send_message(data_return,ID);
+	}
+	else 
+		cExecuteForm("expressoMail1_2.imap_functions.send_mail", form, handler_send_message, ID);
+}
+function change_tr_properties(tr_element, newUid, newSubject){
+	if (tr_element == null)
+		return false;
+	message_id=tr_element.id;
+	var td_who = document.getElementById('td_who_'+message_id);
+	if (typeof(newSubject) != 'undefined')
+		td_who.nextSibling.innerHTML = newSubject;
+	tr_element.id = newUid;
+
+	var openNewMessage = function () {
+		expresso.connector.cacheNextRequest();
+		cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+newUid
+				+"&msg_folder="+url_encode(current_folder),show_msg);
+	};
+	for (var i=2; i < 10; i++){
+		if (typeof(tr_element.childNodes[i].id) != "undefined")
+			tr_element.childNodes[i].id = tr_element.childNodes[i].id.replace(message_id,newUid);
+		tr_element.childNodes[i].onclick = openNewMessage;
+	}
+}
+
+function return_save(data,border_id,folder_name,folder_id,message_id)
+{
+	Element("send_button_"+border_id).style.visibility="visible";
+	var handler_delete_msg = function(data){ refresh(preferences.alert_new_msg); };
+
+	if (data.append != true || !data)
+	{
+		RichTextEditor.saveFlag = -1;
+		if (! data.append)
+			write_msg('ERROR saving your message.');
+		else
+		{
+			if (data.append.match(/^(.*)TRYCREATE(.*)$/))
+			{
+				expresso.connector.loadScript('jscode/TreeS');
+				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.',draftsfolder));
+				expresso.connector.loadScript('jscode/TreeShow');
+				ttree.FOLDER = 'root';
+				ttreeBox.new_past(draftsfolder);
+				setTimeout('save_msg('+border_id+')',3000);
+			}
+			else
+				write_msg(data.append);
+		}
+	}
+	else
+	{
+		RichTextEditor.saveFlag = 1;
+		openTab.imapUid[border_id] = data.msg_no;
+		openTab.imapBox[border_id] = data.folder_id;
+		
+		var newTitle = document.getElementById('subject_'+border_id).value;
+		if (newTitle.length > 18)
+			newTitle = newTitle.substr(18) + '...';
+		else if (newTitle == '')
+				newTitle = get_lang("No subject");
+		document.getElementById('font_border_id_'+border_id).innerHTML = newTitle;
+		
+		// Replace the embedded images for new uids
+		var mainField = document.getElementById('body_'+border_id).contentWindow;
+		var content_body =  mainField.document.getElementsByTagName('body').item(0).innerHTML;
+		var body_images = content_body.match(/msg_num=\d*/g);
+		var images_part = content_body.match(/msg_part=\d*/g);
+		if (body_images)
+		{
+			for (var i=0; i<body_images.length; i++){
+				content_body = 	content_body.replace(body_images[i],"msg_num="+openTab.imapUid[border_id]);
+			}
+			var allImgs = new Array (images_part.length);
+				var j=-1;
+				for (var i in images_part){
+				
+					if (is_ie)
+						if (i == 0)
+							var image_number = parseInt(images_part[i].substr(9));
+						else
+							image_number = "null";
+					else
+						var image_number = parseInt(images_part[i].substr(9));
+					
+				if (! isNaN(image_number))
+					{
+						if (! allImgs[image_number])
+						{
+							allImgs[image_number] = true;
+							j--;					
+						}
+					content_body = content_body.replace(images_part[i],'msg_part='+j);
+					}
+				}
+			content_body = content_body.replace(/msg_part=-/g,'msg_part=');
+			
+			mainField.document.getElementsByTagName('body').item(0).innerHTML = content_body;
+		}	
+				
+		//Replace all files to new files
+		var divFiles = Element("divFiles_"+border_id);
+		elFiles = divFiles.getElementsByTagName("input");
+		var countCheck =0;
+		for (var i=0; i<elFiles.length; i++) {
+			if(elFiles[i].value !=""){
+				if (elFiles[i].type == "checkbox") {
+					countCheck++;							
+				}
+				else {
+					elFiles[i].value ="";
+					parantNodeFile = elFiles[i].parentNode.parentNode;
+					parantNodeFile.removeChild(elFiles[i].parentNode);
+					i--;
+				}
+				
+			}
+		};		
+		
+		var attach_files = expresso.connector.unserialize(data.files);
+		if (attach_files != null) {
+			openTab.countFile[border_id] = attach_files.length;
+			att_index = countCheck;
+		for (att_index; att_index < attach_files.length; att_index++){
+	
+			var link_attachment = document.createElement("A");
+			var fileName = attach_files[att_index].substr(0,attach_files[att_index].indexOf('_SIZE_'));
+			var fileSize = parseInt(attach_files[att_index].substr(attach_files[att_index].indexOf('_SIZE_')+6))/1024;
+			link_attachment.innerHTML = fileName + " ("+borkb((parseInt(fileSize)*1024))+")";
+
+			var href = "'"+folder_id+"','"+data.msg_no+"','"+(att_index)+"','"+(att_index+2)+"','base64'";
+
+			link_attachment.setAttribute("href", "javascript:download_attachments("+href+")");
+
+			var a_tmp = href.split(',');
+			a_tmp[2] = fileName;
+			s_tmp = escape(expresso.connector.serialize(a_tmp));
+					
+			var check_attachment = document.createElement("INPUT");
+			check_attachment.type = 'CHECKBOX';
+			check_attachment.name = 'forwarding_attachments[]';
+			check_attachment.value = s_tmp;
+
+			divFiles.insertBefore(document.createElement("BR"),divFiles.childNodes[0]);			
+			divFiles.insertBefore(link_attachment,divFiles.childNodes[0]);
+			divFiles.insertBefore(check_attachment,divFiles.childNodes[0]);
+
+			check_attachment.checked = true;
+		}
+	}
+		if (message_id)
+		{
+			cExecute ("expressoMail1_2.imap_functions.delete_msgs&folder="+openTab.imapBox[border_id]+"&msgs_number="+message_id,handler_delete_msg);
+			if (openTab.imapBox[0] == "INBOX/"+draftsfolder)
+			{
+				//Update mailbox
+		                var tr_msg = document.getElementById(message_id);
+				change_tr_properties(tr_msg, data.msg_no, data.subject);
+			}
+		
+		}
+		var save_link = Element("save_message_options_"+border_id);
+		save_link.onclick = '';
+		save_link.className = 'message_options_inactive';
+		watch_changes_in_msg(border_id);
+		write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder(folder_name)));
+	}		
+}
+
+function save_msg(border_id,withImage){
+	if (typeof(withImage) == 'undefined')
+		withImage = false;
+
+	var rt_checkbox = Element('viewsource_rt_checkbox');
+	if (rt_checkbox == null)
+		return false;
+	if (rt_checkbox.checked == true)
+		rt_checkbox.click();
+
+	var sendButton = Element("send_button_"+border_id);
+	if (sendButton)
+		sendButton.style.visibility="hidden";
+
+	if (openTab.imapBox[border_id] && openTab.type[border_id] != 6 && openTab.type[border_id] != 7) //Gets the imap folder
+		var folder_id = openTab.imapBox[border_id];
+	else
+		var folder_id = "INBOX/"+draftsfolder;
+
+	if (folder_id == 'INBOX') // and folder name from border
+		var folder_name = get_lang(folder_id);
+	else
+		var folder_name = folder_id.substr(6);
+		
+	// hack to avoid form connector bug,  escapes quotation. Please see #179
+	tmp_border_id=border_id;
+	tmp_folder_name=folder_name;
+	tmp_folder_id=folder_id;
+	message_id = openTab.imapUid[border_id];
+	var handler_save_msg = function(data){ return_save(data,this.tmp_border_id,this.tmp_folder_name,this.tmp_folder_id,this.message_id); };
+
+	var textArea = document.createElement("TEXTAREA");
+	textArea.style.display='none';
+	textArea.name = "body";
+	body = document.getElementById("body_"+border_id);
+	if (! body)
+		return;
+	textArea.value += '<body>\r\n';
+	textArea.value += body.contentWindow.document.body.innerHTML;
+	textArea.value += '\r\n</body>';
+	var input_folder = document.createElement("INPUT");
+	input_folder.style.display='none';
+	input_folder.name = "folder";
+	input_folder.value = folder_id;
+	var input_msgid = document.createElement("INPUT");
+	input_msgid.style.display='none';
+	input_msgid.name = "msg_id";
+	input_msgid.value = message_id;
+	var input_insertImg = document.createElement("INPUT");
+	input_insertImg.style.display='none';
+	input_insertImg.name = "insertImg";
+	input_insertImg.value = withImage;
+
+	
+	if (is_ie){
+		var i = 0;
+		while (document.forms(i).name != "form_message_"+border_id) { i++; }
+		form = document.forms(i);
+	}
+	else
+		form = document.forms["form_message_"+border_id];
+	form.appendChild(textArea);
+	form.appendChild(input_folder);
+	form.appendChild(input_msgid);
+	form.appendChild(input_insertImg);
+
+	cExecuteForm ("expressoMail1_2.imap_functions.save_msg", form, handler_save_msg,border_id);	
+}
+
+function return_saveas(data,border_id,folder_name)
+{
+	if (data.append)
+	{
+		delete_border(border_id,null);
+		write_msg(get_lang('Your message was save as draft in folder %1.', folder_name));
+	}
+	else
+		write_msg('ERROR saving your message.');					
+}
+
+function save_as_msg(border_id, folder_id, folder_name){
+	// hack to avoid form connector bug,  escapes quotation. Please see #179
+	tmp_border_id=border_id;
+	tmp_folder_name=folder_name;
+	var handler_save_msg = function(data){ return_saveas(data,this.tmp_border_id,this.tmp_folder_name); };
+	var textArea = document.createElement("TEXTAREA");
+	textArea.style.display='none';
+	textArea.name = "body";
+	body = document.getElementById("body_"+border_id);
+	textArea.value += '<body>\r\n';
+	textArea.value += body.contentWindow.document.body.innerHTML;
+	textArea.value += '\r\n</body>';
+	
+	var input_folder = document.createElement("INPUT");
+	input_folder.style.display='none';
+	input_folder.name = "folder";
+	input_folder.value = folder_id;
+	
+	if (is_ie){
+		var i = 0;
+		while (document.forms(i).name != "form_message_"+border_id){i++}
+		form = document.forms(i);
+	}
+	else
+		form = document.forms["form_message_"+border_id];
+	form.appendChild(textArea);
+	form.appendChild(input_folder);
+	
+	cExecuteForm ("expressoMail1_2.imap_functions.save_msg", form, handler_save_msg,border_id);
+}
+
+
+// Get checked messages
+function set_messages_flag(flag, msgs_to_set){
+	var _hand_setmsgflag = function (data){
+		
+		var msgs_to_set = data.msgs_to_set.split(",");
+
+		if(!data.status) {
+			alert(data.msg);
+			Element('chkbox_sel_allmsg').checked = false;
+			for (var i = 0; i < msgs_to_set.length; i++) {
+				Element("check_box_message_" + msgs_to_set[i]).checked = false;
+				remove_className(Element(msgs_to_set[i]), 'selected_msg');
+			}
+			if(!data.msgs_unflageds)
+				return;
+			else
+				msgs_to_set = data.msgs_unflageds.split(",");
+		}
+		
+
+		for (var i=0; i<msgs_to_set.length; i++){
+			if(Element("check_box_message_" + msgs_to_set[i])){
+				switch(data.flag){
+					case "unseen":
+						set_msg_as_unread(msgs_to_set[i]);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "seen":
+						set_msg_as_read(msgs_to_set[i], false);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "flagged":
+						set_msg_as_flagged(msgs_to_set[i]);
+						document.getElementById("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+					case "unflagged":
+						set_msg_as_unflagged(msgs_to_set[i]);
+						Element("check_box_message_" + msgs_to_set[i]).checked = false;
+						break;
+				}
+			}
+		}
+		Element('chkbox_sel_allmsg').checked = false;
+	};
+	
+	var folder = get_current_folder();
+	if (msgs_to_set == 'get_selected_messages')
+		var msgs_to_set = this.get_selected_messages();
+	else
+		folder = Element("input_folder_"+msgs_to_set+"_r").value;
+	
+	if (msgs_to_set)
+	{
+		cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, _hand_setmsgflag);
+	}
+	else
+		write_msg(get_lang('No selected message.'));		
+}
+
+// By message number
+function set_message_flag(msg_number, flag){
+	var msg_number_folder = Element("new_input_folder_"+msg_number+"_r");
+	var _hand_setmsgflag = function (data){
+		if (data.status && Element("td_message_answered_"+msg_number)) {	
+			if(flag == 'answered')
+				Element("td_message_answered_"+msg_number).innerHTML = '<img src="'+URL_SERVER+'expressoMail1_2/templates/'+template+'/images/answered.gif" title="Respondida">';
+			else if(flag == 'forwarded')
+				Element("td_message_answered_"+msg_number).innerHTML = '<img src="'+URL_SERVER+'expressoMail1_2/templates/'+template+'/images/forwarded.gif" title="Encaminhada">';
+		}
+	};
+	cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+( msg_number_folder ?  msg_number_folder.value : get_current_folder() )+"&msgs_to_set="+msg_number+"&flag="+flag, _hand_setmsgflag);
+}
+
+function print_all(){
+	if (openTab.type[currentTab] == 2)
+		return print_msg(current_folder,currentTab.substr(0,currentTab.indexOf("_r")),currentTab);
+
+	var folder= Element('border_id_0').innerHTML;
+	var body = Element('divScrollMain_'+numBox).innerHTML;
+	var print_width = screen.width - 200;
+	var x = ((screen.width - print_width) / 2);
+	var y = ((screen.height - 400) / 2) - 35;
+	var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y);
+	var seekDot = /\<img /gi;
+	body = body.replace(seekDot, "<img style='display:none' ");
+	seekDot = /\<input /gi;
+	body = body.replace(seekDot, "<input style='display:none' ");
+	
+	while (1){
+		try{
+			var html = '<br>';
+			html += "<h4>ExpressoLivre - ExpressoMail</h4>";
+			html += folder+"<hr>";
+			
+			window_print.document.body.innerHTML = html + '<blockquote><font size="2">' +
+			'<table style="font-size:12" width="'+(is_ie ? "85%" : "99%" )+'"><TR><TD align="center" width="5%">&nbsp;</TD><TD width="30%" align="center">'+get_lang("Who")+'</TD><TD align="center" width="45%">'+get_lang("Subject")+'</TD><TD align="center" width="10%">'+get_lang("Date")+'</TD><TD width="10%">'+get_lang("Size")+'</TD></TR></table>'
+			+ body + '</font></blockquote>';
+			break;
+		}
+		catch(e){
+			//alert(e.message);
+		}
+	}
+	window_print.document.close();
+	window_print.print();
+}
+
+
+function print_msg(msg_folder, msg_number, border_ID){
+	var div_toaddress_full = Element("div_toaddress_full_"+border_ID);	
+	var div_ccaddress_full = Element("div_ccaddress_full_"+border_ID);
+	var printListTO = (div_toaddress_full && div_toaddress_full.style.display != 'none') || toaddress_array[border_ID].length == 1 ? true : false;	
+	var printListCC = (div_ccaddress_full && div_ccaddress_full.style.display != 'none') || !div_ccaddress_full ? true : false;	
+	var sender		= Element('sender_values_'+border_ID) ? Element('sender_values_'+border_ID).value : null;
+	var from		= Element('from_values_'+border_ID) ? Element('from_values_'+border_ID).value : null;
+	var to			= Element('to_values_'+border_ID) ? Element('to_values_'+border_ID).value :null;
+	var cc 			= Element('cc_values_'+border_ID) ? Element('cc_values_'+border_ID).value : null;		
+	var date		=  Element('date_'+border_ID);	
+	var subject		= Element('subject_'+border_ID);
+	var attachments	= Element('attachments_'+border_ID);
+	var body		= Element('body_'+border_ID);
+	
+	if (!is_ie) {//altera o link da imagem para renderização na tela de impressão no firefox
+		var link = location.href.replace(/\/expressoMail1_2\/(.*)/, "");
+		link = link.replace(/\/expressoMail1_2\/(.*)/, "");
+		body.innerHTML = body.innerHTML.replace(/\.(\/inc\/show_embedded_attach\.php)/, link + "/expressoMail1_2$1");
+		body.innerHTML = body.innerHTML.replace(/(tmpLclAtt\/)/, link + "/expressoMail1_2/$1");
+	}
+
+	var print_width = screen.width - 200;
+	var x = ((screen.width - print_width) / 2);
+	var y = ((screen.height - 400) / 2) - 35;
+	var window_print = window.open('','ExpressoMail','width='+print_width+',height=400,resizable=yes,scrollbars=yes,left='+x+',top='+y);
+	if(window_print == null) {
+		alert(get_lang("The Anti Pop-Up is enabled. Allow this site (%1) for print.",document.location.hostname));
+		return;
+	}
+
+	//needed to get the names of the attachments... only.
+	if(attachments != null)
+	{
+		var a = attachments.childNodes;
+		var attachs = "";
+		var show_attachs = "";
+		for(i=0;i<a.length;i++)
+		{
+			if(a[i].tagName && a[i].tagName == "A")
+			{
+				attachs += a[i].innerHTML;
+			}
+		}
+		show_attachs = "<tr><td width=7%><font size='2'>" + get_lang('Attachments: ')+ " </font></td><td><font size='2'>"+attachs+"</font></td></tr>";
+	} else{
+		show_attachs = "";
+	}
+	
+	while (1){
+		try{
+			var html = '<br><br>';
+			//html += "<input type='button' value='Imprimir' onclick='javascript:window.print();'>";
+			html += "<h4>ExpressoLivre - ExpressoMail</h4><hr>";
+			html += '<table><tbody>';
+			if(sender)
+				html += "<tr><td width=7% noWrap><font size='2'>" + get_lang('Sent by') + ": </font></td><td><font size='2'>"+sender+"</font></td></tr>";
+			if(from)
+				html += "<tr><td width=7%><font size='2'>" + get_lang('From') + ": </font></td><td><font size='2'>"+from+"</font></td></tr>";
+			if(to) {
+				if(!printListTO)
+					to = 'Os destinatários não estão sendo exibidos para esta impressão';
+				html += "<tr><td width=7%><font size='2'>" + get_lang('To') + ": </font></td><td><font size='2'>"+to+"</font></td></tr>";
+			}			
+			if (cc) {
+				if(!printListCC)
+					cc = 'Os destinatários não estão sendo exibidos para esta impressão';
+				html += "<tr><td width=7%><font size='2'>" + get_lang('Cc') + ": </font></td><td><font size='2'>"+cc+"</font></td></tr>";
+			}
+			if(date)
+				html += "<tr><td width=7%><font size='2'>" + get_lang('Date') + ": </font></td><td><font size='2'>"+date.innerHTML+"</font></td></tr>";			
+			html += "<tr><td width=7%><font size='2'>" + get_lang('Subject')+ ": </font></td><td><font size='2'>"+subject.innerHTML+"</font></td></tr>";
+			html += show_attachs; //to show the names of the attachments
+			html += "</tbody></table><hr>";
+			window_print.document.body.innerHTML = html + '<blockquote><font size="2">' + body.innerHTML + '</font></blockquote>';
+			if(!is_ie){
+				var tab_tags = window_print.document.getElementsByTagName("IMG");			
+				for(var i = 0; i < tab_tags.length;i++){
+					var _img = document.createElement("IMG");
+					_img.src = tab_tags[i].src;
+					tab_tags[i].parentNode.replaceChild(_img,tab_tags[i]);
+				}
+			}
+			break;
+		}
+		catch(e){
+			//alert(e.message);
+		}
+	}
+	window_print.document.close();
+	window_print.print();
+}
+
+function empty_trash_imap(){
+	var handler_empty_trash = function(data){
+		Element('chkbox_sel_allmsg').checked = false;
+		tree_folders.getNodeById('INBOX'+cyrus_delimiter+trashfolder).alter({caption: get_lang("Trash")});
+		tree_folders.getNodeById('INBOX'+cyrus_delimiter+trashfolder)._refresh();
+		update_quota(get_current_folder());
+		if (data)
+		{
+			write_msg(get_lang('Your Trash folder was empty.'));
+			if (get_current_folder() == 'INBOX'+cyrus_delimiter+trashfolder){
+				draw_paging(0);
+				kill_current_box();				
+				Element('tot_m').innerHTML = 0;
+				Element('new_m').innerHTML = 0;
+			}
+		}
+		else 
+			write_msg(get_lang('ERROR emptying your Trash folder.'));
+	};
+	var realyEmptyTrash=confirm(get_lang('Do you really want to empty your trash folder?'));
+	if (realyEmptyTrash){
+		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultTrashFolder", handler_empty_trash);
+	}
+}
+
+function empty_spam_imap(){
+	var handler_empty_spam = function(data){
+		Element('chkbox_sel_allmsg').checked = false;
+		if (get_current_folder() == 'INBOX'+cyrus_delimiter+spamfolder){
+			draw_paging(0);
+			kill_current_box();
+		}
+		tree_folders.getNodeById('INBOX'+cyrus_delimiter+spamfolder).alter({caption: get_lang("Spam")});
+		tree_folders.getNodeById('INBOX'+cyrus_delimiter+spamfolder)._refresh();
+		update_quota(get_current_folder());
+		if (data)
+			write_msg(get_lang('Your Spam folder was empty.'));
+		else
+			write_msg(get_lang('ERROR emptying your Spam folder.'));
+	};
+	var realyEmptySpam=confirm(get_lang('Do you really want to empty your spam folder?'));
+	if (realyEmptySpam)
+		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultSpamFolder", handler_empty_spam);
+}
+
+
+function export_all_selected_msgs(){
+	if (openTab.type[currentTab] > 1){
+		source_msg(currentTab,current_folder);
+		return;
+	}
+	var msgs_to_export = this.get_selected_messages();
+	
+	var _hand_expallselmsg = function(data){
+	
+		if(!data){
+			write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'));
+		}
+		else
+			download_attachments(null, null, data, null,null,'mensagens.zip');
+	};
+	
+	if (msgs_to_export) {
+		cExecute ("expressoMail1_2.exporteml.makeAll", _hand_expallselmsg, "folder="+get_current_folder()+"&msgs_to_export="+msgs_to_export);
+		write_msg(get_lang('You must wait while the messages will be exported...'));
+	}
+	else
+		write_msg(get_lang('No selected message.'));
+}
+
+function select_all_search_messages(select, id){
+	var search_box = Element("table_resultsearch_" + id.substr(18)).firstChild;
+	var felement = search_box.firstChild;
+	while(felement)
+	{
+	if (select)
+		felement.firstChild.firstChild.checked = true;
+	else
+		felement.firstChild.firstChild.checked = false;
+	felement = felement.nextSibling;
+	}
+}
+
+// Save image file.
+function save_image(e,thumb,file_type){
+	file_type = file_type.replace("/",".");
+	thumb.oncontextmenu = function(e) {
+		return false;
+	};
+	var _button = is_ie ? window.event.button : e.which;
+	var	_target = is_ie ? event.srcElement : e.target;
+	
+	if(_button == 2 || _button == 3) {
+		var _params = _target.id.split(";;");
+		download_attachments(_params[0],_params[1],_params[2],_params[3],_params[4],file_type);
+	}
+}
+
+function nospam(msgs_number, border_ID, folder){
+	if (folder == 'null')
+		folder = get_current_folder();
+	var new_folder 	= 'INBOX';
+	var new_folder_name = get_lang('INBOX');
+	var handler_move_msgs = function(data){
+		if (msgs_number == 'selected')	
+			set_messages_flag("unseen", "get_selected_messages");
+		else
+			proxy_mensagens.proxy_set_message_flag(msgs_number, "unseen");
+   	    proxy_mensagens.proxy_move_messages(folder, msgs_number, border_ID, new_folder, new_folder_name);
+	};
+
+    if (msgs_number == 'selected')
+	   	msgs_number = get_selected_messages();
+       
+	if (parseInt(msgs_number) > 0 || msgs_number.length > 0)
+		cExecute ("expressoMail1_2.imap_functions.spam&folder="+folder+"&spam=false"+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message+"&cyrus_delimiter="+cyrus_delimiter, handler_move_msgs);
+	else
+		write_msg(get_lang('No selected message.'));
+}
+
+function spam(folder, msgs_number, border_ID){
+	if (folder == 'null')
+		folder = get_current_folder();
+    var new_folder 		= 'INBOX'+cyrus_delimiter+'Spam';
+	var new_folder_name = 'Spam';
+	var handler_move_msgs = function(data){
+		// debug
+		// alert(data);
+		proxy_mensagens.proxy_move_messages(folder, msgs_number, border_ID, new_folder, new_folder_name);
+	};
+    if(msgs_number == 'selected')
+		msgs_number = get_selected_messages();
+	if(parseInt(msgs_number) > 0 || msgs_number.length > 0)
+		cExecute ("expressoMail1_2.imap_functions.spam&folder="+folder+"&spam=true"+"&msgs_number="+msgs_number+"&border_ID="+border_ID+"&sort_box_type="+sort_box_type+"&sort_box_reverse="+sort_box_reverse+"&reuse_border="+border_ID+"&new_folder="+new_folder+"&new_folder_name="+new_folder_name+"&get_previous_msg="+preferences.delete_and_show_previous_message+"&cyrus_delimiter="+cyrus_delimiter, handler_move_msgs);
+	else
+    	write_msg(get_lang('No selected message.'));
+}
+
+function import_window(){
+	var win = arrayJSWin["import_window"];
+	var form_upload = Element("form_upload");
+	if(!win) {
+		var form = document.createElement("DIV");
+		form.id  = "import_window";
+		form.style.visibility = "hidden";
+		form.style.position = "absolute";
+		form.style.background = "#eeeeee";
+		form.style.left = "0px";
+		form.style.top  = "0px"; 
+		form.style.width = "0px";
+		form.style.height = "0px";
+		document.body.appendChild(form);
+		form_upload = document.createElement("DIV");
+		form_upload.id = "form_upload";
+		form_upload.style.position = "absolute";
+		form_upload.style.top = "5px";
+		form_upload.style.left = "5px";
+		form_upload.name =  get_lang('zip mails to import');
+		form_upload.style.width = "450px";
+		form_upload.style.height = "75px";
+		form.appendChild(form_upload);	
+		form.style.width  =  form.firstChild.style.width;
+		form.style.height = form.firstChild.style.height;
+		form.style.zIndex = "10000";			
+		var title = form.firstChild.name;
+		var wHeight = form.offsetHeight + "px";
+		var wWidth =  form.offsetWidth   + "px";
+		form.style.width = form.offsetWidth - 5;
+		win = new dJSWin({
+			id: 'win_'+form.id,
+			content_id: form.id,
+			width: wWidth,
+			height: wHeight,
+			title_color: '#3978d6',
+			bg_color: '#eee',
+			title: title,
+			title_text_color: 'white',
+			button_x_img: '../phpgwapi/images/winclose.gif',
+			border: true });	
+		win.draw();
+	}
+	form_upload.innerHTML = '<form method="POST" name="form_import" enctype="multipart/form-data">'+get_lang('zip mails to import')+':<br>'+
+	'<input name="file_1" maxlength="255" size="50" id="file_1" type="file"><br>' +
+	'<input title="'+get_lang('Select a folder')+'"  value="' + get_lang('Select a folder') + '"' + 'type="button" onclick="javascript:select_import_folder()">&nbsp;' +
+	'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
+	' type="button" onclick="arrayJSWin[\'import_window\'].close()"></form>';	
+	win.open();
+}
+
+function import_msgs(wfolders_tree){
+	function handler(data){		
+		// Its necessary to encapsulate the data returned (IE bugfix)
+		return_import_msgs(data,wfolders_tree);		
+	}
+	var countFiles = document.form_import.countFiles;
+	if(!countFiles){
+		countFiles = document.createElement("INPUT");
+		countFiles.type = "hidden";
+		countFiles.name = "countFiles";
+		countFiles.value = "1";
+		document.form_import.appendChild(countFiles);
+	}
+	var folder = document.createElement("INPUT");
+	folder.type = "hidden";
+	folder.name = "folder";
+	folder.value = wfolders_tree._selected.id;
+	document.form_import.appendChild(folder);
+	write_msg(get_lang('You must wait while the messages will be imported...'));
+	
+	cExecuteForm('expressoMail1_2.imap_functions.import_msgs', document.form_import, handler);
+}
+function return_import_msgs(data, wfolders_tree){
+	if(data && data.error){
+		write_msg(data.error);
+	}
+	else{
+		if(data == 'Post-Content-Length')
+			write_msg(get_lang('The size of this message has exceeded  the limit (%1B).',Element('upload_max_filesize').value));
+		else {	/*
+			* @author Rommel Cysne (rommel.cysne@serpro.gov.br)
+			* @date 2009/05/15
+			* Foi colocado um teste para verificar se a pasta selecionada, passada como parametro,
+			* eh uma pasta local (qualquer uma)
+			*/
+			var er = /^local_/;
+			if ( er.test(wfolders_tree._selected.id) )
+			{
+				archive_msgs('INBOX/Lixeira/tmpMoveToLocal',wfolders_tree._selected.id,data);
+				cExecute('expressoMail1_2.imap_functions.delete_mailbox',function(){},'del_past=INBOX/Lixeira/tmpMoveToLocal');
+			}
+                         else{
+				write_msg(data);
+				arrayJSWin["import_window"].close();
+				if(openTab.imapBox[0] == wfolders_tree._selected.id)
+				{
+					openTab.imapBox[0] = '';
+					change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
+				} else{
+					refresh();
+				}
+			}
+	}
+    }
+
+}
+
+function select_import_folder(){
+	//Begin: Verify if the file extension is allowed.
+	var imgExtensions = new Array("eml","zip");
+	var inputFile = document.form_import.file_1;	
+	if(!inputFile.value){
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		return false;
+	}
+	var fileExtension = inputFile.value.split(".");
+	fileExtension = fileExtension[(fileExtension.length-1)];
+	var deniedExtension = true;
+	for(var i=0; i<imgExtensions.length; i++) {
+		if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) {
+			deniedExtension = false;
+			break;
+		}
+	}
+	if(deniedExtension) {
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		return false;
+	}
+	arrayJSWin['import_window'].close();
+	wfolders.makeWindow('null','import');
+}
+function import_calendar(data){
+	function handler_import_calendar(data){
+		if(data === true){
+			write_msg(get_lang("The event was imported successfully."));
+		}
+	}
+	if(confirm(get_lang("Do you confirm this import to your Calendar?"))){
+			cExecute('expressoMail1_2.db_functions.import_vcard&msg_folder='+data,handler_import_calendar);
+	}
+}
+function hack_sent_queue(data,rowid_message) {
+
+	if (data.success != true) {
+		queue_send_errors = true;
+		expresso_local_messages.set_problem_on_sent(rowid_message,data);
+	}
+	else {
+		expresso_local_messages.set_as_sent(rowid_message);
+		if(document.getElementById('_action')) { //Não posso manter esse elemento, pois o connector irá criar outro com o mesmo id para a próxima mensagem.
+			el =document.getElementById('_action');
+			father = el.parentNode;
+			father.removeChild(el);
+		}
+		send_mail_from_queue(false);
+	}
+}
+
+function send_mail_from_queue(first_pass) {
+	if(first_pass)
+		modal('send_queue');
+	var num_msgs = expresso_local_messages.get_num_msgs_to_send();
+	if (num_msgs <= 0) {
+		close_lightbox();
+		return;
+	}
+	document.getElementById('text_send_queue').innerHTML = get_lang('Number of messages to send:')+' '+num_msgs;	
+	var _hand_sendqueuemsg = function(data,rowid_message) {
+		hack_sent_queue(data,this.ID_tmp);
+	};
+	var msg_to_send = expresso_local_messages.get_form_msg_to_send();
+	if(!is_ie)
+		ID_tmp = msg_to_send.rowid.value;
+	else {//I.E kills me of shame...
+		for (var i=0;i<msg_to_send.length;i++) {
+			if(msg_to_send.elements[i].name=='rowid') {
+				ID_tmp = msg_to_send.elements[i].value;
+				break;
+			}
+		}
+	}
+
+	cExecuteForm("expressoMail1_2.imap_functions.send_mail", msg_to_send, _hand_sendqueuemsg,"queue_"+ID_tmp);
+}
+
+function check_mail_in_queue() {
+	var num_msgs = expresso_local_messages.get_num_msgs_to_send();
+	if(num_msgs>0) {
+		control = confirm(get_lang('You have messages to send. Want you to send them now?'));
+		if(control) {
+			send_mail_from_queue(true);
+		}
+		return true;
+	}
+	else {
+		return false;
+	}
+}
+
+function force_check_queue() {
+	if(!check_mail_in_queue()) {
+		write_msg(get_lang("No messages to send"));
+	}
+}
+
+function searchEmail(emailString){
+		var arrayInvalidEmails = new  Array();
+		arrayInvalidEmails[1] = '';		
+		var email;
+		var arrayEmailsFull = new Array();
+		arrayEmailsFull = emailString.split(',');
+		var er_Email =  new RegExp("<(.*?)>");
+		// TODO Use validateEmail of common functions	
+		var er_ValidaEmail = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$");
+
+		for (i=0; i < arrayEmailsFull.length; i++){
+			email = er_Email.exec(arrayEmailsFull[i]);
+			tempEmail = email == null  ? arrayEmailsFull[i]:email[1];
+			tempEmail = tempEmail.replace(/^\s+|\s+$/g,"");
+			if (tempEmail != '') {
+				singleEmail = er_ValidaEmail.exec(tempEmail);
+				
+				if (singleEmail == null) {
+					arrayInvalidEmails[0] = true;
+					arrayInvalidEmails[1] += (email == null ? arrayEmailsFull[i] : email[1]) + "; ";
+				}
+			}	
+		}
+		
+		return arrayInvalidEmails;
+};
Index: trunk/expressoMail1_2/js/base/drag_area.js
===================================================================
--- trunk/expressoMail1_2/js/base/drag_area.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/drag_area.js	(revision 3073)
@@ -0,0 +1,256 @@
+function DragArea()
+{
+	this.msg_number = false;
+	this.subject	= false;
+	this.folder		= '';
+	this.color_dd	= 'red';
+	this.from_list	= false;
+	this._mousemove = document.onmousemove;
+	this._mouseup = document.onmouseup;
+	this.div_dd = document.createElement("DIV");
+	this.id_messages_to_drag = new Array();
+	this.div_dd.style.position = 'absolute';
+	this.div_dd.style.zIndex = '15';
+	this.div_dd.style.border = '1px solid black';
+	this.div_dd.style.background ="#EEEEEE";
+	var value = "8.5";
+	this.div_dd.style.opacity = value/10;
+	this.div_dd.style.filter = 'alpha(opacity=' + value*10 + ')';	
+	this.div_dd.id = 'div_sel_messages';
+	this.div_dd.style.padding = "3px";
+	this.div_dd.style.width = "0px";
+	this.div_dd.style.height = "0px";
+	this.div_dd.style.display ='none';
+	this.envelope = new Image();
+	this.envelope.src = URL_SERVER + "expressoMail1_2/templates/"+template+"/images/envelope.png";
+	document.body.appendChild(this.div_dd);
+
+	XEvents.add( document, 'onmousemove', function( e )
+	{
+		var	_target = is_ie ? window.event.srcElement : e.target;
+		//if(_dragArea._mousemove)
+		//	_dragArea._mousemove(e);
+
+		//else
+			if( _dragArea && _dragArea.msg_number && _target.type != 'checkbox')
+			{
+				_dragArea.mouseMoveDrag( e );
+			}
+	} );
+
+	XEvents.add( document, 'onmouseup', function( e )
+	{
+		var	_event  = is_ie ? window.event : e;
+		var	_target = is_ie ? _event.srcElement : _event.target;
+		var _button = is_ie ? _event.button : _event.which;
+
+		if(_button != 2 && _button != 3) {		
+
+			if ( Element("div_rightbutton") && Element("div_rightbutton").style.display != 'none' )
+			{
+				if ( ! _target.id.match( /link_rightbutton_(.*)$/ ) )
+				{
+					var id_messages_to_drag = get_selected_messages();
+					id_messages_to_drag = id_messages_to_drag ? id_messages_to_drag.split(',') : id_messages_to_drag;
+
+					for(var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++)
+					{
+						Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
+						changeBgColor(_event ,id_messages_to_drag[i]);
+					}
+					Element("chkbox_sel_allmsg").checked = false;
+					Element('div_rightbutton').style.display = 'none';
+					_dragArea.msg_number = false;
+					_dragArea.div_dd.style.display ='none';
+					return false;
+				}
+			}
+			if(is_ie)
+				_dragArea.onSelectStart(true);
+
+			if ( Element("div_rightbutton_folder") && Element("div_rightbutton_folder").style.display != 'none' )
+			{
+				Element('div_rightbutton_folder').style.display = 'none';
+			}
+
+		}
+
+
+		if(_dragArea.msg_number)
+		{
+			var reg = /^((n|l)(?!root))(.*)tree_folders$/;
+			var new_folder;
+
+			if ( reg.test(_target.parentNode.id) )
+			{
+				new_folder = _target.parentNode.id.substring(1,_target.parentNode.id.length).replace('tree_folders','');
+				new_folder_name = new_folder.replace("INBOX"+cyrus_delimiter, "");
+				if(new_folder_name == 'INBOX')
+					new_folder_name = get_lang("Inbox");
+				if ( _dragArea.from_list )
+				{
+					if (numBox != 0)
+						move_search_msgs("content_id_search_" + numBox, new_folder, new_folder_name);
+					else
+						proxy_mensagens.proxy_move_messages("null", 'selected', 0, new_folder, new_folder_name);
+				}
+				else
+				{
+					var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
+					proxy_mensagens.proxy_move_messages("null", msg_number, msg_number + "_r", new_folder, new_folder_name);
+				}
+			}
+
+			else
+				if ( _dragArea.from_list && _target.type != 'checkbox' && _dragArea.div_dd.style.display !='none' )
+				{
+					var id_messages_to_drag = get_selected_messages( );
+					if( id_messages_to_drag )
+					{
+						id_messages_to_drag = id_messages_to_drag.split(',');
+
+						for ( var i = 0; id_messages_to_drag && i < id_messages_to_drag.length; i++ )
+						{
+							Element("check_box_message_"+id_messages_to_drag[i]).checked = false;
+							changeBgColor(_event ,id_messages_to_drag[i]);
+						}
+						Element("chkbox_sel_allmsg").checked = false;	
+					}
+				}
+
+			_dragArea.msg_number = false;
+			_dragArea.div_dd.style.display ='none';
+			if(is_ie)
+				_dragArea.onSelectStart(true);
+		}
+
+	} );
+}
+
+DragArea.prototype.makeMenuBox = function(element){
+
+	element.oncontextmenu = function(e)
+	{
+		return false;
+	};
+	
+	var _this = this;
+	
+	element.onmousedown = function (e)
+	{
+		var _button = is_ie ? window.event.button : e.which;
+
+		if(_button == 2 || _button == 3)
+		{
+			var boxFolder = element.id.substr(1,element.id.indexOf('tree_folders')-1);
+			var boxName = element.firstChild.nextSibling.innerHTML;
+			ConstructBoxMenu(is_ie ? window.event : e,boxName,boxFolder);
+		}
+				
+		return true;
+	};	
+	
+};
+
+DragArea.prototype.makeDragged = function(element, msg_number, subject, from_list, folder){
+	element.oncontextmenu = function(e) {
+		return false;
+	};
+	var _this = this;
+	element.onmousedown = function (e){
+
+		var _button = is_ie ? window.event.button : e.which;
+	
+		if(_button == 2 || _button == 3) {
+			var _checkb = Element("check_box_message_"+ msg_number);
+
+			if(_checkb) {
+				if(!_checkb.checked) {
+					changeBgColor(is_ie ? window.event : e, msg_number);
+					_checkb.checked = true;
+				}
+				ConstructRightMenu(is_ie ? window.event : e);
+			}			
+			return false;
+		}
+
+		if(!_this.msg_number) {
+			_this.msg_number = msg_number;
+
+			if(!subject)
+				_this.subject = get_lang("No Subject");
+			//else if(subject.length > 40)
+			//	_this.subject = subject.substring(0,40) + '...';				
+			else
+				_this.subject	 = subject;
+
+			_this.from_list  = from_list;
+			_this.div_dd.style.width = "auto";
+			_this.div_dd.style.height = "auto";			
+			_this.folder = folder;
+		}
+		return true;
+	};	
+};
+DragArea.prototype.showLayerDrag = function(e){
+
+	var msg_number = _dragArea.from_list ? _dragArea.msg_number : _dragArea.msg_number.replace('_r','');
+	if(_dragArea.from_list) {
+
+		if((Element("check_box_message_"+msg_number)) && (! Element("check_box_message_"+msg_number).checked)) {
+			if (is_ie)
+				changeBgColor(window.event,msg_number);
+			else
+				changeBgColor(e,msg_number);
+			Element("check_box_message_"+ msg_number).checked = true;	
+		}
+		id_messages_to_drag = get_selected_messages();
+		id_messages_to_drag = id_messages_to_drag ? id_messages_to_drag.split(',') : new Array();
+	
+		if(id_messages_to_drag.length > 1)
+			this.subject = id_messages_to_drag.length +" mensagens selecionadas";
+	}
+
+	this.div_dd.innerHTML = "<img align='center' src='"+this.envelope.src+"'>&nbsp;<span id='content_dd'><font color='red' weight='bold'><b>"+this.subject+"</b></span></font>";
+	this.div_dd.style.display ='';
+};
+
+DragArea.prototype.onSelectStart = function(value){
+	if(!value) {
+		document.body.onselectstart = function (e){return false;};
+		document.body.ondragstart = function (e){return false;};
+	}
+	else {
+		document.body.onselectstart = function (e){return true;};
+		document.body.ondragstart = function (e){return true;};
+	}
+};
+
+DragArea.prototype.mouseMoveDrag = function(e){		
+	
+	var	e  = is_ie ? window.event : e;
+	var	_target = is_ie ? e.srcElement : e.target;
+	if(is_ie)
+		this.onSelectStart(false);
+
+	this.div_dd.style.left	= e.clientX + 5 + document.body.scrollLeft;
+	this.div_dd.style.top 	= e.clientY + 10 + document.body.scrollTop;		
+
+	if(this.div_dd.style.display == 'none')
+		this.showLayerDrag(e);
+	
+	var reg = /^((n|l)(?!root))(.*)tree_folders$/;
+	var _color = this.color_dd;
+
+	if(reg.test(_target.parentNode.id) )
+		_color ='green';
+	else
+		_color ='red';
+	
+	if(this.color_dd != _color) {
+		Element('content_dd').innerHTML = "<font color='"+_color+"' weight='bold'><b>"+this.subject+"</b></font>";
+		this.color_dd = _color;
+	}
+
+	return false;
+};
Index: trunk/expressoMail1_2/js/base/wfolders.js
===================================================================
--- trunk/expressoMail1_2/js/base/wfolders.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/wfolders.js	(revision 3073)
@@ -0,0 +1,161 @@
+	function cWFolders()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this.alert = false;
+	}
+
+	cWFolders.prototype.makeWindowNew = function(border_id, type,from_search)
+	{ //Javascript doesn't seems to have polimorfism
+		_this = this;
+	
+		var el = document.createElement("DIV");
+		el.style.visibility = "hidden";
+		el.style.position = "absolute";
+		el.style.left = "0px";
+		el.style.top = "0px";
+		el.style.width = "0px";
+		el.style.height = "0px";
+		el.id = 'dJSWin_wfolders';
+		document.body.appendChild(el);
+		
+		el.innerHTML = "<table><tbody><tr><td>&nbsp</td><td>"+
+		"<div id='wfolders_content_tree' style='height:200px; width:250px; overflow:auto; background:#F7F7F7'></div>"+
+		"</td></tr></tbody></table>";
+
+		var space = document.createElement('SPAN');
+		space.innerHTML = "<BR>&nbsp;&nbsp;";
+		el.appendChild(space);
+
+		var butt = Element('dJSWin_wfolders_bok');
+		if (!butt){
+			butt = document.createElement('INPUT');
+			butt.id = 'dJSWin_wfolders_bok';
+			butt.type = 'button';
+			el.appendChild(butt);
+		}
+		if (type == 'save')
+				butt.value = get_lang('Save'); 
+		else if (type == 'send_and_file')
+                butt.value = get_lang('Send and file'); 
+		else if (type == 'move_to')
+			butt.value = get_lang('Move');
+		else if (type == 'change_folder')
+			butt.value = get_lang('Change folder');	
+		else //default value
+			butt.value = get_lang(type);
+
+		butt.onclick = function () {
+			wfolders.arrayWin[el.id].close();
+			if (type == 'save'){
+				save_as_msg(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption,true);
+			}
+			else if (type == 'send_and_file'){
+				send_message(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
+				wfolders.alert = true;
+			}
+			else if (type == 'move_to')	{
+				var msg_number =  (border_id ? border_id.replace('_r','') : 'selected');
+				if (border_id.match('search'))
+					move_search_msgs(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);	
+				else{
+					proxy_mensagens.proxy_move_messages('null',msg_number, border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
+					wfolders.alert = true;
+				}
+			}
+			else if (type == 'change_folder'){
+				change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
+				wfolders.alert = true;
+			}
+			else if (type == 'import'){
+				import_msgs(wfolders_tree);
+			}
+		};
+		if (type == 'save')
+			butt.value = get_lang('Save');
+		else if (type == 'send_and_file')
+			butt.value = get_lang('Send and file');
+
+		var space = document.createElement('SPAN');
+		space.innerHTML = "&nbsp;&nbsp;";
+		el.appendChild(space);
+
+		var butt = document.createElement('BUTTON');
+		var buttext = document.createTextNode(get_lang('Close'));
+		butt.appendChild(buttext);
+		butt.onclick = function () {wfolders.arrayWin[el.id].close();};
+		el.appendChild(butt);
+
+		wfolders_tree = new dFTree({name: 'wfolders_tree'});
+		if(!expresso_offline)
+			var n_root = new dNode({id:'root', caption:get_lang("My Folders")});
+		else
+			var n_root = new dNode({id:'local_root', caption:get_lang("local messages")});
+		wfolders_tree.add(n_root,'anything'); //Places the root; second argument can be anything.
+
+		var folders = tree_folders.getNodesList(cyrus_delimiter);
+		for (var i=1; i<folders.length; i++)
+		{
+			if (proxy_mensagens.is_local_folder(folders[i].id) && from_search) {
+				continue;
+			}
+			var nn = new dNode({
+				id: folders[i].id,
+				caption: lang_folder(folders[i].caption),
+				plusSign: folders[i].plusSign
+			});
+			wfolders_tree.add(nn, folders[i].parent);
+			
+		}
+		Element('wfolders_content_tree').innerHTML = ""; //As buscas nÃ£o podem incluir mover entre pastas locais, pelo menos por enquanto
+		wfolders_tree.draw(Element('wfolders_content_tree'));
+		n_root.changeState();
+		if(!expresso_offline)
+			wfolders_tree.getNodeById('INBOX')._select();
+		else
+			wfolders_tree.getNodeById('local_Inbox')._select();
+		_this.showWindow(el, type);
+	};
+
+	cWFolders.prototype.makeWindow = function(border_id, type)
+	{
+		this.makeWindowNew(border_id,type,false);
+	};
+	
+	cWFolders.prototype.showWindow = function (div, type)
+	{
+		if(! div) {
+			alert(get_lang("This list has no participants."));
+			return;
+		}
+		
+		if(! this.arrayWin[div.id]) {
+			div.style.width = "275px";
+			div.style.height = "250px";
+			var title = get_lang('Select a folder')+":";
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";
+			div.style.width = div.offsetWidth - 5;
+
+			win = new dJSWin({
+				id: 'win_'+div.id,
+				content_id: div.id,
+				width: wWidth,
+				height: wHeight,
+				title_color: '#3978d6',
+				bg_color: '#eee',
+				title: title,
+				title_text_color: 'white',
+				button_x_img: '../phpgwapi/images/winclose.gif',
+				border: true });
+			
+			this.arrayWin[div.id] = win;
+			win.draw();
+		}
+		else {
+			win = this.arrayWin[div.id];
+		}
+		win.open();
+	};
+	
+/* Build the Object */
Index: trunk/expressoMail1_2/js/base/abas.js
===================================================================
--- trunk/expressoMail1_2/js/base/abas.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/abas.js	(revision 3073)
@@ -0,0 +1,287 @@
+var openTab = {
+	'type' : [], // 8 types of tabs, further info. see expressolivre.org/dev/wiki/mail/Documentacao
+	'content_id' : [],
+	'imapUid' : [], // Stores the imap email number of current tab
+	'countFile' : [0,0,0,0,0,0,0,0,0,0], // Stores the number of files attached in current tab
+	'imapBox' : [], // Stores the folder name
+	'toPreserve' : [], // Check if the message should be removed from draft after send
+	'autosave_timer' : [] // The timeout timer for autosave function
+};
+var tabTypes = {
+	'new':4,
+	'forward':6,
+	'reply_with_history':7,
+	'reply_to_all_with_history':7,
+	'reply_without_history':7,
+	'reply_to_all_without_history':7,
+	'edit':5
+};
+var currentTab,numBox = 0; // Open Tab and num of mailboxes opened at context
+
+function setBorderAttributes(ID)
+{
+	this.border_id = "border_id_"+ID;
+	this.sequence = ID; 
+}
+
+
+function alternate_border(ID)
+{
+	if (! Element('border_id_'+ID))
+		return false; // Not possible to alternate
+	show_hide_span_paging(ID);
+	spanD = Element("span_D");
+	if (spanD)
+		spanD.style.display = (openTab.type[ID] == 0 ? '' : 'none');
+
+	var footer_menu = Element("footer_menu");	
+	if (footer_menu) {
+		footer_menu.style.display = (openTab.type[ID] != 4 ? '' : 'none');
+	}
+
+	var len = BordersArray.length;
+	for (var i=0; i < len; i++)
+	{
+		m = document.getElementById(BordersArray[i].border_id);
+		if ((m)&&(m.className == 'menu-sel'))
+		{
+			m.className = 'menu';
+			c = document.getElementById("content_id_"+BordersArray[i].sequence);
+			c.style.display = 'none';
+			if(Element("font_border_id_"+BordersArray[i].sequence))
+				Element("font_border_id_"+BordersArray[i].sequence).className = 'font-menu';	
+			var body = Element('body_'+BordersArray[i].sequence);
+			if (body)
+			{
+				try
+				{
+					if (Element('viewsource_rt_checkbox').checked)
+					{  
+						expresso.connector.loadScript("jscode/rich_text_editor");
+						if(typeof(RichTextEditor) == 'undefined'){
+							setTimeout('alernate_border(\''+ID+'\');',500);
+							return false;
+						}
+						RichTextEditor.viewsource(false);
+					}
+				}
+				catch(e)
+				{
+					//alert(e.message)
+				}
+			}
+		}
+	}
+
+	m = Element("border_id_"+ID);
+	if (m)
+		m.className = 'menu-sel';
+	if(Element("font_border_id_" + ID))
+		Element("font_border_id_" + ID).className = 'font-menu-sel';
+	var c = Element("content_id_"+ID);
+	if (c)
+		c.style.display = '';
+
+	body = document.getElementById('body_'+ ID);
+	if (body){
+		try{
+			if(ID){
+				expresso.connector.loadScript("jscode/rich_text_editor");
+				RichTextEditor.loadEditor(ID);
+			}
+			body.contentWindow.document.designMode="on";
+		}
+		catch(e){
+			//alert(e.message);
+		};
+	}
+
+	// hide the DropDrowContact, if necessary
+	window_DropDownContacts = Element('tipDiv');
+	if ((window_DropDownContacts)&&(window_DropDownContacts.style.visibility != 'hidden')){
+		window_DropDownContacts.style.visibility = 'hidden';
+	}
+
+	if (typeof(ID) == 'number')
+	{
+        numBox=ID;
+ 	}
+	else
+		if (ID.match("search_"))
+			numBox=ID.substr(7);
+
+	currentTab=ID;
+	return ID;
+}
+
+function create_border(borderTitle, id_value)
+{
+	if ( _dragArea == null )
+		_dragArea = new DragArea( );
+
+	var resize = false;
+	var offWidth = Element('border_blank').offsetWidth ? Element('border_blank').offsetWidth : Element('border_blank').clientWidth;
+	if (offWidth < 200) {
+		resize = resize_borders();
+		if (!resize){
+			alert(get_lang('Reached maximum tab limit'));
+			return false;
+		}
+	}
+	
+	if (! id_value) // Is new message?
+		var ID = parseInt(BordersArray[(BordersArray.length-1)].sequence) + 1;
+	else
+	{
+                if (Element("border_id_"+id_value)) // It's opened already!
+			return alternate_border(id_value);
+		var ID = id_value;
+		openTab.imapBox[ID] = current_folder;
+	}
+	td = document.createElement("TD");
+	td.id="border_id_" + ID;
+	if(resize) {
+		td.setAttribute("width", parseInt(resize)+"px");
+		td.style.width = parseInt(resize)+"px";
+	}
+	else
+		td.setAttribute("width", "200px");
+
+	td.setAttribute("align", "right");	
+	td.onclick = function(){alternate_border(ID);resizeWindow()}; 
+	td.setAttribute("noWrap","true");
+        td.alt = borderTitle;
+        td.title = borderTitle;
+	borderTitle = borderTitle ?  borderTitle : id_value ? get_lang("No Subject") : "&nbsp;"	;
+	td.value = borderTitle;
+	if (borderTitle.length > 21)
+		borderTitle = borderTitle.substring(0,21) + "...";
+
+	if (resize)
+		borderTitle = borderTitle.substring(0, resize*0.08);
+
+	td.innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + ID+" class='font-menu' width=*>" + borderTitle + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/close_button.gif'></td></tr></table>";
+
+	bb = document.getElementById("border_blank");
+	parent_bb = bb.parentNode; //Pego o tbody
+	parent_bb.insertBefore(td, bb);
+
+	if(! Element("border_id_"+id_value+"_r") ||((typeof(id_value) == 'string') && id_value.match(/_r$/)))
+		_dragArea.makeDragged(td, id_value,td.value);
+
+	BordersArray[BordersArray.length] = new setBorderAttributes(ID);
+
+	var div = document.createElement("DIV");
+	div.id = "content_id_" + ID;
+	div.className = "conteudo";
+	div.style.display='';
+
+	div.style.overflow = "hidden";
+	Element("exmail_main_body").insertBefore(div,Element("footer_menu"));
+	alternate_border(ID);
+	return ID;
+}
+
+function resize_borders()
+{
+	var children;
+	var	numBorders = 0;	
+	var widthTD = 0;
+	var newWidthTD = 0;		
+	children = Element('border_tr').childNodes;	
+	for (var i=0; i<children.length; i++) {
+		if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')) {
+			numBorders++;
+			if(!widthTD)
+				widthTD = children[i].clientWidth;				
+		}
+	}
+	if (numBorders > 8)
+		return false;
+	
+	newWidthTD = ((numBorders*widthTD)+(Element("border_blank").clientWidth-44))/(numBorders+1);
+	for (var i=0; i<children.length; i++) {
+		if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank')){
+			children[i].style.width = newWidthTD;
+			Element("font_"+children[i].id).innerHTML = Element("font_"+children[i].id).innerHTML.substring(0, newWidthTD*0.08);
+		}
+	}
+	return newWidthTD;
+}
+
+function delete_border(ID, msg_sent)
+{
+	var borderElem = Element("border_id_" + ID);
+	if (borderElem)
+		borderElem.onclick = null; // It's avoid a FF3 bug
+	else
+		return false;
+
+	if (msg_sent == 'false')
+	{
+		var body = document.getElementById('body_'+ ID);
+		if (body)
+		{
+				var save_link = Element("save_message_options_"+ID);
+				if (openTab.toPreserve[ID] == undefined);
+					openTab.toPreserve[ID] = false;
+				if ((! openTab.toPreserve[ID] && ! ID.toString().match("_r")) || ((body.contentWindow) == 'object' && body.contentWindow.document.designMode.toLowerCase() == 'on') && (save_link.onclick != ''))
+				{
+					var discard_msg = confirm(get_lang("Your message has not been sent. Discard your message?"), "");
+					if (!discard_msg)
+					{
+						Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
+						return;
+					}
+					else
+					{
+						if (openTab.imapBox[ID] &&  openTab.imapUid[ID] && !openTab.toPreserve[ID]){
+							delete_msgs(openTab.imapBox[ID], openTab.imapUid[ID].toString(), 0);
+							openTab.toPreserve[ID] = false;
+							}
+						delete(openTab.imapBox[ID]);	
+							// Element('to_'+ID).focus(); It crash on IE
+					}
+				}
+		}
+	}
+
+	openTab.toPreserve[ID] = false;
+	openTab.imapUid[ID] = 0;
+
+	if (preferences.auto_save_draft == 1)
+	{
+		if (openTab.autosave_timer[ID])
+			clearTimeout(openTab.autosave_timer[ID]);
+		openTab.autosave_timer[ID] = false;
+	}
+
+	expresso.connector.hold_session = false;
+	if (exist_className(Element('border_id_'+ID),'menu-sel'))
+	{
+		if (BordersArray[BordersArray.length-2].sequence == ID)
+			this.alternate_border(0);
+		else
+			this.alternate_border(BordersArray[BordersArray.length-2].sequence);
+	}
+
+	// Remove TD, title
+	border = Element('border_id_' + ID);
+	border.parentNode.removeChild(border);
+	var j=0;
+	var new_BordersArray = new Array();
+	for (i=0;i<BordersArray.length;i++)
+		if (document.getElementById(BordersArray[i].border_id) != null){
+			new_BordersArray[j] = BordersArray[i];
+			j++;
+		}
+	if(j == 1)
+		Element("footer_menu").style.display = '';
+	BordersArray = new_BordersArray;
+
+	// Remove Div Content
+	content = Element('content_id_' + ID);
+	content.parentNode.removeChild(content);
+	resizeWindow();
+	return true;
+};
Index: trunk/expressoMail1_2/js/base/doiMenuData.js
===================================================================
--- trunk/expressoMail1_2/js/base/doiMenuData.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/doiMenuData.js	(revision 3073)
@@ -0,0 +1,285 @@
+_icon_dir = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/';
+
+function ConstructMenuTools(){
+	// Layout padrão de menu = option1
+	var _divMenu = Element('menu_tools');
+	if(_divMenu)
+		return;
+	var _option1 = preferences.hide_folders == "1" ? false : true;
+								
+	if (!expresso_offline) {
+		var itens = new Array("preferences_mail()|" + get_lang("Preferences") + "|preferences.png",
+				"search_emails(\"\")|" + get_lang("Search") + "|search.png",
+				"filterbox()|" + get_lang("Edit filters") + "|filters.png",
+				"folderbox()|" + get_lang("Edit folders") + "|editfolders.png",
+				"sharebox()|" + get_lang("Share mailbox") + "|usersfolders.png",
+				"empty_trash_imap()|" + get_lang("Empty trash") + "|trash.png");
+		if(preferences.use_local_messages==1) {
+			if(expresso_local_messages.is_offline_installed()) {
+				itens.push("force_check_queue()|" + get_lang("Send from queue") + "|queue.jpg");
+			}
+		}
+	}
+	else {
+		var itens = new Array("search_emails(\"\")|" + get_lang("Search") + "|search.png",
+				"folderbox()|" + get_lang("Edit folders") + "|editfolders.png");	
+	}
+
+	var _link = Element('link_tools');
+	_divMenu = document.createElement("DIV");
+	_divMenu.id = "menu_tools";
+	_divMenu.style.position = "absolute";
+	_divMenu.style.top =  findPosY(_link) + (_option1 ? 19 : 14);
+	_divMenu.style.left = findPosX(_link) + (_option1 ? 22 : 22);
+	_divMenu.style.width = "auto";
+	_divMenu.style.height = "auto";
+	_divMenu.style.padding = "1px";
+	_divMenu.style.paddingTop = "0px";
+	_divMenu.style.zIndex = "10000";
+	_divMenu.style.backgroundColor = "WHITE";
+	_divMenu.style.border = "1px solid #999999";
+	_divMenu.style.borderTop = "0px solid #FFFFFF";
+	_divMenu.style.visibility = "hidden";
+	var _timeout = false;
+	_hideMenuTools = function () {		
+		Element('menu_tools').style.visibility = "hidden";	
+	};
+	_viewMenuTools = function () {
+		Element('menu_tools').style.visibility = "visible";
+	};
+
+	var _mouseover = _link.onmouseover;
+	
+	_link.onmouseover = function () {	
+		var _option1 = preferences.hide_folders == "1" ? false : true;
+		var _link = Element('link_tools');
+		Element('menu_tools').style.top =  findPosY(_link) + (_option1 ? 19 : 14);
+		if(_timeout) {
+			clearTimeout(_timeout);
+			_timeout=false;
+		}	
+		if(_mouseover) 
+			_mouseover(); 
+	
+		_timeout = setTimeout("_viewMenuTools();",500);
+	};
+	
+	_link.onmouseout  = function () {
+		if(_timeout) {
+			clearTimeout(_timeout);
+			_timeout=false;
+		}
+		if(_option1)
+			unset_menu_bg(Element("link_tools"));	
+		_timeout = setTimeout("_hideMenuTools();",500);
+	};
+
+	var _t = document.createElement("TABLE");
+	_t.cellPadding="0";
+	_t.cellSpacing="0";
+	_t.onmouseover = function () {	
+		if(_timeout) {
+			clearTimeout(_timeout);
+			_timeout=false;
+		}	
+		if(_mouseover) 
+			_mouseover(); 
+	
+		Element('menu_tools').style.visibility = "visible";
+	};
+	var _tbody = document.createElement("TBODY");
+	
+	var buildTr = function(value) {
+		var item = value.split('|');
+		var _tr = document.createElement("TR");
+		var _td = document.createElement("TD");
+		_td.innerHTML = '<img height="16px" src="' + _icon_dir + item[2]+'">&nbsp;'+item[1]+'&nbsp;';
+		_td.style.color = "DARKBLUE";
+		_td.style.cursor = "pointer";
+		if(_option1)
+			_td.style.border = '1px solid #f7f7f7';			
+		_td.onclick 	= function() { Element('menu_tools').style.visibility='hidden';eval(item[0]);};
+		_td.onmouseover = function () {
+			if(_timeout) {
+				clearTimeout(_timeout);
+				timeout=false;
+			}
+			
+			if(_option1)
+				set_menu_bg(this);
+			else {
+				this.style.textDecoration="underline";				
+				this.style.color = 'DARKORANGE';
+			}
+		};						
+		_td.onmouseout   = function () {
+			_timeout = setTimeout("_hideMenuTools();",500);
+			if(_option1){
+				unset_menu_bg(this);
+				unset_menu_bg(Element("link_tools"));
+			}else {		
+				this.style.backgroundColor = 'WHITE';
+				this.style.textDecoration="none";
+				this.style.color = 'DARKBLUE';
+			}
+		};		
+		_tr.appendChild(_td);
+		return _tr;
+	};
+	
+	for(i = 0; i < itens.length; i++)
+		_tbody.appendChild(buildTr(itens[i]));
+			
+	_t.appendChild(_tbody);
+	_divMenu.appendChild(_t);
+	document.body.appendChild(_divMenu);
+}
+
+function openListUsers(border_id) {
+	expresso.connector.loadScript("jscode/QuickCatalogSearch");
+	QuickCatalogSearch.showCatalogList(border_id);
+}
+
+function ConstructRightMenu(_event){
+
+	var div = Element("div_rightbutton");
+	if(!div){
+		div = document.createElement("DIV");
+		div.style.position = 'absolute';
+		div.style.zIndex = '15';
+
+		div.style.border = '1px outset BLACK';
+		div.style.background = "#EEEEE6";
+		div.id = 'div_rightbutton';
+		div.style.padding = "1px";
+		div.style.fontSize = is_ie || is_gecko1_5 || is_win ? "9pt" : "11pt";
+		div.style.width = "190px";
+		div.style.height = is_win && !is_ie ? "129px" : "139px";
+		div.style.display ='none';		
+		document.body.appendChild(div);
+		var _tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+		var _sep = "<hr>";
+		var optionsMenu = new Array( 
+			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('seen')+'|'+"proxy_mensagens.proxy_set_messages_flag('seen','get_selected_messages')",
+			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('unseen')+'|'+"proxy_mensagens.proxy_set_messages_flag('unseen','get_selected_messages')",
+			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('important')+'|'+"proxy_mensagens.proxy_set_messages_flag('flagged','get_selected_messages')",
+			_tab + get_lang("Mark as")+"&nbsp;"+get_lang('normal')+'|'+"proxy_mensagens.proxy_set_messages_flag('unflagged','get_selected_messages')",
+			_sep,
+			_tab + get_lang("Move to")+" ... |wfolders.makeWindow('', 'move_to')",
+			_tab + get_lang("Delete")+"|"+"proxy_mensagens.delete_msgs('null','selected','null')",
+			_tab + get_lang("Export")+"|"+"proxy_mensagens.export_all_messages()"
+		);
+
+		for(i = 0; i < optionsMenu.length; i++){
+			optionsMenu_l = optionsMenu[i].split('|');
+			var div_l = document.createElement("DIV");
+			div_l.style.padding = "1px";
+			div_l.style.width = "188px";
+			div_l.style.cursor = 'pointer';			
+			div_l.innerHTML = optionsMenu_l[0];
+			div_l.style.valign = 'top';
+			if(optionsMenu_l[0] != _sep) {
+				var attr = document.createAttribute('javascript');
+				attr.value = optionsMenu_l[1]+";Element('div_rightbutton').style.display = 'none';";
+				div_l.setAttributeNode(attr);
+				div_l.oncontextmenu = function(e) {	return false;};
+				div_l.onclick = function () {this.onmouseout();eval(this.getAttribute('javascript'));};
+				div_l.onmouseover = function () {this.style.color = 'WHITE';this.style.background = "#4a79cd";};
+				div_l.onmouseout = function ()  {this.style.color = 'BLACK';this.style.background = "#EEEEE6";};
+			}
+			else
+				div_l.style.height = "11px";
+				
+			div_l.id="link_rightbutton_"+i;
+			div.appendChild(div_l);
+		}
+	
+	}
+
+	var x = _event.clientX + document.body.scrollLeft +  2;
+	var y =  _event.clientY + document.body.scrollTop +  2;
+
+	var w_width  = is_ie ? document.body.clientWidth : window.innerWidth;
+	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
+
+	if(x + 218 > w_width)
+		div.style.left = w_width - (is_ie ? 198 : 218);	
+	else
+		div.style.left = x;
+	
+	if(y + 131 > w_height)
+		div.style.top =  w_height - (is_ie ? 125 : 131);	
+	else
+		div.style.top = y;	
+
+	div.style.display ='';
+} 
+
+function ConstructBoxMenu(_event,boxName,boxFolder){
+
+	var div = Element("div_rightbutton_folder");
+		if (div)
+			div.parentNode.removeChild(div);
+	
+		div = document.createElement("DIV");
+		div.style.position = 'absolute';
+		div.style.zIndex = '15';
+
+		div.style.border = '1px outset BLACK';
+		div.style.background = "#EEEEE6";
+		div.id = 'div_rightbutton_folder';
+		div.style.padding = "1px";
+		div.style.fontSize = is_ie || is_gecko1_5 || is_win ? "9pt" : "11pt";
+		div.style.width = "190px";
+		div.style.height = is_win && !is_ie ? "35px" : "33px";
+		div.style.display ='none';		
+		document.body.appendChild(div);
+		var _tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
+		var _sep = "<hr>";
+		var optionsMenu = new Array( 
+			_tab + get_lang("Open in new tab")+'|'+"open_folder('"+boxFolder+"', '"+boxName+"')",
+			_tab + get_lang("Edit folders")+'|'+"folderbox()"
+		);
+
+		for(i = 0; i < optionsMenu.length; i++){
+			optionsMenu_l = optionsMenu[i].split('|');
+			var div_l = document.createElement("DIV");
+			div_l.style.padding = "1px";
+			div_l.style.width = "188px";
+			div_l.style.cursor = 'pointer';			
+			div_l.innerHTML = optionsMenu_l[0];
+			div_l.style.valign = 'top';
+			if(optionsMenu_l[0] != _sep) {
+				var attr = document.createAttribute('javascript');
+				attr.value = optionsMenu_l[1]+";Element('div_rightbutton_folder').style.display = 'none';";
+				div_l.setAttributeNode(attr);
+				div_l.oncontextmenu = function(e) {	return false;};
+				div_l.onclick = function () {this.onmouseout();eval(this.getAttribute('javascript'));};
+				div_l.onmouseover = function () {this.style.color = 'WHITE';this.style.background = "#4a79cd";};
+				div_l.onmouseout = function ()  {this.style.color = 'BLACK';this.style.background = "#EEEEE6";};
+			}
+			else
+				div_l.style.height = "11px";
+				
+			div_l.id="link_rightbutton_folder"+i;
+			div.appendChild(div_l);
+		}
+
+	var x = _event.clientX + document.body.scrollLeft +  2;
+	var y =  _event.clientY + document.body.scrollTop +  2;
+
+	var w_width  = is_ie ? document.body.clientWidth : window.innerWidth;
+	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
+
+	if(x + 218 > w_width)
+		div.style.left = w_width - (is_ie ? 198 : 218);	
+	else
+		div.style.left = x;
+	
+	if(y + 131 > w_height)
+		div.style.top =  w_height - (is_ie ? 125 : 131);	
+	else
+		div.style.top = y;	
+
+	div.style.display ='';
+};
Index: trunk/expressoMail1_2/js/base/DropDownContacts.js
===================================================================
--- trunk/expressoMail1_2/js/base/DropDownContacts.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/DropDownContacts.js	(revision 3073)
@@ -0,0 +1,344 @@
+/**********************************************************************************\
+* Written by Joao Alfredo Knopik Junior (JakJr) <joao.alfredo@gmail.com>          *
+* ------------------------------------------------------------------------------- *
+*  This program is free software; you can redistribute it and/or modify it        *
+*  under the terms of the GNU General Public License as published by the	      *
+*  Free Software Foundation; either version 2 of the License, or (at your option) * 
+*  any later version.                                                             *
+\**********************************************************************************/
+// variavel global que salva o contato atual selecionado.
+var actualSelectedContact = 0;
+var setTimeOutLayer = 0;
+var div_message_scroll = 0;
+var tst_i = 0;
+function search_contacts(key_pressed, fld_id)
+{
+	div_message_scroll = Element('div_message_scroll_'+ fld_id.substring(fld_id.length - 1, fld_id.length));
+
+	var string_contacts = contacts;
+	if (Element(fld_id))
+		var mail = Element(fld_id).value;
+	else
+		return;
+	
+	var array_contacts = string_contacts.split(",");
+	var tmp = mail.split(",");
+	mail = trim(tmp[tmp.length - 1]);
+	tmp_mail = mail;
+	
+	seekDot = /\./gi;
+	mail = mail.replace(seekDot, "[.]");
+	mail = mail.replace('"', "&quot;");
+	mail = mail.replace("\n", "");
+	mail = mail.replace("\r", "");
+	mail = mail.replace("\t", "");
+	posX = findPosX(document.getElementById(fld_id));
+	posY = findPosY(document.getElementById(fld_id));
+
+	if ((!string_contacts) || (string_contacts.length==0) || (mail.length==0)){
+		hideTip();
+		return;
+	}
+		
+	if (mail.length == 0){
+		hideTip();
+		return;
+	}
+	
+	var RegExp_name = new RegExp("\\b"+mail, "i");
+	var RegExp_mail = new RegExp("^"+mail, "i");
+
+	var match_contacts = new Array();
+	var match_index = 0;
+
+	for (var i=0; i<array_contacts.length; i++){
+		tmp = array_contacts[i].split(";");
+		if ( (RegExp_name.test(tmp[0])) || (RegExp_mail.test(tmp[1])) ){
+			if (tmp[1])
+			{
+				var _tmp1 = RegExp_mail.exec(tmp[1]);
+				if ( _tmp1 )
+					tmp[1] = tmp[1].replace(RegExp_mail, _tmp1[0].bold());
+				var _tmp0 = RegExp_name.exec(tmp[0]);
+				if ( _tmp0 )
+					tmp[0] = tmp[0].replace(RegExp_name, _tmp0[0].bold());
+				match_contacts[match_index] = '&quot;' + tmp[0] + '&quot; &lt;' + tmp[1] + '&gt;';
+				match_index++;
+			}
+		}
+	}
+
+	if (match_contacts.length == 0){
+		hideTip();
+		return;
+	}
+
+	var lines = document.createElement('TABLE');
+	lines.style.fontFamily='Arial';
+	lines.style.font='12pt';
+	lines.style.color='#0000CF';
+	lines.border='0';
+	lines.cellpadding='0';
+	lines.cellspacing='0';
+
+	var match_cont = "";
+	for (var i=0; i<match_contacts.length; i++)
+	{
+		match_contacts[i] = unescape(match_contacts[i]); 
+		match_cont += match_contacts[i];
+
+		var trElement = document.createElement('TR');
+		var tdElement = document.createElement('TD');
+		tdElement.id = 'td_DD_'+i;
+		tdElement.name = fld_id;
+		XEvents.add( tdElement, 'onmousedown', function ( )
+		{
+			hideTip();
+			makeMailList(this.innerHTML,this.name);
+			setTimeout('document.getElementById("'+this.name+'").focus()',300);
+		} );
+		XEvents.add( tdElement, 'onmouseover', function( )
+		{
+			selectContact(this.id.substr(6));
+		} );
+		tdElement.innerHTML = match_cont;
+		trElement.appendChild(tdElement);
+		lines.appendChild(trElement);
+		match_cont = "";
+	}
+
+	// treat especials keys
+	// key ENTER
+	if ((key_pressed == 13) && (document.getElementById('tipDiv').style.visibility))
+	{
+		//Bug, sometimes the actualSelectedContact do not exist.
+		try{
+			makeMailList(document.getElementById('td_DD_' + actualSelectedContact).innerHTML,fld_id);
+			hideTip();
+		}
+		catch(e){}
+		return;
+	}
+	// key lostfocus
+	if ((key_pressed == 'lostfocus') && (document.getElementById('tipDiv').style.visibility)){
+		hideTip();
+		return;
+	}
+	// key DOWN
+	if ((key_pressed == 40) && (document.getElementById('tipDiv').style.visibility)){
+		if (actualSelectedContact != (match_contacts.length - 1)){
+			selectContact(actualSelectedContact + 1);
+		}
+		return;
+	}
+	// key UP
+	if ((key_pressed == 38) && (document.getElementById('tipDiv').style.visibility)){
+		if (actualSelectedContact != 0){			
+			selectContact(actualSelectedContact - 1);
+			return;
+		}
+	}
+	if (lines.childNodes.length > 0){
+		doTooltip(posX, posY, lines);
+	}
+	else
+		hideTip();
+		
+	return true;
+}
+
+function makeMailList(mail,fld_id)
+{
+	list = Element(fld_id);
+	for (var i = list.value.length; ((i!=0) && (list.value.substring(i-1,i)!=',')); i--) {  };
+	mail = mail.replace(/&lt;/g,"<");
+	mail = mail.replace(/&gt;/g,">");
+	mail = mail.replace(/<[bB]>/g,"");
+	mail = mail.replace(/<\/[bB]>/g,"");
+	if (i == 0)
+		list.value = list.value.substring(0,i) + mail + ', ';
+	else
+		list.value = list.value.substring(0,i) + ' ' + mail + ', ';
+}
+
+function selectContact(newContact){	
+	//Desabilitar o atual
+	var elAtual = document.getElementById('td_DD_' + actualSelectedContact);
+	if(elAtual)
+		elAtual.bgColor = "#efefef";	
+		
+	//Habilitar o novo.		
+	var elNew = document.getElementById('td_DD_' + newContact).bgColor = "#c0e0ff";
+	if(elNew)
+		elNew.bgColor = "#c0e0ff";
+
+	actualSelectedContact = newContact;
+}
+
+function doTooltip(x,y,msg) {
+	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
+	Tooltip.show(x,y,msg);
+}
+
+function hideTip() {
+	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
+	actualSelectedContact=0;
+	Tooltip.hide();
+}
+
+function findPosX(obj)
+{
+	var curleft = 0;
+	if (obj.offsetParent)
+	{
+		while (obj.offsetParent)
+		{
+			curleft += obj.offsetLeft;
+			obj = obj.offsetParent;
+		}
+	}
+	else if (obj.x)
+		curleft += obj.x;
+	return curleft;
+}
+
+function findPosY(obj)
+{
+	var curtop = 0;
+	if (obj.offsetParent)
+	{
+		while (obj.offsetParent)
+		{
+			curtop += obj.offsetTop;
+			obj = obj.offsetParent;
+		}
+	}
+	else if (obj.y)
+		curtop += obj.y;
+	return curtop;
+}
+
+function trim(inputString) {
+   if (typeof inputString != "string") 
+   	return inputString;
+      
+   var retValue = inputString;
+   var ch = retValue.substring(0, 1);
+   while (ch == " ") { 
+	  retValue = retValue.substring(1, retValue.length);
+	  ch = retValue.substring(0, 1);
+   }
+   ch = retValue.substring(retValue.length-1, retValue.length);
+   while (ch == " ") { 
+	  retValue = retValue.substring(0, retValue.length-1);
+	  ch = retValue.substring(retValue.length-1, retValue.length);
+   }
+   while (retValue.indexOf("  ") != -1) { 
+	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
+   }
+   return retValue; 
+}
+
+var Tooltip = {
+    overlaySelects: true,  // iframe shim for select lists (ie win)
+    offX: 0,
+    offY: 50,
+    tipID: "tipDiv",
+    showDelay: 0,
+    hideDelay: 0,
+    
+    ovTimer: 0, // for overlaySelects
+    ready:false, timer:null, tip:null, shim:null, supportsOverlay:false,
+  
+    init: function() {
+			if ( document.getElementById( this.tipID ) == null )
+			{
+				var el_dropdowncontact = document.createElement("DIV");
+				el_dropdowncontact.id = this.tipID;
+				document.body.appendChild(el_dropdowncontact);
+				this.supportsOverlay = this.checkOverlaySupport();
+				this.ready = true;
+			}
+    },
+    
+    show: function(x, y, msg) {
+        this.tip = document.getElementById( this.tipID );
+        this.writeTip(msg);
+        
+        this.positionTipStatic(x,y);
+   		this.handleOverlay(1, this.showDelay, x+this.offX,y+this.offY);
+		document.getElementById('td_DD_0').bgColor = "#c0e0ff";
+      	this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);
+    },
+    
+    writeTip: function(msg) {
+        if ( typeof this.tip != "undefined" ) {
+		this.tip.innerHTML = "";
+		this.tip.appendChild(msg);
+	}
+        this.tip.style.width = 'auto';
+    },
+    
+    positionTipStatic: function(x,y) {
+        if ( this.tip && this.tip.style ) {
+			this.tip.style.left = x + this.offX + "px";
+			this.tip.style.top = y + this.offY + "px";
+        }
+     },
+
+	scrollChanged: function() {
+		Element('tipDiv').style.visibility = 'hidden';
+		Tooltip.hide();
+	},
+
+    hide: function() {
+        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
+		this.handleOverlay(0, this.hideDelay);
+        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);
+        this.tip = null;  
+    },
+    
+  toggleVis: function(id, vis) { // to check for el_dropdowncontact, prevent (rare) error
+      var el_dropdowncontact = document.getElementById(id);
+      if (el_dropdowncontact) el_dropdowncontact.style.visibility = vis;
+  },
+
+	// check need for and support of iframe shim
+	checkOverlaySupport: function() {
+		return (is_ie);
+	}, 
+    
+	handleOverlay: function(bVis, d, x ,y) {
+		var _scrollY = div_message_scroll ? div_message_scroll.scrollTop : 0;
+        if(_scrollY > 0 && this.tip) {
+	        this.tip.style.top = (findPosY(this.tip) - _scrollY)+ "px";
+	    }
+		if ( this.overlaySelects && this.supportsOverlay ) {
+			if (this.ovTimer) { clearTimeout(this.ovTimer); this.ovTimer = 0; }
+			switch (bVis) {
+			case 1 :
+				if ( !document.getElementById('tipShim') ) 
+					document.body.insertAdjacentHTML("beforeEnd", '<iframe id="tipShim" src="about:blank" style="position:absolute; left:' + x + '; top:' + y + '; z-index:500; visibility:hidden" scrolling="no" frameborder="0"></iframe>');
+					this.shim = document.getElementById('tipShim'); 
+					if (this.shim && this.tip) {
+						this.shim.style.width = this.tip.offsetWidth + "px";
+                        this.shim.style.height = this.tip.offsetHeight + "px";
+                        this.shim.style.top = findPosY(this.tip)+ "px";
+					}
+					this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'visible')", d);
+				break;
+			case 0 :
+				this.ovTimer = setTimeout("Tooltip.toggleVis('tipShim', 'hidden')", d);
+				if (this.shim) this.shim = null;
+				break;
+			}
+		}
+	}
+};
+// Criar um estilo no html (tpl) com os seguintes parametros:
+//div#tipDiv {
+//  position:absolute; visibility:hidden; left:0; top:0; z-index:10000;
+//  background-color:#EFEFEF; border:1px solid #337;
+//  width:220px; padding:3px;
+//  color:#000; font-size:11px; line-height:1.2;
+//  cursor: default;
Index: trunk/expressoMail1_2/js/base/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/base/common_functions.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/common_functions.js	(revision 3073)
@@ -0,0 +1,711 @@
+if (!expresso_offline) {
+	var _showBar = showBar;
+	var _hideBar = hideBar;
+}
+
+function __showBar(){
+	_showBar();
+	resizeWindow();
+}
+
+function __hideBar(){
+	_hideBar();
+	resizeWindow();
+}
+showBar = __showBar;
+hideBar = __hideBar;
+
+XEvents.add( window, 'onresize', resizeWindow );
+// BEGIN: FUNCTION RESIZE WINDOW 
+function resizeWindow(){
+
+	var divScrollMain = Element("divScrollMain_"+numBox);
+	var table_message = Element("table_message");
+	var content_folders = Element("content_folders");
+	var clientHeight = ((window.innerHeight ? window.innerHeight : document.body.offsetHeight) - 8);
+	var clientWidth = ((window.innerWidth ? window.innerWidth : document.body.offsetWidth) - 17);
+  
+	if(divScrollMain){ 
+		divScrollMain.style.height = (clientHeight - (findPosY(divScrollMain) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px"; 
+	}
+
+	if(typeof(BordersArray) != 'undefined') {
+		for(var i = 1; BordersArray.length > 1 && i < BordersArray.length;i++) {
+			var div_scroll = Element("div_message_scroll_"+BordersArray[i].sequence);
+			var div = Element("content_id_"+BordersArray[i].sequence);
+
+			if(div){
+			 	div.style.height = (clientHeight - (findPosY(div) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight)+2)) + "px";
+			 	div.style.width = (clientWidth - (findPosX(div)+10)) + "px"; 
+			}
+			if(div_scroll){
+				div_scroll.style.height = (clientHeight - (findPosY(div_scroll) + (table_message.clientHeight ? table_message.clientHeight : table_message.offsetHeight))) + "px";
+				div_scroll.style.width = (clientWidth - (findPosX(div_scroll)+10)) + "px";
+			}
+		} 
+	} 
+			 		 
+ 	if(content_folders){ 
+ 		var search_div = Element("search_div");
+ 		var contentFoldersY = findPosY(content_folders);
+ 		content_folders.style.height = (clientHeight - (contentFoldersY + (contentFoldersY > findPosY(search_div) ? 0 : (search_div.clientHeight ? search_div.clientHeight : search_div.offsetHeight) + 5))) + "px";
+ 	} 
+}
+// END: FUNCTION RESIZE WINDOW
+
+var _beforeunload_ = window.onbeforeunload;
+
+window.onbeforeunload = function()
+{
+	return unloadMess();
+};
+
+function unloadMess(){
+	if (typeof(expresso_mail_sync) != "undefined" && expresso_mail_sync.working) {
+		var mess = get_lang("You're about archiving your e-mails from server. Do you really want to stop this action?");
+		return mess;
+	}
+	else {
+		var mess = get_lang("Your message has not been sent and will be discarted.");
+		for (var i = 0; i < BordersArray.length; i++) {
+			var body = Element('body_' + BordersArray[i].sequence);
+			if (body && body.contentWindow && body.contentWindow.document.designMode.toLowerCase() == 'on') {
+				return mess;
+			}
+		}
+	}
+}
+
+// Change the class of message.
+// In refresh, the flags UnRead and UnSeen don't exist anymore. 
+function set_msg_as_read(msg_number, selected){
+	tr_message = Element(msg_number);
+	if (exist_className(tr_message, 'tr_msg_unread'))
+		decrement_folder_unseen(1);
+	remove_className(tr_message, 'tr_msg_unread');
+	remove_className(tr_message, 'selected_msg');
+	Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/seen.gif' title='"+get_lang('Seen')+"'>";
+	return true;
+}
+
+function msg_is_read(msg_number, selected){
+	tr_message = Element(msg_number);
+	return !(tr_message && LTrim(tr_message.className).match('tr_msg_unread'));
+}
+
+function set_msg_as_unread(msg_number){
+	tr_message = Element(msg_number);
+	if ((exist_className(tr_message, 'tr_msg_read') || exist_className(tr_message, 'tr_msg_read2')) && (!exist_className(tr_message, 'tr_msg_unread')))
+		increment_folder_unseen(1);
+	remove_className(tr_message, 'selected_msg');
+	add_className(tr_message, 'tr_msg_unread');
+	Element("td_message_unseen_"+msg_number).innerHTML = "<img src ='"+URL_SERVER+"expressoMail1_2/templates/"+template+"/images/unseen.gif' title='"+get_lang('Unseen')+"'>";
+}
+
+function set_msg_as_flagged(msg_number){
+	var msg = Element(msg_number);
+	remove_className(msg, 'selected_msg');
+	add_className(msg, 'flagged_msg');
+	Element("td_message_important_"+msg_number).innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
+}
+
+function set_msg_as_unflagged(msg_number){
+	var msg = Element(msg_number);
+	remove_className(msg, 'selected_msg');
+	remove_className(msg, 'flagged_msg');
+	Element("td_message_important_"+msg_number).innerHTML = "&nbsp;&nbsp;&nbsp;";
+}
+
+
+function get_current_folder(){
+	return current_folder;
+}
+
+// Kill current box (folder or page).
+function kill_current_box(){
+	var box = document.getElementById("table_box");
+	if (box != null)
+		box.parentNode.removeChild(box);
+	else
+		return false;
+}
+
+// Kill current paging.
+function kill_current_paging(){
+	var paging = Element("span_paging");
+	if (paging != null)
+		paging.parentNode.removeChild(paging);
+}
+
+function show_hide_span_paging(ID){
+	if ((ID != "0") && Element("span_paging")) 
+		Element("span_paging").style.display = 'none';
+	else
+		if (Element("span_paging"))
+			Element("span_paging").style.display = '';
+}
+
+function download_local_attachment(url) {
+	if (div_attachment == null){
+		var div_attachment = document.createElement("DIV");
+		div_attachment.id="id_div_attachment";
+		document.body.appendChild(div_attachment);
+	}
+	div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='"+url+"'></iframe>";
+}
+
+function download_attachments(msg_folder, msg_number, idx_file, msg_part, encoding, new_file_name, show_iframe){
+	div_attachment = document.getElementById("id_div_attachment");
+	var params = '';
+	
+	if (div_attachment == null){
+		var div_attachment = document.createElement("DIV");
+		div_attachment.id="id_div_attachment";
+		document.body.appendChild(div_attachment);
+	}
+	if(new_file_name)
+		params = "&newfilename="+escape(new_file_name);
+	if(encoding)
+		params += "&encoding="+encoding;
+
+	div_attachment.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='expressoMail1_2/inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params+"'></iframe>";
+}
+
+function download_all_attachments(msg_folder, msg_number){
+	var handler_source = function(data){		
+		download_attachments(null, null, data, null,null,'anexos.zip');
+	};
+	cExecute("expressoMail1_2.exporteml.download_all_attachments",handler_source,"folder="+msg_folder+"&num_msg="+msg_number);
+}
+//ADD forwarded files
+function addForwardedFile(id_border,file_name,link){
+	divFiles = document.getElementById("divFiles_"+id_border);
+
+	if (! divFiles)
+		return false;
+	
+	if (divFiles.lastChild)
+		var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
+
+	if (! countDivFiles)
+		var countDivFiles = 1;
+	
+	divFile = document.createElement('DIV');
+	
+
+	if (!expresso_offline) {
+		if (!is_ie) {
+			var inputFile = document.createElement("INPUT");
+			
+			var tmp_id_border = document.createAttribute('id_border');
+			tmp_id_border.value = id_border;
+			
+			inputFile.setAttributeNode(tmp_id_border);
+			inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
+			inputFile.type = 'file';
+			inputFile.size = 50;
+			inputFile.maxLength = 255;
+			inputFile.name = 'file_' + countDivFiles;
+			inputFile.style.display = "none";
+		}
+		else {
+			var inputFile = document.createElement("link");
+			
+			var tmp_id_border = document.createAttribute('id_border');
+			tmp_id_border.value = id_border;
+			
+			inputFile.setAttributeNode(tmp_id_border);
+			inputFile.id = "inputFile_" + id_border + "_" + countDivFiles;
+			inputFile.name = 'file_' + countDivFiles;
+			
+			
+		}
+		
+	}
+	else {
+		var inputFile = document.createElement("input");
+		inputFile.type = 'hidden';
+		inputFile.name = 'offline_forward_' + countDivFiles;
+	}	
+	divFile.appendChild(inputFile);
+
+	var a_tmp = new Array();
+	a_tmp[0] = "local_";
+	a_tmp[1] = 'file_' + countDivFiles;
+	a_tmp[2] = file_name;
+	s_tmp = escape(expresso.connector.serialize(a_tmp));
+	var checkbox = document.createElement("INPUT");
+	checkbox.type = "checkbox";
+	checkbox.id = "checkbox_"+id_border+"_"+countDivFiles;
+	checkbox.name = "local_attachments[]";
+	
+	checkbox.value = s_tmp;
+	divFile.appendChild(checkbox);
+	
+	var link_attachment = document.createElement("A");
+	link_attachment.setAttribute("href", link);
+	
+	link_attachment.innerHTML = file_name;
+	divFile.appendChild(link_attachment);
+	
+	countDivFiles++;
+	divFile.id = "divFile_"+id_border+"_"+countDivFiles;	
+	divFiles.appendChild(divFile);
+
+	checkbox.checked = true; //IncrÃ­vel, mas no Internet Explorer o checked sÃ³ funciona efetivamente se o elemente jÃ¡ estiver renderizado... por isso sÃ³ aqui eu seleciono ele...
+	return inputFile;
+}
+
+// Add Input File Dynamically.
+function addFile(id_border){
+	divFiles = document.getElementById("divFiles_"+id_border);
+	if (! divFiles)
+		return false;
+	
+	if (divFiles.lastChild)
+		var countDivFiles = parseInt(divFiles.lastChild.id.split('_')[2]) + 1;
+
+	if (! countDivFiles)
+		var countDivFiles = 1;
+	
+	divFile = document.createElement('DIV');
+	
+	
+	divFile.innerHTML = "<input type='file' id_border='"+id_border+"' size='50' maxLength='255' onchange=\"function () {validateFileExtension(this.value, this.id.replace('input','div'), this.getAttribute('id_border'));};\" id='"+"inputFile_"+id_border+"_"+countDivFiles+"' name='file_"+countDivFiles+"'>";
+
+	
+	var linkFile = document.createElement("A");
+	linkFile.id = "linkFile_"+id_border+"_"+countDivFiles;
+	linkFile.href='javascript:void(0)';
+	linkFile.onclick=function () {removeFile(this.id.replace("link","div")); return false;};
+	linkFile.innerHTML=get_lang("Remove");	
+	//divFile.innerHTML += "&nbsp;&nbsp;";
+	divFile.appendChild(linkFile);
+	divFile.id = "divFile_"+id_border+"_"+countDivFiles;	
+	divFiles.appendChild(divFile);
+
+	
+
+	return document.getElementById("inputFile_"+id_border+"_"+countDivFiles);
+}
+
+var setTimeout_write_msg = 0;
+var old_msg = false;
+// Funcao usada para escrever mensagem
+// notimeout = True : mensagem nao apaga
+function write_msg(msg, notimeout){	
+	
+	if (setTimeout_write_msg)
+		clearTimeout(setTimeout_write_msg);
+	
+	var msg_div = Element('em_div_write_msg');
+	var old_divStatusBar = Element("divStatusBar");
+
+	if(!msg_div) {
+		msg_div = document.createElement('DIV');
+		msg_div.id = 'em_div_write_msg';
+		msg_div.className = 'em_div_write_msg';
+		old_divStatusBar.parentNode.insertBefore(msg_div,old_divStatusBar);
+	}
+	
+	if( document.getElementById('JabberMessenger'))
+		loadscript.adIcon();
+
+	msg_div.innerHTML = '<table width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><th width="40%"></th><th noWrap class="action_info_th">'+msg+'</th><th width="40%"></th></tr></tbody></table>';
+
+	old_divStatusBar.style.display = 'none';
+	msg_div.style.display = '';	
+	// Nao ponha var na frente!! jakjr
+	handle_write_msg = function(){
+		try{
+			if(!old_msg)
+				clean_msg();
+			else
+				write_msg(old_msg, true);			
+		}
+		catch(e){}
+	};
+	if(notimeout)
+		old_msg = msg;
+	else
+		setTimeout_write_msg = setTimeout("handle_write_msg();", 5000);
+}
+// Funcao usada para apagar mensagem sem timeout
+function clean_msg(){
+	old_msg = false;
+	var msg_div = Element('em_div_write_msg');
+	var old_divStatusBar = Element("divStatusBar");
+	if(msg_div)
+		msg_div.style.display = 'none';
+	old_divStatusBar.style.display = '';	
+}
+
+function make_body_reply(body, to, date_day, date_hour){
+	to = to.replace("<","&lt;");
+	to = to.replace(">","&gt;");
+	block_quoted_body ="<br><br>";
+	block_quoted_body += get_lang('At %1, %2 hours, %3 wrote:', date_day, date_hour, to);
+	block_quoted_body += "<blockquote style=\"border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;\">";
+	block_quoted_body += body;
+	block_quoted_body += "</blockquote>";
+	return block_quoted_body;
+}
+
+function make_forward_body(body, from, date, subject, to, cc){
+	from = from.replace(/</g,"&lt;");
+	from = from.replace(/>/g,"&gt;");
+	to = to.replace(/</g,"&lt;");
+	to = to.replace(/>/g,"&gt;");
+	var forward_body = '<BR><BR>---------- ' + get_lang('Forwarded message') + ' ----------<BR>';
+	forward_body += get_lang('From') + ': ' + from + '<BR>';
+	forward_body += get_lang('Date') + ': ' + date + '<BR>';
+	forward_body += get_lang('Subject') + ': ' + subject + '<BR>';
+	forward_body += get_lang('To') + ': ' + to+ '<BR>';
+	if(cc != undefined){
+		cc = cc.replace(/</g,"&lt;");
+		cc = cc.replace(/>/g,"&gt;");
+		forward_body += get_lang('CC') + ': ' + cc+ '<BR><BR>';
+	}
+	forward_body += body;
+	return forward_body;
+}
+
+function emMessageSearch(e,value){
+	var	e  = is_ie ? window.event : e;
+	if(e.keyCode == 13) {
+		search_emails(value);
+	}
+}
+
+function emQuickSearch(emailList, field, ID){
+	var quickSearchKeyBegin;
+	var quickSearchKeyEnd;
+	if(expresso_offline) {
+		alert(get_lang('Not allowed in offline mode'));
+		return;
+	}
+		
+	var handler_emQuickSearch = function(data)
+	{
+		window_DropDownContacts = Element('tipDiv');
+		if (window_DropDownContacts.style.visibility != 'hidden'){
+			window_DropDownContacts.style.visibility = 'hidden';
+		}
+		
+		if ((!data.status) && (data.error == "many results")){
+			alert(get_lang('More than %1 results. Please, try to refine your search.',200));
+			return false;
+		}
+			
+		if (data.length > 0){
+			if ((field != 'null') && (ID != 'null'))
+			{
+				expresso.connector.loadScript("jscode/QuickCatalogSearch");
+				if (typeof(QuickCatalogSearch) == 'undefined'){
+					setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
+					return false;
+				}
+				QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
+			}
+			else
+			{
+				expresso.connector.loadScript("jscode/QuickSearchUser");
+				if (typeof(QuickSearchUser) == 'undefined'){
+					setTimeout('emQuickSearch("'+emailList+'", "'+field+'", "'+ID+'")',500);
+					return false;
+				}
+				QuickSearchUser.showList(data);
+			}
+		}
+		else
+			alert(get_lang('None result was found.'));
+		return true;
+	};
+	
+	if ((field != 'null') && (ID != 'null'))
+	{
+		Element(field +'_'+ ID).focus(); //It requires for IE.
+		var i = getPosition(Element(field +'_'+ ID)); //inputBox.selectionStart;
+		var j = --i;
+
+		// Acha o inicio
+    	while ((j >= 0) && (emailList.charAt(j) != ',')){j--};
+	    quickSearchKeyBegin = ++j;
+
+	    // Acha o final
+    	while ((i <= emailList.length) && (emailList.charAt(i) != ',')){i++};
+	    quickSearchKeyEnd = i;
+
+	    // A Chave da Pesquisa
+    	var search_for = trim(emailList.substring(quickSearchKeyBegin, quickSearchKeyEnd));
+	}
+	else
+		var search_for = emailList;
+	
+	if (search_for.length < preferences.search_characters_number){
+            alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
+            return false;
+	}
+	
+	cExecute ("expressoMail1_2.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
+}
+
+function folderbox(){
+	expresso.connector.loadScript("jscode/TreeS");
+	if (typeof(ttree) == 'undefined'){ 
+		setTimeout('folderbox()',500); 
+		return false; 
+	} 
+	ttree.make_Window();
+}
+
+function filterbox(){
+	expresso.connector.loadScript("jscode/filter");
+	expresso.connector.loadScript("jscode/filters");
+	if (typeof(filters) == 'undefined') 
+	{ 
+		setTimeout('filterbox()',500); 
+		return false; 
+	} 
+	filters.Forms();
+}
+
+function sharebox(){
+	var handler_imap_getacl = function(data)
+	{
+		var options = '';
+		for (var x in data)
+		{
+			options += "<option value='"+data[x].uid+"'>"+data[x].cn+"</option>";
+		}
+		expresso.connector.loadScript("jscode/sharemailbox");
+		if (typeof(sharemailbox) == 'undefined') 
+		{ 
+			setTimeout('sharebox()',500); 
+			return false; 
+		} 
+		sharemailbox.makeWindow(options);
+	};
+	cExecute ("expressoMail1_2.imap_functions.getacl", handler_imap_getacl);
+}
+
+function preferences_mail(){
+	location.href="../preferences/preferences.php?appname=expressoMail1_2";
+}
+
+function search_emails(value){
+	expresso.connector.loadScript("TreeS");
+	expresso.connector.loadScript("jscode/search");
+        if (typeof(EsearchE) == 'undefined' || typeof(ttree) == 'undefined'){ 
+                setTimeout('search_emails("'+value+'")',500); 
+                return false; 
+        } 
+	EsearchE.showForms(value);
+}
+
+function source_msg(id_msg,folder){
+	var num_msg = id_msg.substr(0,(id_msg.length - 2));
+	var handler_source = function(data){
+		download_attachments(null, null, data, null,null,'fonte_da_mensagem.eml');
+	};
+	cExecute("expressoMail1_2.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
+}
+
+function Element (el) {
+	return	document.getElementById(el);
+}
+
+function getPosition(obj)
+{
+	if(typeof obj.selectionStart != "undefined")
+	{
+    	return obj.selectionStart;
+	}
+	else if(document.selection && document.selection.createRange)
+	{
+		var M = document.selection.createRange();
+		try
+		{
+			var Lp = M.duplicate();
+			Lp.moveToElementText(obj);
+		}
+		catch(e)
+		{
+			var Lp=obj.createTextRange();
+		}
+		
+		Lp.setEndPoint("EndToStart",M);
+		var rb=Lp.text.length;
+		
+		if(rb > obj.value.length)
+		{
+			return -1;
+		}
+		return rb;
+	}
+};
+
+function increment_folder_unseen(num){
+	if (num < 0)
+		return decrement_folder_unseen(num*-1);
+	else if(num == 0)
+		return;
+	var folder_id = get_current_folder();
+
+	var folder_unseen = Element('dftree_'+folder_id+'_unseen');
+	var abas_unseen = Element('new_m').innerHTML;
+        abas_unseen = abas_unseen.match(/[0-9]+/);
+
+	if (folder_unseen)
+	{
+		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) + num);
+	}
+	else
+	{
+		tree_folders.getNodeById(folder_id).alter({caption: tree_folders.getNodeById(current_folder).caption + '<font style=color:red>&nbsp(</font><span id="dftree_'+current_folder+'_unseen" style=color:red>'+num+'</span><font style=color:red>)</font>'});
+		tree_folders.getNodeById(folder_id)._refresh();
+	}
+	if (abas_unseen)
+	{
+		abas_unseen = parseInt(abas_unseen) + num;
+		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
+	}
+	else{
+		abas_unseen = Element('new_m').innerHTML;
+		abas_unseen = abas_unseen.match( /[0-9]+/);
+		abas_unseen = parseInt(abas_unseen) + num;
+		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
+	}
+	if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
+	{
+		var _disp_unseenshfolder = Element('dftree_user_unseen');
+		if ( _disp_unseenshfolder )
+			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( _disp_unseenshfolder.innerHTML) + num ) + '</span><font style=color:red>]</font>' + get_lang("Shared folders")});
+		else
+			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">1</span><font style=color:red>]</font>' + get_lang("Shared folders")});
+		tree_folders.getNodeById( 'user' )._refresh();
+	}
+	var _disp_unseen_mb = Element('dftree_root_unseen');
+	if(!expresso_offline)
+		var node_to_refresh = 'root';
+	else
+		var node_to_refresh = 'local_root';
+	tree_folders.getNodeById( node_to_refresh )._refresh();
+}
+function decrement_folder_unseen(num){
+	var folder_id = get_current_folder();
+
+	var folder_unseen = Element('dftree_'+folder_id+'_unseen');
+	var abas_unseen = Element('new_m').innerHTML;
+        abas_unseen = abas_unseen.match( /[0-9]+/);
+
+	if(!folder_unseen || !abas_unseen)
+		return;
+
+	if ((folder_unseen) && (parseInt(folder_unseen.innerHTML) > num))
+	{
+		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - num);
+	}
+	else if (parseInt(folder_unseen.innerHTML) <= num)
+	{
+		var tmp_folder_name = tree_folders.getNodeById(folder_id).caption.split('<');
+		var folder_name = tmp_folder_name[0];
+		tree_folders.getNodeById(folder_id).alter({caption: folder_name});
+		tree_folders.getNodeById(folder_id)._refresh();
+	}
+	if ((abas_unseen) && (parseInt(abas_unseen) > num))
+        {
+	        abas_unseen = (parseInt(abas_unseen) - num);
+	        Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
+	}
+	else if (parseInt(abas_unseen) <= 1)
+	{
+		Element('new_m').innerHTML = '0';
+	}
+	if ( current_folder.indexOf( 'INBOX' ) !== 0 )
+	{
+		var _disp_unseenshfolder = Element('dftree_user_unseen');
+		if ( _disp_unseenshfolder )
+		{
+			var _useen_shfolder = parseInt( _disp_unseenshfolder.innerHTML );
+			_useen_shfolder--;
+			if ( _useen_shfolder > 0 )
+				tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + _useen_shfolder + '</span><font style=color:red>]</font>' + get_lang("My Folders")});
+			else
+				tree_folders.getNodeById( 'user' ).alter({caption:get_lang("Shared folders")});
+			tree_folders.getNodeById( 'user' )._refresh();
+		}
+	}
+	var _disp_unseen_mb = Element('dftree_root_unseen');
+	if ( _disp_unseen_mb )
+	{
+		var unseen_in_mailbox = parseInt( _disp_unseen_mb.innerHTML );
+		unseen_in_mailbox--;
+		//if ( unseen_in_mailbox > 0 )
+		//	tree_folders.getNodeById( 'root' ).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
+		if(!expresso_offline)
+			var node_to_refresh = 'root';
+		else
+			var node_to_refresh = 'local_root';
+		tree_folders.getNodeById( node_to_refresh ).alter({caption:get_lang("My Folders")});
+		tree_folders.getNodeById( node_to_refresh )._refresh();
+	}
+}
+
+//changes MENU background color.
+function set_menu_bg(menu)
+{
+	menu.style.backgroundColor = 'white';
+	menu.style.border = '1px solid black';
+	menu.style.padding = '0px 0px';
+}
+//changes MENU background color.
+function unset_menu_bg(menu)
+{
+	menu.style.backgroundColor = '';
+	menu.style.border = '0px';
+	menu.style.padding = '1px 0px';
+}
+
+function array_search(needle, haystack) {
+	var n = haystack.length;
+	for (var i=0; i<n; i++) {
+		if (haystack[i]==needle) {
+			return true;
+		}
+	}
+	return false;
+}
+
+function lang_folder(fn) {
+ 	if (fn.toUpperCase() == "INBOX") return get_lang("Inbox");
+ 	if (special_folders[fn] && typeof(special_folders[fn]) == 'string') {
+ 		return get_lang(special_folders[fn]);
+ 	}
+ 	return fn;
+}
+
+function select_all_messages(select)
+{
+	var main = Element("tbody_box");
+	var main_list = main.childNodes;
+	var len_main_list = main_list.length;
+	
+	if (select)
+	{
+		for (i=0; i<len_main_list; i++)
+		{
+			Element("check_box_message_"+main_list[i].id).checked = true;
+			add_className(Element(main_list[i].id), 'selected_msg');
+		}
+	}
+	else
+	{
+		for (i=0; i<len_main_list; i++)
+		{
+			Element("check_box_message_"+main_list[i].id).checked = false;
+			remove_className(Element(main_list[i].id), 'selected_msg');
+		}
+	}
+};
Index: trunk/expressoMail1_2/js/base/globals.js
===================================================================
--- trunk/expressoMail1_2/js/base/globals.js	(revision 3073)
+++ trunk/expressoMail1_2/js/base/globals.js	(revision 3073)
@@ -0,0 +1,74 @@
+var debug = false;
+var _bTime = new Date();
+_bTime = _bTime.getTime();
+var queue_send_errors = false;
+var current_page = 1;
+var current_folder = '';
+var id_menu_folders = '';
+var preferences = '';
+var contacts = '';
+var search_box_type = 'ALL';
+var sort_box_type = 'SORTARRIVAL';
+var sort_box_reverse = 1;
+var last_message_selected = '';
+var cyrus_delimiter = '';
+var ccaddress_array = new Array();
+var ccoaddress_array = new Array();
+var toaddress_array = new Array();
+var tree_folders = '';
+var folders = new Array();
+var global_search = 1;
+var title_app_menu = '<table align=center border=0 width=100% cellspacing=0 cellpadding=2>'+
+	'<tr><td align=left height=16px width="1%" nowrap class="table_top">&nbsp;'+
+	'<a href=# onclick="javascript:new_message(\'new\',\'null\')" align=left>'+
+	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/createmail.gif">'+
+	'&nbsp;Novo</a>&nbsp;&nbsp;'+
+	'<a href="#" onclick="javascript:wfolders.makeWindow(\'\', \'change_folder\')" align=left>'+
+	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/editfolders.png">'+
+	'&nbsp;Trocar Pasta</a>&nbsp;&nbsp'+	
+	'<a href="#" onclick="javascript:refresh();" align=left>'+
+	'<img src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/checkmail.gif">'+
+	'&nbsp;Atualizar</a>&nbsp;&nbsp;'+
+	'<a id="link_tools" href="#" align=left>'+
+	'<img height="16px" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/menu/tools.gif">'+
+	'&nbsp;Ferramentas...</a>&nbsp;&nbsp;</td><td style="padding-left:17px" width="1%" id="content_quota" align=left nowrap></td><td width=* id="div_menu_c3" align="right"></td></tr></table>';
+
+var title_app = '<table height="16px" border=0 width=100% cellspacing=0 cellpadding=2>'+
+	'<tr>'+
+	'<td style="padding-left:17px" width=33% id="content_quota" align=left></td>'+
+	'<td class="divAppboxHeader" width=33% id="main_title">Expresso Mail</td>'+
+	'<td width=33% id="div_menu_c3" align=right></td>'+
+	'</tr></table>';
+
+var divStatusBar = document.getElementById("divStatusBar");
+var denyFileExtensions = new Array('exe','com','reg','chm','cnf','hta','ins','jse','job','lnk','pif','src','scf','sct','shb','vbe','vbs','wsc','wsf','wsh','cer','its','mau','','mda','mar','mdz','prf','pst');
+
+var special_folders = new Array(4);
+special_folders[ 'Trash' ] = 'Trash';
+special_folders[ 'Drafts' ] = 'Drafts';
+special_folders[ 'Spam' ] = 'Spam';
+special_folders[ 'Sent' ] = 'Sent';
+var trashfolder = 'Trash';
+var draftsfolder = 'Drafts';
+var sentfolder = 'Sent';
+var spamfolder = 'Spam';
+var token_param = '';
+var expresso_offline = false;
+
+var RichTextEditor = null;
+var _dragArea = null;
+var InfoContact = null;
+
+var _connector = new XConnector( {
+	"path" : URL_SERVER,
+	"controller" : "controller.php?action="
+} );
+
+var BordersArray = new Array();
+var expresso_local_messages;
+var proxy_mensagens;
+var wfolders;
+var use_spam_filter;
+
+var loading_img = document.createElement( 'center' );
+loading_img.appendChild( createAndSet("IMG",['src','style'],[URL_SERVER+'phpgwapi/templates/'+template+'/images/loading.gif','padding-top: 20px']) );
Index: trunk/expressoMail1_2/index.php
===================================================================
--- trunk/expressoMail1_2/index.php	(revision 2794)
+++ trunk/expressoMail1_2/index.php	(revision 3073)
@@ -147,20 +147,23 @@
 $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscalendar', 'calendar-setup', 'expressoMail1_2' );
 $GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscalendar', 'lang/calendar-br', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'globals', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'sniff_browser', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'common_functions', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'abas', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'doiMenuData', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'drag_area', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'draw_api_messages', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'draw_messages', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'draw_api_folders', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'DropDownContacts', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'InfoContact', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'local_messages', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'messages_controller', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'rich_text_editor', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'wfolders', 'expressoMail1_2' );
-$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'main', 'expressoMail1_2' );
+
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'main', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'abas', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'doiMenuData', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'drag_area', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'draw_api_folders', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'DropDownContacts', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'globals', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'wfolders', 'expressoMail1_2' );
+$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'base', 'common_functions', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'draw_messages', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'sniff_browser', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'draw_api_messages', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'InfoContact', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'local_messages', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'messages_controller', 'expressoMail1_2' );
+//$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'rich_text_editor', 'expressoMail1_2' );
+
+
 
 if ( $GLOBALS[ 'phpgw_info' ][ 'user' ][ 'preferences' ][ 'expressoMail' ][ 'use_shortcuts' ] )
