Index: trunk/expressoMail1_2/js/jscode/drag_area.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/drag_area.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/drag_area.js	(revision 2517)
@@ -0,0 +1,251 @@
+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 = "templates/"+template+"/images/envelope.png";
+	document.body.appendChild(this.div_dd);
+	
+}
+
+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;
+}	
+
+var _dragArea = new DragArea();
+
+document.onmousemove = function(e) {
+	var	_target = is_ie ? window.event.srcElement : e.target;
+	if(_dragArea._mousemove)
+		_dragArea._mousemove(e);
+	
+	else if(_dragArea.msg_number && _target.type != 'checkbox') {
+		_dragArea.mouseMoveDrag(e);
+	}
+};
+
+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("chk_box_select_all_messages").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("chk_box_select_all_messages").checked = false;			
+			}
+		}
+	
+		_dragArea.msg_number = false;
+		_dragArea.div_dd.style.display ='none';
+		if(is_ie)
+			_dragArea.onSelectStart(true);
+	}
+
+};
Index: trunk/expressoMail1_2/js/jscode/abas.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/abas.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/abas.js	(revision 2517)
@@ -0,0 +1,277 @@
+var BordersArray = new Array();
+BordersArray[0] = new setBorderAttributes(0);
+
+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)
+{
+	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);};
+	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='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='';
+
+	var bar = document.getElementById("toolbar");
+	var offset = 0;
+	if(bar.style.visibility != 'hidden')
+		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;
+
+	div.style.height = document.body.clientHeight - offset - (is_ie ? 76 : 86);
+	div.style.overflow = "hidden";
+
+	if(!is_ie) {
+		var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
+		var defaultWidth = document.body.clientWidth - 27;
+		if(!menuHidden)
+			defaultWidth -= Element("folderscol").offsetWidth;
+
+		div.style.width = defaultWidth;
+	}
+	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);
+	return true;
+}
Index: trunk/expressoMail1_2/js/jscode/InfoContact.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/InfoContact.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/InfoContact.js	(revision 2517)
@@ -0,0 +1,177 @@
+ function emInfoContact()
+{
+	this.email = "";
+	this.timeout = null;
+	this.timeout_hide = null;
+	this._mousemove = document.onmousemove;
+	this.td;
+	this.createCard();
+}
+
+emInfoContact.prototype.createCard = function(){
+	var pic= new Image(); 
+	pic.src="./templates/"+template+"/images/card.gif"; 
+	card = document.createElement("DIV");
+	card.id = "card_cc";
+	card.style.display = "none";
+	card.style.width = "244px";
+	card.style.backgroundImage = "url("+pic.src+")";
+	card.style.height = "134px";
+	card.style.position = "absolute";
+	card.innerHTML = "<table onmouseout='InfoContact.timeout_hide=setTimeout(\"InfoContact.hide()\",50);' onmouseover='clearTimeout(InfoContact.timeout_hide);' cellpadding=0 cellspacing=0 width='100%' height='100%'><tr><td valign='center' align='center' id='card_cc_td'></td></tr></table>";
+	document.body.appendChild(card);
+}
+emInfoContact.prototype.begin = function(td, email){
+
+	var card = Element("card_cc");
+	
+	if(this.td != td){
+		this.email = email;
+		this.td = td;
+		clearTimeout(this.timeout);
+	}
+	this.timeout = setTimeout("InfoContact.search('"+email+"')",1000);		
+}
+
+emInfoContact.prototype.label = function (text){
+	InfoContact.hide();
+	var div_label = Element("div_label");
+	if(!div_label) {
+		div_label = document.createElement("DIV");
+		div_label.id = "div_label";
+		div_label.style.padding = "2px";
+		div_label.style.display = "none";
+		div_label.style.position = "absolute";
+		div_label.style.border = "1px solid black";
+		div_label.style.backgroundColor="#FFFFDC";
+		document.body.appendChild(div_label);
+	}
+	div_label.innerHTML = text;
+	div_label.style.top = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
+	div_label.style.left = findPosX(this.td) + 20;
+	div_label.style.display = '';
+	setTimeout("InfoContact.hide()",1000);
+}
+
+emInfoContact.prototype.connectVoip = function (phoneUser, typePhone){
+	var handler_connectVoip = function(data){
+		if(!data) {
+			alert(get_lang("Error contacting VoIP server."));
+		}
+		else{
+			alert(get_lang("Requesting a VoIP call")+":\n"+data);
+		}
+	}
+	cExecute ("$this.functions.callVoipConnect&to="+phoneUser+"&typePhone="+typePhone, handler_connectVoip);
+}
+
+emInfoContact.prototype.show = function (data){
+	var _this = this;
+	var card = Element("card_cc");
+	card.style.left = findPosX(this.td) + 20;
+	var y = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
+	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
+	if(y + 160 > w_height)
+		card.style.top =  y - 160;	
+	else
+		card.style.top = y;		
+	card.style.display = '';
+	var cn = data.cn;
+	if(cn && cn.toString().length > 35)
+		cn = cn.toString().substring(0,30) + "...";
+	
+	var phoneUser = data.telefone;
+	if(preferences.voip_enabled && phoneUser) {
+		phoneUser = "<a title=\""+get_lang("Call to Comercial Number")+"\" href=\"#\" onclick=\"InfoContact.connectVoip('"+phoneUser+"', 'com')\">"+phoneUser+"</a>";
+		if(data.mobile){
+			phoneUser += " / <a title=\""+get_lang("Call to Mobile Number")+"\" href=\"#\" onclick=\"InfoContact.connectVoip('"+data.mobile+"', 'mob')\">"+data.mobile+"</a>";
+		}
+	}
+
+	Element("card_cc_td").innerHTML = "<table cellpadding=0 cellspacing=0 border=0 height='100%' width='100%'><tr><td width='70' height='93' style='padding-top:5px;padding-left:6px' align='center' valign='center'>"+
+										"<img src='./inc/show_img.php?email="+data.email+"'></td><td style='padding-left:2px' align='left' valign='top'>"+
+										"<br><img align='center' src='templates/"+template+"/images/"+(data.type)+"_catalog.png'><font size=1 color=BLACK>&nbsp;<b>"+get_lang("Sender's Information")+"</b></font>"+
+										_this.verifyIM(data.uid,data.email)+
+										"<br><img align='center' src='templates/"+template+"/images/phone.gif'>&nbsp;<font  size=1  color=BLACK>"+(phoneUser ? phoneUser : get_lang("None") )+"</font>"+
+										"</td></tr><tr><td valign='top' align='center' colspan='2'>"+
+										"<font size=1 color=BLACK>"+cn+"</font>"+
+										"<br><span title='"+get_lang("Write message")+"' style='cursor:pointer' onclick='InfoContact.sendMail(\""+cn+"\",\""+data.email+"\")'><font size=1 color=DARKBLUE><u>"+data.email+"</u></font></span>"+
+										"</td></tr></table>";
+
+
+	this.timeout_hide = setTimeout("InfoContact.hide()",1000);	
+}
+
+emInfoContact.prototype.search = function (email){
+	var _this = this;
+	var trustedDomain = false;
+	//	If "preferences.notification_domains" was setted, then verify if "mail" has a trusted domain.	
+	if (preferences.notification_domains != undefined && preferences.notification_domains != "") {
+		var domains = preferences.notification_domains.split(',');
+		for (var i = 0; i < domains.length; i++) {
+			if (email.toString().match(domains[i]))
+				trustedDomain = true;
+		}
+	}
+	else
+		trustedDomain = true;
+
+	var handler_search = function(data){
+		if(data != null){
+			_this.show(data);
+		}
+		else
+			_this.label(email);			
+	}
+	
+	if (trustedDomain)
+		cExecute ("$this.ldap_functions.getUserByEmail&email="+email, handler_search);
+	else
+		_this.label(email);
+}
+
+emInfoContact.prototype.hide = function(){
+	this.email = "";
+	if(Element("div_label"))
+		Element("div_label").style.display = 'none';
+
+	if(Element("card_cc")) 
+		Element("card_cc").style.display = "none";	
+}
+
+emInfoContact.prototype.sendMail = function(name, email){
+	Element("msg_number").value = "\""+ name+"\" <"+email+">";
+	InfoContact.hide();
+	new_message("new","null");
+}
+
+emInfoContact.prototype.openChat = function(event, email){
+	IM.action_button(event, '1', email ,false);
+}
+
+emInfoContact.prototype.verifyIM = function(uid, email){
+
+	if ( !window.IM || !document.getElementById('myStatus') )
+		return  "<br/><br/>";
+
+	var status = IM.infoContact(uid);
+	var _return = '<br/>';
+
+	if ( status )
+	{
+		_return += '<img align="center" src="'+status.src+'" />';
+		_return	+= '<span onclick="IM.action_button(event,\''+status.jid+'\');"><font size="1" color=';
+		
+		if( status.src != img_unavailable.src)
+			_return 	+= '"DARKBLUE"><u style="cursor:pointer;">'+get_lang("User connected")+"</u>";
+		else
+			_return 	+= '"BLACK">'+get_lang("User not connected");
+
+		_return	+= "</font></span><br />";
+	}
+
+	return _return;
+}
+/* Build the Object */
+var emInfoContact;
+InfoContact = new emInfoContact();
Index: trunk/expressoMail1_2/js/jscode/sniff_browser.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/sniff_browser.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/sniff_browser.js	(revision 2517)
@@ -0,0 +1,19 @@
+    var agt=navigator.userAgent.toLowerCase();
+    var is_major = parseInt(navigator.appVersion);
+    var is_minor = parseFloat(navigator.appVersion);    
+    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
+                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
+                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
+    var is_gecko = (agt.indexOf('gecko') != -1);
+    var is_gecko1_5 = (agt.indexOf('firefox/1.5') != -1 || agt.indexOf('firefox/2') != -1 || agt.indexOf('iceweasel/2') != -1 || agt.indexOf('firefox/3'));
+    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
+    var is_ie3    = (is_ie && (is_major < 4));
+    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
+    var is_ie4up  = (is_ie && (is_major >= 4));
+    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
+    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
+    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
+    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
+    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
+    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);    
+    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
Index: trunk/expressoMail1_2/js/jscode/filters.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/filters.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/filters.js	(revision 2517)
@@ -0,0 +1,240 @@
+var rules_limit = 300;
+
+	function cfilterSh(){
+		this.filter_Sh   = new Array;
+		this.qvfaf		 = "";
+		
+		// Images
+		this.grp_open_img = new Image();
+		this.grp_open_img.src = 'templates/'+template+'/images/filtro/group_open.gif';
+		this.grp_close_img = new Image();
+		this.grp_close_img.src = 'templates/'+template+'/images/filtro/group_close.gif';
+		this.filter_img = new Image();
+		this.filter_img.src = 'templates/'+template+'/images/filtro/filters.gif';
+		this.for_email_img = new Image();
+		this.for_email_img.src = 'templates/'+template+'/images/filtro/answered.gif';
+		this.telephone_voip = new Image();
+		this.telephone_voip.src = 'templates/'+template+'/images/filtro/telephone_voip.jpg';
+	}		
+
+	cfilterSh.prototype.Forms = function(){
+	
+		var form = document.createElement("DIV");
+		form.id  = "window_ffilter_ccform";
+		form.style.visibility = "hidden";
+		form.style.position = "absolute";
+		form.style.left = "0px";
+		form.style.top  = "0px"; 
+		form.style.width = "0px";
+		form.style.height = "0px";
+		document.body.appendChild(form);
+
+		var form_cont = document.createElement("SPAN");
+		form_cont.id = "form_status";
+		form_cont.style.display = "block";			
+		form_cont.style.position = "absolute";
+		form_cont.style.top = "10px";
+		form_cont.style.left = "600px";
+		form_cont.innerHTML = "";
+		form.appendChild(form_cont);
+		
+		var form_buttons = document.createElement("DIV");
+		form_buttons.id = "form_buttons";
+		form_buttons.style.position = "absolute";
+		form_buttons.style.display = "";
+		form_buttons.style.top = "320px";
+		form_buttons.style.left = "5px";
+		form_buttons.style.width = "655px";
+		form_buttons.innerHTML = "<input type='button' value="+get_lang("Enable")+" onclick='filter.enabled_disabled(\"ENABLED\");'>"+
+								 "&nbsp;<input type='button' value="+get_lang("Disable")+" onclick='filter.enabled_disabled(\"DISABLED\");'>"+	
+								 "&nbsp;<input type='button' value="+get_lang("Remove")+" onclick='filter.delete_r();'>"+
+ 								 "&nbsp;<input type='button' value="+get_lang("Close")+" onclick='filter.close_frm();'>";
+
+		form.appendChild(form_buttons);
+		
+		var form_body = document.createElement("DIV");
+		form_body.id = "form_body";
+		form_body.style.position = "absolute";
+		form_body.style.left = "5px";
+		form_body.style.top = "5px";
+		form_body.style.width = "668px";
+		form_body.style.height = "310px";
+		form_body.style.borderStyle = "outset";
+		form_body.style.borderColor = "black";
+		form_body.style.borderWidth = "1px";
+		form_body.style.overflow = "auto";
+		form.appendChild(form_body);	
+
+		this.showWindow(form);
+		filter.load_rules();
+		this.list_rules();			
+	
+	}
+
+	cfilterSh.prototype.list_rules = function(){
+		if(filter.rulest.length == 0)
+			setTimeout("filters.mount_list()",2500);
+		else
+			this.mount_list();
+	}
+
+	cfilterSh.prototype.mount_list = function(){
+
+		Element('form_status').innerHTML = "";
+		var list = "";
+	
+		// rules
+		if(filter.rulest.length == 0){
+			list = "<img id='set_rules_img' src='" + this.grp_close_img.src + "' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + "<a href='javascript:filters.n_rule()'>" + get_lang("new rule") + "</a>";		
+		}else{
+			if ( filter.rulest.length < rules_limit ) //Limit of rules
+				list = "<img id='set_rules_img' src='" + this.grp_open_img.src + "' onclick='visibleRulesFalse(\"set_rules\");' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + "<a href='javascript:filters.n_rule();'>" + get_lang("new rule") + "</a>";
+			else
+				list = "<img id='set_rules_img' src='" + this.grp_open_img.src + "' onclick='visibleRulesFalse(\"set_rules\");' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + get_lang("You have reached the maximum number of rules");
+			
+			list += "<div id='set_rules'>";
+			
+			for(var i= 0; i < filter.rulest.length; i++)
+			{
+				list += "<input id=rule_"+i+" type='checkBox'>&nbsp;<img src='"+this.filter_img.src+"' width='16' height='16' border='0' />&nbsp;" + get_lang("Rule")+" : " + parseInt(i+1) + " -- " + this.vl_rule(filter.rulest[i],i,'') + "<br>";
+			}
+			list += "</div>";			
+		}
+		
+		list += "<br/>";
+		
+		// out office
+		if(!filter.out_officeR){
+			list += "<img id='set_out_img' src='"+this.grp_close_img.src+"' border='0' />&nbsp;";
+			list += "<span><b>"+get_lang('out office') + " - ( 0 ) </b></span> " + "<a href='javascript:filters.n_out_office()'>" + get_lang("new rule") + "</a>";			
+		}else{
+			list += "<img id='set_out_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"set_out\");' border='0' />&nbsp;";
+			list += "<span><b>"+get_lang('out office') + " - ( 1 )</b></span>";
+			list += "<div id='set_out'>";
+			list += "<input id='out_0' type='checkBox'><img id='set_out_form_email_img' src='"+this.for_email_img.src+"' border='0'>";
+			list += " " + this.vl_outOffice(filter.out_officeR) + " " ;
+			list += "</div>";
+		}
+		list += "<br/>";
+	
+		// Voip
+		if(preferences.voip_email_redirect)
+		{
+			if( filter.rulesVoip.length == 0)
+			{
+				list += "<img id='voip_rule_img' src='"+this.grp_close_img.src+"' border='0' />&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + "<a href='javascript:filters.n_voipFilter();'>" + get_lang("new rule") + "</a>";		
+			}
+			else
+			{
+				if ( filter.rulest.length < rules_limit ) //Limit of rules
+					list += "<img id='voip_rule_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"voip_rule\");' border='0'/>&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + "<a href='javascript:filters.n_voipFilter()'>" + get_lang("new rule") + "</a>";
+				else
+					list += "<img id='voip_rule_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"voip_rule\");' border='0'/>&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + get_lang("You have reached the maximum number of rules");
+					
+				list += "<div id='voip_rule'>";
+				for(var i= 0; i < filter.rulesVoip.length; i++)
+				{
+					list += "<input id='voip_rule_"+i+"' type='checkBox'>&nbsp;<img src='"+this.telephone_voip.src+"' width='16' height='16' border='0'/>&nbsp;" + get_lang("Rule")+" : " + parseInt(i+1) + " -- " + this.vl_rule(filter.rulesVoip[i],i,'voip') + "<br>";
+				}
+				list += "</div>";
+			}
+		}
+
+		Element("form_body").innerHTML = list;
+	}
+	
+	cfilterSh.prototype.vl_rule = function(rule,pos,type)
+	{
+		var fields = rule.split("&&");
+		if(type == 'voip')
+			return " <a href='javascript:void(0)' onclick=filter.form_r('"+pos+"','voip')><b>" + get_lang("Status") + " : </b>" + "<font color='red'>" + get_lang(fields[2]) + "</font>" + " - " + fields[3] + " <b>" + get_lang("Subject") + ":</b> " + fields[5] + "</a>";
+		else
+			return " <a href='javascript:void(0)' onclick=filter.form_r('"+pos+"','')><b>" + get_lang("Status") + " : </b>" + "<font color='red'>" + get_lang(fields[2]) + "</font>" + " - <b>" + get_lang("E-mail rule") + ":</b> " + fields[3] + " - <b>" + get_lang("Action") + ":</b> " + fields[6] + "</a>";
+	}
+	
+	cfilterSh.prototype.vl_outOffice = function(outOffice){		
+		var aux = outOffice.split("&&");
+		return get_lang("Rule") + " - <a href='javascript:void(0)' onclick=filter.form_out()> " + "<b>" + get_lang("Status") + " : </b><font color='red'>" + (aux[4] == "off" ? get_lang("Disabled") : get_lang("Enabled")) + "</font></a>";
+	}
+	
+	cfilterSh.prototype.n_rule = function()
+	{
+		Element('form_body').innerHTML = "";
+		Element('form_body').innerHTML = filter.forms_();	
+		Element('div_rule').style.display = "block";
+		filter.ac_form = "new_rule";
+		Element('form_buttons').style.display = 'none';
+		filter.sel_boxes();
+
+	}
+
+	cfilterSh.prototype.n_out_office = function()
+	{
+		Element('form_body').innerHTML = "";
+		Element('form_body').innerHTML = filter.forms_();	
+		Element('div_vacation').style.display = "block";			
+		Element('form_buttons').style.display = 'none';
+		filter.ac_form = "new_out";	
+	}
+
+	cfilterSh.prototype.n_voipFilter = function()
+	{
+		Element('form_body').innerHTML = "";
+		Element('form_body').innerHTML = filter.forms_();
+		Element('div_voipFilter').style.display = "block";	
+		Element('form_buttons').style.display = 'none';
+		filter.ac_form = "new_voip";
+	}
+
+	function visibleRulesFalse(el)
+	{
+		Element(el).style.display = "none";
+		Element(el+"_img").src = filters.grp_close_img.src;
+		Element(el+"_img").onclick = function(){visibleRulesTrue(el);};
+	}
+
+	function visibleRulesTrue(el)
+	{
+		Element(el).style.display = "";
+		Element(el+"_img").src = filters.grp_open_img.src;
+		Element(el+"_img").onclick = function(){visibleRulesFalse(el);};
+	}
+
+	cfilterSh.prototype.showWindow = function (div)
+	{
+		if(! this.filter_Sh[div.id]) {
+			div.style.width = "680px";
+			div.style.height = "345px";
+			div.style.visibility = "hidden";
+			div.style.position = "absolute";
+			div.style.zIndex = "10000";			
+			var title = ':: ' + get_lang('Filters management') + ' - ' + get_lang('Filters maintenance') + ':: ';
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";
+
+			win = new dJSWin({			
+				id: 'filter'+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.filter_Sh[div.id] = win;
+			win.draw();
+		}else{
+			div.innerHTML = '';
+			win = this.filter_Sh[div.id];
+			filter.form_m();			
+		}
+		win.open();
+	}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// build object
+ 	var filters;
+	filters = new cfilterSh();
Index: trunk/expressoMail1_2/js/jscode/sharemailbox.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/sharemailbox.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/sharemailbox.js	(revision 2517)
@@ -0,0 +1,393 @@
+	function cShareMailbox()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this.alert = false;
+	}
+
+	cShareMailbox.prototype.get_available_users = function(context)
+	{
+		var handler_get_available_users = function(data)
+		{
+			select_available_users = document.getElementById('em_select_available_users');
+		
+			//Limpa o select
+			for(var i=0; i<select_available_users.options.length; i++)
+			{
+				select_available_users.options[i] = null;
+				i--;
+			}
+
+			if ((data) && (data.length > 0))
+			{
+				// Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
+				select_available_users.innerHTML = '#' + data;
+				select_available_users.outerHTML = select_available_users.outerHTML;
+			
+				select_available_users.disabled = false;
+				select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
+				document.getElementById('em_input_searchUser').value = '';
+			}
+		}
+		cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users);
+	}
+
+	cShareMailbox.prototype.getaclfromuser = function(user)
+	{
+		var handler_getaclfromuser = function(data)
+		{
+			Element('em_input_readAcl').checked = false;
+			Element('em_input_deleteAcl').checked = false;
+			Element('em_input_writeAcl').checked = false;
+			Element('em_input_sendAcl').checked = false;
+			Element('em_input_saveAcl').checked = false;
+			Element('em_input_saveAcl').disabled = true;
+			
+			if (data[user].indexOf('lrs',0) >= 0)
+			{
+				Element('em_input_sendAcl').disabled = false;
+				Element('em_input_readAcl').checked = true;
+			}
+			else
+				Element('em_input_sendAcl').disabled = true;
+				
+			if (data[user].indexOf('d',0) >= 0)
+			{
+				Element('em_input_deleteAcl').checked = true;
+			}
+			if (data[user].indexOf('wi',0) >= 0)
+			{
+				Element('em_input_writeAcl').checked = true;
+			}
+			
+			if (data[user] != "false" && data[user].indexOf('a',0) >= 0)
+			{
+				Element('em_input_sendAcl').disabled = false;
+				Element('em_input_sendAcl').checked = true;
+			}
+			if (data[user] != "false" && data[user].indexOf('p',0) >= 0)
+			{
+				Element('em_input_saveAcl').disabled = false;
+				Element('em_input_saveAcl').checked = true;
+			} 
+			if( data[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
+				Element('em_input_saveAcl').disabled = false;
+			} else Element('em_input_saveAcl').disabled = true;
+		}
+		cExecute ("$this.imap_functions.getaclfromuser&user="+user, handler_getaclfromuser);
+	}
+	
+	cShareMailbox.prototype.setaclfromuser = function()
+	{
+		var acl		= '';
+		var select 	= Element('em_select_sharefolders_users');
+
+		if(select.selectedIndex == "-1"){
+			alert("Selecione antes um usuário!");
+			return false;
+		}
+		var user = select.options[select.selectedIndex].value;
+		
+		if (Element('em_input_readAcl').checked) {
+			Element('em_input_sendAcl').disabled = false;
+			acl = 'lrs';
+		}
+		else{
+			Element('em_input_sendAcl').disabled = true;
+			Element('em_input_sendAcl').checked = false;
+		}
+				
+		if (Element('em_input_deleteAcl').checked)
+			acl += 'd';
+
+		if (Element('em_input_writeAcl').checked) {
+			acl += 'wi';			
+		}		
+		if (Element('em_input_sendAcl').checked){
+			acl += 'a';			
+		}
+		if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
+			Element('em_input_saveAcl').disabled = false;				
+		} else {
+			Element('em_input_saveAcl').disabled = true;
+			Element('em_input_saveAcl').checked = false;
+		}
+		
+		if (Element('em_input_saveAcl').checked)
+			acl += 'p';
+		
+		var handler_setaclfromuser = function(data) {
+			if (!data)
+				alert(data);	
+			return true;
+		}
+		cExecute ("$this.imap_functions.setaclfromuser&user="+user+"&acl="+acl, handler_setaclfromuser);
+	}
+	
+	cShareMailbox.prototype.makeWindow = function(options)
+	{
+		_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_sharefolders';
+		document.body.appendChild(el);
+
+		if (Element('em_select_sharefolders_users'))
+		{
+			var select_users = Element('em_select_sharefolders_users');
+			select_users.innerHTML = '#' + options;
+			select_users.outerHTML = select_users.outerHTML;
+			
+			Element('em_input_readAcl').checked = false;
+			Element('em_input_deleteAcl').checked = false;
+			Element('em_input_writeAcl').checked = false;
+			Element('em_input_sendAcl').checked = false;
+			Element('em_input_saveAcl').checked = false;
+		}
+		else
+		{
+			el.innerHTML = "<table border=0><tbody><tr>"+
+							
+							"<td valign='bottom'>"+
+								'<font color="red">'+
+									get_lang('Note: This sharing will take action on all of your folders and messages.')+
+									'<br><br>'+
+								'</font>'+
+								get_lang('Your mailbox is shared with')
+								+":<br><br>"+
+								"<select onchange=sharemailbox.getaclfromuser(this.value); id='em_select_sharefolders_users' size='13' style='width:250px;height:200px'>" + options + "</select>"+
+							"</td>"+
+							
+							"<td>"+
+								'<br><br><br><br><br><br>'+
+								'<img onClick="javascript:sharemailbox.add_user();" src="templates/'+template+'/images/arrow_left.gif" style="vertical-align:middle;cursor:pointer;">' +
+								'<br><br>'+
+								'<img onClick="javascript:sharemailbox.remove_user();" src="templates/'+template+'/images/arrow_right.gif" style="vertical-align:middle;cursor:pointer;">' +
+							"</td>"+
+							
+							"<td valign='bottom'><br>"+
+								get_lang('Organization')+":&nbsp;" + 
+								"<select id='em_combo_org' onchange='javascript:sharemailbox.get_available_users(this.value);'></select>"+
+								
+								"<br><br>"+get_lang('Search user')+":<br>" +
+								'<input id="em_input_searchUser" size="35" autocomplete="off"  onkeyup="javascript:sharemailbox.optionFinderTimeout(this)"><br>'+
+								
+								'<font color="red"><span id="em_span_searching">&nbsp;</span></font><br>'+
+								
+								"<select id='em_select_available_users' style='width:250px;height:200px' multiple></select></td>"+
+							'</tr>'+
+							'<tr><td>'+
+								'<table border=0><tbody><tr><td colspan=2>'+
+									get_lang('Access right')+':'+
+								'</td></tr>'+
+								'<tr><td>'+get_lang('Read')+':</td><td><input id=\'em_input_readAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang("hlp_msg_read_acl")+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
+								'<tr><td>'+get_lang('Exclusion')+':</td><td><input id=\'em_input_deleteAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_delmov_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
+								'<tr><td>'+get_lang('Write')+':</td><td><input id=\'em_input_writeAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_addcreate_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
+								'<tr><td>'+get_lang('Send')+':</td><td><input id=\'em_input_sendAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_sendlike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
+								'<tr><td>'+get_lang('Save')+':</td><td><input id=\'em_input_saveAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_savelike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr></tbody></table>'+
+							'</td></tr>'+
+			"</tbody></table>";
+		}
+
+		var handler_organizations = function(data){
+			var user_organization = Element('user_organization').value;
+			
+			for(i = 0; i < data.length; i++) {
+				Element('em_combo_org').options[i] = new Option(data[i].ou,data[i].dn);
+				if(user_organization.toUpperCase() == data[i].ou.toUpperCase())
+				{
+					Element('em_combo_org').options[i].selected = true;
+					_this.get_available_users(data[i].dn);
+				}
+			}
+		}
+		cExecute ("$this.ldap_functions.get_organizations2&referral=false", handler_organizations);
+
+		var butt = Element('dJSWin_wfolders_bok')
+		if (!butt){
+			butt = document.createElement('INPUT');
+			butt.id = 'dJSWin_wfolders_bok';
+			butt.type = 'button';
+			butt.value = get_lang('Save');
+			el.appendChild(butt);
+		}
+		butt.onclick = function ()
+		{
+			// Needed select all options from select
+			var users_setacl = new Array();
+			select_users = Element('em_select_sharefolders_users');
+			for(var i=0; i<select_users.options.length; i++)
+			{
+				users_setacl[i] = select_users.options[i].value;
+			}
+			attributes = expresso.connector.serialize(users_setacl);
+			
+			var handler_save = function(data)
+			{
+				if (data)
+				{
+					alert(get_lang('Shared options saved with success'));
+					sharemailbox.arrayWin[el.id].close();
+				}
+			}
+
+			cExecute ("$this.imap_functions.setacl", handler_save, 'users='+attributes);
+
+		}
+		
+		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 () {sharemailbox.arrayWin[el.id].close();};
+		el.appendChild(butt);
+		
+		_this.showWindow(el);
+	}
+	
+	cShareMailbox.prototype.showWindow = function (div)
+	{
+		if(! div) {
+			alert(get_lang('This list has no participants'));
+			return;
+		}
+		
+		if(! this.arrayWin[div.id])
+		{
+			div.style.height = "480px";
+			div.style.width = "540px";
+			var title = ":: "+get_lang("Mailbox Sharing")+" ::";
+			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];
+		}
+		Element('em_input_sendAcl').disabled = true;
+		Element('em_input_saveAcl').disabled = true;
+		win.open();
+	}
+	
+	var finderTimeout = '';
+	cShareMailbox.prototype.optionFinderTimeout = function(obj)
+	{
+		clearTimeout(finderTimeout);	
+		var oWait = document.getElementById("em_span_searching");
+		oWait.innerHTML = get_lang('Searching')+"...";
+		var finderTimeout = setTimeout("sharemailbox.optionFinder('"+obj.id+"')",500);
+	}
+	
+	cShareMailbox.prototype.optionFinder = function(id)
+	{
+		var oWait = document.getElementById("em_span_searching");
+		var oText = document.getElementById(id);
+			
+		//Limpa todo o select
+		
+		var select_available_users_tmp = document.getElementById('em_select_available_users')
+		for(var i = 0;i < select_available_users_tmp.options.length; i++)
+			select_available_users_tmp.options[i--] = null;
+
+		var RegExp_name = new RegExp("\\b"+oText.value, "i");
+		
+		//Inclui usuário começando com a pesquisa
+		for(i = 0; i < select_available_users_clone.length; i++){
+			if (RegExp_name.test(select_available_users_clone[i].text))
+			{
+				sel = select_available_users_tmp.options;
+				option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);				
+				sel[sel.length] = option;
+			}
+		}
+		oWait.innerHTML = '&nbsp;';
+	}
+	
+	cShareMailbox.prototype.add_user = function()
+	{
+		var select_available_users = document.getElementById('em_select_available_users');
+		var select_users = document.getElementById('em_select_sharefolders_users');
+
+		var count_available_users = select_available_users.length;
+		var count_users = select_users.options.length;
+		var new_options = '';
+	
+		for (i = 0 ; i < count_available_users ; i++)
+		{
+			if (select_available_users.options[i].selected)
+			{
+				if(document.all)
+				{
+					if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_users.options[i].value
+									+ '>'
+									+ select_available_users.options[i].text
+									+ '</option>';
+					}
+				}
+				else
+				{
+					if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_users.options[i].value
+									+ '>'
+									+ select_available_users.options[i].text
+									+ '</option>';
+					}
+				}
+			}
+		}
+
+		if (new_options != '')
+		{
+			select_users.innerHTML = '#' + new_options + select_users.innerHTML;
+			select_users.outerHTML = select_users.outerHTML;
+		}
+	}
+
+	cShareMailbox.prototype.remove_user = function()
+	{
+		select_users = document.getElementById('em_select_sharefolders_users');
+	
+		for(var i = 0;i < select_users.options.length; i++)
+			if(select_users.options[i].selected)
+				select_users.options[i--] = null;
+				
+		Element('em_input_readAcl').checked = false;
+		Element('em_input_deleteAcl').checked = false;
+		Element('em_input_writeAcl').checked = false;
+		Element('em_input_sendAcl').checked = false;
+		Element('em_input_saveAcl').checked = false;
+	}
+	
+	
+/* Build the Object */
+	var sharemailbox;
+	sharemailbox = new cShareMailbox();
Index: trunk/expressoMail1_2/js/jscode/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/common_functions.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/common_functions.js	(revision 2517)
@@ -0,0 +1,926 @@
+// BEGIN: FUNCTION RESIZE WINDOW
+if (!expresso_offline) {
+	var _showBar = showBar;
+	var _hideBar = hideBar;
+}
+
+function __showBar(){
+	_showBar();
+	resizeWindow();
+}
+
+function __hideBar(){
+	_hideBar();
+	resizeWindow();
+}
+showBar = __showBar;
+hideBar = __hideBar;
+
+window.onresize = resizeWindow;
+
+function config_events(pObj, pEvent, pHandler)
+{
+    if( typeof pObj == 'object')
+    {
+        if( pEvent.substring(0, 2) == 'on')
+            pEvent = pEvent.substring(2, pEvent.length);
+
+        if ( pObj.addEventListener )
+            pObj.addEventListener(pEvent, pHandler, false);
+        else if( pObj.attachEvent )
+            pObj.attachEvent('on' + pEvent, pHandler );
+    }
+}
+
+function resizeWindow(){
+
+	var bar = Element("toolbar");
+	var offset = 0;
+	if(bar.style.visibility != 'hidden') 
+		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);	
+
+	var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
+	var defaultHeight = screenHeight - offset;
+
+	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);
+
+			// This comented code cause/avoid (!?) Firefox to stuck some request
+			if(div)
+//				div.setAttribute("style","height: "+parseInt(defaultHeight - 90)+"px;");
+				div.style.height = defaultHeight - 90;
+			if(div_scroll)
+//				div_scroll.setAttribute("style","height: "+parseInt(defaultHeight - 130)+"px;");
+				div_scroll.style.height = defaultHeight - 130;
+		}
+	}
+
+	if(Element('content_folders'))
+		Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
+	if(Element("divScrollMain_"+numBox))
+		Element("divScrollMain_"+numBox).style.height 	= defaultHeight - (is_ie ? 111 : 110);
+}
+// 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;
+			}
+		}
+	}
+}
+
+// Translate words and phrases using user language from eGroupware.
+function get_lang(_key) {
+	var key = _key.toLowerCase();
+	if(array_lang[key])
+		var _value = array_lang[key];
+	else
+		var _value = _key+"*";
+
+	if(arguments.length > 1)
+		for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
+			_value = _value.replace("%"+j,arguments[j]);
+	return _value;
+}
+
+// Make decimal round, using in size message
+function round(value, decimal){
+	var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
+	return( return_value );
+}
+
+// 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();
+	remove_className(tr_message, 'tr_msg_unread');
+	remove_className(tr_message, 'selected_msg');
+	expresso.connector.purgeCache();
+	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();	
+	remove_className(tr_message, 'selected_msg');
+	add_className(tr_message, 'tr_msg_unread');
+}
+
+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 removeAll(id){
+	do
+	{
+		if (typeof(Element(id)) == 'undefined')
+			break;
+		Element(id).parentNode.removeChild(Element(id));
+	}
+	while(Element(id));
+}
+
+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 = '';
+}
+
+//Get the current number of messages in a page.
+function get_messages_number_in_page(){
+	//Get element tBody.
+	main = document.getElementById("tbody_box");
+		
+	// Get all TR (messages) in tBody.
+	main_list = main.childNodes;
+	
+	return main_list.length;
+}
+
+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='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("$this.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);
+}
+//	Remove Input File Dynamically.
+function removeFile(id){
+	var border_id = id.substr(8,1);
+	var el = Element(id);
+	el.parentNode.removeChild(el);
+}
+
+function validateFileExtension(fileName, id, id_border){
+	
+	var error_flag  = false;
+
+	if ( fileName.indexOf('/') != -1 )
+	{
+		if (fileName[0] != '/'){ // file name is windows format?
+			var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
+			if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
+				error_flag = true;	
+		}
+		else // is Unix
+			var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);						
+	}
+	else  // is Firefox 3
+		var file = fileName;
+
+	var fileExtension = file.split(".");
+	fileExtension = fileExtension[(fileExtension.length-1)];
+	for(var i=0; i<denyFileExtensions.length; i++)
+	{
+		if(denyFileExtensions[i] == fileExtension)
+		{
+			error_flag = true;
+			break;
+		}
+			
+	}
+
+	if ( error_flag == true )
+	{
+		alert(get_lang('File extension forbidden or invalid file') + '.');
+		removeFile(id);
+		addFile(id_border);
+		return false;
+	}
+	return true;
+}
+
+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 validateEmail(email){
+	if (typeof(email) != 'string')
+		return false;
+	var validName = /^[a-z][a-z-_0-9\.]*/i;
+	emailParts = email.split('@');
+	return (validName.test(emailParts[0]) && validateDomain(emailParts[1]));
+}
+function validateDomain(domain){
+	var domainReg = /^(([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}\])$/i;
+	return (domainReg.test(domain));
+}
+
+function validateUrl(url){
+	var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
+	urlParts = url.split(urlReg);
+	return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
+}
+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 ("$this.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 ("$this.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("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
+}
+
+function url_encode(str){
+    var hex_chars = "0123456789ABCDEF"; 
+    var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
+    var n, strCode, hex1, hex2, strEncode = ""; 
+
+    for(n = 0; n < str.length; n++) { 
+        if (noEncode.test(str.charAt(n))) { 
+            strEncode += str.charAt(n); 
+        } else { 
+            strCode = str.charCodeAt(n); 
+            hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
+            hex2 = hex_chars.charAt(strCode % 16); 
+            strEncode += "%" + (hex1 + hex2); 
+        } 
+    } 
+    return strEncode; 
+}  
+
+function url_decode(str) { 
+
+	var n, strCode, strDecode = ""; 
+	for (n = 0; n < str.length; n++) { 
+	    if (str.charAt(n) == "%") { 
+	        strCode = str.charAt(n + 1) + str.charAt(n + 2); 
+	        strDecode += String.fromCharCode(parseInt(strCode, 16)); 
+	        n += 2; 
+	    } else { 
+	        strDecode += str.charAt(n); 
+	    } 
+	} 
+	return strDecode; 
+}  
+
+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 borkb(size){
+	kbyte = 1024;
+	mbyte = kbyte*1024;
+	gbyte = mbyte*1024;
+	if (!size)
+		size = 0;
+	if (size < kbyte)
+		return size + 'B';
+	else if (size < mbyte)
+		return parseInt(size/kbyte) + 'KB';
+	else if (size < gbyte)
+		if (size/mbyte > 100)
+			return (size/mbyte).toFixed(0) + 'MB';
+		else
+			return (size/mbyte).toFixed(1) + 'MB';
+	else
+		return parseInt(size/gbyte).toFixed(1) + 'GB';
+}
+
+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; 
+}
+
+function increment_folder_unseen(){
+	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) + 1);
+	}
+	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>1</span><font style=color:red>)</font>'});
+		tree_folders.getNodeById(folder_id)._refresh();
+	}
+	if (abas_unseen)
+	{
+		abas_unseen = parseInt(abas_unseen) + 1;
+		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) + 1;
+		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
+	}
+	if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
+	{
+		var display_unseen_in_shared_folders = Element('dftree_user_unseen');
+		if ( display_unseen_in_shared_folders )
+			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( display_unseen_in_shared_folders.innerHTML) + 1 ) + '</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 display_unseen_in_mailbox = 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(){
+	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) > 1))
+	{
+		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
+	}
+	else if (parseInt(folder_unseen.innerHTML) <= 1)
+	{
+		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) > 1))
+        {
+	        abas_unseen = (parseInt(abas_unseen) - 1);
+	        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 display_unseen_in_shared_folders = Element('dftree_user_unseen');
+		if ( display_unseen_in_shared_folders )
+		{
+			var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
+			unseen_in_shared_folders--;
+			if ( unseen_in_shared_folders > 0 )
+				tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_shared_folders + '</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 display_unseen_in_mailbox = Element('dftree_root_unseen');
+	if ( display_unseen_in_mailbox )
+	{
+		var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.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();
+	}
+}
+
+function LTrim(value){
+	var w_space = String.fromCharCode(32);
+	var strTemp = "";
+	var iTemp = 0;
+
+	var v_length = value ? value.length : 0;
+	if(v_length < 1)
+		return "";
+
+	while(iTemp < v_length){
+		if(value && value.charAt(iTemp) != w_space){
+			strTemp = value.substring(iTemp,v_length);
+			break;
+		}
+		iTemp++;
+	}
+	return strTemp;
+}
+
+//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 add_className(obj, className){
+	if (obj && !exist_className(obj, className))
+		obj.className = obj.className + ' ' + className;
+}
+
+function remove_className(obj, className){
+	var re = new RegExp("\\s*"+className);
+	if (obj)
+		obj.className = obj.className.replace(re, ' ');
+}
+
+function exist_className(obj, className){
+	return ( obj && obj.className.indexOf(className) != -1 )
+}
+
+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');
+		}
+	}
+}
+
+function validate_date(date){
+    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
+    {
+        tmp = date.split('/');
+
+        day = new Number(tmp[0]);
+        month = new Number(tmp[1]);
+        year = new Number(tmp[2]);
+        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
+        {
+            if (month == 02 && day <= 29)
+            {
+                return true;
+            }
+            return true;
+        }
+        else
+            {
+                return false;
+            }
+    }
+    else
+        {
+            return false;
+        }
+}
Index: trunk/expressoMail1_2/js/jscode/main.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/main.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/main.js	(revision 2517)
@@ -0,0 +1,2550 @@
+// 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(){
+	current_folder = "INBOX";
+	if (!is_ie)
+		Element('tableDivAppbox').width = '100%';
+	
+	var save_contacts = function(data){
+		contacts = 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;
+		 cExecute ("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", handler_draw_box);
+
+		if(preferences.hide_folders == "1")
+			Element('divAppboxHeader').innerHTML =  title_app_menu;
+		
+		if (preferences.delete_trash_messages_after_n_days != 0)
+			cExecute ("expressoMail1_2.imap_functions.automatic_trash_cleanness&before_date="+preferences.delete_trash_messages_after_n_days+"&cyrus_delimiter="+cyrus_delimiter, handler_automatic_trash_cleanness);
+		
+		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
+
+		cExecute ("expressoMail1_2.db_functions.get_dropdown_contacts", save_contacts); //Save contacts needs preferences.
+		cExecute ("expressoMail1_2.imap_functions.get_folders_list&onload=true", update_menu);
+		
+	}
+	var handler_automatic_trash_cleanness = function(data){
+		if (data != false){
+			write_msg(data.length +' '+ Element('txt_clear_trash').value);
+		}
+	}
+	
+	// Versão
+	Element('divAppboxHeader').innerHTML = title_app;
+	
+	// Get cyrus delimiter
+	cyrus_delimiter = Element('cyrus_delimiter').value;
+
+	cExecute ("expressoMail1_2.functions.get_preferences", save_preferences);
+	setTimeout('auto_refresh()', time_refresh);
+
+}
+
+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(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;
+       if (!Element(data.msg_number)){
+	       trElement = document.createElement('DIV');
+	       trElement.id = data.msg_number;
+	       Element("tbody_box").appendChild(trElement);
+       }
+       show_msg(data);
+    }
+
+    proxy_mensagens.msg_img(msg_number,folder,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 handler_sendNotification = 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), handler_sendNotification);
+           // }
+
+            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_get_msg_info == 'false')
+	{
+		write_msg(get_lang("Problems reading your message")+ ".");
+		return;
+	}
+
+	if (msg_info.status == 'false'){
+		eval(msg_info.command_to_exec);
+	}
+	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 (openTab.type[currentTab] == 2 || openTab.type[currentTab] == 3)
+			delete_border(currentTab,'false');
+
+		
+		if(Element("border_id_" + id_msg_read)) 
+			alternate_border(id_msg_read);		
+		else {
+			var border_id = create_border(msg_info.subject, id_msg_read);
+			if(border_id)
+			{
+				openTab.type[border_id] = 2;
+				draw_message(msg_info,border_id);
+				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
+				return;
+		}
+
+		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), handler_sendNotification);
+		}
+		//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
+            }
+        }
+	}
+}
+
+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)
+		{
+			td_info = document.createElement("H3");
+			td_info.setAttribute("height", "25%");
+			td_info.setAttribute("background", "#FFF");
+			td_info.setAttribute("id", "msg_info");
+			td_info.align = "center";
+			td_info.innerHTML = get_lang("This mail box is empty");
+			box.appendChild(td_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());
+			}						
+			 //if(data.new_msgs > 0 || data.msgs_to_delete.length > 0)
+			//	purgeCache();						
+		}
+		// Update Box BgColor
+		var box = Element("tbody_box");
+		if(box.childNodes.length > 1){
+			updateBoxBgColor(box.childNodes);
+		}
+		expresso.connector.purgeCache();
+		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('chk_box_select_all_messages').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)
+	{
+		expresso.connector.purgeCache();
+		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 handler_move_search_msgs = 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);
+		}
+		expresso.connector.purgeCache();
+	}
+
+	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", handler_move_search_msgs, 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('chk_box_select_all_messages').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)
+	{
+		expresso.connector.purgeCache();
+		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 , handler_arquivar_mensagens);
+	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 handler_arquivar_mensagens = 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('chk_box_select_all_messages').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 , handler_arquivar_mensagens);
+	else 
+		write_msg(get_lang('No selected message.'));*/
+	
+}
+
+function get_selected_messages(){
+	main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
+	if (! main)
+		main = Element("tbody_box");
+
+	// Get all TR (messages) in tBody.
+	main_list = main.childNodes;
+
+	var selected_messages = '';
+	var selected_messages_by_shortcuts = '';
+	var j = 0;
+	for (j; j<(main_list.length); j++)
+	{
+	check_box = Element("check_box_message_"+main_list[j].id);
+	if ( (check_box) && (check_box.checked) )
+		selected_messages += main_list[j].id + ',';
+		
+		if (preferences.use_shortcuts == '1')
+		{
+			if ( exist_className(Element(main_list[j].id), 'selected_shortcut_msg') )
+			{
+				selected_messages_by_shortcuts += main_list[j].id + ',';
+			}
+		}
+	}
+	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
+	
+	if (preferences.use_shortcuts == '1')
+	{
+		selected_messages_by_shortcuts = selected_messages_by_shortcuts.substring(0,(selected_messages_by_shortcuts.length-1));
+		
+		var array_selected_messages_by_shortcuts = selected_messages_by_shortcuts.split(",");
+		var array_selected_messages = selected_messages.split(",");
+		
+		if ((array_selected_messages.length <= 1) && (array_selected_messages_by_shortcuts.length > 1))
+		{
+			return selected_messages_by_shortcuts;
+		}
+	}
+	
+	if (selected_messages == '')
+		return false;
+	else
+		return selected_messages;
+}
+
+function replaceAll(string, token, newtoken) {
+	while (string.indexOf(token) != -1) {
+ 		string = string.replace(token, newtoken);
+	}
+	return string;
+}
+
+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 (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 )
+	{
+		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='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){
+
+    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))
+		{
+			expresso.connector.purgeCache();
+			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).',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)
+{
+	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);
+		Element("send_button_"+border_id).style.visibility="visible";
+		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]) //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 handler_set_messages_flag = function (data){
+		
+		var msgs_to_set = data.msgs_to_set.split(",");
+
+		if(!data.status) {
+			alert(data.msg);
+			Element('chk_box_select_all_messages').checked = false;
+			for (var i = 0; i < msgs_to_set.length; i++) {
+				Element("check_box_message_" + msgs_to_set[i]).checked = false;
+				remove_className(Element(msgs_to_set[i]), 'selected_msg');
+			}
+			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('chk_box_select_all_messages').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)
+	{
+		expresso.connector.purgeCache();
+		cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, handler_set_messages_flag);
+	}
+	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 handler_set_messages_flag = function (data){
+		if (data.status && Element("td_message_answered_"+msg_number)) {	
+			if(flag == 'answered')
+				Element("td_message_answered_"+msg_number).innerHTML = '<img src=templates/'+template+'/images/answered.gif title=Respondida>';
+			else if(flag == 'forwarded')
+				Element("td_message_answered_"+msg_number).innerHTML = '<img src=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, handler_set_messages_flag);
+}
+
+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('chk_box_select_all_messages').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){
+		expresso.connector.purgeCache();
+		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultTrashFolder", handler_empty_trash);
+	}
+}
+
+function empty_spam_imap(){
+	var handler_empty_spam = function(data){
+		Element('chk_box_select_all_messages').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 handler_export_all_selected_msgs = 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", handler_export_all_selected_msgs, "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 handler_send_queue_message = 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, handler_send_queue_message,"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/manifest
===================================================================
--- trunk/expressoMail1_2/js/jscode/manifest	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/manifest	(revision 2517)
@@ -0,0 +1,201 @@
+{
+  // version of the manifest file format
+  "betaManifestVersion": 1,
+
+  // version of the set of resources described in this manifest file
+  "version": "second version",
+
+  // optional
+  // If the store specifies a requiredCookie, when a request would hit
+  // an entry contained in the manifest except the requiredCookie is
+  // not present, the local server responds with a redirect to this URL.
+  "redirectUrl":  "login.html",
+  
+  // URLs to be cached (URLs are given relative to the manifest URL)
+  "entries": [
+      { "url": "../offline.php" },
+      { "url": "../login_offline.php" },
+      { "url": "abas.js?1.222" },
+      { "url": "ccQuickAdd.js?1.222" },
+      { "url": "color_palette.js?1.222" },
+	  { "url": "common_functions.js?1.222" },
+	  { "url": "doiMenuData.js?1.222" },
+	  { "url": "drag_area.js?1.222" },
+	  { "url": "draw_api.js?1.222" },
+	  { "url": "DropDownContacts.js?1.222" },
+	  { "url": "filter.js?1.222" },
+	  { "url": "filters.js?1.222" },
+	  { "url": "globals.js?1.222" },
+	  { "url": "html2xhtml.js?1.222" },
+	  { "url": "InfoContact.js?1.222" },
+	  { "url": "QuickCatalogSearch.js?1.222" },
+	  { "url": "QuickSearchUser.js?1.222" },
+	  { "url": "search.js?1.222" },
+	  { "url": "sharemailbox.js?1.222" },
+	  { "url": "shortcut.js?1.222" },
+	  { "url": "main.js?1.222" },
+      { "url": "gears_init.js?1.222" },
+	  { "url": "local_messages.js?1.222" },
+	  { "url": "messages_proxy.js?1.222"},
+	  { "url": "rich_text_editor.js?1.222"},
+	  { "url": "wfolders.js?1.222"},
+	  { "url": "sniff_browser.js?1.222" },
+	  { "url": "TreeS.js?1.222" },
+	  { "url": "TreeShow.js?1.222" },
+	  { "url": "offline_access.js?1.222" },
+
+        { "url": "../../phpgwapi/js/jscalendar/calendar-win2k-1.css?1.222" },
+        { "url": "../../phpgwapi/js/jscalendar/calendar.js?1.222" },
+        { "url": "../../phpgwapi/js/jscalendar/calendar-setup.js?1.222" },
+        { "url": "../../phpgwapi/js/jscalendar/lang/calendar-br.js?1.222" },
+
+	  { "url": "../../phpgwapi/templates/celepar/js/cookieManager.js" },
+	  { "url": "../../phpgwapi/templates/celepar/js/simple_show_hide.js" },
+	  { "url": "../../phpgwapi/templates/celepar/js/pngfix.js" },
+	  { "url": "../../phpgwapi/templates/celepar/login.css" },
+	  { "url": "../../phpgwapi/templates/default/login.css" },
+
+	  { "url": "../../phpgwapi/js/wz_dragdrop/wz_dragdrop.js?1.222" },
+	  { "url": "../../phpgwapi/js/dJSWin/dJSWin.js?1.222" },
+	  { "url": "../../phpgwapi/js/dftree/dftree.js?1.222" },
+	  
+	  { "url": "../templates/default/main.css" },
+	  { "url": "../templates/default/main.css" },
+	  { "url": "../../phpgwapi/js/dftree/dftree.css" },
+	  { "url": "../../phpgwapi/images/winclose.gif" },	
+	  { "url": "../../phpgwapi/images/win_min.gif" },	
+	  { "url": "../../phpgwapi/templates/celepar/images/logout.png" },
+	  { "url": "../../phpgwapi/templates/default/images/folder_bg.png" },
+	  { "url": "../../phpgwapi/templates/default/images/foldertree_folder.png" },
+	  { "url": "../../phpgwapi/templates/default/images/foldertree_folderopen.png" },
+	  { "url": "../../phpgwapi/templates/default/images/fundo_topo.png" },
+	  { "url": "../../phpgwapi/templates/default/images/back_pagina.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/fundo1.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/back_botao.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/corpo.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/topo_reflexo.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/back_botao_over.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/fundo2.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/rodape.jpg" },
+	  { "url": "../../phpgwapi/templates/default/images/logo_celepar.jpg" },
+	  
+
+
+	  { "url": "../../phpgwapi/templates/celepar/images/favicon.ico" },
+  	  { "url": "../../phpgwapi/templates/celepar/css/celepar.css" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/fundo_topo.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso.png" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/appbox-header-background21.png" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/icon_login.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso_1.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso_2.gif" },
+   	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso_3.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso_4.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_expresso_5.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_celepar.jpg" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_celepar.gif" },
+  	  { "url": "../../phpgwapi/templates/celepar/images/logo_governo.gif" },
+  	 
+  	  
+	  { "url": "../../phpgwapi/templates/default/css/azul.css" },
+	  { "url": "../../phpgwapi/templates/default/js/simple_show_hide.js" },
+	  { "url": "../../phpgwapi/templates/default/js/cookieManager.js" },
+	  { "url": "../../phpgwapi/templates/default/images/bgBlockContent.jpg" },
+
+
+	  { "url": "../templates/default/images/menu/createmail.gif" },
+	  { "url": "../templates/default/images/menu/checkmail.gif" },  
+	  { "url": "../templates/default/images/menu/tools.gif" },
+   	  { "url": "../templates/default/images/menu/preferences.png" },
+  	  { "url": "../templates/default/images/menu/search.png" },
+  	  { "url": "../templates/default/images/menu/acroread.png" },
+  	  { "url": "../templates/default/images/menu/arrow.gif" },
+  	  { "url": "../templates/default/images/menu/checkspell.gif" },
+  	  { "url": "../templates/default/images/menu/createmail.gif" },
+  	  { "url": "../templates/default/images/menu/delete.png" },
+  	  { "url": "../templates/default/images/menu/deletemail.gif" },
+  	  { "url": "../templates/default/images/menu/edit.gif" },
+  	  { "url": "../templates/default/images/menu/editfolders.png" },
+  	  { "url": "../templates/default/images/menu/export.gif" },
+  	  { "url": "../templates/default/images/menu/filters.png" },
+  	  { "url": "../templates/default/images/menu/folders.gif" },
+  	  { "url": "../templates/default/images/menu/forward.gif" },
+  	  { "url": "../templates/default/images/menu/ktip.png" },
+  	  { "url": "../templates/default/images/menu/markas.gif" },
+  	  { "url": "../templates/default/images/menu/moveto.gif" },
+  	  { "url": "../templates/default/images/menu/people.png" },
+  	  { "url": "../templates/default/images/menu/perform.gif" },
+  	  { "url": "../templates/default/images/menu/preferences.png" },
+  	  { "url": "../templates/default/images/menu/print.gif" },
+  	  { "url": "../templates/default/images/menu/reply.gif" },
+  	  { "url": "../templates/default/images/menu/save.gif" },
+  	  { "url": "../templates/default/images/menu/search.png" },
+  	  { "url": "../templates/default/images/menu/send.gif" },
+  	  { "url": "../templates/default/images/menu/tools.gif" },
+  	  { "url": "../templates/default/images/menu/trash.png" },
+  	  { "url": "../templates/default/images/menu/usersfolders.png" },
+  	  { "url": "../templates/default/images/menu/view_headers-24.gif" },
+  	  { "url": "../templates/default/images/menu/view_raw-24.gif" },
+  	  
+  	  { "url": "../templates/default/images/filtro/answered.gif" },
+  	  { "url": "../templates/default/images/filtro/filters.gif" },
+  	  { "url": "../templates/default/images/filtro/group_close.gif" },
+  	  { "url": "../templates/default/images/filtro/group_open.gif" },
+  	  
+	  { "url": "../templates/default/images/search.gif" },
+	  { "url": "../templates/default/images/users.jpg" },
+	  { "url": "../templates/default/images/arrow_descendant.gif" },
+	  { "url": "../templates/default/images/arrow_ascendant.gif" },
+  	  { "url": "../templates/default/images/answered.gif" },
+  	  { "url": "../templates/default/images/clip.gif" },
+  	  { "url": "../templates/default/images/card.gif" },
+  	  { "url": "../templates/default/images/close_button.gif" },
+  	  { "url": "../templates/default/images/deny.gif" },
+  	  { "url": "../templates/default/images/down.button.png" },
+  	  { "url": "../templates/default/images/draft.gif" },
+  	  { "url": "../templates/default/images/envelope.png" },
+  	  { "url": "../templates/default/images/forwarded.gif" },
+  	  { "url": "../templates/default/images/bold.gif" },
+  	  { "url": "../templates/default/images/dsalert.gif" },
+  	  { "url": "../../phpgwapi/templates/default/images/dsunused.gif" },
+  	  { "url": "../templates/default/images/dsused.gif" },
+  	  { "url": "../templates/default/images/dswarn.gif" },
+  	  { "url": "../templates/default/images/forecolor.gif" },
+  	  { "url": "../templates/default/images/image.gif" },
+  	  { "url": "../templates/default/images/indent.gif" },
+  	  { "url": "../templates/default/images/insertorderedlist.gif" },
+  	  { "url": "../templates/default/images/insertunorderedlist.gif" },
+  	  { "url": "../templates/default/images/invalid.gif" },
+  	  { "url": "../templates/default/images/italic.gif" },
+  	  { "url": "../templates/default/images/justifycenter.gif" },
+  	  { "url": "../templates/default/images/justifyfull.gif" },
+  	  { "url": "../templates/default/images/justifyleft.gif" },
+  	  { "url": "../templates/default/images/justifyright.gif" },
+  	  { "url": "../templates/default/images/left.button.png" },
+  	  { "url": "../templates/default/images/link.gif" },
+  	  { "url": "../templates/default/images/minus.png" },
+  	  { "url": "../templates/default/images/navbar.png" },
+  	  { "url": "../templates/default/images/notification.gif" },
+  	  { "url": "../templates/default/images/outdent.gif" },
+  	  { "url": "../templates/default/images/important.gif" },
+  	  { "url": "../templates/default/images/personal_catalog.png" },
+  	  { "url": "../templates/default/images/phone.gif" },
+  	  { "url": "../templates/default/images/photo.jpg" },
+  	  { "url": "../templates/default/images/plus.png" },
+  	  { "url": "../templates/default/images/redo.gif" },
+  	  { "url": "../templates/default/images/right.button.gif" },
+  	  { "url": "../templates/default/images/search.gif" },
+  	  { "url": "../templates/default/images/sent.gif" },
+  	  { "url": "../templates/default/images/signature.gif" },
+  	  { "url": "../templates/default/images/signed.gif" },
+  	  { "url": "../templates/default/images/table.gif" },
+  	  { "url": "../templates/default/images/underline.gif" },
+  	  { "url": "../templates/default/images/undo.gif" },
+  	  { "url": "../templates/default/images/up.button.png" },
+  	  { "url": "../templates/default/images/user_card.png" },
+  	  { "url": "../templates/default/images/filtro/telephone_voip.jpg" },
+  	  { "url": "../templates/default/images/down.gray.button.png" },
+  	  { "url": "../templates/default/images/up.gray.button.png" }
+  	  
+    ]
+}
Index: trunk/expressoMail1_2/js/jscode/ccQuickAdd.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/ccQuickAdd.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/ccQuickAdd.js	(revision 2517)
@@ -0,0 +1,150 @@
+	function cQuickAddContact ()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this._nFields = 5;
+	}
+
+	
+	cQuickAddContact.prototype.showList = function(data){
+		_this = this;
+
+		var	cc_data = (typeof data) == 'object' ? data : data.split(',');
+		
+		if (document.getElementById('cc_rectQuickAddContact') == null){		
+			el = document.createElement("DIV");
+			el.style.visibility = "hidden";									
+			el.style.position = "absolute";
+			el.style.left = "0px";
+			el.style.top = "0px";
+			el.style.width = "0px";
+			wHeight = 165;
+			el.style.height = wHeight + 'px';
+			el.className = "div_cc_rectQuickAddContact";
+			el.id = 'cc_rectQuickAddContact';
+			document.body.appendChild(el);																
+		}
+		else {
+			el = document.getElementById('cc_rectQuickAddContact');
+		}
+		el.innerHTML = "";
+		var fieldsTop = 10;
+		var fieldsSpace = 30;
+		var lang_save 	= get_lang('Save');
+		var lang_cancel = get_lang('Cancel');
+		
+		//função lang
+		fields = new Array(get_lang('Nickname')+":", get_lang('First Name')+":", get_lang('Last Name')+":", 'E-mail:');
+		for (i=0; i<fields.length; i++) {
+			el.innerHTML += '<span id="ccQuickAddCT' + i + '" style="position: absolute; top: ' +  (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + fields[i] + '</span>';
+			el.innerHTML += '<input id="ccQuickAddCI' + i + '" type="text" value="' + cc_data[i] + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
+		}
+		el.innerHTML +='<div id="ccQAFunctions" style="border: 0px solid black; width: 220px; height: 20px">' +
+			'<input title="'+lang_save+'" type="button" onclick="ccQuickAddOne.send(\''+data+'\');" value="'+lang_save+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 75px; width: 60px" />' +
+			'<input title="'+lang_cancel+'" type="button" onclick="ccQuickAddOne.fechar(\'' + id + '\');" value="'+lang_cancel+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 140px; width: 60px" />' +
+			'</div>';
+		el.innerHTML +=	"<br>";
+		_this.showWindow(el);
+
+	}
+		
+	cQuickAddContact.prototype.showWindow = function (div)
+	{						
+		if(! this.arrayWin[div.id]) {
+			win = new dJSWin({			
+				id: 'ccQuickAddOne_'+div.id,
+				content_id: div.id,
+				width: '255px',
+				height: wHeight+'px',
+				title_color: '#3978d6',
+				bg_color: '#eee',
+				title: get_lang("Quick Add"),
+				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();
+	}
+	
+	cQuickAddContact.prototype.send = function (data)
+	{
+		
+		var handler = function (responseText)
+		{
+			var data = responseText;
+			if (!data || typeof(data) != 'object')
+			{
+				write_msg("Problema ao contactar servidor");
+				return;
+			}
+			else if (data['status'] == 'alreadyExists')
+			{
+				alert(data['msg']);
+				return;
+			}
+			else if (data['status'] != 'ok')
+			{
+				return;
+			}
+			contacts += ',' + full_name + ';' + email;
+			write_msg("Contato adicionado com sucesso.");
+			win.close();
+
+			if (_this.afterSave)
+			{
+				switch (typeof(_this.afterSave))
+				{
+					case 'function':
+						_this.afterSave();
+						break;
+
+					case 'string':
+						eval(_this.afterSave);
+						break;
+				}
+			}
+		}
+				
+		var _this = this;
+		var sdata = data.split(",");
+		var temp = sdata[3];
+		sdata[3]='';
+		sdata[4]=temp;
+		sdata = new Array();
+
+		for (i=0; i< fields.length; i++) {			
+			if(i == 3){
+				sdata[i] = '';
+				sdata[i+1] = document.getElementById("ccQuickAddCI" + i).value;
+			}
+			else
+				sdata[i] = document.getElementById("ccQuickAddCI" + i).value;
+		}
+
+		var full_name = trim(sdata[1]) + ' ' + trim(sdata[2]);
+		var email = trim(sdata[4]);
+
+		if(!validateEmail(email)){
+			alert(get_lang("The email address %1 is not valid, please use a valid address.",email));
+			return false;
+		}
+		
+		var sdata = 'add='+escape(expresso.connector.serialize(sdata));
+		var CC_url = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=';
+		expresso.connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
+	}
+	
+	cQuickAddContact.prototype.fechar = function(id) {
+		var div = document.getElementById('cc_rectQuickAddContact');
+		win = this.arrayWin[div.id];
+		win.close();
+	}
+	
+	
+/* Build the Object */
+	var	ccQuickAddOne = new cQuickAddContact();
Index: trunk/expressoMail1_2/js/jscode/QuickSearchUser.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/QuickSearchUser.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/QuickSearchUser.js	(revision 2517)
@@ -0,0 +1,99 @@
+	function emQuickSearchUser ()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this.cc_contacts = new Array();
+		this.cc_groups  = new Array();
+	}
+
+	emQuickSearchUser.prototype.showList = function(data)
+	{
+		id = '1';
+		_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 = 'window_QuickSearchUser';
+		document.body.appendChild(el);
+		el.innerHTML = '<br>';
+		
+		if (document.getElementById('div_QuickSearchUser') == null)
+		{
+			el.innerHTML += '<div id="div_QuickSearchUser" class="quicksearchcontacts">' + 
+			'<table class="quicksearchcontacts"><tbody id="table_QuickSearchUser">' + data + '</tbody></table>' +
+			'</div>';
+			el.innerHTML += '&nbsp;&nbsp;<input type="button" value=' + get_lang("Close")+ ' id="QuickSearchUser_button_close" onClick="QuickSearchUser.close_window();">';
+		}
+		else{
+			var div_QuickSearchUser = document.getElementById('div_QuickSearchUser');
+			div_QuickSearchUser.style.display = "";
+			div_QuickSearchUser.innerHTML = '<table class="quicksearchcontacts"><tbody id="table_QuickSearchUser">' + data + '</tbody></table>';
+			var butt_close = document.getElementById("QuickSearchUser_button_close");
+			butt_close.onclick = function () {QuickSearchUser.close_window();};
+		}
+		_this.showWindow(el);
+	}
+
+	emQuickSearchUser.prototype.showWindow = function (div)
+	{
+		if(! div) {
+			alert(get_lang('The list has no participant.'));
+			return;
+		}
+							
+		if(! this.arrayWin[div.id]) {
+			div.style.width = "600px";
+			div.style.height = "350px";
+			var title = get_lang('The results were found in the Global Catalog')+':';
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";
+			div.style.width = div.offsetWidth - 5;
+
+			win = new dJSWin({			
+				id: 'QuickSearchUser_'+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();
+	}
+
+	emQuickSearchUser.prototype.close_window = function() {
+		Element("em_message_search").value = "";
+		this.arrayWin['window_QuickSearchUser'].close();
+	}
+	
+	emQuickSearchUser.prototype.create_new_message = function (cn, mail) {
+		QuickSearchUser.close_window();
+		if (openTab.type[currentTab] != 4)
+		{
+			Element("msg_number").value = "\""+cn+"\" <"+mail+">";
+			new_message("new","null");
+		}
+		else
+		{
+			var ToField = Element('to_'+currentTab);
+			ToField.value = ToField.value +"\""+cn+"\" <"+mail+">,";
+		}
+	}
+
+/* Build the Object */
+	var QuickSearchUser;
+	QuickSearchUser = new emQuickSearchUser();
Index: trunk/expressoMail1_2/js/jscode/html2xhtml.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/html2xhtml.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/html2xhtml.js	(revision 2517)
@@ -0,0 +1,1 @@
+var need_nl_before='|div|p|table|tbody|tr|td|th|title|head|body|script|comment|li|meta|h1|h2|h3|h4|h5|h6|hr|ul|ol|option|';var need_nl_after='|html|head|body|p|th|style|';var re_comment=new RegExp();re_comment.compile("^<!--(.*)-->$");var re_hyphen=new RegExp();re_hyphen.compile("-$");function get_xhtml(node,lang,encoding,need_nl,inside_pre){var i;var text='';var children=node.childNodes;var child_length=children.length;var tag_name;var do_nl=need_nl?true:false;var page_mode=true;for(i=0;i<child_length;i++){var child=children[i];switch(child.nodeType){case 1:{var tag_name=String(child.tagName).toLowerCase();if(tag_name=='')break;if(tag_name=='meta'){var meta_name=String(child.name).toLowerCase();if(meta_name=='generator')break;}if(!need_nl&&tag_name=='body'){page_mode=false;}if(tag_name=='!'){var parts=re_comment.exec(child.text);if(parts){var inner_text=parts[1];text+=fix_comment(inner_text);}}else{if(tag_name=='html'){text='<?xml version="1.0" encoding="'+encoding+'"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';}if(need_nl_before.indexOf('|'+tag_name+'|')!=-1){if((do_nl||text!='')&&!inside_pre)text+='\n';}else{do_nl=true;}text+='<'+tag_name;var attr=child.attributes;var attr_length=attr.length;var attr_value;var attr_lang=false;var attr_xml_lang=false;var attr_xmlns=false;var is_alt_attr=false;for(j=0;j<attr_length;j++){var attr_name=attr[j].nodeName.toLowerCase();if(!attr[j].specified&&(attr_name!='selected'||!child.selected)&&(attr_name!='style'||child.style.cssText=='')&&attr_name!='value')continue;if(attr_name=='_moz_dirty'||attr_name=='_moz_resizing'||tag_name=='br'&&attr_name=='type'&&child.getAttribute('type')=='_moz')continue;var valid_attr=true;switch(attr_name){case"style":attr_value=child.style.cssText;break;case"class":attr_value=child.className;break;case"http-equiv":attr_value=child.httpEquiv;break;case"noshade":break;case"checked":break;case"selected":break;case"multiple":break;case"nowrap":break;case"disabled":break;attr_value=attr_name;break;default:try{attr_value=child.getAttribute(attr_name,2);}catch(e){valid_attr=false;}break;}if(attr_name=='lang'){attr_lang=true;attr_value=lang;}if(attr_name=='xml:lang'){attr_xml_lang=true;attr_value=lang;}if(attr_name=='xmlns')attr_xmlns=true;if(valid_attr){if(!(tag_name=='li'&&attr_name=='value')){text+=' '+attr_name+'="'+fix_attribute(attr_value)+'"';}}if(attr_name=='alt')is_alt_attr=true;}if(tag_name=='img'&&!is_alt_attr){text+=' alt=""';}if(tag_name=='html'){if(!attr_lang)text+=' lang="'+lang+'"';if(!attr_xml_lang)text+=' xml:lang="'+lang+'"';if(!attr_xmlns)text+=' xmlns="http://www.w3.org/1999/xhtml"';}if(child.canHaveChildren||child.hasChildNodes()){text+='>';text+=get_xhtml(child,lang,encoding,true,inside_pre||tag_name=='pre'?true:false);text+='</'+tag_name+'>';}else{if(tag_name=='style'||tag_name=='title'||tag_name=='script'){text+='>';var inner_text;if(tag_name=='script'){inner_text=child.text;}else{inner_text=child.innerHTML;}if(tag_name=='style'){inner_text=String(inner_text).replace(/[\n]+/g,'\n');}text+=inner_text+'</'+tag_name+'>';}else{text+=' />';}}}break;}case 3:{if(!inside_pre){if(child.nodeValue!='\n'){text+=fix_text(child.nodeValue);}}else{text+=child.nodeValue;}break;}case 8:{text+=fix_comment(child.nodeValue);break;}default:break;}}if(!need_nl&&!page_mode){text=text.replace(/<\/?head>[\n]*/gi,"");text=text.replace(/<head \/>[\n]*/gi,"");text=text.replace(/<\/?body>[\n]*/gi,"");}return text;}function fix_comment(text){text=text.replace(/--/g,"__");if(re_hyphen.exec(text)){text+=" ";}return"<!--"+text+"-->";}function fix_text(text){return String(text).replace(/\n{2,}/g,"\n").replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\u00A0/g,"&nbsp;");}function fix_attribute(text){return String(text).replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");}
Index: trunk/expressoMail1_2/js/jscode/search.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/search.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/search.js	(revision 2517)
@@ -0,0 +1,1037 @@
+/**************************************************************************\
+ Início 
+\**************************************************************************/
+	function searchE()
+	{
+		this.searchW   = new Array;
+		this.name_box_search = "";
+		this.all_boxes = new Array;
+		this.type = "";
+		this.txtfields = new Array("txt_ass","txt_de","txt_body","txt_para","txt_cc","txt_cco",
+                                        "since_date", "before_date", "on_date");
+                this.selectFields = new Array("flagged", "seen", "answered", "recent");
+	}
+	
+	//Monta os forms dentro da janela;
+	searchE.prototype.showForms = function(value){
+		// Principal
+		if(!Element("window_search")) {
+			var form_search = document.createElement("DIV");
+			form_search.style.visibility = 'hidden';
+			form_search.style.top = '0px';
+			form_search.style.left = '0px';
+			form_search.id = "window_search";
+			document.body.appendChild(form_search);			
+		}
+		
+		// Pesquisa
+		if(!Element("div_form_search")){
+			var div_form_search = document.createElement("DIV");
+			div_form_search.id = "div_form_search";
+			div_form_search.style.position = "absolute";
+			div_form_search.style.left = "10px";
+			div_form_search.style.top  = "10px";
+			div_form_search.style.width = "784px";
+			div_form_search.style.height = "418px";
+			div_form_search.style.overflow = "hidden";
+			div_form_search.innerHTML = "";
+			var call_form_search = EsearchE.mount_form();
+			div_form_search.appendChild(call_form_search);
+			form_search.appendChild(div_form_search);
+
+                        Calendar._TT['WEEKEND'] = '0,6'; // hack
+                        Calendar._TT['DAY_FIRST'] = 'Mostrar %s primeiro';
+                        Calendar.setup({
+                            inputField  : 'since_date',
+                            button      : 'since_date-trigger',
+                            ifFormat    : '%d/%m/%Y',
+                            daFormat    : '%d/%m/%Y'
+                        });
+
+                        Calendar.setup({
+                            inputField  : 'before_date',
+                            button      : 'before_date-trigger',
+                            ifFormat    : '%d/%m/%Y',
+                            daFormat    : '%d/%m/%Y'
+                        });
+
+                        Calendar.setup({
+                            inputField  : 'on_date',
+                            button      : 'on_date-trigger',
+                            ifFormat    : '%d/%m/%Y',
+                            daFormat    : '%d/%m/%Y'
+                        });
+
+		}	
+		
+		if(!Element("div_button_search")){
+			var div_button_search    = document.createElement("DIV");
+				div_button_search.id = "div_button_search";
+				div_button_search.style.position = "absolute";
+				div_button_search.style.marginLeft = "430px";
+				div_button_search.style.top = "223px";
+				div_button_search.style.width = "350px";
+				div_button_search.style.height = "25px";
+				div_button_search.innerHTML = "<table style='width: 100%;' border='0' cellpadding='0' cellspacing='0' align='center'>"+
+											  "<tr>"+
+											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Search') + " onclick='EsearchE.func_search()'></td>"+
+											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Clean') + " onclick='EsearchE.func_clean()'></td>"+
+											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Close') + " onclick='EsearchE.func_close(\"hidden\")'></td>"+
+											  "</tr>"+
+											  "</table>";
+				form_search.appendChild(div_button_search);
+		}
+		
+		if(!Element("table_layer")){
+			var table_layer    = "";
+		}
+		
+		if(value == "")
+			EsearchE.showWindow(Element("window_search"));
+	
+		// Cria as caixas postais;
+		EsearchE.mount_folders();
+
+		if(value){
+			Element("check_all_msg").checked = true;
+			EsearchE.all_mailboxes();
+			EsearchE.func_search(value);
+		}
+
+	}
+	
+	//Form
+	searchE.prototype.mount_form = function(value){
+		var form_sch = document.createElement("FORM");
+		form_sch.id  = "form_sch";
+
+		form_sch.innerHTML =  '<fieldset style="width:400px; text-align:right; padding: 5px; position:absolute;">'
+							+ '	<legend>'+get_lang('Inform your search in the text fields')+'</legend>'
+							+ '	<label>'+get_lang("From")+':</label>'
+							+ '	<input style="margin-left: 6px;" type="text" id="txt_de" size="39">'
+							+ '	<br style="margin-bottom:15px"/>'
+							+ '	<label>'+get_lang('To')+':</label>'
+							+ '	<input style="margin-left: 6px;" type="text" id="txt_para" size="39">'
+							+ '	<br style="margin-bottom:15px"/>'
+							+ '	<label>'+get_lang('Cc')+':</label>'
+							+ '	<input style="margin-left: 6px;" type="text" id="txt_cc" size="39">'
+							+ '	<br style="margin-bottom:15px"/>'
+							+ '	<label>'+get_lang('Subject')+':</label>'
+							+ '	<input style="margin-left: 6px;" type="text" id="txt_ass" size="39">'
+							+ '	<br style="margin-bottom:15px"/>'
+							+ '	<label>'+get_lang('Message body')+':</label>'
+                                                        + '	<input style="margin-left: 6px;" type="text" id="txt_body" size="39">'
+
+							+ '	<br style="margin-bottom:30px"/>'
+                                                        + '     <label>'+get_lang("Since Date")+':</label>'
+                                                        + '     <input style="margin-left: 6px;" type="text" id="since_date" size="8">'
+                                                        + '     <img id="since_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
+                                                        + '     <label style="margin-left: 20px;">'+get_lang('Before Date')+':</label>'
+                                                        + '     <input style="margin-left: 6px;" type="text" id="before_date" size="8">'
+                                                        + '     <img id="before_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
+                                                        + '     <br style="margin-bottom:15px"/>'
+
+                                                        + '     <label>'+get_lang('On Date')+':</label>'
+                                                        + '     <input style="margin-left: 6px;" type="text" id="on_date" size="8">'
+                                                        + '     <img style="margin-right: -8px" id="on_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>&nbsp;&nbsp;</spam>'
+                                                        + '     <br style="margin-bottom:30px"/>'
+
+                                                        + '     <label>'+get_lang('Flags')+':</label>'
+                                                        + '     <select style="width:15em; margin-left: 6px" name="flagged" id="flagged">'
+                                                        + '     <option value=""/>'
+                                                        + '     <option value="FLAGGED">'+ get_lang("Flagged") +'</option>'
+                                                        + '     <option value="UNFLAGGED">'+ get_lang("Unflagged") +'</option>'
+                                                        + '     </select>'
+                                                        + '     <br style="margin-bottom:15px"/>'
+                                                        + '     <select style="width:15em;" name="seen" id="seen">'
+                                                        + '     <option value=""/>'
+                                                        + '     <option value="SEEN">'+ get_lang("Seen") +'</option>'
+                                                        + '     <option value="UNSEEN">'+ get_lang("Unseen") +'</option>'
+                                                        + '     </select>'
+                                                        + '     <br style="margin-bottom:15px"/>'
+                                                        + '     <select style="width:15em;" name="answered" id="answered">'
+                                                        + '     <option value=""/>'
+                                                        + '     <option value="ANSWERED">'+ get_lang('Answered/Forwarded') +'</option>'
+                                                        + '     <option value="UNANSWERED">'+ get_lang('Unanswered/Unforwarded') +'</option>'
+                                                        + '     </select>'
+                                                        + '     <br style="margin-bottom:15px"/>'
+                                                        + '     <select style="width:15em;" name="recent" id="recent">'
+                                                        + '     <option value=""/>'
+                                                        + '     <option value="RECENT">'+ get_lang('Recent') +'</option>'
+                                                        + '     <option value="OLD">'+ get_lang('Old') +'</option>'
+                                                        + '     </select>'
+
+							+ '	<br style="margin-bottom:60px"/>'
+							+ '</fieldset>'
+							+ '<fieldset style="width:350px; padding: 5px; position:absolute; margin-left: 414px">'
+							+ '	<legend>'+get_lang('Search the messages in these folders')+'</legend>'
+							+ '	<div id="folders" style="width:160px; height:150px;float:left;margin-bottom:10px;"></div>'
+							+ '	<div style="float:left;height:100px;padding-top:50px;margin: 0 3px;">'
+							+ '		<input type="button" id="incluir" name="incluir" value=">>" onclick="EsearchE.add_mailboxes()">'
+							+ '		<br style="margin-bottom:15px">'
+							+ '		<input type="button" id="excluir" name="excluir" value="<<" onclick="EsearchE.del_mailboxes()">'
+							+ '	</div>'
+							+ ' <div style="float:left;">'	
+							+ '	 <select multiple id="sel_search_nm_box1" name="sel_search_nm_box1" style="width:140px;height:150px;"></select>'
+							+ ' </div>'
+							+ '	<br clear="both">'
+							+ '	<input type="checkBox" id="check_all_msg" name="check_all_msg" onclick="EsearchE.all_mailboxes()">'
+							+ '	<b>'+get_lang('In all the folders')+'</b>'
+							+ '</fieldset>';
+		
+		return form_sch;
+	}
+
+	// Pastas;
+	searchE.prototype.mount_folders = function(){
+		expresso.connector.loadScript("jscode/TreeS");
+
+		if( Element("div_folders_search") == null){
+			var div_folders = document.createElement("DIV");
+				div_folders.id = "div_folders_search";
+				div_folders.style.width = "155px";
+				div_folders.style.height = "152px";
+				div_folders.style.borderStyle = "outset";
+				div_folders.style.borderColor = "black";
+				div_folders.style.borderWidth = "1px";
+				div_folders.style.background  = "#F7F7F7";
+				div_folders.style.overflow = "auto";
+				div_folders.innerHTML = "";
+				var dest_div = Element("folders");
+				dest_div.appendChild(div_folders);
+		}		
+		ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
+	}
+	
+	//This func returns the most recent date
+	function date_comp(a,b)
+	{
+		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
+		data1 = data1[0].substr(0, data1[0].indexOf('--'))
+		with ( data1 ) 
+			data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
+		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
+		data2 = data2[0].substr(0, data2[0].indexOf('--'))
+		with ( data2 )
+			data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
+		return data2 - data1;
+	}
+	function date_comp_reverse(a,b)
+	{
+		return date_comp(b,a);
+	}
+	
+	function box_comp(a,b)
+	{
+	var compare = [];
+	compare[0] = a.substr(0, a.indexOf('--'));
+	compare[0] = compare[0].toLowerCase();
+	var temp=compare[0];
+	compare[1] = b.substr(0, b.indexOf('--'))
+	compare[1] = compare[1].toLowerCase();
+	compare.sort();
+	if (temp != compare[0])
+		return +1;
+	else
+		return -1;
+	}
+	function box_comp_reverse(a,b)
+	{
+		return box_comp(b,a);
+	}
+
+	function who_comp(a,b)
+	{
+	var compare = [];
+	compare[0] = a.substr(a.indexOf('--')+2);
+	compare[0] = compare[0].toLowerCase();
+	var temp=compare[0];
+	compare[1] = b.substr(b.indexOf('--')+2);
+	compare[1] = compare[1].toLowerCase();
+	compare.sort();
+	if (temp != compare[0])
+		return +1;
+	else
+		return -1;
+	}
+	function who_comp_reverse(a,b)
+	{
+		return who_comp(b,a);
+	}
+
+	function subject_comp(a,b)
+	{
+	var compare = [];
+	compare[0] = a.substr(a.indexOf('--')+2);
+	compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
+	compare[0] = compare[0].toLowerCase();
+	var temp=compare[0];
+	compare[1] = b.substr(b.indexOf('--')+2);
+	compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
+	compare[1] = compare[1].toLowerCase();
+	compare.sort();
+	if (temp != compare[0])
+		return +1;
+	else
+		return -1;
+	}
+	function subject_comp_reverse(a,b)
+	{
+		return subject_comp(b,a);
+	}
+
+	function size_comp(a,b)
+	{
+		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
+		data1 = data1[0].substr(data1[0].indexOf('--')+2)
+		data1 = data1.substr(0,data1.indexOf('--'))
+		var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
+		if (data1.match("k"))
+			size_a = size_a * 1024;
+		else
+			if (data1.match("m"))
+				size_a = size_a * 1048576;
+		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
+		data2 = data2[0].substr(data2[0].indexOf('--')+2)
+		data2 = data2.substr(0,data2.indexOf('--'))
+		var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
+		if (data2.match("k"))
+			size_b = size_b * 1024;
+		else
+			if (data2.match("m"))
+				size_b = size_b * 1048576;
+		return size_b - size_a;
+	}
+	function size_comp_reverse(a,b)
+	{
+		return size_comp(b,a);
+	}
+
+	// Form resultado
+	searchE.prototype.mount_result = function(data,sort_type){
+		var nw_array = new Array;
+		var var_tmp = data.substr(2, data.length - 4);
+		var_tmp  = var_tmp.split("####");
+		var cont = parseInt(0);
+		switch (sort_type)
+		{
+			case 'SORTDATE':
+				var_tmp.sort(date_comp);
+				break;
+			case 'SORTDATE_REVERSE':
+				var_tmp.sort(date_comp_reverse);
+				break;
+			case 'SORTBOX':
+				var_tmp.sort(box_comp);
+				break;
+			case 'SORTBOX_REVERSE':
+                                var_tmp.sort(box_comp_reverse);
+                                break;
+			case 'SORTSUBJECT':
+				var_tmp.sort(subject_comp);
+				break;
+			case 'SORTSUBJECT_REVERSE':
+                                var_tmp.sort(subject_comp_reverse);
+				break;
+			case 'SORTWHO':
+				var_tmp.sort(who_comp);
+				break;
+			case 'SORTWHO_REVERSE':
+                                var_tmp.sort(who_comp_reverse);
+				break;
+			case 'SORTSIZE':
+				var_tmp.sort(size_comp);
+				break;
+			case 'SORTSIZE_REVERSE':
+				var_tmp.sort(size_comp_reverse);
+				break;
+			default:
+				var showMsg = 1;
+		}
+
+		for(var i=0; i < var_tmp.length; i++){
+			if(var_tmp[i] != "")
+			{
+				nw_array[cont] = var_tmp[i];
+				cont++;
+			}
+		}
+
+                if( (preferences.search_result_number != '65536') && (nw_array.length > 0) && (nw_array.length >= preferences.search_result_number) ){
+                    nw_array.length = preferences.search_result_number;
+                    write_msg(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
+                }
+                else {
+                        write_msg(nw_array.length + " "+ get_lang('results found'));
+                }
+
+		numBox++;
+		var border_id = create_border(get_lang("Search Results"), "search_" + numBox);
+                if (!border_id)
+                {
+                    return;
+                }
+		currentTab = border_id;
+                openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
+		openTab.type[currentTab] = 1;
+		var table = document.createElement("TABLE");
+		table.id    = "table_resultsearch_" + numBox;
+		table.frame = "void";
+		table.rules = "rows";
+		table.cellPadding = "0";
+		table.cellSpacing = "0";
+		table.className = "table_box";
+
+		var tbody = document.createElement("TBODY");
+		tbody.id    = "tbody_box_" + numBox;
+
+		for( var i=0; i < nw_array.length; i++){
+			var tr = document.createElement("TR");
+			tr.style.height = preferences.line_height;
+
+			if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
+			{
+				var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
+				aux1 = aux1[0].split("--");
+				nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
+				var aux = [];
+				aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
+				nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
+				aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
+				aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
+				aux = aux.concat(aux1);
+			}
+			else
+			{
+				var aux = nw_array[i].split("--");
+			}
+
+			var mailbox = aux[0];
+			var uid_msg = aux[6];
+			var subject = aux[2];
+			tr.id = uid_msg+"_s"+global_search;
+
+			// Keep the two lines together please
+			tr.setAttribute('name',mailbox);
+			tr.name = mailbox;
+
+			if (aux[5].match("U"))
+				add_className(tr,'tr_msg_unread');
+			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
+            var _onclick = function () { proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);};
+            for(var j=0 ; j < 10 ; j++)
+			{
+				var td = document.createElement("TD");
+				if (j == 0)
+				{
+					td.style.width = "1%";
+					var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
+					
+				}
+				if (j == 1)
+				{
+					td.style.width = "2%";
+					if (aux[5].match('T'))
+					{
+						attachNum = parseInt(aux[5].substr(aux[5].indexOf('T')+1));
+						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
+					}
+					else
+						td1 = '';
+				}
+				if (j == 2)
+				{
+					td.style.width = "1%";
+					td.id = "td_message_answered_"+uid_msg;
+					if (aux[5].match('X'))
+						td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
+					else
+						if (aux[5].match('A'))
+							td1 = '<img src=templates/'+template+'/images/answered.gif>';
+						else
+							td1 = '';
+				}
+				if (j == 3)
+				{
+					td.style.width = "1%";
+					td.id = "td_message_important_"+uid_msg;
+					if (aux[5].match("F"))
+					{
+						add_className(tr, 'flagged_msg');
+						td.style.background = "url(templates/"+template+"/images/important.gif) no-repeat center";
+					}
+					else
+						td1 = '';
+				}
+				if (j == 4)
+				{
+					td.style.width = "1%";
+					td.id = "td_message_sent_"+uid_msg;
+					td1 = '';
+				}
+				if (j == 5)
+				{
+					td.style.width = "14%";
+					td.onclick = _onclick;
+					var nm_box = aux[0].split(cyrus_delimiter);
+					var td1 = nm_box.pop();
+					td.setAttribute("NoWrap","true");
+					td.style.overflow = "hidden";
+					td.style.color = "#42795b";
+					td.style.fontWeight = "bold";
+					
+					var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
+                                        if ((tmp = translatedFolders.get(td1)))
+                                        {
+                                            td1 = tmp;
+                                        }
+
+					if(proxy_mensagens.is_local_folder(td1)) {
+						var td1 = this.aux_local_folder_display(td1);
+					}
+				}
+				if( j == 6)
+				{
+					if (aux[1].length > 29)
+						aux[1] = aux[1].substr(0,29) + "...";
+					td.style.width = "20%";
+					td.onclick = _onclick;
+					td.setAttribute("NoWrap","true");
+                                        td.style.overflow = "hidden";
+					var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
+				}
+				if( j == 7)
+				{
+					var subject_encode = url_encode(subject);
+					if (! subject_encode)
+						aux[2] = get_lang("no subject") + "...";
+					if (aux[2].length > 70)
+						aux[2] = aux[2].substr(0,70) + "...";
+					td.style.width = "35%";
+					td.onclick = _onclick;
+                                        td.setAttribute("NoWrap","true");
+                                        td.style.overflow = "hidden";
+					var td1  = aux[2];
+
+				}
+				if( j == 8)
+				{
+					td.style.width = "15%";
+					td.align = "center";
+					td.onclick = _onclick;
+					var td1  = aux[3];
+				}
+				if( j == 9)
+				{
+					td.style.width = "10%";
+					td.align = "center";
+					td.onclick = _onclick;
+					var td1  = aux[4];
+				}
+				if (j == 10)
+				{
+					if (aux[5].match("U"))
+						add_className(tr, 'tr_msg_unread');
+					if (aux[5].match("F"))
+						add_className(tr, 'flagged_msg');
+					var td1 = '';
+				}
+				td.innerHTML = td1;
+				tr.appendChild(td);
+			}
+			aux.splice(0,(aux.length));
+
+		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
+		tbody.appendChild(tr);
+		}
+		global_search++; //Tabs from search must not have the same id on its tr's
+		
+		table.appendChild(tbody);
+
+	var content_search =  Element('content_id_search_' + numBox);
+	// BEGIN MAKE THE SCROLL HEIGHT		
+	var defaultWidth = document.body.offsetWidth - 31;
+	var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
+	if(!menuHidden)
+		defaultWidth -= Element("folderscol").offsetWidth;			
+	var bar = Element("toolbar");
+	var offset = 0;
+	if(bar.style.visibility != 'hidden') 
+		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;		
+	var div_scroll_result = document.createElement("DIV");
+	div_scroll_result.id = "divScrollMain_"+numBox;
+	div_scroll_result.style.height = document.body.clientHeight - offset - 120;
+	content_search.style.height = document.body.clientHeight - offset - 80;
+	div_scroll_result.style.overflow = "auto";
+	div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
+	// END MAKE THE SCROLL HEIGHT		
+		
+	
+		if(is_ie)
+			Element("border_table").width = "99.5%";
+		
+		// Put header
+		var table_element = document.createElement("TABLE");
+		var tbody_element = document.createElement("TBODY");
+		table_element.setAttribute("id", "table_message_header_box");
+		table_element.className = "table_message_header_box";
+		tr_element = document.createElement("TR");
+		tr_element.className = "message_header";
+		td_element0 = document.createElement("TD");
+		td_element0.setAttribute("width", "1%");
+		chk_box_element = document.createElement("INPUT");
+		chk_box_element.id  = "chk_box_select_all_messages";
+		chk_box_element.setAttribute("type", "checkbox");
+		chk_box_element.className = "checkbox";
+		chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
+		chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
+		chk_box_element.onkeydown = function (e){
+			if (is_ie)
+			{
+				if ((window.event.keyCode) == 46)
+					delete_msgs(current_folder,'selected','null');
+			}
+			else
+			{
+				if ((e.keyCode) == 46)
+					delete_msgs(current_folder,'selected','null');
+			}
+		};
+		
+		td_element0.appendChild(chk_box_element);
+		td_element1 = document.createElement("TD");
+		td_element1.setAttribute("width", "20%");
+		td_element1.align = "left";
+		if (sort_type == 'SORTBOX')
+		{
+			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
+			td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
+		}
+		else
+		{
+			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
+			if  (sort_type == 'SORTBOX_REVERSE')
+				td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
+			else
+				td_element1.innerHTML = get_lang("Folder");
+		}
+		td_element2 = document.createElement("TD");
+		td_element2.setAttribute("width", "20%");
+		td_element2.align = "left";
+		if (sort_type == 'SORTWHO')
+		{
+			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
+			td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
+		}
+		else
+		{
+			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
+			if  (sort_type == 'SORTWHO_REVERSE')
+				td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
+			else
+				td_element2.innerHTML = get_lang("who");
+		}
+		td_element3 = document.createElement("TD");
+		td_element3.setAttribute("width", "35%");
+		td_element3.align = "left";
+		if (sort_type == 'SORTSUBJECT')
+		{
+			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
+			td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
+		}
+		else
+		{
+			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
+			if  (sort_type == 'SORTSUBJECT_REVERSE')
+				td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
+			else
+				td_element3.innerHTML = get_lang("subject");
+		}
+		td_element4 = document.createElement("TD");
+		td_element4.setAttribute("width", "15%");
+		td_element4.align = "center";
+		if (sort_type == 'SORTDATE')
+		{
+			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
+			td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
+		}
+		else
+		{
+			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
+			if  (sort_type == 'SORTDATE_REVERSE')
+				td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
+			else
+				td_element4.innerHTML = get_lang("Date");
+		}
+		td_element5 = document.createElement("TD");
+		td_element5.setAttribute("width", "10%");
+		td_element5.align = "center";
+		if (sort_type == 'SORTSIZE')
+		{
+			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
+			td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
+		}
+		else
+		{
+			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
+			if  (sort_type == 'SORTSIZE_REVERSE')
+				td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
+			else
+				td_element5.innerHTML = get_lang("Size");
+		}
+		tr_element.appendChild(td_element0);
+		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);
+		tbody_element.appendChild(tr_element);
+		table_element.appendChild(tbody_element);
+		content_search.appendChild(table_element);
+		/*end of "put header"*/
+		
+		if (!expresso_offline) {
+/*			var span_options = document.createElement("SPAN");
+			if (span_options) 
+				span_options.innerHTML = '<span title="' + get_lang("Delete") + '" style="margin-top:3px;margin-left:8px" class="message_options" onclick="javascript:move_search_msgs(\'' + content_search.id + '\');">' + get_lang("Delete") + '</span> | ' +
+				'<span title="' +
+				get_lang("Move") +
+				'" class="message_options" onclick=wfolders.makeWindowNew(\"' +
+				content_search.id +
+				'\",\"move_to\",true)>' +
+				get_lang("Move") +
+				'</span>';*/
+			div_scroll_result.appendChild(table);
+			content_search.appendChild(div_scroll_result);
+			/*if (span_options) 
+				content_search.appendChild(span_options);*/
+		}
+		else {
+			div_scroll_result.appendChild(table);
+			content_search.appendChild(div_scroll_result);
+		}
+	}
+
+	searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
+		var handler_get_msg = function(data){
+			if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
+			else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));}
+			//set_msg_as_read(msgs_to_set[i], false);
+		}
+		proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
+		/*var args   = "$this.imap_functions.get_info_msg";
+		var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
+		cExecute(args,handler_get_msg,params);*/
+
+	}
+
+	// Adiciona caixas postais na busca;
+	searchE.prototype.add_mailboxes = function(){
+		var sel = Element("sel_search_nm_box1");
+		if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
+			var name_box     = this.name_box_search.split(cyrus_delimiter);
+			if(this.name_box_search == "")
+				return false;
+			var name_box_def = "";
+			if(name_box.length != 1){
+				name_box_def = name_box[(name_box.length-1)];
+			}else{
+				name_box_def = get_lang("Inbox");		
+			}
+		}
+		else {
+			if(this.name_box_search=='local_root')
+				return;
+			if(this.name_box_search=='local_Inbox')
+				name_box_def = get_lang("Inbox");
+			else if(this.name_box_search.indexOf("/")!="-1") {
+				final_pos = this.name_box_search.lastIndexOf("/");
+				name_box_def = this.name_box_search.substr(final_pos+1);
+			}
+			else
+				name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
+		}
+		if( sel.length > 0){
+			for(var i=0; i < sel.options.length; i++){
+				if(sel.options[i].value == this.name_box_search){
+					alert(get_lang('This message is already selected!'));
+					return false;
+				}
+			}
+		}
+		var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
+		sel[sel.length] = opt;
+	}
+	// Remove as caixas postais na busca;
+	searchE.prototype.del_mailboxes = function(){
+		var sel = Element("sel_search_nm_box1");
+		if(sel.length > 0){
+			for(var i=0; i < sel.options.length; i++){
+				if(sel.options[i].selected == true){
+					sel.options[i] = null;
+					i--;
+				}
+			}
+		}
+	
+	}
+	// todas as caixas
+	searchE.prototype.all_mailboxes = function(){
+		var value = Element("check_all_msg").checked;
+		var cont = parseInt(0);
+		if(value){
+			if(EsearchE.all_boxes.length > 0){
+				EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));			
+			}
+			for(var i=0; i < folders.length; i++){
+				EsearchE.all_boxes[cont] = folders[i].folder_id;
+				cont++;
+			}
+		}else{
+			EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
+		}
+	}
+
+	// Search;
+	searchE.prototype.func_search = function(value){
+		var fields = "##";
+			// Verifica se os campos estão preenchidos;
+			if(trim(Element("txt_ass").value) != ""){
+				fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
+			}
+			if(trim(Element("txt_body").value) != ""){
+				fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
+			}
+			if(trim(Element("txt_de").value) != ""){
+				fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
+			}
+			if(trim(Element("txt_para").value) != ""){
+				fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
+			}
+			if(trim(Element("txt_cc").value) != ""){
+				fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
+			}
+                        if (trim(Element("since_date").value) != ""){
+                            if (validate_date(Element("since_date").value))
+                            {
+                                fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##";
+                            }
+                            else
+                                {
+                                    alert(get_lang('Invalid date on field %1'), get_lang('Since Date'));
+                                    return false;
+                                }
+                        }
+                        if (trim(Element("before_date").value) != ""){
+                            if (validate_date(Element("before_date").value))
+                            {
+                                fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##";
+                            }
+                            else
+                                {
+                                    alert(get_lang('Invalid date on field %1'), get_lang('Before Date'));
+                                    return false;
+                                }
+                        }
+                        if(trim(Element("on_date").value) != ""){
+                            if (validate_date(Element("on_date").value))
+                            {
+                                fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##";
+                            }
+                            else
+                                {
+                                    alert(get_lang('Invalid date on field %1'), get_lang('On Date'));
+                                    return false;
+                                }
+
+                        }
+                        if(trim(Element("flagged").options[Element("flagged").selectedIndex].value) != ""){
+                            if (Element("flagged").options[Element("flagged").selectedIndex].value == "FLAGGED"){
+                                fields += "FLAGGED##";
+                            }
+                            else {
+                                fields += "UNFLAGGED##";
+                            }
+                        }
+                        if(trim(Element("seen").options[Element("seen").selectedIndex].value) != ""){
+                            if (Element("seen").options[Element("seen").selectedIndex].value == "SEEN"){
+                                fields += "SEEN##";
+                            }
+                            else {
+                                fields += "UNSEEN##";
+                            }
+                        }
+                        if(trim(Element("answered").options[Element("answered").selectedIndex].value) != ""){
+                            if (Element("answered").options[Element("answered").selectedIndex].value == "ANSWERED"){
+                                fields += "ANSWERED##";
+                            }
+                            else {
+                                fields += "UNANSWERED##";
+                            }
+                        }
+                        if(trim(Element("recent").options[Element("recent").selectedIndex].value) != ""){
+                            if (Element("answered").options[Element("answered").selectedIndex].value == "RECENT"){
+                                fields += "RECENT##";
+                            }
+                            else {
+                                fields += "OLD##";
+                            }
+                        }
+			if(value) {
+				fields = "##ALL " +  "<=>" +url_encode(value) + "##";
+			}
+
+		if(fields == "##"){
+			alert(get_lang("Define some search parameters!"));
+			return false;
+		}
+		var local_folders = new Array();
+		var temp;
+		
+		if(Element("check_all_msg").checked){
+			this.all_mailboxes();
+			var nm_box = new Array;
+			for(var i=0; i < EsearchE.all_boxes.length; i++){
+				nm_box[i] = EsearchE.all_boxes[i] + fields;
+			}
+			if (preferences.use_local_messages == 1) {
+				temp = expresso_local_messages.list_local_folders();
+				for (var x in temp) {
+					local_folders.push(temp[x][0]);
+				}
+			}
+		}else{
+			var nm_box = new Array;
+			var sel_combo = Element("sel_search_nm_box1");
+			if( sel_combo.options.length <= 0){
+				alert(get_lang("Define the boxes to search!"));
+				return false;
+			}
+			
+			for(var i=0; i < sel_combo.options.length; i++){
+				sel_combo.options[i].selected = true;
+			}
+			for(var i=0; i < sel_combo.options.length; i++){
+				if(sel_combo.options[i].selected == true){
+					if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
+						nm_box[nm_box.length] = sel_combo.options[i].value + fields;
+					else
+						local_folders.push(sel_combo.options[i].value.substr(6));
+				}
+			}
+		}
+		var handler = function(data){
+			var tmp;
+			var countTmp= new Array();
+
+                        var dataTemp = data.split('=sumResults=');
+                        var sumResults = dataTemp[0];
+
+                        var data = dataTemp[1] ? dataTemp[1] : dataTemp[0];
+
+			if (local_folders.length > 0) {
+				tmp = expresso_local_messages.search(local_folders, fields);
+				if (tmp!=false) {
+					var tmp2 = tmp.substr(2, data.length - 4);
+					countTmp = tmp.split('####');
+				}
+			}
+//			if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
+//			if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number))
+//                        {
+//                            EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);
+//                        }
+//                        else if (data == 'many results' || countTmp.length >= preferences.search_result_number)
+//                        {
+//                            alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
+//                        }
+
+                        if ((sumResults == "none") && (countTmp.length==0)){
+                            alert(get_lang("None result was found."));
+                        }
+                        else
+                        {
+                            EsearchE.mount_result((sumResults=='none')?tmp:(countTmp.length==0)?data:data+tmp);
+                        }
+
+		}
+		var args   = "$this.imap_functions.search_msg";
+		var params = "condition=" + nm_box;
+		if(expresso_offline)
+			handler('none');
+		else
+			cExecute(args,handler,params);
+	}
+	// clean;
+	searchE.prototype.func_clean = function(){
+		// Limpa os campos;
+            for(var i=0; i < this.txtfields.length; i++){
+                    if(Element(this.txtfields[i]) != null){Element(this.txtfields[i]).value = "";}
+            }
+
+            for(i = 0; i < this.selectFields.length; i++)
+            {
+                if (Element(this.selectFields[i]))
+                {
+                    Element(this.selectFields[i]).selectedIndex = 0;
+                }
+            }
+	    if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
+
+	    EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
+	  	EsearchE.del_mailboxes();
+	}
+
+	// close
+	searchE.prototype.func_close = function(type){
+		var _this = this;
+		_this.name_box_search = "";
+		EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
+		_this.type = type;
+		_this.searchW['window_search'].close();
+	}
+	// Monta a janela em tela;
+	searchE.prototype.showWindow = function(div){
+		if(!this.searchW[div.id]) {
+			div.style.width = "804px";
+			div.style.height = "440px";
+			div.style.visibility = "hidden";
+			div.style.position = "absolute";
+			div.style.zIndex = "10003";
+			var title = ":: "+ get_lang("Search")+" ::";
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";
+
+			win = new dJSWin({
+				id: 'ccList'+div.id,
+				content_id: div.id,
+				width: wWidth,
+				height: wHeight,
+				title_color: '#3978d6',
+				bg_color: '#eee',
+				title: title,
+				title_text_color: 'white',
+				button_y_img: '../phpgwapi/images/win_min.gif',
+				button_x_img: '../phpgwapi/images/winclose.gif',
+				border: true });
+			this.searchW[div.id] = win;
+			win.draw();
+		}else{
+			var _this = this;
+			win = this.searchW[div.id];
+			if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
+			win.draw();
+		}
+		win.open();	
+	}
+	
+	searchE.prototype.aux_local_folder_display = function(folder) {
+		if(!expresso_offline)
+			return "(Local) " + lang_folder(folder.substr(6));
+		else
+			return lang_folder(folder.substr(6));
+	}
+	
+// Cria o objeto
+	var EsearchE;
+	EsearchE = new searchE();
Index: trunk/expressoMail1_2/js/jscode/InfoQuota.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/InfoQuota.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/InfoQuota.js	(revision 2517)
@@ -0,0 +1,217 @@
+function emInfoQuota ()
+	{
+		this.win;
+		this.el;	
+		this.preLoad();
+	}
+	
+	emInfoQuota.prototype.preLoad = function(){
+		if(Element("table_quota")) {
+			Element("table_quota").style.cursor = "pointer";
+			Element("table_quota").title = get_lang("View Quota Usage in Folders");			
+			Element("table_quota").onclick = function (){
+				InfoQuota.showList();
+			}		
+		}
+	}
+
+	emInfoQuota.prototype.showList = function()
+	{
+		var _this = this;		
+		var el = Element("window_InfoQuota");
+		if(!el) {
+			el = document.createElement("DIV");
+			el.style.visibility = "hidden";
+			el.style.position = "absolute";
+			el.style.left = "0px";
+			el.style.top = "0px";
+			el.style.overflowY = "auto";
+			el.align = "center";			
+			div.style.height = "400px";			
+			el.id = 'window_InfoQuota';
+			document.body.appendChild(el);
+		}		
+		
+		var handler_buildQuota = function(data){			
+			el.appendChild(InfoQuota.buildQuota(data));			
+			el.innerHTML += '<br><input style="margin-bottom:10px" type="button" value=' + get_lang("Close")+ 
+			' id="InfoQuota_button_close" onClick="InfoQuota.close_window();">';			
+			_this.showWindow(el);
+		}
+		
+		cExecute ("$this.imap_functions.get_quota_folders", handler_buildQuota);		
+	}
+
+	emInfoQuota.prototype.showWindow = function (div)
+	{							
+		if(! this.win) {
+			div.style.height = "350px";
+			div.style.width = "450px";
+			var title = get_lang("View Quota Usage in Folders");			
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";			
+
+			this.win = new dJSWin({			
+				id: 'win_'+div.id,
+				content_id: div.id,
+				width: wWidth,
+				height: wHeight,
+				title_color: '#3978d6',
+				title_align: 'center',
+				bg_color: '#eee',
+				title: title,						
+				title_text_color: 'white',
+				button_x_img: '../phpgwapi/images/winclose.gif',
+				border: true });
+						
+			this.win.draw();
+			this.win.title.align = "center";
+		}
+		
+		this.win.open();
+	}
+
+	emInfoQuota.prototype.close_window = function() {		
+		this.win.close();
+	}
+	
+	emInfoQuota.prototype.buildQuota = function (data){
+		if(Element("window_InfoQuota")){
+			Element("window_InfoQuota").innerHTML = '';
+		}
+		var content = '';
+		var q_limit = data.quota_root.quota_limit;		
+		
+		var value = '';
+		var q_used = '';
+		var table = document.createElement("TABLE");
+		table.id = "table_quota";
+		table.style.border="1px solid #CCC";
+		table.style.marginTop = "10px";
+		table.style.width="100%";
+		table.style.height="80%";
+		table.style.background = "#FFF";
+		table.cellSpacing = 5;
+		table.cellPadding = 0;		 		
+		var thead = document.createElement("THEAD");
+		var tbody = document.createElement("TBODY");
+		var tfoot = document.createElement("TFOOT");
+		table.appendChild(thead);
+		table.appendChild(tbody);
+		table.appendChild(tfoot);		
+		thead.style.background = "#FFF";
+		var tr_thead = document.createElement("TR");
+		tr_thead.style.fontSize = "10pt";
+		tr_thead.style.height = '10px';
+		tr_thead.style.background = "#3978d6";
+		tr_thead.style.color = "white";
+		tr_thead.style.fontWeight = "bold";
+		tr_thead.outerHTML = tr_thead.outerHTML;
+		thead.appendChild(tr_thead);
+		var th_thead = document.createElement("TH");
+		th_thead.style.paddingRight = '5px';
+		th_thead.style.paddingLeft = '5px';		
+		th_thead.innerHTML = get_lang('Folder');
+		tr_thead.appendChild(th_thead);		
+		th_thead = document.createElement("TH");
+		th_thead.style.paddingRight = '5px';
+		th_thead.style.paddingLeft = '5px';
+		th_thead.style.align = "center";
+		th_thead.colSpan = "2"; 
+		th_thead.noWrap = "true";		
+		th_thead.innerHTML = get_lang('% used');
+		tr_thead.appendChild(th_thead);		
+		th_thead = document.createElement("TH");
+		th_thead.style.paddingRight = '5px';
+		th_thead.style.paddingLeft = '5px';
+		th_thead.noWrap = "true";
+		th_thead.innerHTML = get_lang("Size")+" (bytes)";
+		tr_thead.appendChild(th_thead);
+		tbody.style.overflowY = "auto";
+		tbody.style.overflowX = "hidden";
+		tbody.style.width = "50%";		
+		var last_folder = 'null';
+		for(var x in data) {
+			if(x == 'quota_root') continue;				
+			q_used = data[x]['quota_used'];
+			value = data[x]['quota_percent'];
+			td01 = document.createElement("TD");
+			td01.align="left";			
+			if(x.indexOf(last_folder+"/") == -1){
+				last_folder = x;
+				td01.innerHTML = "&nbsp;"+x;
+			}
+			else {
+				var a_folder = x.split('/');
+				for (var i =0; i< a_folder.length;i++)
+					td01.innerHTML  += "&nbsp;&nbsp;";				
+				td01.innerHTML  += a_folder[a_folder.length-1];
+			}
+			
+			td01.style.borderBottom = "1px dashed #DDD";
+			td01.width="40%";
+			td01.setAttribute("noWrap","true");			
+			td02 = document.createElement("TD");
+			td02.align="center";
+			td02.width="5%";
+			td02.setAttribute("noWrap","true");			
+			td02.innerHTML = value+"%";
+			td11 = document.createElement("TD");
+			td11.width="10%";
+			td11.align="center";
+			td11.setAttribute("noWrap","true");
+			td11.style.borderBottom = "1px dashed #DDD";
+			td11.innerHTML += '&nbsp;<span class="boxHeaderText">'+q_used+"</span>";
+			tr2 = document.createElement("TR");
+			td21 = document.createElement("TD");
+			td21.setAttribute("noWrap","true");			
+			td21.height="15px";
+			td22 = document.createElement("TD");	
+			td21.setAttribute("background","../phpgwapi/templates/"+template+"/images/dsunused.gif");
+			table221 = document.createElement("TABLE");
+			tbody221 = document.createElement("TBODY");
+			table221.appendChild(tbody221);
+			table221.style.width=value+"%";	
+			td21.width="30%";
+			table221.cellSpacing = 0;
+			table221.cellPadding = 0;
+			tr221 = document.createElement("TR");
+			td221 = document.createElement("TD");
+			td221.height="15px";
+			td221.className = 'dsused';			
+			tr221.appendChild(td221);
+			tbody221.appendChild(tr221);
+			td21.appendChild(table221);
+			tr2.appendChild(td01);
+			tr2.appendChild(td02);
+			tr2.appendChild(td21);
+			tr2.appendChild(td11);	
+			tbody.appendChild(tr2);
+		}	
+		var tr_tfoot = document.createElement("TR");
+		tr_tfoot.style.fontSize = "10pt";		
+		tr_tfoot.style.color = "#bbb";
+		tr_tfoot.style.fontWeight = "bold";
+		tfoot.appendChild(tr_tfoot);		
+		var th_tfoot = document.createElement("TH");
+		th_tfoot.style.align = "center";
+		th_tfoot.colSpan = "4";
+		th_tfoot.style.paddingRight = '5px';
+		th_tfoot.style.paddingLeft = '5px';		
+		th_tfoot.innerHTML = get_lang("You are currently using %1Mb (%2%).",data.quota_root.quota_used, data.quota_root.quota_percent);
+		tr_tfoot.appendChild(th_tfoot);		
+		return table;
+	}
+	
+/* Build the Object */	
+	var InfoQuota;
+	InfoQuota = new emInfoQuota();
+	
+	/* Override function :: refresh and auto_refresh */	
+	var __build_quota = build_quota;
+	build_quota = function (data) {
+		__build_quota(data);
+		if(InfoQuota.win)
+			InfoQuota.win.close();
+		InfoQuota.preLoad();
+	}
Index: trunk/expressoMail1_2/js/jscode/messages_controller.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/messages_controller.js	(revision 2517)
@@ -0,0 +1,327 @@
+/**
+ * @author diogenes
+ */
+
+	function messages_proxy() {
+		
+	}
+/**
+ * Retorna os cabeçalhos das mensagens a serem desenhadas na caixa de email.
+ */
+	messages_proxy.prototype.messages_list = function(folder,msg_range_begin,emails_per_page,sort_box_type,search_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip,call_back) {
+		if(this.is_local_folder(folder)) {
+			var real_folder = folder.substr(6);		
+			var msgs = expresso_local_messages.get_local_range_msgs(real_folder,msg_range_begin,preferences.max_email_per_page,sort_box_type,sort_box_reverse,search_box_type,preferences.preview_msg_subject,preferences.preview_msg_tip);
+			eval('call_back(msgs)');
+			draw_tree_local_folders();
+		}else {
+			cExecute ("$this.imap_functions.get_range_msgs2&folder="+folder+"&msg_range_begin="+msg_range_begin+"&msg_range_end="+emails_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", call_back);
+		}
+	}
+
+	messages_proxy.prototype.get_msg = function(msg_number,msg_folder,set_flag,call_back) {
+		if(this.is_local_folder(msg_folder)) {
+			if(set_flag)
+				expresso_local_messages.set_messages_flag(msg_number,"seen");
+			var data = expresso_local_messages.get_local_mail(msg_number);	
+
+			eval("call_back(data)");
+		}else {
+			expresso.connector.cacheNextRequest();
+			cExecute("$this.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), call_back);
+		}
+	}
+	
+	messages_proxy.prototype.delete_msgs = function(folder, msgs_number, border_ID) {
+
+		if (folder == 'null')
+			folder = get_current_folder();
+		if (msgs_number == 'selected')
+			msgs_number = get_selected_messages();
+			
+		if (!this.is_local_folder(folder)) 
+			delete_msgs(folder, msgs_number, border_ID);
+		else {
+			expresso_local_messages.delete_msgs(msgs_number, border_ID);
+			draw_tree_local_folders();
+		}
+	}
+	
+	messages_proxy.prototype.link_anexo = function (info_msg,numero_ordem_anexo) {
+
+		if(info_msg.local_message==true) {
+			return "javascript:download_local_attachment('"+
+					expresso_local_messages.get_url_anexo(info_msg.msg_number,info_msg.attachments[numero_ordem_anexo].pid)+
+					"')";
+		}
+		else {
+			return "javascript:download_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"',"+numero_ordem_anexo+",'"+info_msg.attachments[numero_ordem_anexo].pid+"','"+info_msg.attachments[numero_ordem_anexo].encoding+"','"+info_msg.attachments[numero_ordem_anexo].name+"')";
+		}
+	}
+
+	messages_proxy.prototype.proxy_source_msg = function (id_msg,folder) {
+		if(!this.is_local_folder(folder)) {
+			source_msg(id_msg,folder);
+		}
+		else {
+			var num_msg = id_msg.substr(0,(id_msg.length - 2));
+			expresso_local_messages.get_source_msg(num_msg);
+		}
+	}
+	
+	messages_proxy.prototype.proxy_set_messages_flag = function (flag,msg_number){
+		if(this.is_local_folder(get_current_folder())) {
+			expresso_local_messages.set_messages_flag(msg_number,flag);
+		}
+		else {
+			set_messages_flag(flag,msg_number);
+		}
+	}
+	
+	messages_proxy.prototype.proxy_set_message_flag = function (msg_number,flag){
+		var msg_number_folder = Element("new_input_folder_"+msg_number+"_r");
+		var folder = msg_number_folder ?  msg_number_folder.value : get_current_folder()
+		if(this.is_local_folder(folder)) {
+			expresso_local_messages.set_message_flag(msg_number,flag);
+		}
+		else {
+			set_message_flag(msg_number,flag);
+		}
+	}
+	
+	messages_proxy.prototype.is_local_folder = function(folder) {
+		if(folder.indexOf("local_")==-1)
+			return false;
+		return true;
+	}
+	
+
+	messages_proxy.prototype.proxy_rename_folder = function(){
+
+		if (ttree.FOLDER == 'local_Inbox') {
+			alert(get_lang("It's not possible rename the folder: ") + lang_folder(ttree.FOLDER.substr(6)));
+			return false;
+		}
+		if(ttree.FOLDER == 'local_root') {
+				alert(get_lang("It's not possible rename this folder!"));
+				return false;
+		}
+		if (this.is_local_folder(ttree.FOLDER)) {
+			folder = prompt(get_lang("Enter a name for the box"), "");
+			if(trim(folder) == "" || trim(folder) == null){
+				alert(get_lang("you have to enter the name of the new folder"));
+				return false;
+			}
+			var temp = expresso_local_messages.rename_folder(folder, ttree.FOLDER.substr(6));
+			if (!temp) 
+				alert(get_lang("cannot rename folder. try other folder name"));
+			ttreeBox.update_folder();
+		}
+		else {
+			ttreeBox.validate("rename");
+		}
+		
+	}
+
+	messages_proxy.prototype.proxy_create_folder = function() {
+		if (this.is_local_folder(ttree.FOLDER)) {
+			folder = prompt(get_lang('Enter the name of the new folder:'), "");
+
+			if(trim(folder) == "" || trim(folder) == null){
+				alert(get_lang("you have to enter the name of the new folder"));
+				return false;
+			}
+			if(ttree.FOLDER=="local_root")
+				var temp = expresso_local_messages.create_folder(folder);
+			else
+				var temp = expresso_local_messages.create_folder(ttree.FOLDER.substr(6)+"/"+folder);
+			if (!temp) 
+				alert(get_lang("cannot create folder. try other folder name"));
+			ttreeBox.update_folder();
+		}
+		else			
+			if(ttree.FOLDER == "INBOX")
+				alert(get_lang("It's not possible create inside: ") + lang_folder(ttree.FOLDER));
+			else if (!this.is_local_folder(ttree.FOLDER))
+				ttreeBox.validate("newpast");
+			else 
+				alert(get_lang("It's not possible create inside: ") + lang_folder(ttree.FOLDER.substr(6)));
+	}
+	
+	messages_proxy.prototype.proxy_remove_folder = function() {
+		if (this.is_local_folder(ttree.FOLDER)) {
+			if(ttree.FOLDER == 'local_root') {
+				alert(get_lang("Select a folder!"));
+				return false;
+			}
+			if (ttree.FOLDER == 'local_Inbox') {
+				alert(get_lang("It's not possible delete the folder: ")  + lang_folder(ttree.FOLDER.substr(6)));
+				return false;
+			}
+			if(ttree.FOLDER.indexOf("/")!="-1") {
+				final_pos = ttree.FOLDER.lastIndexOf("/");
+				new_caption = ttree.FOLDER.substr(final_pos+1);
+			}
+			else {
+				new_caption = ttree.FOLDER.substr(6);
+			}
+			var string_confirm = get_lang("Do you wish to exclude the folder ") + new_caption + "?";
+
+			if (confirm(string_confirm)) {
+				expresso_local_messages.remove_folder(ttree.FOLDER.substr(6));
+				alert(get_lang("The folder %1 was successfully removed", new_caption));
+				ttreeBox.update_folder();
+			}
+		}
+		else
+			ttreeBox.del();
+	}
+
+	messages_proxy.prototype.proxy_move_messages = function (folder, msgs_number, border_ID, new_folder, new_folder_name) {
+		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 ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
+			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 (new_folder == 'local_root')
+				alert(get_lang("Select a folder!"));
+			if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
+				expresso_local_messages.move_messages(new_folder.substr(6), msgs_number);
+				this.aux_interface_remove_mails(msgs_number, new_folder_name, border_ID);
+				draw_tree_local_folders();
+			}
+			else 
+				write_msg(get_lang('No selected message.'));
+		}
+		else 
+			if ((!this.is_local_folder(folder)) && (!this.is_local_folder(new_folder))) { //Move entre pastas locais...
+				move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
+			}
+			else if ((!this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) {
+				if(msgs_number=='selected')
+					archive_msgs(folder,new_folder);
+				else
+					archive_msgs(folder,new_folder,msgs_number);
+				draw_tree_local_folders();
+			}
+			else {
+                //Por Bruno Costa (bruno.vieira-costa@serpro.gov.br) permite o desarquivamento de menssagens chamando a função unarchive_msgs quando uma msg é movida de uma pasta local para uma pasta remota.
+
+				expresso_local_messages.unarchive_msgs(folder,new_folder,msgs_number);
+                //write_msg(get_lang("you can't move mails from local to server folders"));
+			}
+		
+		
+	}
+	
+	messages_proxy.prototype.proxy_move_search_messages = function(border_id, new_folder, new_folder_name) {
+		
+		
+		/*
+		
+		
+		if ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
+			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 (new_folder == 'local_root')
+				alert(get_lang("Select a folder!"));
+			if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
+				expresso_local_messages.move_messages(new_folder.substr(6), msgs_number);
+				this.aux_interface_remove_mails(msgs_number, new_folder_name, border_ID);
+			}
+			else 
+				write_msg(get_lang('No selected message.'));
+		}
+		else 
+			if ((!this.is_local_folder(folder)) && (!this.is_local_folder(new_folder))) { //Move entre pastas locais...
+				move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
+			}
+			else if ((!this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) {
+				archive_msgs(folder,new_folder);
+			}
+			else {
+				write_msg(get_lang("you can't move mails from local to server folders"));
+			}*/
+	}
+	
+	messages_proxy.prototype.aux_interface_remove_mails = function(msgs_number,new_folder_name,border_ID,previous_msg) {
+		Element('chk_box_select_all_messages').checked = false;
+		mail_msg = Element("tbody_box");
+		msgs_number = msgs_number.split(",");
+		var msg_to_delete;
+		for (var i=0; i<msgs_number.length; i++){
+			msg_to_delete = Element(msgs_number[i]);
+			if (msg_to_delete){
+				if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') )
+					select_msg('null', 'down');
+				mail_msg.removeChild(msg_to_delete);
+			}
+		}
+		if (msgs_number.length == 1)
+			write_msg(get_lang("The message was moved to folder ") + new_folder_name);
+		else
+			write_msg(get_lang("The messages were moved to folder ") + new_folder_name);
+
+		if (border_ID != '' && border_ID != 'null'){
+				delete_border(border_ID,'false');
+		}
+		if(folder == get_current_folder())
+			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - msgs_number.length;			
+		refresh();		
+		
+	}
+
+   	messages_proxy.prototype.msg_img = function(msgs_number,folder_name,call_back) {
+     if(this.is_local_folder(folder_name)){
+         var msg = expresso_local_messages.get_local_mail(msgs_number);
+		 eval('call_back(msg)');
+     }
+     else
+     {
+	expresso.connector.cacheNextRequest();
+        cExecute('$this.imap_functions.get_info_msg&msg_number='+msgs_number+'&msg_folder='+url_encode(folder_name),call_back);
+     }
+    }
+
+    messages_proxy.prototype.export_all_messages = function(folder){
+
+		if (!folder){
+			folder = get_current_folder();
+		}
+
+		if(!this.is_local_folder(folder)){
+			export_all_selected_msgs();
+		}else{
+			local_messages.prototype.local_messages_to_export();
+		}
+	}
+
+    	messages_proxy.prototype.proxy_export_all_msg=function(){
+
+		var er=/^local/;
+
+
+		if(ttree.FOLDER == "local_root"){return false;}   //Usuario não selecionou uma pasta local e esta no comeÃ§o dos nÃ³s
+		var nm_bx = ttree.FOLDER.split(cyrus_delimiter);
+
+		var name_f = nm_bx[nm_bx.length -1].replace("local_","");
+
+		if (!er.test(nm_bx)){
+			//Se a pasta nao for local, ou seja a string nao contem a string "local"
+			ttreeBox.export_all_msg();
+		} else{
+			expresso_local_messages.get_all_local_folder_messages(name_f);
+		}
+	}
+
+	var proxy_mensagens;
+	proxy_mensagens = new messages_proxy();
Index: trunk/expressoMail1_2/js/jscode/shortcut.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/shortcut.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/shortcut.js	(revision 2517)
@@ -0,0 +1,558 @@
+/**
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
+ * Version : 2.01.A
+ * By Binny V A
+ * License : BSD
+ */
+shortcut = {
+	'all_shortcuts':{},//All the shortcuts are stored in this array
+	'add': function(shortcut_combination,callback,opt) {
+		//Provide a set of default options
+		var default_options = {
+			'type':'keydown',
+			'propagate':false,
+			'disable_in_input':false,
+			'target':document,
+			'keycode':false
+		}
+		if(!opt) opt = default_options;
+		else {
+			for(var dfo in default_options) {
+				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
+			}
+		}
+		
+		var ele = opt.target
+		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
+		var ths = this;
+		shortcut_combination = shortcut_combination.toLowerCase();
+
+		//The function to be called at keypress
+		var func = function(e) {
+			e = e || window.event;
+			
+			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
+				var element;
+				if(e.target) element=e.target;
+				else if(e.srcElement) element=e.srcElement;
+				if(element.nodeType==3) element=element.parentNode;
+
+				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
+			}
+	
+			//Find Which key is pressed
+			if (e.keyCode) code = e.keyCode;
+			else if (e.which) code = e.which;
+			var character = String.fromCharCode(code).toLowerCase();
+			
+			if(code == 188) character=","; //If the user presses , when the type is onkeydown
+			if(code == 190) character="."; //If the user presses , when the type is onkeydown
+	
+			var keys = shortcut_combination.split("+");
+			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
+			var kp = 0;
+			
+			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
+			var shift_nums = {
+				"`":"~",
+				"1":"!",
+				"2":"@",
+				"3":"#",
+				"4":"$",
+				"5":"%",
+				"6":"^",
+				"7":"&",
+				"8":"*",
+				"9":"(",
+				"0":")",
+				"-":"_",
+				"=":"+",
+				";":":",
+				"'":"\"",
+				",":"<",
+				".":">",
+				"/":"?",
+				"\\":"|"
+			}
+			//Special Keys - and their codes
+			var special_keys = {
+				'esc':27,
+				'escape':27,
+				'tab':9,
+				'space':32,
+				'return':13,
+				'enter':13,
+				'backspace':8,
+	
+				'scrolllock':145,
+				'scroll_lock':145,
+				'scroll':145,
+				'capslock':20,
+				'caps_lock':20,
+				'caps':20,
+				'numlock':144,
+				'num_lock':144,
+				'num':144,
+				
+				'pause':19,
+				'break':19,
+				
+				'insert':45,
+				'home':36,
+				'delete':46,
+				'end':35,
+				
+				'pageup':33,
+				'page_up':33,
+				'pu':33,
+	
+				'pagedown':34,
+				'page_down':34,
+				'pd':34,
+	
+				'left':37,
+				'up':38,
+				'right':39,
+				'down':40,
+	
+				'f1':112,
+				'f2':113,
+				'f3':114,
+				'f4':115,
+				'f5':116,
+				'f6':117,
+				'f7':118,
+				'f8':119,
+				'f9':120,
+				'f10':121,
+				'f11':122,
+				'f12':123
+			}
+	
+			var modifiers = { 
+				shift: { wanted:false, pressed:false},
+				ctrl : { wanted:false, pressed:false},
+				alt  : { wanted:false, pressed:false},
+				meta : { wanted:false, pressed:false}	//Meta is Mac specific
+			};
+                        
+			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
+			if(e.shiftKey)	modifiers.shift.pressed = true;
+			if(e.altKey)	modifiers.alt.pressed = true;
+			if(e.metaKey)   modifiers.meta.pressed = true;
+                        
+			for(var i=0; k=keys[i],i<keys.length; i++) {
+				//Modifiers
+				if(k == 'ctrl' || k == 'control') {
+					kp++;
+					modifiers.ctrl.wanted = true;
+
+				} else if(k == 'shift') {
+					kp++;
+					modifiers.shift.wanted = true;
+
+				} else if(k == 'alt') {
+					kp++;
+					modifiers.alt.wanted = true;
+				} else if(k == 'meta') {
+					kp++;
+					modifiers.meta.wanted = true;
+				} else if(k.length > 1) { //If it is a special key
+					if(special_keys[k] == code) kp++;
+					
+				} else if(opt['keycode']) {
+					if(opt['keycode'] == code) kp++;
+
+				} else { //The special keys did not match
+					if(character == k) kp++;
+					else {
+						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
+							character = shift_nums[character]; 
+							if(character == k) kp++;
+						}
+					}
+				}
+			}
+
+			if(kp == keys.length && 
+						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
+						modifiers.shift.pressed == modifiers.shift.wanted &&
+						modifiers.alt.pressed == modifiers.alt.wanted &&
+						modifiers.meta.pressed == modifiers.meta.wanted) {
+				callback(e);
+	
+				if(!opt['propagate']) { //Stop the event
+					//e.cancelBubble is supported by IE - this will kill the bubbling process.
+					e.cancelBubble = true;
+					e.returnValue = false;
+	
+					//e.stopPropagation works in Firefox.
+					if (e.stopPropagation) {
+						e.stopPropagation();
+						e.preventDefault();
+					}
+					return false;
+				}
+			}
+		}
+		this.all_shortcuts[shortcut_combination] = {
+			'callback':func, 
+			'target':ele, 
+			'event': opt['type']
+		};
+		//Attach the function with the event
+		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
+		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
+		else ele['on'+opt['type']] = func;
+	},
+
+	//Remove the shortcut - just specify the shortcut and I will remove the binding
+	'remove':function(shortcut_combination) {
+		shortcut_combination = shortcut_combination.toLowerCase();
+		var binding = this.all_shortcuts[shortcut_combination];
+		delete(this.all_shortcuts[shortcut_combination])
+		if(!binding) return;
+		var type = binding['event'];
+		var ele = binding['target'];
+		var callback = binding['callback'];
+
+		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
+		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
+		else ele['on'+type] = false;
+	}
+}
+
+/* ExpressMail Functions */
+var shift_up_count = 0;
+var shift_down_count = 0;
+var selMessageShortcut = "";
+
+shortcut.add("N",function(){ new_message("new","null"); },{'disable_in_input':true});
+
+shortcut.add("Esc",function(){
+	var window_closed = false;
+	for(var window in arrayJSWin)
+	{
+		if (arrayJSWin[window].visible)
+		{
+			arrayJSWin[window].close();
+			window_closed = true;
+		}
+	}
+	if (!window_closed)
+		delete_border(get_msg_id(), 'false');
+},{'disable_in_input':false});
+
+shortcut.add("I",function(){ print_all(); },{'disable_in_input':true}); 
+shortcut.add("E",function(){ exec_msg_action('forward'); },{'disable_in_input':true});
+shortcut.add("R",function(){ exec_msg_action('reply'); },{'disable_in_input':true});
+shortcut.add("O",function(){ show_head_option(); },{'disable_in_input':true});
+shortcut.add("M",function(){ show_address_full(); },{'disable_in_input':true});
+
+shortcut.add("Delete",function(){
+	
+	var selected_shortcut_msgs = '';
+	var tbody_box = Element('tbody_box');
+	all_messages = Element('tbody_box').childNodes;
+	
+	for ( var i=0; i < all_messages.length; i++ )
+	{
+		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+		{
+			selected_shortcut_msgs += all_messages[i].id + ',';
+			
+			if( all_messages[i].nextSibling )
+				selMessageShortcut = all_messages[i].nextSibling.id + "-" + "down";
+			else if(all_messages[i].previousSibling)
+				selMessageShortcut = all_messages[i].previousSibling.id + "-" + "up";
+		}
+	}
+	selected_shortcut_msgs = selected_shortcut_msgs.substring(0,(selected_shortcut_msgs.length-1));
+	
+	if ( Element('border_id_0').className==='menu-sel' )
+	{
+		proxy_mensagens.delete_msgs(current_folder, selected_shortcut_msgs, 'null');
+	}
+	else
+	{
+		exec_msg_action('delete');
+		select_msg(selMessageShortcut.substring(0, selMessageShortcut.indexOf("-")),
+				   selMessageShortcut.substring(selMessageShortcut.indexOf("-")), true );
+	}
+}
+,{'disable_in_input':true});
+
+shortcut.add("Ctrl+Up",function(){ exec_msg_action('previous'); select_msg('null', 'up', true);},{'disable_in_input':true});
+shortcut.add("Ctrl+Down",function(){ exec_msg_action('next'); select_msg('null', 'down', true);},{'disable_in_input':true});
+
+if (is_ie)
+{
+	shortcut.add("down",function(){ select_msg('null', 'down'); },{'disable_in_input':false});
+	shortcut.add("up",function(){ select_msg('null', 'up'); },{'disable_in_input':false});	
+	
+	shortcut.add("Shift+down",function(){
+		if ( Element('border_id_0').className==='menu-sel' )
+		{
+			if (shift_up_count > 0)
+				unselect_top_msg();
+			else
+				select_bottom_msg();
+		}
+	},{'disable_in_input':true, 'propagate':false});
+	
+	shortcut.add("Shift+up",function(){
+		if ( Element('border_id_0').className==='menu-sel' )
+		{
+			if (shift_down_count > 0)
+				unselect_bottom_msg();
+			else
+				select_top_msg();
+		}
+	},{'disable_in_input':true, 'propagate':false});
+}
+else
+{
+	shortcut.add("down",function(){ select_msg('null', 'down');},{'type':'keypress', 'disable_in_input':false});
+	shortcut.add("up",function(){ select_msg('null', 'up');},{'type':'keypress', 'disable_in_input':false});
+	
+	shortcut.add("Shift+down",function(){
+		if ( Element('border_id_0').className==='menu-sel' )
+		{
+			if (shift_up_count > 0)
+				unselect_top_msg();
+			else
+				select_bottom_msg();
+		}
+	},{'type':'keypress','disable_in_input':true, 'propagate':false});
+	
+	shortcut.add("Shift+up",function(){
+		if ( Element('border_id_0').className==='menu-sel' )
+		{
+			if (shift_down_count > 0)
+				unselect_bottom_msg();
+			else
+				select_top_msg();
+		}
+	},{'type':'keypress', 'disable_in_input':true, 'propagate':false});
+}
+
+shortcut.add("return",function(){
+	if ( Element('border_id_0').className==='menu-sel' )
+	{
+		all_messages = Element('tbody_box').childNodes;
+		for (var i=0; i < all_messages.length; i++)
+		{
+			if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+			{
+				Element("td_who_" + all_messages[i].id).onclick();
+				return;
+			}
+		}
+	}
+}
+,{'disable_in_input':true});
+
+shortcut.add("f9",function(){
+	Element("em_refresh_button").onclick();
+	return;
+},{'disable_in_input':true});
+
+function exec_msg_action(action)
+{
+	var msg_id = get_msg_id();
+	if (msg_id)
+	{
+		var msg_id = 'msg_opt_' + action + '_' + msg_id;
+		try {Element(msg_id).onclick();}
+		catch(e){/*alert(e);*/}
+	}
+	return;
+}
+
+function show_head_option()
+{
+        var msg_id = get_msg_id();
+		
+        if (msg_id)
+        {
+                var msg_id = 'option_hide_more_' + msg_id;
+	        try {Element(msg_id).onclick();}
+                catch(e){/*alert(e);*/}
+        }
+        return;
+}
+
+function show_address_full()
+{
+	var toaddress = Element('div_toaddress_' + get_msg_id());
+	if ( '' == toaddress.style.display )
+	{
+		show_div_address_full(get_msg_id(),'to')
+		show_div_address_full(get_msg_id(),'cc')
+	}
+	else
+	{
+	        Element('div_toaddress_full_' + get_msg_id()).style.display='none';
+        	Element('div_toaddress_' + get_msg_id()).style.display='';
+	        Element('div_ccaddress_full_'+ get_msg_id()).style.display='none';
+        	Element('div_ccaddress_'+ get_msg_id()).style.display='';
+	}
+
+	return;
+}
+
+function get_msg_id()
+{
+	children = Element('border_tr').childNodes;
+	
+	for (var i=0; i<children.length; i++)
+	{
+		if ( (children[i].nodeName==='TD') && (children[i].className==='menu-sel') && children[i].id != 'border_id_0')
+		{
+			var border_selected = children[i];
+			var msg_id = border_selected.id.replace("border_id_","");
+			return msg_id;
+		}
+	}
+	return false;
+}
+
+function select_msg(msg_number, keyboard_action, force_msg_selection)
+{
+	//Select msg, even if the focus isn't the border_id_0
+	if ( (Element('border_id_0').className != 'menu-sel') && (!force_msg_selection) )
+		return;
+
+	shift_up_count = 0;
+	shift_down_count = 0;
+
+	if (msg_number != 'null')
+	{
+		unselect_all_msgs();
+		add_className(Element(msg_number), 'selected_shortcut_msg')
+	}
+	else
+	{
+		var scrollMain = Element('divScrollMain_0');
+		var selection_size = parseInt(preferences.line_height) + 10; 
+
+		if( keyboard_action == 'down')
+		{
+			for (var i=all_messages.length-1; i >=0; i--)
+			{
+				if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+				{
+					add_className(all_messages[i+1], 'selected_shortcut_msg')
+					var mailPos = i;
+					break;
+				}
+			}
+			
+			for (; i>=0; i--)
+			{
+				if( all_messages[i].nextSibling )
+					remove_className(all_messages[i], 'selected_shortcut_msg');
+			}
+			if ((mailPos) && (parseInt(scrollMain.style.height.substr(0,scrollMain.style.height.length-2)) + scrollMain.scrollTop) < (all_messages[mailPos].offsetTop + selection_size))
+				scrollMain.scrollTop += selection_size;
+
+		}
+		else if( keyboard_action == 'up')
+		{
+			for (var i=0; i < all_messages.length; i++)
+			{
+				if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+				{
+					if( all_messages[i].previousSibling )
+					{
+						add_className(all_messages[i-1], 'selected_shortcut_msg')
+						var mailPos = i;
+						break;
+					}
+				}
+			}
+			
+			for (; i< all_messages.length; i++)
+			{
+				remove_className(all_messages[i], 'selected_shortcut_msg')
+			}
+		if (typeof(all_messages[mailPos]) != 'undefined' && all_messages[mailPos].offsetTop <= scrollMain.scrollTop)
+			scrollMain.scrollTop -= selection_size+10;
+		}
+
+		return true;
+	}
+}
+
+function select_bottom_msg()
+{
+	all_messages = Element('tbody_box').childNodes;
+	
+	if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') )
+		return;
+	
+	for (var i=all_messages.length-1; i >=0; i--)
+	{
+		if ( (exist_className(all_messages[i], 'selected_shortcut_msg')) && (i+1 <= all_messages.length-1) )
+		{
+			shift_down_count++;
+			add_className(all_messages[i+1], 'selected_shortcut_msg');
+			break;
+		}
+	}
+}
+
+function select_top_msg()
+{
+	all_messages = Element('tbody_box').childNodes;
+		
+	if ( exist_className(all_messages[0], 'selected_shortcut_msg') )
+		return;
+	
+	for (var i=0; i <=all_messages.length-1; i++)
+	{
+		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+		{
+			shift_up_count++;
+			add_className(all_messages[i-1], 'selected_shortcut_msg');
+			break;
+		}
+	}
+}
+
+function unselect_bottom_msg()
+{
+	all_messages = Element('tbody_box').childNodes;
+	for (var i=all_messages.length-1; i >=0; i--)
+	{
+		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+		{
+			shift_down_count--;
+			remove_className(all_messages[i], 'selected_shortcut_msg');
+			break;
+		}
+	}
+}
+
+function unselect_top_msg()
+{
+	all_messages = Element('tbody_box').childNodes;
+	for (var i=0; i <=all_messages.length-1; i++)
+	{
+		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
+		{
+			shift_up_count--;
+			remove_className(all_messages[i], 'selected_shortcut_msg');
+			break;
+		}
+	}
+}
+
+function unselect_all_msgs()
+{
+	all_messages = Element('tbody_box').childNodes;
+	for (var i=0; i <=all_messages.length-1; i++)
+	{
+		remove_className(all_messages[i], 'selected_shortcut_msg');
+	}
+}
Index: trunk/expressoMail1_2/js/jscode/mail_sync.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/mail_sync.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/mail_sync.js	(revision 2517)
@@ -0,0 +1,498 @@
+/**
+ * @author diogenes
+ */
+
+	/**
+	 *  @param folders:
+	 * 		1 - rowid of folder in sqlite
+	 * 		2 - folder name in sqlite
+	 * 		3 - ids to not download(for auto archiving) or ids to download(for archiving)
+	 * 		4 - true for auto archiving and false for normal archiving.
+	 */
+	function mail_sync() {
+//		this.dbGears = null;
+//		this.localServer = null;
+//		this.store = null;
+		this.folders = new Array();
+		this.messages = null;
+		this.attachs = null;
+		this.url_attachs = null;
+		this.working = false;
+		this.is_auto = null;
+		this.errors = new Array();
+//		this.main_title = null;
+		
+		this.main_title = null;
+		this.dbGears = google.gears.factory.create('beta.database');
+		this.localServer = google.gears.factory.create('beta.localserver');
+		this.store = this.localServer.createStore('test-store');
+	}
+	
+	mail_sync.prototype.open_conn = function(){
+		var db_in_other_use = true;
+		var start_trying = new Date().getTime();
+		while (db_in_other_use) {
+			try {
+				this.dbGears.open('database-test');
+				db_in_other_use = false;
+			} 
+			catch (ex) {
+				if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception
+					throw ex;
+				}
+			}
+		}
+	}
+	
+	mail_sync.prototype.start_sync = function() {
+		if(this.working) {
+			//Já está sincronizando...
+			return;
+		}
+		
+		this.open_conn();
+
+		var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario=?",[account_id]);
+		if(!rs.isValidRow()) {
+			this.dbGears.close();
+			return;
+		}
+			
+
+		this.working=true;
+		this.messages = null;
+		this.attachs = null;
+		this.url_attachs = null;
+
+		document.getElementById('main_title').innerHTML = get_lang("Creating folders structure");
+		while(rs.isValidRow()) {
+			var temp = new Array();
+			temp[0] = rs.field(0);
+			temp[1] = rs.field(1);
+			temp[2] = null;
+			temp[3] = false;
+			var rs2 = this.dbGears.execute("select mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where folder.folder = ? and mail.uid_usuario=?",[temp[1]==get_lang('Inbox')?'Inbox':temp[1],account_id]);
+			while(rs2.isValidRow()) {
+				if(temp[2]==null)
+					temp[2]=rs2.field(0)+",";
+				else
+					temp[2]+=rs2.field(0)+",";
+				rs2.next();
+			}
+			this.folders.push(temp);
+			
+			
+			//Criando estrutura de pastas...
+			var folders_to_check = temp[0].split("/");//Todas as pastas tem ao menos INBOX/
+			if (folders_to_check.length == 1) 
+				var actual_check = "Inbox";
+			else {
+				folders_to_check = folders_to_check.slice(1);
+				var actual_check = folders_to_check[0];
+			}
+			for (var i in folders_to_check) {
+				var rs2 = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [actual_check, account_id]);
+				
+				if (!rs2.isValidRow()) {
+					this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)", [actual_check, account_id]);
+				}
+				if(parseInt(i)+1<folders_to_check.length)
+					actual_check += "/"+folders_to_check[parseInt(i)+1];
+			}
+			ttreeBox.update_folder();
+			rs.next();
+		}
+		this.dbGears.close();
+		this.syncronize_folders();
+	}
+	
+	mail_sync.prototype.archive_msgs = function(folder,folder_dest,ids) {
+		//this.main_title = document.getElementById('main_title').innerHTML;
+		var temp = new Array();
+		temp[0] = folder;
+		temp[1] = folder_dest.substr(6);
+		temp[2] = ids;
+		temp[3] = true;
+		this.folders.push(temp);
+		Element('chk_box_select_all_messages').checked = false;
+		
+		array_ids = ids.split(",");
+		for (var i in array_ids) {
+			if (Element("check_box_message_" + array_ids[i])) 
+				Element("check_box_message_" + array_ids[i]).checked = false;
+			remove_className(Element(array_ids[i]), 'selected_msg');
+		}
+		if(!this.working) {
+			this.working=true;
+			this.syncronize_folders();
+		}
+		else {
+			write_msg(get_lang("An archiving is in process, but dont worry, expresso will process this messages after the actual archiving"));
+		}
+	}
+	
+	mail_sync.prototype.syncronize_folders = function() {
+		if (this.folders.length == 0) {
+			document.getElementById('main_title').innerHTML = get_lang("Deleting downloadeds msgs...");
+			expresso_mail_sync.remove_archived_mails();
+			this.working=false;
+			update_menu();
+			return;
+		}
+		var folder_to_sync = this.folders.pop();
+		folder_to_sync[1] = folder_to_sync[0].toUpperCase()=="INBOX" && !folder_to_sync[3]?"Inbox":folder_to_sync[1];
+		
+		if(folder_to_sync[3]) { //Em caso de arquivamento normal, pode ser que a pasta inbox ainda não tenha sido criada.
+			expresso_mail_sync.open_conn()
+			if(folder_to_sync[1]=="Inbox" && !expresso_mail_sync.has_inbox_folder()) {
+				expresso_mail_sync.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]);
+			}
+			expresso_mail_sync.dbGears.close();
+			ttreeBox.update_folder();
+			
+		}
+		
+		var start_sync_mails = function(data) {
+			expresso_mail_sync.messages=data;
+			if(expresso_mail_sync.is_auto)
+				document.getElementById('main_title').innerHTML = get_lang("Auto archiving")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length;
+			else
+				document.getElementById('main_title').innerHTML = get_lang("Archiving messages on folder")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length;
+
+			expresso_mail_sync.syncronize_mails(folder_to_sync[1]);
+		}
+		
+
+		if (folder_to_sync[3]) {
+			document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages");
+			cExecute("$this.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails);
+			this.is_auto = false;
+		}
+		else {
+			document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder")+" "+lang_folder(folder_to_sync[1]);
+			var params = "folder="+folder_to_sync[0]+"&mails="+folder_to_sync[2];
+			cExecute("$this.imap_functions.msgs_to_archive", start_sync_mails,params);
+			this.is_auto = true;
+		}
+			
+	}
+	
+	mail_sync.prototype.syncronize_mails = function(folder_dest) {
+		if (expresso_mail_sync.messages == null || expresso_mail_sync.messages.length == 0) {
+			expresso_mail_sync.syncronize_folders();
+			return;
+		}
+		
+		msg_to_sync = expresso_mail_sync.messages.pop();
+		
+		//refresh loading
+		var value_to_change = document.getElementById('main_title').innerHTML.match(/\d+ \//);
+		value_to_change += "";
+		var new_value = value_to_change.replace(" /","");
+		new_value = parseInt(new_value) + 1;
+		document.getElementById('main_title').innerHTML = document.getElementById('main_title').innerHTML.replace(value_to_change,new_value+" /");
+		msg_to_sync = expresso.connector.unserialize(msg_to_sync);
+		
+		var source_msg = new Array();
+		source_msg['url'] = msg_to_sync.url_export_file;
+
+		if (typeof(msg_to_sync['array_attach'])=='object'&&(msg_to_sync['array_attach'] instanceof Array))
+			expresso_mail_sync.attachs = msg_to_sync['array_attach'].slice();
+		else
+			expresso_mail_sync.attachs = new Array();
+		expresso_mail_sync.attachs.push(source_msg);
+		expresso_mail_sync.download_attachs(msg_to_sync,folder_dest);
+	}
+	
+	mail_sync.prototype.download_attachs = function(msg,folder_dest) {
+		if (expresso_mail_sync.attachs == null || expresso_mail_sync.attachs.length == 0) {
+			expresso_mail_sync.insert_mail(msg, folder_dest);
+			
+			return;
+		}
+		
+		attach_to_capt = expresso_mail_sync.attachs.pop();
+		
+		var call_back = function(url,success,captureId) {
+			if (!success) {
+				/*
+				 * 0 - original id
+				 * 1 - message subject
+				 * 2 - original folder
+				 */
+				var mail_error = new Array();
+				mail_error[0] = msg.msg_number;
+				mail_error[1] = msg.subject;
+				mail_error[2] = msg.msg_folder;
+				expresso_mail_sync.errors.push(mail_error);
+				alert('erro ao baixar: '+url);
+				
+				/*if (typeof(msg['array_attach']) == 'object' && (msg['array_attach'] instanceof Array)) {
+					for (var i in msg['array_attach']) { //remove os anexos que já foram baixados para essa mensagem...
+						expresso_mail_sync.store.remove(msg['array_attach'][i]['url']);
+					}
+				}*/
+				expresso_mail_sync.syncronize_mails(folder_dest); //Pula para o próximo e-mail.
+			}
+			else {
+				expresso_mail_sync.download_attachs(msg, folder_dest);//continua baixando o próximo anexo
+			}
+		}
+		expresso_mail_sync.store.capture(attach_to_capt['url'],call_back);
+	}
+	
+	mail_sync.prototype.insert_mail = function(msg,folder) {
+		try {
+			connector = expresso.connector;
+			expresso_mail_sync.open_conn();
+		
+			var msg_info = msg;
+			var msg_header = msg['header'];
+			var anexos = msg['array_attach'];
+			
+			
+			var unseen = 0;
+			var login = msg_info.login;
+			var original_id = msg_info.msg_number;
+			var original_folder = msg_info.msg_folder=='INBOX/Lixeira/tmpMoveToLocal'?msg_info.msg_folder+(Date.parse(new Date)):msg_info.msg_folder;
+
+			//Os campos abaixo precisam estar isolados para busca de mensagens em cima deles.
+			var from = connector.serialize(msg_info.from);
+			var subject = msg_info.subject;
+			var body = msg_info.body;
+			var to = connector.serialize(msg_info.toaddress2);
+			var cc = connector.serialize(msg_info.cc);
+			var size = msg_header.Size;
+	
+			//Zero os campos que foram isolados para não ter informações duplicadas
+			msg_info.from = null;
+			msg_info.subject = null;
+			msg_info.body = null;
+			msg_info.to = null;
+			msg_info.cc = null;
+			msg_header.Size=null;
+			
+			//A data no header pode vir como horário ao invés de data, caso o usuário tenha arquivado no mesmo
+			//dia que recebeu a msg. Para esses casos, usar a data aux que vem com o dia.
+			if(msg_header.udate.indexOf("/")==-1) {
+				msg_header.udate = msg_header.aux_date;
+			}
+		
+			
+			/**
+			 * The importance attribute can be empty, and javascript consider as null causing nullpointer.
+			 */
+			if((msg_header.Importance == null) ||  (msg_header.Importance == ""))
+				msg_header.Importance = "Normal";
+			
+			msg_header.aux_date = null; //esse dado não é mais preciso no email.
+			
+			var mail = connector.serialize(msg_info);
+			var header = connector.serialize(msg_header);
+	
+			var timestamp = msg_info.timestamp;
+			var id_folder;
+			
+			var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [folder, account_id]);
+			id_folder = rs.field(0);
+	
+			if((msg_info.Unseen=="U")|| (msg_info.Recent=="N"))
+				unseen = 1;
+			this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size]);
+			
+			
+			
+			//Preenche os anexos.
+			var id_mail = this.dbGears.lastInsertRowId;
+
+			for (var i = 0; i < anexos.length; i++) {
+				this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_mail, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]);
+			}
+			
+			var check_remove;
+			if(this.is_auto)
+				check_remove = preferences.keep_after_auto_archiving;
+			else
+				check_remove = preferences.keep_archived_messages;
+			
+			
+			
+			if(check_remove!=1)
+				this.dbGears.execute("insert into msgs_to_remove (id_msg,folder,uid_usuario) values (?,?,?)",[original_id,original_folder,account_id]);
+						
+		} catch (error) {
+			/*
+			 * 0 - original id
+			 * 1 - message subject
+			 * 2 - original folder
+			 */
+			var mail_error = new Array();
+			mail_error[0] = original_id;
+			mail_error[1] = subject;
+			mail_error[2] = original_folder;
+			this.errors.push(mail_error);
+			
+			if (typeof(msg_info['array_attach'])=='object'&&(msg_info['array_attach'] instanceof Array)) { 
+				for(var i in msg_info['array_attach']) { //remove os anexos que já foram baixados para essa mensagem...
+					this.store.remove(msg_info['array_attach'][i]['url']);
+				}
+			}
+
+		}
+		this.dbGears.close();
+		this.syncronize_mails(folder);
+	}
+	
+	mail_sync.prototype.has_inbox_folder = function() {//This function considers that the connection with base is already opened.
+		var rs = this.dbGears.execute("select rowid from folder where folder='Inbox'");
+		if(rs.isValidRow())
+			return true;
+		else 
+			return false;
+	}
+	
+	mail_sync.prototype.remove_archived_mails = function() {
+		
+		expresso_mail_sync.open_conn();
+
+		var rs = this.dbGears.execute("select distinct(folder) from msgs_to_remove where uid_usuario=?",[account_id]);
+		if(rs.isValidRow()) {
+			var folder_to_remove_msgs = rs.field(0);
+			var rs2 = this.dbGears.execute("select id_msg from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]);
+			
+			var msgs = null;
+			while(rs2.isValidRow()) {
+				if(msgs==null)
+					msgs = rs2.field(0);
+				else
+					msgs += ","+rs2.field(0);
+				rs2.next();
+			}
+			
+			
+			var handler_delete_msgs = function(data){
+				if (current_folder == data.folder) {
+					mail_msg = Element("tbody_box");
+					var msg_to_delete;
+					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);
+						}
+					}
+					Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
+				}
+				ttreeBox.update_folder();
+				refresh();
+				expresso_mail_sync.remove_archived_mails();
+			}
+			
+			cExecute ("$this.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs, handler_delete_msgs);
+			this.dbGears.execute("delete from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]);
+			this.dbGears.close();
+			
+		}
+		else {
+			this.dbGears.close();
+			document.getElementById('main_title').innerHTML = get_lang("End of archive messages");
+			if(this.errors.length>0) {
+				//TODO: Tratar melhor quando existirem erros...
+				write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later"));
+				this.errors=new Array();
+			}
+			window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000);
+		}
+		
+	}
+	
+	mail_sync.prototype.configure_sync = function(folders,formul) {
+		this.dbGears = google.gears.factory.create('beta.database');
+		this.localServer = google.gears.factory.create('beta.localserver');
+		this.store = this.localServer.createStore('test-store');	
+		this.dbGears.open('database-test');
+		this.dbGears.execute("delete from folders_sync where uid_usuario=?",[account_id]);
+		for (var i=0;i<folders.length;i++) {
+			var pos = folders[i].value.indexOf("/");
+			if(pos=="-1")
+				var folder_name = folders[i].text;
+			else
+				var folder_name = folders[i].value.substr(pos+1);
+			this.dbGears.execute("insert into folders_sync (id_folder,folder_name,uid_usuario) values (?,?,?)",[folders[i].value,folder_name,account_id]);
+		}
+		this.dbGears.close();
+		formul.submit();
+	}
+	
+	mail_sync.prototype.fill_combos_of_folders = function(combo_sync) {
+		var folders = expresso_local_messages.get_folders_to_sync();
+
+		for(var i=0;i<folders.length;i++) {
+			var option = document.createElement('option');
+			option.value = folders[i][0];
+			if (folders[i][1].indexOf("/") != "-1") {
+				final_pos = folders[i][1].lastIndexOf("/");
+				option.text =folders[i][1].substr(final_pos+1);
+			}
+			else
+				option.text = folders[i][1];
+			try {
+				combo_sync.add(option,null);
+			}catch (ex) {// I.E
+				combo_sync.add(option);
+			}
+
+		}
+	}
+	
+	mail_sync.prototype.add_folder = function (select_sync_folders,select_available_folders)
+	{
+		var count_available_folders = select_available_folders.length;
+		var count_sync_folders = select_sync_folders.options.length;
+		var new_options = '';
+		
+		for (i = 0 ; i < count_available_folders ; i++)
+		{
+			if (select_available_folders.options[i].selected)
+			{
+				if(document.all)
+				{
+					if ( (select_sync_folders.innerHTML.indexOf('value='+select_available_folders.options[i].value)) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_folders.options[i].value
+									+ '>'
+									+ select_available_folders.options[i].text
+									+ '</option>';
+					}
+				}
+				else
+				{
+					if ( (select_sync_folders.innerHTML.indexOf('value="'+select_available_folders.options[i].value+'"')) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_folders.options[i].value
+									+ '>'
+									+ select_available_folders.options[i].text
+									+ '</option>';
+					}
+				}
+			}
+		}
+	
+		if (new_options != '')
+		{
+			select_sync_folders.innerHTML = '&nbsp;' + new_options + select_sync_folders.innerHTML;
+			select_sync_folders.outerHTML = select_sync_folders.outerHTML;
+		}
+	}
+	
+	mail_sync.prototype.remove_folder = function(select_sync_folders)
+	{
+		for(var i = 0;i < select_sync_folders.options.length; i++)
+			if(select_sync_folders.options[i].selected)
+				select_sync_folders.options[i--] = null;
+	}
+	
+	var expresso_mail_sync;
+	expresso_mail_sync = new mail_sync();
+	
Index: trunk/expressoMail1_2/js/jscode/local_messages.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/local_messages.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/local_messages.js	(revision 2517)
@@ -0,0 +1,1598 @@
+/**
+ * @author diogenes
+ */
+
+	function local_messages() {
+		this.dbGears = null;
+		this.localServer = null;
+		this.store = null;
+	}
+
+        function HeaderFlags()
+        {
+            this.Answered = 0;
+            //this.Draft = 0;
+            this.Flagged = 0;
+            this.Recent = 0;
+        }
+
+        HeaderFlags.prototype.getAnswered = function()
+        {
+            return this.Answered;
+        }
+
+        HeaderFlags.prototype.setAnswered = function(answered)
+        {
+            this.Answered = answered;
+        }
+
+        //HeaderFlags.prototype.getDraft = function()
+        //{
+        //    return this.Draft;
+        //}
+
+        HeaderFlags.prototype.setDraft = function(draft)
+        {
+            this.Draft = draft;
+        }
+
+        HeaderFlags.prototype.getFlagged = function()
+        {
+            return this.Flagged;
+        }
+
+        HeaderFlags.prototype.setFlagged = function(flagged)
+        {
+            this.Flagged = flagged;
+        }
+
+        HeaderFlags.prototype.getRecent = function()
+        {
+            return this.Recent;
+        }
+
+        HeaderFlags.prototype.setRecent = function(recent)
+        {
+            this.Recent = recent;
+        }
+
+        function FlagsParser(headerObj)
+        {
+            this.Header = headerObj;
+        }
+
+        FlagsParser.prototype.parse = function()
+        {
+            var tmp = null;
+            if (typeof this.Header == 'string')
+            {
+                tmp = expresso.connector.unserialize(this.Header);
+            }
+            else
+            {
+                tmp = this.Header;
+            }
+
+            flags = new HeaderFlags();
+
+            if (tmp.Answered && tmp.Answered.match(/^A$/))
+            {
+                flags.setAnswered(1);
+                //if (tmp.Draft && tmp.Draft.match(/^X$/))
+                //{
+                //    flags.setDraft(1);
+                //}
+            }
+
+            if (tmp.Flagged && tmp.Flagged.match(/^F$/)){
+                flags.setFlagged(1);
+            }
+
+            if (tmp.Forwarded && tmp.Forwarded.match(/^F$/)){
+                flags.setAnswered(1);
+                //flags.setDraft(1);
+            }
+
+            if (tmp.Recent && tmp.Recent.match(/^R$/)){
+                flags.setRecent(1);
+            }
+
+            return flags;
+
+        }
+        
+	local_messages.prototype.installGears = function (){
+		temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to install it now?"));
+		if (temp && typeof(preferences.googlegears_url) != 'undefined'){
+			if (is_ie)
+				location.href = preferences.googlegears_url + "/gears.exe";
+			else
+				location.href = preferences.googlegears_url + "/gears.xpi";
+			return false;
+		}
+		if (temp) {
+			location.href = "http://gears.google.com/?action=install&message="+
+				get_lang("To use local messages, install Google Gears")+"&return=" + document.location.href;
+		}
+		else return false;
+	}
+
+	local_messages.prototype.create_objects = function() {
+		try {
+			if(this.dbGears == null)
+				this.dbGears = google.gears.factory.create('beta.database');
+			if(this.localServer == null)
+				this.localServer = google.gears.factory.create('beta.localserver');
+			if(this.store == null)
+				this.store = this.localServer.createStore('test-store');
+		}
+		catch(e){}
+	}
+
+	local_messages.prototype.init_local_messages = function(){ //starts only database operations
+		
+		if(this.dbGears==null || this.localServer==null || this.store == null)
+			this.create_objects();
+		
+		var db_in_other_use = true;
+		var start_trying = new Date().getTime();
+		while (db_in_other_use) {
+			try {
+				this.dbGears.open('database-test');
+				db_in_other_use = false;
+			} 
+			catch (ex) {
+				if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception
+					throw ex;
+				}
+			}
+		}
+			
+//		this.dbGears.open('database-test');
+		this.dbGears.execute('create table if not exists folder (folder text,uid_usuario int,unique(folder,uid_usuario))');
+		this.dbGears.execute('create table if not exists mail' +
+		' (mail blob,original_id int,original_folder text,header blob,timestamp int,uid_usuario int,unseen int,id_folder int,' + 
+		' ffrom text, subject text, fto text, cc text, body text, size int,unique (original_id,original_folder,uid_usuario))');
+		this.dbGears.execute('create table if not exists anexo' +
+		' (id_mail int,nome_anexo text,url text,pid int)');
+		this.dbGears.execute('create table if not exists folders_sync' +
+		' (id_folder text,folder_name text,uid_usuario int)');
+		this.dbGears.execute('create table if not exists msgs_to_remove (id_msg int,folder text,uid_usuario int)');
+		this.dbGears.execute('create index if not exists idx_user3 on mail (id_folder,uid_usuario,timestamp)');
+
+		//some people that used old version of local messages could not have the size column. If it's the first version
+		//with local messages you're using in expresso, this part of code can be removed
+		try {
+			this.dbGears.execute('alter table mail add column size int');
+		}catch(Exception) {
+			
+		}
+		var rs = this.dbGears.execute('select rowid,header from mail where size is null');
+		while(rs.isValidRow()) {
+			var temp = expresso.connector.unserialize(rs.field(1));
+			
+			this.dbGears.execute('update mail set size='+temp.Size+' where rowid='+rs.field(0));
+			rs.next();
+		}
+		//end of temporary code
+
+		try {
+                    this.dbGears.execute('begin transaction');
+                    this.dbGears.execute('alter table mail add column answered int');
+                    //this.dbGears.execute('alter table mail add column draft int');
+                    this.dbGears.execute('alter table mail add column flagged int');
+                    this.dbGears.execute('alter table mail add column recent int');
+                    //this.dbGears.execute('commit transaction');
+                    //transaction_ended = true;
+                    //if (transaction_ended){
+                    rs = null;
+                    rs = this.dbGears.execute('select rowid,header from mail');
+
+                    // Popular os valores das novas colunas.
+                    var tmp = null;
+                    //this.dbGears.execute('begin transaction');
+                    while(rs.isValidRow()) {
+                        //tmp = expresso.connector.unserialize(rs.field(1));
+                        parser = new FlagsParser(rs.field(1));
+                        flags = parser.parse();
+
+                        this.dbGears.execute('update mail set answered='+flags.getAnswered()+
+                            ',flagged='+flags.getFlagged()+',recent='+flags.getRecent()+
+                            //',draft='+flags.getDraft()+' where rowid='+rs.field(0));
+                            ' where rowid='+rs.field(0));
+
+			rs.next();
+                    }
+                    this.dbGears.execute('commit transaction');
+
+                    //tmp = null;
+
+                }catch(Exception) {
+                    this.dbGears.execute('rollback transaction');
+		}
+
+	}
+	
+	local_messages.prototype.drop_tables = function() {
+		this.init_local_messages();
+		var rs = this.dbGears.execute('select url from anexo');
+		while(rs.isValidRow()) {
+			this.store.remove(rs.field(0));
+			rs.next();
+		}
+		this.dbGears.execute('drop table folder');
+		this.dbGears.execute('drop table mail');
+		this.dbGears.execute('drop table anexo');
+		this.finalize();
+	}
+	/**
+	 * @Depracated Use of this function in mail_sync.js
+	 * 
+	 */
+	local_messages.prototype.insert_mail = function(msg_info,msg_header,anexos,folder) {
+		try {
+			this.init_local_messages();
+			var unseen = 0;
+			var login = msg_info.login;
+			var original_id = msg_info.msg_number;
+			var original_folder = msg_info.msg_folder;
+			
+			//This fields needs to be separeted to search.
+			var from = expresso.connector.serialize(msg_info.from);
+			var subject = msg_info.subject;
+			var body = msg_info.body;
+			var to = expresso.connector.serialize(msg_info.toaddress2);
+			var cc = expresso.connector.serialize(msg_info.cc);
+			var size = msg_header.Size;
+	
+			//do not duplicate this information
+			msg_info.from = null;
+			msg_info.subject = null;
+			msg_info.body = null;
+			msg_info.to = null;
+			msg_info.cc = null;
+			msg_header.Size=null;
+			//If the mail was archieved in the same date the user received it, the date cames with the time.
+			//here I solved it
+			if(msg_header.udate.indexOf(":")!=-1) {
+				msg_header.udate = msg_header.aux_date;
+			}
+			
+			/**
+			 * The importance attribute can be empty, and javascript consider as null causing nullpointer.
+			 */
+			if((msg_header.Importance == null) ||  (msg_header.Importance == ""))
+				msg_header.Importance = "Normal";
+			
+			msg_header.aux_date = null; 
+			
+			var mail = expresso.connector.serialize(msg_info);
+			var header = expresso.connector.serialize(msg_header);
+	
+			var timestamp = msg_info.timestamp;
+			var id_folder;
+	
+			if((folder==null) || (folder=="local_root"))
+				folder = "Inbox";
+			else
+				folder = folder.substr(6);//take off the word "local_"
+			
+			var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]);
+        		if(rs.isValidRow())
+				id_folder=rs.field(0);
+			else {
+				this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]);
+				id_folder = this.dbGears.lastInsertRowId;
+			}
+			
+			if((msg_info.Unseen=="U")|| (msg_info.Recent=="N"))
+				unseen = 1;
+
+                        //parse header
+                        parser = new FlagsParser(msg_header);
+                        flags = parser.parse();
+
+                        //insere o e-mail
+                        //this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size]);
+                        this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size,answered,flagged,recent) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size,flags.getAnswered(),flags.getFlagged(),flags.getRecent()]);
+			var call_back = function() {
+			}
+			this.store.capture(msg_info.url_export_file,call_back);
+			var id_mail = this.dbGears.lastInsertRowId;
+	
+			this.insert_attachments(id_mail,anexos);
+			this.finalize();
+			return true;
+		} catch (error) {
+			this.finalize();
+			return false;
+		}
+
+
+	}
+	
+	/**
+	 * check if ID is no from main tab, if it's from main returns false, else 
+	 * returns an array with all string in position 0, the mail id in position 1 
+	 * and the part of string relative to tab in position 2
+	 * @param {Object} id_mail
+	 */
+	local_messages.prototype.parse_id_mail = function(id_mail) { 
+		if (this.isInt(id_mail))
+			return false;
+		
+		var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/);
+		return matches;
+	}
+	
+	local_messages.prototype.isInt = function(x) {
+		var y=parseInt(x);
+		if (isNaN(y)) return false;
+		return x==y && x.toString()==y.toString();
+	} 
+	
+	local_messages.prototype.get_local_mail = function(id_mail) {
+		this.init_local_messages();
+
+		var plus_id = '';
+		var matches = '';
+		if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab.
+			id_mail = matches[1];
+			plus_id = matches[2];
+		}
+		
+		var rs = this.dbGears.execute("select mail.rowid,mail.mail,mail.ffrom,mail.subject,mail.body,mail.fto,mail.cc,folder.folder,mail.original_id from mail inner join folder on mail.id_folder=folder.rowid  where mail.rowid="+id_mail);
+		var retorno = null;
+		if(rs.isValidRow()) {
+			 retorno = rs.field(1);
+		}
+		retorno = expresso.connector.unserialize(retorno);
+
+        //alert('tipo retorno.source: ' + typeof(retorno.source));
+
+        if (typeof(retorno.source) == 'string')
+        {
+            retorno.msg_number=rs.field(0)+plus_id;
+            retorno.original_ID=rs.field(8);
+            retorno.msg_folder=rs.field(7);
+
+            //alert('tipo retorno: '+typeof(retorno))
+            //show_msg(retorno);
+        }
+		else
+        {
+            retorno['from'] = expresso.connector.unserialize(rs.field(2));
+            retorno['subject'] = rs.field(3);
+            retorno['body'] = rs.field(4);
+            //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do
+            //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]"
+            //sï¿œo substituidos pelos links dos anexos capturados pelo gears.
+
+            var thumbs= retorno.thumbs;
+            var anexos= retorno.array_attach;
+            for (i in anexos)
+            {
+                nomeArquivo = anexos[i]['name'].substring(0,anexos[i]['name'].length - 4);
+                if(nomeArquivo.match('jpg')||anexos[i]['name'].match('gif')||anexos[i]['name'].match('png'))
+                    {
+                        var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']);
+                        var Result_imagens = er_imagens.exec(retorno['body']);
+                        retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']);
+                        if(thumbs && thumbs[i]){
+                            er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']);
+                            Result_imagens = er_imagens.exec(thumbs[i]);
+                            thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'");
+                            er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']);
+                            Result_imagens = er_imagens.exec(thumbs[i]);
+                            thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'");
+                            thumbs[i] = thumbs[i].replace(/<IMG/i,'<img width="120"');
+                        }
+                    }
+            }
+
+            retorno['to'] = expresso.connector.unserialize(rs.field(5));
+            retorno['cc'] = expresso.connector.unserialize(rs.field(6));
+
+            retorno['local_message'] = true;
+            retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder
+            retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid
+
+        }
+
+        rs.close();
+		this.finalize();
+		return retorno;
+	}
+
+	local_messages.prototype.insert_attachments = function(id_msg,anexos) { 
+		//insert_mail already close and open gears.
+		for (var i = 0; i < anexos.length; i++) {
+			this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_msg, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]);
+			this.capt_url(anexos[i]['url']);
+		}
+	}
+
+	local_messages.prototype.capt_url = function (url) {
+		//insert_mail already close and open gears.
+		var call_back = function(url,success,captureId) {
+				//alert("Capturado: " + url);
+			}
+		//alert(url);
+		this.store.capture(url,call_back);
+	}
+
+	local_messages.prototype.strip_tags = function (str) {
+		return str.replace(/<\/?[^>]+>/gi, '');
+	}
+
+	local_messages.prototype.get_local_range_msgs = function(folder,msg_range_begin,emails_per_page,sort,sort_reverse,search,preview_msg_subject,preview_msg_tip) {
+
+		this.init_local_messages();
+		var retorno = new Array();
+		msg_range_begin--;
+		
+		filter = " ";
+		if(search=="FLAGGED") {
+			filter = "and (header like '%\"Flagged\";s:1:\"F%' or header like '%\"Importance\";s:5:\"High%') ";
+		}
+		if(search=="UNSEEN") {
+			filter = "and unseen = 1 ";
+		}
+		if(search=="SEEN") {
+			filter = "and unseen = 0 ";
+		}
+		if (search=="ANSWERED") {
+			filter = "and header like '%\"Answered\";s:1:\"A%' ";
+		}
+		
+		sql = 'select mail.rowid as rowid,mail.header as header,mail.size as size,mail.timestamp as timestamp,mail.unseen as unseen,mail.body as body,case when lower(mail.ffrom) like ? then ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') else ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') end as order_from,mail.subject from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=? order by '
+		
+		if(sort == 'SORTFROM') {
+			sql += 'order_from ';
+		}
+		if(sort == 'SORTARRIVAL') {
+			sql += 'timestamp ';
+		}
+		if(sort == 'SORTSIZE') {
+			sql += 'size ';
+		}
+		if(sort == 'SORTSUBJECT') {
+			sql += 'UPPER(subject) ';
+		}
+
+
+		sql+= sort_reverse==0?"ASC ":"DESC ";
+		sql +='limit ?,? ';
+
+
+		var rs = this.dbGears.execute(sql,['%'+Element("user_email").value+'%',account_id,folder,msg_range_begin,emails_per_page]);
+		var cont = 0;
+		
+		var rs3 = this.dbGears.execute('select count(*) from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=?'+filter,[account_id,folder]);
+				
+		while (rs.isValidRow()) {
+			//var email = rs.field(1);
+			var head = rs.field(1);
+			var codigoMail = rs.field(0);
+
+			var msg_body = rs.field(5);//recebe o conteudo da coluna "body" do banco de dados;
+
+			var rs2 = this.dbGears.execute('select count(*) from anexo where id_mail = '+codigoMail);
+			var head_unserialized = expresso.connector.unserialize(head);
+			head_unserialized.Size = rs.field(2);
+			if(rs.field(4)==1)
+				head_unserialized.Unseen = 'U';		
+			
+
+			head_unserialized.subject=(head_unserialized.subject==null)?"":head_unserialized.subject;
+
+			//var email_unserialized = expresso.connector.unserialize(email);
+			retorno[cont] = head_unserialized;
+			retorno[cont]['msg_number'] = codigoMail;
+			
+			//declaracao do array() para receber o body de cada mensagem encontrada na busca sql realizada;
+			msg_body=this.strip_tags(msg_body);
+			msg_body=msg_body.replace(/\&nbsp;/ig," ");
+			retorno[cont]['msg_sample'] = new Array();
+
+			if( (preview_msg_subject == 0) && (preview_msg_tip == 0) )
+			{
+				retorno[cont]['msg_sample']['body'] = "";
+			}
+			else
+			{
+				retorno[cont]['msg_sample']['body'] = " - " + msg_body.substr(2,300);
+			}
+
+			cont++;
+		  	rs.next();
+		}
+		retorno['num_msgs'] = rs3.field(0);
+		rs3.close();
+		rs.close();
+		if(cont>0)
+			rs2.close();
+		this.finalize();
+		return retorno;
+	}
+	
+	local_messages.prototype.get_url_anexo = function(msg_number,pid) {
+		this.init_local_messages();
+		var matches = '';
+		if(matches = this.parse_id_mail(msg_number)) {
+			msg_number = matches[1];
+		}
+		
+		var retorno;
+		var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'");
+		retorno = rs.field(0)
+		this.finalize();
+		
+		return retorno;
+	}
+
+	local_messages.prototype.getInputFileFromAnexo = function (element,url) { 
+		this.init_local_messages();
+		fileSubmitter = this.store.createFileSubmitter();
+		fileSubmitter.setFileInputElement(element,url);
+		this.finalize();
+	}
+
+	local_messages.prototype.finalize = function() {
+		this.dbGears.close();
+		this.dbGears = null;
+	}
+
+	local_messages.prototype.delete_msgs = function(msgs_number,border_ID) {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select url from anexo where id_mail in ("+msgs_number+")");
+		while(rs.isValidRow()) {
+			this.store.remove(rs.field(0));
+			rs.next();
+		}
+		this.dbGears.execute("delete from anexo where id_mail in ("+msgs_number+")");
+		this.dbGears.execute("delete from mail where rowid in ("+msgs_number+")");
+		this.finalize();
+		if (msgs_number.length == 1)
+			write_msg(get_lang("The message was deleted."));
+		else
+			write_msg(get_lang("The messages were deleted."));
+		
+		mail_msg = Element("tbody_box");
+
+		try {
+			msgs_exploded = msgs_number.split(",");
+		}catch(error) {
+			msgs_exploded = new Array();
+			msgs_exploded[0] = msgs_number;
+		}
+		var msg_to_delete;
+		for (var i=0; i<msgs_exploded.length; i++){
+			msg_to_delete = Element(msgs_exploded[i]);
+			if (msg_to_delete){
+				if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') )
+					select_msg('null', 'down');
+				mail_msg.removeChild(msg_to_delete);
+				decrement_folder_unseen();
+			}
+		}
+		Element('chk_box_select_all_messages').checked = false;
+		if (border_ID != 'null')
+			delete_border(border_ID,'false');
+		
+	}
+	
+	local_messages.prototype.get_source_msg = function(id_msg) {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select mail from mail where rowid="+id_msg);
+
+
+		mail = expresso.connector.unserialize(rs.field(0));		
+		download_local_attachment(mail.url_export_file)
+
+		this.finalize();
+	}
+	
+	
+	
+	local_messages.prototype.set_messages_flag = function(msgs_number, flag) {
+		this.init_local_messages();
+		var msgs_to_set;
+		if (msgs_number == 'get_selected_messages') { 
+			var msgs_to_set = get_selected_messages();
+			msgs_to_set= msgs_to_set.split(",");
+		}
+		else { //Just one message
+			msgs_to_set = new Array();
+			msgs_to_set[0] = msgs_number;
+		}
+		for (var i in msgs_to_set) {
+			
+			var matches = '';//Messages comming from other tabs.
+			if(matches = this.parse_id_mail(msgs_to_set[i])) { 
+				msgs_to_set[i] = matches[1];
+			}
+			
+			var rs = this.dbGears.execute("select header,unseen from mail where rowid=" + msgs_to_set[i]);
+			header = expresso.connector.unserialize(rs.field(0));
+			unseen = rs.field(1);
+			switch(flag) {
+				case "unseen":
+					set_msg_as_unread(msgs_to_set[i]);
+					header["Unseen"] = "U";
+					unseen = 1;
+					break;
+				case "flagged":
+					set_msg_as_flagged(msgs_to_set[i]);
+					header["Flagged"] = "F";
+					break;
+				case "unflagged":
+					if (header["Importance"].indexOf("High") != -1) 
+						write_msg(get_lang("At least one of selected message cant be marked as normal"));
+					else {
+						set_msg_as_unflagged(msgs_to_set[i]);
+						header["Flagged"] = "N";
+					}
+					break;
+				case "seen":
+					header["Unseen"] = "N";
+					set_msg_as_read(msgs_to_set[i],true);
+					unseen = 0;
+					break;
+				case "answered":
+					header["Draft"]="";
+					header["Answered"]="A";
+					Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/answered.gif title=Respondida>';
+					break;
+				case "forwarded":
+					header["Draft"]="X";
+					header["Answered"]="A";
+					Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/forwarded.gif title=Encaminhada>';
+					break;
+			}
+		
+			rs.close();
+			
+			if(Element("check_box_message_" + msgs_to_set[i]))
+				Element("check_box_message_" + msgs_to_set[i]).checked = false;
+
+			this.dbGears.execute("update mail set header='"+expresso.connector.serialize(header)+"',unseen="+unseen+" where rowid="+msgs_to_set[i]);			
+		}
+		if(Element('chk_box_select_all_messages'))
+			Element('chk_box_select_all_messages').checked = false;
+		this.finalize();
+
+	}
+	
+	local_messages.prototype.set_message_flag = function(msg_number,flag) {
+		this.set_messages_flag(msg_number,flag);
+	}
+	
+	local_messages.prototype.get_unseen_msgs_number = function() {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select count(*) from mail where unseen=1");
+		var retorno = rs.field(0);
+		rs.close();
+		this.finalize();
+		return retorno;
+	}
+
+	local_messages.prototype.create_folder = function(folder) {
+
+		if (folder.indexOf("local_") != -1)
+			return false; //can't create folder with string local_
+
+		this.init_local_messages();
+		try {
+			this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",[folder,account_id]);
+		} catch (error) {
+			this.finalize();
+			throw error;
+			return false;
+		}
+		this.finalize();
+		return true;
+	}
+
+	local_messages.prototype.list_local_folders = function(folder) {
+		this.init_local_messages();
+		var retorno = new Array();
+		rs = this.dbGears.execute("select folder,rowid from folder where uid_usuario=?",[account_id]);
+		while(rs.isValidRow()) {
+			var temp = new Array();
+			temp[0] = rs.field(0);
+			
+			var rs2 = this.dbGears.execute("select count(*) from mail where id_folder=? and unseen=1",[rs.field(1)]);
+			temp[1] = rs2.field(0);			
+
+			var rs3 = this.dbGears.execute("select * from folder where folder like ? limit 1",[temp[0]+"/%"]);
+			if(rs3.isValidRow())
+				temp[2] = 1;
+			else
+				temp[2] = 0;
+			retorno.push(temp);
+			rs.next();
+		}
+		
+		rs.close();
+		this.finalize();
+		return retorno;
+	}
+
+	local_messages.prototype.rename_folder = function(folder,old_folder) {
+		if (folder.indexOf("local_") != -1)
+			return false; //can't create folder with string local_
+		this.init_local_messages();
+		if (old_folder.indexOf("/") != "-1") {
+			final_pos = old_folder.lastIndexOf("/");
+			folder = old_folder.substr(0, final_pos) + "/" + folder;
+		}
+		try {
+			this.dbGears.execute("update folder set folder=? where folder=? and uid_usuario=?",[folder,old_folder,account_id]);
+		} catch (error) {
+			this.finalize();
+			return false;
+		}
+		rs = this.dbGears.execute("select folder from folder where folder like ? and uid_usuario=?",[old_folder+'/%',account_id]);
+		while(rs.isValidRow()) {
+			folder_tmp = rs.field(0);
+			folder_new = folder_tmp.replace(old_folder,folder);
+			this.dbGears.execute("update folder set folder=? where folder=?",[folder_new,folder_tmp]);
+			rs.next();
+		}
+
+
+		this.finalize();
+		return true;
+	}
+	
+	local_messages.prototype.remove_folder = function(folder) {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select count(rowid) from folder where folder like ? and uid_usuario=?",[folder+"/%",account_id]);
+		var sons = rs.field(0);
+		rs.close();
+
+		if(sons == 0){
+		var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]);
+		var folder_id = rs.field(0);
+		rs.close();
+		this.dbGears.execute("delete from folder where rowid=?",[folder_id]);
+		rs = this.dbGears.execute("select rowid,mail from mail where id_folder=?",[folder_id]);
+		while(rs.isValidRow()) {
+			var rs2 = this.dbGears.execute("select url from anexo where id_mail=?",[rs.field(0)]);
+			while(rs2.isValidRow()) {
+				this.store.remove(rs2.field(0));
+				rs2.next();
+			}
+			rs2.close();
+			this.dbGears.execute("delete from anexo where id_mail=?",[rs.field(0)]);
+			var mail = expresso.connector.unserialize(rs.field(1));
+			this.store.remove(mail.url_export_file);
+			rs.next();
+		}
+		rs.close();
+		this.dbGears.execute("delete from mail where id_folder=?",[folder_id]);
+		this.finalize();
+		return true;
+		}else  {
+		    this.finalize();
+			return false;
+	}
+
+	}
+
+	local_messages.prototype.move_messages = function(new_folder,msgs_number) {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[new_folder,account_id]);
+		var id_folder = rs.field(0);
+		rs.close();
+		this.dbGears.execute("update mail set id_folder="+id_folder+" where rowid in ("+msgs_number.toString()+")"); //usando statement nï¿œo tava funcionando quando tinha mais de um email...
+		this.finalize();
+	}
+	
+	local_messages.prototype.search = function(folders,sFilter) {
+		this.init_local_messages();
+                var filters = sFilter.replace(/^##|##$/g,"").split('##');
+		var friendly_filters = new Array();
+
+                if (sFilter.indexOf('ALL') != -1) { //all filters...
+                    filters[0] = sFilter.replace(/##/g,"");
+                    tmp = filters[0].split("<=>");
+
+                    searchKey = new Array();
+                    searchKey.push("SUBJECT");
+                    searchKey.push(tmp[1]);
+                    friendly_filters.push(searchKey);
+
+                    searchKey = new Array();
+                    searchKey.push("BODY");
+                    searchKey.push(tmp[1]);
+                    friendly_filters.push(searchKey);
+
+                    searchKey = new Array();
+                    searchKey.push("FROM");
+                    searchKey.push(tmp[1]);
+                    friendly_filters.push(searchKey);
+
+                    searchKey = new Array();
+                    searchKey.push("TO");
+                    searchKey.push(tmp[1]);
+                    friendly_filters.push(searchKey);
+
+                    searchKey = new Array();
+                    searchKey.push("CC");
+                    searchKey.push(tmp[1]);
+                    friendly_filters.push(searchKey);
+		}
+		else {
+                    for (var i=0; i<filters.length; i++)
+                    {
+                        if (filters[i] != ""){
+                            //tmp[0] = tmp[0].replace(/^\s+|\s+$/g,"");
+                            //tmp[1] = tmp[1].replace(/^\s+|\s+$/g,"");
+                            friendly_filters.push(filters[i].split("<=>"));
+                        }
+                    }
+		}
+		var sql = "select mail.header,folder.folder,mail.rowid,size from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario="+account_id + " and folder.folder in (";
+		for(var fnum in folders) {
+			sql+="'"+folders[fnum]+"'";
+			if(fnum<folders.length-1)
+				sql+=",";
+		}
+		sql += ") and (";
+		for (var z=0;z<friendly_filters.length;z++) {
+                    if (z != 0) {
+                        if (sFilter.indexOf('ALL') != -1)
+                            sql += " or";
+                        else
+                            sql += " and";
+                    }
+                    var cond = friendly_filters[z][0].replace(/^\s+|\s+$/g,"");
+                    if (cond == "SINCE" || cond == "BEFORE" | cond == "ON"){
+
+                        tmpDate = url_decode(friendly_filters[z][1]).split('/');
+
+                        // Date = url_decode(friendly_filters[z][1]);
+                        sql+=" mail.timestamp " + this.aux_convert_filter_field(friendly_filters[z][0], tmpDate);
+                    }
+                    else if (!friendly_filters[z][1])
+                        {
+                            sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0]);
+                        }
+                        else
+                            {
+                                sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0])+" like '%"+url_decode(friendly_filters[z][1])+"%'";
+                            }
+		}
+		sql += ")";
+		var rs = this.dbGears.execute(sql);
+		var retorno = "";
+		while(rs.isValidRow()) {
+                    var header = expresso.connector.unserialize(rs.field(0));
+                    retorno+="##"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##";
+                    rs.next();
+		}
+
+		this.finalize();
+		return retorno==""?false:retorno;
+
+	}
+	
+	local_messages.prototype.aux_convert_size = function(size) {
+		var tmp = Math.floor(size/1024);
+		if(tmp >= 1){
+			return tmp + " kb";	
+		}else{
+			return size + " b";	
+		}
+		
+	}
+	
+	local_messages.prototype.aux_convert_filter_field = function(filter,date) {
+                if (typeof date != 'undefined'){
+                    var dateObj=new Date();
+                    dateObj.setFullYear(date[2],date[1]-1,date[0]);
+                }
+
+		if((filter=="SUBJECT ") || (filter=="SUBJECT"))
+			return "subject";
+		else if((filter=="BODY ") || (filter=="BODY"))
+			return "body";
+		else if((filter=="FROM ") || (filter=="FROM"))
+			return "ffrom";
+		else if((filter=="TO ") || (filter=="TO"))
+			return "fto";
+		else if((filter=="CC ") || (filter=="CC"))
+			return "cc";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "SINCE"){
+                        dateObj.setHours(0, 0, 0, 0);
+                        return ">= " + dateObj.getTime().toString(10).substr(0, 10);
+                }
+                else if (filter.replace(/^\s+|\s+$/g,"") == "BEFORE"){
+                        dateObj.setHours(23, 59, 59, 999);
+                        return "<= " + dateObj.getTime().toString(10).substr(0, 10);
+                }
+                else if (filter.replace(/^\s+|\s+$/g,"") == "ON"){
+                        dateObj.setHours(0, 0, 0, 0);
+                        var ts1 = dateObj.getTime().toString(10).substr(0, 10);
+                        dateObj.setHours(23, 59, 59, 999);
+                        var ts2 = dateObj.getTime().toString(10).substr(0, 10);
+                        return ">= " + ts1 + ") and (timestamp <= " + ts2;
+                }
+                else if (filter.replace(/^\s+|\s+$/g,"") == "FLAGGED")
+                        return "flagged = 1";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "UNFLAGGED")
+                        return "flagged = 0";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "UNSEEN")
+                        return "unseen = 1";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "SEEN")
+                        return "unseen = 0";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "ANSWERED")
+                        return "answered = 1";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "UNANSWERED")
+                        return "answered = 0";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "RECENT")
+                        return "recent = 1";
+                else if (filter.replace(/^\s+|\s+$/g,"") == "OLD")
+                        return "recent = 0";
+
+	}
+	
+	local_messages.prototype.has_local_mails = function() {
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select rowid from folder limit 0,1");
+		var retorno;
+		if(rs.isValidRow())
+			retorno = true;
+		else 
+			retorno = false;
+		this.finalize();
+		return retorno;
+	}
+
+     //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Essa funï¿œï¿œo ï¿œ um AJAX simples que serve apenas para pegar o fonte de uma msg local (no formato RFC 822).
+    local_messages.prototype.get_src = function(url){
+        AJAX = false;
+        if (window.XMLHttpRequest) { // Mozilla, Safari,...
+            AJAX = new XMLHttpRequest();
+            if (AJAX.overrideMimeType) {
+                AJAX.overrideMimeType('text/xml');
+            }
+        } else if (window.ActiveXObject) { // IE
+            try {
+                AJAX = new ActiveXObject("Msxml2.XMLHTTP");
+            } catch (e) {
+                try {
+                AJAX = new ActiveXObject("Microsoft.XMLHTTP");
+                } catch (e) {}
+            }
+        }
+
+        if (!AJAX) {
+            alert('ERRO :(Seu navegador nï¿œo suporta a aplicaï¿œï¿œo usada neste site');
+            return false;
+        }
+
+        AJAX.onreadystatechange = function() {
+            if (AJAX.readyState == 4) {
+                AJAX.src=AJAX.responseText;
+                if (AJAX.status == 200) {
+                    return AJAX.responseText;
+                    } else {
+                    return false;
+                }
+            }
+        }
+
+        AJAX.open('get', url, false);
+        AJAX.send(null);
+        return AJAX.responseText;
+    };
+
+  //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Dessarquiva msgs locais pegando o codigo fonte das mesmas e mandando via POST para o servidor
+  //para que elas sejam inseridas no imap pela funï¿œï¿œo  imap_functions.unarchive_mail.
+    local_messages.prototype.unarchive_msgs = function (folder,new_folder,msgs_number){
+
+        if(!new_folder)
+            new_folder='INBOX';
+        this.init_local_messages();
+       // alert(folder+new_folder+msgs_number);
+        var handler_unarchive = function(data)
+        {
+            if(data.error == '')
+                write_msg(get_lang('All messages are successfully unarchived'));
+            else
+                alert(data.error);
+        }
+        if(msgs_number =='selected' || !msgs_number)
+        {
+            msgs_number = get_selected_messages()
+            if (!msgs_number){
+                write_msg(get_lang('No selected message.'));
+                return;
+            }
+            var rs = this.dbGears.execute("select mail,timestamp from mail where rowid in ("+msgs_number+")");
+            var source="";
+            var timestamp="";
+            while(rs.isValidRow()) {
+                mail=expresso.connector.unserialize(rs.field(0));
+                source_tmp=escape(this.get_src(mail.url_export_file));
+                    source+="#@#@#@"+source_tmp;
+                    timestamp+="#@#@#@"+rs.field(1);
+                rs.next();
+            }
+            rs.close();
+            this.finalize();
+        }
+        else
+        {
+            var rs = this.dbGears.execute("select mail,timestamp from mail where rowid="+msgs_number);
+            mail=expresso.connector.unserialize(rs.field(0));
+            var source ="";
+            source = this.get_src(mail.url_export_file);
+            timestamp=rs.field(1);
+             rs.close();
+             this.finalize();
+        }
+            params="&folder="+new_folder+"&source="+source+"&timestamp="+timestamp;
+            cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params);
+    }
+
+    local_messages.prototype.get_msg_date = function (original_id, is_local){
+
+        this.init_local_messages();
+
+        if (typeof(is_local) == 'undefined')
+        {
+            is_local = false;
+        }
+
+        var rs;
+
+        if (is_local)
+        {
+            rs = this.dbGears.execute("select mail from mail where rowid="+original_id);
+        }
+        else
+        {
+            rs = this.dbGears.execute("select mail from mail where original_id="+original_id);
+        }
+        var tmp = expresso.connector.unserialize(rs.field(0));
+        var ret = new Array();
+        ret.fulldate = tmp.fulldate.substr(0,16);
+        ret.smalldate = tmp.msg_day;
+        ret.msg_day = tmp.msg_day;
+        ret.msg_hour = tmp.msg_day;
+
+        rs.close();
+        this.finalize();
+        return ret;
+    }
+
+
+    local_messages.prototype.download_all_local_attachments = function(folder,id){
+        this.init_local_messages();
+        var rs = this.dbGears.execute("select mail from mail where rowid="+id);
+        var tmp = expresso.connector.unserialize(rs.field(0));
+        rs.close();
+        this.finalize();
+        source = this.get_src(tmp.url_export_file);
+        source = escape(source);
+        var handler_source = function(data){
+            download_attachments(null, null, data, null,null,'anexos.zip');
+        }
+        cExecute("$this.imap_functions.download_all_local_attachments",handler_source,"source="+source);
+    }
+
+    /*************************************************************************/
+/* Funcao usada para exportar mensagens arquivadas localmente.
+ * Rommel de Brito Cysne (rommel.cysne@serpro.gov.br)
+ * em 22/12/2008.
+ */
+    local_messages.prototype.local_messages_to_export = function(){
+
+        if (openTab.type[currentTab] > 1){
+            var msgs_to_export_id = currentTab.substring(0,currentTab.length-2,currentTab);
+        }else{
+            var msgs_to_export_id = get_selected_messages();
+        }
+        var handler_local_mesgs_to_export = function(data){
+            download_attachments(null, null, data, null,null,'mensagens.zip');
+        }
+        if(msgs_to_export_id){
+            this.init_local_messages();
+            var l_msg = "t";
+            var mesgs ="";
+            var subjects ="";
+            var rs = this.dbGears.execute("select mail,subject from mail where rowid in ("+msgs_to_export_id+")");
+            while(rs.isValidRow()){
+                mail = expresso.connector.unserialize(rs.field(0));
+                mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file);
+                subject = rs.field(1);
+                mesgs += src;
+                mesgs += "@@";
+                subjects += subject;
+                subjects += "@@";
+                rs.next();
+            }
+            rs.close();
+            this.finalize();
+            mesgs = escape(mesgs);
+            subjects = escape(subjects);
+            params = "subjects="+subjects+"&mesgs="+mesgs+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export_id;
+            cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params);
+        }
+        return true;
+    }
+
+    local_messages.prototype.get_all_local_folder_messages= function(folder_name){
+
+
+         var mesgs = new Array();
+         var subjects = new Array();
+         var hoje = new Date();
+         var msgs_to_export = new Array();
+         var l_msg="t";
+
+        this.init_local_messages();
+        var query = "select mail,subject,mail.rowid from mail inner join folder on (mail.id_folder=folder.rowid) where folder.folder='" + folder_name + "'";
+
+        var rs = this.dbGears.execute(" "+query)
+
+            var handler_local_mesgs_to_export = function(data){
+                    //alert("data - " + data + " - tipo - " + typeof(data));
+                    download_attachments(null, null, data, null,null,'mensagens.zip');
+            }
+        var j=0;
+        while (rs.isValidRow()){
+              msgs_to_export[j]=rs.field(2)
+              mail = expresso.connector.unserialize(rs.field(0));
+                      mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file);
+                      subject = rs.field(1);
+                      mesgs += msg;
+                      mesgs += "@@";
+                      subjects += subject;
+                      subjects += "@@";
+                      rs.next();
+              j++;
+
+        }
+           rs.close();
+           this.finalize();
+           source = escape(mesgs);
+           subjects = escape(subjects);
+           params = "folder="+folder_name+"&subjects="+subjects+"&mesgs="+source+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export;
+           cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params);
+          
+
+    }
+
+
+    /*************************************************************************/
+
+	
+/******************************************************************
+	 				Offline Part 
+ ******************************************************************/
+
+	local_messages.prototype.is_offline_installed = function() {
+		this.init_local_messages();
+		var check = this.localServer.openManagedStore('expresso-offline');
+		this.finalize();
+		if(check==null)
+			return false;
+		else
+			return true;
+		
+	}
+	local_messages.prototype.update_offline = function(redirect) {
+		this.init_local_messages();
+		var managedStore = this.localServer.openManagedStore('expresso-offline');
+
+		if(managedStore!=null){
+			
+			managedStore.oncomplete = function(details){
+				if(redirect!=null)
+					location.href=redirect;
+			}
+			
+			managedStore.checkForUpdate();
+		} else if(redirect!=null) {
+			location.href=redirect;
+		}
+		this.finalize();
+	}
+	
+	local_messages.prototype.uninstall_offline = function() {
+		if (!window.google || !google.gears) {
+				temp = confirm(document.getElementById('lang_gears_redirect').value);
+				if (temp) {
+					expresso_local_messages.installGears();
+				}
+				return;
+
+		}
+		this.init_local_messages();
+		this.localServer.removeManagedStore('expresso-offline');
+		alert(document.getElementById('lang_offline_uninstalled').value);
+		//this.dbGears.execute('drop table user');
+		//this.dbGears.execute('drop table queue');
+		//this.dbGears.execute('drop table attachments_queue');
+		this.finalize();
+	}
+	
+	local_messages.prototype.get_folders_to_sync = function() {//Precisa ter visibilidade ao array de linguagens.
+		this.init_local_messages();
+		var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario="+account_id);
+		var retorno = new Array();
+		while(rs.isValidRow()) {
+			temp = new Array();
+			temp[0] = rs.field(0);
+			if(temp[0]=='INBOX/Drafts' ||temp[0]=='INBOX/Trash' || temp[0]=='INBOX/Sent') {
+				temp[1] = array_lang[rs.field(1).toLowerCase()];
+			}
+			else {
+				temp[1] = rs.field(1);	
+			}
+			
+			retorno.push(temp);
+			rs.next();
+		}
+		this.finalize();
+		return retorno;
+	}
+	
+	local_messages.prototype.install_offline = function(urlOffline,urlIcone,uid_usuario,login,pass,redirect) {
+		if (!window.google || !google.gears) {
+				temp = confirm(document.getElementById('lang_gears_redirect').value);
+				if (temp) {
+					 expresso_local_messages.installGears();
+				}
+				return;
+
+		}
+		
+		if(pass.length>0) {
+			only_spaces = true;
+			for(cont=0;cont<pass.length;cont++) {
+				if(pass.charAt(cont)!=" ")
+					only_spaces = false;
+			}
+			if(only_spaces) {
+				alert(document.getElementById('lang_only_spaces_not_allowed').value);
+				return false;
+			}
+		}
+
+		modal('loading');
+		var desktop = google.gears.factory.create('beta.desktop');
+		desktop.createShortcut('ExpressoMail Offline',
+			urlOffline,
+	        {'32x32': urlIcone},
+	        'ExpressoMail Offline');
+
+
+		this.init_local_messages();
+
+		//user with offline needs to have at least the folder Inbox already created.
+		tmp_rs = this.dbGears.execute("select rowid from folder where folder='Inbox' and uid_usuario=?",[uid_usuario]);
+		if(!tmp_rs.isValidRow())
+			this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",['Inbox',uid_usuario]);
+
+		this.localServer.removeManagedStore('expresso-offline');
+	
+		var managedStore = this.localServer.createManagedStore('expresso-offline');
+		managedStore.manifestUrl = 'js/manifest';
+
+		managedStore.onerror = function (error) {
+			alert(error);
+		}
+		
+		managedStore.oncomplete = function(details) {
+			if (close_lightbox_div) {
+				close_lightbox();
+				close_lightbox_div = false;
+				alert(document.getElementById('lang_offline_installed').value);
+				location.href=redirect;
+			}
+		}
+
+		//create structure to user in db
+		this.dbGears.execute('create table if not exists user (uid_usuario int,login text,pass text, logged int,unique(uid_usuario))');
+		this.dbGears.execute('create table if not exists queue (ffrom text, fto text, cc text, cco text,'+
+			'subject text, conf_receipt int, important int,body text,sent int,user int)');
+		this.dbGears.execute('create table if not exists attachments_queue ('+
+			'id_queue int, url_attach text)');
+		this.dbGears.execute('create table if not exists sent_problems (' +
+			'id_queue int,message text)');
+		
+		//d = new Date();
+		
+		try {
+			var rs = this.dbGears.execute("select uid_usuario from user where uid_usuario=?",[uid_usuario]);
+			if(!rs.isValidRow())
+				this.dbGears.execute("insert into user (uid_usuario,login,pass) values (?,?,?)",[uid_usuario,login,pass]);
+			else
+				this.dbGears.execute("update user set pass=? where uid_usuario=?",[pass,uid_usuario]);
+		} catch (error) {
+			this.finalize();
+			alert(error);
+			return false;
+		}
+		managedStore.checkForUpdate();
+		this.capt_url('controller.php?action=$this.db_functions.get_dropdown_contacts_to_cache');
+		
+		this.finalize();
+	}
+	
+	/**
+	 * Return all users in an array following the structure below.
+	 * 
+	 * key: uid
+	 * value: user login
+	 */
+	local_messages.prototype.get_all_users = function() {
+		this.init_local_messages();
+		var users = new Array();
+		var rs = this.dbGears.execute("select uid_usuario,login from user");
+		while(rs.isValidRow()) {
+			users[rs.field(0)] = rs.field(1);
+			rs.next();
+		}
+		this.finalize();
+		return users;
+	}
+	
+	local_messages.prototype.set_as_logged = function(uid_usuario,pass,bypass) {
+		this.init_local_messages();
+		if (!bypass) {
+			var rs = this.dbGears.execute("select pass from user where uid_usuario=?", [uid_usuario]);
+			if (!rs.isValidRow() || (pass != rs.field(0) && pass != MD5(rs.field(0)))) {
+				this.finalize();
+				return false;
+			}
+		}
+		d = new Date();
+
+		this.dbGears.execute("update user set logged=null"); //Logoff in everybody
+		this.dbGears.execute("update user set logged=? where uid_usuario=?",[d.getTime(),uid_usuario]); //Login just in one...
+		this.finalize();
+		return true;
+	}
+	
+	local_messages.prototype.unset_as_logged = function() {
+		this.init_local_messages();
+		this.dbGears.execute("update user set logged=null"); //Logoff in everybody
+		this.finalize();
+	}
+	
+	local_messages.prototype.user_logged = function() {
+		this.init_local_messages();
+		var user_logged = new Array();
+		var rs = this.dbGears.execute("select uid_usuario,logged from user where logged is not null");
+		if(!rs.isValidRow()) {
+			this.finalize();
+			return null;
+		}
+		user_logged[0] = rs.field(0);
+		user_logged[1] = rs.field(1);
+		this.finalize();
+		return user_logged;
+	}
+	
+	local_messages.prototype.send_to_queue = function (form) {
+		this.init_local_messages();
+		var mail_values = new Array();
+		
+		for (var i=0;i<form.length;i++) {
+			if (form.elements[i].name != '') { //I.E made me to do that...
+				if(form.elements[i].name=='folder' || form.elements[i].name=='msg_id' || form.elements[i].name=='' || form.elements[i].name==null)
+					continue;
+				else if (form.elements[i].name == 'input_return_receipt' ) 
+					mail_values['conf_receipt'] = form.elements[i].checked ? 1 : 0;
+				else if(form.elements[i].name == 'input_important_message')
+					mail_values['important'] = form.elements[i].checked ? 1 : 0;
+				else 
+					if (form.elements[i].name == 'body') 
+						mail_values['body'] = form.elements[i].value;
+					else 
+						if (form.elements[i].name == 'input_from') 
+							mail_values['ffrom'] = form.elements[i].value;
+						else 
+							if (form.elements[i].name == 'input_to') 
+								mail_values['fto'] = form.elements[i].value;
+							else 
+								if (form.elements[i].name == 'input_cc') 
+									mail_values['cc'] = form.elements[i].value;
+								else 
+									if (form.elements[i].name == 'input_cco') 
+										mail_values['cco'] = form.elements[i].value;
+									else 
+										if (form.elements[i].name == 'input_subject') 
+											mail_values['subject'] = form.elements[i].value;
+			}
+		}
+		//mail_values['fto'] = input_to;
+		//mail_values['cc'] = input_cc;
+		//mail_values['cco'] = input_cco;
+		//mail_values['subject'] = input_subject;
+		//mail_values['conf_receipt'] = input_return_receipt;
+		//mail_values['important'] = input_important_message;
+		
+		try {
+			this.dbGears.execute("insert into queue (ffrom,fto,cc,cco,subject,conf_receipt,important,body,sent,user) values (?,?,?,?,?,?,?,?,0,?)", [mail_values['ffrom'], mail_values['fto'], mail_values['cc'], mail_values['cco'], mail_values['subject'], mail_values['conf_receipt'], mail_values['important'], mail_values['body'], account_id]);
+			this.send_attach_to_queue(this.dbGears.lastInsertRowId,form);
+		}catch(error) {
+			alert(error);
+			return get_lang('Error sending a mail to queue. Verify if you have installed ExpressoMail Offline');
+		}
+		this.finalize();
+		return true;
+	}
+	
+	local_messages.prototype.send_attach_to_queue = function(id_queue,form) {
+		
+		for(i=0;i<form.elements.length;i++) {
+			
+			if(form.elements[i].name.indexOf("file_")!=-1) {
+				var tmp_input = form.elements[i];
+				var d = new Date();
+				var url_local = 'local_attachs/'+d.getTime();
+				this.store.captureFile(tmp_input, url_local);
+				this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,url_local]);
+			}
+			else if(form.elements[i].name.indexOf("offline_forward_")!=-1){
+				//alert();
+				this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,form.elements[i].value]);
+			}
+		}
+	}
+
+	
+	local_messages.prototype.get_num_msgs_to_send = function() {
+		this.init_local_messages();
+
+		var rs = this.dbGears.execute("select count(*) from queue where user=? and sent=0",[account_id]);
+		var to_return = rs.field(0);
+
+		this.finalize();
+		return to_return;
+	}
+	
+	local_messages.prototype.set_problem_on_sent = function(rowid_message,msg) {
+		this.init_local_messages();
+		this.dbGears.execute("update queue set sent = 2 where rowid=?",[rowid_message]);
+		this.dbGears.execute("insert into sent_problems (id_queue,message) values (?,?)"[rowid_message,msg]);
+		this.finalize();
+	}
+	
+	local_messages.prototype.set_as_sent = function(rowid_message) {
+		this.init_local_messages();
+		this.dbGears.execute("update queue set sent = 1 where rowid=?",[rowid_message]);
+		this.finalize();
+	}
+	
+	local_messages.prototype.get_form_msg_to_send = function() {
+		this.init_local_messages();
+		var rs = this.dbGears.execute('select ffrom,fto,cc,cco,subject,conf_receipt,important,body,rowid from queue where sent=0 and user = ? limit 0,1',[account_id]);
+		if(!rs.isValidRow())
+			return false;
+		
+		var form = document.createElement('form');
+		form.method = 'POST';
+		form.name = 'form_queue_'+rs.field(8);
+		form.style.display = 'none';
+		form.onsubmit = function(){return false;}
+		if(!is_ie)
+			form.enctype="multipart/form-data";
+		else
+			form.encoding="multipart/form-data";
+		
+		var ffrom = document.createElement('TEXTAREA');
+		ffrom.name = "input_from";
+		ffrom.value = rs.field(0);
+		form.appendChild(ffrom);
+		
+		var fto = document.createElement('TEXTAREA');
+		fto.name = "input_to";
+		fto.value = rs.field(1);
+		form.appendChild(fto);
+		
+		var cc = document.createElement('TEXTAREA');
+		cc.name = "input_cc";
+		cc.value = rs.field(2);
+		form.appendChild(cc);
+
+		var cco = document.createElement('TEXTAREA');
+		cco.name = "input_cco";
+		cco.value = rs.field(3);
+		form.appendChild(cco);
+		
+		var subject = document.createElement('TEXTAREA');
+		subject.name = "input_subject";
+		subject.value = rs.field(4);
+		form.appendChild(subject);
+		
+		var folder = document.createElement('input');
+		folder.name='folder';
+		folder.value=preferences.save_in_folder;
+		form.appendChild(folder);
+		
+		if (rs.field(5) == 1) {
+			var conf_receipt = document.createElement('input');
+			conf_receipt.type='text';
+			conf_receipt.name = "input_return_receipt";
+			conf_receipt.value = 'on';
+			form.appendChild(conf_receipt);
+		}
+		
+		if (rs.field(6) == 1) {
+			var important = document.createElement('input');
+			important.type='text';
+			important.name = "input_important_message";
+			important.value = 'on';
+			form.appendChild(important);
+		}
+		
+		var body = document.createElement('TEXTAREA');
+		body.name = "body";
+		body.value = rs.field(7);
+		form.appendChild(body);
+		
+		var rowid = document.createElement('input');
+		rowid.type = 'hidden';
+		rowid.name = 'rowid';
+		rowid.value = rs.field(8);
+		form.appendChild(rowid);
+		
+		//Mounting the attachs
+		var divFiles = document.createElement("div");
+		divFiles.id = 'divFiles_queue_'+rs.field(8);
+		
+		form.appendChild(divFiles);
+		
+		document.getElementById('forms_queue').appendChild(form);
+
+		var is_local_forward = false;
+		try {
+			
+			var rs_attach = this.dbGears.execute('select url_attach from attachments_queue where id_queue=?', [rs.field(8)]);
+			while (rs_attach.isValidRow()) {
+				if(rs_attach.field(0).indexOf('../tmpLclAtt/')==-1) {
+					tmp_field = addForwardedFile('queue_' + rs.field(8), this.store.getCapturedFileName(rs_attach.field(0)), 'nothing');
+				}
+				else {
+					var tempNomeArquivo = rs_attach.field(0).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.
+					is_local_forward = true;
+					tmp_field = addForwardedFile('queue_' + rs.field(8), nomeArquivo, 'nothing');
+				}
+				fileSubmitter = this.store.createFileSubmitter();
+				fileSubmitter.setFileInputElement(tmp_field,rs_attach.field(0));
+		//		alert(form.innerHTML);
+			//	div.appendChild(tmp_field);
+				rs_attach.next();
+			}
+			
+			if(is_local_forward) {
+				var is_lcl_fw = document.createElement('input');
+				is_lcl_fw.type = 'hidden';
+				is_lcl_fw.name = 'is_local_forward';
+				is_lcl_fw.value = "1";
+				form.appendChild(is_lcl_fw);
+			}
+				
+		}
+		catch(exception) {
+			alert(exception);
+		}
+		
+		this.finalize();
+		return form;
+	}
+
+	var expresso_local_messages;
+	expresso_local_messages = new local_messages();
+	expresso_local_messages.create_objects();
Index: trunk/expressoMail1_2/js/jscode/TreeS.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/TreeS.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/TreeS.js	(revision 2517)
@@ -0,0 +1,216 @@
+/**************************************************************************\
+ Início 
+\**************************************************************************/
+
+	function treeS()
+	{
+		this.arrayW = new Array();
+		this.el;
+		this.FOLDER = "";
+	}
+
+	treeS.prototype.make_Window = function(){	
+		_this = this;
+		expresso.connector.loadScript("jscode/TreeShow");
+		var title = ':: '+get_lang("Manager your folders and export messages")+' ::';
+		tree 				  = document.createElement("DIV");
+		tree.style.visibility = "hidden";
+		tree.style.position   = "absolute";
+		tree.style.left 	  = "0px";
+		tree.style.top 		  = "0px";
+		tree.style.width 	  = "0px";
+		tree.style.height 	  = "0px";									
+		tree.id				  = "window_tree";
+		document.body.appendChild(tree);
+
+		tree.innerHTML = "&nbsp;&nbsp;&nbsp;<b><font color='BLACK' nowrap>"+title+"</font></b>"+
+		"&nbsp;&nbsp;<br><u></u>&nbsp;&nbsp;";
+
+		var div_buttons = document.createElement("DIV");
+		div_buttons.id = "div_buttons";
+		div_buttons.style.position = "absolute";		
+		div_buttons.style.left = "440px";
+		div_buttons.style.top = "20px"		
+		div_buttons.style.width = "130px";
+		div_buttons.style.height = "214px";
+		div_buttons.innerHTML = "<table border='0' cellpading='0' cellspacing='0'>"+
+							    "<tr>"+
+							    "<td><input type='button' value='"+get_lang('New folder')+"' onclick='proxy_mensagens.proxy_create_folder()'></td>"+
+							    "</tr>"+
+							    "<tr>"+
+							    "<td><input type='button' value='"+get_lang('Delete folder')+"' onclick='proxy_mensagens.proxy_remove_folder()'></td>"+
+							    "</tr>"+
+							    "<tr>"+
+							    "<td><input type='button' value='"+get_lang('Rename folder')+"' onclick='proxy_mensagens.proxy_rename_folder()'></td>"+
+							    "</tr>"+
+							    "<tr>"+
+                                                            //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Chama o proxy_mensagens para que uma pasta local também possa ser exportada
+                                                            "<td><input type='button' value='"+get_lang('Export messages')+"' onclick='proxy_mensagens.proxy_export_all_msg()'></td>"+
+							    "</tr>"+
+							    "<tr><td><br><br><br><br><br></td></tr>"+
+							    "<tr><td><input type='button' value='"+get_lang('Close')+"' onclick='ttree.close_win()'></td></tr>"+
+							    "</table>";
+		tree.appendChild(div_buttons);		
+
+		// Conf tree
+		var jo = document.createElement("DIV");
+		jo.id = "div_tree";
+		jo.style.position = "absolute";
+		jo.style.left = "10px";
+		jo.style.top = "20px";
+		jo.style.width = "420px";
+		jo.style.height = "215px";
+		jo.style.borderStyle = "outset";
+		jo.style.borderColor = "black";
+		jo.style.borderWidth = "2px";
+		jo.style.background  = "#F7F7F7";
+		jo.style.overflow    = "auto";
+		jo.innerHTML = "";
+		tree.appendChild(jo);
+
+		if(!expresso_offline)
+			ttree.make_tree(folders,"div_tree","folders_tree","ttree.get_folder(\"root\")","","root",false);
+		else
+			ttree.make_tree(folders,"div_tree","folders_tree","ttree.get_folder(\"local_root\")","","local_root",false);
+		_this.showWindow(tree);
+
+	}
+	
+	treeS.prototype.get_folder = function(param){
+		this.FOLDER = param;
+	}
+
+	treeS.prototype.showWindow = function (div){
+		if(! div) {
+			return;
+		}
+		
+		if(! this.arrayW[div.id]) {
+			div.style.width  = "580px";
+			div.style.height = "250px";
+			div.style.zIndex = "10000";			
+			var title = get_lang("Folder Management");
+			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.arrayW[div.id] = win;
+			win.draw();
+		}
+		else {
+			win = this.arrayW[div.id];
+		}
+		win.open();
+	}
+	
+	treeS.prototype.close_win = function(){
+	
+		this.FOLDER = "";
+		this.arrayW['window_tree'].close();
+	
+	}
+
+	treeS.prototype.make_tree = function (data,destination,name_tree, click_root, opentomb, selected,menu_folder){
+		//Somente para teste
+		//alert("data: " + data.length + "\n" + "destination : " + destination + "\n" + "name_tree : " + name_tree + "\n" + "click_root : " + click_root + "\n" + "opentomb : " + opentomb + "\n" + "selected : " + selected + "\n" + "menu_folder : " + menu_folder);
+			
+		if(Element('dftree_' + name_tree)){
+			Element('dftree_' + name_tree).innerHTML = '';
+		}
+		
+		folders_tree = new dFTree({name: name_tree});
+		if (!expresso_offline) {		
+			if(click_root != ""){
+				var n_root = new dNode({id:'root', caption:get_lang("My Folders"), onClick:click_root});
+			}else{
+				var n_root = new dNode({id:'root', caption:get_lang("My Folders")});		
+			}
+			folders_tree.add(n_root,'root'); //Places the root; second argument can be anything.
+	
+			if(data.length == 0){
+				alert("sem dados");
+				return false;
+			}
+		
+			for (var i=0; i<data.length; i++){
+				if(menu_folder){
+					if (data[i].folder_unseen > 0)
+						var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+data[i].folder_id+"','"+data[i].folder_name+"')", plusSign:data[i].folder_hasChildren}); 
+					else
+						var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name), onClick:"change_folder('"+data[i].folder_id+"','"+data[i].folder_name+"')", plusSign:data[i].folder_hasChildren}); 
+				}else{
+					var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name), plusSign:data[i].folder_hasChildren});
+				}
+	
+				if (data[i].folder_parent == '')
+					data[i].folder_parent = 'root';
+				else if (data[i].folder_parent == 'user'){
+					if (!tree_folders.getNodeById('user')){
+						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared Folders"), plusSign:true}); 
+						folders_tree.add(n_root_shared_folders,'root');
+					}
+				}
+				folders_tree.add(nn,data[i].folder_parent);
+			}
+		}
+		//Pastas locais
+		if (preferences.use_local_messages == 1) {
+			var n_root_local = new dNode({
+				id: 'local_root',
+				caption: get_lang("local messages"),
+				plusSign: true,
+                                onClick:"ttree.get_folder('local_root')"
+			});
+			folders_tree.add(n_root_local, 'root');
+			
+			var local_folders = expresso_local_messages.list_local_folders();
+			for (var i in local_folders) { //Coloca as pastas locais.
+			
+				var node_parent = "local_root";
+				var new_caption = local_folders[i][0];
+				if(local_folders[i][0].indexOf("/")!="-1") {
+					final_pos = local_folders[i][0].lastIndexOf("/");
+					node_parent = "local_"+local_folders[i][0].substr(0,final_pos);
+					new_caption = local_folders[i][0].substr(final_pos+1);
+				}
+				
+				if (local_folders[i][1] > 0) 
+					var nodeLocal = new dNode({
+						id: "local_" + local_folders[i][0],
+						caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
+						plusSign: local_folders[i][2]
+					});
+				else 
+					var nodeLocal = new dNode({
+						id: "local_" + local_folders[i][0],
+						caption: lang_folder(new_caption),
+						plusSign: local_folders[i][2]
+					});
+				folders_tree.add(nodeLocal, node_parent);
+			}
+		}
+		folders_tree.draw(Element(destination));
+		if(!expresso_offline)
+			n_root.changeState();
+		else
+			n_root_local.changeState();
+		if(opentomb != ""){folders_tree.openTo(opentomb);}
+		if(selected != "" && folders_tree.getNodeById(selected)){folders_tree.getNodeById(selected)._select();}
+
+	}
+
+/* Build the Object */
+	var ttree;
+	ttree = new treeS();
Index: trunk/expressoMail1_2/js/jscode/globals.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/globals.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/globals.js	(revision 2517)
@@ -0,0 +1,46 @@
+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 array_lang = new Array();
+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 height="16px" 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="templates/'+template+'/images/menu/createmail.gif">'+
+	'&nbsp;Novo</a>&nbsp;&nbsp;'+
+	'<a href="#" onclick="javascript:wfolders.makeWindow(\'\', \'change_folder\')" align=left>'+
+	'<img src="templates/'+template+'/images/menu/editfolders.png">'+
+	'&nbsp;Trocar Pasta</a>&nbsp;&nbsp'+	
+	'<a href="#" onclick="javascript:refresh();" align=left>'+
+	'<img src="templates/'+template+'/images/menu/checkmail.gif">'+
+	'&nbsp;Atualizar</a>&nbsp;&nbsp;'+
+	'<a id="link_tools" href="#" align=left>'+
+	'<img height="16px" src="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');
+
Index: trunk/expressoMail1_2/js/jscode/gears_init.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/gears_init.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/gears_init.js	(revision 2517)
@@ -0,0 +1,86 @@
+// Copyright 2007, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+//  1. Redistributions of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//  2. Redistributions in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//  3. Neither the name of Google Inc. nor the names of its contributors may be
+//     used to endorse or promote products derived from this software without
+//     specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Sets up google.gears.*, which is *the only* supported way to access Gears.
+//
+// Circumvent this file at your own risk!
+//
+// In the future, Gears may automatically define google.gears.* without this
+// file. Gears may use these objects to transparently fix bugs and compatibility
+// issues. Applications that use the code below will continue to work seamlessly
+// when that happens.
+
+(function() {
+  // We are already defined. Hooray!
+  if (window.google && google.gears) {
+    return;
+  }
+
+  var factory = null;
+
+  // Firefox
+  if (typeof GearsFactory != 'undefined') {
+    factory = new GearsFactory();
+  } else {
+    // IE
+    try {
+      factory = new ActiveXObject('Gears.Factory');
+      // privateSetGlobalObject is only required and supported on WinCE.
+      if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
+        factory.privateSetGlobalObject(this);
+      }
+    } catch (e) {
+      // Safari
+      if ((typeof navigator.mimeTypes != 'undefined')
+           && navigator.mimeTypes["application/x-googlegears"]) {
+        factory = document.createElement("object");
+        factory.style.display = "none";
+        factory.width = 0;
+        factory.height = 0;
+        factory.type = "application/x-googlegears";
+        document.documentElement.appendChild(factory);
+      }
+    }
+  }
+
+  // *Do not* define any objects if Gears is not installed. This mimics the
+  // behavior of Gears defining the objects in the future.
+  if (!factory) {
+    return;
+  }
+
+  // Now set up the objects, being careful not to overwrite anything.
+  //
+  // Note: In Internet Explorer for Windows Mobile, you can't add properties to
+  // the window object. However, global objects are automatically added as
+  // properties of the window object in all browsers.
+  if (!window.google) {
+    google = {};
+  }
+
+  if (!google.gears) {
+    google.gears = {factory: factory};
+  }
+})();
Index: trunk/expressoMail1_2/js/jscode/wfolders.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/wfolders.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/wfolders.js	(revision 2517)
@@ -0,0 +1,163 @@
+	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 */
+	var wfolders;
+	wfolders = new cWFolders();
Index: trunk/expressoMail1_2/js/jscode/filter.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/filter.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/filter.js	(revision 2517)
@@ -0,0 +1,752 @@
+
+	function charCounter(form)
+	{
+		if (form.value.length >= 300)
+		{
+			alert(get_lang("You have exceeded the number of allowed characters"));
+			return false;
+		}
+	}
+
+	function cfilter(){
+
+		this.mode_in   = "";
+		this.rulest		 = new Array;
+		this.rulesVoip	 = new Array;
+		this.out_officeR = "";
+		this.out_officeF = false;
+		this.email_deny  = new Array;
+		this.ac_form     = "";
+		this.ind		 = "";
+		this.email_deny  = new Array;
+		this.email_ld	 = "";
+		this.values = new Array("",
+					",checkBox1",
+					",select_size=1",
+					",checkBox1,select_size=1",
+					",select_rules=1",
+					",checkBox1,select_rules=1",				
+					",select_size=1,select_rules=1",				
+					",checkBox1,select_size=1,select_rules=1",
+					",checkBox2",				
+					",checkBox1,checkBox2",				
+					",checkBox2,select_size=1",
+					",ckeckBox1,checkBox2,select_size=1",
+					",checkBox2,select_rules=1",																				
+					",checkBox1,checkBox2,select_rules=1",				
+					",checkBox2,select_size=1,select_rules=1",				
+					",checkBox1,checkBox2,select_size=1,select_rules=1");
+		
+	}
+
+	
+	cfilter.prototype.load_rules = function()
+	{
+		var _this = this;
+		var cont1 = parseInt(0);
+		var cont2 = parseInt(0);
+				
+		if( _this.rulest.length == 0 )
+		{
+			var handler_sieve = function(data)
+			{
+				if(data.rule.length > 0){
+					for(var i=0 ; i < data.rule.length; i++)
+					{
+						var fields = data.rule[i].split("&&");
+						if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect )
+							_this.rulesVoip[cont1++] = data.rule[i];
+						else
+							_this.rulest[cont2++] = data.rule[i];
+					}
+				}
+				_this.out_officeR = data.vacation[0];
+				_this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
+				if(data.mode.length > 0){_this.mode_in = data.mode[0];}
+			}
+			if(Element('form_status') != null)
+				Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
+			cExecute("$this.ScriptS.init_a",handler_sieve);
+			_this.get_email();
+	    }
+	}
+	
+	cfilter.prototype.form_m = function(){
+		Element('form_body').innerHTML = "";
+		Element('form_buttons').style.display = '';
+		filters.mount_list();
+		this.ac_form = "";		
+	}
+	
+	cfilter.prototype.form_out = function(){
+		Element('form_body').innerHTML = "";
+		Element('form_body').innerHTML = this.forms_();
+		Element('div_vacation').style.display = "";
+		this.ac_form = "old_out";		
+		this.r_rules_out();		
+	}
+	
+	cfilter.prototype.form_r = function(pos,type)
+	{
+		Element('form_body').innerHTML = "";
+		Element('form_body').innerHTML = this.forms_();
+		this.ind = pos;		
+		
+		if( type === 'voip')
+		{
+			this.ac_form = "old_voip";
+			Element('div_voipFilter').style.display = "";
+			this.r_rules_form(pos, type);	
+		}
+		else
+		{
+			this.ac_form = "old_rule";
+			Element('div_rule').style.display = "";	
+			this.r_rules_form(pos, type);
+		}
+	}
+	
+	cfilter.prototype.get_email = function()
+	{
+		var _this = this;
+		var handler_get_email = function(data)
+		{
+			_this.email_ld = data ? data : "";
+		}
+		cExecute("$this.user.get_email",handler_get_email);
+	}
+	
+	cfilter.prototype.sel_boxes = function()
+	{
+		var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
+		if(document.getElementById("select_mailboxes") != null){
+			var sel_nm = document.getElementById("select_mailboxes");
+			if(sel_nm.length > 0 ){
+				for(var i=0; i < sel_nm.options.length; i++){
+					sel_nm.options[i] = null;
+					i--;
+				}
+			}
+			for(var i=0; i < nm_folders.length; i++){
+				if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){
+					var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
+					sel_nm[sel_nm.length] = opt;
+				}
+			}
+			sel_nm[0].selected = true;
+		}
+	}
+
+	cfilter.prototype.box_select = function(param){
+		var aux = this.BoxSelection[param].split(",");
+		var ele1 = document.getElementById(aux[0]);
+		var ele2 = document.getElementById(aux[1]);
+		var noption = "";
+		if(param == 0 || param == 1){
+			if(ele1.selectedIndex != -1){
+				noption = new Option(ele1.value,ele1.value,false,false);
+				ele2.options[ele2.length] = noption;
+				ele1.options[ele1.selectedIndex] = null;
+				ele1.selectedIndex = 0;
+			}
+		}
+	}
+
+	cfilter.prototype.r_rules_form = function(ind, type)
+	{
+		var fields = new Array;
+		var _this = this;
+		
+		// hide buttons
+		Element('form_buttons').style.display = 'none';
+		
+		if( type === 'voip')
+		{
+			fields = _this.rulesVoip[ind].split("&&");
+			document.getElementById("field9").value = fields[5];			
+		}
+		else
+		{
+			this.sel_boxes();
+			if(this.rulest.length == 0){
+				return false;
+			}
+			fields = _this.rulest[ind].split("&&");
+			document.getElementById("field1").value = fields[3];
+			document.getElementById("field2").value = fields[4];
+			document.getElementById("field3").value = fields[5];
+			document.getElementById("field4").value = fields[11];				
+			
+			switch(fields[6]){
+				case "folder":
+					document.getElementById("radio1").checked  = true;
+					var name_mb = fields[7];
+					var sel_mb = document.getElementById("select_mailboxes");
+					for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
+					break;
+				case "address":
+					document.getElementById("radio2").checked   = true;
+					document.getElementById("field5").value 	= fields[7];
+					break;
+				case "reject":
+					 document.getElementById("radio3").checked  = true;
+					 var text0 = fields[7].split("\\n");				 	
+					 for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
+					 break;
+				case "discard":
+					document.getElementById("radio4").checked 	= true;
+					break;
+			}
+			var mark_values = this.values[fields[8]].split(",");
+			for(var i=0; i < mark_values.length; i++){
+				if( mark_values[i] == "checkBox1" || mark_values[i] == "checkBox2"){
+					document.getElementById(mark_values[i]).checked = true;
+				}
+				if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
+					var mark_val = mark_values[i].split("=");
+					document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
+				}
+			}
+		}
+	}
+
+	cfilter.prototype.r_rules_out = function(){
+	
+		var _this = this;
+		if(_this.out_officeR.length == 0){
+			return false;
+		}
+		
+		// hide buttons
+		Element('form_buttons').style.display = 'none';
+	
+		var aux = _this.out_officeR.split("&&");
+		var days   = aux[1];
+		var emails = aux[2];
+		var mens   = aux[3];		
+		var p_emails = new Array;
+		var d_emails = new Array;
+				
+		var p_aux = emails.split(", ");
+		for(var i=0; i < p_aux.length; i++){
+			p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
+			p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
+		}
+		for(var i=0; i < _this.email_ld.length; i++){
+			d_emails[i] = _this.email_ld[i];
+		}
+
+		diff = function(vet, comp){
+			var sel1 = new Array;
+			for(var i=0; i < vet.length; i++){
+				for(var j=0; j < comp.length; j++){
+					if(vet[i] == comp[j]){
+						comp.splice(j,1);
+						j--;
+					}
+				}
+			}
+		};	
+		diff(p_emails,d_emails);
+		var text    = mens.split("\\n");
+		for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
+		for(var i=0; i < _this.email_ld.length; i++){
+			d_emails[i] = _this.email_ld[i];
+		}
+
+	}
+
+	/*
+	 * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição)
+	 * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada
+	 */
+	cfilter.prototype.disable_radio3 =  function()
+	{
+		radio3 = Element('radio3');
+		field6 = Element('field6');
+		cb2 = Element('checkBox2');
+
+		if (cb2.checked)
+		{
+			radio3.disabled = true;
+			field6.disabled = true;
+
+			if (radio3.checked)
+			{
+				radio3.checked = false;
+			}
+		}
+		else
+		{
+			radio3.disabled = false;
+			field6.disabled = false;
+		}
+
+	}
+
+	cfilter.prototype.forms_ = function()
+	{
+			 var form = "";
+				 form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
+						"<tr><td colspan='2'><input type='checkBox' id='checkBox1' name='checkb'>"+get_lang('Also check message against next rule') + "</td></tr>"+
+						"<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio3();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
+						"<tr><td colspan='2'><hr size='1' width='100%'></td></tr><tr>"+
+						"<td rowspan='4' width='20%'>"+get_lang('Coincident')+"<br><select id='select_rules' name='select_rules'>"+
+						"<option value='0'>"+get_lang("with all")+"</option><option value='1'>"+get_lang("with some")+"</option>"+
+						"</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+
+						"</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+
+						"</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+
+						"</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
+						"<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+						 
+						"</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
+						"</tr><tr><td colspan='2'><hr size='1' width='100%'></td></tr>"+
+						"</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
+						"<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
+						"<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
+						"</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
+						"<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
+						"</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
+						"<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
+						"</tr><tr><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
+						"</tr></table></div><div id='div_vacation' style='display:none'>"+
+						"<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
+ 						"<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
+						//"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
+						"<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
+	 					"</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>" +
+						"<div id='div_voipFilter' style='display:none'>" +
+						"<br/><table id='table_voipFilter'>" +
+						"<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+
+						"</td></tr><tr><td><input type='text' id='field9' size='50' maxlength='200'>" +
+						"</td></tr><br/></table></div>" +
+				 		"<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
+				 		"<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";
+		return form;
+	}
+
+	cfilter.prototype.enabled_disabled = function(param){
+
+		// Rules
+		if(Element("rule_0") != null){
+			for(var i=0; i < this.rulest.length; i++){
+				if(Element("rule_"+i).checked){
+					var aux_rul = this.rulest[i].split("&&");
+					if(aux_rul[2] != param){
+						aux_rul[2] = param;					
+						var rl = "";
+						for(var j=0; j < aux_rul.length; j++){
+							rl += aux_rul[j] + "&&";
+						}
+						rl = rl.substr(0,(rl.length - 2));
+						this.rulest[i] = rl;					
+					}
+				}
+			}
+		}
+		// Out Office
+		if(Element("out_0") != null){
+			if(Element("out_0").checked){
+				var aux_out = this.out_officeR.split("&&");
+				if(param == "ENABLED")
+					aux_out[4] = "on ";
+				else
+					aux_out[4] = "off";
+				var out = "";
+				for(var i=0; i < aux_out.length; i++){
+					out += aux_out[i] + "&&";
+				}				
+				out = out.substr(0,(out.length - 2));
+				this.out_officeR = out;
+			}
+		}
+
+		// Voip
+		if(Element("voip_rule_0") != null){
+			for(var i=0; i < this.rulesVoip.length; i++){
+				if(Element("voip_rule_"+i).checked){
+					var aux_rul = this.rulesVoip[i].split("&&");
+					if(aux_rul[2] != param){
+						aux_rul[2] = param;					
+						var rl = "";
+						for(var j=0; j < aux_rul.length; j++){
+							rl += aux_rul[j] + "&&";
+						}
+						rl = rl.substr(0,(rl.length - 2));
+						this.rulesVoip[i] = rl;					
+					}
+				}
+			}
+		}
+		
+		this.reload_rules();
+	}
+	
+	cfilter.prototype.new_rule = function(email){
+
+		if(this.email_deny.length > 0){
+			for(var i=0 ; i < this.email_deny.length; i++){
+				if(this.email_deny[i] == email){
+					alert(get_lang("Sender blocked")+"!");
+					return false;
+				}
+			}
+		}
+
+	    	if(!validateEmail(email)){
+			alert(get_lang("Inform a valid e-mail!"));
+			return false;
+		}
+
+		this.load_rules();
+		if(confirm(get_lang("Do you want to block this e-mail?"))){
+			new_r = "&&ENABLED&&" + email + "&&&&&&discard&&&&0&&&&&&0";
+//			setTimeout("filter.e_newrule('" + new_r + "')",2000);		
+			if (filter.e_newrule(new_r)){
+				this.email_deny.push(email);
+				write_msg(get_lang("The sender was blocked"));							
+			}else
+				write_msg(get_lang("You have reached the maximum number of rules"));
+		}
+	}
+	
+	cfilter.prototype.e_newrule = function(nw_rule)
+	{
+
+		var new_rl = "";
+		if (this.rulest.length >= rules_limit)
+			return false;
+			
+		if(this.rulest.length == 0){
+			new_rl = "#rule&&1" + nw_rule;
+		}else{
+			var aux = this.rulest[this.rulest.length -1 ].split("&&");
+			new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
+		}
+		this.rulest.push(new_rl);
+		this.saved_all();
+		return true;
+	}
+	
+	cfilter.prototype.delete_r = function(){
+	
+		// rule
+		var _this = this;
+		if(Element("rule_0") != null){
+			for(var i=0; i < _this.rulest.length; i++){
+				if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
+			}
+			for(var i=0; i < _this.rulest.length; i++){
+				if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
+			}
+		}
+	
+		if(_this.rulest.length > 0){
+			var cont = parseInt(1);
+			for(var i=0; i < _this.rulest.length ; i++){
+				var n_rulest = _this.rulest[i].split("&&");
+				n_rulest[1] = cont;
+				cont = cont + parseInt(2);
+				var aux = "";
+				for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
+				aux = aux.substr(0,(aux.length - 2));
+				_this.rulest[i] = aux;
+			}
+		} 
+		// out office
+		if(Element("out_0") != null){
+			if(Element("out_0").checked){
+				_this.out_officeR ='';
+				_this.out_officeF = false;
+				//Save outoffice in prefs:
+				expresso.connector.loadScript("jscode/preferences");
+				prefe.save("outoffice", _this.out_officeF);
+			}
+		}
+		
+		// Voip
+		if(Element("voip_rule_0") != null){
+			for(var i=0; i < _this.rulesVoip.length; i++){
+				if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
+			}
+			for(var i=0; i < _this.rulesVoip.length; i++){
+				if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
+			}
+		}
+	
+		if(_this.rulesVoip.length > 0){
+			var cont = parseInt(1);
+			for(var i=0; i < _this.rulesVoip.length ; i++){
+				var n_rulest = _this.rulesVoip[i].split("&&");
+				n_rulest[1] = cont;
+				cont = cont + parseInt(2);
+				var aux = "";
+				for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
+				aux = aux.substr(0,(aux.length - 2));
+				_this.rulesVoip[i] = aux;
+			}
+		} 
+
+		_this.reload_rules();
+	}
+	
+	cfilter.prototype.reload_rules = function()
+	{
+		this.saved_all();
+		Element('form_body').innerHTML = "";
+		this.load_rules();
+
+		if(this.out_officeF)
+		{
+			write_msg(get_lang("Attention, you are in out of office mode."), true);
+		}else{
+			clean_msg();
+			this.out_officeF = false;
+		}
+		filters.mount_list();
+	}
+
+	cfilter.prototype.saved_rules = function(){
+
+		var mount_rule = "";
+		var form = this.ac_form.split("_");
+		var n_rule = "";
+
+		if(form[1] == "rule")
+		{
+			mount_rule = "#rule&&";
+			if(form[0] == "new")
+			{
+				n_rule = "1&&";
+				if(this.rulest.length > 0)
+				{
+					aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
+					n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
+				}
+				mount_rule += n_rule + "ENABLED&&";
+			}
+			else
+			{
+				n_rule = this.rulest[this.ind].split("&&");
+				mount_rule += n_rule[1] + "&&";
+				mount_rule += n_rule[2] + "&&";
+			}
+
+			if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "")
+			{
+				alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
+				return false;
+			}
+
+			if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){
+				alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
+				return false;
+			}
+			
+			for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";} 
+			var v_checked = false;
+			if(Element("radio1").checked){
+				mount_rule += "folder&&";
+				var sel_nameBox = Element("select_mailboxes");
+				for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
+				v_checked = true;
+			}
+			if(Element("radio2").checked){
+				mount_rule += "address&&";
+				if(Element("field5").value == ""){
+					alert(get_lang("Inform a forwarding e-mail!"));
+					return false;
+				}else{
+					var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
+			    	if(emailReg.test(Element("field5").value)){
+						mount_rule += Element("field5").value + "&&";
+					}else{
+						alert(get_lang("Inform a valid e-mail!"));
+						return false;
+					}
+				}
+				v_checked = true;
+			}
+			if(Element("radio3").checked){
+				mount_rule += "reject&&";
+				if(Element("field6").value == ""){
+					alert(get_lang("Inform a text for rejection!"));
+					return false;
+				}else{
+					mount_rule += Element("field6").value + "&&";
+				}
+				v_checked = true;
+			}				
+			if(Element("radio4").checked){
+				mount_rule += "discard&&&&";
+				v_checked = true;
+			}
+			if(!v_checked){
+				alert(get_lang("No option marked!"));
+				return false;
+			}
+			var opts = "";
+			if(Element("checkBox1").checked == true){opts += ",checkBox1";}
+			if(Element("checkBox2").checked == true){opts += ",checkBox2";}
+			if(Element("select_size").options[1].selected == true){opts += ",select_size=1";}
+			if(Element("select_rules").options[1].selected == true){opts += ",select_rules=1";}
+			for(var i=0; i < this.values.length; i++){if(this.values[i] == opts){mount_rule += i + "&&";}}
+			mount_rule += "&&&&";
+			if(LTrim(Element("field4").value) != ""){
+				mount_rule += LTrim(Element("field4").value);
+			}else{
+				mount_rule += 0;
+			}
+			if(form[0] == "new")
+			{
+				this.rulest[this.rulest.length] = mount_rule;
+			}
+			else
+				this.rulest[this.ind] = mount_rule;
+		}
+		else if(form[1] == "out")
+		{
+			mount_rule = "";
+			var fld_emails = this.email_ld; // Get first email of list!
+			var fld_men	   = Element("field8");
+			mount_rule = "#vacation&&";
+			mount_rule += "1&&";
+			mount_rule += "\"" + fld_emails + "\", ";			
+			mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
+			mount_rule += "&&";
+			mount_rule += fld_men.value + "&&on";
+			if(LTrim(fld_men.value) == ""){
+				alert(get_lang("Inform a message!"));
+				return false;
+			}
+			this.out_officeR = mount_rule;
+		}
+		else if(form[1] == "voip")
+		{
+			if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
+			{
+				mount_rule = "#rule&&";
+				if(form[0] == "new")
+				{
+					n_rule = "1&&";
+					if( this.rulesVoip.length > 0 )
+					{
+						aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
+						n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
+					}
+					mount_rule += n_rule + "ENABLED&&";
+				}
+				else
+				{
+					n_rule = this.rulesVoip[this.ind].split("&&");
+					mount_rule += n_rule[1] + "&&";
+					mount_rule += n_rule[2] + "&&";
+				}
+
+				if ( Element("field9").value.indexOf("#") >= 0 )
+				{
+					alert(get_lang('Caracter "#" is not allowed!'));
+					return false;
+				}
+				
+				mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
+
+				if( form[0] == "new" )
+				{
+					this.rulesVoip[this.rulesVoip.length] = mount_rule;
+				}
+				else
+				{
+					this.rulesVoip[this.ind] = mount_rule;
+				}
+			}
+			else
+			{
+				alert( 'CAMPOS EM BRANCO !!' );
+				return false;
+			}
+		}
+		
+		Element('form_buttons').style.display = '';
+		this.reload_rules();
+	}
+
+	cfilter.prototype.close_frm= function()
+	{
+		filters.filter_Sh['window_ffilter_ccform'].close();
+	}
+	
+	cfilter.prototype.saved_all = function()
+	{
+		var aux_rul = "";
+		var _this = this;
+		var cont = 0;
+		
+		// Regras Gerais
+		if(_this.rulest.length > 0)
+		{
+			for(var i=0; i < _this.rulest.length; i++)
+			{
+				var fieldsNormal = _this.rulest[i].split("&&");				
+				aux_rul += "_begin_##";
+				for(var j=0 ; j < fieldsNormal.length; j++)
+				{
+					aux_rul += url_encode(fieldsNormal[j]) + "##";
+					cont = parseInt(fieldsNormal[1]);					
+				}	
+				aux_rul += "_end_\n";
+			}
+		}
+	
+		// Voip
+		if(_this.rulesVoip.length > 0)
+		{
+			for(var i=0; i < _this.rulesVoip.length; i++)
+			{
+				var fieldsVoip = _this.rulesVoip[i].split("&&");
+				aux_rul += "_begin_##";
+				for(var j=0 ; j < fieldsVoip.length; j++)
+				{
+					if(j == 1)
+					{
+						if( cont == 0 )
+							cont = parseInt(1);
+						else
+							cont = parseInt(cont) + parseInt(2);
+						aux_rul += cont;
+						aux_rul += "##";
+					}
+					else
+						aux_rul += url_encode(fieldsVoip[j]) + "##";
+				}
+				aux_rul += "_end_\n";
+			}
+		}
+		
+		// Fora do Escritório
+		if(_this.out_officeR.length > 0)
+		{
+				var aux = _this.out_officeR.split("&&");				
+				aux_rul += "_begin_##";
+				for(var j=0 ; j < aux.length; j++)
+				{
+					aux_rul += url_encode(aux[j]) + "##";					
+				}	
+				aux_rul += "_end_\n";
+				_this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
+				//Save outoffice in prefs:
+				expresso.connector.loadScript("jscode/preferences");
+				prefe.save("outoffice", _this.out_officeF);
+		}
+		
+		var h_filter = function(data)
+		{
+			if(data != "Ok"){alert("Erro : \n" + data);}
+		}
+		var args   = "$this.ScriptS.rec_rules";
+		var params = "arfilter="+aux_rul;
+		cExecute(args,h_filter,params);
+	}
+
+// build object
+   var filter;
+   filter = new cfilter();
Index: trunk/expressoMail1_2/js/jscode/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/draw_api.js	(revision 2517)
@@ -0,0 +1,3088 @@
+ 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
+
+// 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 draw_tree_folders(folders){
+	// Check if the tree folders alredy exist.
+        translatedFolders = new Map();
+	if (Element('dftree_tree_folders')){
+		if (!expresso_offline) {
+			var update_tree_folders = function(data){
+				build_quota(data);
+				var unseen_in_mailbox = 0;
+				var unseen_in_shared_folders = 0;
+				for (var i=0; i<data.length; i++){
+					if ( data[i].folder_unseen > 0 )
+					{
+						unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
+						if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+							unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
+					}
+	
+					var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
+					
+					if ((folder_unseen) && (data[i].folder_unseen > 0))
+					{
+						folder_unseen.innerHTML = data[i].folder_unseen;
+					}
+					else if (data[i].folder_unseen > 0)
+					{
+						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
+						tree_folders.getNodeById(data[i].folder_id)._refresh();
+					}
+					else if (data[i].folder_unseen <= 0)
+					{
+						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name)});
+						tree_folders.getNodeById(data[i].folder_id)._refresh();
+					}
+
+					if(data[i].folder_id == current_folder){					
+						var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
+	//					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
+	//						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
+	//					}
+						Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
+						draw_paging(Element('tot_m').innerHTML);
+					}
+				}
+
+				var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+				//if ( unseen_in_mailbox )
+				//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
+				//else
+					display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
+				display_unseen_in_mailbox._refresh();
+	
+				var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
+				if ( display_unseen_in_shared_folders )
+				{
+					if ( unseen_in_shared_folders )
+						display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
+					else
+						display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
+					display_unseen_in_shared_folders._refresh();
+				}
+			}
+			expresso.connector.cacheNextRequest(1);
+			cExecute ("expressoMail1_2.imap_functions.get_folders_list&folder=INBOX", update_tree_folders);
+		}
+	
+		return;
+	}
+	else{
+		if (!expresso_offline) {
+			tree_folders = new dFTree({name: 'tree_folders'});
+	
+			var n_root = new dNode({id:'root', caption: get_lang("My Folders")});
+			tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
+	
+			var unseen_in_mailbox = 0;
+			var unseen_in_shared_folders = 0;
+			for (var i=0; i<folders.length; i++){
+				if (folders[i].folder_unseen > 0)
+				{
+					unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
+					if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+						unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
+
+					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+				
+					if( folders[i].folder_name.toLowerCase() == 'inbox' )
+						Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
+				}
+				else
+					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+				
+				if (folders[i].folder_parent == '')
+					folders[i].folder_parent = 'root';
+				else if (folders[i].folder_parent == 'user'){	
+					
+					if (!tree_folders.getNodeById('user')){
+                                                tmpFolderId = folders[i].folder_id.split(cyrus_delimiter).pop();
+                                                if (tmpFolderId != folders[i].folder_name)
+                                                {
+                                                    translatedFolders.add(tmpFolderId, folders[i].folder_name);
+                                                }
+						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared folders"), plusSign:true}); 
+						tree_folders.add(n_root_shared_folders,'root');
+					}
+				}
+				tree_folders.add(nn,folders[i].folder_parent);
+			}
+		}
+		//tree_local_folders = new dFTree({name: 'tree_local_folders'});
+		/**
+		 * Pastas locais
+		 */
+		if (preferences.use_local_messages==1 || expresso_offline) {
+			if (!window.google || !google.gears) {
+				if (!expresso_local_messages.installGears())
+					preferences.use_local_messages=0;
+			}
+			else{
+				if (!window.google || !google.gears) {
+				temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
+				if (temp) {
+					location.href = "http://gears.google.com/?action=install&message="+
+					"Para utilizar o recurso de mensagens locais, instale o google gears&return=" +
+					document.location.href;
+				}
+				else {
+					preferences.use_local_messages=0;
+				}
+			}
+			else{
+				if (expresso_offline) 
+					tree_folders = new dFTree({
+						name: 'tree_folders'
+					});
+				var root_local = new dNode({
+					id: "local_root",
+					caption: get_lang('local folders')
+				});
+				tree_folders.add(root_local, "root"); //coloca root local
+				var local_folders = expresso_local_messages.list_local_folders();
+				for (var i in local_folders) { //Coloca as pastas locais.
+					var node_root = "local_root";
+					var new_caption = local_folders[i][0];
+					if (local_folders[i][0].indexOf("/") != "-1") {
+						final_pos = local_folders[i][0].lastIndexOf("/");
+						node_root = "local_" + local_folders[i][0].substr(0, final_pos);
+						new_caption = local_folders[i][0].substr(final_pos + 1);
+					}
+					if (local_folders[i][1] > 0) 
+						var nodeLocal = new dNode({
+							id: "local_" + local_folders[i][0],
+							caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
+							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
+							plusSign: local_folders[i][2]
+						});
+					else 
+						var nodeLocal = new dNode({
+							id: "local_" + local_folders[i][0],
+							caption: lang_folder(new_caption),
+							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
+							plusSign: local_folders[i][2]
+						});
+						tree_folders.add(nodeLocal, node_root);
+					}
+				}
+			}		
+		}
+
+		tree_folders.draw(Element('content_folders'));
+		if (!expresso_offline) {
+			n_root.changeState();
+			folder_select = (current_folder ? current_folder:"INBOX");
+			if (typeof(tree_folders.getNodeById(folder_select)) == 'undefined')
+				return false;
+			tree_folders.getNodeById(folder_select)._select();
+		}
+		else {
+			root_local.changeState();
+			tree_folders.getNodeById('local_Inbox')._select();
+		}
+
+		var trash_span=document.getElementById('lINBOX/'+trashfolder+'tree_folders');
+		var draft_span=document.getElementById('lINBOX/'+draftsfolder+'tree_folders');
+		var sent_span=document.getElementById('lINBOX/'+sentfolder+'tree_folders');
+		var spam_span=document.getElementById('lINBOX/'+spamfolder+'tree_folders');
+
+		if (trash_span)
+			trash_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_trash.png)";
+
+		if (draft_span)
+			draft_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_draft.png)"
+
+		if (sent_span)
+			sent_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_sent.png)";
+
+		if (spam_span)
+			spam_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_spam.png)";
+
+
+		draw_paging(Element('tot_m').innerHTML);
+		if(document.getElementById("nINBOX/"+trashfolder+"tree_folders"))
+		{
+			var trash = document.createElement("SPAN");
+			trash.id = 'empty_trash';
+			trash.className = 'clean_folder';
+			trash.style.cursor = 'pointer';
+			trash.onclick = function () {empty_trash_imap();};
+			trash.innerHTML = "["+get_lang("Clean")+"]";
+			trash.title=get_lang("Empty trash");
+			trash.onmouseover = function() {trash.style.color="red";};
+			trash.onmouseout= function() {trash.style.color="#666666";};
+			document.getElementById("nINBOX/"+trashfolder+"tree_folders").appendChild(trash);
+		}
+		if(document.getElementById("nINBOX/"+spamfolder+"tree_folders"))
+		{
+                        var spam = document.createElement("SPAN");
+                        spam.id = 'empty_spam';
+                        spam.className = 'clean_folder';
+                        spam.style.cursor = 'pointer';
+                        spam.style.padding = '0 0 0 6px';
+                        spam.onclick = function () {empty_spam_imap();};
+                        spam.innerHTML = "["+get_lang("Clean")+"]";
+                        spam.title=get_lang("Empty Spam Folder");
+                        spam.onmouseover = function() {spam.style.color="red";};
+                        spam.onmouseout= function() {spam.style.color="#666666";};
+                        document.getElementById("nINBOX/"+spamfolder+"tree_folders").appendChild(spam);
+               }
+
+		// Draw right menu folders.
+		/*
+		var treeroot = document.getElementById('chroottree_folders'); 
+		for (var linkBox = treeroot.firstChild; linkBox != null; linkBox = linkBox.nextSibling)
+			_dragArea.makeMenuBox(linkBox);
+		*/
+
+		if(!expresso_offline)
+			var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+		else
+			var display_unseen_in_mailbox = tree_folders.getNodeById( 'local_root' );
+		//if ( unseen_in_mailbox )
+		//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
+		//else
+			display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
+		display_unseen_in_mailbox._refresh();
+
+		var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
+		if ( display_unseen_in_shared_folders )
+		{
+			if ( unseen_in_shared_folders )
+				display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
+			else
+				display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
+			display_unseen_in_shared_folders._refresh();
+		}
+	}
+
+	if (!expresso_offline) {
+		var folder_create = "";
+		var nm1 = "";
+		if(tree_folders._folderPr.length > 0){
+			var nm_folder = "";
+			for(var i=0; i < tree_folders._folderPr.length; i++){
+				nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
+				if(nm_folder[0] == "INBOX"){
+					if(nm1 == ""){
+						nm1 = nm_folder[1];
+						folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+					}else{
+						if( nm1 != nm_folder[1]){
+							folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+							nm1 = nm_folder[1];
+						}
+					}
+				}
+			}
+		}
+		if(folder_create != ""){
+			if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
+				var handler_correct_folders = function(data){
+					//Timeout to release HTTPRequest , loadScript and update tree folders.
+					if(data)
+						setTimeout("expresso.connector.loadScript('jscode/TreeShow');ttreeBox.update_folder();",500);
+				}
+				cExecute("expressoMail1_2.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
+			}
+		}
+	}
+}
+
+function draw_tree_local_folders() {
+	/**
+	 * Pastas locais
+	 */
+	if(preferences.use_local_messages==1 || expresso_offline) {
+		var local_folders = expresso_local_messages.list_local_folders();
+		var has_changes = false;
+		for (var i in local_folders) { //Coloca as pastas locais.
+			
+			var new_caption = local_folders[i][0];
+			if(local_folders[i][0].indexOf("/")!="-1") {
+				final_pos = local_folders[i][0].lastIndexOf("/");
+				new_caption = local_folders[i][0].substr(final_pos+1);
+			}
+			
+			var folder_unseen = Element('dftree_local_'+local_folders[i][0]+'_unseen');
+			
+			if ((folder_unseen) && (local_folders[i][1] > 0))
+			{
+				folder_unseen.innerHTML = local_folders[i][1];
+				has_changes = true;
+			}
+			else if (local_folders[i][1] > 0)
+			{
+				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="dftree_local_'+local_folders[i][0]+'_unseen" style=color:red>'+local_folders[i][1]+'</span><font style=color:red>)</font>'});
+				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
+				has_changes = true;
+			}
+			else if (local_folders[i][1] <= 0)
+			{
+				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption)});
+				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
+				has_changes = true;
+			}
+
+			if("local_"+local_folders[i][0] == get_current_folder()){					
+				var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
+				if(!isNaN(old_new_m) && old_new_m < local_folders[i][1]){
+					Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(local_folders[i][1])-old_new_m);
+				}
+				Element('new_m').innerHTML = local_folders[i][1] ? '<font color="RED">'+local_folders[i][1]+'</font>' : 0;
+				draw_paging(Element('tot_m').innerHTML);
+				has_changes = true;
+			}
+		}
+		if(has_changes)
+			tree_folders.getNodeById("local_root").open();
+
+	}	
+}
+
+function 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', '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(data, 'INBOX', true);
+	//alternate_border(0);
+}
+
+// Action on change folders.
+function change_folder(folder, folder_name){
+	if (openTab.imapBox[0] != folder)
+	{
+		current_folder = folder;
+		var handler_draw_box = function(data)
+		{
+			alternate_border(0);
+			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
+			draw_box(data, folder, true);
+			draw_paging(data.num_msgs);
+			Element("tot_m").innerHTML = data.num_msgs;
+			update_menu();
+			return true;
+		}
+		proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
+//		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
+	}
+	else
+		alternate_border(0);
+}
+
+function open_folder(folder, folder_name){
+	if (current_folder!= folder) {
+		current_folder = folder;
+		var handler_draw_box = function(data){
+			numBox++;
+			create_border(folder_name,numBox.toString());
+			draw_box(data, current_folder, false);
+			alternate_border(numBox);
+			return true;
+		}
+		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
+	}
+	else
+		alternate_border(numBox);
+	return true;
+}
+
+var lastPage = 1;
+var numPages = 5;
+var last_folder = 'INBOX';
+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";
+		document.getElementById("div_menu_c3").appendChild(span_paging);	
+	}
+	span_paging.style.width="100%";		  	 		
+  	span_paging.innerHTML="";
+  	msg_range_begin = 1;
+	msg_range_end = preferences.max_email_per_page;
+  	if(current_page != 1) {
+	  	lnk_page = document.createElement("A");
+		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+  	}
+  	else {
+  	 	lnk_page = document.createElement("SPAN");
+  	}
+  	span_paging.appendChild(lnk_page);
+
+  	lnk_page.innerHTML = "&lt;&lt;";
+	lnk_page.title = get_lang("First");
+  	span_paging.innerHTML += "&nbsp;";
+  		
+  	if(current_page == lastPage + numPages)
+  		lastPage = current_page - 1;  		
+  	else if((lastPage != 1 && lastPage == current_page) || current_page == total_pages)  		
+  		lastPage = current_page - (numPages - 1);
+  	else if(current_page == 1)
+  	 	lastPage = 1;
+
+	if(lastPage < 1)
+		lastPage = 1;
+	else if(lastPage > 1 && (lastPage > (total_pages -(numPages - 1))))
+		lastPage = total_pages -(numPages - 1);
+
+	var	hasMarked = false;
+
+  	for(i = lastPage; i <= total_pages; i++) {
+  			
+  		if(current_page == i || (i == total_pages && !hasMarked)) {	  		
+  			lnk_page = document.createElement("SPAN");
+  			span_paging.appendChild(lnk_page);
+  			lnk_page.innerHTML = "&nbsp;<b>"+i+"</b>&nbsp;";
+  			hasMarked = true;
+  			continue;
+  		}
+  		else{	  		
+  			lnk_page = document.createElement("A");
+  			span_paging.appendChild(lnk_page);
+  			msg_range_begin = ((i*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
+			msg_range_end = (i*preferences.max_email_per_page);
+			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+  		}
+  		
+  		lnk_page.innerHTML = "&nbsp;...&nbsp;";
+  		
+  		if(i == (lastPage + numPages))
+  				break;	  		
+  		else if(lastPage == 1 || i != lastPage)	  			  			
+  			lnk_page.innerHTML = "&nbsp;"+i+"&nbsp;";
+  		
+  		span_paging.innerHTML += "&nbsp;";	  			  			  			  			  			  			  		
+  	}
+  	
+ 	if(current_page != total_pages) {
+  		lnk_page = document.createElement("A");
+  		msg_range_begin = ((total_pages*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
+		msg_range_end = (total_pages*preferences.max_email_per_page);  		
+		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
+	}
+	else {
+		lnk_page = document.createElement("SPAN");
+	}
+  	span_paging.innerHTML += "&nbsp;";
+  	span_paging.appendChild(lnk_page);
+
+	lnk_page.title = get_lang("Last");
+  	lnk_page.innerHTML = "&gt;&gt;";
+}
+
+
+// Draw the inbox and another folders
+function draw_box(headers_msgs, msg_folder, 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.imapBox[numBox] = msg_folder;
+	openTab.type[numBox] = 0;
+	
+	table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
+	if (table_message_header_box == null){
+		var table_element = document.createElement("TABLE");
+		var tbody_element = document.createElement("TBODY");
+		table_element.setAttribute("id", "table_message_header_box_"+numBox);
+		table_element.className = "table_message_header_box";
+		
+		tr_element = document.createElement("TR");
+		tr_element.className = "message_header";
+		td_element1 = document.createElement("TD");
+		td_element1.setAttribute("width", "1%");
+		chk_box_element = document.createElement("INPUT");
+		chk_box_element.id  = "chk_box_select_all_messages";
+		chk_box_element.setAttribute("type", "checkbox");
+		chk_box_element.className = "checkbox";
+		chk_box_element.onclick = function(){select_all_messages(this.checked);};
+		chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
+		chk_box_element.onkeydown = function (e){
+			if (is_ie)
+			{
+				if ((window.event.keyCode) == 46)
+					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+			else
+			{
+				if ((e.keyCode) == 46)
+					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		};
+		
+		td_element1.appendChild(chk_box_element);
+		
+		td_element2 = document.createElement("TD");
+		td_element2.setAttribute("width", "7%");
+		td_element3 = document.createElement("TD");
+		td_element3.setAttribute("width", "29%");
+		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
+		td_element3.id = "message_header_SORTFROM_"+numBox;
+		td_element3.align = "left";
+		td_element3.innerHTML = get_lang("Who");
+		
+		td_element4 = document.createElement("TD");
+		td_element4.setAttribute("width", "38%");
+		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
+		td_element4.id = "message_header_SORTSUBJECT_"+numBox;
+		td_element4.align = "left";
+		td_element4.innerHTML = get_lang("Subject");
+	
+		td_element5 = document.createElement("TD");
+		td_element5.setAttribute("width", "14%");
+		td_element5.onclick = function () {sort_box(search_box_type,'SORTARRIVAL');};
+		td_element5.id = "message_header_SORTARRIVAL_"+numBox;
+		td_element5.align = "center";
+		td_element5.innerHTML = get_lang("Date");
+		td_element6 = document.createElement("TD");
+		td_element6.setAttribute("width", "14%");
+		td_element6.onclick = function () {sort_box(search_box_type,'SORTSIZE');}
+		td_element6.id = "message_header_SORTSIZE_"+numBox;
+		td_element6.align = "left";
+		td_element6.innerHTML = get_lang("Size");
+		
+		tr_element.appendChild(td_element1);
+		tr_element.appendChild(td_element2);		
+		var td_element21 = document.createElement("TD");
+		td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
+		var td_element22 = document.createElement("TD");
+		td_element22.innerHTML = "&nbsp;&nbsp;&nbsp;";
+		var td_element23 = document.createElement("TD");
+		td_element23.innerHTML = "&nbsp;&nbsp;";
+		tr_element.appendChild(td_element21);
+		tr_element.appendChild(td_element22);
+		tr_element.appendChild(td_element23);
+		tr_element.appendChild(td_element3);
+		tr_element.appendChild(td_element4);
+		tr_element.appendChild(td_element5);
+		tr_element.appendChild(td_element6);
+		tbody_element.appendChild(tr_element);
+		table_element.appendChild(tbody_element);
+		openTab.content_id[numBox].appendChild(table_element);
+	}
+	draw_header_box();
+	var table_element = document.createElement("TABLE");
+	var tbody_element = document.createElement("TBODY");	
+	table_element.id = "table_box";
+	table_element.className = "table_box";
+	table_element.borderColorDark = "#bbbbbb";
+	table_element.frame = "void";
+	table_element.rules = "rows";
+	table_element.cellPadding = "0";
+	table_element.cellSpacing = "0";
+	
+	table_element.onkeydown = function (e){
+		if (is_ie)
+		{
+			if ((window.event.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+		else
+		{
+			if ((e.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+	};
+	if (is_ie)
+		table_element.style.cursor = "hand";
+	
+	tbody_element.setAttribute("id", "tbody_box");
+	table_element.appendChild(tbody_element);
+	
+	var _divScroll = document.getElementById("divScrollMain_"+numBox);
+
+	var bar = document.getElementById("toolbar");
+	var offset = 0;
+
+	if(!_divScroll){		
+		_divScroll = document.createElement("DIV");
+		_divScroll.id = "divScrollMain_"+numBox;
+	}
+	
+	_divScroll.style.overflowY = "auto";								
+	_divScroll.style.overflowX = "hidden";
+	_divScroll.style.width	="100%";
+	
+	if (is_mozilla){
+		_divScroll.style.overflow = "-moz-scrollbars-vertical";
+		_divScroll.style.width	="99.3%";
+	}
+	// Inicio: Redimensiona DIV SCROLL
+	var bar = Element("toolbar");
+	var offset = 0;
+	if(bar.style.visibility != 'hidden') 
+		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);		
+	var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
+	var defaultHeight = screenHeight - offset;		
+	_divScroll.style.height 	= defaultHeight - 110;
+	Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
+	// Fim: Redimensiona DIV SCROLL
+	_divScroll.appendChild(table_element);
+	openTab.content_id[numBox].appendChild(_divScroll);
+	
+	var f_unseen = 0;
+
+		if (headers_msgs.num_msgs == 0){
+			td_info = document.createElement("H3");
+			td_info.setAttribute("height", "25%");
+			td_info.setAttribute("background", "#FFF");
+			td_info.setAttribute("id", "msg_info");
+			td_info.align = "center";
+			td_info.innerHTML = get_lang("This mail box is empty");
+			tbody_element.appendChild(td_info);
+		}
+	
+	
+	for (var i=0; i < headers_msgs.length; i++){
+			if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
+				f_unseen++;				
+			tr_element = this.make_tr_message(headers_msgs[i], msg_folder);
+			if (tr_element){
+				tbody_element.appendChild(tr_element);
+				add_className(tr_element, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');				
+			}
+			_dragArea.makeDragged(tr_element, headers_msgs[i].msg_number, headers_msgs[i].subject, true);
+	}
+	
+	if ((preferences.use_shortcuts == '1') && (headers_msgs[0]))
+		select_msg(headers_msgs[0].msg_number, 'null', true);
+
+	var tdFolders  =  Element("folderscol");
+	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
+	if ( !currentTab )
+		alternate_border(numBox);
+	draw_footer_box(headers_msgs.num_msgs);	
+	Element('main_table').style.display = '';
+	if(debug) {
+		var _eTime = new Date();
+		_eTime = _eTime.getTime();
+		alert("Carregou em "+(_eTime - _bTime)+" ms");
+	}
+	var msg_folder = Element('msg_folder').value;
+	var msg_number = Element('msg_number').value;	
+	if(!msg_folder && msg_number) {
+		new_message('new','null');
+	}
+	else if(msg_folder && msg_number){
+		expresso.connector.cacheNextRequest();
+		cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), show_msg);
+		Element('msg_folder').value = '';
+		Element('msg_number').value = '';
+	}
+
+	if(!is_ie) {
+		var scripts = new Array("jscode/ccQuickAdd",
+							"jscode/color_palette",
+							"jscode/filter",
+							"jscode/filters",
+							"jscode/html2xhtml",
+							"jscode/preferences",
+							"jscode/QuickCatalogSearch",
+							"jscode/QuickSearchUser",
+							"jscode/rich_text_editor",
+							"jscode/sharemailbox",
+							"jscode/search",
+							"jscode/TreeS",
+							"jscode/TreeShow");
+							
+		expresso.connector.loadAllScripts(scripts);
+	}
+	// Loading Quota View Folder Component (if exists...)
+	if(Element("table_quota"))
+		expresso.connector.loadScript("jscode/InfoQuota");	
+}
+
+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 = document.createElement("TD");
+		td_element1.className = "td_msg";
+		td_element1.setAttribute("width", "1%");
+		chk_box_element = document.createElement("INPUT");
+		chk_box_element.setAttribute("type", "checkbox");
+		chk_box_element.className = "checkbox";
+		chk_box_element.setAttribute("id", "check_box_message_"+headers_msgs.msg_number);
+		chk_box_element.onclick = function(e){
+			if (is_ie)
+				changeBgColor(window.event,headers_msgs.msg_number);
+			else
+				changeBgColor(e,headers_msgs.msg_number);
+		};
+		td_element1.appendChild(chk_box_element);
+		
+		td_element2 = document.createElement("TD");
+		td_element2.className = "td_msg";
+		td_element2.setAttribute("width", "2%");
+		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)
+			td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(headers_msgs.attachment.names) + "'>";			
+			
+		td_element21 = document.createElement("TD");
+		td_element21.className = "td_msg";
+		td_element21.setAttribute("width", "1%");
+		td_element21.id = "td_message_answered_"+headers_msgs.msg_number;
+
+		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {
+			attach_name = headers_msgs.attachment.names.split(", ");
+			for(var item in attach_name)
+			{
+				if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){
+					td_element21.innerHTML = "<img src ='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 ='templates/"+template+"/images/forwarded.gif' title='"+get_lang('Forwarded')+"'>";
+			headers_msgs.Draft = '' 
+			headers_msgs.Answered = '';
+			headers_msgs.Forwarded = 'F';
+		}
+		else if (headers_msgs.Draft == 'X')
+			td_element21.innerHTML = "<img src ='templates/"+template+"/images/draft.gif' title='"+get_lang('Draft')+"'>";
+		else if (headers_msgs.Answered == 'A')
+			td_element21.innerHTML = "<img src ='templates/"+template+"/images/answered.gif' title='"+get_lang('Answered')+"'>";
+		else
+			td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
+
+		td_element22 = document.createElement("TD");
+		td_element22.className = "td_msg";
+		td_element22.setAttribute("width", "1%");
+		td_element22.id = "td_message_signed_"+headers_msgs.msg_number;
+
+        //td_element23 = document.createElement("TD");
+		//td_element23.setAttribute("width", "1%");
+		//td_element23.id = "td_message_signed_"+headers_msgs.msg_number;
+        switch(headers_msgs.ContentType)
+		{
+            case "signature":
+			{
+				td_element22.innerHTML = "<img src ='templates/"+template+"/images/signed_msg.gif' title='" + get_lang('Signed message') + "'>";
+				break;
+			}
+            case "cipher":
+			{
+				td_element22.innerHTML = "<img src ='templates/"+template+"/images/lock.gif' title='" + get_lang('Crypted message') + "'>";
+				break;
+			}
+            default:
+			{
+				break;
+			}
+		}
+
+        td_element23 = document.createElement("TD");
+		td_element23.className = "td_msg"
+		td_element23.setAttribute("width", "1%");
+		td_element23.id = "td_message_important_"+headers_msgs.msg_number;
+
+		if (headers_msgs.Flagged == 'F' || (headers_msgs.Importance.toLowerCase().indexOf("high") != -1 && parseInt(preferences.use_important_flag)))
+		{
+			td_element23.innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
+		}
+		else
+			td_element23.innerHTML = "&nbsp;&nbsp;&nbsp;";
+
+		td_element24 = document.createElement("TD");
+		td_element24.className = "td_msg";
+		td_element24.setAttribute("width", "1%");
+		td_element24.id = "td_message_sent_"+headers_msgs.msg_number;
+		td_element24.innerHTML = "&nbsp;&nbsp;&nbsp;";
+		// preload image
+		var _img_sent = new Image();
+		_img_sent.src 	 = "templates/"+template+"/images/sent.gif";
+
+		td_element3 = document.createElement("TD");
+		td_element3.className = "td_msg";
+		td_element3.id = "td_who_"+ headers_msgs.msg_number;
+		td_element3.setAttribute("width", "20%");
+		var _onclick = function(){InfoContact.hide();proxy_mensagens.get_msg(headers_msgs.msg_number, msg_folder,true, show_msg);};
+		td_element3.onclick = _onclick;
+		td_element3.innerHTML = '&nbsp;';
+		
+		if (typeof(headers_msgs.from) == 'undefined')
+			return false;
+		if(headers_msgs.from.email.toLowerCase() == Element("user_email").value)
+		{ 
+			td_element3.onmouseover = function () {this.title=headers_msgs.to.email;};
+			if (headers_msgs.Draft == 'X')
+				td_element3.innerHTML += "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
+			else{				
+				if(headers_msgs.to.email != null && headers_msgs.to.email.toLowerCase() != Element("user_email").value)
+					td_element24.innerHTML = "<img valign='center' src ='templates/"+template+"/images/sent.gif' title='"+get_lang('Sent')+"'>";
+			
+				if ((headers_msgs.to)&&(headers_msgs.to.name != null))
+					td_element3.innerHTML += headers_msgs.to.name;
+				else if (headers_msgs.to){
+					td_element3.innerHTML += headers_msgs.to.email;
+				}
+			}
+		}
+		else{
+			if (headers_msgs.Draft == 'X'){
+				td_element3.innerHTML = "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
+			}
+			else{				
+				var spanSender = document.createElement("SPAN");
+				spanSender.onmouseover = function (event) {this.style.textDecoration = "underline";try {InfoContact.begin(this,headers_msgs.from.email)} catch(e){};};
+				spanSender.onmouseout = function (){ try {this.style.textDecoration = "none"; clearTimeout(InfoContact.timeout);} catch(e){}};
+				spanSender.innerHTML =  headers_msgs.from.name != null ? headers_msgs.from.name : headers_msgs.from.email;
+				if (spanSender.innerHTML.indexOf(" ") == '-1' && spanSender.innerHTML.length > 25){
+					spanSender.innerHTML = spanSender.innerHTML.substring(0,25) + "...";
+				}
+				else if (spanSender.innerHTML.length > 40 ){
+					spanSender.innerHTML = spanSender.innerHTML.substring(0,40) + "...";
+				}				
+				td_element3.appendChild(spanSender);				
+			}
+		}			
+		td_element4 = document.createElement("TD");
+		td_element4.className = "td_msg";
+		td_element4.setAttribute("width", "50%");
+		td_element4.onclick = _onclick;
+//		td_element4.setAttribute("style","white-space:nowrap;");
+		td_element4.innerHTML = !is_ie ? "<a nowrap id='a_message_"+tr_element.id+"'>&nbsp;" : "&nbsp;";
+		
+		if ((headers_msgs.subject)&&(headers_msgs.subject.length > 50))
+		{
+//			if( (headers_msgs.subject.length+tr_element.msg_sample.length)>
+			td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
+		}
+		else
+		{
+			td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample + "</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
+		}
+					
+		td_element4.title=tr_element.tip;
+		if(!is_ie){
+			td_element4.innerHTML += "</a>";
+		}
+		
+
+		td_element5 = document.createElement("TD");
+		td_element5.className = "td_msg";
+		td_element5.setAttribute("width", "14%");
+		td_element5.onclick = _onclick;
+		td_element5.setAttribute("align", "center");
+		td_element5.innerHTML = headers_msgs.udate;
+
+		td_element6 = document.createElement("TD");
+		td_element6.className = "td_msg";
+		td_element6.setAttribute("width", "14%");
+		td_element6.onclick = _onclick;
+		td_element6.setAttribute("noWrap","true");
+		td_element6.setAttribute("align", "center");
+
+		td_element6.innerHTML = borkb(headers_msgs.Size);
+
+		tr_element.appendChild(td_element1);
+		tr_element.appendChild(td_element2);
+		tr_element.appendChild(td_element21);
+		tr_element.appendChild(td_element22);
+		tr_element.appendChild(td_element23);
+        tr_element.appendChild(td_element24);
+		tr_element.appendChild(td_element3);
+		tr_element.appendChild(td_element4);
+		tr_element.appendChild(td_element5);
+		tr_element.appendChild(td_element6);
+		return tr_element;
+}
+
+function sort_box(search, sort){
+	var message_header = Element("message_header_"+search);
+	var handler_draw_box = function(data){
+		draw_box(data, current_folder,true);
+		draw_paging(Element('tot_m').innerHTML);
+		//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
+                var msgs_unseen = 0;
+                for(i in data){
+	                if(data[i].Unseen == 'U')
+		                msgs_unseen++;
+	}
+		Element("new_m").innerHTML = '<font style="color:'+(msgs_unseen == 0 ? '': 'red')+'">' + msgs_unseen + '</font>';
+	}
+
+	if(sort_box_type == sort && search_box_type == search){
+		sort_box_reverse = sort_box_reverse ? 0 : 1;
+	}
+	else if(sort_box_type != sort){
+		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
+			sort_box_reverse = 0;
+		else
+			sort_box_reverse = 1;
+	}
+		
+	// Global variable.
+	sort_box_type = sort;
+	search_box_type = search;
+
+	proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
+	current_page = 1;
+	//Comentado para nao sobrepor o numero de msgs nao lidas ao utilizar os filtros
+	//update_menu();
+}
+function 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("message_header_SORTFROM_"+numBox).innerHTML 	= get_lang("Who");
+	document.getElementById("message_header_SORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
+	document.getElementById("message_header_SORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
+	document.getElementById("message_header_SORTSIZE_"+numBox).innerHTML	= get_lang("Size");	
+	document.getElementById("message_header_"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox ).innerHTML = "<B>"+type_name+"</B><img src ='templates/"+template+"/images/arrow_"+(sort_box_reverse == 1 ? 'desc' : 'asc')+"endant.gif'>";
+}
+function draw_message(info_msg, ID){
+	var content = document.getElementById('content_id_' + ID);
+	var defaultWidth = document.body.offsetWidth - 37;
+	
+	var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
+	if(!menuHidden)
+		defaultWidth -= Element("folderscol").offsetWidth;
+	 //////////////////////////////////////////////////////////////////////////////////////////////////////
+	//Make the next/previous buttom.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var next_previous_msg_td = document.createElement("TD");
+	next_previous_msg_td.setAttribute("noWrap","true");
+	next_previous_msg_td.align = "right";
+	next_previous_msg_td.width = "40px";
+	var img_next_msg = document.createElement("IMG");
+	img_next_msg.id = 'msg_opt_next_' + ID;
+	img_next_msg.src = './templates/'+template+'/images/down.button.png';
+	img_next_msg.title = get_lang('Next');
+	img_next_msg.style.cursor = 'pointer';
+
+	// Old
+	//img_next_msg.onclick = function () {cExecute ("expressoMail1_2.imap_functions.get_info_next_msg&msg_number="+ info_msg.msg_number + "&msg_folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type +  "&search_box_type="+ search_box_type +"&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)};
+    var folder_id = 0;
+    folder_id = info_msg.original_ID ? info_msg.original_ID: info_msg.msg_number;
+	var folder = document.getElementById(folder_id);
+	if (!folder){
+		delete_border(ID);
+		return;
+		}
+    if (folder){ // mensagem local criptografada nao tem ID da pasta local
+        if (folder.nextSibling){
+            var nextMsgBox = folder.nextSibling.name?folder.nextSibling.name:info_msg.msg_folder;
+
+            if (nextMsgBox == "INBOX/decifradas")// teste para ver se a mensagem vem da pasta oculta decifradas
+                    nextMsgBox = get_current_folder();
+
+            img_next_msg.onclick = function()
+            {
+                currentTab = ID;
+                openTab.type[ID] = 2;
+                            proxy_mensagens.get_msg(folder.nextSibling.id,nextMsgBox,true,show_msg);
+                //cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+folder.nextSibling.id+"&msg_folder="+nextMsgBox, show_msg);
+            };
+        }
+        else
+        {
+            img_next_msg.src = "./templates/"+template+"/images/down.gray.button.png";
+            img_next_msg.style.cursor = 'default';
+
+        }
+    }
+    else
+    {
+        img_next_msg.src = "./templates/"+template+"/images/down.gray.button.png";
+		img_next_msg.style.cursor = 'default';
+		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
+		{
+            img_next_msg.onclick = function()
+                {
+                    /*current_page++;
+                    msg_range_end = (current_page*preferences.max_email_per_page);
+                    msg_range_begin = (msg_range_end-(preferences.max_email_per_page)+1);
+                    kill_current_box();
+                    cExecute ('expressoMail1_2.imap_functions.get_range_msgs2&folder='+current_folder+'&msg_range_begin='+msg_range_begin+'&msg_range_end='+msg_range_end+'&sort_box_reverse=1', function handler(data){draw_box(data, current_folder);}) */
+                        delete_border(ID);
+                };
+        }
+    }
+	var img_space = document.createElement("SPAN");
+	img_space.innerHTML = "&nbsp;";
+	var img_previous_msg = document.createElement("IMG");
+	img_previous_msg.id = 'msg_opt_previous_' + ID;
+	img_previous_msg.src = './templates/'+template+'/images/up.button.png';
+	img_previous_msg.title = get_lang('Previous');
+	img_previous_msg.style.cursor = 'pointer';
+
+	//Old
+	//img_previous_msg.onclick = function () {cExecute ("expressoMail1_2.imap_functions.get_info_previous_msg&msgs_number="+ info_msg.msg_number + "&folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type+ "&search_box_type="+ search_box_type + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)}
+	//folder = document.getElementById(ID.substr(0, ID.indexOf('_')));
+	if (!folder){
+	        delete_border(ID);
+		return;
+		}
+    if (folder){ // mensagem local criptografada nao tem ID da pasta local
+        if (folder.previousSibling)
+        {
+            var previousMsgBox = folder.previousSibling.name?folder.previousSibling.name:info_msg.msg_folder;
+
+            if (previousMsgBox == "INBOX/decifradas") // teste para ver se a mensagem vem da pasta oculta decifradas
+                    previousMsgBox = get_current_folder();
+
+            img_previous_msg.onclick = function()
+            {
+                currentTab = ID;
+                openTab.type[ID] = 2;
+                //cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+folder.previousSibling.id+"&msg_folder=" + previousMsgBox, show_msg);
+                            proxy_mensagens.get_msg(folder.previousSibling.id,previousMsgBox,true,show_msg);
+            };
+        }
+        else
+        {
+            img_previous_msg.src = "./templates/"+template+"/images/up.gray.button.png";
+            img_previous_msg.style.cursor = 'default';
+        }
+	}
+	else
+	{
+		img_previous_msg.src = "./templates/"+template+"/images/up.gray.button.png";
+		img_previous_msg.style.cursor = 'default';
+		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
+        {
+            img_previous_msg.onclick = function()
+            {
+                delete_border(ID);
+            };
+        }
+    }
+	next_previous_msg_td.appendChild(img_previous_msg);
+	next_previous_msg_td.appendChild(img_space);
+	next_previous_msg_td.appendChild(img_next_msg);
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	//Make the header message.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var table_message = document.createElement("TABLE");
+	var tbody_message = document.createElement("TBODY");
+	table_message.border = "0";
+	table_message.width = defaultWidth ;
+
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	//Make the options message.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr0 = document.createElement("TR");
+	tr0.className = "tr_message_header";
+	var td0 = document.createElement("TD");
+	var table_message_options = document.createElement("TABLE");
+	table_message_options.width = "100%";
+	table_message_options.border = '0';
+	table_message_options.className = 'table_message';
+	var tbody_message_options = document.createElement("TBODY");
+	var tr = document.createElement("TR");
+	var td = document.createElement("TD");
+	td.setAttribute("noWrap","true");
+	var _name = '';
+	var _maxChar = menuHidden ? 40 : 15;
+	
+	if (info_msg.from.name)
+	{
+		var spanName = document.createElement("SPAN");
+			spanName.innerHTML = info_msg.from.name;
+		_name = spanName.innerHTML.length > _maxChar ? spanName.innerHTML.substring(0,_maxChar) + "..." : spanName.innerHTML;
+	}
+	else
+		_name = info_msg.from.email.length > _maxChar ? info_msg.from.email.substring(0,_maxChar) + "..." : info_msg.from.email;
+
+	td.innerHTML = _name.bold() + ', ' + info_msg.smalldate;
+	if (info_msg.attachments.length > 0)
+		td.innerHTML += "&nbsp<img style='cursor:pointer' onclick='javascript:Element(\"option_hide_more_"+ID+"\").onclick()' src ='templates/"+template+"/images/clip.gif' title='"+info_msg.attachments.names+"'>";
+	
+	if (typeof(info_msg.signature) == 'string')
+	{	
+		if (info_msg.signature != "void")
+			td.innerHTML += '&nbsp;<img style="cursor:pointer" onclick="alert(\''+ get_lang("This message is signed, and you can trust.") + info_msg.signature +'\');" src="templates/'+template+'/images/signed.gif">';
+		else
+			td.innerHTML += "&nbsp;<img style='cursor:pointer' onclick='alert(\""+get_lang("This message is signed, but it is invalid. You should not trust on it.")+"\");' title='"+get_lang("Voided message")+"' src='templates/"+template+"/images/invalid.gif'>";
+	}
+	
+	if (info_msg.DispositionNotificationTo)
+	{
+		td.innerHTML += '&nbsp;<img style="cursor:pointer" alt="'+ get_lang('Message with read notification') + '" title="'+ get_lang('Message with read notification') + '" src="templates/'+template+'/images/notification.gif">';
+	}
+	
+	// NORMAL MSG
+	if(info_msg.Draft != 'X')
+	{
+	var options = document.createElement("TD");
+	options.width = "30%";
+	options.setAttribute("noWrap","true");
+	var option_hide_more = document.createElement("SPAN");
+	option_hide_more.className = 'message_options';
+	options.align = 'right';
+	option_hide_more.value = 'more_options';
+	option_hide_more.id = 'option_hide_more_'+ID;
+	option_hide_more.onclick = function(){
+		var _height = Element("div_message_scroll_"+ID).style.height;
+		_height = parseInt(_height.replace("px",""));
+		var _offset = 35;
+		if (this.value == 'more_options'){
+			this.innerHTML = "<b><u>"+get_lang('Options')+"</u></b>";
+			this.value = 'hide_options';
+			Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
+			Element('table_message_others_options_'+ID).style.display = '';
+			Element('tr_other_options_'+ID).style.display = '';
+			
+		}
+		else{
+			this.innerHTML = get_lang('Options');
+			this.value = 'more_options';
+			Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
+			Element('table_message_others_options_'+ID).style.display = 'none';
+			Element('tr_other_options_'+ID).style.display = 'none';			
+		}
+	};
+	var option_mark = document.createElement('TD');
+	option_mark.align = "left";
+	option_mark.width = "50%";
+
+	var option_mark_as_unseen = '<span class="message_options" onclick="\
+		changeLinkState(this,\'seen\');\
+		set_messages_flag(\'unseen\','+folder_id+');\
+		write_msg(\''+get_lang('Message marked as ')+get_lang("Unseen")+
+	'.\');">'+get_lang("Unseen")+'</span>, ';
+
+	if (info_msg.Flagged == "F")
+		var option_mark_important = '<span class="message_options" onclick="\
+			changeLinkState(this,\'important\');\
+			set_messages_flag(\'unflagged\','+folder_id+');\
+			write_msg(\''+get_lang('Message marked as ')+get_lang("Normal")+
+			'.\');">'+get_lang("Normal")+'</span>';
+	else
+		var option_mark_important = '<span class="message_options" onclick="\
+			changeLinkState(this,\'normal\');\
+			set_messages_flag(\'flagged\','+folder_id+');\
+			write_msg(\''+get_lang('Message marked as ')+get_lang("Important")+
+			'.\');">'+get_lang("Important")+'</span>';
+	option_mark.innerHTML = option_mark_as_unseen+option_mark_important;
+	option_hide_more.innerHTML = get_lang('Options');
+	options.appendChild(option_hide_more);
+	
+	var space0 = document.createElement("SPAN");
+	space0.innerHTML = '&nbsp;|&nbsp;';
+	var space1 = document.createElement("SPAN");
+	space1.innerHTML = '&nbsp;|&nbsp;';
+	var space2 = document.createElement("SPAN");
+	space2.innerHTML = '&nbsp;|&nbsp;';
+	var space3 = document.createElement("SPAN");
+	space3.innerHTML = '&nbsp;|&nbsp;';
+	var space4 = document.createElement("SPAN");
+	space4.innerHTML = '&nbsp;|&nbsp;';
+
+	var option_forward = document.createElement("SPAN");
+	option_forward.id = 'msg_opt_forward_'+ID;
+	option_forward.className = 'message_options';
+	option_forward.onclick = function(){new_message('forward', ID);};
+	option_forward.innerHTML = get_lang('Forward');
+	options.appendChild(space1);
+	options.appendChild(option_forward);
+	var option_reply = document.createElement("SPAN");
+	option_reply.id = 'msg_opt_reply_'+ID;
+	option_reply.className = 'message_options';
+	option_reply.onclick = function(){new_message('reply_with_history', ID);};
+	option_reply.innerHTML = get_lang('Reply');
+	options.appendChild(space2);
+	options.appendChild(option_reply);
+	var option_delete = document.createElement("SPAN");
+	option_delete.id = 'msg_opt_delete_'+ID;
+	option_delete.className = 'message_options';
+	option_delete.onclick = function(){proxy_mensagens.delete_msgs(info_msg.msg_folder, info_msg.msg_number, ID);};
+	option_delete.innerHTML = get_lang('Delete');
+	options.appendChild(space3);
+	options.appendChild(option_delete);
+	
+	tr.appendChild(td);
+	tr.appendChild(option_mark);
+	tr.appendChild(options);
+	tr.appendChild(next_previous_msg_td);
+	tbody_message_options.appendChild(tr);
+	
+	////////// OTHER OPTIONS ////////////////////
+	var tr_other_options = document.createElement("TR");
+	tr_other_options.id = 'tr_other_options_' + ID;
+	tr_other_options.style.display = 'none';
+	
+	var td_other_options = document.createElement("TD");
+	td_other_options.colSpan = '3';
+	//td_other_options.align = 'right';
+	//td_other_options.setAttribute("noWrap","true");
+	var div_other_options = document.createElement("DIV");
+
+	var option_mark_as						= '<span>'+get_lang("Mark as")+'</span>: ';
+	var option_mark_as_unseen				= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'unseen\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Unseen")+'.\');">'+get_lang("Unseen")+'</span>, ';
+	var option_mark_as_important			= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'flagged\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Important")+'.\');">'+get_lang("Important")+'</span>, ';
+	var option_mark_as_normal				= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'unflagged\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Normal")+'.\');">'+get_lang("Normal")+'</span> | ';
+	
+	var option_move							= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","move_to");>'+get_lang("Move")+'</span> | ';
+	var option_reply_to_all					= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_to_all_with_history","'+ID+'");>'+get_lang("Reply to all")+'</span> | ';
+	var option_reply_without_history		= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_without_history","'+ID+'");>'+get_lang("Reply without history")+'</span> | ';
+	var option_reply_to_all_without_history	= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_to_all_without_history","'+ID+'");>'+get_lang("Reply to all without history")+'</span> |';
+	var option_source_msg = '<span class="message_options" onclick=proxy_mensagens.proxy_source_msg("'+ID+'","'+url_encode(info_msg.msg_folder)+'");>'+get_lang("Message Font")+'</span> </div>';		
+
+	div_other_options.innerHTML = option_reply_to_all + option_reply_without_history + option_reply_to_all_without_history + option_source_msg;
+	if (use_spam_filter) {
+		if(info_msg.msg_folder == 'INBOX'+cyrus_delimiter+'Spam')
+			div_other_options.innerHTML += ' | <span class="message_options" onclick="nospam('+info_msg.msg_number+',\'null\', \''+info_msg.msg_folder+'\')";>'+get_lang("Not Spam")+'</span>';	
+		else
+			div_other_options.innerHTML += ' | <span class="message_options" onclick="spam(\''+info_msg.msg_folder+'\', '+info_msg.msg_number+',\'null\')";>'+get_lang("Mark as Spam")+'</span>';	
+	}
+		
+	td_other_options.appendChild(div_other_options);
+	//td_other_options.innerHTML = option_print + option_reply_to_all + option_source_msg;
+	
+	tr_other_options.appendChild(td_other_options);
+	tbody_message_options.appendChild(tr_other_options);
+	////////// END OTHER OPTIONS ////////////////
+
+    	////////// BEGIN SIGNATURE //////////////////
+	if (info_msg.signature && info_msg.signature.length > 0)
+	{
+		var tr_signature = document.createElement("TR");
+		var td_signature = document.createElement("TD");
+		td_signature.className = 'tr_message_header';
+		tr_signature.id = 'tr_signature_'+ID;
+		td_signature.colSpan = "5";
+		tr_signature.style.display = 'none';
+
+		for (i in info_msg.signature)
+			td_signature.innerHTML += '<span>'+info_msg.signature[i]+'</span> <br /> ';
+		var signature_status_pos = info_msg.signature[0].indexOf(get_lang('Message untouched'));
+		td_signature.id = "td_signature_"+ID;
+		if(signature_status_pos < 0 )
+		{
+		td.innerHTML += '&nbsp;<img style="cursor:pointer" src="templates/'+template+'/images/signed_error.gif" title="'+get_lang("Details")+'">';
+		tr_signature.style.display = '';
+		}
+		else
+		{
+		td.innerHTML += '&nbsp;<img style="cursor:pointer" src="templates/'+template+'/images/signed_table.gif" title="'+get_lang("Details")+'">';
+		}
+		td.onclick = function(){
+		var _height = Element("div_message_scroll_"+ID).style.height;
+		_height = parseInt(_height.replace("px",""));
+		var _offset = 130;
+		if (this.value == 'more_cert'){
+			//this.innerHTML += "<b><u>Mais Informaï¿œï¿œes</u></b>";
+			this.value = 'hide_cert';
+			Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
+			Element('tr_signature_'+ID).style.display = 'none';
+			Element('td_signature_'+ID).style.display = 'none';
+
+		}
+		else{
+			//this.innerHTML += "Mais Informaï¿œï¿œes";
+			this.value = 'more_cert';
+			Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
+			Element('tr_signature_'+ID).style.display = '';
+			Element('td_signature_'+ID).style.display = '';
+		}
+	};
+
+		tr_signature.appendChild(td_signature);
+		tbody_message_options.appendChild(tr_signature);
+	/******************************************* Old signature   ***********************************************/
+		//if (info_msg.signature != "void")
+		//	td.innerHTML += '&nbsp;<img style="cursor:pointer" onclick="alert(\''+ get_lang("This message is signed, and you can trust.") + info_msg.signature +'\');" src="'+tpl_img_path+'/signed.gif">';
+		//else
+		//	td.innerHTML += "&nbsp;<img style='cursor:pointer' onclick='alert(\""+get_lang("This message is signed, but it is invalid. You should not trust on it.")+"\");' title='"+get_lang("Voided message")+"' src='"+tpl_img_path+"/invalid.gif'>";
+	/*****************************************															********/
+	}
+	//////////// END SIGNATURE ////////////////
+
+	table_message_options.appendChild(tbody_message_options);
+	td0.appendChild(table_message_options);
+	tr0.appendChild(td0);
+	tbody_message.appendChild(tr0);
+	}
+	// IF DRAFT
+	else
+	{
+		var options = document.createElement("TD");
+		options.width = "1%";
+		options.setAttribute("noWrap","true");
+		var option_edit	  = '<span class="message_options" onclick="new_message(\'edit\',\''+ID+'\');">'+get_lang('Edit')+'</span> | ';
+		var option_print = '<span class="message_options" onclick="print_msg(\''+info_msg.msg_folder+'\',\''+info_msg.msg_number+'\',\''+ID+'\');">'+get_lang('Print')+'</span> | ';
+		var option_delete = '<span class="message_options" onclick="proxy_mensagens.delete_msgs(\''+info_msg.msg_folder+'\',\''+info_msg.msg_number+'\',\''+ID+'\');">'+get_lang('Delete')+'</span> | ';		
+		var option_hide_more = document.createElement("SPAN");
+		option_hide_more.className = 'message_options';
+		options.align = 'right';
+		option_hide_more.value = 'more_options';
+		option_hide_more.id = 'option_hide_more_'+ID;
+		option_hide_more.innerHTML = get_lang('Options');
+		option_hide_more.onclick = function(){
+			var _height = Element("div_message_scroll_"+ID).style.height;
+			_height = parseInt(_height.replace("px",""));
+			var _offset = 35;
+			if (this.value == 'more_options'){
+				this.innerHTML = "<b><u>"+get_lang('Options')+"</u></b>";
+				this.value = 'hide_options';
+				Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
+				Element('table_message_others_options_'+ID).style.display = '';
+			}
+			else{
+				this.innerHTML = get_lang('Options');
+				this.value = 'more_options';
+				Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
+				Element('table_message_others_options_'+ID).style.display = 'none';
+			}
+		};
+		options.innerHTML = option_edit + option_print + option_delete;
+		options.appendChild(option_hide_more);
+		tr.appendChild(td);
+		tr.appendChild(options);
+		tr.appendChild(next_previous_msg_td);
+		tbody_message_options.appendChild(tr);
+		table_message_options.appendChild(tbody_message_options);
+		td0.appendChild(table_message_options);
+		tr0.appendChild(td0);
+		tbody_message.appendChild(tr0);
+	}
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	// END options message.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	var table_message_others_options = document.createElement("TABLE");
+	table_message_others_options.id = 'table_message_others_options_' + ID;
+	table_message_others_options.width =  defaultWidth - 30;
+	table_message_others_options.style.display = 'none';
+	table_message_others_options.className = "table_message";
+	var tbody_message_others_options = document.createElement("TBODY");
+	var tr1 = document.createElement("TR");
+	tr1.className = "tr_message_header";
+	var td1 = document.createElement("TD");
+	td1.innerHTML = get_lang("From: ");
+	td1.appendChild(deny_email(info_msg.from.email));
+	td1.width = "7%";
+	
+	if (info_msg.sender){
+		var tr111 = document.createElement("TR");
+		tr111.className = "tr_message_header";
+		var td111 = document.createElement("TD");
+		td111.innerHTML = get_lang("Sent by")+": ";
+		td111.appendChild(deny_email(info_msg.sender.email));
+		td111.setAttribute("noWrap","true");
+		var sender = document.createElement("TD");
+		sender.id = "sender_"+ID;
+		var sender_values = document.createElement("INPUT");
+		sender_values.id = "sender_values_"+ID;
+		sender_values.type = "HIDDEN";
+		sender_values.value = info_msg.sender.full; //Veio do IMAP, sem images nem links.
+		sender.innerHTML += draw_plugin_cc(ID, info_msg.sender.full);
+		sender.className = "header_message_field";
+		tr111.appendChild(td111);
+		tr111.appendChild(sender);
+		tr111.appendChild(sender_values);
+		tbody_message_others_options.appendChild(tr111);
+	}
+	
+	var from = document.createElement("TD");
+	from.id = "from_"+ID;
+	from.innerHTML = info_msg.from.full;
+	if (info_msg.Draft != "X"){
+		from.innerHTML += draw_plugin_cc(ID, info_msg.from);
+		tbody_message_others_options.appendChild(tr1);
+	}
+	from.className = "header_message_field";
+	var from_values = document.createElement("INPUT");
+	from_values.id = "from_values_"+ID;
+	from_values.type = "HIDDEN";
+	from_values.value = info_msg.from.full; //Veio do IMAP, sem images nem links.
+
+	var local_message = document.createElement("INPUT");
+	local_message.id = "is_local_"+ID;
+	local_message.name = "is_local";
+	local_message.type = "HIDDEN";
+	local_message.value = (info_msg.local_message)?"1":"0";
+
+	tr1.appendChild(td1);
+	tr1.appendChild(from);
+	tr1.appendChild(from_values);
+	tr1.appendChild(local_message);
+
+
+
+	if (info_msg.reply_to){
+		var tr11 = document.createElement("TR");
+		tr11.className = "tr_message_header";
+		var td11 = document.createElement("TD");
+		td11.innerHTML = get_lang("Reply to")+": ";
+		td11.setAttribute("noWrap","true");
+		var reply_to = document.createElement("TD");
+		reply_to.id = "reply_to_"+ID;
+		
+		var reply_to_values = document.createElement("INPUT");
+		reply_to_values.id = "reply_to_values_"+ID;
+		reply_to_values.type = "HIDDEN";
+		reply_to_values.value = info_msg.reply_to; //Veio do IMAP, sem images nem links.
+		reply_to.innerHTML = draw_plugin_cc(ID, info_msg.reply_to);
+		reply_to.className = "header_message_field";
+		tr11.appendChild(td11);
+		tr11.appendChild(reply_to);
+		tr11.appendChild(reply_to_values);
+		tbody_message_others_options.appendChild(tr11);
+	}
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr2 = document.createElement("TR");
+	tr2.className = "tr_message_header";
+	var td2 = document.createElement("TD");
+	td2.innerHTML = get_lang("To: ");
+	var to = document.createElement("TD");
+	to.id = "to_"+ID;
+
+	var to_values = document.createElement("INPUT");
+	to_values.id = "to_values_"+ID;
+	to_values.type = "HIDDEN";
+	to_values.value = info_msg.toaddress2; //Veio do IMAP, sem images nem links.	
+
+	// Salva a pasta da mensagem
+	var input_current_folder = document.createElement('input');	
+	input_current_folder.id = "input_folder_"+ID;
+	input_current_folder.name = "input_folder";
+	input_current_folder.type = "hidden";
+	input_current_folder.value = info_msg.msg_folder;
+	td2.appendChild(input_current_folder);	
+	// fim
+	toaddress_array[ID] = info_msg.toaddress2.split(",");
+	if (toaddress_array[ID].length > 1){
+		to.innerHTML += draw_plugin_cc(ID, toaddress_array[ID][0]);
+		var div_toaddress = document.createElement("SPAN");
+		div_toaddress.id = "div_toaddress_"+ID;
+		div_toaddress.style.display="";
+		div_toaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','to');>"+get_lang('more')+"</a>)";
+		to.appendChild(div_toaddress);		
+	}
+	else {
+		to.innerHTML += draw_plugin_cc(ID,toaddress_array[ID]);
+	}
+	to.className = "header_message_field";
+	tr2.appendChild(td2);
+	tr2.appendChild(to);
+	tr2.appendChild(to_values);
+	tbody_message_others_options.appendChild(tr2);
+
+	if (info_msg.cc){
+		var tr3 = document.createElement("TR");
+		tr3.className = "tr_message_header";
+		var td3 = document.createElement("TD");
+		td3.innerHTML = "CC: ";
+		var cc = document.createElement("TD");
+		cc.id = "cc_"+ID;
+
+		var cc_values = document.createElement("INPUT");
+		cc_values.id = "cc_values_"+ID;
+		cc_values.type = "HIDDEN";
+		cc_values.value = info_msg.cc;
+		
+		ccaddress_array[ID] = info_msg.cc.split(",");		
+		if (ccaddress_array[ID].length > 1){
+			var div_ccaddress = document.createElement("SPAN");
+			div_ccaddress.id = "div_ccaddress_"+ID;
+			var div_ccaddress_full = document.createElement("SPAN");
+			div_ccaddress_full.id = "div_ccaddress_full_"+ID;		
+			div_ccaddress.style.display="";
+			cc.innerHTML = draw_plugin_cc(ID, ccaddress_array[ID][0]);
+			div_ccaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','cc');>"+get_lang('more')+"</a>)";
+			cc.appendChild(div_ccaddress);
+		}
+		else{
+			cc.innerHTML = draw_plugin_cc(ID, info_msg.cc);
+		}
+		cc.className = "header_message_field";
+		tr3.appendChild(td3);
+		tr3.appendChild(cc);
+		tr3.appendChild(cc_values);
+		tbody_message_others_options.appendChild(tr3);
+	}
+
+	/*
+	 * @AUTHOR Rodrigo Souza dos Santos
+	 * @MODIFY-DATE 2008/09/11
+	 * @BRIEF Adding routine to create bcc field if there is one.
+	 */
+	if (info_msg.bcc)
+	{
+		var tr3 = document.createElement("tr");
+		tr3.className = "tr_message_header";
+		var td3 = document.createElement("td");
+		td3.innerHTML = get_lang("BCC") + " : ";
+		var cco = document.createElement("td");
+		cco.id = "cco_"+ID;
+
+		var cco_values = document.createElement("input");
+		cco_values.id = "cco_values_"+ID;
+		cco_values.type = "hidden";
+		cco_values.value = info_msg.bcc;
+
+		ccoaddress_array[ID] = info_msg.bcc.split(",");		
+		if (ccoaddress_array[ID].length > 1){
+			var div_ccoaddress = document.createElement("SPAN");
+			div_ccoaddress.id = "div_ccoaddress_"+ID;
+			var div_ccoaddress_full = document.createElement("SPAN");
+			div_ccoaddress_full.id = "div_ccoaddress_full_"+ID;		
+			div_ccoaddress.style.display="";
+
+			/*
+			 * The function below is ugly, doesn't possible use this.
+			 * The problem is that the code's function was written
+			 * on a hardcode concept.
+			 */
+			//cco.innerHTML = draw_plugin_cc(ID, ccoaddress_array[ID][0]);
+			cco.innerHTML = ccoaddress_array[ID][0];
+			div_ccoaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','cco');>"+get_lang('more')+"</a>)";
+			cco.appendChild(div_ccoaddress);
+		}
+		else{
+			/*
+			 * The function below is ugly, it is not possible to use this.
+			 * The problem is that the code's function was written
+			 * on a hardcode concept.
+			 */
+			//cco.innerHTML = draw_plugin_cc(ID, info_msg.cco);
+			cco.innerHTML = info_msg.bcc;
+		}
+		cco.className = "header_message_field";
+		tr3.appendChild(td3);
+		tr3.appendChild(cco);
+		tr3.appendChild(cco_values);
+		tbody_message_others_options.appendChild(tr3);
+	}
+
+	var tr4 = document.createElement("TR");
+	tr4.className = "tr_message_header";
+	var td4 = document.createElement("TD");
+	td4.innerHTML = get_lang("Date: ");
+	var date = document.createElement("TD");
+	date.id = "date_"+ID;
+	date.innerHTML = info_msg.fulldate;
+	var date_day = document.createElement("INPUT");
+	date_day.id = "date_day_"+ID;
+	date_day.type = "HIDDEN";
+	date_day.value = info_msg.msg_day;
+	var date_hour = document.createElement("INPUT");
+	date_hour.id = "date_hour_"+ID;
+	date_hour.type = "HIDDEN";
+	date_hour.value = info_msg.msg_hour
+	date.className = "header_message_field";
+	tr4.appendChild(td4);
+	tr4.appendChild(date);
+	tr4.appendChild(date_day);
+	tr4.appendChild(date_hour);
+	tbody_message_others_options.appendChild(tr4);
+	
+	var tr5 = document.createElement("TR");
+	tr5.className = "tr_message_header";
+	var td5 = document.createElement("TD");
+	td5.innerHTML = get_lang("Subject");
+	var subject = document.createElement("TD");
+	subject.id = "subject_"+ID;
+	subject.innerHTML = info_msg.subject;
+	subject.className = "header_message_field";
+	tr5.appendChild(td5);
+	tr5.appendChild(subject);
+	tbody_message_others_options.appendChild(tr5);
+	if (info_msg.attachments.length > 0){
+		var tr6 = document.createElement("TR");
+		tr6.className = "tr_message_header";
+		var td6 = document.createElement("TD");
+		td6.innerHTML = get_lang("Attachments: ");
+
+		var attachments = document.createElement("TD");
+		td6.vAlign = "top";
+		attachments.align='left';
+		var zipped_attachments = '';
+		if(info_msg.attachments.length >= 1) {
+			var zipped_attachments  = document.createElement("TABLE");
+			zipped_attachments.style.marginBottom = "4px";
+			zipped_attachments.cellPadding="0";
+			zipped_attachments.cellSpacing="0";
+			var td = document.createElement("TD");
+			if(info_msg.attachments.length > 1) {
+				var link_attachment     = document.createElement("A");
+                 if(proxy_mensagens.is_local_folder(current_folder))
+                    link_attachment.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+                else
+                    link_attachment.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+				link_attachment.innerHTML = " "+info_msg.attachments.length+' '+get_lang('files')+' :: '+get_lang('Download all atachments');
+				link_attachment.innerHTML += '<BR>';
+				td.appendChild(link_attachment);
+			}
+			var tr = document.createElement("TR");
+			if(parseInt(preferences.remove_attachments_function))
+			{
+				var del_attachments = document.createElement("A");
+				del_attachments.setAttribute("href", "javascript:remove_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+				del_attachments.innerHTML = get_lang('remove all attachments');
+				del_attachments.appendChild(document.createElement('BR'));
+				td.appendChild(del_attachments);
+				tr.appendChild(td);
+			}
+			tr.appendChild(td);
+			zipped_attachments.appendChild(tr);
+			attachments.appendChild(zipped_attachments);
+		}
+
+		attachments.id = "attachments_" + ID;
+		for (var i=0; i<info_msg.attachments.length; i++){
+			var link_attachment = document.createElement("A");
+			link_attachment.setAttribute("href", proxy_mensagens.link_anexo(info_msg,i));
+//			link_attachment.setAttribute("href", "javascript:download_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"',"+i+",'"+info_msg.attachments[i].pid+"','"+info_msg.attachments[i].encoding+"')");
+			link_attachment.innerHTML = url_decode(info_msg.attachments[i].name);
+			link_attachment.innerHTML = borkb(info_msg.attachments[i].fsize);
+
+			if((url_decode(info_msg.attachments[i].name).indexOf(".ics")!=-1) || (url_decode(info_msg.attachments[i].name).indexOf(".vcard")!=-1)){
+				//Link para importar calendário
+				var link_import_attachment = new Image();
+				link_import_attachment.src = "templates/"+template+"/images/new.png";
+				link_import_attachment.setAttribute("onclick","javascript:import_calendar('"+info_msg.msg_folder+"&msg_number="+info_msg.msg_number+"&msg_part="+info_msg.attachments[i].pid+"&idx_file="+i+"&encoding="+info_msg.attachments[i].encoding+"');");
+				link_import_attachment.title = get_lang("Import to calendar");
+				link_import_attachment.align = "top";				
+				link_import_attachment.style.cursor = "pointer";
+				var space = document.createElement("span");
+				space.innerHTML = "&nbsp;";
+				attachments.appendChild(link_attachment);
+				attachments.appendChild(space);
+				attachments.appendChild(link_import_attachment);
+			}
+			else {
+				link_attachment.innerHTML += '<BR>';
+				attachments.appendChild(link_attachment);
+			}
+		}
+		tr6.appendChild(td6);
+		tr6.appendChild(attachments);
+		tbody_message_others_options.appendChild(tr6);
+	}
+
+
+	// BEGIN MAKE THE SCROLL HEIGHT
+	var bar = document.getElementById("toolbar");
+	var offset = 0;
+	if(bar.style.visibility != 'hidden')
+		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;
+	var div = document.createElement("DIV");
+	div.id = "div_message_scroll_"+ID;
+	div.style.background = 'WHITE';
+	div.style.height = document.body.clientHeight - offset - 125;
+	content.style.height = document.body.clientHeight - offset - 90;
+	div.style.overflow = "auto";
+	div.style.width = defaultWidth - (is_ie ? 5 : 0);
+	// END MAKE THE SCROLL HEIGHT
+	table_message_others_options.appendChild(tbody_message_others_options);
+	var tr = document.createElement("TR");
+	var td = document.createElement("TD");
+	td.colSpan = '2';
+	div.appendChild(table_message_others_options);
+	var imgTag = info_msg.body.match(/(<img[^>]*src[^>=]*=['"]?[^'">]*["']?[^>]*>)|(<[^>]*(style[^=>]*=['"][^>]*background(-image)?:[^:;>]*url\()[^>]*>)/gi);
+
+	var newBody = info_msg.body;
+	if(!info_msg.showImg && imgTag)
+	{
+		var domains = '';
+		var blocked = false;
+		var forbidden = true;
+
+		if (preferences.notification_domains != null && typeof(preferences.notification_domains) != 'undefined')
+		{
+			domains = preferences.notification_domains.split(',');
+			for(var j = 0; j < imgTag.length; j++)
+			{
+				for (var i = 0; i < domains.length; i++)
+				{
+					if (imgTag[j].match(/cid:([\w\d]){5,}/) || imgTag[j].match(/src=\"\.\/inc\/show_embedded_attach\.php/g))
+					{
+						forbidden = false;
+						continue;
+					}
+					imgSource = imgTag[j].match(/=['"](http:\/\/)+[^'"\/]*/);
+					if (imgSource && imgSource.toString().substr(5).match(domains[i]))
+						forbidden = false;
+				}
+				if (forbidden)
+				{
+					newBody = newBody.replace(imgTag[j],"<img src='templates/"+template+"/images/forbidden.jpg'>");
+					blocked=true;
+				}
+			}
+			if (blocked)
+			{
+				var showImgLink = document.createElement('DIV');
+				showImgLink.id="show_img_link_"+ID;
+				showImgLink.onclick = function(){show_msg_img(info_msg.msg_number,info_msg.msg_folder)};
+				showImgLink.className="show_img_link";
+				showImgLink.innerHTML = get_lang("Show images from")+": "+info_msg.from.email;
+				td.appendChild(showImgLink);
+			}
+		}
+	}
+	td.appendChild(div);
+	tr.appendChild(td)
+	tbody_message.appendChild(tr);
+
+
+	//////////////////////////////////////////////////////////////////////////////////////////////////////	
+	//Make the body message.
+	///////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr = document.createElement("TR");
+	tr.className = "tr_message_body";
+	var td = document.createElement("TD");
+	//td.setAttribute("colSpan","2");
+	newBody = newBody.replace("<body","<span");
+	newBody = newBody.replace("<BODY","<span");
+	div.innerHTML+= "<span id='body_"+ID+"' style='font-size:16px;'>"+newBody+"</span><br><br>";
+	function mailto( link )
+	{
+		var mail = link.href.substr( 7 );
+		link.onclick = function( )
+		{
+			new_message_to( mail );
+			return false;
+		};
+	}
+	var links = div.getElementsByTagName( 'a' );
+	for ( var i = 0; i < links.length; i++ )
+		if ( links.item( i ).href.indexOf( 'mailto:' ) === 0 )
+			mailto( links.item( i ) );
+		else
+		{
+			if ( links.item( i ).href.indexOf( 'javascript:' ) !== 0 )
+				links.item( i ).setAttribute( 'target', '_blank' );
+		}
+	//////////////////////////////////////////////////////////////////////////////////////////////////////	
+	//Make the thumbs of the message.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	if ((info_msg.thumbs)&&(info_msg.thumbs.length > 0)){
+		var table_message_thumbs = document.createElement("TABLE");
+		table_message_thumbs.width = "80%";
+		table_message_thumbs.style.borderTop = "2px solid rgb(170, 170, 170)";
+		var tbody_message_thumbs = document.createElement("TBODY");
+		var tr = document.createElement("TR");
+		tr.className = "tr_message_body";
+		var td = document.createElement("TD");
+		td.setAttribute("colSpan","2");
+		td.id = "body_thumbs_"+ID;
+		td.innerHTML += "&nbsp;<font color='DARKBLUE' size='2'><b>"+info_msg.attachments.length+" "+get_lang("attachment")+(info_msg.attachments.length > 1 ? "s" : "")+" "+get_lang("in this message")+"</font></b>";
+		var _link_attachments = '';
+		if(info_msg.thumbs.length > 1){
+			_link_attachments 	= document.createElement("A");
+			_link_attachments.className = "message_options";
+             if(proxy_mensagens.is_local_folder(current_folder))
+                _link_attachments.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+            else
+                _link_attachments.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
+			_link_attachments.innerHTML = get_lang('Download all atachments');
+		}
+		
+		if(_link_attachments){
+			td.innerHTML +=	" :: ";
+			td.appendChild(_link_attachments);
+		}
+		
+		td.innerHTML +=	"<BR><img src='templates/"+template+"/images/menu/ktip.png'>"+get_lang("<b>Tip:</b> For faster save, click over the image with <u>right button</u>.");
+		td.innerHTML += "<BR>";
+
+		for (var i=0; i<info_msg.thumbs.length; i++){
+			if ((i % 4) == 0)
+				td.innerHTML += "<BR>";
+			td.innerHTML += info_msg.thumbs[i];
+			td.innerHTML += "&nbsp;&nbsp;";
+		}
+		tr.appendChild(td);
+		tbody_message_thumbs.appendChild(tr);
+		table_message_thumbs.appendChild(tbody_message_thumbs);
+		div.appendChild(table_message_thumbs);
+	}
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	table_message.appendChild(tbody_message);
+	content.appendChild(table_message);
+	var msg_number = document.createElement('INPUT');
+	msg_number.id = "msg_number_" + ID;
+	msg_number.type = "hidden";
+	msg_number.value = info_msg.msg_number;
+	content.appendChild(msg_number);
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	//Exibe o cabecalho da mensagem totalmente aberto caso esteja setado nas preferencias do usuario
+	if (preferences.show_head_msg_full == 1)
+	{
+		option_hide_more.onclick();
+
+		if (Element('div_toaddress_'+ID) != null)
+		{
+			show_div_address_full(ID,'to');
+		}	
+		if (Element('div_ccaddress_'+ID) != null)
+		{
+			show_div_address_full(ID,'cc');
+		}
+	}
+
+}
+function changeLinkState(el,state){
+	el.innerHTML = get_lang(state);
+	switch (state){
+		case 'important':
+			{
+				el.onclick = function(){changeLinkState(el,'normal');set_messages_flag('unflagged',currentTab.substr(0,currentTab.indexOf("_r"))); write_msg(get_lang('Message marked as ')+get_lang("Normal"))}
+				break;
+			}
+		case 'normal':
+			{
+				el.onclick = function(){  changeLinkState(el,'important');set_messages_flag('flagged',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("Important"))}
+				break;
+			}
+		case 'unseen':
+			{
+				el.onclick = function(){  changeLinkState(el,'seen');set_messages_flag('unseen',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("unseen"))}
+				break;
+
+			}
+		case 'seen':
+			{
+				el.onclick = function(){  changeLinkState(el,'unseen');set_messages_flag('seen',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("seen"))}
+				break;
+
+			}
+		default:
+			{
+				break;
+			}
+	}
+}
+
+
+function draw_new_message(border_ID){
+	var ID = create_border("",border_ID);
+	if (ID == false)
+		return false;
+	expresso.connector.hold_session = true;
+	
+	var footer_menu = Element("footer_menu");	
+	if (footer_menu) {
+		footer_menu.style.display = 'none';
+	}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+	var form = document.createElement("FORM");
+	form.name = "form_message_"+ID;
+	form.method = "POST";
+	form.onsubmit = function(){return false;}
+	if(!is_ie)
+		form.enctype="multipart/form-data";
+	else
+		form.encoding="multipart/form-data";
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+	//ConstructMenuNewMessage(ID);
+////////////////////////////////////////////////////////////////////////////////////////////////////////	
+	var content = Element('content_id_' + ID);
+	var table_message = document.createElement("TABLE");
+	table_message.width = "100%";
+	var tbody_message = document.createElement("TBODY");
+	var tr0 = document.createElement("TR");
+	tr0.className = "tr_message_header";
+	var td0 = document.createElement("TD");
+	td0.colSpan = '3';
+	
+	var table_menu_new_message = document.createElement("TABLE");
+	table_menu_new_message.width = "100%";
+	table_menu_new_message.border = '0';
+	table_menu_new_message.className = 'table_message';
+	var tbody_menu_new_message = document.createElement("TBODY");
+	var tr_menu_new_message = document.createElement("TR");
+	var td_menu_new_message = document.createElement("TD");
+	td_menu_new_message.setAttribute("noWrap","true");
+	
+	if ((preferences.save_in_folder == '-1') || (preferences.save_in_folder == '')){
+		//var option_send = '<span class="message_options" onclick=send_message("'+ID+'","null","null");>'+get_lang("Send")+'</span> | ';
+		var option_send   = '<input type="button" id="send_button_'+ID+'" class="em_button_like_span" tabindex="1" value="'+get_lang("Send")+'" onclick=send_message("'+ID+'","null","null");>' + ' | ';
+		if(!expresso_offline)
+			var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
+		else
+			var option_send_and_file='';
+	}
+	else{
+		//var option_send = '<span class="message_options" onclick="send_message(\''+ID+'\',\''+preferences.save_in_folder+'\',\'null\');">'+get_lang("Send")+'</span> | ';
+		var option_send   = '<input type="button" id="send_button_'+ID+'" class="em_button_like_span" tabindex="1" value="'+get_lang("Send")+'" onclick="send_message(\''+ID+'\',\''+preferences.save_in_folder+'\',\'null\');">' + ' | ';
+		var option_send_and_file='';
+		wfolders.alert = true;
+	}
+//	var option_save_as		= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","save");>'+get_lang("Save as")+'</span> | ';
+	if (!expresso_offline) {
+		var option_save = '<span id="save_message_options_'+ID+'" class="message_options" onclick="openTab.toPreserve['+ID+'] = true; save_msg('+ID+');">'+get_lang("Save")+'</span> | ';
+		var option_search = '<span class="message_options" onclick=openListUsers("'+ID+'");>'+get_lang("Search")+'</span>';
+	}
+	else {
+		var option_save = '<input type="hidden" id="save_message_options_'+ID+'">';
+		var option_search = '';
+	}
+	td_menu_new_message.innerHTML = option_send + option_send_and_file + option_save + option_search;
+	
+	tr_menu_new_message.appendChild(td_menu_new_message);
+	tbody_menu_new_message.appendChild(tr_menu_new_message);
+	table_menu_new_message.appendChild(tbody_menu_new_message);
+	
+	content.appendChild(table_menu_new_message);
+	tr0.appendChild(td0);
+	tbody_message.appendChild(tr0);
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr1_1 = document.createElement("TR");
+	tr1_1.style.display = 'none';
+	var td1_1 = document.createElement("TD");
+	td1_1.innerHTML = get_lang("From")+":";
+	td1_1.setAttribute("noWrap","true");
+	td1_1.style.width = "1%";
+	
+	var td_from = document.createElement("TD");
+	td_from.setAttribute("noWrap","true");
+	td_from.style.width = "100%";
+			
+	var sel_from = document.createElement('SELECT');	
+	sel_from.id = "from_"+ID;
+	sel_from.name = "input_from";
+	sel_from.style.width = "70%";
+	sel_from.setAttribute("wrap","soft");
+	td_from.appendChild(sel_from);	
+	tr1_1.appendChild(td1_1);
+	tr1_1.appendChild(td_from);
+	tbody_message.appendChild(tr1_1);	
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr1 = document.createElement("TR");
+	var td1 = document.createElement("TD");
+	td1.innerHTML = get_lang("To")+":";
+	td1.setAttribute("noWrap","true");
+	td1.style.width = "1%";
+	
+	var td_to = document.createElement("TD");
+	td_to.setAttribute("noWrap","true");
+	td_to.style.width = "100%";
+	
+	var input_to = document.createElement('TEXTAREA');
+	input_to.id = "to_"+ID;
+	input_to.name = "input_to";
+	input_to.setAttribute("tabIndex","1");	
+	input_to.style.width = "100%";
+	input_to.setAttribute("wrap","soft");
+	input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
+	input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
+	if (!is_ie)
+	{
+		input_to.rows = 2;
+		input_to.onkeypress = function (e)
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_to.value, 'to', ID);
+            }
+            else
+            {
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_to.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
+	}
+	else
+	{
+		input_to.rows = 3;
+		input_to.onkeyup = function (e)
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_to.value, 'to', ID);
+            }
+            else 
+            { 
+                search_contacts(window.event.keyCode,this.id);
+            }   
+        }
+	}
+	td_to.appendChild(input_to);
+	
+	var forwarded_local_message = document.createElement("INPUT"); //Hidden para indicar se é um forward de uma mensagem local
+	forwarded_local_message.id = "is_local_forward"+ID;
+	forwarded_local_message.name = "is_local_forward";
+	forwarded_local_message.type = "HIDDEN";
+	forwarded_local_message.value = "0";
+	td_to.appendChild(forwarded_local_message);
+	
+	if (!expresso_offline) {
+		var img_search = document.createElement("IMG");
+		img_search.src = "./templates/"+template+"/images/search.gif";
+		img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
+		img_search.onclick = function () {emQuickSearch(document.getElementById('to_'+ID).value, 'to', ID);};
+	}
+	else {
+		var img_search = document.createElement("SPAN");
+	}
+	
+	var span_search = document.createElement("SPAN");
+	span_search.innerHTML = get_lang('Search');
+	
+	var td1_img_search = document.createElement("TD");
+	td1_img_search.setAttribute("noWrap","true");
+	var td1_span_search = document.createElement("TD");
+	td1_span_search.setAttribute("noWrap","true");	
+	
+	td1_img_search.appendChild(img_search);
+	td1_span_search.appendChild(span_search);
+	
+	tr1.appendChild(td1);
+	tr1.appendChild(td_to);
+	tr1.appendChild(td1_img_search);
+
+	tbody_message.appendChild(tr1);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr2 = document.createElement("TR");
+	tr2.id = "tr_cc_"+ID;
+	tr2.style.display = 'none';
+	var td2 = document.createElement("TD");
+	td2.innerHTML = "Cc:";
+	td2.setAttribute("noWrap","true");	
+	td2.style.width = "1%";
+	
+	var td_cc = document.createElement("TD");
+	td_cc.setAttribute("noWrap","true");
+	td_cc.style.width = "100%";
+	
+	var input_cc = document.createElement('TEXTAREA');
+	input_cc.id = "cc_"+ID;
+	input_cc.name = "input_cc";
+	input_cc.setAttribute("tabIndex","1");
+	input_cc.style.width = "100%";
+	input_cc.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
+	input_cc.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
+    if (!is_ie)
+    {
+        input_cc.rows = 2;
+        input_cc.onkeypress = function (e)
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cc.value, 'cc', ID);
+            }
+            else
+            {
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_cc.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
+    }
+    else if (is_ie)
+    {
+        input_cc.rows = 3;
+        input_cc.onkeyup = function (e)
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cc.value, 'cc', ID);
+            }
+            else
+            {
+                search_contacts(window.event.keyCode,this.id);
+            }
+        }
+    }
+	
+	td_cc.appendChild(input_cc);
+	var img_search = document.createElement("IMG");
+	img_search.src = "./templates/"+template+"/images/search.gif";
+	img_search.onclick = function () {emQuickSearch(document.getElementById('cc_'+ID).value, 'cc', ID)}
+	img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
+	var span_search = document.createElement("SPAN");
+	span_search.innerHTML = get_lang('Search');
+	
+	var td2_img_search = document.createElement("TD");
+	td2_img_search.setAttribute("noWrap","true");
+	var td2_span_search = document.createElement("TD");
+	td2_span_search.setAttribute("noWrap","true");	
+	
+	td2_img_search.appendChild(img_search);
+	td2_span_search.appendChild(span_search);
+		
+	tr2.appendChild(td2);
+	tr2.appendChild(td_cc);
+	tr2.appendChild(td2_img_search);
+	tbody_message.appendChild(tr2);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr3 = document.createElement("TR");
+	tr3.id = "tr_cco_"+ID;
+	tr3.style.display = 'none';
+	var td3 = document.createElement("TD");
+	td3.setAttribute("noWrap","true");
+	td3.innerHTML = get_lang("CCo")+":";
+	td3.style.width = "1%";
+	
+	var td_cco = document.createElement("TD");
+	td_cco.setAttribute("noWrap","true");
+	td_cco.style.width = "100%";
+	
+	var input_cco = document.createElement('TEXTAREA');
+	input_cco.id = "cco_"+ID;
+	input_cco.name = "input_cco";
+	input_cco.setAttribute("tabIndex","1");
+	input_cco.style.width = "100%";
+	input_cco.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
+	input_cco.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
+	
+	if (!is_ie)
+    {
+        input_cco.rows = 2;
+        input_cco.onkeypress = function (e)
+        {
+            if ((e.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cco.value, 'cco', ID);
+            }
+            else 
+            { 
+                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
+                {
+                    e.preventDefault();
+                    search_contacts(e.keyCode,this.id);
+                }
+            }
+        }
+        input_cco.onkeyup = function (e)
+        {
+            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
+            {
+                search_contacts(e.keyCode,this.id);
+            }
+        }
+    }
+    else if (is_ie)
+    {
+        input_cco.rows = 3;
+        input_cco.onkeyup = function (e)
+        {
+            if ((window.event.keyCode) == 120) //F9
+            {
+                emQuickSearch(input_cco.value, 'cco', ID);
+            }
+            else 
+            { 
+                search_contacts(window.event.keyCode,this.id);
+            }   
+        }
+    }
+	
+	td_cco.appendChild(input_cco);
+	var img_search = document.createElement("IMG");
+	img_search.src = "./templates/"+template+"/images/search.gif";
+	img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');	
+	img_search.onclick = function () {emQuickSearch(document.getElementById('cco_'+ID).value, 'cco', ID);};
+	var span_search = document.createElement("SPAN");
+	span_search.innerHTML = get_lang('Search');
+
+	var td3_img_search = document.createElement("TD");
+	td3_img_search.setAttribute("noWrap","true");
+	var td3_span_search = document.createElement("TD");
+	td3_span_search.setAttribute("noWrap","true");	
+	
+	td3_img_search.appendChild(img_search);
+	td3_span_search.appendChild(span_search);
+		
+	tr3.appendChild(td3);
+	tr3.appendChild(td_cco);
+	tr3.appendChild(td3_img_search);	
+	tbody_message.appendChild(tr3);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr_link = document.createElement("TR");
+	tr_link.id = "tr_link_"+ID;		
+	var td1_link = document.createElement("TD");
+	var td2_link = document.createElement("TD");
+	td1_link.innerHTML = "&nbsp;";
+	var a_cc_link = document.createElement('A');
+	a_cc_link.innerHTML = get_lang('Add CC');
+	a_cc_link.id = "a_cc_link_"+ID;
+	a_cc_link.setAttribute("href","javascript:void(0)");
+	a_cc_link.setAttribute("tabIndex","-1");
+	a_cc_link.onclick = function () {this.style.display='none';document.getElementById('tr_cc_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cc.focus(); return false;}
+	td2_link.appendChild(a_cc_link);	
+	var space = document.createElement("span");
+	space.id ="space_link_"+ID;
+	space.innerHTML="&nbsp;|&nbsp;";
+	td2_link.appendChild(space);
+	var a_cco_link = document.createElement('A');
+	a_cco_link.innerHTML = get_lang('Add BCC');
+	a_cco_link.id = "a_cco_link_"+ID;
+	a_cco_link.setAttribute("href","javascript:void(0)");
+	a_cco_link.setAttribute("tabIndex","-1");
+	a_cco_link.onclick = function () {this.style.display='none';document.getElementById('tr_cco_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cco.focus(); return false;}
+	td2_link.appendChild(a_cco_link);	
+	tr_link.appendChild(td1_link);
+	tr_link.appendChild(td2_link);
+	tbody_message.appendChild(tr_link);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr4 = document.createElement("TR");
+	var td4 = document.createElement("TD");
+	//td4.setAttribute("noWrap","true");	
+	td4.innerHTML = get_lang("Subject")+":";
+	var td_subject = document.createElement("TD");
+	var input_subject = document.createElement('input');
+	input_subject.id = "subject_"+ID;
+	input_subject.name = "input_subject";
+	input_subject.setAttribute("tabIndex","1");
+	input_subject.style.width = "90%";
+	input_subject.setAttribute("autocomplete","off");
+	td_subject.appendChild(input_subject);
+	tr4.appendChild(td4);
+	tr4.appendChild(td_subject);
+	tbody_message.appendChild(tr4);
+//////////////////////////////////////////////////////////////////////////////////////////////////////	
+	var tr5 = document.createElement("TR");
+	var td5 = document.createElement("TD");
+	td5.innerHTML = "&nbsp;";
+	var td_return_receipt = document.createElement("TD");
+	td_return_receipt.setAttribute("noWrap","true");
+	td_return_receipt.innerHTML = get_lang("Return receipt")+":";
+        if (is_ie)
+        {
+            var input_return_receipt = document.createElement('input name=input_return_receipt');
+        }
+        else
+        {
+            var input_return_receipt = document.createElement('input');
+            input_return_receipt.name = "input_return_receipt";
+        }
+	input_return_receipt.type = "checkbox";
+	input_return_receipt.className = "checkbox";
+	input_return_receipt.id = "return_receipt_"+ID;
+	input_return_receipt.setAttribute("tabIndex","-1");
+	td_return_receipt.appendChild(input_return_receipt);
+
+    // Workaround para resolver problema ao enviar e-mails
+    if((preferences.use_assinar_criptografar != '0'))
+	{
+        if(parseInt(preferences.use_signature_digital_cripto)==1)
+		{
+			td_return_receipt.innerHTML +=  "&nbsp;&nbsp;" + get_lang("Digitally sign message?")+"";
+
+            if (is_ie)
+            {
+                var input_return_digital = document.createElement('input name=input_return_digital');
+            }
+            else
+            {
+			var input_return_digital = document.createElement('input');
+                input_return_digital.name = "input_return_digital";
+            }
+
+			input_return_digital.type = "checkbox";
+			input_return_digital.className = "checkbox";
+			input_return_digital.id = "return_digital_"+ID;
+			input_return_digital.setAttribute("tabIndex","-1");
+            if(parseInt(preferences.use_signature_digital)==1)
+			{
+				input_return_digital.defaultChecked=true;
+			}
+			td_return_receipt.appendChild(input_return_digital);
+			td_return_receipt.innerHTML +=  "&nbsp;&nbsp;" + get_lang("Digitally crypt message?")+"";
+
+            if (is_ie)
+            {
+                var input_return_cripto = document.createElement('input name=input_return_cripto');
+            }
+            else
+            {
+			var input_return_cripto = document.createElement('input');
+                input_return_cripto.name = "input_return_cripto";
+            }
+
+			input_return_cripto.type = "checkbox";
+			input_return_cripto.className = "checkbox";
+			input_return_cripto.id = "return_cripto_"+ID;
+			input_return_cripto.setAttribute("tabIndex","-1");
+			input_return_cripto.defaultChecked=false;
+
+            if(parseInt(preferences.use_signature_cripto)==1)
+			{
+				input_return_cripto.defaultChecked=true;
+			}
+
+			td_return_receipt.appendChild(input_return_cripto);
+		}
+                td_return_receipt.innerHTML += "";
+	}
+
+	tr5.appendChild(td5);
+	tr5.appendChild(td_return_receipt);
+	tbody_message.appendChild(tr5);
+	if (parseInt(preferences.use_important_flag))
+	{
+		var trn = document.createElement("TR");
+		var tdn = document.createElement("TD");
+		tdn.innerHTML = "&nbsp;";
+		var td_important_msg = document.createElement("TD");
+		td_important_msg.setAttribute("noWrap","true");
+		td_important_msg.innerHTML = get_lang("Important message")+":";
+		var input_important_message = document.createElement('input');
+		input_important_message.type = "checkbox";
+		input_important_message.className = "checkbox";
+		input_important_message.id = "important_message_"+ID;
+		input_important_message.name = "input_important_message";
+		input_important_message.setAttribute("tabIndex","-1");
+		td_important_msg.appendChild(input_important_message);	
+		trn.appendChild(tdn);
+		trn.appendChild(td_important_msg);
+		tbody_message.appendChild(trn);
+	}
+
+	var add_files = document.createElement("A");
+	add_files.setAttribute("href", "javascript:void(0)");
+	add_files.onclick = function () { addFile(ID); return false;};
+	add_files.innerHTML =  get_lang("Attachments: add+");
+	add_files.setAttribute("tabIndex","-1");
+	var divfiles = document.createElement("DIV");
+	divfiles.id = "divFiles_"+ID;
+	var tr5 = document.createElement("TR");
+	var td5_link = document.createElement("TD");
+	var td5_input = document.createElement("TD");	
+	td5_input.innerHTML = "&nbsp;"
+	td5_link.setAttribute("valign","top");
+	td5_link.setAttribute("colSpan","2");
+	td5_link.appendChild(add_files);
+	tr5.appendChild(td5_input);
+	tr5.appendChild(td5_link);
+	tbody_message.appendChild(tr5);
+	var tr6 = document.createElement("TR");
+	var td6_link  = document.createElement("TD");
+	var td6_input = document.createElement("TD");
+	tr6.appendChild(td6_link);
+	td6_input.appendChild(divfiles);
+	tr6.appendChild(td6_input);	
+	tbody_message.appendChild(tr6);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr5 = document.createElement("TR");
+	var td5 = document.createElement("TD");	
+	td5.innerHTML = "&nbsp;";
+	var td_body = document.createElement("TD");
+	td_body.setAttribute("colSpan","2");
+	var div_body_position = document.createElement("DIV");
+	div_body_position.id = "body_position_" + ID;
+	td_body.appendChild(div_body_position);
+	tr5.appendChild(td5);
+	tr5.appendChild(td_body);
+	tbody_message.appendChild(tr5);
+// BEGIN MAKE THE SCROLL HEIGHT
+    var defaultWidth = document.body.clientWidth - (is_ie ? 200 : 195);
+	var _bar = document.getElementById("toolbar");
+	var _offset = 0;
+	if(_bar.style.visibility != 'hidden') 
+		_offset = _bar.offsetHeight ? _bar.offsetHeight :  _bar.clientHeight;		
+	var _div = document.createElement("DIV");
+	_div.id = "div_message_scroll_"+ID;
+	_div.style.height = document.body.clientHeight - _offset - 105;
+	content.style.height = document.body.clientHeight - _offset - 80;
+	_div.style.overflow = "auto";
+	_div.style.width = defaultWidth;
+	// END MAKE THE SCROLL HEIGHT
+
+	// Hide the contac tips and re-position the pallete color.
+	_div.onscroll = function() {
+		var intElemScrollTop = Element("div_message_scroll_"+ID).scrollTop;
+		if (!is_ie)
+			ColorPalette.repos(intElemScrollTop);
+		Tooltip.scrollChanged();
+	};
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	_div.appendChild(form);
+	content.appendChild(_div);
+	table_message.appendChild(tbody_message);
+	form.appendChild(table_message);
+	expresso.connector.loadScript("jscode/rich_text_editor");
+	RichTextEditor.loadEditor(ID);
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+	if(!expresso_offline)
+		draw_from_field(sel_from,tr1_1);
+	return ID;
+}
+
+//	Verify if any user is sharing his name/email address
+//	for use in the new messages's "From " field.
+function draw_from_field(sel_from,tr1_1){
+
+	var el_shared_users = Element("el_shared_users");
+	// The element was loaded and populated...so return.
+	if(el_shared_users){	
+		// Nothing to work...so return.
+		if(el_shared_users.options.length == 0)
+			return;
+		tr1_1.style.display = '';
+		for (var x = 0; x < el_shared_users.options.length; x++) {
+			var _option = document.createElement("OPTION");
+			_option.text = el_shared_users.options[x].text;
+			_option.value = el_shared_users.options[x].value;
+			sel_from.options[sel_from.options.length] = _option	;
+		}
+		return;
+	}
+	// Get the shared folders.....
+ 	var sharedFolders = new Array();
+	for(var i = 0; i < folders.length; i++) {
+		var x = folders[i].folder_id;
+      	if (folders[i].folder_parent == 'user'){
+      		sharedFolders[sharedFolders.length] = x;
+      	}
+    }
+
+    var matchUser = '#';
+    var sharedUsers = new Array();
+  	// Filter the shared folders (only root folders) .....
+   	for(var i = 0; i < sharedFolders.length; i++) {
+      if(!sharedFolders[i].match(matchUser)) {
+		matchUser = sharedFolders[i];
+		sharedUsers[sharedUsers.length] = matchUser.substring(("user"+cyrus_delimiter).length,matchUser.length);
+      }
+    }
+
+	// Handler function for cExecute
+	var h_user = function(data) {
+		if(data.length > 0) {
+			tr1_1.style.display = '';
+			var _option = document.createElement("OPTION");
+			_option.text =  '"'+data.myname+'" <'+Element("user_email").value+'>';
+			_option.value  = data.myname+";"+Element("user_email").value;
+			sel_from.options[sel_from.options.length] = _option;
+	
+			var options = '';
+			for (var x = 0; x < data.length; x++)	{
+				var _option = document.createElement("OPTION");
+				_option.text = '"'+data[x].cn[0] + '" <'+data[x].mail[0]+'>';
+				_option.value = data[x].cn[0] + ';'+data[x].mail[0]+';'+data[x].save_shared[0]+';'+data[x].uid[0];
+				sel_from.options[sel_from.options.length] = _option	;
+			}
+		}
+		var shared_users_from = Element("el_shared_users");
+		if(!shared_users_from) {
+			shared_users_from = sel_from.cloneNode(true);
+			shared_users_from.id = "el_shared_users";
+			shared_users_from.style.display = 'none';
+			document.body.appendChild(shared_users_from);
+		}
+	}
+	// First time, so execute.....
+	cExecute ("expressoMail1_2.ldap_functions.getSharedUsersFrom&uids="+sharedUsers.join(';'), h_user);
+}
+
+function changeBgColorToON(all_messages, begin, end){
+	for (begin; begin<=end; begin++)
+	{
+		add_className(all_messages[begin], 'selected_msg');
+		Element("check_box_message_" + all_messages[begin].id).checked = true;
+	}
+}
+function updateBoxBgColor(box){
+	// Set first TR Class
+	var _className = 'tr_msg_read2';
+	for(var i = 0; i < box.length;i++){	
+		if(exist_className(box[i],_className))
+			remove_className(box[i], _className);
+		_className = (_className == 'tr_msg_read2' ? 'tr_msg_read' : 'tr_msg_read2');
+		if(!exist_className(box[i],_className))
+			add_className( box[i], _className);
+	}
+}
+
+function changeBgColor(event, msg_number){
+	actual_tr = Element(msg_number);
+
+	if (event.shiftKey)
+	{
+		last_tr = Element(last_message_selected);
+		if(!last_tr)
+			last_tr = actual_tr;
+
+		all_messages = actual_tr.parentNode.childNodes;
+		
+		for (var i=0; i < all_messages.length; i++)
+		{
+			if (actual_tr.id == all_messages[i].id)
+				first_order = i;
+			if (last_tr.id == all_messages[i].id)
+				last_order = i;
+		}
+		
+		if (parseInt(first_order) > parseInt(last_order))
+			changeBgColorToON(all_messages, last_order, first_order);
+		else
+			changeBgColorToON(all_messages, first_order, last_order);
+	}
+	else{
+		//if ( exist_className(actual_tr, 'selected_msg') )
+		if ( Element('check_box_message_' + msg_number).checked )
+			add_className(actual_tr, 'selected_msg');
+		else
+			remove_className(actual_tr, 'selected_msg');
+	}
+	last_message_selected = msg_number;
+}
+
+function build_quota(data){
+	id = "content_quota";
+	q_limit = data['quota_limit'];
+	var div	= document.getElementById(id);
+	if(!q_limit){
+	    div.innerHTML = '<span><font size="2" style="color:red"><strong>'+get_lang("Without Quota")+'</strong></font></span>';
+	}
+	else{
+	if(div)
+		div.innerHTML = '';
+	value = data['quota_percent'];
+	q_used = data['quota_used'];
+	table = document.getElementById("table_quota");
+	if(table)
+		table.parentNode.removeChild(table);
+	table = document.createElement("TABLE");	
+	tbody = document.createElement("TBODY");	
+	table.appendChild(tbody);
+	table.id = "table_quota";
+	table.width="102";
+	table.border="0";
+	table.cellSpacing = 0;
+	table.cellPadding = 0;
+	
+	//tr1 = document.createElement("TR");
+	td11 = document.createElement("TD");
+	td11.align="center";
+	td11.setAttribute("noWrap","true");
+	td11.innerHTML += '&nbsp;<span class="boxHeaderText">' + value+"% ("+q_used+"M/"+q_limit+"M)</span>";
+	//tr1.appendChild(td11);
+	
+	tr2 = document.createElement("TR");
+	td21 = document.createElement("TD");
+	td21.setAttribute("noWrap","true");
+	td21.height="15";
+	td22 = document.createElement("TD");	
+	td21.setAttribute("background","../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","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_quota(data){
+	build_quota(data);
+}
+
+function update_quota(folder_id){
+	cExecute ("expressoMail1_2.imap_functions.get_quota&folder_id="+folder_id,build_quota);
+}
+
+function draw_search(headers_msgs){
+	Element("border_id_0").innerHTML = "&nbsp;&nbsp;" + get_lang('Search Result') + "&nbsp;&nbsp;";
+
+	var tbody = Element('tbody_box');
+	for (var i=0; i<(headers_msgs.length); i++){
+		var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
+		if (tr)
+			tbody.appendChild(tr);
+	}
+}
+
+function draw_search_header_box(){
+	var table_message_header_box = Element("table_message_header_box");
+	table_message_header_box.parentNode.removeChild(table_message_header_box);
+
+	var content_id_0 = Element("content_id_0");
+	var table_element = document.createElement("TABLE");
+	var tbody_element = document.createElement("TBODY");
+	table_element.setAttribute("id", "table_message_header_box");
+	table_element.className = "table_message_header_box";
+	tr_element = document.createElement("TR");
+	tr_element.className = "message_header";
+	td_element1 = document.createElement("TD");
+	td_element1.setAttribute("width", "1%");
+	chk_box_element = document.createElement("INPUT");
+	chk_box_element.id  = "chk_box_select_all_messages";
+	chk_box_element.setAttribute("type", "checkbox");
+	chk_box_element.className = "checkbox";
+	chk_box_element.onclick = function(){select_all_messages(this.checked);};
+	chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
+	chk_box_element.onkeydown = function (e){
+		if (is_ie)
+		{
+			if ((window.event.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+		else
+		{
+			if ((e.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+	};
+	
+	td_element1.appendChild(chk_box_element);
+	td_element2 = document.createElement("TD");
+	td_element2.setAttribute("width", "3%");
+	td_element3 = document.createElement("TD");
+	td_element3.setAttribute("width", "30%");
+	td_element3.id = "message_header_SORTFROM";
+	td_element3.align = "left";
+	td_element3.innerHTML = get_lang("From");
+	td_element4 = document.createElement("TD");
+	td_element4.setAttribute("width", "49%");
+	td_element4.id = "message_header_SORTSUBJECT";
+	td_element4.align = "left";
+	td_element4.innerHTML = get_lang("Subject");	
+	td_element5 = document.createElement("TD");
+	td_element5.setAttribute("width", "10%");
+	td_element5.id = "message_header_SORTARRIVAL";
+	td_element5.align = "center";
+	td_element5.innerHTML = "<B>"+get_lang("Date")+"</B>";	
+	td_element5.innerHTML += "<img src ='templates/"+template+"/images/arrow_descendant.gif'>";
+	td_element6 = document.createElement("TD");
+	td_element6.setAttribute("width", "10%");
+	td_element6.id = "message_header_SORTSIZE";
+	td_element6.align = "right";
+	td_element6.innerHTML = get_lang("Size");
+	tr_element.appendChild(td_element1);
+	tr_element.appendChild(td_element2);
+	tr_element.appendChild(td_element3);
+	tr_element.appendChild(td_element4);
+	tr_element.appendChild(td_element5);
+	tr_element.appendChild(td_element6);
+	
+	tbody_element.appendChild(tr_element);
+	table_element.appendChild(tbody_element);
+	content_id_0.appendChild(table_element);
+}
+
+function draw_search_division(msg){
+	var tbody = Element('tbody_box');
+	var tr = document.createElement("TR");
+	var td = document.createElement("TD");
+	td.colSpan = '7';
+	td.width = '100%';
+
+	var action_info_table = document.createElement("TABLE");
+	var action_info_tbody = document.createElement("TBODY");
+	
+	action_info_table.className = "action_info_table";
+	action_info_table.width = "100%";
+	
+	var action_info_tr = document.createElement("TR");
+	
+	var action_info_th1 = document.createElement("TH");
+	action_info_th1.width = "40%";
+	action_info_th1.innerHTML = "&nbsp;";
+
+	var action_info_th2 = document.createElement("TH");
+	
+	action_info_th2.innerHTML = msg;
+	action_info_th2.className = "action_info_th";
+	action_info_th2.setAttribute("noWrap", "true");
+	
+	var action_info_th3 = document.createElement("TH");
+	action_info_th3.width = "40%";
+	action_info_th3.innerHTML = "&nbsp;";
+	
+	action_info_tr.appendChild(action_info_th1);
+	action_info_tr.appendChild(action_info_th2);
+	action_info_tr.appendChild(action_info_th3);
+	action_info_tbody.appendChild(action_info_tr);
+	action_info_table.appendChild(action_info_tbody);
+
+	td.appendChild(action_info_table);
+	tr.appendChild(td);
+	tbody.appendChild(tr);
+}
+
+function draw_search_box(){
+	var content_id_0 = Element("content_id_0");
+	var table = document.createElement("TABLE");
+	table.id = "table_box";
+	table.width = 'auto';
+	var tbody = document.createElement("TBODY");
+	tbody.id = "tbody_box";
+
+	table.className = "table_box";
+	table.setAttribute("frame", "below");
+	table.setAttribute("rules", "none");
+	table.setAttribute("cellpadding", "0");
+	table.onkeydown = function (e){
+		if (is_ie)
+		{
+			if ((window.event.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+		else
+		{
+			if ((e.keyCode) == 46)
+			{
+				//delete_all_selected_msgs_imap();
+				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
+			}
+		}
+	};
+	if (is_ie)
+		table.style.cursor = "hand";
+	
+	table.appendChild(tbody);
+	content_id_0.appendChild(table);
+}
+	var idx_cc = 0;
+function draw_plugin_cc(ID, addrs)
+{
+	expresso.connector.loadScript("jscode/ccQuickAdd");
+
+	var array_addrs = '';
+	var array_name 	= '';	
+	var cc_data = new Array();
+	if(typeof(addrs.name) != 'undefined') {	
+		array_name 	= LTrim(addrs.name).split(" ");
+		array_addrs = new Array(addrs.email);		
+	}
+	else {
+		array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
+		array_name 	= LTrim(array_addrs[0]).replace('"','').split(" ");	
+	}
+
+	var _split = array_name[0].split('@');
+	cc_data[0] = _split[0];
+	cc_data[1] = _split[0];
+	cc_data[2] = '';
+
+	for (i=1; i < array_name.length; i++)
+		cc_data[2] += array_name[i] + " ";			
+	
+
+	if(array_addrs.length > 1)			
+		cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';		
+	else
+		cc_data[3] = array_addrs[0];
+	
+	var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
+	'" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="./templates/'+template+'/images/user_card.png">';
+	var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
+	to_addybook_add += addrs;
+	to_addybook_add +=  sm_envelope_img1;
+	idx_cc++;
+	to_addybook_add += "</SPAN>";
+	return to_addybook_add;
+}
+function deny_email(email){
+	expresso.connector.loadScript("jscode/filter");
+	expresso.connector.loadScript("jscode/filters");
+	var dn_em 	= document.createElement("SPAN");
+		dn_em.id = "tt_d";
+		dn_em.onclick = function(){filter_rules.new_rule(email);};
+		dn_em.setAttribute("title",get_lang("Block Sender"));
+		dn_em.style.cursor = "pointer";		
+		dn_em.innerHTML = "<img align='top' onclick=filter.new_rule('"+email+"') src='./templates/"+template+"/images/deny.gif'>";
+	return dn_em;
+	
+}
+function show_div_address_full(id, type) {
+	var div_address_full = Element("div_"+type+"address_full_"+id);
+	if(!div_address_full) {
+		div_address_full = document.createElement("SPAN");
+		div_address_full.id = "div_"+type+"address_full_"+id;	
+		div_address_full.style.display="none";	
+		var _address = eval(type+"address_array['"+id+"']");
+		var isOverLimit = (_address.length > 100);
+		
+		if(isOverLimit) {
+			alert("Esse campo possui muitos endereços ("+_address.length+" destinatários).\r\n"+
+			"Para evitar o travamento do navegador, o botão 'Adicionar Contato' foi desabilitado!");
+		}
+
+		for(var idx = 1 ; idx  < _address.length;idx++) {
+			div_address_full.innerHTML += isOverLimit ?  '<br>'+_address[idx] : ','+draw_plugin_cc(id,_address[idx]);
+		}		
+		div_address_full.innerHTML += " (<a STYLE='color: RED;' onclick=document.getElementById('div_"+type+"address_full_"+id+"').style.display='none';document.getElementById('div_"+type+"address_"+id+"').style.display='';>"+get_lang('less')+"</a>)";
+		Element(type+"_"+id).appendChild(div_address_full);
+	}
+	Element('div_'+type+'address_'+id).style.display='none';
+	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/doiMenuData.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/doiMenuData.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/doiMenuData.js	(revision 2517)
@@ -0,0 +1,285 @@
+_icon_dir="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=\"templates/"+template+"/images/menu/"+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 2517)
+++ trunk/expressoMail1_2/js/jscode/DropDownContacts.js	(revision 2517)
@@ -0,0 +1,327 @@
+/**********************************************************************************\
+* 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 table_contacts_header = "<table style='font-family:arial;font-size:12;color:#0000CF' border=0 cellpadding=0 cellspacing=0>";
+	var table_contacts_foot = "</table>";
+	var lines = '';
+	var REG_EXP = /^[^\#|^\$|^\%|^\!|^\?|^\"|^\']+$/;
+	var match_cont = "";
+	for (var i=0; i<match_contacts.length; i++)
+	{
+		var aux = match_contacts[i].split("");
+		for(var j in aux){
+			if(REG_EXP.test(aux[j])){
+				match_cont += aux[j];
+			}else{
+				match_cont += "";
+			}
+		}
+		//lines = lines + "<tr><td id=td_DD_"+i+" onClick=\"javascript:hideTip();makeMailList('"+match_contacts[i]+"','"+fld_id+"');document.getElementById('" + fld_id + "').focus();\" onmouseover=\"selectContact("+i+")\">" + match_contacts[i] + "</td></tr>"
+		lines = lines + "<tr><td id=td_DD_"+i+" onMouseDown=\"javascript:hideTip();makeMailList('"+match_cont+"','"+fld_id+"');setTimeout('document.getElementById(\\'"+fld_id+"\\').focus()',300);\" onmouseover=\"selectContact("+i+")\">" + match_cont + "</td></tr>"
+		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 != ''){
+		table_contacts = table_contacts_header + lines + table_contacts_foot
+		doTooltip(posX, posY, table_contacts)
+	}
+	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() {
+            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 ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = 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;
+			}
+		}
+	}
+}
+Tooltip.init();
+// 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/jscode/color_palette.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/color_palette.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/color_palette.js	(revision 2517)
@@ -0,0 +1,96 @@
+// Inicializa palheta de cores;
+function cColorPalette(){
+	this.editor;
+	this.div;
+	this.parentDiv;
+	this.colors = new Array(	new Array("#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF"),
+						new Array("#CCCCCC","#FF6666","#FF9966","#FFFF66","#FFFF33","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF"),
+						new Array("#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC"),
+						new Array("#999999","#CC0000","#ff6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC"),
+						new Array("#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399"),
+						new Array("#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366"),
+						new Array("#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"));
+	this.buildPalette();
+}
+
+// funçoes
+cColorPalette.prototype.changeFontColor = function (color){	
+	var mainField = this.editor.contentWindow;
+	mainField.document.execCommand("forecolor", false, color);	
+	document.getElementById("palettecolor").style.visibility="hidden";
+	mainField.focus();
+}
+
+cColorPalette.prototype.repos = function (intElemScrollTop)
+{
+	var new_pos = findPosY(Element("forecolor")) - intElemScrollTop + 20;
+	this.div.style.top = new_pos;
+}
+
+cColorPalette.prototype.loadPalette = function (id)
+{
+	this.parentDiv = document.getElementById("body_position_"+id);
+	this.editor = document.getElementById("body_"+id);
+	if(this.div.parentNode)
+		this.div.parentNode.removeChild(this.div);	
+
+	this.parentDiv.appendChild(this.div);	
+	this.div.style.position = "absolute";
+
+	if(is_ie)
+	{
+		this.div.style.top = findPosY(Element("forecolor")) - 100;
+		this.div.style.left = findPosX(Element("forecolor"))- 200;
+	}
+	else
+	{
+		this.div.style.top = ColorPalette.repos(Element("div_message_scroll_"+id).scrollTop);
+		this.div.style.left = findPosY(Element("forecolor"))+ 227;
+	}
+}
+
+cColorPalette.prototype.buildPalette = function (){
+	
+  	this.div = document.createElement("DIV");
+	this.div.style.visibility="hidden";
+  	this.div.id= "palettecolor";
+  	this.div.style.top = "0px";
+  	this.div.style.left = "0px";
+  	this.div.style.width	= "auto";
+  	this.div.style.height= "auto";
+  	var t1 = document.createElement("TABLE");
+ 	var tb1 = document.createElement("TBODY");
+ 	t1.appendChild(tb1);
+  	t1.border ="1px";
+	t1.cellPadding ="0px";
+	t1.cellSpacing ="0px";
+ 	t1.style.width = "100px";
+ 	t1.bgcolor = "WHITE";
+  	this.div.appendChild(t1);
+  	_this = this;
+  	for( i = 0; i < 10; i++) {
+  		var _tr = document.createElement("TR");
+		tb1.appendChild(_tr);		
+  		for( j = 0; j < 7; j++) {
+			var _td = document.createElement("TD");
+  			_td.style.background =  this.colors[j][i];
+	  		_td.unselectable = "on";
+  			_td.style.width = "15px";
+  			_td.style.height = "15px";
+  			_td.title =   this.colors[j][i];
+  			_td.id =   this.colors[j][i];
+  			_td.className = "unsel_color";
+	  		_td.onclick= function(){ document.getElementById("palettecolor").style.visibility="hidden";ColorPalette.changeFontColor(this.id);};
+	  		_td.onmouseover = function(){ this.className = "sel_color";};
+	  		_td.onmouseout = function(){ this.className = "unsel_color";}
+			var p = new Image();
+  			p.style.width='1px';
+  			p.style.height='1px';
+			_td.appendChild(p);
+	  		_tr.appendChild(_td);
+  		}
+	}
+}
+
+/* Build the Object */
+var ColorPalette = new cColorPalette();
Index: trunk/expressoMail1_2/js/jscode/QuickCatalogSearch.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/QuickCatalogSearch.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/QuickCatalogSearch.js	(revision 2517)
@@ -0,0 +1,539 @@
+	function emQuickCatalogSearch ()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this.cc_contacts = new Array();
+		this.cc_groups  = new Array();
+	}
+
+	emQuickCatalogSearch.prototype.showList = function(data, begin, end){
+		id = '1';
+		_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 = 'window_QuickCatalogSearch';
+		document.body.appendChild(el);
+		el.innerHTML = "";
+		
+		if (document.getElementById('select_QuickCatalogSearch') == null){
+
+			var title_innerHTML = get_lang('Select a name') + ':';
+			if (data.quickSearch_only_in_userSector)
+				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
+
+			var title = document.createElement("SPAM");
+			title.id = 'window_QuickCatalogSearch_title';
+			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
+			el.appendChild(title);
+			
+			var cmb = document.createElement("SELECT");
+			cmb.id = "select_QuickCatalogSearch";
+			cmb.style.width = "685px";
+			cmb.size = "12";
+			cmb.onkeypress = function (e)
+			{
+				if (is_ie)
+				{
+					if ((window.event.keyCode) == 13)
+					{
+						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
+					}
+					else if ((window.event.keyCode) == 27)
+					{
+						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
+					}
+				}
+				else
+				{
+					if ((e.keyCode) == 13)
+					{
+						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
+					}
+					else if ((e.keyCode) == 27)
+					{
+						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
+					}
+				}
+			};
+			el.appendChild(cmb);
+
+			var space = document.createElement('SPAN');
+			space.innerHTML = "<BR>&nbsp;&nbsp;";
+			el.appendChild(space);
+
+			var butt = document.createElement('BUTTON');
+			var buttext = document.createTextNode('OK');
+			butt.id = "QuickCatalogSearch_button_ok";
+			butt.appendChild(buttext);
+			butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
+			el.appendChild(butt);
+
+			var space = document.createElement('SPAN');
+			space.innerHTML = "&nbsp;&nbsp;";
+			el.appendChild(space);
+
+			var butt = document.createElement('BUTTON');
+			butt.id = "QuickCatalogSearch_button_close";
+			var buttext = document.createTextNode(get_lang('Close'));
+			butt.appendChild(buttext);
+			butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
+			el.appendChild(butt);
+		}
+		else{
+			var title_innerHTML = get_lang('Select a name') + ':';
+			if (data.quickSearch_only_in_userSector)
+				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
+
+			var title = Element('window_QuickCatalogSearch_title');
+			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
+			
+			var cmb = document.getElementById('select_QuickCatalogSearch');
+			cmb.onkeypress = function (e)
+			{
+				if (is_ie)
+				{
+					if ((window.event.keyCode) == 13)
+					{
+						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
+					}
+					else if ((window.event.keyCode) == 27)
+					{
+						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
+					}
+				}
+				else
+				{
+					if ((e.keyCode) == 13)
+					{
+						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
+					}
+					else if ((e.keyCode) == 27)
+					{
+						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
+					}
+				}
+			};
+
+			for (i=0; i<cmb.length; i++)
+				cmb.options[i--] = null;
+			
+			var butt_ok = document.getElementById("QuickCatalogSearch_button_ok");
+			var butt_close = document.getElementById("QuickCatalogSearch_button_close");
+			butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
+			butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
+		}
+
+		for (i=0; i<data.length; i++){
+			var Op = document.createElement("OPTION");
+			Op.text = data[i].cn + ' (' + data[i].mail + ')';
+			if (data[i].phone != '')
+				Op.text += ' - ' + data[i].phone;
+			if (data[i].ou != '')
+				Op.text += ' - ' + data[i].ou; // adicionado "data[i].ou" para exibir setor (F9)
+			Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
+			cmb.options.add(Op);
+		}
+		cmb.options[0].selected = true;
+		_this.showWindow(el);
+	}
+	
+	emQuickCatalogSearch.prototype.showWindow = function (div)
+	{
+		if(! div) {
+			alert(get_lang('The list has no participant.'));
+			return;
+		}
+							
+		if(! this.arrayWin[div.id]) {
+			div.style.width = "700px";
+			div.style.height = "230px";
+			var title = get_lang('The results were found in the Global Catalog')+':';
+			var wHeight = div.offsetHeight + "px";
+			var wWidth =  div.offsetWidth   + "px";
+			div.style.width = div.offsetWidth - 5;
+
+			win = new dJSWin({			
+				id: 'QuickCatalogSearch_'+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];
+		}
+		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "";
+		win.open();
+		document.getElementById('select_QuickCatalogSearch').focus();
+	}
+	
+	emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){
+		cm = document.getElementById('select_QuickCatalogSearch');
+		option_selected = cm.options[cm.selectedIndex].value + ", ";
+		emailList = document.getElementById(field + "_" + ID).value;
+		
+		new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length);
+		document.getElementById(field + "_" + ID).value = new_emailList;
+		document.getElementById(field + "_" + ID).focus();
+		
+		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
+		this.arrayWin['window_QuickCatalogSearch'].close();
+	}
+	
+	emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){
+		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
+		document.getElementById(field + "_" + ID).focus();
+		this.arrayWin['window_QuickCatalogSearch'].close();
+	}
+
+	emQuickCatalogSearch.prototype.close_window = function(id) {
+		this.arrayWin[id].close();
+		var group_values = Element('list_values');
+		var user_values = Element('user_values');	
+	}
+	emQuickCatalogSearch.prototype.showCatalogList = function (border_id){
+		var el = Element('catalog_list');
+
+		if(el) {
+			Element('border_id').value = border_id;
+			win = this.arrayWin[el.id];
+			win.open();
+			return;		
+		}
+		var border_input   = document.createElement("INPUT");
+		border_input.type  = 'hidden';
+		border_input.id    = 'border_id';
+		border_input.value = border_id;
+		document.body.appendChild(border_input);
+		el = document.createElement("DIV");		
+		el.id = 'catalog_list';
+		document.body.appendChild(el);			
+		el.style.visibility = "hidden";
+		el.style.position = "absolute";
+		el.style.width = "700px";
+		el.style.height = is_ie ? "360px" : "375px";		
+		el.style.left = "0px";
+		el.style.top = "0px";			
+		el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+
+					   "<tr><td id='td1' style='cursor:pointer' align='center' onclick='QuickCatalogSearch.select_div(\"tab1\")'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab1\");'>"+get_lang('Global Catalog')+"</a></td>"+
+					   "<td id='td2' style='background:#cecece;cursor:pointer' onclick='QuickCatalogSearch.select_div(\"tab2\")' align='center'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab2\");'>"+get_lang('Personal Catalog')+"</a></td></tr>"+
+					   '</table>'+
+					   '<div id="tab1" align="center"><br>'+
+					   '<table border="0" cellpading="0" cellspacing="0">'+
+					   '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+'&nbsp;:</td></tr>'+
+  					'<tr><td><select style="display:none;width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select>&nbsp'+
+					'<select id="select_organization" style="width:150px" name="select_organization"></select>&nbsp;'+   
+					'<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="30"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:visible" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
+					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type_l" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" id="type_u" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
+					   '<span style="visibility:hidden;background:#cc4444" id=msg_search>&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font>&nbsp;</span></td></tr>'+
+					   '<tr><td>'+
+				  	   '<span id="list_span"><select multiple style="display:none;width:580px" size="14" id="list_values"></select></span>'+
+				  	   '<span id="user_span"><select multiple style="width:580px" size="14" id="user_values"></select></span>'+
+				 	   '</td></tr>'+
+					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to\')">&nbsp;'+
+				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')">&nbsp;'+
+				   	   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">'+
+				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
+					   '</table>'+
+					   '</div>'+
+					   '<div style="display:none" id="tab2" align="center">'+
+					   '<br><br><br>'+
+					   '<table border="0" cellpading="0" cellspacing="0">'+
+					   '<tr><td>'+get_lang("Select the type of contact that you want to view")+'&nbsp;:</td></tr>'+
+					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" type="radio" name="type" value="p"/>' + get_lang('People') + '&nbsp;&nbsp;<input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>' + get_lang('Groups') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
+					   '<tr><td>'+
+				  	   '<span id="personal_span"><select multiple style="width:580px" size="14" id="list_personal"></select></span>'+
+				  	   '<span id="groups_span"><select multiple style="display:none;width:580px" size="14" id="list_groups"></select></span>'+
+				 	   '</td></tr>'+
+					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to1\')">&nbsp;'+
+				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')">&nbsp;'+
+				   	   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">'+
+				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
+					   '</table>'+
+					   '</div>';
+
+		var title = get_lang('Search in the Global Catalog');
+		var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px";
+		var wWidth =  el.offsetWidth   + "px";
+		el.style.width = el.offsetWidth;
+		
+		Element('search_for').onkeypress = function (e) {
+			if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) {
+				QuickCatalogSearch.searchCatalogList(true);
+			}
+		};
+
+		win = new dJSWin({			
+			id: 'win_'+el.id,
+			content_id: el.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[el.id] = win;		
+		win.draw();
+		win.open();
+
+		var handler_catalogs = function(data){
+			var user_catalog = get_lang("Global Catalog");
+			if(data.length > 1) {
+				Element('select_catalog').style.display = '';
+				for(i = 0; i < data.length; i++) {		
+					Element('select_catalog').options[i] = new Option(data[i],i);
+					if(user_catalog.toUpperCase() == data[i].toUpperCase())
+						Element('select_catalog').options[i].selected = true;
+				}
+			}
+		}
+		cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs);		
+		
+		this.update_organizations();
+		var handler_cc_contacts= function(data){
+			if(data && data.length > 0){
+				var aux = data.split(",");
+				for(var i=0; i< aux.length; i++){
+					QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i];				
+				}
+			}
+		}
+		cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts);
+
+		var handler_cc_groups = function(data){
+			if(data && data.length > 0){
+				var aux = data.split(",");
+				for(var i=0; i < data.length; i++){
+					QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i];								
+				}	
+			}
+		}
+		cExecute("$this.db_functions.get_cc_groups",handler_cc_groups);
+	
+	}
+	
+	emQuickCatalogSearch.prototype.select_div = function(element){
+		if(element == 'tab1'){
+		   Element('tab1').style.display = '';
+		   Element('tab2').style.display = 'none';
+		   Element('td1').style.background = '#eee';	
+		   Element('td2').style.background = '#cecece';
+		}
+		if(element == 'tab2'){
+		   Element('tab1').style.display = 'none';
+		   Element('tab2').style.display = '';
+		   Element('td1').style.background = '#cecece';
+		   Element('td2').style.background = '#eee';		   
+
+		}
+	}
+	
+	emQuickCatalogSearch.prototype.load_catalog = function(){
+	
+		var _this = this;
+		var content = new Array;
+		var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal');
+		
+		if(Element('list_personal').style.display == 'none'){
+			content = _this.cc_groups;
+		}else{
+			content = _this.cc_contacts;
+		}
+		if(select.options.length > 0){
+			for(var i=0; i < select.options.length; i++){
+				select.options[i] = null;
+				i--;
+			}
+		}
+		for(var i=0; i < content.length; i++){
+			if(content[i] != undefined){
+				var aux = content[i].split(";");
+				var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false);
+				select[select.length] = opt;
+			}
+		}
+		content.splice(0,(content.lenght));
+	}
+
+	emQuickCatalogSearch.prototype.update_organizations = function(){
+		while(Element('select_organization').options.length > 0) {
+			Element('select_organization').remove(0);
+		}
+	 	var handler_org = function(data){
+			Element('select_organization').options[0] = new Option(get_lang('all'),'all');
+			if (data != null){
+				var user_organization = Element('user_organization').value;
+				for(x = 0; x < data.length; x++) {
+					Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]);
+					if(user_organization.toUpperCase() == data[x].toUpperCase())
+						Element('select_organization').options[x+1].selected = true;
+				}
+			}
+		}		
+		cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org);		
+	}
+
+	emQuickCatalogSearch.prototype.changeOptions = function(type){	
+
+		switch(type){
+			case 'u':
+				Element('list_values').style.display = 'none';
+				Element('user_values').style.display = '';
+				break;
+			
+			case 'l':		
+				Element('user_values').style.display = 'none';
+				Element('list_values').style.display = '';		
+				break;
+
+			case 'p':
+				Element('list_personal').style.display = '';
+				Element('list_groups').style.display = 'none'
+				QuickCatalogSearch.load_catalog();				
+				break;
+			
+			case 'g':
+				Element('list_personal').style.display = 'none';
+				Element('list_groups').style.display = ''
+				QuickCatalogSearch.load_catalog();
+				break;
+		}
+
+	}
+
+	emQuickCatalogSearch.prototype.addContacts = function(field) {
+		
+		var border_id 	= Element('border_id').value;
+ 		var select		= Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values');
+		if(field == "to1" || field == "cc1" || field == "cco1"){
+			field = field.substr(0,field.length - 1);
+			var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal');
+		}
+		var fieldOpener = Element(field+"_"+border_id);
+		var not_selected = true;		
+		for (i = 0 ; i < select.length ; i++) {			
+			if (select.options[i].selected && select.options[i].value != '-1') {
+				if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length -1))){
+					fieldOpener.value += ",";
+				}
+				fieldOpener.value += select.options[i].value + ",";
+				not_selected = false;
+				select.options[i].selected = false;
+			}
+		}
+		
+		if(not_selected)
+			return false;
+			
+		if(field != 'to'){
+ 			a_link = Element("a_"+field+"_link_"+border_id);
+ 			if(a_link)
+ 				a_link.onclick(); 			
+ 		}				
+	}
+	
+	emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){
+
+		if(itemSearch && Element('search_for').value.length < preferences.search_characters_number){
+			alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
+			Element('search_for').focus();
+			return false;
+		}
+		var organization = Element('select_organization').value;		
+		var search		 = itemSearch ? Element('search_for').value : '';
+		var catalog		 = Element('select_catalog').value;
+		var max_result	= 400;
+
+		var handler_searchResults = function(data){
+			Element('msg_search').style.visibility = 'hidden';
+			if(data.error){
+				alert(get_lang('More than %1 results. Please, try to refine your search.',max_result));
+				return false;
+			}else if(data.users.length == 0 && data.groups.length == 0){
+				alert(get_lang('None result was found.'));
+			}
+
+			
+			var group = Element('list_span');
+			var user  = Element('user_span');	
+			if(is_ie){
+				group.innerHTML = '';
+				user.innerHTML = '';
+			}
+			else {
+				group = Element('list_values');
+				user  = Element('user_values');	
+				for(var i = 0;i < group.options.length; i++)				
+					group.options[i--] = null;
+				for(var i = 0;i < user.options.length; i++)				
+					user.options[i--] = null;
+			}
+
+			var arr 	= new Array(max_result);
+
+			for(i = 0; data.groups && i < data.groups.length; i++) {
+				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
+				if(is_ie)
+					arr[i] = '<option value="'+'&quot;'+data.groups[i].name+'&quot; &lt;'+data.groups[i].email+'&gt;">'+data.groups[i].name+' ('+data.groups[i].email+')'+'</option>';
+				else
+					group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>');
+			}
+	
+			
+			if(is_ie)
+				group.innerHTML = '<select multiple style="display:none;width:580px" size="14" id="list_values">'+ arr.join() +'</select>';
+
+			arr = new Array(max_result);
+			
+			for(i = 0; data.users && i < data.users.length; i++) {
+			/*******************************************************************************************/
+			/* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela,
+			ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o
+			resultado apresentado em tela sera exibido de maneira mais apresentavel;
+			*/
+				//verifica se departamento eh null ou nao;
+				var department = data.users[i].department ? " - " + data.users[i].department : "";
+				//verifica se email eh null ou nao;
+				var email = data.users[i].email ? data.users[i].email : "";
+
+				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
+				if(is_ie)
+					arr[i] = '<option value="'+'&quot;'+data.users[i].name+'&quot; &lt;'+email+'&gt;">'+data.users[i].name+' ('+email+')'+department+'</option>';
+				else {
+					user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email;
+				}
+			}
+	
+			if(is_ie)
+				user.innerHTML = '<select multiple style="width:580px" size="14" id="user_values">'+ arr.join() +'</select>';
+
+			// Display entries found.
+			var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u';
+			Element("type_"+type).checked = true;
+			QuickCatalogSearch.changeOptions(type);
+		}
+
+		Element('msg_search').style.visibility = 'visible';
+		cExecute ("$this.ldap_functions.catalogsearch&max_result="+max_result+"&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults);
+	}
+
+	
+/* Build the Object */
+	var QuickCatalogSearch;
+	QuickCatalogSearch = new emQuickCatalogSearch();
Index: trunk/expressoMail1_2/js/jscode/rich_text_editor.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/rich_text_editor.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/rich_text_editor.js	(revision 2517)
@@ -0,0 +1,506 @@
+function cRichTextEditor(){
+	this.emwindow   = new Array;
+	this.editor = "body_1";
+	this.table = "";
+	this.id = "1";
+	this.buildEditor();
+	this.saveFlag = 0;
+}
+
+cRichTextEditor.prototype.loadEditor = function(ID) {
+	var _this = this;
+	_this.id = ID;
+	parentDiv = document.getElementById("body_position_"+this.id);
+	this.editor = "body_"+this.id;
+
+	if(this.table.parentNode)
+		this.table.parentNode.removeChild(this.table);
+	
+	if( parentDiv.firstChild )
+	{
+		if (!parentDiv.firstChild.hasChildNodes()) 
+			parentDiv.insertBefore(this.table,parentDiv.firstChild);
+	}
+	else
+		parentDiv.appendChild(this.table);
+
+	if(!Element(this.editor))
+	{
+		this.createElementEditor(this.editor);
+	}
+	else
+	{
+		Element("viewsource_rt_checkbox").checked=false;
+	}
+
+	document.getElementById('fontname').selectedIndex = 0;
+	document.getElementById('fontsize').selectedIndex = 0;
+}
+
+cRichTextEditor.prototype.createElementEditor = function(pObj)
+{
+		iframe = document.createElement("IFRAME");
+		iframe.id = pObj;
+		iframe.name = pObj;
+		iframe.width = "99%";
+		iframe.height = 300;
+		iframe.setAttribute("unselectable","on");
+		iframe.setAttribute("tabIndex","1");
+
+		config_events( iframe, 'onload', function( )
+		{
+			iframe.contentWindow.document.designMode = "on";
+			if ( iframe.contentWindow.document.documentElement )
+				iframe.contentWindow.document.documentElement.style.background = '#fff';
+				iframe.contentWindow.document.documentElement.style.fontSize = '16px';
+		});
+
+		var checkbox = document.createElement("INPUT");
+		checkbox.id = 'viewsource_rt_checkbox';
+		checkbox.type = "checkbox";
+		checkbox.setAttribute("tabIndex","-1");
+		checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)};
+		var text = document.createTextNode(get_lang('View HTML source') + '.');
+		parentDiv.appendChild(iframe);
+		parentDiv.appendChild(checkbox);
+		parentDiv.appendChild(text);
+}
+
+cRichTextEditor.prototype.viewsource = function(source) {
+	var html;
+	var mainField = document.getElementById(this.editor).contentWindow;
+	if (source) {
+		if (is_ie){
+			expresso.connector.loadScript('jscode/html2xhtml');
+			html = frames[this.editor].document.body;
+			var xhtml = get_xhtml(html, 'en', 'iso-8859-1');
+			frames[this.editor].document.body.innerText = xhtml;
+			document.getElementById("table_richtext_toolbar").style.visibility="hidden";
+		}
+		else{
+			html = document.createTextNode(document.getElementById(this.editor).contentWindow.document.body.innerHTML);
+			document.getElementById(this.editor).contentWindow.document.body.innerHTML = "";
+			html = document.getElementById(this.editor).contentWindow.document.importNode(html,false);
+			document.getElementById(this.editor).contentWindow.document.body.appendChild(html);
+			document.getElementById("table_richtext_toolbar").style.visibility="hidden";
+		}		
+	} else {
+		if (is_ie){
+			var output = escape(frames[this.editor].document.body.innerText);
+			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
+			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
+			frames[this.editor].document.body.innerHTML = unescape(output);
+			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
+		}
+		else{
+			html = document.getElementById(this.editor).contentWindow.document.body.ownerDocument.createRange();
+			html.selectNodeContents(document.getElementById(this.editor).contentWindow.document.body);
+			document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString();
+			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
+		}
+	}
+}
+
+cRichTextEditor.prototype.buildEditor = function() {
+	this.table = document.createElement("TABLE");
+	this.table.id = "table_richtext_toolbar";
+	this.table.className = "richtext_toolbar";
+	this.table.width = "100%";
+	var tbody = document.createElement("TBODY");
+	var tr = document.createElement("TR");
+	var td = document.createElement("TD");
+	var div_button_rt = document.createElement("DIV");
+	
+	selectBox=document.createElement("SELECT");
+	selectBox.id="fontname";
+	selectBox.setAttribute("tabIndex","-1");
+	selectBox.onchange = function () {RichTextEditor.Select("fontname");};
+	selectBox.className = 'select_richtext';
+	var option1 = new Option(get_lang('Font'), 'Font');
+	var option2 = new Option('Arial', 'Arial');
+	var option3 = new Option('Courier', 'Courier');
+	var option4 = new Option('Times New Roman', 'Times');
+	if (is_ie){
+		selectBox.add(option1);
+		selectBox.add(option2);
+		selectBox.add(option3);
+		selectBox.add(option4);
+	}
+	else{
+		selectBox.add(option1, null);
+		selectBox.add(option2, null);
+		selectBox.add(option3, null);
+		selectBox.add(option4, null);
+	}
+	div_button_rt.appendChild(selectBox);
+
+	selectBox=document.createElement("SELECT");
+	selectBox.id="fontsize";
+	selectBox.setAttribute("tabIndex","-1");
+	selectBox.setAttribute("unselectable","on");
+	selectBox.className = 'select_richtext';
+	selectBox.onchange = function () {RichTextEditor.Select("fontsize");};
+	var option1 = new Option(get_lang('Size'), 'Size');
+	var option2 = new Option('1 (8 pt)','1' );
+	var option3 = new Option('2 (10 pt)','2');
+	var option4 = new Option('3 (12 pt)','3');
+	var option5 = new Option('4 (14 pt)','4');
+	var option6 = new Option('5 (18 pt)','5');
+	var option7 = new Option('6 (24 pt)','6');
+	var option8 = new Option('7 (36 pt)','7');
+	if (is_ie){
+		selectBox.add(option1);
+		selectBox.add(option2);
+		selectBox.add(option3);
+		selectBox.add(option4);
+		selectBox.add(option5);
+		selectBox.add(option6);
+		selectBox.add(option7);
+		selectBox.add(option8);
+	}
+	else{
+		selectBox.add(option1, null);
+		selectBox.add(option2, null);
+		selectBox.add(option3, null);
+		selectBox.add(option4, null);
+		selectBox.add(option5, null);
+		selectBox.add(option6, null);
+		selectBox.add(option7, null);
+		selectBox.add(option8, null);	
+	}
+	div_button_rt.appendChild(selectBox);
+	
+	var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
+				   'undo', 'redo', 'insertorderedlist', 'insertunorderedlist', 'outdent', 'indent', 'link', 'image', 'table', 'signature'];
+
+	for (var i=0; i<buttons.length; i++){
+		var img = document.createElement("IMG");
+		img.id = buttons[i];
+		img.className = 'imagebutton';
+		img.align = 'center';
+		img.src = './templates/'+template+'/images/'+buttons[i]+'.gif';
+		img.title = get_lang(buttons[i]);
+		img.style.cursor = 'pointer';
+
+		if (buttons[i] == 'forecolor')
+			img.onclick = function () {RichTextEditor.show_pc('forecolor')};
+		else if (buttons[i] == 'link')
+			img.onclick = function () {RichTextEditor.createLink();};
+		else if (buttons[i] == 'image')
+			img.onclick = function () {RichTextEditor.createImage();};
+		else if (buttons[i] == 'table')
+			img.onclick = function () {RichTextEditor.createTable();};
+		else
+			img.onclick = function () {RichTextEditor.editorCommand(this.id,'');};
+		
+		img.onmouseover = function () {this.style.border="outset 2px";};
+		img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";};
+		div_button_rt.appendChild(img);
+	}
+
+	td.appendChild(div_button_rt);
+	tr.appendChild(td);
+	tbody.appendChild(tr);
+	this.table.appendChild(tbody);
+}
+
+cRichTextEditor.prototype.editorCommand = function(command, option) {
+	try {
+		var mainField = document.getElementById(this.editor).contentWindow;
+		mainField.focus();
+		var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
+		if (command == 'signature'){
+			if (is_ie){
+				var sel = document.selection;
+				if (sel!=null)
+				{
+				    var rng = sel.createRange();
+				    if (rng!=null)
+			        	rng.pasteHTML(signature);
+				}
+			}
+			else{
+				mainField.document.execCommand('inserthtml', false, signature);
+			}
+		}
+		else if (command == 'CreateLink')
+			mainField.document.execCommand('CreateLink', false, option);
+		else if (command == 'Table'){
+			if (is_ie){
+				var sel = document.selection;
+				if (sel!=null)
+				{
+				    var rng = sel.createRange();
+				    if (rng!=null)
+			        rng.pasteHTML(option);
+				}
+			}
+			else 
+				mainField.document.execCommand('inserthtml', false, option);
+			}
+		else if (command == 'Image')
+			mainField.document.execCommand('InsertImage', false, option);
+		else
+			mainField.document.execCommand(command, false, option);
+		//mainField.focus();
+    } catch (e) {/* alert(e);*/ }
+}
+
+cRichTextEditor.prototype.createLink = function(){
+	var mainField = document.getElementById(this.editor).contentWindow;
+	if (is_ie){
+		if ((mainField.document.selection.createRange().text) == ''){
+				alert(get_lang('Chose the text you want transform in link before.')); 
+			return;
+		}
+	}
+	else{
+		if (mainField.window.getSelection() == ''){
+				alert(get_lang('Chose the text you want transform in link before.')); 
+			return;
+		}
+	}
+		var szURL = prompt(get_lang('Enter with link URL:'), 'http://'); 
+	if ((szURL != null) && (szURL != "")){
+		this.editorCommand("CreateLink", szURL);
+	}
+}
+
+// It include the image file in emails body
+// It saves and attach in drafts folder and open it
+cRichTextEditor.prototype.addInputFile = function()
+{
+	//Begin: Verify if the image extension is allowed.
+	var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx");
+	var inputFile = document.getElementById('inputFile_img');	
+	if(!inputFile.value) 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;
+	}
+	// End: Verify image extension.
+	var id = this.editor.substr(5); // border_id
+	divFiles = document.getElementById("divFiles_"+id);
+	var countDivFiles = divFiles.childNodes.length + 1;
+
+	var divFiles = document.getElementById('divFiles_'+id);
+	inputFile.id = 'inputFile_'+id +"_"+countDivFiles;
+	inputFile.name = 'file_'+countDivFiles;
+	divFile = document.createElement('DIV');
+	divFile.appendChild(inputFile);
+	divFiles.appendChild(divFile);
+
+	var form_upload = document.getElementById('form_upload');
+	form_upload.parentNode.removeChild(form_upload);
+	win.close();
+
+	RichTextEditor.saveFlag = 0; // See if save function finished
+	var save_link = document.getElementById("save_message_options_"+id);
+	//save_link.onclick = function () {};
+	save_msg(id,true);
+	setTimeout("RichTextEditor.insertImgHtml("+id+")",1000);
+}
+
+cRichTextEditor.prototype.insertImgHtml = function (id){
+	if (RichTextEditor.saveFlag == 0)
+		setTimeout("RichTextEditor.insertImgHtml("+id+")",500);
+	else
+		if (RichTextEditor.saveFlag == 1)
+			this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=INBOX/'+draftsfolder+'&msg_num='+openTab.imapUid[id]+'&msg_part='+(openTab.countFile[id]+1));
+			// this.editorCommand('Image', '.inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params'));
+}
+
+cRichTextEditor.prototype.insertTableHtml = function (){
+	var id = this.editor.substr(5); // border_id
+	var	rows = document.getElementById('rows').value;
+	var	cols = document.getElementById('cols').value;
+	var border = document.getElementById('border').value;
+	var insertTable = '<table border="'+border+'px"><tbody>';
+	for (var i = 0; i < rows; i++){
+		insertTable += "<tr>";	
+		for (var j = 0; j < cols; j++)
+			insertTable += "<td>&nbsp;</td>";	
+		insertTable += "</tr>";
+	}
+	insertTable += "</tbody></table>";
+	this.editorCommand('Table', insertTable);
+}
+
+cRichTextEditor.prototype.createTable = function(){
+	var form = document.getElementById("table_window");
+	if (form == null){
+		form = document.createElement("DIV");
+		form.id  = "table_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);
+	}
+		
+		var form_table = document.createElement("DIV");
+		form_table.id = "form_table";
+		form_table.style.position = "absolute";
+		form_table.style.top = "5px";
+		form_table.style.left = "5px";
+		form_table.style.width = "190px";
+		form_table.style.height = "90px";
+		form_table.name = get_lang("Insert Table");		
+		form_table.innerHTML = get_lang('Select the table size')+':<br><br><table cellspacing="0"><tbody><tr><td align="center">'+
+								get_lang('Rows')+':</td><td></td><td align="center">'+get_lang('Cols')+':</td><td></td><td align="center">'+get_lang('Border')+':</td></tr>'+
+									'<tr><td align="right"><input type="text" readonly="true" id="rows" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'rows\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'rows\');"></img></td>'+
+									'<td align="right"><input type="text" readonly="true" id="cols" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'cols\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'cols\');"></img></td>'+
+									'<td align="right"><input type="text" readonly="true" id="border" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'border\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'border\');"></img></td>'+
+									'</tr></tbody></table>'+
+	  								'&nbsp;&nbsp;&nbsp;<input title="'+get_lang('Close')+'"  value="' + get_lang('Close') + '" type="button" onclick="win.close()">&nbsp;'+
+									'<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '" type="button" onclick="RichTextEditor.insertTableHtml();win.close();">';	
+		form.appendChild(form_table);
+		
+		this.showWindow(form);
+		}
+
+cRichTextEditor.prototype.incrementField = function(id_val){
+	var field_text = document.getElementById(id_val);
+	field_text.value = parseInt(field_text.value)+1;
+}
+
+cRichTextEditor.prototype.decrementField = function(id_val){
+	var field_text = document.getElementById(id_val);
+	if (parseInt(field_text.value) > 0)
+		field_text.value = parseInt(field_text.value)-1;
+}
+
+cRichTextEditor.prototype.createImage = function(){
+	if (preferences.auto_save_draft == 1){
+			autosave_time = 200000;
+			clearTimeout(openTab.autosave_timer[currentTab]);
+		}
+	var form = document.getElementById("attachment_window");
+	if (form == null){
+		form = document.createElement("DIV");
+		form.id  = "attachment_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);
+	}
+		var form_upload = Element('form_upload');
+		if (form_upload == null)
+			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("Upload File");
+		form_upload.style.width = "450px";
+		form_upload.style.height = "75px";
+		form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+
+								'<input name="image_at" maxlength="255" size="50" id="inputFile_img" type="file"><br>' +
+								'<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '"' + 'type="button" onclick="RichTextEditor.addInputFile();">&nbsp;' +
+								'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
+								' type="button" onclick="win.close()">';
+		form.appendChild(form_upload);
+		
+		this.showWindow(form);
+}
+cRichTextEditor.prototype.showWindow = function (div){
+
+		if(! div) {
+			return;
+		}
+		
+		if(! this.emwindow[div.id]) {
+			div.style.width  =  div.firstChild.style.width;
+			div.style.height = div.firstChild.style.height;
+			div.style.zIndex = "10000";			
+			var title = div.firstChild.name;
+			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.emwindow[div.id] = win;
+			win.draw();
+		}
+		else
+			win = this.emwindow[div.id];
+		win.open();	
+}
+
+cRichTextEditor.prototype.Select = function(selectname)
+{
+	var mainField = Element(this.editor).contentWindow;
+	var cursel = document.getElementById(selectname).selectedIndex;
+
+	if (cursel != 0) {
+		var selected = document.getElementById(selectname).options[cursel].value;
+		mainField.document.execCommand(selectname, false, selected);
+		document.getElementById(selectname).selectedIndex = cursel;
+	}
+	mainField.focus();
+}
+
+cRichTextEditor.prototype.show_pc = function(command)
+{
+	expresso.connector.loadScript("jscode/color_palette");
+	ColorPalette.loadPalette(this.id);
+  	if (ColorPalette.div.style.visibility != "visible")
+		ColorPalette.div.style.visibility="visible";
+	else
+		this.hide_pc();
+}
+
+cRichTextEditor.prototype.hide_pc = function()
+{
+	document.getElementById("palettecolor").style.visibility="hidden";
+}
+
+cRichTextEditor.prototype.getOffsetTop = function(elm) {
+  var mOffsetTop = elm.offsetTop;1
+  var mOffsetParent = elm.offsetParent;
+  while(mOffsetParent){
+    mOffsetTop += mOffsetParent.offsetTop;
+    mOffsetParent = mOffsetParent.offsetParent;
+  }
+  return mOffsetTop;
+}
+
+cRichTextEditor.prototype.getOffsetLeft = function(elm) {
+  var mOffsetLeft = elm.offsetLeft;
+  var mOffsetParent = elm.offsetParent;
+  while(mOffsetParent){
+    mOffsetLeft += mOffsetParent.offsetLeft;
+    mOffsetParent = mOffsetParent.offsetParent;
+  }
+  return mOffsetLeft;
+}
+
+//Build the Object
+RichTextEditor = new cRichTextEditor();
Index: trunk/expressoMail1_2/js/jscode/TreeShow.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/TreeShow.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/TreeShow.js	(revision 2517)
@@ -0,0 +1,315 @@
+/**************************************************************************\
+ Início 
+\**************************************************************************/
+
+	function Tree_Box(){
+		
+		this.name_folder = "";
+		this.name_func   = "";
+		expresso.connector.loadScript("jscode/TreeS");
+	}
+	Tree_Box.prototype.update_folder = function(){
+
+		var handler_update_folders = function(data){
+			folders = data;
+			// update element dftree_folders_tree;
+			ttree.make_tree(data,"div_tree","folders_tree","ttree.get_folder(\"root\")",ttreeBox.name_folder,ttreeBox.name_folder,false);
+			
+			// update element dftree_tree_folders;
+			if(Element('content_folders')){Element('content_folders').innerHTML = "";}
+			draw_tree_folders(folders);
+			
+			// update element dftree_wfolders_tree;
+			if (Element('dftree_wfolders_tree')){
+				Element('dftree_wfolders_tree').innerHTML = '';
+				ttree.make_tree(data,"wfolders_content_tree","wfolders_tree","","","",false);	
+			}
+			ttree.FOLDER = ttreeBox.name_folder;
+			if (tree_folders.getNodeById(ttree.FOLDER))
+				tree_folders.getNodeById(ttree.FOLDER)._select();
+			/*
+			if (tree_folders.getNodeById(get_current_folder()))
+				tree_folders.getNodeById(get_current_folder())._select();
+			*/
+		}
+		if(!expresso_offline)
+		{
+			expresso.connector.cacheNextRequest(1);
+			cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, handler_update_folders);		
+		}
+		else
+			handler_update_folders('');
+	}
+
+	Tree_Box.prototype.verify_children = function(param){
+		var aux;
+		var aux1;
+		var cont = parseInt(0);
+		for(var i=0 ; i < folders.length; i++){
+			aux = folders[i].folder_id.split(cyrus_delimiter);
+			aux.pop();
+			for(var j=0; j < aux.length; j++){
+				if(j == 0)
+					aux1 = aux[j];
+				else
+					aux1 += cyrus_delimiter + aux[j];
+			}
+			if( aux1 == param){
+				cont++;
+			}
+		}
+		if( cont == 0){
+			ttreeBox.del_past(param);
+		}else{
+                       alert(get_lang("Delete your sub-folders first"));
+		}
+		cont = parseInt(0);
+	}
+	
+	Tree_Box.prototype.verify = function(exp)
+ 	{
+                // IE does not understand regExp!!!
+		if (is_ie)
+			var reTipo = /[^a-z0-9 \-_+=]*$/i;
+		else
+			reTipo = /[^a-z0-9 \-_=áéíóúàèìòùâêôãõÃÕÁÉÍÓÚÀÈÌÒÙÂÊÔçÇüñ]/i;
+			
+        return reTipo.test(exp);
+ 	}
+
+ 	// Função para verificar o nome da caixa;
+ 	Tree_Box.prototype.verify_names = function(name_folder){
+	    var arr_nm_folder = new Array("INBOX",trashfolder,draftsfolder,sentfolder,spamfolder);
+ 		for(var i=0 ; i < arr_nm_folder.length; i++){
+ 			if(name_folder == arr_nm_folder[i]){
+				ttree.FOLDER = "";
+				return true;
+ 			}
+ 		}
+		return false;
+ 	}
+	
+	// Valida os nomes das pastas
+	Tree_Box.prototype.validate = function(func){
+		var aux = ttree.FOLDER.split(cyrus_delimiter);
+		var aux2;
+		if(ttree.FOLDER != ""){
+			if(aux.length > 1)
+			{
+				aux2 = aux[1];
+			}
+			else
+			{
+				aux2 = aux[0];
+			}
+			if(func == "rename" && this.verify_names(aux2)){
+			       alert(get_lang("It's not possible rename the folder: ") + lang_folder(aux2));
+			       return false;
+			}else{
+			if(func == "newpast"){
+	                    var button = prompt(get_lang('Enter the name of the new folder:'),"");
+					if (button.indexOf("local_") != -1  || button.toUpperCase() == "INBOX") {
+						alert(get_lang("cannot create folder. try other folder name"));
+						return false; //Não posso criar pastas contendo a string local_					
+					}
+
+					if(trim(button) == "" || trim(button) == null){
+						return false;
+					}else{
+						ttreeBox.new_past(button);
+					}
+				}
+				if(func == "rename"){
+					if(ttree.FOLDER == "root"){
+	                	alert(get_lang("It's not possible rename this folder!"));
+						return false;
+					}
+					if(ttree.FOLDER == get_current_folder()){
+                        alert(get_lang("It's not possible rename this folder, because it is being used in the moment!"));
+						return false;
+					}
+                    var button1 = prompt(get_lang("Enter a name for the box"), "");
+					if (button1.indexOf("local_") != -1 || button1.toUpperCase() == "INBOX") {
+						alert(get_lang("cannot create folder. try other folder name"));
+						return false; //Não posso criar pastas contendo a string local_					
+					}
+					if(trim(button1) == "" || trim(button1) == null){
+						return false;
+					}else{
+						ttreeBox.rename(button1);
+					}
+				}
+			}
+		}else{
+            alert(get_lang("Select a folder!"));
+			return false;
+		}
+	}
+
+// Para criar a nova pasta;
+	Tree_Box.prototype.new_past = function(newp){
+
+		var aux   = ttree.FOLDER.split(cyrus_delimiter);
+		var newp2 = "";
+		if( aux[0] == "root"){
+			if(this.verify(newp)){
+				alert(get_lang("The folder name must not contain special characters."));
+				newp = "";
+				return false;
+			}else{
+				newp2 = newp;
+				newp = "INBOX" + cyrus_delimiter + newp;
+			}
+		}else{
+			if(this.verify(newp)){
+				alert(get_lang("The folder name must not contain special characters."));
+				newp = "";
+				return false;
+			}else{
+				newp2 = newp;
+				newp = ttree.FOLDER + cyrus_delimiter + newp;
+			}
+		}
+
+		if(newp != ""){
+			var handler_return = function(data){		
+				if(data != "Ok"){
+					alert(get_lang(data));
+				}else{
+					ttreeBox.name_folder = "root"; //or use var newpast
+					this.name_func = "newpast";
+					expresso.connector.purgeCache();
+					ttreeBox.update_folder();
+				}
+			}
+			var args = "$this.imap_functions.create_mailbox";
+			var params = "newp="+newp;
+			cExecute(args,handler_return,params);
+		}	
+	}
+	
+	// Funcao para renomear a pasta;
+	Tree_Box.prototype.rename = function(rename){
+		var old_box  = ttree.FOLDER;
+		var aux = old_box.split(cyrus_delimiter);
+		var rename_new = "";
+		
+		if(old_box == "root"){
+            alert(get_lang("Select a folder!"));
+			return false;
+		}
+		if(aux.length == 1){
+            alert(get_lang("It's not possible rename the folder: ") + aux[0]);
+			rename = "";
+			return false;
+		}else{
+			if(this.verify_names(aux[1])){
+                alert(get_lang("It's not possible rename the folder: ") + aux[1]);
+				rename = "";
+				return false;
+			}else{
+				if(this.verify(rename)){
+                    alert(get_lang("The folder name must not contain special characters."));
+					rename = "";
+					return false;
+				}else{
+					aux.pop();
+					aux.push(rename);
+					for(var i=0; i< aux.length; i++){
+						if( i == 0)
+							rename_new = aux[i];
+						else
+							rename_new += cyrus_delimiter + aux[i];
+					}
+				}	
+			}
+		}
+		if(rename != ""){
+			var handler_return = function(data)
+			{
+				if (data != "Ok") {
+					alert(get_lang(data));
+				}
+				else {
+					expresso.connector.purgeCache();
+					ttreeBox.name_folder = "root";
+					ttreeBox.update_folder();
+				}
+			}
+			var args = "$this.imap_functions.ren_mailbox";
+			var params = "rename="+rename_new+"&current="+old_box;
+			cExecute(args,handler_return,params);
+		}
+	}
+	//
+	Tree_Box.prototype.export_all_msg = function(){
+			
+		if(ttree.FOLDER == "root"){return false;}
+		var nm_bx = ttree.FOLDER.split(cyrus_delimiter);
+		var name_f = nm_bx[nm_bx.length -1];
+		var hand_export = function(data){
+			if(!data){
+				write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'))
+			}else if(data["empty_folder"]){
+				write_msg(get_lang("The selected folder is empty."));
+				alert(get_lang("The selected folder is empty."));
+			}else
+			  download_attachments(null, null, data, null,null, name_f +'.zip');
+		}
+		cExecute("$this.exporteml.export_all",hand_export,"folder="+ttree.FOLDER);	
+		write_msg(get_lang('You must wait while the messages will be exported...'));			
+	}
+	
+	// Função para deletar a pasta;
+	Tree_Box.prototype.del = function(){
+		var folder_name = ttree.FOLDER;
+		var aux = ttree.FOLDER.split(cyrus_delimiter);
+
+		if(aux[0] == "root" || ttree.FOLDER == ""){
+                        alert(get_lang("Select a folder!"));
+			return false;
+		}
+		
+		if(aux.length == 1){
+            alert(get_lang("It's not possible delete the folder: ") + get_lang("Inbox"));
+			return false;
+		}else{
+			if(this.verify_names(aux[1]) && typeof(aux[2]) == 'undefined'){
+	            alert(get_lang("It's not possible delete the folder: ") + get_lang(special_folders[aux[1]]));	 
+      			return false;
+			}else{
+				this.verify_children(folder_name);
+			}
+		}	
+	}
+	
+	Tree_Box.prototype.del_past = function(param){
+		var aux = param.split(cyrus_delimiter);
+		var aux1 = aux.pop();
+
+		if(ttree.FOLDER == get_current_folder()){
+            alert(get_lang("It's not possible delete this folder, because it is being used in the moment!"));
+			return false;
+		}
+        if(confirm(get_lang("Do you wish to exclude the folder ") + aux1+ "?")){
+			var handler_return = function(data)
+			{		
+				if(data != "Ok")
+				{
+					alert(data);
+				}else{
+					expresso.connector.purgeCache();
+					ttreeBox.name_folder = "root";
+					ttreeBox.update_folder();
+					write_msg(get_lang("The folder %1 was successfully removed", aux1));
+				}
+			}
+			var args = "$this.imap_functions.delete_mailbox";
+			var params = "del_past="+param;
+			cExecute(args,handler_return,params);
+		}
+	
+	}
+/* - Build Object -*/
+ 	var ttreeBox;
+	ttreeBox = new Tree_Box();
Index: trunk/expressoMail1_2/js/jscode/preferences.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/preferences.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/preferences.js	(revision 2517)
@@ -0,0 +1,31 @@
+/**************************************************************************\
+ Início 
+\**************************************************************************/
+	function Preferences(){
+		this.prefeW 		= new Array;
+	}
+
+	// Salva uma unica preferencia
+	Preferences.prototype.save = function(key, value){
+		var _this = this;               
+		var handler_preferences = function(data){
+			if(data && data.success)
+				return;                 
+			else
+			alert(data);
+		}
+		preferences[key] = value;
+		var args   = "$this.db_functions.update_preferences";
+		var params = "prefe_string="+url_encode(connector.serialize(preferences));
+		cExecute(args,handler_preferences,params);
+	}
+
+	Preferences.prototype.delete_dynamic_contacts = function(){
+		var handler = function(data){}
+		var args   = "$this.dynamic_contacts.delete_dynamic_contacts";
+		var params = "";
+		cExecute(args,handler,params);
+	}
+// Cria o objeto	
+	var prefe;
+	prefe = new Preferences();
Index: trunk/expressoMail1_2/js/jscode/offline_access.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/offline_access.js	(revision 2517)
+++ trunk/expressoMail1_2/js/jscode/offline_access.js	(revision 2517)
@@ -0,0 +1,65 @@
+/**
+ * @author diogenes
+ */
+	function offline_access() {
+		this.login = null;
+		this.pass = null;
+		this.access = null;
+	}
+
+	offline_access.prototype.init = function (login,pass,access){
+		this.login = login;
+		this.pass = pass;
+		this.access = access;
+	}
+	
+	offline_access.prototype.fill_combo_of_users = function(users_combo) { 
+		
+		var users = expresso_local_messages.get_all_users();
+
+		for(var i in users) {
+					
+			var option = document.createElement('option');
+			option.value = i;
+			option.text = users[i];
+			try {
+				users_combo.add(option, null);
+			} 
+			catch (ex) {//I.E
+				users_combo.add(option);
+			}
+
+		}
+	}
+	
+	offline_access.prototype.do_login = function(uid_usuario,pass) {
+		control = expresso_local_messages.set_as_logged(uid_usuario,pass,false);
+		if(!control) {
+			document.getElementById('div_error').innerHTML = 'login ou senha inválida';
+		}
+		else {
+			document.location.href = 'offline.php';
+		}
+		
+	}
+	
+	offline_access.prototype.has_permition = function() {
+		var user_logged = expresso_local_messages.user_logged();
+		var d = new Date();
+
+		if(user_logged==null || d.getTime()>=user_logged[1]+60000) {
+			document.location.href = 'login_offline.php';
+		}
+		else	
+			account_id = user_logged[0];
+		
+	}
+
+	offline_access.prototype.do_logoff = function() {
+		expresso_local_messages.unset_as_logged();
+		location.href="login_offline.php"
+	}
+	
+
+	var expresso_offline_access;
+	expresso_offline_access = new offline_access();
Index: trunk/expressoMail1_2/js/drag_area.js
===================================================================
--- trunk/expressoMail1_2/js/drag_area.js	(revision 790)
+++ 	(revision )
@@ -1,251 +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 = "templates/"+template+"/images/envelope.png";
-	document.body.appendChild(this.div_dd);
-	
-}
-
-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;
-}	
-
-var _dragArea = new DragArea();
-
-document.onmousemove = function(e) {
-	var	_target = is_ie ? window.event.srcElement : e.target;
-	if(_dragArea._mousemove)
-		_dragArea._mousemove(e);
-	
-	else if(_dragArea.msg_number && _target.type != 'checkbox') {
-		_dragArea.mouseMoveDrag(e);
-	}
-};
-
-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("chk_box_select_all_messages").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("chk_box_select_all_messages").checked = false;			
-			}
-		}
-	
-		_dragArea.msg_number = false;
-		_dragArea.div_dd.style.display ='none';
-		if(is_ie)
-			_dragArea.onSelectStart(true);
-	}
-
-};
Index: trunk/expressoMail1_2/js/abas.js
===================================================================
--- trunk/expressoMail1_2/js/abas.js	(revision 2328)
+++ 	(revision )
@@ -1,277 +1,0 @@
-var BordersArray = new Array();
-BordersArray[0] = new setBorderAttributes(0);
-
-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("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("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)
-{
-	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);};
-	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='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='';
-
-	var bar = document.getElementById("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden')
-		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;
-
-	div.style.height = document.body.clientHeight - offset - (is_ie ? 76 : 86);
-	div.style.overflow = "hidden";
-
-	if(!is_ie) {
-		var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
-		var defaultWidth = document.body.clientWidth - 27;
-		if(!menuHidden)
-			defaultWidth -= Element("folderscol").offsetWidth;
-
-		div.style.width = defaultWidth;
-	}
-	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);
-	return true;
-}
Index: trunk/expressoMail1_2/js/InfoContact.js
===================================================================
--- trunk/expressoMail1_2/js/InfoContact.js	(revision 1445)
+++ 	(revision )
@@ -1,177 +1,0 @@
- function emInfoContact()
-{
-	this.email = "";
-	this.timeout = null;
-	this.timeout_hide = null;
-	this._mousemove = document.onmousemove;
-	this.td;
-	this.createCard();
-}
-
-emInfoContact.prototype.createCard = function(){
-	var pic= new Image(); 
-	pic.src="./templates/"+template+"/images/card.gif"; 
-	card = document.createElement("DIV");
-	card.id = "card_cc";
-	card.style.display = "none";
-	card.style.width = "244px";
-	card.style.backgroundImage = "url("+pic.src+")";
-	card.style.height = "134px";
-	card.style.position = "absolute";
-	card.innerHTML = "<table onmouseout='InfoContact.timeout_hide=setTimeout(\"InfoContact.hide()\",50);' onmouseover='clearTimeout(InfoContact.timeout_hide);' cellpadding=0 cellspacing=0 width='100%' height='100%'><tr><td valign='center' align='center' id='card_cc_td'></td></tr></table>";
-	document.body.appendChild(card);
-}
-emInfoContact.prototype.begin = function(td, email){
-
-	var card = Element("card_cc");
-	
-	if(this.td != td){
-		this.email = email;
-		this.td = td;
-		clearTimeout(this.timeout);
-	}
-	this.timeout = setTimeout("InfoContact.search('"+email+"')",1000);		
-}
-
-emInfoContact.prototype.label = function (text){
-	InfoContact.hide();
-	var div_label = Element("div_label");
-	if(!div_label) {
-		div_label = document.createElement("DIV");
-		div_label.id = "div_label";
-		div_label.style.padding = "2px";
-		div_label.style.display = "none";
-		div_label.style.position = "absolute";
-		div_label.style.border = "1px solid black";
-		div_label.style.backgroundColor="#FFFFDC";
-		document.body.appendChild(div_label);
-	}
-	div_label.innerHTML = text;
-	div_label.style.top = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
-	div_label.style.left = findPosX(this.td) + 20;
-	div_label.style.display = '';
-	setTimeout("InfoContact.hide()",1000);
-}
-
-emInfoContact.prototype.connectVoip = function (phoneUser, typePhone){
-	var handler_connectVoip = function(data){
-		if(!data) {
-			alert(get_lang("Error contacting VoIP server."));
-		}
-		else{
-			alert(get_lang("Requesting a VoIP call")+":\n"+data);
-		}
-	}
-	cExecute ("$this.functions.callVoipConnect&to="+phoneUser+"&typePhone="+typePhone, handler_connectVoip);
-}
-
-emInfoContact.prototype.show = function (data){
-	var _this = this;
-	var card = Element("card_cc");
-	card.style.left = findPosX(this.td) + 20;
-	var y = findPosY(this.td) + 20 - Element("divScrollMain_"+numBox).scrollTop;
-	var w_height = is_ie ? document.body.clientHeight + document.body.scrollTop : window.innerHeight + window.pageYOffset;
-	if(y + 160 > w_height)
-		card.style.top =  y - 160;	
-	else
-		card.style.top = y;		
-	card.style.display = '';
-	var cn = data.cn;
-	if(cn && cn.toString().length > 35)
-		cn = cn.toString().substring(0,30) + "...";
-	
-	var phoneUser = data.telefone;
-	if(preferences.voip_enabled && phoneUser) {
-		phoneUser = "<a title=\""+get_lang("Call to Comercial Number")+"\" href=\"#\" onclick=\"InfoContact.connectVoip('"+phoneUser+"', 'com')\">"+phoneUser+"</a>";
-		if(data.mobile){
-			phoneUser += " / <a title=\""+get_lang("Call to Mobile Number")+"\" href=\"#\" onclick=\"InfoContact.connectVoip('"+data.mobile+"', 'mob')\">"+data.mobile+"</a>";
-		}
-	}
-
-	Element("card_cc_td").innerHTML = "<table cellpadding=0 cellspacing=0 border=0 height='100%' width='100%'><tr><td width='70' height='93' style='padding-top:5px;padding-left:6px' align='center' valign='center'>"+
-										"<img src='./inc/show_img.php?email="+data.email+"'></td><td style='padding-left:2px' align='left' valign='top'>"+
-										"<br><img align='center' src='templates/"+template+"/images/"+(data.type)+"_catalog.png'><font size=1 color=BLACK>&nbsp;<b>"+get_lang("Sender's Information")+"</b></font>"+
-										_this.verifyIM(data.uid,data.email)+
-										"<br><img align='center' src='templates/"+template+"/images/phone.gif'>&nbsp;<font  size=1  color=BLACK>"+(phoneUser ? phoneUser : get_lang("None") )+"</font>"+
-										"</td></tr><tr><td valign='top' align='center' colspan='2'>"+
-										"<font size=1 color=BLACK>"+cn+"</font>"+
-										"<br><span title='"+get_lang("Write message")+"' style='cursor:pointer' onclick='InfoContact.sendMail(\""+cn+"\",\""+data.email+"\")'><font size=1 color=DARKBLUE><u>"+data.email+"</u></font></span>"+
-										"</td></tr></table>";
-
-
-	this.timeout_hide = setTimeout("InfoContact.hide()",1000);	
-}
-
-emInfoContact.prototype.search = function (email){
-	var _this = this;
-	var trustedDomain = false;
-	//	If "preferences.notification_domains" was setted, then verify if "mail" has a trusted domain.	
-	if (preferences.notification_domains != undefined && preferences.notification_domains != "") {
-		var domains = preferences.notification_domains.split(',');
-		for (var i = 0; i < domains.length; i++) {
-			if (email.toString().match(domains[i]))
-				trustedDomain = true;
-		}
-	}
-	else
-		trustedDomain = true;
-
-	var handler_search = function(data){
-		if(data != null){
-			_this.show(data);
-		}
-		else
-			_this.label(email);			
-	}
-	
-	if (trustedDomain)
-		cExecute ("$this.ldap_functions.getUserByEmail&email="+email, handler_search);
-	else
-		_this.label(email);
-}
-
-emInfoContact.prototype.hide = function(){
-	this.email = "";
-	if(Element("div_label"))
-		Element("div_label").style.display = 'none';
-
-	if(Element("card_cc")) 
-		Element("card_cc").style.display = "none";	
-}
-
-emInfoContact.prototype.sendMail = function(name, email){
-	Element("msg_number").value = "\""+ name+"\" <"+email+">";
-	InfoContact.hide();
-	new_message("new","null");
-}
-
-emInfoContact.prototype.openChat = function(event, email){
-	IM.action_button(event, '1', email ,false);
-}
-
-emInfoContact.prototype.verifyIM = function(uid, email){
-
-	if ( !window.IM || !document.getElementById('myStatus') )
-		return  "<br/><br/>";
-
-	var status = IM.infoContact(uid);
-	var _return = '<br/>';
-
-	if ( status )
-	{
-		_return += '<img align="center" src="'+status.src+'" />';
-		_return	+= '<span onclick="IM.action_button(event,\''+status.jid+'\');"><font size="1" color=';
-		
-		if( status.src != img_unavailable.src)
-			_return 	+= '"DARKBLUE"><u style="cursor:pointer;">'+get_lang("User connected")+"</u>";
-		else
-			_return 	+= '"BLACK">'+get_lang("User not connected");
-
-		_return	+= "</font></span><br />";
-	}
-
-	return _return;
-}
-/* Build the Object */
-var emInfoContact;
-InfoContact = new emInfoContact();
Index: trunk/expressoMail1_2/js/filters.js
===================================================================
--- trunk/expressoMail1_2/js/filters.js	(revision 810)
+++ 	(revision )
@@ -1,240 +1,0 @@
-var rules_limit = 300;
-
-	function cfilterSh(){
-		this.filter_Sh   = new Array;
-		this.qvfaf		 = "";
-		
-		// Images
-		this.grp_open_img = new Image();
-		this.grp_open_img.src = 'templates/'+template+'/images/filtro/group_open.gif';
-		this.grp_close_img = new Image();
-		this.grp_close_img.src = 'templates/'+template+'/images/filtro/group_close.gif';
-		this.filter_img = new Image();
-		this.filter_img.src = 'templates/'+template+'/images/filtro/filters.gif';
-		this.for_email_img = new Image();
-		this.for_email_img.src = 'templates/'+template+'/images/filtro/answered.gif';
-		this.telephone_voip = new Image();
-		this.telephone_voip.src = 'templates/'+template+'/images/filtro/telephone_voip.jpg';
-	}		
-
-	cfilterSh.prototype.Forms = function(){
-	
-		var form = document.createElement("DIV");
-		form.id  = "window_ffilter_ccform";
-		form.style.visibility = "hidden";
-		form.style.position = "absolute";
-		form.style.left = "0px";
-		form.style.top  = "0px"; 
-		form.style.width = "0px";
-		form.style.height = "0px";
-		document.body.appendChild(form);
-
-		var form_cont = document.createElement("SPAN");
-		form_cont.id = "form_status";
-		form_cont.style.display = "block";			
-		form_cont.style.position = "absolute";
-		form_cont.style.top = "10px";
-		form_cont.style.left = "600px";
-		form_cont.innerHTML = "";
-		form.appendChild(form_cont);
-		
-		var form_buttons = document.createElement("DIV");
-		form_buttons.id = "form_buttons";
-		form_buttons.style.position = "absolute";
-		form_buttons.style.display = "";
-		form_buttons.style.top = "320px";
-		form_buttons.style.left = "5px";
-		form_buttons.style.width = "655px";
-		form_buttons.innerHTML = "<input type='button' value="+get_lang("Enable")+" onclick='filter.enabled_disabled(\"ENABLED\");'>"+
-								 "&nbsp;<input type='button' value="+get_lang("Disable")+" onclick='filter.enabled_disabled(\"DISABLED\");'>"+	
-								 "&nbsp;<input type='button' value="+get_lang("Remove")+" onclick='filter.delete_r();'>"+
- 								 "&nbsp;<input type='button' value="+get_lang("Close")+" onclick='filter.close_frm();'>";
-
-		form.appendChild(form_buttons);
-		
-		var form_body = document.createElement("DIV");
-		form_body.id = "form_body";
-		form_body.style.position = "absolute";
-		form_body.style.left = "5px";
-		form_body.style.top = "5px";
-		form_body.style.width = "668px";
-		form_body.style.height = "310px";
-		form_body.style.borderStyle = "outset";
-		form_body.style.borderColor = "black";
-		form_body.style.borderWidth = "1px";
-		form_body.style.overflow = "auto";
-		form.appendChild(form_body);	
-
-		this.showWindow(form);
-		filter.load_rules();
-		this.list_rules();			
-	
-	}
-
-	cfilterSh.prototype.list_rules = function(){
-		if(filter.rulest.length == 0)
-			setTimeout("filters.mount_list()",2500);
-		else
-			this.mount_list();
-	}
-
-	cfilterSh.prototype.mount_list = function(){
-
-		Element('form_status').innerHTML = "";
-		var list = "";
-	
-		// rules
-		if(filter.rulest.length == 0){
-			list = "<img id='set_rules_img' src='" + this.grp_close_img.src + "' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + "<a href='javascript:filters.n_rule()'>" + get_lang("new rule") + "</a>";		
-		}else{
-			if ( filter.rulest.length < rules_limit ) //Limit of rules
-				list = "<img id='set_rules_img' src='" + this.grp_open_img.src + "' onclick='visibleRulesFalse(\"set_rules\");' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + "<a href='javascript:filters.n_rule();'>" + get_lang("new rule") + "</a>";
-			else
-				list = "<img id='set_rules_img' src='" + this.grp_open_img.src + "' onclick='visibleRulesFalse(\"set_rules\");' border='0' />&nbsp;<span><b>"+get_lang('list of the filters') + " - ( " + filter.rulest.length + " ) </b></span> - " + get_lang("You have reached the maximum number of rules");
-			
-			list += "<div id='set_rules'>";
-			
-			for(var i= 0; i < filter.rulest.length; i++)
-			{
-				list += "<input id=rule_"+i+" type='checkBox'>&nbsp;<img src='"+this.filter_img.src+"' width='16' height='16' border='0' />&nbsp;" + get_lang("Rule")+" : " + parseInt(i+1) + " -- " + this.vl_rule(filter.rulest[i],i,'') + "<br>";
-			}
-			list += "</div>";			
-		}
-		
-		list += "<br/>";
-		
-		// out office
-		if(!filter.out_officeR){
-			list += "<img id='set_out_img' src='"+this.grp_close_img.src+"' border='0' />&nbsp;";
-			list += "<span><b>"+get_lang('out office') + " - ( 0 ) </b></span> " + "<a href='javascript:filters.n_out_office()'>" + get_lang("new rule") + "</a>";			
-		}else{
-			list += "<img id='set_out_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"set_out\");' border='0' />&nbsp;";
-			list += "<span><b>"+get_lang('out office') + " - ( 1 )</b></span>";
-			list += "<div id='set_out'>";
-			list += "<input id='out_0' type='checkBox'><img id='set_out_form_email_img' src='"+this.for_email_img.src+"' border='0'>";
-			list += " " + this.vl_outOffice(filter.out_officeR) + " " ;
-			list += "</div>";
-		}
-		list += "<br/>";
-	
-		// Voip
-		if(preferences.voip_email_redirect)
-		{
-			if( filter.rulesVoip.length == 0)
-			{
-				list += "<img id='voip_rule_img' src='"+this.grp_close_img.src+"' border='0' />&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + "<a href='javascript:filters.n_voipFilter();'>" + get_lang("new rule") + "</a>";		
-			}
-			else
-			{
-				if ( filter.rulest.length < rules_limit ) //Limit of rules
-					list += "<img id='voip_rule_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"voip_rule\");' border='0'/>&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + "<a href='javascript:filters.n_voipFilter()'>" + get_lang("new rule") + "</a>";
-				else
-					list += "<img id='voip_rule_img' src='"+this.grp_open_img.src+"' onclick='visibleRulesFalse(\"voip_rule\");' border='0'/>&nbsp;<span><b>" + get_lang('Phone Warnings List') + " - ( " + filter.rulesVoip.length + " ) </b></span> - " + get_lang("You have reached the maximum number of rules");
-					
-				list += "<div id='voip_rule'>";
-				for(var i= 0; i < filter.rulesVoip.length; i++)
-				{
-					list += "<input id='voip_rule_"+i+"' type='checkBox'>&nbsp;<img src='"+this.telephone_voip.src+"' width='16' height='16' border='0'/>&nbsp;" + get_lang("Rule")+" : " + parseInt(i+1) + " -- " + this.vl_rule(filter.rulesVoip[i],i,'voip') + "<br>";
-				}
-				list += "</div>";
-			}
-		}
-
-		Element("form_body").innerHTML = list;
-	}
-	
-	cfilterSh.prototype.vl_rule = function(rule,pos,type)
-	{
-		var fields = rule.split("&&");
-		if(type == 'voip')
-			return " <a href='javascript:void(0)' onclick=filter.form_r('"+pos+"','voip')><b>" + get_lang("Status") + " : </b>" + "<font color='red'>" + get_lang(fields[2]) + "</font>" + " - " + fields[3] + " <b>" + get_lang("Subject") + ":</b> " + fields[5] + "</a>";
-		else
-			return " <a href='javascript:void(0)' onclick=filter.form_r('"+pos+"','')><b>" + get_lang("Status") + " : </b>" + "<font color='red'>" + get_lang(fields[2]) + "</font>" + " - <b>" + get_lang("E-mail rule") + ":</b> " + fields[3] + " - <b>" + get_lang("Action") + ":</b> " + fields[6] + "</a>";
-	}
-	
-	cfilterSh.prototype.vl_outOffice = function(outOffice){		
-		var aux = outOffice.split("&&");
-		return get_lang("Rule") + " - <a href='javascript:void(0)' onclick=filter.form_out()> " + "<b>" + get_lang("Status") + " : </b><font color='red'>" + (aux[4] == "off" ? get_lang("Disabled") : get_lang("Enabled")) + "</font></a>";
-	}
-	
-	cfilterSh.prototype.n_rule = function()
-	{
-		Element('form_body').innerHTML = "";
-		Element('form_body').innerHTML = filter.forms_();	
-		Element('div_rule').style.display = "block";
-		filter.ac_form = "new_rule";
-		Element('form_buttons').style.display = 'none';
-		filter.sel_boxes();
-
-	}
-
-	cfilterSh.prototype.n_out_office = function()
-	{
-		Element('form_body').innerHTML = "";
-		Element('form_body').innerHTML = filter.forms_();	
-		Element('div_vacation').style.display = "block";			
-		Element('form_buttons').style.display = 'none';
-		filter.ac_form = "new_out";	
-	}
-
-	cfilterSh.prototype.n_voipFilter = function()
-	{
-		Element('form_body').innerHTML = "";
-		Element('form_body').innerHTML = filter.forms_();
-		Element('div_voipFilter').style.display = "block";	
-		Element('form_buttons').style.display = 'none';
-		filter.ac_form = "new_voip";
-	}
-
-	function visibleRulesFalse(el)
-	{
-		Element(el).style.display = "none";
-		Element(el+"_img").src = filters.grp_close_img.src;
-		Element(el+"_img").onclick = function(){visibleRulesTrue(el);};
-	}
-
-	function visibleRulesTrue(el)
-	{
-		Element(el).style.display = "";
-		Element(el+"_img").src = filters.grp_open_img.src;
-		Element(el+"_img").onclick = function(){visibleRulesFalse(el);};
-	}
-
-	cfilterSh.prototype.showWindow = function (div)
-	{
-		if(! this.filter_Sh[div.id]) {
-			div.style.width = "680px";
-			div.style.height = "345px";
-			div.style.visibility = "hidden";
-			div.style.position = "absolute";
-			div.style.zIndex = "10000";			
-			var title = ':: ' + get_lang('Filters management') + ' - ' + get_lang('Filters maintenance') + ':: ';
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-
-			win = new dJSWin({			
-				id: 'filter'+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.filter_Sh[div.id] = win;
-			win.draw();
-		}else{
-			div.innerHTML = '';
-			win = this.filter_Sh[div.id];
-			filter.form_m();			
-		}
-		win.open();
-	}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// build object
- 	var filters;
-	filters = new cfilterSh();
Index: trunk/expressoMail1_2/js/sniff_browser.js
===================================================================
--- trunk/expressoMail1_2/js/sniff_browser.js	(revision 553)
+++ 	(revision )
@@ -1,19 +1,0 @@
-    var agt=navigator.userAgent.toLowerCase();
-    var is_major = parseInt(navigator.appVersion);
-    var is_minor = parseFloat(navigator.appVersion);    
-    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
-                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
-                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
-    var is_gecko = (agt.indexOf('gecko') != -1);
-    var is_gecko1_5 = (agt.indexOf('firefox/1.5') != -1 || agt.indexOf('firefox/2') != -1 || agt.indexOf('iceweasel/2') != -1 || agt.indexOf('firefox/3'));
-    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
-    var is_ie3    = (is_ie && (is_major < 4));
-    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
-    var is_ie4up  = (is_ie && (is_major >= 4));
-    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
-    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
-    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
-    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
-    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
-    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);    
-    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
Index: trunk/expressoMail1_2/js/sharemailbox.js
===================================================================
--- trunk/expressoMail1_2/js/sharemailbox.js	(revision 2006)
+++ 	(revision )
@@ -1,393 +1,0 @@
-	function cShareMailbox()
-	{
-		this.arrayWin = new Array();
-		this.el;
-		this.alert = false;
-	}
-
-	cShareMailbox.prototype.get_available_users = function(context)
-	{
-		var handler_get_available_users = function(data)
-		{
-			select_available_users = document.getElementById('em_select_available_users');
-		
-			//Limpa o select
-			for(var i=0; i<select_available_users.options.length; i++)
-			{
-				select_available_users.options[i] = null;
-				i--;
-			}
-
-			if ((data) && (data.length > 0))
-			{
-				// Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
-				select_available_users.innerHTML = '#' + data;
-				select_available_users.outerHTML = select_available_users.outerHTML;
-			
-				select_available_users.disabled = false;
-				select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
-				document.getElementById('em_input_searchUser').value = '';
-			}
-		}
-		cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users);
-	}
-
-	cShareMailbox.prototype.getaclfromuser = function(user)
-	{
-		var handler_getaclfromuser = function(data)
-		{
-			Element('em_input_readAcl').checked = false;
-			Element('em_input_deleteAcl').checked = false;
-			Element('em_input_writeAcl').checked = false;
-			Element('em_input_sendAcl').checked = false;
-			Element('em_input_saveAcl').checked = false;
-			Element('em_input_saveAcl').disabled = true;
-			
-			if (data[user].indexOf('lrs',0) >= 0)
-			{
-				Element('em_input_sendAcl').disabled = false;
-				Element('em_input_readAcl').checked = true;
-			}
-			else
-				Element('em_input_sendAcl').disabled = true;
-				
-			if (data[user].indexOf('d',0) >= 0)
-			{
-				Element('em_input_deleteAcl').checked = true;
-			}
-			if (data[user].indexOf('wi',0) >= 0)
-			{
-				Element('em_input_writeAcl').checked = true;
-			}
-			
-			if (data[user] != "false" && data[user].indexOf('a',0) >= 0)
-			{
-				Element('em_input_sendAcl').disabled = false;
-				Element('em_input_sendAcl').checked = true;
-			}
-			if (data[user] != "false" && data[user].indexOf('p',0) >= 0)
-			{
-				Element('em_input_saveAcl').disabled = false;
-				Element('em_input_saveAcl').checked = true;
-			} 
-			if( data[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
-				Element('em_input_saveAcl').disabled = false;
-			} else Element('em_input_saveAcl').disabled = true;
-		}
-		cExecute ("$this.imap_functions.getaclfromuser&user="+user, handler_getaclfromuser);
-	}
-	
-	cShareMailbox.prototype.setaclfromuser = function()
-	{
-		var acl		= '';
-		var select 	= Element('em_select_sharefolders_users');
-
-		if(select.selectedIndex == "-1"){
-			alert("Selecione antes um usuário!");
-			return false;
-		}
-		var user = select.options[select.selectedIndex].value;
-		
-		if (Element('em_input_readAcl').checked) {
-			Element('em_input_sendAcl').disabled = false;
-			acl = 'lrs';
-		}
-		else{
-			Element('em_input_sendAcl').disabled = true;
-			Element('em_input_sendAcl').checked = false;
-		}
-				
-		if (Element('em_input_deleteAcl').checked)
-			acl += 'd';
-
-		if (Element('em_input_writeAcl').checked) {
-			acl += 'wi';			
-		}		
-		if (Element('em_input_sendAcl').checked){
-			acl += 'a';			
-		}
-		if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
-			Element('em_input_saveAcl').disabled = false;				
-		} else {
-			Element('em_input_saveAcl').disabled = true;
-			Element('em_input_saveAcl').checked = false;
-		}
-		
-		if (Element('em_input_saveAcl').checked)
-			acl += 'p';
-		
-		var handler_setaclfromuser = function(data) {
-			if (!data)
-				alert(data);	
-			return true;
-		}
-		cExecute ("$this.imap_functions.setaclfromuser&user="+user+"&acl="+acl, handler_setaclfromuser);
-	}
-	
-	cShareMailbox.prototype.makeWindow = function(options)
-	{
-		_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_sharefolders';
-		document.body.appendChild(el);
-
-		if (Element('em_select_sharefolders_users'))
-		{
-			var select_users = Element('em_select_sharefolders_users');
-			select_users.innerHTML = '#' + options;
-			select_users.outerHTML = select_users.outerHTML;
-			
-			Element('em_input_readAcl').checked = false;
-			Element('em_input_deleteAcl').checked = false;
-			Element('em_input_writeAcl').checked = false;
-			Element('em_input_sendAcl').checked = false;
-			Element('em_input_saveAcl').checked = false;
-		}
-		else
-		{
-			el.innerHTML = "<table border=0><tbody><tr>"+
-							
-							"<td valign='bottom'>"+
-								'<font color="red">'+
-									get_lang('Note: This sharing will take action on all of your folders and messages.')+
-									'<br><br>'+
-								'</font>'+
-								get_lang('Your mailbox is shared with')
-								+":<br><br>"+
-								"<select onchange=sharemailbox.getaclfromuser(this.value); id='em_select_sharefolders_users' size='13' style='width:250px;height:200px'>" + options + "</select>"+
-							"</td>"+
-							
-							"<td>"+
-								'<br><br><br><br><br><br>'+
-								'<img onClick="javascript:sharemailbox.add_user();" src="templates/'+template+'/images/arrow_left.gif" style="vertical-align:middle;cursor:pointer;">' +
-								'<br><br>'+
-								'<img onClick="javascript:sharemailbox.remove_user();" src="templates/'+template+'/images/arrow_right.gif" style="vertical-align:middle;cursor:pointer;">' +
-							"</td>"+
-							
-							"<td valign='bottom'><br>"+
-								get_lang('Organization')+":&nbsp;" + 
-								"<select id='em_combo_org' onchange='javascript:sharemailbox.get_available_users(this.value);'></select>"+
-								
-								"<br><br>"+get_lang('Search user')+":<br>" +
-								'<input id="em_input_searchUser" size="35" autocomplete="off"  onkeyup="javascript:sharemailbox.optionFinderTimeout(this)"><br>'+
-								
-								'<font color="red"><span id="em_span_searching">&nbsp;</span></font><br>'+
-								
-								"<select id='em_select_available_users' style='width:250px;height:200px' multiple></select></td>"+
-							'</tr>'+
-							'<tr><td>'+
-								'<table border=0><tbody><tr><td colspan=2>'+
-									get_lang('Access right')+':'+
-								'</td></tr>'+
-								'<tr><td>'+get_lang('Read')+':</td><td><input id=\'em_input_readAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang("hlp_msg_read_acl")+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
-								'<tr><td>'+get_lang('Exclusion')+':</td><td><input id=\'em_input_deleteAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_delmov_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
-								'<tr><td>'+get_lang('Write')+':</td><td><input id=\'em_input_writeAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_addcreate_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
-								'<tr><td>'+get_lang('Send')+':</td><td><input id=\'em_input_sendAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_sendlike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr>'+
-								'<tr><td>'+get_lang('Save')+':</td><td><input id=\'em_input_saveAcl\' onClick="return sharemailbox.setaclfromuser();" type="checkbox"><img title="'+get_lang('hlp_msg_savelike_acl')+'." src=\'./templates/'+template+'/images/ajuda.jpg\'></td></tr></tbody></table>'+
-							'</td></tr>'+
-			"</tbody></table>";
-		}
-
-		var handler_organizations = function(data){
-			var user_organization = Element('user_organization').value;
-			
-			for(i = 0; i < data.length; i++) {
-				Element('em_combo_org').options[i] = new Option(data[i].ou,data[i].dn);
-				if(user_organization.toUpperCase() == data[i].ou.toUpperCase())
-				{
-					Element('em_combo_org').options[i].selected = true;
-					_this.get_available_users(data[i].dn);
-				}
-			}
-		}
-		cExecute ("$this.ldap_functions.get_organizations2&referral=false", handler_organizations);
-
-		var butt = Element('dJSWin_wfolders_bok')
-		if (!butt){
-			butt = document.createElement('INPUT');
-			butt.id = 'dJSWin_wfolders_bok';
-			butt.type = 'button';
-			butt.value = get_lang('Save');
-			el.appendChild(butt);
-		}
-		butt.onclick = function ()
-		{
-			// Needed select all options from select
-			var users_setacl = new Array();
-			select_users = Element('em_select_sharefolders_users');
-			for(var i=0; i<select_users.options.length; i++)
-			{
-				users_setacl[i] = select_users.options[i].value;
-			}
-			attributes = expresso.connector.serialize(users_setacl);
-			
-			var handler_save = function(data)
-			{
-				if (data)
-				{
-					alert(get_lang('Shared options saved with success'));
-					sharemailbox.arrayWin[el.id].close();
-				}
-			}
-
-			cExecute ("$this.imap_functions.setacl", handler_save, 'users='+attributes);
-
-		}
-		
-		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 () {sharemailbox.arrayWin[el.id].close();};
-		el.appendChild(butt);
-		
-		_this.showWindow(el);
-	}
-	
-	cShareMailbox.prototype.showWindow = function (div)
-	{
-		if(! div) {
-			alert(get_lang('This list has no participants'));
-			return;
-		}
-		
-		if(! this.arrayWin[div.id])
-		{
-			div.style.height = "480px";
-			div.style.width = "540px";
-			var title = ":: "+get_lang("Mailbox Sharing")+" ::";
-			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];
-		}
-		Element('em_input_sendAcl').disabled = true;
-		Element('em_input_saveAcl').disabled = true;
-		win.open();
-	}
-	
-	var finderTimeout = '';
-	cShareMailbox.prototype.optionFinderTimeout = function(obj)
-	{
-		clearTimeout(finderTimeout);	
-		var oWait = document.getElementById("em_span_searching");
-		oWait.innerHTML = get_lang('Searching')+"...";
-		var finderTimeout = setTimeout("sharemailbox.optionFinder('"+obj.id+"')",500);
-	}
-	
-	cShareMailbox.prototype.optionFinder = function(id)
-	{
-		var oWait = document.getElementById("em_span_searching");
-		var oText = document.getElementById(id);
-			
-		//Limpa todo o select
-		
-		var select_available_users_tmp = document.getElementById('em_select_available_users')
-		for(var i = 0;i < select_available_users_tmp.options.length; i++)
-			select_available_users_tmp.options[i--] = null;
-
-		var RegExp_name = new RegExp("\\b"+oText.value, "i");
-		
-		//Inclui usuário começando com a pesquisa
-		for(i = 0; i < select_available_users_clone.length; i++){
-			if (RegExp_name.test(select_available_users_clone[i].text))
-			{
-				sel = select_available_users_tmp.options;
-				option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);				
-				sel[sel.length] = option;
-			}
-		}
-		oWait.innerHTML = '&nbsp;';
-	}
-	
-	cShareMailbox.prototype.add_user = function()
-	{
-		var select_available_users = document.getElementById('em_select_available_users');
-		var select_users = document.getElementById('em_select_sharefolders_users');
-
-		var count_available_users = select_available_users.length;
-		var count_users = select_users.options.length;
-		var new_options = '';
-	
-		for (i = 0 ; i < count_available_users ; i++)
-		{
-			if (select_available_users.options[i].selected)
-			{
-				if(document.all)
-				{
-					if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
-					{
-						new_options +=  '<option value='
-									+ select_available_users.options[i].value
-									+ '>'
-									+ select_available_users.options[i].text
-									+ '</option>';
-					}
-				}
-				else
-				{
-					if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
-					{
-						new_options +=  '<option value='
-									+ select_available_users.options[i].value
-									+ '>'
-									+ select_available_users.options[i].text
-									+ '</option>';
-					}
-				}
-			}
-		}
-
-		if (new_options != '')
-		{
-			select_users.innerHTML = '#' + new_options + select_users.innerHTML;
-			select_users.outerHTML = select_users.outerHTML;
-		}
-	}
-
-	cShareMailbox.prototype.remove_user = function()
-	{
-		select_users = document.getElementById('em_select_sharefolders_users');
-	
-		for(var i = 0;i < select_users.options.length; i++)
-			if(select_users.options[i].selected)
-				select_users.options[i--] = null;
-				
-		Element('em_input_readAcl').checked = false;
-		Element('em_input_deleteAcl').checked = false;
-		Element('em_input_writeAcl').checked = false;
-		Element('em_input_sendAcl').checked = false;
-		Element('em_input_saveAcl').checked = false;
-	}
-	
-	
-/* Build the Object */
-	var sharemailbox;
-	sharemailbox = new cShareMailbox();
Index: trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/common_functions.js	(revision 2515)
+++ 	(revision )
@@ -1,901 +1,0 @@
-// BEGIN: FUNCTION RESIZE WINDOW
-if (!expresso_offline) {
-	var _showBar = showBar;
-	var _hideBar = hideBar;
-}
-
-function __showBar(){
-	_showBar();
-	resizeWindow();
-}
-
-function __hideBar(){
-	_hideBar();
-	resizeWindow();
-}
-showBar = __showBar;
-hideBar = __hideBar;
-
-window.onresize = resizeWindow;
-
-function config_events(pObj, pEvent, pHandler)
-{
-    if( typeof pObj == 'object')
-    {
-        if( pEvent.substring(0, 2) == 'on')
-            pEvent = pEvent.substring(2, pEvent.length);
-
-        if ( pObj.addEventListener )
-            pObj.addEventListener(pEvent, pHandler, false);
-        else if( pObj.attachEvent )
-            pObj.attachEvent('on' + pEvent, pHandler );
-    }
-}
-
-function resizeWindow(){
-
-	var bar = Element("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
-		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);	
-
-	var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
-	var defaultHeight = screenHeight - offset;
-
-	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);
-
-			// This comented code cause/avoid (!?) Firefox to stuck some request
-			if(div)
-//				div.setAttribute("style","height: "+parseInt(defaultHeight - 90)+"px;");
-				div.style.height = defaultHeight - 90;
-			if(div_scroll)
-//				div_scroll.setAttribute("style","height: "+parseInt(defaultHeight - 130)+"px;");
-				div_scroll.style.height = defaultHeight - 130;
-		}
-	}
-
-	if(Element('content_folders'))
-		Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
-	if(Element("divScrollMain_"+numBox))
-		Element("divScrollMain_"+numBox).style.height 	= defaultHeight - (is_ie ? 111 : 110);
-}
-// 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;
-			}
-		}
-	}
-}
-
-// Translate words and phrases using user language from eGroupware.
-function get_lang(_key) {
-	var key = _key.toLowerCase();
-	if(array_lang[key])
-		var _value = array_lang[key];
-	else
-		var _value = _key+"*";
-
-	if(arguments.length > 1)
-		for(j = 1; typeof(arguments[j]) != 'undefined'; j++)
-			_value = _value.replace("%"+j,arguments[j]);
-	return _value;
-}
-
-// Make decimal round, using in size message
-function round(value, decimal){
-	var return_value = Math.round( value * Math.pow( 10 , decimal ) ) / Math.pow( 10 , decimal );
-	return( return_value );
-}
-
-// 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();
-	remove_className(tr_message, 'tr_msg_unread');
-	remove_className(tr_message, 'selected_msg');
-	expresso.connector.purgeCache();
-	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();	
-	remove_className(tr_message, 'selected_msg');
-	add_className(tr_message, 'tr_msg_unread');
-}
-
-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 removeAll(id){
-	do
-	{
-		if (typeof(Element(id)) == 'undefined')
-			break;
-		Element(id).parentNode.removeChild(Element(id));
-	}
-	while(Element(id));
-}
-
-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 = '';
-}
-
-//Get the current number of messages in a page.
-function get_messages_number_in_page(){
-	//Get element tBody.
-	main = document.getElementById("tbody_box");
-		
-	// Get all TR (messages) in tBody.
-	main_list = main.childNodes;
-	
-	return main_list.length;
-}
-
-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='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("$this.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);
-}
-//	Remove Input File Dynamically.
-function removeFile(id){
-	var border_id = id.substr(8,1);
-	var el = Element(id);
-	el.parentNode.removeChild(el);
-}
-
-function validateFileExtension(fileName, id, id_border){
-	
-	var error_flag  = false;
-
-	if ( fileName.indexOf('/') != -1 )
-	{
-		if (fileName[0] != '/'){ // file name is windows format?
-			var file = fileName.substr(fileName.lastIndexOf('\\') + 1, fileName.length);
-			if ((fileName.indexOf(':\\') != 1) && (fileName.indexOf('\\\\') != 0)) // Is stored in partition or a network file?
-				error_flag = true;	
-		}
-		else // is Unix
-			var file = fileName.substr(fileName.lastIndexOf('/') + 1, fileName.length);						
-	}
-	else  // is Firefox 3
-		var file = fileName;
-
-	var fileExtension = file.split(".");
-	fileExtension = fileExtension[(fileExtension.length-1)];
-	for(var i=0; i<denyFileExtensions.length; i++)
-	{
-		if(denyFileExtensions[i] == fileExtension)
-		{
-			error_flag = true;
-			break;
-		}
-			
-	}
-
-	if ( error_flag == true )
-	{
-		alert(get_lang('File extension forbidden or invalid file') + '.');
-		removeFile(id);
-		addFile(id_border);
-		return false;
-	}
-	return true;
-}
-
-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 validateEmail(email){
-	if (typeof(email) != 'string')
-		return false;
-	var validName = /^[a-z][a-z-_0-9\.]*/i;
-	emailParts = email.split('@');
-	return (validName.test(emailParts[0]) && validateDomain(emailParts[1]));
-}
-function validateDomain(domain){
-	var domainReg = /^(([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}\])$/i;
-	return (domainReg.test(domain));
-}
-
-function validateUrl(url){
-	var urlReg = /([A-Za-z]{2,7}:\/\/)(.*)/i;
-	urlParts = url.split(urlReg);
-	return (urlParts[1].length > 4 &&  validateDomain(urlParts[2]));
-}
-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("QuickCatalogSearch");
-				QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
-			}
-			else
-			{
-				expresso.connector.loadScript("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 ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
-}
-
-function folderbox(){
-	expresso.connector.loadScript("TreeS");
-	ttree.make_Window();
-}
-
-function filterbox(){
-	expresso.connector.loadScript("filter");
-	expresso.connector.loadScript("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("sharemailbox");
-		sharemailbox.makeWindow(options);
-	}
-	cExecute ("$this.imap_functions.getacl", handler_imap_getacl);
-}
-
-function preferences_mail(){
-	location.href="../preferences/preferences.php?appname=expressoMail1_2";
-}
-
-function search_emails(value){
-	expresso.connector.loadScript("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("$this.exporteml.export_msg",handler_source,"folder="+url_decode(folder)+"&msgs_to_export="+num_msg);
-}
-
-function url_encode(str){
-	return escape(str);
-}  
-
-function url_decode(str) { 
-	return unescape(str);
-}  
-
-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 borkb(size){
-	kbyte = 1024;
-	mbyte = kbyte*1024;
-	gbyte = mbyte*1024;
-	if (!size)
-		size = 0;
-	if (size < kbyte)
-		return size + 'B';
-	else if (size < mbyte)
-		return parseInt(size/kbyte) + 'KB';
-	else if (size < gbyte)
-		if (size/mbyte > 100)
-			return (size/mbyte).toFixed(0) + 'MB';
-		else
-			return (size/mbyte).toFixed(1) + 'MB';
-	else
-		return parseInt(size/gbyte).toFixed(1) + 'GB';
-}
-
-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; 
-}
-
-function increment_folder_unseen(){
-	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) + 1);
-	}
-	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>1</span><font style=color:red>)</font>'});
-		tree_folders.getNodeById(folder_id)._refresh();
-	}
-	if (abas_unseen)
-	{
-		abas_unseen = parseInt(abas_unseen) + 1;
-		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) + 1;
-		Element('new_m').innerHTML = '<font style="color:red">' + abas_unseen + '</font>';
-	}
-	if ( current_folder.indexOf( 'INBOX' ) !== 0 && current_folder.indexOf( 'local_' ) !== 0 )
-	{
-		var display_unseen_in_shared_folders = Element('dftree_user_unseen');
-		if ( display_unseen_in_shared_folders )
-			tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + ( parseInt( display_unseen_in_shared_folders.innerHTML) + 1 ) + '</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 display_unseen_in_mailbox = 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(){
-	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) > 1))
-	{
-		folder_unseen.innerHTML = (parseInt(folder_unseen.innerHTML) - 1);
-	}
-	else if (parseInt(folder_unseen.innerHTML) <= 1)
-	{
-		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) > 1))
-        {
-	        abas_unseen = (parseInt(abas_unseen) - 1);
-	        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 display_unseen_in_shared_folders = Element('dftree_user_unseen');
-		if ( display_unseen_in_shared_folders )
-		{
-			var unseen_in_shared_folders = parseInt( display_unseen_in_shared_folders.innerHTML );
-			unseen_in_shared_folders--;
-			if ( unseen_in_shared_folders > 0 )
-				tree_folders.getNodeById( 'user' ).alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_shared_folders + '</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 display_unseen_in_mailbox = Element('dftree_root_unseen');
-	if ( display_unseen_in_mailbox )
-	{
-		var unseen_in_mailbox = parseInt( display_unseen_in_mailbox.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();
-	}
-}
-
-function LTrim(value){
-	var w_space = String.fromCharCode(32);
-	var strTemp = "";
-	var iTemp = 0;
-
-	var v_length = value ? value.length : 0;
-	if(v_length < 1)
-		return "";
-
-	while(iTemp < v_length){
-		if(value && value.charAt(iTemp) != w_space){
-			strTemp = value.substring(iTemp,v_length);
-			break;
-		}
-		iTemp++;
-	}
-	return strTemp;
-}
-
-//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 add_className(obj, className){
-	if (obj && !exist_className(obj, className))
-		obj.className = obj.className + ' ' + className;
-}
-
-function remove_className(obj, className){
-	var re = new RegExp("\\s*"+className);
-	if (obj)
-		obj.className = obj.className.replace(re, ' ');
-}
-
-function exist_className(obj, className){
-	return ( obj && obj.className.indexOf(className) != -1 )
-}
-
-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');
-		}
-	}
-}
-
-function validate_date(date){
-    if (date.match(/^[0-3][0-9]\/[0-1][0-9]\/\d{4,4}$/))
-    {
-        tmp = date.split('/');
-
-        day = new Number(tmp[0]);
-        month = new Number(tmp[1]);
-        year = new Number(tmp[2]);
-        if (month >= 1 && month <= 12 && day >= 1 && day <= 31)
-        {
-            if (month == 02 && day <= 29)
-            {
-                return true;
-            }
-            return true;
-        }
-        else
-            {
-                return false;
-            }
-    }
-    else
-        {
-            return false;
-        }
-}
Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 2497)
+++ 	(revision )
@@ -1,2550 +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(){
-	current_folder = "INBOX";
-	if (!is_ie)
-		Element('tableDivAppbox').width = '100%';
-	
-	var save_contacts = function(data){
-		contacts = 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;
-		 cExecute ("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", handler_draw_box);
-
-		if(preferences.hide_folders == "1")
-			Element('divAppboxHeader').innerHTML =  title_app_menu;
-		
-		if (preferences.delete_trash_messages_after_n_days != 0)
-			cExecute ("expressoMail1_2.imap_functions.automatic_trash_cleanness&before_date="+preferences.delete_trash_messages_after_n_days+"&cyrus_delimiter="+cyrus_delimiter, handler_automatic_trash_cleanness);
-		
-		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('mail_sync');
-			if (is_ie)
-				expresso.connector.loadScript('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
-
-		cExecute ("expressoMail1_2.db_functions.get_dropdown_contacts", save_contacts); //Save contacts needs preferences.
-		cExecute ("expressoMail1_2.imap_functions.get_folders_list&onload=true", update_menu);
-		
-	}
-	var handler_automatic_trash_cleanness = function(data){
-		if (data != false){
-			write_msg(data.length +' '+ Element('txt_clear_trash').value);
-		}
-	}
-	
-	// Versão
-	Element('divAppboxHeader').innerHTML = title_app;
-	
-	// Get cyrus delimiter
-	cyrus_delimiter = Element('cyrus_delimiter').value;
-
-	cExecute ("expressoMail1_2.functions.get_preferences", save_preferences);
-	setTimeout('auto_refresh()', time_refresh);
-
-}
-
-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(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;
-       if (!Element(data.msg_number)){
-	       trElement = document.createElement('DIV');
-	       trElement.id = data.msg_number;
-	       Element("tbody_box").appendChild(trElement);
-       }
-       show_msg(data);
-    }
-
-    proxy_mensagens.msg_img(msg_number,folder,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 handler_sendNotification = 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), handler_sendNotification);
-           // }
-
-            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_get_msg_info == 'false')
-	{
-		write_msg(get_lang("Problems reading your message")+ ".");
-		return;
-	}
-
-	if (msg_info.status == 'false'){
-		eval(msg_info.command_to_exec);
-	}
-	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 (openTab.type[currentTab] == 2 || openTab.type[currentTab] == 3)
-			delete_border(currentTab,'false');
-
-		
-		if(Element("border_id_" + id_msg_read)) 
-			alternate_border(id_msg_read);		
-		else {
-			var border_id = create_border(msg_info.subject, id_msg_read);
-			if(border_id)
-			{
-				openTab.type[border_id] = 2;
-				draw_message(msg_info,border_id);
-				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
-				return;
-		}
-
-		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), handler_sendNotification);
-		}
-		//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
-            }
-        }
-	}
-}
-
-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)
-		{
-			td_info = document.createElement("H3");
-			td_info.setAttribute("height", "25%");
-			td_info.setAttribute("background", "#FFF");
-			td_info.setAttribute("id", "msg_info");
-			td_info.align = "center";
-			td_info.innerHTML = get_lang("This mail box is empty");
-			box.appendChild(td_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());
-			}						
-			 //if(data.new_msgs > 0 || data.msgs_to_delete.length > 0)
-			//	purgeCache();						
-		}
-		// Update Box BgColor
-		var box = Element("tbody_box");
-		if(box.childNodes.length > 1){
-			updateBoxBgColor(box.childNodes);
-		}
-		expresso.connector.purgeCache();
-		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('chk_box_select_all_messages').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)
-	{
-		expresso.connector.purgeCache();
-		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 handler_move_search_msgs = 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);
-		}
-		expresso.connector.purgeCache();
-	}
-
-	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", handler_move_search_msgs, 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('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('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('chk_box_select_all_messages').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)
-	{
-		expresso.connector.purgeCache();
-		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 , handler_arquivar_mensagens);
-	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 handler_arquivar_mensagens = 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('chk_box_select_all_messages').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 , handler_arquivar_mensagens);
-	else 
-		write_msg(get_lang('No selected message.'));*/
-	
-}
-
-function get_selected_messages(){
-	main = document.getElementById("divScrollMain_"+numBox).firstChild.firstChild;
-	if (! main)
-		main = Element("tbody_box");
-
-	// Get all TR (messages) in tBody.
-	main_list = main.childNodes;
-
-	var selected_messages = '';
-	var selected_messages_by_shortcuts = '';
-	var j = 0;
-	for (j; j<(main_list.length); j++)
-	{
-	check_box = Element("check_box_message_"+main_list[j].id);
-	if ( (check_box) && (check_box.checked) )
-		selected_messages += main_list[j].id + ',';
-		
-		if (preferences.use_shortcuts == '1')
-		{
-			if ( exist_className(Element(main_list[j].id), 'selected_shortcut_msg') )
-			{
-				selected_messages_by_shortcuts += main_list[j].id + ',';
-			}
-		}
-	}
-	selected_messages = selected_messages.substring(0,(selected_messages.length-1));
-	
-	if (preferences.use_shortcuts == '1')
-	{
-		selected_messages_by_shortcuts = selected_messages_by_shortcuts.substring(0,(selected_messages_by_shortcuts.length-1));
-		
-		var array_selected_messages_by_shortcuts = selected_messages_by_shortcuts.split(",");
-		var array_selected_messages = selected_messages.split(",");
-		
-		if ((array_selected_messages.length <= 1) && (array_selected_messages_by_shortcuts.length > 1))
-		{
-			return selected_messages_by_shortcuts;
-		}
-	}
-	
-	if (selected_messages == '')
-		return false;
-	else
-		return selected_messages;
-}
-
-function replaceAll(string, token, newtoken) {
-	while (string.indexOf(token) != -1) {
- 		string = string.replace(token, newtoken);
-	}
-	return string;
-}
-
-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 (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 )
-	{
-		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='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){
-
-    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))
-		{
-			expresso.connector.purgeCache();
-			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).',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)
-{
-	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('TreeS');
-				alert(get_lang('There is not %1 folder, Expresso is creating it for you... Please, repeat your request later.',draftsfolder));
-				expresso.connector.loadScript('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);
-		Element("send_button_"+border_id).style.visibility="visible";
-		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]) //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 handler_set_messages_flag = function (data){
-		
-		var msgs_to_set = data.msgs_to_set.split(",");
-
-		if(!data.status) {
-			alert(data.msg);
-			Element('chk_box_select_all_messages').checked = false;
-			for (var i = 0; i < msgs_to_set.length; i++) {
-				Element("check_box_message_" + msgs_to_set[i]).checked = false;
-				remove_className(Element(msgs_to_set[i]), 'selected_msg');
-			}
-			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('chk_box_select_all_messages').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)
-	{
-		expresso.connector.purgeCache();
-		cExecute ("expressoMail1_2.imap_functions.set_messages_flag&folder="+folder+"&msgs_to_set="+msgs_to_set+"&flag="+flag, handler_set_messages_flag);
-	}
-	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 handler_set_messages_flag = function (data){
-		if (data.status && Element("td_message_answered_"+msg_number)) {	
-			if(flag == 'answered')
-				Element("td_message_answered_"+msg_number).innerHTML = '<img src=templates/'+template+'/images/answered.gif title=Respondida>';
-			else if(flag == 'forwarded')
-				Element("td_message_answered_"+msg_number).innerHTML = '<img src=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, handler_set_messages_flag);
-}
-
-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('chk_box_select_all_messages').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){
-		expresso.connector.purgeCache();
-		cExecute ("expressoMail1_2.imap_functions.empty_folder&clean_folder="+"imapDefaultTrashFolder", handler_empty_trash);
-	}
-}
-
-function empty_spam_imap(){
-	var handler_empty_spam = function(data){
-		Element('chk_box_select_all_messages').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 handler_export_all_selected_msgs = 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", handler_export_all_selected_msgs, "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 handler_send_queue_message = 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, handler_send_queue_message,"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/ccQuickAdd.js
===================================================================
--- trunk/expressoMail1_2/js/ccQuickAdd.js	(revision 2400)
+++ 	(revision )
@@ -1,150 +1,0 @@
-	function cQuickAddContact ()
-	{
-		this.arrayWin = new Array();
-		this.el;
-		this._nFields = 5;
-	}
-
-	
-	cQuickAddContact.prototype.showList = function(data){
-		_this = this;
-
-		var	cc_data = (typeof data) == 'object' ? data : data.split(',');
-		
-		if (document.getElementById('cc_rectQuickAddContact') == null){		
-			el = document.createElement("DIV");
-			el.style.visibility = "hidden";									
-			el.style.position = "absolute";
-			el.style.left = "0px";
-			el.style.top = "0px";
-			el.style.width = "0px";
-			wHeight = 165;
-			el.style.height = wHeight + 'px';
-			el.className = "div_cc_rectQuickAddContact";
-			el.id = 'cc_rectQuickAddContact';
-			document.body.appendChild(el);																
-		}
-		else {
-			el = document.getElementById('cc_rectQuickAddContact');
-		}
-		el.innerHTML = "";
-		var fieldsTop = 10;
-		var fieldsSpace = 30;
-		var lang_save 	= get_lang('Save');
-		var lang_cancel = get_lang('Cancel');
-		
-		//função lang
-		fields = new Array(get_lang('Nickname')+":", get_lang('First Name')+":", get_lang('Last Name')+":", 'E-mail:');
-		for (i=0; i<fields.length; i++) {
-			el.innerHTML += '<span id="ccQuickAddCT' + i + '" style="position: absolute; top: ' +  (fieldsTop+i*fieldsSpace) + 'px; left: 5px; width: 100px; text-align: right; border: 0px solid #999;">' + fields[i] + '</span>';
-			el.innerHTML += '<input id="ccQuickAddCI' + i + '" type="text" value="' + cc_data[i] + '" maxlength="50" style="position: absolute; top: ' + (fieldsTop+i*fieldsSpace) + 'px; left: 110px; width: 135px;">';
-		}
-		el.innerHTML +='<div id="ccQAFunctions" style="border: 0px solid black; width: 220px; height: 20px">' +
-			'<input title="'+lang_save+'" type="button" onclick="ccQuickAddOne.send(\''+data+'\');" value="'+lang_save+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 75px; width: 60px" />' +
-			'<input title="'+lang_cancel+'" type="button" onclick="ccQuickAddOne.fechar(\'' + id + '\');" value="'+lang_cancel+'" style="position: absolute; top: ' + (fieldsTop+(i*fieldsSpace)) + 'px; left: 140px; width: 60px" />' +
-			'</div>';
-		el.innerHTML +=	"<br>";
-		_this.showWindow(el);
-
-	}
-		
-	cQuickAddContact.prototype.showWindow = function (div)
-	{						
-		if(! this.arrayWin[div.id]) {
-			win = new dJSWin({			
-				id: 'ccQuickAddOne_'+div.id,
-				content_id: div.id,
-				width: '255px',
-				height: wHeight+'px',
-				title_color: '#3978d6',
-				bg_color: '#eee',
-				title: get_lang("Quick Add"),
-				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();
-	}
-	
-	cQuickAddContact.prototype.send = function (data)
-	{
-		
-		var handler = function (responseText)
-		{
-			var data = responseText;
-			if (!data || typeof(data) != 'object')
-			{
-				write_msg("Problema ao contactar servidor");
-				return;
-			}
-			else if (data['status'] == 'alreadyExists')
-			{
-				alert(data['msg']);
-				return;
-			}
-			else if (data['status'] != 'ok')
-			{
-				return;
-			}
-			contacts += ',' + full_name + ';' + email;
-			write_msg("Contato adicionado com sucesso.");
-			win.close();
-
-			if (_this.afterSave)
-			{
-				switch (typeof(_this.afterSave))
-				{
-					case 'function':
-						_this.afterSave();
-						break;
-
-					case 'string':
-						eval(_this.afterSave);
-						break;
-				}
-			}
-		}
-				
-		var _this = this;
-		var sdata = data.split(",");
-		var temp = sdata[3];
-		sdata[3]='';
-		sdata[4]=temp;
-		sdata = new Array();
-
-		for (i=0; i< fields.length; i++) {			
-			if(i == 3){
-				sdata[i] = '';
-				sdata[i+1] = document.getElementById("ccQuickAddCI" + i).value;
-			}
-			else
-				sdata[i] = document.getElementById("ccQuickAddCI" + i).value;
-		}
-
-		var full_name = trim(sdata[1]) + ' ' + trim(sdata[2]);
-		var email = trim(sdata[4]);
-
-		if(!validateEmail(email)){
-			alert(get_lang("The email address %1 is not valid, please use a valid address.",email));
-			return false;
-		}
-		
-		var sdata = 'add='+escape(expresso.connector.serialize(sdata));
-		var CC_url = '../index.php?menuaction=contactcenter.ui_data.data_manager&method=';
-		expresso.connector.newRequest('cQuickAdd.Send', CC_url+'quick_add', 'POST', handler, sdata);
-	}
-	
-	cQuickAddContact.prototype.fechar = function(id) {
-		var div = document.getElementById('cc_rectQuickAddContact');
-		win = this.arrayWin[div.id];
-		win.close();
-	}
-	
-	
-/* Build the Object */
-	var	ccQuickAddOne = new cQuickAddContact();
Index: trunk/expressoMail1_2/js/QuickSearchUser.js
===================================================================
--- trunk/expressoMail1_2/js/QuickSearchUser.js	(revision 1699)
+++ 	(revision )
@@ -1,99 +1,0 @@
-	function emQuickSearchUser ()
-	{
-		this.arrayWin = new Array();
-		this.el;
-		this.cc_contacts = new Array();
-		this.cc_groups  = new Array();
-	}
-
-	emQuickSearchUser.prototype.showList = function(data)
-	{
-		id = '1';
-		_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 = 'window_QuickSearchUser';
-		document.body.appendChild(el);
-		el.innerHTML = '<br>';
-		
-		if (document.getElementById('div_QuickSearchUser') == null)
-		{
-			el.innerHTML += '<div id="div_QuickSearchUser" class="quicksearchcontacts">' + 
-			'<table class="quicksearchcontacts"><tbody id="table_QuickSearchUser">' + data + '</tbody></table>' +
-			'</div>';
-			el.innerHTML += '&nbsp;&nbsp;<input type="button" value=' + get_lang("Close")+ ' id="QuickSearchUser_button_close" onClick="QuickSearchUser.close_window();">';
-		}
-		else{
-			var div_QuickSearchUser = document.getElementById('div_QuickSearchUser');
-			div_QuickSearchUser.style.display = "";
-			div_QuickSearchUser.innerHTML = '<table class="quicksearchcontacts"><tbody id="table_QuickSearchUser">' + data + '</tbody></table>';
-			var butt_close = document.getElementById("QuickSearchUser_button_close");
-			butt_close.onclick = function () {QuickSearchUser.close_window();};
-		}
-		_this.showWindow(el);
-	}
-
-	emQuickSearchUser.prototype.showWindow = function (div)
-	{
-		if(! div) {
-			alert(get_lang('The list has no participant.'));
-			return;
-		}
-							
-		if(! this.arrayWin[div.id]) {
-			div.style.width = "600px";
-			div.style.height = "350px";
-			var title = get_lang('The results were found in the Global Catalog')+':';
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-			div.style.width = div.offsetWidth - 5;
-
-			win = new dJSWin({			
-				id: 'QuickSearchUser_'+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();
-	}
-
-	emQuickSearchUser.prototype.close_window = function() {
-		Element("em_message_search").value = "";
-		this.arrayWin['window_QuickSearchUser'].close();
-	}
-	
-	emQuickSearchUser.prototype.create_new_message = function (cn, mail) {
-		QuickSearchUser.close_window();
-		if (openTab.type[currentTab] != 4)
-		{
-			Element("msg_number").value = "\""+cn+"\" <"+mail+">";
-			new_message("new","null");
-		}
-		else
-		{
-			var ToField = Element('to_'+currentTab);
-			ToField.value = ToField.value +"\""+cn+"\" <"+mail+">,";
-		}
-	}
-
-/* Build the Object */
-	var QuickSearchUser;
-	QuickSearchUser = new emQuickSearchUser();
Index: trunk/expressoMail1_2/js/html2xhtml.js
===================================================================
--- trunk/expressoMail1_2/js/html2xhtml.js	(revision 2)
+++ 	(revision )
@@ -1,1 +1,0 @@
-var need_nl_before='|div|p|table|tbody|tr|td|th|title|head|body|script|comment|li|meta|h1|h2|h3|h4|h5|h6|hr|ul|ol|option|';var need_nl_after='|html|head|body|p|th|style|';var re_comment=new RegExp();re_comment.compile("^<!--(.*)-->$");var re_hyphen=new RegExp();re_hyphen.compile("-$");function get_xhtml(node,lang,encoding,need_nl,inside_pre){var i;var text='';var children=node.childNodes;var child_length=children.length;var tag_name;var do_nl=need_nl?true:false;var page_mode=true;for(i=0;i<child_length;i++){var child=children[i];switch(child.nodeType){case 1:{var tag_name=String(child.tagName).toLowerCase();if(tag_name=='')break;if(tag_name=='meta'){var meta_name=String(child.name).toLowerCase();if(meta_name=='generator')break;}if(!need_nl&&tag_name=='body'){page_mode=false;}if(tag_name=='!'){var parts=re_comment.exec(child.text);if(parts){var inner_text=parts[1];text+=fix_comment(inner_text);}}else{if(tag_name=='html'){text='<?xml version="1.0" encoding="'+encoding+'"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';}if(need_nl_before.indexOf('|'+tag_name+'|')!=-1){if((do_nl||text!='')&&!inside_pre)text+='\n';}else{do_nl=true;}text+='<'+tag_name;var attr=child.attributes;var attr_length=attr.length;var attr_value;var attr_lang=false;var attr_xml_lang=false;var attr_xmlns=false;var is_alt_attr=false;for(j=0;j<attr_length;j++){var attr_name=attr[j].nodeName.toLowerCase();if(!attr[j].specified&&(attr_name!='selected'||!child.selected)&&(attr_name!='style'||child.style.cssText=='')&&attr_name!='value')continue;if(attr_name=='_moz_dirty'||attr_name=='_moz_resizing'||tag_name=='br'&&attr_name=='type'&&child.getAttribute('type')=='_moz')continue;var valid_attr=true;switch(attr_name){case"style":attr_value=child.style.cssText;break;case"class":attr_value=child.className;break;case"http-equiv":attr_value=child.httpEquiv;break;case"noshade":break;case"checked":break;case"selected":break;case"multiple":break;case"nowrap":break;case"disabled":break;attr_value=attr_name;break;default:try{attr_value=child.getAttribute(attr_name,2);}catch(e){valid_attr=false;}break;}if(attr_name=='lang'){attr_lang=true;attr_value=lang;}if(attr_name=='xml:lang'){attr_xml_lang=true;attr_value=lang;}if(attr_name=='xmlns')attr_xmlns=true;if(valid_attr){if(!(tag_name=='li'&&attr_name=='value')){text+=' '+attr_name+'="'+fix_attribute(attr_value)+'"';}}if(attr_name=='alt')is_alt_attr=true;}if(tag_name=='img'&&!is_alt_attr){text+=' alt=""';}if(tag_name=='html'){if(!attr_lang)text+=' lang="'+lang+'"';if(!attr_xml_lang)text+=' xml:lang="'+lang+'"';if(!attr_xmlns)text+=' xmlns="http://www.w3.org/1999/xhtml"';}if(child.canHaveChildren||child.hasChildNodes()){text+='>';text+=get_xhtml(child,lang,encoding,true,inside_pre||tag_name=='pre'?true:false);text+='</'+tag_name+'>';}else{if(tag_name=='style'||tag_name=='title'||tag_name=='script'){text+='>';var inner_text;if(tag_name=='script'){inner_text=child.text;}else{inner_text=child.innerHTML;}if(tag_name=='style'){inner_text=String(inner_text).replace(/[\n]+/g,'\n');}text+=inner_text+'</'+tag_name+'>';}else{text+=' />';}}}break;}case 3:{if(!inside_pre){if(child.nodeValue!='\n'){text+=fix_text(child.nodeValue);}}else{text+=child.nodeValue;}break;}case 8:{text+=fix_comment(child.nodeValue);break;}default:break;}}if(!need_nl&&!page_mode){text=text.replace(/<\/?head>[\n]*/gi,"");text=text.replace(/<head \/>[\n]*/gi,"");text=text.replace(/<\/?body>[\n]*/gi,"");}return text;}function fix_comment(text){text=text.replace(/--/g,"__");if(re_hyphen.exec(text)){text+=" ";}return"<!--"+text+"-->";}function fix_text(text){return String(text).replace(/\n{2,}/g,"\n").replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\u00A0/g,"&nbsp;");}function fix_attribute(text){return String(text).replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");}
Index: trunk/expressoMail1_2/js/search.js
===================================================================
--- trunk/expressoMail1_2/js/search.js	(revision 2005)
+++ 	(revision )
@@ -1,1037 +1,0 @@
-/**************************************************************************\
- Início 
-\**************************************************************************/
-	function searchE()
-	{
-		this.searchW   = new Array;
-		this.name_box_search = "";
-		this.all_boxes = new Array;
-		this.type = "";
-		this.txtfields = new Array("txt_ass","txt_de","txt_body","txt_para","txt_cc","txt_cco",
-                                        "since_date", "before_date", "on_date");
-                this.selectFields = new Array("flagged", "seen", "answered", "recent");
-	}
-	
-	//Monta os forms dentro da janela;
-	searchE.prototype.showForms = function(value){
-		// Principal
-		if(!Element("window_search")) {
-			var form_search = document.createElement("DIV");
-			form_search.style.visibility = 'hidden';
-			form_search.style.top = '0px';
-			form_search.style.left = '0px';
-			form_search.id = "window_search";
-			document.body.appendChild(form_search);			
-		}
-		
-		// Pesquisa
-		if(!Element("div_form_search")){
-			var div_form_search = document.createElement("DIV");
-			div_form_search.id = "div_form_search";
-			div_form_search.style.position = "absolute";
-			div_form_search.style.left = "10px";
-			div_form_search.style.top  = "10px";
-			div_form_search.style.width = "784px";
-			div_form_search.style.height = "418px";
-			div_form_search.style.overflow = "hidden";
-			div_form_search.innerHTML = "";
-			var call_form_search = EsearchE.mount_form();
-			div_form_search.appendChild(call_form_search);
-			form_search.appendChild(div_form_search);
-
-                        Calendar._TT['WEEKEND'] = '0,6'; // hack
-                        Calendar._TT['DAY_FIRST'] = 'Mostrar %s primeiro';
-                        Calendar.setup({
-                            inputField  : 'since_date',
-                            button      : 'since_date-trigger',
-                            ifFormat    : '%d/%m/%Y',
-                            daFormat    : '%d/%m/%Y'
-                        });
-
-                        Calendar.setup({
-                            inputField  : 'before_date',
-                            button      : 'before_date-trigger',
-                            ifFormat    : '%d/%m/%Y',
-                            daFormat    : '%d/%m/%Y'
-                        });
-
-                        Calendar.setup({
-                            inputField  : 'on_date',
-                            button      : 'on_date-trigger',
-                            ifFormat    : '%d/%m/%Y',
-                            daFormat    : '%d/%m/%Y'
-                        });
-
-		}	
-		
-		if(!Element("div_button_search")){
-			var div_button_search    = document.createElement("DIV");
-				div_button_search.id = "div_button_search";
-				div_button_search.style.position = "absolute";
-				div_button_search.style.marginLeft = "430px";
-				div_button_search.style.top = "223px";
-				div_button_search.style.width = "350px";
-				div_button_search.style.height = "25px";
-				div_button_search.innerHTML = "<table style='width: 100%;' border='0' cellpadding='0' cellspacing='0' align='center'>"+
-											  "<tr>"+
-											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Search') + " onclick='EsearchE.func_search()'></td>"+
-											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Clean') + " onclick='EsearchE.func_clean()'></td>"+
-											  "<td width='33%' align='center'><input type='button' value=" + get_lang('Close') + " onclick='EsearchE.func_close(\"hidden\")'></td>"+
-											  "</tr>"+
-											  "</table>";
-				form_search.appendChild(div_button_search);
-		}
-		
-		if(!Element("table_layer")){
-			var table_layer    = "";
-		}
-		
-		if(value == "")
-			EsearchE.showWindow(Element("window_search"));
-	
-		// Cria as caixas postais;
-		EsearchE.mount_folders();
-
-		if(value){
-			Element("check_all_msg").checked = true;
-			EsearchE.all_mailboxes();
-			EsearchE.func_search(value);
-		}
-
-	}
-	
-	//Form
-	searchE.prototype.mount_form = function(value){
-		var form_sch = document.createElement("FORM");
-		form_sch.id  = "form_sch";
-
-		form_sch.innerHTML =  '<fieldset style="width:400px; text-align:right; padding: 5px; position:absolute;">'
-							+ '	<legend>'+get_lang('Inform your search in the text fields')+'</legend>'
-							+ '	<label>'+get_lang("From")+':</label>'
-							+ '	<input style="margin-left: 6px;" type="text" id="txt_de" size="39">'
-							+ '	<br style="margin-bottom:15px"/>'
-							+ '	<label>'+get_lang('To')+':</label>'
-							+ '	<input style="margin-left: 6px;" type="text" id="txt_para" size="39">'
-							+ '	<br style="margin-bottom:15px"/>'
-							+ '	<label>'+get_lang('Cc')+':</label>'
-							+ '	<input style="margin-left: 6px;" type="text" id="txt_cc" size="39">'
-							+ '	<br style="margin-bottom:15px"/>'
-							+ '	<label>'+get_lang('Subject')+':</label>'
-							+ '	<input style="margin-left: 6px;" type="text" id="txt_ass" size="39">'
-							+ '	<br style="margin-bottom:15px"/>'
-							+ '	<label>'+get_lang('Message body')+':</label>'
-                                                        + '	<input style="margin-left: 6px;" type="text" id="txt_body" size="39">'
-
-							+ '	<br style="margin-bottom:30px"/>'
-                                                        + '     <label>'+get_lang("Since Date")+':</label>'
-                                                        + '     <input style="margin-left: 6px;" type="text" id="since_date" size="8">'
-                                                        + '     <img id="since_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
-                                                        + '     <label style="margin-left: 20px;">'+get_lang('Before Date')+':</label>'
-                                                        + '     <input style="margin-left: 6px;" type="text" id="before_date" size="8">'
-                                                        + '     <img id="before_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>'
-                                                        + '     <br style="margin-bottom:15px"/>'
-
-                                                        + '     <label>'+get_lang('On Date')+':</label>'
-                                                        + '     <input style="margin-left: 6px;" type="text" id="on_date" size="8">'
-                                                        + '     <img style="margin-right: -8px" id="on_date-trigger" src="/phpgwapi/templates/default/images/datepopup.gif" title="'+get_lang("Select Date")+'" style="cursor:pointer; cursor:hand;"/>&nbsp;&nbsp;</spam>'
-                                                        + '     <br style="margin-bottom:30px"/>'
-
-                                                        + '     <label>'+get_lang('Flags')+':</label>'
-                                                        + '     <select style="width:15em; margin-left: 6px" name="flagged" id="flagged">'
-                                                        + '     <option value=""/>'
-                                                        + '     <option value="FLAGGED">'+ get_lang("Flagged") +'</option>'
-                                                        + '     <option value="UNFLAGGED">'+ get_lang("Unflagged") +'</option>'
-                                                        + '     </select>'
-                                                        + '     <br style="margin-bottom:15px"/>'
-                                                        + '     <select style="width:15em;" name="seen" id="seen">'
-                                                        + '     <option value=""/>'
-                                                        + '     <option value="SEEN">'+ get_lang("Seen") +'</option>'
-                                                        + '     <option value="UNSEEN">'+ get_lang("Unseen") +'</option>'
-                                                        + '     </select>'
-                                                        + '     <br style="margin-bottom:15px"/>'
-                                                        + '     <select style="width:15em;" name="answered" id="answered">'
-                                                        + '     <option value=""/>'
-                                                        + '     <option value="ANSWERED">'+ get_lang('Answered/Forwarded') +'</option>'
-                                                        + '     <option value="UNANSWERED">'+ get_lang('Unanswered/Unforwarded') +'</option>'
-                                                        + '     </select>'
-                                                        + '     <br style="margin-bottom:15px"/>'
-                                                        + '     <select style="width:15em;" name="recent" id="recent">'
-                                                        + '     <option value=""/>'
-                                                        + '     <option value="RECENT">'+ get_lang('Recent') +'</option>'
-                                                        + '     <option value="OLD">'+ get_lang('Old') +'</option>'
-                                                        + '     </select>'
-
-							+ '	<br style="margin-bottom:60px"/>'
-							+ '</fieldset>'
-							+ '<fieldset style="width:350px; padding: 5px; position:absolute; margin-left: 414px">'
-							+ '	<legend>'+get_lang('Search the messages in these folders')+'</legend>'
-							+ '	<div id="folders" style="width:160px; height:150px;float:left;margin-bottom:10px;"></div>'
-							+ '	<div style="float:left;height:100px;padding-top:50px;margin: 0 3px;">'
-							+ '		<input type="button" id="incluir" name="incluir" value=">>" onclick="EsearchE.add_mailboxes()">'
-							+ '		<br style="margin-bottom:15px">'
-							+ '		<input type="button" id="excluir" name="excluir" value="<<" onclick="EsearchE.del_mailboxes()">'
-							+ '	</div>'
-							+ ' <div style="float:left;">'	
-							+ '	 <select multiple id="sel_search_nm_box1" name="sel_search_nm_box1" style="width:140px;height:150px;"></select>'
-							+ ' </div>'
-							+ '	<br clear="both">'
-							+ '	<input type="checkBox" id="check_all_msg" name="check_all_msg" onclick="EsearchE.all_mailboxes()">'
-							+ '	<b>'+get_lang('In all the folders')+'</b>'
-							+ '</fieldset>';
-		
-		return form_sch;
-	}
-
-	// Pastas;
-	searchE.prototype.mount_folders = function(){
-		expresso.connector.loadScript("TreeS");
-
-		if( Element("div_folders_search") == null){
-			var div_folders = document.createElement("DIV");
-				div_folders.id = "div_folders_search";
-				div_folders.style.width = "155px";
-				div_folders.style.height = "152px";
-				div_folders.style.borderStyle = "outset";
-				div_folders.style.borderColor = "black";
-				div_folders.style.borderWidth = "1px";
-				div_folders.style.background  = "#F7F7F7";
-				div_folders.style.overflow = "auto";
-				div_folders.innerHTML = "";
-				var dest_div = Element("folders");
-				dest_div.appendChild(div_folders);
-		}		
-		ttree.make_tree(folders,"div_folders_search","_folders_tree_search","","","","");
-	}
-	
-	//This func returns the most recent date
-	function date_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data1 = data1[0].substr(0, data1[0].indexOf('--'))
-		with ( data1 ) 
-			data1 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data2 = data2[0].substr(0, data2[0].indexOf('--'))
-		with ( data2 )
-			data2 = Date.UTC(substr(6), substr(3, 2), substr(0, 2));
-		return data2 - data1;
-	}
-	function date_comp_reverse(a,b)
-	{
-		return date_comp(b,a);
-	}
-	
-	function box_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(0, a.indexOf('--'));
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(0, b.indexOf('--'))
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function box_comp_reverse(a,b)
-	{
-		return box_comp(b,a);
-	}
-
-	function who_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(a.indexOf('--')+2);
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(b.indexOf('--')+2);
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function who_comp_reverse(a,b)
-	{
-		return who_comp(b,a);
-	}
-
-	function subject_comp(a,b)
-	{
-	var compare = [];
-	compare[0] = a.substr(a.indexOf('--')+2);
-	compare[0] = compare[0].substr(compare[0].indexOf('--')+2);
-	compare[0] = compare[0].toLowerCase();
-	var temp=compare[0];
-	compare[1] = b.substr(b.indexOf('--')+2);
-	compare[1] = compare[1].substr(compare[1].indexOf('--')+2);
-	compare[1] = compare[1].toLowerCase();
-	compare.sort();
-	if (temp != compare[0])
-		return +1;
-	else
-		return -1;
-	}
-	function subject_comp_reverse(a,b)
-	{
-		return subject_comp(b,a);
-	}
-
-	function size_comp(a,b)
-	{
-		var data1 = a.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data1 = data1[0].substr(data1[0].indexOf('--')+2)
-		data1 = data1.substr(0,data1.indexOf('--'))
-		var size_a = parseInt(data1.substr(0,data1.indexOf(' ')));
-		if (data1.match("k"))
-			size_a = size_a * 1024;
-		else
-			if (data1.match("m"))
-				size_a = size_a * 1048576;
-		var data2 = b.match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-		data2 = data2[0].substr(data2[0].indexOf('--')+2)
-		data2 = data2.substr(0,data2.indexOf('--'))
-		var size_b = parseInt(data2.substr(0,data2.indexOf(' ')));
-		if (data2.match("k"))
-			size_b = size_b * 1024;
-		else
-			if (data2.match("m"))
-				size_b = size_b * 1048576;
-		return size_b - size_a;
-	}
-	function size_comp_reverse(a,b)
-	{
-		return size_comp(b,a);
-	}
-
-	// Form resultado
-	searchE.prototype.mount_result = function(data,sort_type){
-		var nw_array = new Array;
-		var var_tmp = data.substr(2, data.length - 4);
-		var_tmp  = var_tmp.split("####");
-		var cont = parseInt(0);
-		switch (sort_type)
-		{
-			case 'SORTDATE':
-				var_tmp.sort(date_comp);
-				break;
-			case 'SORTDATE_REVERSE':
-				var_tmp.sort(date_comp_reverse);
-				break;
-			case 'SORTBOX':
-				var_tmp.sort(box_comp);
-				break;
-			case 'SORTBOX_REVERSE':
-                                var_tmp.sort(box_comp_reverse);
-                                break;
-			case 'SORTSUBJECT':
-				var_tmp.sort(subject_comp);
-				break;
-			case 'SORTSUBJECT_REVERSE':
-                                var_tmp.sort(subject_comp_reverse);
-				break;
-			case 'SORTWHO':
-				var_tmp.sort(who_comp);
-				break;
-			case 'SORTWHO_REVERSE':
-                                var_tmp.sort(who_comp_reverse);
-				break;
-			case 'SORTSIZE':
-				var_tmp.sort(size_comp);
-				break;
-			case 'SORTSIZE_REVERSE':
-				var_tmp.sort(size_comp_reverse);
-				break;
-			default:
-				var showMsg = 1;
-		}
-
-		for(var i=0; i < var_tmp.length; i++){
-			if(var_tmp[i] != "")
-			{
-				nw_array[cont] = var_tmp[i];
-				cont++;
-			}
-		}
-
-                if( (preferences.search_result_number != '65536') && (nw_array.length > 0) && (nw_array.length >= preferences.search_result_number) ){
-                    nw_array.length = preferences.search_result_number;
-                    write_msg(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
-                }
-                else {
-                        write_msg(nw_array.length + " "+ get_lang('results found'));
-                }
-
-		numBox++;
-		var border_id = create_border(get_lang("Search Results"), "search_" + numBox);
-                if (!border_id)
-                {
-                    return;
-                }
-		currentTab = border_id;
-                openTab.content_id[currentTab] = Element('content_id_search_' + numBox);
-		openTab.type[currentTab] = 1;
-		var table = document.createElement("TABLE");
-		table.id    = "table_resultsearch_" + numBox;
-		table.frame = "void";
-		table.rules = "rows";
-		table.cellPadding = "0";
-		table.cellSpacing = "0";
-		table.className = "table_box";
-
-		var tbody = document.createElement("TBODY");
-		tbody.id    = "tbody_box_" + numBox;
-
-		for( var i=0; i < nw_array.length; i++){
-			var tr = document.createElement("TR");
-			tr.style.height = preferences.line_height;
-
-			if (nw_array[i].match(/.*--.*--\w*--\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g) != null) //subject with "--"
-			{
-				var aux1 = nw_array[i].match(/\d{2}\/\d{2}\/\d{4}--\d+? \w*b--.*--\d*$/g);
-				aux1 = aux1[0].split("--");
-				nw_array[i] = nw_array[i].substr(0, nw_array[i].indexOf(aux1[0])-2);
-				var aux = [];
-				aux[0] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-				nw_array[i] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-				aux[1] = nw_array[i].substr(0, nw_array[i].indexOf('--'));
-				aux[2] = nw_array[i].substr(nw_array[i].indexOf('--')+2);
-				aux = aux.concat(aux1);
-			}
-			else
-			{
-				var aux = nw_array[i].split("--");
-			}
-
-			var mailbox = aux[0];
-			var uid_msg = aux[6];
-			var subject = aux[2];
-			tr.id = uid_msg+"_s"+global_search;
-
-			// Keep the two lines together please
-			tr.setAttribute('name',mailbox);
-			tr.name = mailbox;
-
-			if (aux[5].match("U"))
-				add_className(tr,'tr_msg_unread');
-			add_className(tr, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');
-            var _onclick = function () { proxy_mensagens.get_msg(this.parentNode.id,url_encode(this.parentNode.getAttribute('name')),false,show_msg);};
-            for(var j=0 ; j < 10 ; j++)
-			{
-				var td = document.createElement("TD");
-				if (j == 0)
-				{
-					td.style.width = "1%";
-					var td1 = '<input type="checkbox" id="check_box_message_'+uid_msg+'"></input>';
-					
-				}
-				if (j == 1)
-				{
-					td.style.width = "2%";
-					if (aux[5].match('T'))
-					{
-						attachNum = parseInt(aux[5].substr(aux[5].indexOf('T')+1));
-						td1 = "<img src='templates/"+template+"/images/clip.gif' title='"+attachNum +' '+ get_lang('attachment(s)')+"'>";
-					}
-					else
-						td1 = '';
-				}
-				if (j == 2)
-				{
-					td.style.width = "1%";
-					td.id = "td_message_answered_"+uid_msg;
-					if (aux[5].match('X'))
-						td1 = '<img src=templates/'+template+'/images/forwarded.gif title=Forwarded>';
-					else
-						if (aux[5].match('A'))
-							td1 = '<img src=templates/'+template+'/images/answered.gif>';
-						else
-							td1 = '';
-				}
-				if (j == 3)
-				{
-					td.style.width = "1%";
-					td.id = "td_message_important_"+uid_msg;
-					if (aux[5].match("F"))
-					{
-						add_className(tr, 'flagged_msg');
-						td.style.background = "url(templates/"+template+"/images/important.gif) no-repeat center";
-					}
-					else
-						td1 = '';
-				}
-				if (j == 4)
-				{
-					td.style.width = "1%";
-					td.id = "td_message_sent_"+uid_msg;
-					td1 = '';
-				}
-				if (j == 5)
-				{
-					td.style.width = "14%";
-					td.onclick = _onclick;
-					var nm_box = aux[0].split(cyrus_delimiter);
-					var td1 = nm_box.pop();
-					td.setAttribute("NoWrap","true");
-					td.style.overflow = "hidden";
-					td.style.color = "#42795b";
-					td.style.fontWeight = "bold";
-					
-					var td1  = get_lang(td1).substr(get_lang(td1).length-1) == "*"?td1:get_lang(td1);
-                                        if ((tmp = translatedFolders.get(td1)))
-                                        {
-                                            td1 = tmp;
-                                        }
-
-					if(proxy_mensagens.is_local_folder(td1)) {
-						var td1 = this.aux_local_folder_display(td1);
-					}
-				}
-				if( j == 6)
-				{
-					if (aux[1].length > 29)
-						aux[1] = aux[1].substr(0,29) + "...";
-					td.style.width = "20%";
-					td.onclick = _onclick;
-					td.setAttribute("NoWrap","true");
-                                        td.style.overflow = "hidden";
-					var td1  =  '<div style="width:100%;overflow:hidden">'+aux[1]+"</div>";
-				}
-				if( j == 7)
-				{
-					var subject_encode = url_encode(subject);
-					if (! subject_encode)
-						aux[2] = get_lang("no subject") + "...";
-					if (aux[2].length > 70)
-						aux[2] = aux[2].substr(0,70) + "...";
-					td.style.width = "35%";
-					td.onclick = _onclick;
-                                        td.setAttribute("NoWrap","true");
-                                        td.style.overflow = "hidden";
-					var td1  = aux[2];
-
-				}
-				if( j == 8)
-				{
-					td.style.width = "15%";
-					td.align = "center";
-					td.onclick = _onclick;
-					var td1  = aux[3];
-				}
-				if( j == 9)
-				{
-					td.style.width = "10%";
-					td.align = "center";
-					td.onclick = _onclick;
-					var td1  = aux[4];
-				}
-				if (j == 10)
-				{
-					if (aux[5].match("U"))
-						add_className(tr, 'tr_msg_unread');
-					if (aux[5].match("F"))
-						add_className(tr, 'flagged_msg');
-					var td1 = '';
-				}
-				td.innerHTML = td1;
-				tr.appendChild(td);
-			}
-			aux.splice(0,(aux.length));
-
-		_dragArea.makeDragged(tr, uid_msg, subject, true, mailbox);
-		tbody.appendChild(tr);
-		}
-		global_search++; //Tabs from search must not have the same id on its tr's
-		
-		table.appendChild(tbody);
-
-	var content_search =  Element('content_id_search_' + numBox);
-	// BEGIN MAKE THE SCROLL HEIGHT		
-	var defaultWidth = document.body.offsetWidth - 31;
-	var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
-	if(!menuHidden)
-		defaultWidth -= Element("folderscol").offsetWidth;			
-	var bar = Element("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
-		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;		
-	var div_scroll_result = document.createElement("DIV");
-	div_scroll_result.id = "divScrollMain_"+numBox;
-	div_scroll_result.style.height = document.body.clientHeight - offset - 120;
-	content_search.style.height = document.body.clientHeight - offset - 80;
-	div_scroll_result.style.overflow = "auto";
-	div_scroll_result.style.width = defaultWidth - (is_ie ? 7 : 0);
-	// END MAKE THE SCROLL HEIGHT		
-		
-	
-		if(is_ie)
-			Element("border_table").width = "99.5%";
-		
-		// Put header
-		var table_element = document.createElement("TABLE");
-		var tbody_element = document.createElement("TBODY");
-		table_element.setAttribute("id", "table_message_header_box");
-		table_element.className = "table_message_header_box";
-		tr_element = document.createElement("TR");
-		tr_element.className = "message_header";
-		td_element0 = document.createElement("TD");
-		td_element0.setAttribute("width", "1%");
-		chk_box_element = document.createElement("INPUT");
-		chk_box_element.id  = "chk_box_select_all_messages";
-		chk_box_element.setAttribute("type", "checkbox");
-		chk_box_element.className = "checkbox";
-		chk_box_element.onclick = function(){select_all_search_messages(this.checked,content_search.id);};
-		chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
-		chk_box_element.onkeydown = function (e){
-			if (is_ie)
-			{
-				if ((window.event.keyCode) == 46)
-					delete_msgs(current_folder,'selected','null');
-			}
-			else
-			{
-				if ((e.keyCode) == 46)
-					delete_msgs(current_folder,'selected','null');
-			}
-		};
-		
-		td_element0.appendChild(chk_box_element);
-		td_element1 = document.createElement("TD");
-		td_element1.setAttribute("width", "20%");
-		td_element1.align = "left";
-		if (sort_type == 'SORTBOX')
-		{
-			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX_REVERSE'); delete_border(border_id,false);};
-			td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
-		}
-		else
-		{
-			td_element1.onclick = function () { EsearchE.mount_result(data,'SORTBOX'); delete_border(border_id,false);};
-			if  (sort_type == 'SORTBOX_REVERSE')
-				td_element1.innerHTML ="<b>"+get_lang("Folder")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
-			else
-				td_element1.innerHTML = get_lang("Folder");
-		}
-		td_element2 = document.createElement("TD");
-		td_element2.setAttribute("width", "20%");
-		td_element2.align = "left";
-		if (sort_type == 'SORTWHO')
-		{
-			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO_REVERSE'); delete_border(border_id,false);};
-			td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
-		}
-		else
-		{
-			td_element2.onclick = function () { EsearchE.mount_result(data,'SORTWHO'); delete_border(border_id,false);};
-			if  (sort_type == 'SORTWHO_REVERSE')
-				td_element2.innerHTML ="<b>"+get_lang("who")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
-			else
-				td_element2.innerHTML = get_lang("who");
-		}
-		td_element3 = document.createElement("TD");
-		td_element3.setAttribute("width", "35%");
-		td_element3.align = "left";
-		if (sort_type == 'SORTSUBJECT')
-		{
-			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT_REVERSE'); delete_border(border_id,false);};
-			td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
-		}
-		else
-		{
-			td_element3.onclick = function () { EsearchE.mount_result(data,'SORTSUBJECT'); delete_border(border_id,false);};
-			if  (sort_type == 'SORTSUBJECT_REVERSE')
-				td_element3.innerHTML ="<b>"+get_lang("subject")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
-			else
-				td_element3.innerHTML = get_lang("subject");
-		}
-		td_element4 = document.createElement("TD");
-		td_element4.setAttribute("width", "15%");
-		td_element4.align = "center";
-		if (sort_type == 'SORTDATE')
-		{
-			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE_REVERSE'); delete_border(border_id,false);};
-			td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
-		}
-		else
-		{
-			td_element4.onclick = function () { EsearchE.mount_result(data,'SORTDATE'); delete_border(border_id,false);};
-			if  (sort_type == 'SORTDATE_REVERSE')
-				td_element4.innerHTML ="<b>"+get_lang("Date")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
-			else
-				td_element4.innerHTML = get_lang("Date");
-		}
-		td_element5 = document.createElement("TD");
-		td_element5.setAttribute("width", "10%");
-		td_element5.align = "center";
-		if (sort_type == 'SORTSIZE')
-		{
-			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE_REVERSE'); delete_border(border_id,false);};
-			td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_descendant.gif'>";
-		}
-		else
-		{
-			td_element5.onclick = function () { EsearchE.mount_result(data,'SORTSIZE'); delete_border(border_id,false);};
-			if  (sort_type == 'SORTSIZE_REVERSE')
-				td_element5.innerHTML ="<b>"+get_lang("size")+"</b><img src='templates/"+template+"/images/arrow_ascendant.gif'>";
-			else
-				td_element5.innerHTML = get_lang("Size");
-		}
-		tr_element.appendChild(td_element0);
-		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);
-		tbody_element.appendChild(tr_element);
-		table_element.appendChild(tbody_element);
-		content_search.appendChild(table_element);
-		/*end of "put header"*/
-		
-		if (!expresso_offline) {
-/*			var span_options = document.createElement("SPAN");
-			if (span_options) 
-				span_options.innerHTML = '<span title="' + get_lang("Delete") + '" style="margin-top:3px;margin-left:8px" class="message_options" onclick="javascript:move_search_msgs(\'' + content_search.id + '\');">' + get_lang("Delete") + '</span> | ' +
-				'<span title="' +
-				get_lang("Move") +
-				'" class="message_options" onclick=wfolders.makeWindowNew(\"' +
-				content_search.id +
-				'\",\"move_to\",true)>' +
-				get_lang("Move") +
-				'</span>';*/
-			div_scroll_result.appendChild(table);
-			content_search.appendChild(div_scroll_result);
-			/*if (span_options) 
-				content_search.appendChild(span_options);*/
-		}
-		else {
-			div_scroll_result.appendChild(table);
-			content_search.appendChild(div_scroll_result);
-		}
-	}
-
-	searchE.prototype.open_msg = function(mailbox, uid_msg, subject){
-		var handler_get_msg = function(data){
-			if(Element("border_id_" + uid_msg + "_r")){alert(get_lang("This message is already opened!"));}
-			else{draw_message(data,create_border(url_decode(subject), uid_msg + "_r"));}
-			//set_msg_as_read(msgs_to_set[i], false);
-		}
-		proxy_mensagens.get_msg(uid_msg,mailbox,false,handler_get_msg);
-		/*var args   = "$this.imap_functions.get_info_msg";
-		var params = "msg_number=" + uid_msg + "&msg_folder=" + mailbox;
-		cExecute(args,handler_get_msg,params);*/
-
-	}
-
-	// Adiciona caixas postais na busca;
-	searchE.prototype.add_mailboxes = function(){
-		var sel = Element("sel_search_nm_box1");
-		if (!proxy_mensagens.is_local_folder(this.name_box_search)) {
-			var name_box     = this.name_box_search.split(cyrus_delimiter);
-			if(this.name_box_search == "")
-				return false;
-			var name_box_def = "";
-			if(name_box.length != 1){
-				name_box_def = name_box[(name_box.length-1)];
-			}else{
-				name_box_def = get_lang("Inbox");		
-			}
-		}
-		else {
-			if(this.name_box_search=='local_root')
-				return;
-			if(this.name_box_search=='local_Inbox')
-				name_box_def = get_lang("Inbox");
-			else if(this.name_box_search.indexOf("/")!="-1") {
-				final_pos = this.name_box_search.lastIndexOf("/");
-				name_box_def = this.name_box_search.substr(final_pos+1);
-			}
-			else
-				name_box_def = this.name_box_search.substr(6);//Retira o 'local_'
-		}
-		if( sel.length > 0){
-			for(var i=0; i < sel.options.length; i++){
-				if(sel.options[i].value == this.name_box_search){
-					alert(get_lang('This message is already selected!'));
-					return false;
-				}
-			}
-		}
-		var opt = new Option(lang_folder(name_box_def),this.name_box_search,false,true);
-		sel[sel.length] = opt;
-	}
-	// Remove as caixas postais na busca;
-	searchE.prototype.del_mailboxes = function(){
-		var sel = Element("sel_search_nm_box1");
-		if(sel.length > 0){
-			for(var i=0; i < sel.options.length; i++){
-				if(sel.options[i].selected == true){
-					sel.options[i] = null;
-					i--;
-				}
-			}
-		}
-	
-	}
-	// todas as caixas
-	searchE.prototype.all_mailboxes = function(){
-		var value = Element("check_all_msg").checked;
-		var cont = parseInt(0);
-		if(value){
-			if(EsearchE.all_boxes.length > 0){
-				EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));			
-			}
-			for(var i=0; i < folders.length; i++){
-				EsearchE.all_boxes[cont] = folders[i].folder_id;
-				cont++;
-			}
-		}else{
-			EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
-		}
-	}
-
-	// Search;
-	searchE.prototype.func_search = function(value){
-		var fields = "##";
-			// Verifica se os campos estão preenchidos;
-			if(trim(Element("txt_ass").value) != ""){
-				fields += "SUBJECT " +  "<=>" +url_encode(Element("txt_ass").value) + "##";
-			}
-			if(trim(Element("txt_body").value) != ""){
-				fields += "BODY " + "<=>" + url_encode(Element("txt_body").value) + "##";
-			}
-			if(trim(Element("txt_de").value) != ""){
-				fields += "FROM " + "<=>" + url_encode(Element("txt_de").value) + "##";
-			}
-			if(trim(Element("txt_para").value) != ""){
-				fields += "TO " + "<=>" + url_encode(Element("txt_para").value) + "##";
-			}
-			if(trim(Element("txt_cc").value) != ""){
-				fields += "CC " + "<=>" + url_encode(Element("txt_cc").value) + "##";
-			}
-                        if (trim(Element("since_date").value) != ""){
-                            if (validate_date(Element("since_date").value))
-                            {
-                                fields += "SINCE " + "<=>" + url_encode(Element("since_date").value) + "##";
-                            }
-                            else
-                                {
-                                    alert(get_lang('Invalid date on field %1'), get_lang('Since Date'));
-                                    return false;
-                                }
-                        }
-                        if (trim(Element("before_date").value) != ""){
-                            if (validate_date(Element("before_date").value))
-                            {
-                                fields += "BEFORE " + "<=>" + url_encode(Element("before_date").value) + "##";
-                            }
-                            else
-                                {
-                                    alert(get_lang('Invalid date on field %1'), get_lang('Before Date'));
-                                    return false;
-                                }
-                        }
-                        if(trim(Element("on_date").value) != ""){
-                            if (validate_date(Element("on_date").value))
-                            {
-                                fields += "ON " + "<=>" + url_encode(Element("on_date").value) + "##";
-                            }
-                            else
-                                {
-                                    alert(get_lang('Invalid date on field %1'), get_lang('On Date'));
-                                    return false;
-                                }
-
-                        }
-                        if(trim(Element("flagged").options[Element("flagged").selectedIndex].value) != ""){
-                            if (Element("flagged").options[Element("flagged").selectedIndex].value == "FLAGGED"){
-                                fields += "FLAGGED##";
-                            }
-                            else {
-                                fields += "UNFLAGGED##";
-                            }
-                        }
-                        if(trim(Element("seen").options[Element("seen").selectedIndex].value) != ""){
-                            if (Element("seen").options[Element("seen").selectedIndex].value == "SEEN"){
-                                fields += "SEEN##";
-                            }
-                            else {
-                                fields += "UNSEEN##";
-                            }
-                        }
-                        if(trim(Element("answered").options[Element("answered").selectedIndex].value) != ""){
-                            if (Element("answered").options[Element("answered").selectedIndex].value == "ANSWERED"){
-                                fields += "ANSWERED##";
-                            }
-                            else {
-                                fields += "UNANSWERED##";
-                            }
-                        }
-                        if(trim(Element("recent").options[Element("recent").selectedIndex].value) != ""){
-                            if (Element("answered").options[Element("answered").selectedIndex].value == "RECENT"){
-                                fields += "RECENT##";
-                            }
-                            else {
-                                fields += "OLD##";
-                            }
-                        }
-			if(value) {
-				fields = "##ALL " +  "<=>" +url_encode(value) + "##";
-			}
-
-		if(fields == "##"){
-			alert(get_lang("Define some search parameters!"));
-			return false;
-		}
-		var local_folders = new Array();
-		var temp;
-		
-		if(Element("check_all_msg").checked){
-			this.all_mailboxes();
-			var nm_box = new Array;
-			for(var i=0; i < EsearchE.all_boxes.length; i++){
-				nm_box[i] = EsearchE.all_boxes[i] + fields;
-			}
-			if (preferences.use_local_messages == 1) {
-				temp = expresso_local_messages.list_local_folders();
-				for (var x in temp) {
-					local_folders.push(temp[x][0]);
-				}
-			}
-		}else{
-			var nm_box = new Array;
-			var sel_combo = Element("sel_search_nm_box1");
-			if( sel_combo.options.length <= 0){
-				alert(get_lang("Define the boxes to search!"));
-				return false;
-			}
-			
-			for(var i=0; i < sel_combo.options.length; i++){
-				sel_combo.options[i].selected = true;
-			}
-			for(var i=0; i < sel_combo.options.length; i++){
-				if(sel_combo.options[i].selected == true){
-					if(!proxy_mensagens.is_local_folder(sel_combo.options[i].value))
-						nm_box[nm_box.length] = sel_combo.options[i].value + fields;
-					else
-						local_folders.push(sel_combo.options[i].value.substr(6));
-				}
-			}
-		}
-		var handler = function(data){
-			var tmp;
-			var countTmp= new Array();
-
-                        var dataTemp = data.split('=sumResults=');
-                        var sumResults = dataTemp[0];
-
-                        var data = dataTemp[1] ? dataTemp[1] : dataTemp[0];
-
-			if (local_folders.length > 0) {
-				tmp = expresso_local_messages.search(local_folders, fields);
-				if (tmp!=false) {
-					var tmp2 = tmp.substr(2, data.length - 4);
-					countTmp = tmp.split('####');
-				}
-			}
-//			if((data == "none") && (countTmp.length==0)){alert(get_lang("None result was found."));}
-//			if (preferences.search_result_number == '65536' || (data != 'many results' && countTmp.length < preferences.search_result_number))
-//                        {
-//                            EsearchE.mount_result((data=='none')?tmp:(countTmp.length==0)?data:data+tmp);
-//                        }
-//                        else if (data == 'many results' || countTmp.length >= preferences.search_result_number)
-//                        {
-//                            alert(get_lang("More than %1 results. Please, try to refine your search.",preferences.search_result_number));
-//                        }
-
-                        if ((sumResults == "none") && (countTmp.length==0)){
-                            alert(get_lang("None result was found."));
-                        }
-                        else
-                        {
-                            EsearchE.mount_result((sumResults=='none')?tmp:(countTmp.length==0)?data:data+tmp);
-                        }
-
-		}
-		var args   = "$this.imap_functions.search_msg";
-		var params = "condition=" + nm_box;
-		if(expresso_offline)
-			handler('none');
-		else
-			cExecute(args,handler,params);
-	}
-	// clean;
-	searchE.prototype.func_clean = function(){
-		// Limpa os campos;
-            for(var i=0; i < this.txtfields.length; i++){
-                    if(Element(this.txtfields[i]) != null){Element(this.txtfields[i]).value = "";}
-            }
-
-            for(i = 0; i < this.selectFields.length; i++)
-            {
-                if (Element(this.selectFields[i]))
-                {
-                    Element(this.selectFields[i]).selectedIndex = 0;
-                }
-            }
-	    if(Element("check_all_msg") != null){Element("check_all_msg").checked = false;}
-
-	    EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
-	  	EsearchE.del_mailboxes();
-	}
-
-	// close
-	searchE.prototype.func_close = function(type){
-		var _this = this;
-		_this.name_box_search = "";
-		EsearchE.all_boxes.splice(0,(EsearchE.all_boxes.length));
-		_this.type = type;
-		_this.searchW['window_search'].close();
-	}
-	// Monta a janela em tela;
-	searchE.prototype.showWindow = function(div){
-		if(!this.searchW[div.id]) {
-			div.style.width = "804px";
-			div.style.height = "440px";
-			div.style.visibility = "hidden";
-			div.style.position = "absolute";
-			div.style.zIndex = "10003";
-			var title = ":: "+ get_lang("Search")+" ::";
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-
-			win = new dJSWin({
-				id: 'ccList'+div.id,
-				content_id: div.id,
-				width: wWidth,
-				height: wHeight,
-				title_color: '#3978d6',
-				bg_color: '#eee',
-				title: title,
-				title_text_color: 'white',
-				button_y_img: '../phpgwapi/images/win_min.gif',
-				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true });
-			this.searchW[div.id] = win;
-			win.draw();
-		}else{
-			var _this = this;
-			win = this.searchW[div.id];
-			if((_this.type == "close" && win.state == 0) || win.state == 2){EsearchE.func_clean();}
-			win.draw();
-		}
-		win.open();	
-	}
-	
-	searchE.prototype.aux_local_folder_display = function(folder) {
-		if(!expresso_offline)
-			return "(Local) " + lang_folder(folder.substr(6));
-		else
-			return lang_folder(folder.substr(6));
-	}
-	
-// Cria o objeto
-	var EsearchE;
-	EsearchE = new searchE();
Index: trunk/expressoMail1_2/js/InfoQuota.js
===================================================================
--- trunk/expressoMail1_2/js/InfoQuota.js	(revision 2365)
+++ 	(revision )
@@ -1,217 +1,0 @@
-function emInfoQuota ()
-	{
-		this.win;
-		this.el;	
-		this.preLoad();
-	}
-	
-	emInfoQuota.prototype.preLoad = function(){
-		if(Element("table_quota")) {
-			Element("table_quota").style.cursor = "pointer";
-			Element("table_quota").title = get_lang("View Quota Usage in Folders");			
-			Element("table_quota").onclick = function (){
-				InfoQuota.showList();
-			}		
-		}
-	}
-
-	emInfoQuota.prototype.showList = function()
-	{
-		var _this = this;		
-		var el = Element("window_InfoQuota");
-		if(!el) {
-			el = document.createElement("DIV");
-			el.style.visibility = "hidden";
-			el.style.position = "absolute";
-			el.style.left = "0px";
-			el.style.top = "0px";
-			el.style.overflowY = "auto";
-			el.align = "center";			
-			div.style.height = "400px";			
-			el.id = 'window_InfoQuota';
-			document.body.appendChild(el);
-		}		
-		
-		var handler_buildQuota = function(data){			
-			el.appendChild(InfoQuota.buildQuota(data));			
-			el.innerHTML += '<br><input style="margin-bottom:10px" type="button" value=' + get_lang("Close")+ 
-			' id="InfoQuota_button_close" onClick="InfoQuota.close_window();">';			
-			_this.showWindow(el);
-		}
-		
-		cExecute ("$this.imap_functions.get_quota_folders", handler_buildQuota);		
-	}
-
-	emInfoQuota.prototype.showWindow = function (div)
-	{							
-		if(! this.win) {
-			div.style.height = "350px";
-			div.style.width = "450px";
-			var title = get_lang("View Quota Usage in Folders");			
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";			
-
-			this.win = new dJSWin({			
-				id: 'win_'+div.id,
-				content_id: div.id,
-				width: wWidth,
-				height: wHeight,
-				title_color: '#3978d6',
-				title_align: 'center',
-				bg_color: '#eee',
-				title: title,						
-				title_text_color: 'white',
-				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true });
-						
-			this.win.draw();
-			this.win.title.align = "center";
-		}
-		
-		this.win.open();
-	}
-
-	emInfoQuota.prototype.close_window = function() {		
-		this.win.close();
-	}
-	
-	emInfoQuota.prototype.buildQuota = function (data){
-		if(Element("window_InfoQuota")){
-			Element("window_InfoQuota").innerHTML = '';
-		}
-		var content = '';
-		var q_limit = data.quota_root.quota_limit;		
-		
-		var value = '';
-		var q_used = '';
-		var table = document.createElement("TABLE");
-		table.id = "table_quota";
-		table.style.border="1px solid #CCC";
-		table.style.marginTop = "10px";
-		table.style.width="100%";
-		table.style.height="80%";
-		table.style.background = "#FFF";
-		table.cellSpacing = 5;
-		table.cellPadding = 0;		 		
-		var thead = document.createElement("THEAD");
-		var tbody = document.createElement("TBODY");
-		var tfoot = document.createElement("TFOOT");
-		table.appendChild(thead);
-		table.appendChild(tbody);
-		table.appendChild(tfoot);		
-		thead.style.background = "#FFF";
-		var tr_thead = document.createElement("TR");
-		tr_thead.style.fontSize = "10pt";
-		tr_thead.style.height = '10px';
-		tr_thead.style.background = "#3978d6";
-		tr_thead.style.color = "white";
-		tr_thead.style.fontWeight = "bold";
-		tr_thead.outerHTML = tr_thead.outerHTML;
-		thead.appendChild(tr_thead);
-		var th_thead = document.createElement("TH");
-		th_thead.style.paddingRight = '5px';
-		th_thead.style.paddingLeft = '5px';		
-		th_thead.innerHTML = get_lang('Folder');
-		tr_thead.appendChild(th_thead);		
-		th_thead = document.createElement("TH");
-		th_thead.style.paddingRight = '5px';
-		th_thead.style.paddingLeft = '5px';
-		th_thead.style.align = "center";
-		th_thead.colSpan = "2"; 
-		th_thead.noWrap = "true";		
-		th_thead.innerHTML = get_lang('% used');
-		tr_thead.appendChild(th_thead);		
-		th_thead = document.createElement("TH");
-		th_thead.style.paddingRight = '5px';
-		th_thead.style.paddingLeft = '5px';
-		th_thead.noWrap = "true";
-		th_thead.innerHTML = get_lang("Size")+" (bytes)";
-		tr_thead.appendChild(th_thead);
-		tbody.style.overflowY = "auto";
-		tbody.style.overflowX = "hidden";
-		tbody.style.width = "50%";		
-		var last_folder = 'null';
-		for(var x in data) {
-			if(x == 'quota_root') continue;				
-			q_used = data[x]['quota_used'];
-			value = data[x]['quota_percent'];
-			td01 = document.createElement("TD");
-			td01.align="left";			
-			if(x.indexOf(last_folder+"/") == -1){
-				last_folder = x;
-				td01.innerHTML = "&nbsp;"+x;
-			}
-			else {
-				var a_folder = x.split('/');
-				for (var i =0; i< a_folder.length;i++)
-					td01.innerHTML  += "&nbsp;&nbsp;";				
-				td01.innerHTML  += a_folder[a_folder.length-1];
-			}
-			
-			td01.style.borderBottom = "1px dashed #DDD";
-			td01.width="40%";
-			td01.setAttribute("noWrap","true");			
-			td02 = document.createElement("TD");
-			td02.align="center";
-			td02.width="5%";
-			td02.setAttribute("noWrap","true");			
-			td02.innerHTML = value+"%";
-			td11 = document.createElement("TD");
-			td11.width="10%";
-			td11.align="center";
-			td11.setAttribute("noWrap","true");
-			td11.style.borderBottom = "1px dashed #DDD";
-			td11.innerHTML += '&nbsp;<span class="boxHeaderText">'+q_used+"</span>";
-			tr2 = document.createElement("TR");
-			td21 = document.createElement("TD");
-			td21.setAttribute("noWrap","true");			
-			td21.height="15px";
-			td22 = document.createElement("TD");	
-			td21.setAttribute("background","../phpgwapi/templates/"+template+"/images/dsunused.gif");
-			table221 = document.createElement("TABLE");
-			tbody221 = document.createElement("TBODY");
-			table221.appendChild(tbody221);
-			table221.style.width=value+"%";	
-			td21.width="30%";
-			table221.cellSpacing = 0;
-			table221.cellPadding = 0;
-			tr221 = document.createElement("TR");
-			td221 = document.createElement("TD");
-			td221.height="15px";
-			td221.className = 'dsused';			
-			tr221.appendChild(td221);
-			tbody221.appendChild(tr221);
-			td21.appendChild(table221);
-			tr2.appendChild(td01);
-			tr2.appendChild(td02);
-			tr2.appendChild(td21);
-			tr2.appendChild(td11);	
-			tbody.appendChild(tr2);
-		}	
-		var tr_tfoot = document.createElement("TR");
-		tr_tfoot.style.fontSize = "10pt";		
-		tr_tfoot.style.color = "#bbb";
-		tr_tfoot.style.fontWeight = "bold";
-		tfoot.appendChild(tr_tfoot);		
-		var th_tfoot = document.createElement("TH");
-		th_tfoot.style.align = "center";
-		th_tfoot.colSpan = "4";
-		th_tfoot.style.paddingRight = '5px';
-		th_tfoot.style.paddingLeft = '5px';		
-		th_tfoot.innerHTML = get_lang("You are currently using %1Mb (%2%).",data.quota_root.quota_used, data.quota_root.quota_percent);
-		tr_tfoot.appendChild(th_tfoot);		
-		return table;
-	}
-	
-/* Build the Object */	
-	var InfoQuota;
-	InfoQuota = new emInfoQuota();
-	
-	/* Override function :: refresh and auto_refresh */	
-	var __build_quota = build_quota;
-	build_quota = function (data) {
-		__build_quota(data);
-		if(InfoQuota.win)
-			InfoQuota.win.close();
-		InfoQuota.preLoad();
-	}
Index: trunk/expressoMail1_2/js/messages_controller.js
===================================================================
--- trunk/expressoMail1_2/js/messages_controller.js	(revision 2402)
+++ 	(revision )
@@ -1,327 +1,0 @@
-/**
- * @author diogenes
- */
-
-	function messages_proxy() {
-		
-	}
-/**
- * Retorna os cabeçalhos das mensagens a serem desenhadas na caixa de email.
- */
-	messages_proxy.prototype.messages_list = function(folder,msg_range_begin,emails_per_page,sort_box_type,search_box_type,sort_box_reverse,preview_msg_subject,preview_msg_tip,call_back) {
-		if(this.is_local_folder(folder)) {
-			var real_folder = folder.substr(6);		
-			var msgs = expresso_local_messages.get_local_range_msgs(real_folder,msg_range_begin,preferences.max_email_per_page,sort_box_type,sort_box_reverse,search_box_type,preferences.preview_msg_subject,preferences.preview_msg_tip);
-			eval('call_back(msgs)');
-			draw_tree_local_folders();
-		}else {
-			cExecute ("$this.imap_functions.get_range_msgs2&folder="+folder+"&msg_range_begin="+msg_range_begin+"&msg_range_end="+emails_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", call_back);
-		}
-	}
-
-	messages_proxy.prototype.get_msg = function(msg_number,msg_folder,set_flag,call_back) {
-		if(this.is_local_folder(msg_folder)) {
-			if(set_flag)
-				expresso_local_messages.set_messages_flag(msg_number,"seen");
-			var data = expresso_local_messages.get_local_mail(msg_number);	
-
-			eval("call_back(data)");
-		}else {
-			expresso.connector.cacheNextRequest();
-			cExecute("$this.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), call_back);
-		}
-	}
-	
-	messages_proxy.prototype.delete_msgs = function(folder, msgs_number, border_ID) {
-
-		if (folder == 'null')
-			folder = get_current_folder();
-		if (msgs_number == 'selected')
-			msgs_number = get_selected_messages();
-			
-		if (!this.is_local_folder(folder)) 
-			delete_msgs(folder, msgs_number, border_ID);
-		else {
-			expresso_local_messages.delete_msgs(msgs_number, border_ID);
-			draw_tree_local_folders();
-		}
-	}
-	
-	messages_proxy.prototype.link_anexo = function (info_msg,numero_ordem_anexo) {
-
-		if(info_msg.local_message==true) {
-			return "javascript:download_local_attachment('"+
-					expresso_local_messages.get_url_anexo(info_msg.msg_number,info_msg.attachments[numero_ordem_anexo].pid)+
-					"')";
-		}
-		else {
-			return "javascript:download_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"',"+numero_ordem_anexo+",'"+info_msg.attachments[numero_ordem_anexo].pid+"','"+info_msg.attachments[numero_ordem_anexo].encoding+"','"+info_msg.attachments[numero_ordem_anexo].name+"')";
-		}
-	}
-
-	messages_proxy.prototype.proxy_source_msg = function (id_msg,folder) {
-		if(!this.is_local_folder(folder)) {
-			source_msg(id_msg,folder);
-		}
-		else {
-			var num_msg = id_msg.substr(0,(id_msg.length - 2));
-			expresso_local_messages.get_source_msg(num_msg);
-		}
-	}
-	
-	messages_proxy.prototype.proxy_set_messages_flag = function (flag,msg_number){
-		if(this.is_local_folder(get_current_folder())) {
-			expresso_local_messages.set_messages_flag(msg_number,flag);
-		}
-		else {
-			set_messages_flag(flag,msg_number);
-		}
-	}
-	
-	messages_proxy.prototype.proxy_set_message_flag = function (msg_number,flag){
-		var msg_number_folder = Element("new_input_folder_"+msg_number+"_r");
-		var folder = msg_number_folder ?  msg_number_folder.value : get_current_folder()
-		if(this.is_local_folder(folder)) {
-			expresso_local_messages.set_message_flag(msg_number,flag);
-		}
-		else {
-			set_message_flag(msg_number,flag);
-		}
-	}
-	
-	messages_proxy.prototype.is_local_folder = function(folder) {
-		if(folder.indexOf("local_")==-1)
-			return false;
-		return true;
-	}
-	
-
-	messages_proxy.prototype.proxy_rename_folder = function(){
-
-		if (ttree.FOLDER == 'local_Inbox') {
-			alert(get_lang("It's not possible rename the folder: ") + lang_folder(ttree.FOLDER.substr(6)));
-			return false;
-		}
-		if(ttree.FOLDER == 'local_root') {
-				alert(get_lang("It's not possible rename this folder!"));
-				return false;
-		}
-		if (this.is_local_folder(ttree.FOLDER)) {
-			folder = prompt(get_lang("Enter a name for the box"), "");
-			if(trim(folder) == "" || trim(folder) == null){
-				alert(get_lang("you have to enter the name of the new folder"));
-				return false;
-			}
-			var temp = expresso_local_messages.rename_folder(folder, ttree.FOLDER.substr(6));
-			if (!temp) 
-				alert(get_lang("cannot rename folder. try other folder name"));
-			ttreeBox.update_folder();
-		}
-		else {
-			ttreeBox.validate("rename");
-		}
-		
-	}
-
-	messages_proxy.prototype.proxy_create_folder = function() {
-		if (this.is_local_folder(ttree.FOLDER)) {
-			folder = prompt(get_lang('Enter the name of the new folder:'), "");
-
-			if(trim(folder) == "" || trim(folder) == null){
-				alert(get_lang("you have to enter the name of the new folder"));
-				return false;
-			}
-			if(ttree.FOLDER=="local_root")
-				var temp = expresso_local_messages.create_folder(folder);
-			else
-				var temp = expresso_local_messages.create_folder(ttree.FOLDER.substr(6)+"/"+folder);
-			if (!temp) 
-				alert(get_lang("cannot create folder. try other folder name"));
-			ttreeBox.update_folder();
-		}
-		else			
-			if(ttree.FOLDER == "INBOX")
-				alert(get_lang("It's not possible create inside: ") + lang_folder(ttree.FOLDER));
-			else if (!this.is_local_folder(ttree.FOLDER))
-				ttreeBox.validate("newpast");
-			else 
-				alert(get_lang("It's not possible create inside: ") + lang_folder(ttree.FOLDER.substr(6)));
-	}
-	
-	messages_proxy.prototype.proxy_remove_folder = function() {
-		if (this.is_local_folder(ttree.FOLDER)) {
-			if(ttree.FOLDER == 'local_root') {
-				alert(get_lang("Select a folder!"));
-				return false;
-			}
-			if (ttree.FOLDER == 'local_Inbox') {
-				alert(get_lang("It's not possible delete the folder: ")  + lang_folder(ttree.FOLDER.substr(6)));
-				return false;
-			}
-			if(ttree.FOLDER.indexOf("/")!="-1") {
-				final_pos = ttree.FOLDER.lastIndexOf("/");
-				new_caption = ttree.FOLDER.substr(final_pos+1);
-			}
-			else {
-				new_caption = ttree.FOLDER.substr(6);
-			}
-			var string_confirm = get_lang("Do you wish to exclude the folder ") + new_caption + "?";
-
-			if (confirm(string_confirm)) {
-				expresso_local_messages.remove_folder(ttree.FOLDER.substr(6));
-				alert(get_lang("The folder %1 was successfully removed", new_caption));
-				ttreeBox.update_folder();
-			}
-		}
-		else
-			ttreeBox.del();
-	}
-
-	messages_proxy.prototype.proxy_move_messages = function (folder, msgs_number, border_ID, new_folder, new_folder_name) {
-		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 ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
-			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 (new_folder == 'local_root')
-				alert(get_lang("Select a folder!"));
-			if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
-				expresso_local_messages.move_messages(new_folder.substr(6), msgs_number);
-				this.aux_interface_remove_mails(msgs_number, new_folder_name, border_ID);
-				draw_tree_local_folders();
-			}
-			else 
-				write_msg(get_lang('No selected message.'));
-		}
-		else 
-			if ((!this.is_local_folder(folder)) && (!this.is_local_folder(new_folder))) { //Move entre pastas locais...
-				move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
-			}
-			else if ((!this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) {
-				if(msgs_number=='selected')
-					archive_msgs(folder,new_folder);
-				else
-					archive_msgs(folder,new_folder,msgs_number);
-				draw_tree_local_folders();
-			}
-			else {
-                //Por Bruno Costa (bruno.vieira-costa@serpro.gov.br) permite o desarquivamento de menssagens chamando a função unarchive_msgs quando uma msg é movida de uma pasta local para uma pasta remota.
-
-				expresso_local_messages.unarchive_msgs(folder,new_folder,msgs_number);
-                //write_msg(get_lang("you can't move mails from local to server folders"));
-			}
-		
-		
-	}
-	
-	messages_proxy.prototype.proxy_move_search_messages = function(border_id, new_folder, new_folder_name) {
-		
-		
-		/*
-		
-		
-		if ((this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) { //Move entre pastas não locais...
-			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 (new_folder == 'local_root')
-				alert(get_lang("Select a folder!"));
-			if (parseInt(msgs_number) > 0 || msgs_number.length > 0) {
-				expresso_local_messages.move_messages(new_folder.substr(6), msgs_number);
-				this.aux_interface_remove_mails(msgs_number, new_folder_name, border_ID);
-			}
-			else 
-				write_msg(get_lang('No selected message.'));
-		}
-		else 
-			if ((!this.is_local_folder(folder)) && (!this.is_local_folder(new_folder))) { //Move entre pastas locais...
-				move_msgs(folder, msgs_number, border_ID, new_folder, new_folder_name);
-			}
-			else if ((!this.is_local_folder(folder)) && (this.is_local_folder(new_folder))) {
-				archive_msgs(folder,new_folder);
-			}
-			else {
-				write_msg(get_lang("you can't move mails from local to server folders"));
-			}*/
-	}
-	
-	messages_proxy.prototype.aux_interface_remove_mails = function(msgs_number,new_folder_name,border_ID,previous_msg) {
-		Element('chk_box_select_all_messages').checked = false;
-		mail_msg = Element("tbody_box");
-		msgs_number = msgs_number.split(",");
-		var msg_to_delete;
-		for (var i=0; i<msgs_number.length; i++){
-			msg_to_delete = Element(msgs_number[i]);
-			if (msg_to_delete){
-				if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') )
-					select_msg('null', 'down');
-				mail_msg.removeChild(msg_to_delete);
-			}
-		}
-		if (msgs_number.length == 1)
-			write_msg(get_lang("The message was moved to folder ") + new_folder_name);
-		else
-			write_msg(get_lang("The messages were moved to folder ") + new_folder_name);
-
-		if (border_ID != '' && border_ID != 'null'){
-				delete_border(border_ID,'false');
-		}
-		if(folder == get_current_folder())
-			Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - msgs_number.length;			
-		refresh();		
-		
-	}
-
-   	messages_proxy.prototype.msg_img = function(msgs_number,folder_name,call_back) {
-     if(this.is_local_folder(folder_name)){
-         var msg = expresso_local_messages.get_local_mail(msgs_number);
-		 eval('call_back(msg)');
-     }
-     else
-     {
-	expresso.connector.cacheNextRequest();
-        cExecute('$this.imap_functions.get_info_msg&msg_number='+msgs_number+'&msg_folder='+url_encode(folder_name),call_back);
-     }
-    }
-
-    messages_proxy.prototype.export_all_messages = function(folder){
-
-		if (!folder){
-			folder = get_current_folder();
-		}
-
-		if(!this.is_local_folder(folder)){
-			export_all_selected_msgs();
-		}else{
-			local_messages.prototype.local_messages_to_export();
-		}
-	}
-
-    	messages_proxy.prototype.proxy_export_all_msg=function(){
-
-		var er=/^local/;
-
-
-		if(ttree.FOLDER == "local_root"){return false;}   //Usuario não selecionou uma pasta local e esta no comeÃ§o dos nÃ³s
-		var nm_bx = ttree.FOLDER.split(cyrus_delimiter);
-
-		var name_f = nm_bx[nm_bx.length -1].replace("local_","");
-
-		if (!er.test(nm_bx)){
-			//Se a pasta nao for local, ou seja a string nao contem a string "local"
-			ttreeBox.export_all_msg();
-		} else{
-			expresso_local_messages.get_all_local_folder_messages(name_f);
-		}
-	}
-
-	var proxy_mensagens;
-	proxy_mensagens = new messages_proxy();
Index: trunk/expressoMail1_2/js/shortcut.js
===================================================================
--- trunk/expressoMail1_2/js/shortcut.js	(revision 2017)
+++ 	(revision )
@@ -1,558 +1,0 @@
-/**
- * http://www.openjs.com/scripts/events/keyboard_shortcuts/
- * Version : 2.01.A
- * By Binny V A
- * License : BSD
- */
-shortcut = {
-	'all_shortcuts':{},//All the shortcuts are stored in this array
-	'add': function(shortcut_combination,callback,opt) {
-		//Provide a set of default options
-		var default_options = {
-			'type':'keydown',
-			'propagate':false,
-			'disable_in_input':false,
-			'target':document,
-			'keycode':false
-		}
-		if(!opt) opt = default_options;
-		else {
-			for(var dfo in default_options) {
-				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
-			}
-		}
-		
-		var ele = opt.target
-		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
-		var ths = this;
-		shortcut_combination = shortcut_combination.toLowerCase();
-
-		//The function to be called at keypress
-		var func = function(e) {
-			e = e || window.event;
-			
-			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
-				var element;
-				if(e.target) element=e.target;
-				else if(e.srcElement) element=e.srcElement;
-				if(element.nodeType==3) element=element.parentNode;
-
-				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
-			}
-	
-			//Find Which key is pressed
-			if (e.keyCode) code = e.keyCode;
-			else if (e.which) code = e.which;
-			var character = String.fromCharCode(code).toLowerCase();
-			
-			if(code == 188) character=","; //If the user presses , when the type is onkeydown
-			if(code == 190) character="."; //If the user presses , when the type is onkeydown
-	
-			var keys = shortcut_combination.split("+");
-			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
-			var kp = 0;
-			
-			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
-			var shift_nums = {
-				"`":"~",
-				"1":"!",
-				"2":"@",
-				"3":"#",
-				"4":"$",
-				"5":"%",
-				"6":"^",
-				"7":"&",
-				"8":"*",
-				"9":"(",
-				"0":")",
-				"-":"_",
-				"=":"+",
-				";":":",
-				"'":"\"",
-				",":"<",
-				".":">",
-				"/":"?",
-				"\\":"|"
-			}
-			//Special Keys - and their codes
-			var special_keys = {
-				'esc':27,
-				'escape':27,
-				'tab':9,
-				'space':32,
-				'return':13,
-				'enter':13,
-				'backspace':8,
-	
-				'scrolllock':145,
-				'scroll_lock':145,
-				'scroll':145,
-				'capslock':20,
-				'caps_lock':20,
-				'caps':20,
-				'numlock':144,
-				'num_lock':144,
-				'num':144,
-				
-				'pause':19,
-				'break':19,
-				
-				'insert':45,
-				'home':36,
-				'delete':46,
-				'end':35,
-				
-				'pageup':33,
-				'page_up':33,
-				'pu':33,
-	
-				'pagedown':34,
-				'page_down':34,
-				'pd':34,
-	
-				'left':37,
-				'up':38,
-				'right':39,
-				'down':40,
-	
-				'f1':112,
-				'f2':113,
-				'f3':114,
-				'f4':115,
-				'f5':116,
-				'f6':117,
-				'f7':118,
-				'f8':119,
-				'f9':120,
-				'f10':121,
-				'f11':122,
-				'f12':123
-			}
-	
-			var modifiers = { 
-				shift: { wanted:false, pressed:false},
-				ctrl : { wanted:false, pressed:false},
-				alt  : { wanted:false, pressed:false},
-				meta : { wanted:false, pressed:false}	//Meta is Mac specific
-			};
-                        
-			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
-			if(e.shiftKey)	modifiers.shift.pressed = true;
-			if(e.altKey)	modifiers.alt.pressed = true;
-			if(e.metaKey)   modifiers.meta.pressed = true;
-                        
-			for(var i=0; k=keys[i],i<keys.length; i++) {
-				//Modifiers
-				if(k == 'ctrl' || k == 'control') {
-					kp++;
-					modifiers.ctrl.wanted = true;
-
-				} else if(k == 'shift') {
-					kp++;
-					modifiers.shift.wanted = true;
-
-				} else if(k == 'alt') {
-					kp++;
-					modifiers.alt.wanted = true;
-				} else if(k == 'meta') {
-					kp++;
-					modifiers.meta.wanted = true;
-				} else if(k.length > 1) { //If it is a special key
-					if(special_keys[k] == code) kp++;
-					
-				} else if(opt['keycode']) {
-					if(opt['keycode'] == code) kp++;
-
-				} else { //The special keys did not match
-					if(character == k) kp++;
-					else {
-						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
-							character = shift_nums[character]; 
-							if(character == k) kp++;
-						}
-					}
-				}
-			}
-
-			if(kp == keys.length && 
-						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
-						modifiers.shift.pressed == modifiers.shift.wanted &&
-						modifiers.alt.pressed == modifiers.alt.wanted &&
-						modifiers.meta.pressed == modifiers.meta.wanted) {
-				callback(e);
-	
-				if(!opt['propagate']) { //Stop the event
-					//e.cancelBubble is supported by IE - this will kill the bubbling process.
-					e.cancelBubble = true;
-					e.returnValue = false;
-	
-					//e.stopPropagation works in Firefox.
-					if (e.stopPropagation) {
-						e.stopPropagation();
-						e.preventDefault();
-					}
-					return false;
-				}
-			}
-		}
-		this.all_shortcuts[shortcut_combination] = {
-			'callback':func, 
-			'target':ele, 
-			'event': opt['type']
-		};
-		//Attach the function with the event
-		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
-		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
-		else ele['on'+opt['type']] = func;
-	},
-
-	//Remove the shortcut - just specify the shortcut and I will remove the binding
-	'remove':function(shortcut_combination) {
-		shortcut_combination = shortcut_combination.toLowerCase();
-		var binding = this.all_shortcuts[shortcut_combination];
-		delete(this.all_shortcuts[shortcut_combination])
-		if(!binding) return;
-		var type = binding['event'];
-		var ele = binding['target'];
-		var callback = binding['callback'];
-
-		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
-		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
-		else ele['on'+type] = false;
-	}
-}
-
-/* ExpressMail Functions */
-var shift_up_count = 0;
-var shift_down_count = 0;
-var selMessageShortcut = "";
-
-shortcut.add("N",function(){ new_message("new","null"); },{'disable_in_input':true});
-
-shortcut.add("Esc",function(){
-	var window_closed = false;
-	for(var window in arrayJSWin)
-	{
-		if (arrayJSWin[window].visible)
-		{
-			arrayJSWin[window].close();
-			window_closed = true;
-		}
-	}
-	if (!window_closed)
-		delete_border(get_msg_id(), 'false');
-},{'disable_in_input':false});
-
-shortcut.add("I",function(){ print_all(); },{'disable_in_input':true}); 
-shortcut.add("E",function(){ exec_msg_action('forward'); },{'disable_in_input':true});
-shortcut.add("R",function(){ exec_msg_action('reply'); },{'disable_in_input':true});
-shortcut.add("O",function(){ show_head_option(); },{'disable_in_input':true});
-shortcut.add("M",function(){ show_address_full(); },{'disable_in_input':true});
-
-shortcut.add("Delete",function(){
-	
-	var selected_shortcut_msgs = '';
-	var tbody_box = Element('tbody_box');
-	all_messages = Element('tbody_box').childNodes;
-	
-	for ( var i=0; i < all_messages.length; i++ )
-	{
-		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-		{
-			selected_shortcut_msgs += all_messages[i].id + ',';
-			
-			if( all_messages[i].nextSibling )
-				selMessageShortcut = all_messages[i].nextSibling.id + "-" + "down";
-			else if(all_messages[i].previousSibling)
-				selMessageShortcut = all_messages[i].previousSibling.id + "-" + "up";
-		}
-	}
-	selected_shortcut_msgs = selected_shortcut_msgs.substring(0,(selected_shortcut_msgs.length-1));
-	
-	if ( Element('border_id_0').className==='menu-sel' )
-	{
-		proxy_mensagens.delete_msgs(current_folder, selected_shortcut_msgs, 'null');
-	}
-	else
-	{
-		exec_msg_action('delete');
-		select_msg(selMessageShortcut.substring(0, selMessageShortcut.indexOf("-")),
-				   selMessageShortcut.substring(selMessageShortcut.indexOf("-")), true );
-	}
-}
-,{'disable_in_input':true});
-
-shortcut.add("Ctrl+Up",function(){ exec_msg_action('previous'); select_msg('null', 'up', true);},{'disable_in_input':true});
-shortcut.add("Ctrl+Down",function(){ exec_msg_action('next'); select_msg('null', 'down', true);},{'disable_in_input':true});
-
-if (is_ie)
-{
-	shortcut.add("down",function(){ select_msg('null', 'down'); },{'disable_in_input':false});
-	shortcut.add("up",function(){ select_msg('null', 'up'); },{'disable_in_input':false});	
-	
-	shortcut.add("Shift+down",function(){
-		if ( Element('border_id_0').className==='menu-sel' )
-		{
-			if (shift_up_count > 0)
-				unselect_top_msg();
-			else
-				select_bottom_msg();
-		}
-	},{'disable_in_input':true, 'propagate':false});
-	
-	shortcut.add("Shift+up",function(){
-		if ( Element('border_id_0').className==='menu-sel' )
-		{
-			if (shift_down_count > 0)
-				unselect_bottom_msg();
-			else
-				select_top_msg();
-		}
-	},{'disable_in_input':true, 'propagate':false});
-}
-else
-{
-	shortcut.add("down",function(){ select_msg('null', 'down');},{'type':'keypress', 'disable_in_input':false});
-	shortcut.add("up",function(){ select_msg('null', 'up');},{'type':'keypress', 'disable_in_input':false});
-	
-	shortcut.add("Shift+down",function(){
-		if ( Element('border_id_0').className==='menu-sel' )
-		{
-			if (shift_up_count > 0)
-				unselect_top_msg();
-			else
-				select_bottom_msg();
-		}
-	},{'type':'keypress','disable_in_input':true, 'propagate':false});
-	
-	shortcut.add("Shift+up",function(){
-		if ( Element('border_id_0').className==='menu-sel' )
-		{
-			if (shift_down_count > 0)
-				unselect_bottom_msg();
-			else
-				select_top_msg();
-		}
-	},{'type':'keypress', 'disable_in_input':true, 'propagate':false});
-}
-
-shortcut.add("return",function(){
-	if ( Element('border_id_0').className==='menu-sel' )
-	{
-		all_messages = Element('tbody_box').childNodes;
-		for (var i=0; i < all_messages.length; i++)
-		{
-			if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-			{
-				Element("td_who_" + all_messages[i].id).onclick();
-				return;
-			}
-		}
-	}
-}
-,{'disable_in_input':true});
-
-shortcut.add("f9",function(){
-	Element("em_refresh_button").onclick();
-	return;
-},{'disable_in_input':true});
-
-function exec_msg_action(action)
-{
-	var msg_id = get_msg_id();
-	if (msg_id)
-	{
-		var msg_id = 'msg_opt_' + action + '_' + msg_id;
-		try {Element(msg_id).onclick();}
-		catch(e){/*alert(e);*/}
-	}
-	return;
-}
-
-function show_head_option()
-{
-        var msg_id = get_msg_id();
-		
-        if (msg_id)
-        {
-                var msg_id = 'option_hide_more_' + msg_id;
-	        try {Element(msg_id).onclick();}
-                catch(e){/*alert(e);*/}
-        }
-        return;
-}
-
-function show_address_full()
-{
-	var toaddress = Element('div_toaddress_' + get_msg_id());
-	if ( '' == toaddress.style.display )
-	{
-		show_div_address_full(get_msg_id(),'to')
-		show_div_address_full(get_msg_id(),'cc')
-	}
-	else
-	{
-	        Element('div_toaddress_full_' + get_msg_id()).style.display='none';
-        	Element('div_toaddress_' + get_msg_id()).style.display='';
-	        Element('div_ccaddress_full_'+ get_msg_id()).style.display='none';
-        	Element('div_ccaddress_'+ get_msg_id()).style.display='';
-	}
-
-	return;
-}
-
-function get_msg_id()
-{
-	children = Element('border_tr').childNodes;
-	
-	for (var i=0; i<children.length; i++)
-	{
-		if ( (children[i].nodeName==='TD') && (children[i].className==='menu-sel') && children[i].id != 'border_id_0')
-		{
-			var border_selected = children[i];
-			var msg_id = border_selected.id.replace("border_id_","");
-			return msg_id;
-		}
-	}
-	return false;
-}
-
-function select_msg(msg_number, keyboard_action, force_msg_selection)
-{
-	//Select msg, even if the focus isn't the border_id_0
-	if ( (Element('border_id_0').className != 'menu-sel') && (!force_msg_selection) )
-		return;
-
-	shift_up_count = 0;
-	shift_down_count = 0;
-
-	if (msg_number != 'null')
-	{
-		unselect_all_msgs();
-		add_className(Element(msg_number), 'selected_shortcut_msg')
-	}
-	else
-	{
-		var scrollMain = Element('divScrollMain_0');
-		var selection_size = parseInt(preferences.line_height) + 10; 
-
-		if( keyboard_action == 'down')
-		{
-			for (var i=all_messages.length-1; i >=0; i--)
-			{
-				if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-				{
-					add_className(all_messages[i+1], 'selected_shortcut_msg')
-					var mailPos = i;
-					break;
-				}
-			}
-			
-			for (; i>=0; i--)
-			{
-				if( all_messages[i].nextSibling )
-					remove_className(all_messages[i], 'selected_shortcut_msg');
-			}
-			if ((mailPos) && (parseInt(scrollMain.style.height.substr(0,scrollMain.style.height.length-2)) + scrollMain.scrollTop) < (all_messages[mailPos].offsetTop + selection_size))
-				scrollMain.scrollTop += selection_size;
-
-		}
-		else if( keyboard_action == 'up')
-		{
-			for (var i=0; i < all_messages.length; i++)
-			{
-				if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-				{
-					if( all_messages[i].previousSibling )
-					{
-						add_className(all_messages[i-1], 'selected_shortcut_msg')
-						var mailPos = i;
-						break;
-					}
-				}
-			}
-			
-			for (; i< all_messages.length; i++)
-			{
-				remove_className(all_messages[i], 'selected_shortcut_msg')
-			}
-		if (typeof(all_messages[mailPos]) != 'undefined' && all_messages[mailPos].offsetTop <= scrollMain.scrollTop)
-			scrollMain.scrollTop -= selection_size+10;
-		}
-
-		return true;
-	}
-}
-
-function select_bottom_msg()
-{
-	all_messages = Element('tbody_box').childNodes;
-	
-	if ( exist_className(all_messages[all_messages.length-1], 'selected_shortcut_msg') )
-		return;
-	
-	for (var i=all_messages.length-1; i >=0; i--)
-	{
-		if ( (exist_className(all_messages[i], 'selected_shortcut_msg')) && (i+1 <= all_messages.length-1) )
-		{
-			shift_down_count++;
-			add_className(all_messages[i+1], 'selected_shortcut_msg');
-			break;
-		}
-	}
-}
-
-function select_top_msg()
-{
-	all_messages = Element('tbody_box').childNodes;
-		
-	if ( exist_className(all_messages[0], 'selected_shortcut_msg') )
-		return;
-	
-	for (var i=0; i <=all_messages.length-1; i++)
-	{
-		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-		{
-			shift_up_count++;
-			add_className(all_messages[i-1], 'selected_shortcut_msg');
-			break;
-		}
-	}
-}
-
-function unselect_bottom_msg()
-{
-	all_messages = Element('tbody_box').childNodes;
-	for (var i=all_messages.length-1; i >=0; i--)
-	{
-		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-		{
-			shift_down_count--;
-			remove_className(all_messages[i], 'selected_shortcut_msg');
-			break;
-		}
-	}
-}
-
-function unselect_top_msg()
-{
-	all_messages = Element('tbody_box').childNodes;
-	for (var i=0; i <=all_messages.length-1; i++)
-	{
-		if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-		{
-			shift_up_count--;
-			remove_className(all_messages[i], 'selected_shortcut_msg');
-			break;
-		}
-	}
-}
-
-function unselect_all_msgs()
-{
-	all_messages = Element('tbody_box').childNodes;
-	for (var i=0; i <=all_messages.length-1; i++)
-	{
-		remove_className(all_messages[i], 'selected_shortcut_msg');
-	}
-}
Index: trunk/expressoMail1_2/js/mail_sync.js
===================================================================
--- trunk/expressoMail1_2/js/mail_sync.js	(revision 2378)
+++ 	(revision )
@@ -1,498 +1,0 @@
-/**
- * @author diogenes
- */
-
-	/**
-	 *  @param folders:
-	 * 		1 - rowid of folder in sqlite
-	 * 		2 - folder name in sqlite
-	 * 		3 - ids to not download(for auto archiving) or ids to download(for archiving)
-	 * 		4 - true for auto archiving and false for normal archiving.
-	 */
-	function mail_sync() {
-//		this.dbGears = null;
-//		this.localServer = null;
-//		this.store = null;
-		this.folders = new Array();
-		this.messages = null;
-		this.attachs = null;
-		this.url_attachs = null;
-		this.working = false;
-		this.is_auto = null;
-		this.errors = new Array();
-//		this.main_title = null;
-		
-		this.main_title = null;
-		this.dbGears = google.gears.factory.create('beta.database');
-		this.localServer = google.gears.factory.create('beta.localserver');
-		this.store = this.localServer.createStore('test-store');
-	}
-	
-	mail_sync.prototype.open_conn = function(){
-		var db_in_other_use = true;
-		var start_trying = new Date().getTime();
-		while (db_in_other_use) {
-			try {
-				this.dbGears.open('database-test');
-				db_in_other_use = false;
-			} 
-			catch (ex) {
-				if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception
-					throw ex;
-				}
-			}
-		}
-	}
-	
-	mail_sync.prototype.start_sync = function() {
-		if(this.working) {
-			//Já está sincronizando...
-			return;
-		}
-		
-		this.open_conn();
-
-		var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario=?",[account_id]);
-		if(!rs.isValidRow()) {
-			this.dbGears.close();
-			return;
-		}
-			
-
-		this.working=true;
-		this.messages = null;
-		this.attachs = null;
-		this.url_attachs = null;
-
-		document.getElementById('main_title').innerHTML = get_lang("Creating folders structure");
-		while(rs.isValidRow()) {
-			var temp = new Array();
-			temp[0] = rs.field(0);
-			temp[1] = rs.field(1);
-			temp[2] = null;
-			temp[3] = false;
-			var rs2 = this.dbGears.execute("select mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where folder.folder = ? and mail.uid_usuario=?",[temp[1]==get_lang('Inbox')?'Inbox':temp[1],account_id]);
-			while(rs2.isValidRow()) {
-				if(temp[2]==null)
-					temp[2]=rs2.field(0)+",";
-				else
-					temp[2]+=rs2.field(0)+",";
-				rs2.next();
-			}
-			this.folders.push(temp);
-			
-			
-			//Criando estrutura de pastas...
-			var folders_to_check = temp[0].split("/");//Todas as pastas tem ao menos INBOX/
-			if (folders_to_check.length == 1) 
-				var actual_check = "Inbox";
-			else {
-				folders_to_check = folders_to_check.slice(1);
-				var actual_check = folders_to_check[0];
-			}
-			for (var i in folders_to_check) {
-				var rs2 = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [actual_check, account_id]);
-				
-				if (!rs2.isValidRow()) {
-					this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)", [actual_check, account_id]);
-				}
-				if(parseInt(i)+1<folders_to_check.length)
-					actual_check += "/"+folders_to_check[parseInt(i)+1];
-			}
-			ttreeBox.update_folder();
-			rs.next();
-		}
-		this.dbGears.close();
-		this.syncronize_folders();
-	}
-	
-	mail_sync.prototype.archive_msgs = function(folder,folder_dest,ids) {
-		//this.main_title = document.getElementById('main_title').innerHTML;
-		var temp = new Array();
-		temp[0] = folder;
-		temp[1] = folder_dest.substr(6);
-		temp[2] = ids;
-		temp[3] = true;
-		this.folders.push(temp);
-		Element('chk_box_select_all_messages').checked = false;
-		
-		array_ids = ids.split(",");
-		for (var i in array_ids) {
-			if (Element("check_box_message_" + array_ids[i])) 
-				Element("check_box_message_" + array_ids[i]).checked = false;
-			remove_className(Element(array_ids[i]), 'selected_msg');
-		}
-		if(!this.working) {
-			this.working=true;
-			this.syncronize_folders();
-		}
-		else {
-			write_msg(get_lang("An archiving is in process, but dont worry, expresso will process this messages after the actual archiving"));
-		}
-	}
-	
-	mail_sync.prototype.syncronize_folders = function() {
-		if (this.folders.length == 0) {
-			document.getElementById('main_title').innerHTML = get_lang("Deleting downloadeds msgs...");
-			expresso_mail_sync.remove_archived_mails();
-			this.working=false;
-			update_menu();
-			return;
-		}
-		var folder_to_sync = this.folders.pop();
-		folder_to_sync[1] = folder_to_sync[0].toUpperCase()=="INBOX" && !folder_to_sync[3]?"Inbox":folder_to_sync[1];
-		
-		if(folder_to_sync[3]) { //Em caso de arquivamento normal, pode ser que a pasta inbox ainda não tenha sido criada.
-			expresso_mail_sync.open_conn()
-			if(folder_to_sync[1]=="Inbox" && !expresso_mail_sync.has_inbox_folder()) {
-				expresso_mail_sync.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]);
-			}
-			expresso_mail_sync.dbGears.close();
-			ttreeBox.update_folder();
-			
-		}
-		
-		var start_sync_mails = function(data) {
-			expresso_mail_sync.messages=data;
-			if(expresso_mail_sync.is_auto)
-				document.getElementById('main_title').innerHTML = get_lang("Auto archiving")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length;
-			else
-				document.getElementById('main_title').innerHTML = get_lang("Archiving messages on folder")+" "+lang_folder(folder_to_sync[1])+": 0 / "+data.length;
-
-			expresso_mail_sync.syncronize_mails(folder_to_sync[1]);
-		}
-		
-
-		if (folder_to_sync[3]) {
-			document.getElementById('main_title').innerHTML = get_lang("Starting to archive messages");
-			cExecute("$this.imap_functions.get_info_msgs&folder=" + folder_to_sync[0] + "&msgs_number=" + folder_to_sync[2], start_sync_mails);
-			this.is_auto = false;
-		}
-		else {
-			document.getElementById('main_title').innerHTML = get_lang("Starting to sync folder")+" "+lang_folder(folder_to_sync[1]);
-			var params = "folder="+folder_to_sync[0]+"&mails="+folder_to_sync[2];
-			cExecute("$this.imap_functions.msgs_to_archive", start_sync_mails,params);
-			this.is_auto = true;
-		}
-			
-	}
-	
-	mail_sync.prototype.syncronize_mails = function(folder_dest) {
-		if (expresso_mail_sync.messages == null || expresso_mail_sync.messages.length == 0) {
-			expresso_mail_sync.syncronize_folders();
-			return;
-		}
-		
-		msg_to_sync = expresso_mail_sync.messages.pop();
-		
-		//refresh loading
-		var value_to_change = document.getElementById('main_title').innerHTML.match(/\d+ \//);
-		value_to_change += "";
-		var new_value = value_to_change.replace(" /","");
-		new_value = parseInt(new_value) + 1;
-		document.getElementById('main_title').innerHTML = document.getElementById('main_title').innerHTML.replace(value_to_change,new_value+" /");
-		msg_to_sync = expresso.connector.unserialize(msg_to_sync);
-		
-		var source_msg = new Array();
-		source_msg['url'] = msg_to_sync.url_export_file;
-
-		if (typeof(msg_to_sync['array_attach'])=='object'&&(msg_to_sync['array_attach'] instanceof Array))
-			expresso_mail_sync.attachs = msg_to_sync['array_attach'].slice();
-		else
-			expresso_mail_sync.attachs = new Array();
-		expresso_mail_sync.attachs.push(source_msg);
-		expresso_mail_sync.download_attachs(msg_to_sync,folder_dest);
-	}
-	
-	mail_sync.prototype.download_attachs = function(msg,folder_dest) {
-		if (expresso_mail_sync.attachs == null || expresso_mail_sync.attachs.length == 0) {
-			expresso_mail_sync.insert_mail(msg, folder_dest);
-			
-			return;
-		}
-		
-		attach_to_capt = expresso_mail_sync.attachs.pop();
-		
-		var call_back = function(url,success,captureId) {
-			if (!success) {
-				/*
-				 * 0 - original id
-				 * 1 - message subject
-				 * 2 - original folder
-				 */
-				var mail_error = new Array();
-				mail_error[0] = msg.msg_number;
-				mail_error[1] = msg.subject;
-				mail_error[2] = msg.msg_folder;
-				expresso_mail_sync.errors.push(mail_error);
-				alert('erro ao baixar: '+url);
-				
-				/*if (typeof(msg['array_attach']) == 'object' && (msg['array_attach'] instanceof Array)) {
-					for (var i in msg['array_attach']) { //remove os anexos que já foram baixados para essa mensagem...
-						expresso_mail_sync.store.remove(msg['array_attach'][i]['url']);
-					}
-				}*/
-				expresso_mail_sync.syncronize_mails(folder_dest); //Pula para o próximo e-mail.
-			}
-			else {
-				expresso_mail_sync.download_attachs(msg, folder_dest);//continua baixando o próximo anexo
-			}
-		}
-		expresso_mail_sync.store.capture(attach_to_capt['url'],call_back);
-	}
-	
-	mail_sync.prototype.insert_mail = function(msg,folder) {
-		try {
-			connector = expresso.connector;
-			expresso_mail_sync.open_conn();
-		
-			var msg_info = msg;
-			var msg_header = msg['header'];
-			var anexos = msg['array_attach'];
-			
-			
-			var unseen = 0;
-			var login = msg_info.login;
-			var original_id = msg_info.msg_number;
-			var original_folder = msg_info.msg_folder=='INBOX/Lixeira/tmpMoveToLocal'?msg_info.msg_folder+(Date.parse(new Date)):msg_info.msg_folder;
-
-			//Os campos abaixo precisam estar isolados para busca de mensagens em cima deles.
-			var from = connector.serialize(msg_info.from);
-			var subject = msg_info.subject;
-			var body = msg_info.body;
-			var to = connector.serialize(msg_info.toaddress2);
-			var cc = connector.serialize(msg_info.cc);
-			var size = msg_header.Size;
-	
-			//Zero os campos que foram isolados para não ter informações duplicadas
-			msg_info.from = null;
-			msg_info.subject = null;
-			msg_info.body = null;
-			msg_info.to = null;
-			msg_info.cc = null;
-			msg_header.Size=null;
-			
-			//A data no header pode vir como horário ao invés de data, caso o usuário tenha arquivado no mesmo
-			//dia que recebeu a msg. Para esses casos, usar a data aux que vem com o dia.
-			if(msg_header.udate.indexOf("/")==-1) {
-				msg_header.udate = msg_header.aux_date;
-			}
-		
-			
-			/**
-			 * The importance attribute can be empty, and javascript consider as null causing nullpointer.
-			 */
-			if((msg_header.Importance == null) ||  (msg_header.Importance == ""))
-				msg_header.Importance = "Normal";
-			
-			msg_header.aux_date = null; //esse dado não é mais preciso no email.
-			
-			var mail = connector.serialize(msg_info);
-			var header = connector.serialize(msg_header);
-	
-			var timestamp = msg_info.timestamp;
-			var id_folder;
-			
-			var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [folder, account_id]);
-			id_folder = rs.field(0);
-	
-			if((msg_info.Unseen=="U")|| (msg_info.Recent=="N"))
-				unseen = 1;
-			this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size]);
-			
-			
-			
-			//Preenche os anexos.
-			var id_mail = this.dbGears.lastInsertRowId;
-
-			for (var i = 0; i < anexos.length; i++) {
-				this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_mail, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]);
-			}
-			
-			var check_remove;
-			if(this.is_auto)
-				check_remove = preferences.keep_after_auto_archiving;
-			else
-				check_remove = preferences.keep_archived_messages;
-			
-			
-			
-			if(check_remove!=1)
-				this.dbGears.execute("insert into msgs_to_remove (id_msg,folder,uid_usuario) values (?,?,?)",[original_id,original_folder,account_id]);
-						
-		} catch (error) {
-			/*
-			 * 0 - original id
-			 * 1 - message subject
-			 * 2 - original folder
-			 */
-			var mail_error = new Array();
-			mail_error[0] = original_id;
-			mail_error[1] = subject;
-			mail_error[2] = original_folder;
-			this.errors.push(mail_error);
-			
-			if (typeof(msg_info['array_attach'])=='object'&&(msg_info['array_attach'] instanceof Array)) { 
-				for(var i in msg_info['array_attach']) { //remove os anexos que já foram baixados para essa mensagem...
-					this.store.remove(msg_info['array_attach'][i]['url']);
-				}
-			}
-
-		}
-		this.dbGears.close();
-		this.syncronize_mails(folder);
-	}
-	
-	mail_sync.prototype.has_inbox_folder = function() {//This function considers that the connection with base is already opened.
-		var rs = this.dbGears.execute("select rowid from folder where folder='Inbox'");
-		if(rs.isValidRow())
-			return true;
-		else 
-			return false;
-	}
-	
-	mail_sync.prototype.remove_archived_mails = function() {
-		
-		expresso_mail_sync.open_conn();
-
-		var rs = this.dbGears.execute("select distinct(folder) from msgs_to_remove where uid_usuario=?",[account_id]);
-		if(rs.isValidRow()) {
-			var folder_to_remove_msgs = rs.field(0);
-			var rs2 = this.dbGears.execute("select id_msg from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]);
-			
-			var msgs = null;
-			while(rs2.isValidRow()) {
-				if(msgs==null)
-					msgs = rs2.field(0);
-				else
-					msgs += ","+rs2.field(0);
-				rs2.next();
-			}
-			
-			
-			var handler_delete_msgs = function(data){
-				if (current_folder == data.folder) {
-					mail_msg = Element("tbody_box");
-					var msg_to_delete;
-					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);
-						}
-					}
-					Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) - data.msgs_number.length;
-				}
-				ttreeBox.update_folder();
-				refresh();
-				expresso_mail_sync.remove_archived_mails();
-			}
-			
-			cExecute ("$this.imap_functions.delete_msgs&folder="+folder_to_remove_msgs+"&msgs_number="+msgs, handler_delete_msgs);
-			this.dbGears.execute("delete from msgs_to_remove where folder=? and uid_usuario=?",[folder_to_remove_msgs,account_id]);
-			this.dbGears.close();
-			
-		}
-		else {
-			this.dbGears.close();
-			document.getElementById('main_title').innerHTML = get_lang("End of archive messages");
-			if(this.errors.length>0) {
-				//TODO: Tratar melhor quando existirem erros...
-				write_msg(get_lang("at least, one of selected mails is already archived, expresso tried to archive the others, check them later"));
-				this.errors=new Array();
-			}
-			window.setTimeout("eval('document.getElementById(\"main_title\").innerHTML =\"Expresso Mail\"')",3000);
-		}
-		
-	}
-	
-	mail_sync.prototype.configure_sync = function(folders,formul) {
-		this.dbGears = google.gears.factory.create('beta.database');
-		this.localServer = google.gears.factory.create('beta.localserver');
-		this.store = this.localServer.createStore('test-store');	
-		this.dbGears.open('database-test');
-		this.dbGears.execute("delete from folders_sync where uid_usuario=?",[account_id]);
-		for (var i=0;i<folders.length;i++) {
-			var pos = folders[i].value.indexOf("/");
-			if(pos=="-1")
-				var folder_name = folders[i].text;
-			else
-				var folder_name = folders[i].value.substr(pos+1);
-			this.dbGears.execute("insert into folders_sync (id_folder,folder_name,uid_usuario) values (?,?,?)",[folders[i].value,folder_name,account_id]);
-		}
-		this.dbGears.close();
-		formul.submit();
-	}
-	
-	mail_sync.prototype.fill_combos_of_folders = function(combo_sync) {
-		var folders = expresso_local_messages.get_folders_to_sync();
-
-		for(var i=0;i<folders.length;i++) {
-			var option = document.createElement('option');
-			option.value = folders[i][0];
-			if (folders[i][1].indexOf("/") != "-1") {
-				final_pos = folders[i][1].lastIndexOf("/");
-				option.text =folders[i][1].substr(final_pos+1);
-			}
-			else
-				option.text = folders[i][1];
-			try {
-				combo_sync.add(option,null);
-			}catch (ex) {// I.E
-				combo_sync.add(option);
-			}
-
-		}
-	}
-	
-	mail_sync.prototype.add_folder = function (select_sync_folders,select_available_folders)
-	{
-		var count_available_folders = select_available_folders.length;
-		var count_sync_folders = select_sync_folders.options.length;
-		var new_options = '';
-		
-		for (i = 0 ; i < count_available_folders ; i++)
-		{
-			if (select_available_folders.options[i].selected)
-			{
-				if(document.all)
-				{
-					if ( (select_sync_folders.innerHTML.indexOf('value='+select_available_folders.options[i].value)) == '-1' )
-					{
-						new_options +=  '<option value='
-									+ select_available_folders.options[i].value
-									+ '>'
-									+ select_available_folders.options[i].text
-									+ '</option>';
-					}
-				}
-				else
-				{
-					if ( (select_sync_folders.innerHTML.indexOf('value="'+select_available_folders.options[i].value+'"')) == '-1' )
-					{
-						new_options +=  '<option value='
-									+ select_available_folders.options[i].value
-									+ '>'
-									+ select_available_folders.options[i].text
-									+ '</option>';
-					}
-				}
-			}
-		}
-	
-		if (new_options != '')
-		{
-			select_sync_folders.innerHTML = '&nbsp;' + new_options + select_sync_folders.innerHTML;
-			select_sync_folders.outerHTML = select_sync_folders.outerHTML;
-		}
-	}
-	
-	mail_sync.prototype.remove_folder = function(select_sync_folders)
-	{
-		for(var i = 0;i < select_sync_folders.options.length; i++)
-			if(select_sync_folders.options[i].selected)
-				select_sync_folders.options[i--] = null;
-	}
-	
-	var expresso_mail_sync;
-	expresso_mail_sync = new mail_sync();
-	
Index: trunk/expressoMail1_2/js/local_messages.js
===================================================================
--- trunk/expressoMail1_2/js/local_messages.js	(revision 2378)
+++ 	(revision )
@@ -1,1598 +1,0 @@
-/**
- * @author diogenes
- */
-
-	function local_messages() {
-		this.dbGears = null;
-		this.localServer = null;
-		this.store = null;
-	}
-
-        function HeaderFlags()
-        {
-            this.Answered = 0;
-            //this.Draft = 0;
-            this.Flagged = 0;
-            this.Recent = 0;
-        }
-
-        HeaderFlags.prototype.getAnswered = function()
-        {
-            return this.Answered;
-        }
-
-        HeaderFlags.prototype.setAnswered = function(answered)
-        {
-            this.Answered = answered;
-        }
-
-        //HeaderFlags.prototype.getDraft = function()
-        //{
-        //    return this.Draft;
-        //}
-
-        HeaderFlags.prototype.setDraft = function(draft)
-        {
-            this.Draft = draft;
-        }
-
-        HeaderFlags.prototype.getFlagged = function()
-        {
-            return this.Flagged;
-        }
-
-        HeaderFlags.prototype.setFlagged = function(flagged)
-        {
-            this.Flagged = flagged;
-        }
-
-        HeaderFlags.prototype.getRecent = function()
-        {
-            return this.Recent;
-        }
-
-        HeaderFlags.prototype.setRecent = function(recent)
-        {
-            this.Recent = recent;
-        }
-
-        function FlagsParser(headerObj)
-        {
-            this.Header = headerObj;
-        }
-
-        FlagsParser.prototype.parse = function()
-        {
-            var tmp = null;
-            if (typeof this.Header == 'string')
-            {
-                tmp = expresso.connector.unserialize(this.Header);
-            }
-            else
-            {
-                tmp = this.Header;
-            }
-
-            flags = new HeaderFlags();
-
-            if (tmp.Answered && tmp.Answered.match(/^A$/))
-            {
-                flags.setAnswered(1);
-                //if (tmp.Draft && tmp.Draft.match(/^X$/))
-                //{
-                //    flags.setDraft(1);
-                //}
-            }
-
-            if (tmp.Flagged && tmp.Flagged.match(/^F$/)){
-                flags.setFlagged(1);
-            }
-
-            if (tmp.Forwarded && tmp.Forwarded.match(/^F$/)){
-                flags.setAnswered(1);
-                //flags.setDraft(1);
-            }
-
-            if (tmp.Recent && tmp.Recent.match(/^R$/)){
-                flags.setRecent(1);
-            }
-
-            return flags;
-
-        }
-        
-	local_messages.prototype.installGears = function (){
-		temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to install it now?"));
-		if (temp && typeof(preferences.googlegears_url) != 'undefined'){
-			if (is_ie)
-				location.href = preferences.googlegears_url + "/gears.exe";
-			else
-				location.href = preferences.googlegears_url + "/gears.xpi";
-			return false;
-		}
-		if (temp) {
-			location.href = "http://gears.google.com/?action=install&message="+
-				get_lang("To use local messages, install Google Gears")+"&return=" + document.location.href;
-		}
-		else return false;
-	}
-
-	local_messages.prototype.create_objects = function() {
-		try {
-			if(this.dbGears == null)
-				this.dbGears = google.gears.factory.create('beta.database');
-			if(this.localServer == null)
-				this.localServer = google.gears.factory.create('beta.localserver');
-			if(this.store == null)
-				this.store = this.localServer.createStore('test-store');
-		}
-		catch(e){}
-	}
-
-	local_messages.prototype.init_local_messages = function(){ //starts only database operations
-		
-		if(this.dbGears==null || this.localServer==null || this.store == null)
-			this.create_objects();
-		
-		var db_in_other_use = true;
-		var start_trying = new Date().getTime();
-		while (db_in_other_use) {
-			try {
-				this.dbGears.open('database-test');
-				db_in_other_use = false;
-			} 
-			catch (ex) {
-				if(new Date().getTime()-start_trying>10000) { //too much time trying, throw an exception
-					throw ex;
-				}
-			}
-		}
-			
-//		this.dbGears.open('database-test');
-		this.dbGears.execute('create table if not exists folder (folder text,uid_usuario int,unique(folder,uid_usuario))');
-		this.dbGears.execute('create table if not exists mail' +
-		' (mail blob,original_id int,original_folder text,header blob,timestamp int,uid_usuario int,unseen int,id_folder int,' + 
-		' ffrom text, subject text, fto text, cc text, body text, size int,unique (original_id,original_folder,uid_usuario))');
-		this.dbGears.execute('create table if not exists anexo' +
-		' (id_mail int,nome_anexo text,url text,pid int)');
-		this.dbGears.execute('create table if not exists folders_sync' +
-		' (id_folder text,folder_name text,uid_usuario int)');
-		this.dbGears.execute('create table if not exists msgs_to_remove (id_msg int,folder text,uid_usuario int)');
-		this.dbGears.execute('create index if not exists idx_user3 on mail (id_folder,uid_usuario,timestamp)');
-
-		//some people that used old version of local messages could not have the size column. If it's the first version
-		//with local messages you're using in expresso, this part of code can be removed
-		try {
-			this.dbGears.execute('alter table mail add column size int');
-		}catch(Exception) {
-			
-		}
-		var rs = this.dbGears.execute('select rowid,header from mail where size is null');
-		while(rs.isValidRow()) {
-			var temp = expresso.connector.unserialize(rs.field(1));
-			
-			this.dbGears.execute('update mail set size='+temp.Size+' where rowid='+rs.field(0));
-			rs.next();
-		}
-		//end of temporary code
-
-		try {
-                    this.dbGears.execute('begin transaction');
-                    this.dbGears.execute('alter table mail add column answered int');
-                    //this.dbGears.execute('alter table mail add column draft int');
-                    this.dbGears.execute('alter table mail add column flagged int');
-                    this.dbGears.execute('alter table mail add column recent int');
-                    //this.dbGears.execute('commit transaction');
-                    //transaction_ended = true;
-                    //if (transaction_ended){
-                    rs = null;
-                    rs = this.dbGears.execute('select rowid,header from mail');
-
-                    // Popular os valores das novas colunas.
-                    var tmp = null;
-                    //this.dbGears.execute('begin transaction');
-                    while(rs.isValidRow()) {
-                        //tmp = expresso.connector.unserialize(rs.field(1));
-                        parser = new FlagsParser(rs.field(1));
-                        flags = parser.parse();
-
-                        this.dbGears.execute('update mail set answered='+flags.getAnswered()+
-                            ',flagged='+flags.getFlagged()+',recent='+flags.getRecent()+
-                            //',draft='+flags.getDraft()+' where rowid='+rs.field(0));
-                            ' where rowid='+rs.field(0));
-
-			rs.next();
-                    }
-                    this.dbGears.execute('commit transaction');
-
-                    //tmp = null;
-
-                }catch(Exception) {
-                    this.dbGears.execute('rollback transaction');
-		}
-
-	}
-	
-	local_messages.prototype.drop_tables = function() {
-		this.init_local_messages();
-		var rs = this.dbGears.execute('select url from anexo');
-		while(rs.isValidRow()) {
-			this.store.remove(rs.field(0));
-			rs.next();
-		}
-		this.dbGears.execute('drop table folder');
-		this.dbGears.execute('drop table mail');
-		this.dbGears.execute('drop table anexo');
-		this.finalize();
-	}
-	/**
-	 * @Depracated Use of this function in mail_sync.js
-	 * 
-	 */
-	local_messages.prototype.insert_mail = function(msg_info,msg_header,anexos,folder) {
-		try {
-			this.init_local_messages();
-			var unseen = 0;
-			var login = msg_info.login;
-			var original_id = msg_info.msg_number;
-			var original_folder = msg_info.msg_folder;
-			
-			//This fields needs to be separeted to search.
-			var from = expresso.connector.serialize(msg_info.from);
-			var subject = msg_info.subject;
-			var body = msg_info.body;
-			var to = expresso.connector.serialize(msg_info.toaddress2);
-			var cc = expresso.connector.serialize(msg_info.cc);
-			var size = msg_header.Size;
-	
-			//do not duplicate this information
-			msg_info.from = null;
-			msg_info.subject = null;
-			msg_info.body = null;
-			msg_info.to = null;
-			msg_info.cc = null;
-			msg_header.Size=null;
-			//If the mail was archieved in the same date the user received it, the date cames with the time.
-			//here I solved it
-			if(msg_header.udate.indexOf(":")!=-1) {
-				msg_header.udate = msg_header.aux_date;
-			}
-			
-			/**
-			 * The importance attribute can be empty, and javascript consider as null causing nullpointer.
-			 */
-			if((msg_header.Importance == null) ||  (msg_header.Importance == ""))
-				msg_header.Importance = "Normal";
-			
-			msg_header.aux_date = null; 
-			
-			var mail = expresso.connector.serialize(msg_info);
-			var header = expresso.connector.serialize(msg_header);
-	
-			var timestamp = msg_info.timestamp;
-			var id_folder;
-	
-			if((folder==null) || (folder=="local_root"))
-				folder = "Inbox";
-			else
-				folder = folder.substr(6);//take off the word "local_"
-			
-			var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]);
-        		if(rs.isValidRow())
-				id_folder=rs.field(0);
-			else {
-				this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",["Inbox",account_id]);
-				id_folder = this.dbGears.lastInsertRowId;
-			}
-			
-			if((msg_info.Unseen=="U")|| (msg_info.Recent=="N"))
-				unseen = 1;
-
-                        //parse header
-                        parser = new FlagsParser(msg_header);
-                        flags = parser.parse();
-
-                        //insere o e-mail
-                        //this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size]);
-                        this.dbGears.execute("insert into mail (mail,original_id,original_folder,header,timestamp,uid_usuario,unseen,id_folder,ffrom,subject,fto,cc,body,size,answered,flagged,recent) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",[mail,original_id,original_folder,header,timestamp,login,unseen,id_folder,from,subject,to,cc,body,size,flags.getAnswered(),flags.getFlagged(),flags.getRecent()]);
-			var call_back = function() {
-			}
-			this.store.capture(msg_info.url_export_file,call_back);
-			var id_mail = this.dbGears.lastInsertRowId;
-	
-			this.insert_attachments(id_mail,anexos);
-			this.finalize();
-			return true;
-		} catch (error) {
-			this.finalize();
-			return false;
-		}
-
-
-	}
-	
-	/**
-	 * check if ID is no from main tab, if it's from main returns false, else 
-	 * returns an array with all string in position 0, the mail id in position 1 
-	 * and the part of string relative to tab in position 2
-	 * @param {Object} id_mail
-	 */
-	local_messages.prototype.parse_id_mail = function(id_mail) { 
-		if (this.isInt(id_mail))
-			return false;
-		
-		var matches = id_mail.match(/(.+)(_[a-zA-Z0-9]+)/);
-		return matches;
-	}
-	
-	local_messages.prototype.isInt = function(x) {
-		var y=parseInt(x);
-		if (isNaN(y)) return false;
-		return x==y && x.toString()==y.toString();
-	} 
-	
-	local_messages.prototype.get_local_mail = function(id_mail) {
-		this.init_local_messages();
-
-		var plus_id = '';
-		var matches = '';
-		if(matches = this.parse_id_mail(id_mail)) { //Mails coming from other tab.
-			id_mail = matches[1];
-			plus_id = matches[2];
-		}
-		
-		var rs = this.dbGears.execute("select mail.rowid,mail.mail,mail.ffrom,mail.subject,mail.body,mail.fto,mail.cc,folder.folder,mail.original_id from mail inner join folder on mail.id_folder=folder.rowid  where mail.rowid="+id_mail);
-		var retorno = null;
-		if(rs.isValidRow()) {
-			 retorno = rs.field(1);
-		}
-		retorno = expresso.connector.unserialize(retorno);
-
-        //alert('tipo retorno.source: ' + typeof(retorno.source));
-
-        if (typeof(retorno.source) == 'string')
-        {
-            retorno.msg_number=rs.field(0)+plus_id;
-            retorno.original_ID=rs.field(8);
-            retorno.msg_folder=rs.field(7);
-
-            //alert('tipo retorno: '+typeof(retorno))
-            //show_msg(retorno);
-        }
-		else
-        {
-            retorno['from'] = expresso.connector.unserialize(rs.field(2));
-            retorno['subject'] = rs.field(3);
-            retorno['body'] = rs.field(4);
-            //Codigo que as imagens embutidas em emails (com multipart/related ou multipart/mixed) sejam corretamente mostradas em emails arquivados. Os links do
-            //tipo "./inc/show_embedded_attach.php?msg_folder=[folder]&msg_num=[msg_num]&msg_part=[part]"
-            //sï¿œo substituidos pelos links dos anexos capturados pelo gears.
-
-            var thumbs= retorno.thumbs;
-            var anexos= retorno.array_attach;
-            for (i in anexos)
-            {
-                nomeArquivo = anexos[i]['name'].substring(0,anexos[i]['name'].length - 4);
-                if(nomeArquivo.match('jpg')||anexos[i]['name'].match('gif')||anexos[i]['name'].match('png'))
-                    {
-                        var er_imagens = new RegExp("\\.\\/inc\\/show_embedded_attach.php\\?msg_folder=[\\w/]+\\&msg_num=[0-9]+\\&msg_part="+anexos[i]['pid']);
-                        var Result_imagens = er_imagens.exec(retorno['body']);
-                        retorno['body'] = retorno['body'].replace(Result_imagens,anexos[i]['url']);
-                        if(thumbs && thumbs[i]){
-                            er_imagens = new RegExp("\\.\\/inc\\/show_thumbs.php\\?file_type=image\\/[\\w]+\\&msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']);
-                            Result_imagens = er_imagens.exec(thumbs[i]);
-                            thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'");
-                            er_imagens = new RegExp("\\.\\/inc\\/show_img.php\\?msg_num=[0-9]+\\&msg_folder=[\\w/%]+\\&msg_part="+anexos[i]['pid']);
-                            Result_imagens = er_imagens.exec(thumbs[i]);
-                            thumbs[i] = thumbs[i].replace(Result_imagens,"'"+anexos[i]['url']+"'");
-                            thumbs[i] = thumbs[i].replace(/<IMG/i,'<img width="120"');
-                        }
-                    }
-            }
-
-            retorno['to'] = expresso.connector.unserialize(rs.field(5));
-            retorno['cc'] = expresso.connector.unserialize(rs.field(6));
-
-            retorno['local_message'] = true;
-            retorno['msg_folder'] = "local_"+rs.field(7); //Now it's a local folder
-            retorno['msg_number'] = rs.field(0)+plus_id; //the message number is the rowid
-
-        }
-
-        rs.close();
-		this.finalize();
-		return retorno;
-	}
-
-	local_messages.prototype.insert_attachments = function(id_msg,anexos) { 
-		//insert_mail already close and open gears.
-		for (var i = 0; i < anexos.length; i++) {
-			this.dbGears.execute("insert into anexo (id_mail,nome_anexo,url,pid) values (?,?,?,?)", [id_msg, anexos[i]['name'],anexos[i]['url'],anexos[i]['pid']]);
-			this.capt_url(anexos[i]['url']);
-		}
-	}
-
-	local_messages.prototype.capt_url = function (url) {
-		//insert_mail already close and open gears.
-		var call_back = function(url,success,captureId) {
-				//alert("Capturado: " + url);
-			}
-		//alert(url);
-		this.store.capture(url,call_back);
-	}
-
-	local_messages.prototype.strip_tags = function (str) {
-		return str.replace(/<\/?[^>]+>/gi, '');
-	}
-
-	local_messages.prototype.get_local_range_msgs = function(folder,msg_range_begin,emails_per_page,sort,sort_reverse,search,preview_msg_subject,preview_msg_tip) {
-
-		this.init_local_messages();
-		var retorno = new Array();
-		msg_range_begin--;
-		
-		filter = " ";
-		if(search=="FLAGGED") {
-			filter = "and (header like '%\"Flagged\";s:1:\"F%' or header like '%\"Importance\";s:5:\"High%') ";
-		}
-		if(search=="UNSEEN") {
-			filter = "and unseen = 1 ";
-		}
-		if(search=="SEEN") {
-			filter = "and unseen = 0 ";
-		}
-		if (search=="ANSWERED") {
-			filter = "and header like '%\"Answered\";s:1:\"A%' ";
-		}
-		
-		sql = 'select mail.rowid as rowid,mail.header as header,mail.size as size,mail.timestamp as timestamp,mail.unseen as unseen,mail.body as body,case when lower(mail.ffrom) like ? then ltrim(ltrim(substr(UPPER(ffrom),21,length(ffrom)),\':\'),\'"\') else ltrim(ltrim(substr(UPPER(fto),7,length(fto)),\':\'),\'"\') end as order_from,mail.subject from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=? order by '
-		
-		if(sort == 'SORTFROM') {
-			sql += 'order_from ';
-		}
-		if(sort == 'SORTARRIVAL') {
-			sql += 'timestamp ';
-		}
-		if(sort == 'SORTSIZE') {
-			sql += 'size ';
-		}
-		if(sort == 'SORTSUBJECT') {
-			sql += 'UPPER(subject) ';
-		}
-
-
-		sql+= sort_reverse==0?"ASC ":"DESC ";
-		sql +='limit ?,? ';
-
-
-		var rs = this.dbGears.execute(sql,['%'+Element("user_email").value+'%',account_id,folder,msg_range_begin,emails_per_page]);
-		var cont = 0;
-		
-		var rs3 = this.dbGears.execute('select count(*) from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario=? and folder.folder=?'+filter,[account_id,folder]);
-				
-		while (rs.isValidRow()) {
-			//var email = rs.field(1);
-			var head = rs.field(1);
-			var codigoMail = rs.field(0);
-
-			var msg_body = rs.field(5);//recebe o conteudo da coluna "body" do banco de dados;
-
-			var rs2 = this.dbGears.execute('select count(*) from anexo where id_mail = '+codigoMail);
-			var head_unserialized = expresso.connector.unserialize(head);
-			head_unserialized.Size = rs.field(2);
-			if(rs.field(4)==1)
-				head_unserialized.Unseen = 'U';		
-			
-
-			head_unserialized.subject=(head_unserialized.subject==null)?"":head_unserialized.subject;
-
-			//var email_unserialized = expresso.connector.unserialize(email);
-			retorno[cont] = head_unserialized;
-			retorno[cont]['msg_number'] = codigoMail;
-			
-			//declaracao do array() para receber o body de cada mensagem encontrada na busca sql realizada;
-			msg_body=this.strip_tags(msg_body);
-			msg_body=msg_body.replace(/\&nbsp;/ig," ");
-			retorno[cont]['msg_sample'] = new Array();
-
-			if( (preview_msg_subject == 0) && (preview_msg_tip == 0) )
-			{
-				retorno[cont]['msg_sample']['body'] = "";
-			}
-			else
-			{
-				retorno[cont]['msg_sample']['body'] = " - " + msg_body.substr(2,300);
-			}
-
-			cont++;
-		  	rs.next();
-		}
-		retorno['num_msgs'] = rs3.field(0);
-		rs3.close();
-		rs.close();
-		if(cont>0)
-			rs2.close();
-		this.finalize();
-		return retorno;
-	}
-	
-	local_messages.prototype.get_url_anexo = function(msg_number,pid) {
-		this.init_local_messages();
-		var matches = '';
-		if(matches = this.parse_id_mail(msg_number)) {
-			msg_number = matches[1];
-		}
-		
-		var retorno;
-		var rs = this.dbGears.execute("select url from anexo where id_mail="+msg_number+" and pid = '"+pid+"'");
-		retorno = rs.field(0)
-		this.finalize();
-		
-		return retorno;
-	}
-
-	local_messages.prototype.getInputFileFromAnexo = function (element,url) { 
-		this.init_local_messages();
-		fileSubmitter = this.store.createFileSubmitter();
-		fileSubmitter.setFileInputElement(element,url);
-		this.finalize();
-	}
-
-	local_messages.prototype.finalize = function() {
-		this.dbGears.close();
-		this.dbGears = null;
-	}
-
-	local_messages.prototype.delete_msgs = function(msgs_number,border_ID) {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select url from anexo where id_mail in ("+msgs_number+")");
-		while(rs.isValidRow()) {
-			this.store.remove(rs.field(0));
-			rs.next();
-		}
-		this.dbGears.execute("delete from anexo where id_mail in ("+msgs_number+")");
-		this.dbGears.execute("delete from mail where rowid in ("+msgs_number+")");
-		this.finalize();
-		if (msgs_number.length == 1)
-			write_msg(get_lang("The message was deleted."));
-		else
-			write_msg(get_lang("The messages were deleted."));
-		
-		mail_msg = Element("tbody_box");
-
-		try {
-			msgs_exploded = msgs_number.split(",");
-		}catch(error) {
-			msgs_exploded = new Array();
-			msgs_exploded[0] = msgs_number;
-		}
-		var msg_to_delete;
-		for (var i=0; i<msgs_exploded.length; i++){
-			msg_to_delete = Element(msgs_exploded[i]);
-			if (msg_to_delete){
-				if ( (msg_to_delete.style.backgroundColor != '') && (preferences.use_shortcuts == '1') )
-					select_msg('null', 'down');
-				mail_msg.removeChild(msg_to_delete);
-				decrement_folder_unseen();
-			}
-		}
-		Element('chk_box_select_all_messages').checked = false;
-		if (border_ID != 'null')
-			delete_border(border_ID,'false');
-		
-	}
-	
-	local_messages.prototype.get_source_msg = function(id_msg) {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select mail from mail where rowid="+id_msg);
-
-
-		mail = expresso.connector.unserialize(rs.field(0));		
-		download_local_attachment(mail.url_export_file)
-
-		this.finalize();
-	}
-	
-	
-	
-	local_messages.prototype.set_messages_flag = function(msgs_number, flag) {
-		this.init_local_messages();
-		var msgs_to_set;
-		if (msgs_number == 'get_selected_messages') { 
-			var msgs_to_set = get_selected_messages();
-			msgs_to_set= msgs_to_set.split(",");
-		}
-		else { //Just one message
-			msgs_to_set = new Array();
-			msgs_to_set[0] = msgs_number;
-		}
-		for (var i in msgs_to_set) {
-			
-			var matches = '';//Messages comming from other tabs.
-			if(matches = this.parse_id_mail(msgs_to_set[i])) { 
-				msgs_to_set[i] = matches[1];
-			}
-			
-			var rs = this.dbGears.execute("select header,unseen from mail where rowid=" + msgs_to_set[i]);
-			header = expresso.connector.unserialize(rs.field(0));
-			unseen = rs.field(1);
-			switch(flag) {
-				case "unseen":
-					set_msg_as_unread(msgs_to_set[i]);
-					header["Unseen"] = "U";
-					unseen = 1;
-					break;
-				case "flagged":
-					set_msg_as_flagged(msgs_to_set[i]);
-					header["Flagged"] = "F";
-					break;
-				case "unflagged":
-					if (header["Importance"].indexOf("High") != -1) 
-						write_msg(get_lang("At least one of selected message cant be marked as normal"));
-					else {
-						set_msg_as_unflagged(msgs_to_set[i]);
-						header["Flagged"] = "N";
-					}
-					break;
-				case "seen":
-					header["Unseen"] = "N";
-					set_msg_as_read(msgs_to_set[i],true);
-					unseen = 0;
-					break;
-				case "answered":
-					header["Draft"]="";
-					header["Answered"]="A";
-					Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/answered.gif title=Respondida>';
-					break;
-				case "forwarded":
-					header["Draft"]="X";
-					header["Answered"]="A";
-					Element("td_message_answered_"+msgs_to_set[i]).innerHTML = '<img src=templates/default/images/forwarded.gif title=Encaminhada>';
-					break;
-			}
-		
-			rs.close();
-			
-			if(Element("check_box_message_" + msgs_to_set[i]))
-				Element("check_box_message_" + msgs_to_set[i]).checked = false;
-
-			this.dbGears.execute("update mail set header='"+expresso.connector.serialize(header)+"',unseen="+unseen+" where rowid="+msgs_to_set[i]);			
-		}
-		if(Element('chk_box_select_all_messages'))
-			Element('chk_box_select_all_messages').checked = false;
-		this.finalize();
-
-	}
-	
-	local_messages.prototype.set_message_flag = function(msg_number,flag) {
-		this.set_messages_flag(msg_number,flag);
-	}
-	
-	local_messages.prototype.get_unseen_msgs_number = function() {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select count(*) from mail where unseen=1");
-		var retorno = rs.field(0);
-		rs.close();
-		this.finalize();
-		return retorno;
-	}
-
-	local_messages.prototype.create_folder = function(folder) {
-
-		if (folder.indexOf("local_") != -1)
-			return false; //can't create folder with string local_
-
-		this.init_local_messages();
-		try {
-			this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",[folder,account_id]);
-		} catch (error) {
-			this.finalize();
-			throw error;
-			return false;
-		}
-		this.finalize();
-		return true;
-	}
-
-	local_messages.prototype.list_local_folders = function(folder) {
-		this.init_local_messages();
-		var retorno = new Array();
-		rs = this.dbGears.execute("select folder,rowid from folder where uid_usuario=?",[account_id]);
-		while(rs.isValidRow()) {
-			var temp = new Array();
-			temp[0] = rs.field(0);
-			
-			var rs2 = this.dbGears.execute("select count(*) from mail where id_folder=? and unseen=1",[rs.field(1)]);
-			temp[1] = rs2.field(0);			
-
-			var rs3 = this.dbGears.execute("select * from folder where folder like ? limit 1",[temp[0]+"/%"]);
-			if(rs3.isValidRow())
-				temp[2] = 1;
-			else
-				temp[2] = 0;
-			retorno.push(temp);
-			rs.next();
-		}
-		
-		rs.close();
-		this.finalize();
-		return retorno;
-	}
-
-	local_messages.prototype.rename_folder = function(folder,old_folder) {
-		if (folder.indexOf("local_") != -1)
-			return false; //can't create folder with string local_
-		this.init_local_messages();
-		if (old_folder.indexOf("/") != "-1") {
-			final_pos = old_folder.lastIndexOf("/");
-			folder = old_folder.substr(0, final_pos) + "/" + folder;
-		}
-		try {
-			this.dbGears.execute("update folder set folder=? where folder=? and uid_usuario=?",[folder,old_folder,account_id]);
-		} catch (error) {
-			this.finalize();
-			return false;
-		}
-		rs = this.dbGears.execute("select folder from folder where folder like ? and uid_usuario=?",[old_folder+'/%',account_id]);
-		while(rs.isValidRow()) {
-			folder_tmp = rs.field(0);
-			folder_new = folder_tmp.replace(old_folder,folder);
-			this.dbGears.execute("update folder set folder=? where folder=?",[folder_new,folder_tmp]);
-			rs.next();
-		}
-
-
-		this.finalize();
-		return true;
-	}
-	
-	local_messages.prototype.remove_folder = function(folder) {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select count(rowid) from folder where folder like ? and uid_usuario=?",[folder+"/%",account_id]);
-		var sons = rs.field(0);
-		rs.close();
-
-		if(sons == 0){
-		var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[folder,account_id]);
-		var folder_id = rs.field(0);
-		rs.close();
-		this.dbGears.execute("delete from folder where rowid=?",[folder_id]);
-		rs = this.dbGears.execute("select rowid,mail from mail where id_folder=?",[folder_id]);
-		while(rs.isValidRow()) {
-			var rs2 = this.dbGears.execute("select url from anexo where id_mail=?",[rs.field(0)]);
-			while(rs2.isValidRow()) {
-				this.store.remove(rs2.field(0));
-				rs2.next();
-			}
-			rs2.close();
-			this.dbGears.execute("delete from anexo where id_mail=?",[rs.field(0)]);
-			var mail = expresso.connector.unserialize(rs.field(1));
-			this.store.remove(mail.url_export_file);
-			rs.next();
-		}
-		rs.close();
-		this.dbGears.execute("delete from mail where id_folder=?",[folder_id]);
-		this.finalize();
-		return true;
-		}else  {
-		    this.finalize();
-			return false;
-	}
-
-	}
-
-	local_messages.prototype.move_messages = function(new_folder,msgs_number) {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?",[new_folder,account_id]);
-		var id_folder = rs.field(0);
-		rs.close();
-		this.dbGears.execute("update mail set id_folder="+id_folder+" where rowid in ("+msgs_number.toString()+")"); //usando statement nï¿œo tava funcionando quando tinha mais de um email...
-		this.finalize();
-	}
-	
-	local_messages.prototype.search = function(folders,sFilter) {
-		this.init_local_messages();
-                var filters = sFilter.replace(/^##|##$/g,"").split('##');
-		var friendly_filters = new Array();
-
-                if (sFilter.indexOf('ALL') != -1) { //all filters...
-                    filters[0] = sFilter.replace(/##/g,"");
-                    tmp = filters[0].split("<=>");
-
-                    searchKey = new Array();
-                    searchKey.push("SUBJECT");
-                    searchKey.push(tmp[1]);
-                    friendly_filters.push(searchKey);
-
-                    searchKey = new Array();
-                    searchKey.push("BODY");
-                    searchKey.push(tmp[1]);
-                    friendly_filters.push(searchKey);
-
-                    searchKey = new Array();
-                    searchKey.push("FROM");
-                    searchKey.push(tmp[1]);
-                    friendly_filters.push(searchKey);
-
-                    searchKey = new Array();
-                    searchKey.push("TO");
-                    searchKey.push(tmp[1]);
-                    friendly_filters.push(searchKey);
-
-                    searchKey = new Array();
-                    searchKey.push("CC");
-                    searchKey.push(tmp[1]);
-                    friendly_filters.push(searchKey);
-		}
-		else {
-                    for (var i=0; i<filters.length; i++)
-                    {
-                        if (filters[i] != ""){
-                            //tmp[0] = tmp[0].replace(/^\s+|\s+$/g,"");
-                            //tmp[1] = tmp[1].replace(/^\s+|\s+$/g,"");
-                            friendly_filters.push(filters[i].split("<=>"));
-                        }
-                    }
-		}
-		var sql = "select mail.header,folder.folder,mail.rowid,size from mail inner join folder on mail.id_folder=folder.rowid where mail.uid_usuario="+account_id + " and folder.folder in (";
-		for(var fnum in folders) {
-			sql+="'"+folders[fnum]+"'";
-			if(fnum<folders.length-1)
-				sql+=",";
-		}
-		sql += ") and (";
-		for (var z=0;z<friendly_filters.length;z++) {
-                    if (z != 0) {
-                        if (sFilter.indexOf('ALL') != -1)
-                            sql += " or";
-                        else
-                            sql += " and";
-                    }
-                    var cond = friendly_filters[z][0].replace(/^\s+|\s+$/g,"");
-                    if (cond == "SINCE" || cond == "BEFORE" | cond == "ON"){
-
-                        tmpDate = url_decode(friendly_filters[z][1]).split('/');
-
-                        // Date = url_decode(friendly_filters[z][1]);
-                        sql+=" mail.timestamp " + this.aux_convert_filter_field(friendly_filters[z][0], tmpDate);
-                    }
-                    else if (!friendly_filters[z][1])
-                        {
-                            sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0]);
-                        }
-                        else
-                            {
-                                sql+=" mail."+this.aux_convert_filter_field(friendly_filters[z][0])+" like '%"+url_decode(friendly_filters[z][1])+"%'";
-                            }
-		}
-		sql += ")";
-		var rs = this.dbGears.execute(sql);
-		var retorno = "";
-		while(rs.isValidRow()) {
-                    var header = expresso.connector.unserialize(rs.field(0));
-                    retorno+="##"+"local_"+rs.field(1)+"--"+header["from"]["name"]+"--"+header["subject"]+"--"+header["udate"]+"--"+this.aux_convert_size(rs.field(3))+"--"+header["Unseen"]+header["Recent"]+header["Flagged"]+header["Draft"]+"--"+rs.field(2)+"##";
-                    rs.next();
-		}
-
-		this.finalize();
-		return retorno==""?false:retorno;
-
-	}
-	
-	local_messages.prototype.aux_convert_size = function(size) {
-		var tmp = Math.floor(size/1024);
-		if(tmp >= 1){
-			return tmp + " kb";	
-		}else{
-			return size + " b";	
-		}
-		
-	}
-	
-	local_messages.prototype.aux_convert_filter_field = function(filter,date) {
-                if (typeof date != 'undefined'){
-                    var dateObj=new Date();
-                    dateObj.setFullYear(date[2],date[1]-1,date[0]);
-                }
-
-		if((filter=="SUBJECT ") || (filter=="SUBJECT"))
-			return "subject";
-		else if((filter=="BODY ") || (filter=="BODY"))
-			return "body";
-		else if((filter=="FROM ") || (filter=="FROM"))
-			return "ffrom";
-		else if((filter=="TO ") || (filter=="TO"))
-			return "fto";
-		else if((filter=="CC ") || (filter=="CC"))
-			return "cc";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "SINCE"){
-                        dateObj.setHours(0, 0, 0, 0);
-                        return ">= " + dateObj.getTime().toString(10).substr(0, 10);
-                }
-                else if (filter.replace(/^\s+|\s+$/g,"") == "BEFORE"){
-                        dateObj.setHours(23, 59, 59, 999);
-                        return "<= " + dateObj.getTime().toString(10).substr(0, 10);
-                }
-                else if (filter.replace(/^\s+|\s+$/g,"") == "ON"){
-                        dateObj.setHours(0, 0, 0, 0);
-                        var ts1 = dateObj.getTime().toString(10).substr(0, 10);
-                        dateObj.setHours(23, 59, 59, 999);
-                        var ts2 = dateObj.getTime().toString(10).substr(0, 10);
-                        return ">= " + ts1 + ") and (timestamp <= " + ts2;
-                }
-                else if (filter.replace(/^\s+|\s+$/g,"") == "FLAGGED")
-                        return "flagged = 1";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "UNFLAGGED")
-                        return "flagged = 0";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "UNSEEN")
-                        return "unseen = 1";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "SEEN")
-                        return "unseen = 0";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "ANSWERED")
-                        return "answered = 1";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "UNANSWERED")
-                        return "answered = 0";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "RECENT")
-                        return "recent = 1";
-                else if (filter.replace(/^\s+|\s+$/g,"") == "OLD")
-                        return "recent = 0";
-
-	}
-	
-	local_messages.prototype.has_local_mails = function() {
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select rowid from folder limit 0,1");
-		var retorno;
-		if(rs.isValidRow())
-			retorno = true;
-		else 
-			retorno = false;
-		this.finalize();
-		return retorno;
-	}
-
-     //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Essa funï¿œï¿œo ï¿œ um AJAX simples que serve apenas para pegar o fonte de uma msg local (no formato RFC 822).
-    local_messages.prototype.get_src = function(url){
-        AJAX = false;
-        if (window.XMLHttpRequest) { // Mozilla, Safari,...
-            AJAX = new XMLHttpRequest();
-            if (AJAX.overrideMimeType) {
-                AJAX.overrideMimeType('text/xml');
-            }
-        } else if (window.ActiveXObject) { // IE
-            try {
-                AJAX = new ActiveXObject("Msxml2.XMLHTTP");
-            } catch (e) {
-                try {
-                AJAX = new ActiveXObject("Microsoft.XMLHTTP");
-                } catch (e) {}
-            }
-        }
-
-        if (!AJAX) {
-            alert('ERRO :(Seu navegador nï¿œo suporta a aplicaï¿œï¿œo usada neste site');
-            return false;
-        }
-
-        AJAX.onreadystatechange = function() {
-            if (AJAX.readyState == 4) {
-                AJAX.src=AJAX.responseText;
-                if (AJAX.status == 200) {
-                    return AJAX.responseText;
-                    } else {
-                    return false;
-                }
-            }
-        }
-
-        AJAX.open('get', url, false);
-        AJAX.send(null);
-        return AJAX.responseText;
-    };
-
-  //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Dessarquiva msgs locais pegando o codigo fonte das mesmas e mandando via POST para o servidor
-  //para que elas sejam inseridas no imap pela funï¿œï¿œo  imap_functions.unarchive_mail.
-    local_messages.prototype.unarchive_msgs = function (folder,new_folder,msgs_number){
-
-        if(!new_folder)
-            new_folder='INBOX';
-        this.init_local_messages();
-       // alert(folder+new_folder+msgs_number);
-        var handler_unarchive = function(data)
-        {
-            if(data.error == '')
-                write_msg(get_lang('All messages are successfully unarchived'));
-            else
-                alert(data.error);
-        }
-        if(msgs_number =='selected' || !msgs_number)
-        {
-            msgs_number = get_selected_messages()
-            if (!msgs_number){
-                write_msg(get_lang('No selected message.'));
-                return;
-            }
-            var rs = this.dbGears.execute("select mail,timestamp from mail where rowid in ("+msgs_number+")");
-            var source="";
-            var timestamp="";
-            while(rs.isValidRow()) {
-                mail=expresso.connector.unserialize(rs.field(0));
-                source_tmp=escape(this.get_src(mail.url_export_file));
-                    source+="#@#@#@"+source_tmp;
-                    timestamp+="#@#@#@"+rs.field(1);
-                rs.next();
-            }
-            rs.close();
-            this.finalize();
-        }
-        else
-        {
-            var rs = this.dbGears.execute("select mail,timestamp from mail where rowid="+msgs_number);
-            mail=expresso.connector.unserialize(rs.field(0));
-            var source ="";
-            source = this.get_src(mail.url_export_file);
-            timestamp=rs.field(1);
-             rs.close();
-             this.finalize();
-        }
-            params="&folder="+new_folder+"&source="+source+"&timestamp="+timestamp;
-            cExecute ("$this.imap_functions.unarchive_mail&", handler_unarchive, params);
-    }
-
-    local_messages.prototype.get_msg_date = function (original_id, is_local){
-
-        this.init_local_messages();
-
-        if (typeof(is_local) == 'undefined')
-        {
-            is_local = false;
-        }
-
-        var rs;
-
-        if (is_local)
-        {
-            rs = this.dbGears.execute("select mail from mail where rowid="+original_id);
-        }
-        else
-        {
-            rs = this.dbGears.execute("select mail from mail where original_id="+original_id);
-        }
-        var tmp = expresso.connector.unserialize(rs.field(0));
-        var ret = new Array();
-        ret.fulldate = tmp.fulldate.substr(0,16);
-        ret.smalldate = tmp.msg_day;
-        ret.msg_day = tmp.msg_day;
-        ret.msg_hour = tmp.msg_day;
-
-        rs.close();
-        this.finalize();
-        return ret;
-    }
-
-
-    local_messages.prototype.download_all_local_attachments = function(folder,id){
-        this.init_local_messages();
-        var rs = this.dbGears.execute("select mail from mail where rowid="+id);
-        var tmp = expresso.connector.unserialize(rs.field(0));
-        rs.close();
-        this.finalize();
-        source = this.get_src(tmp.url_export_file);
-        source = escape(source);
-        var handler_source = function(data){
-            download_attachments(null, null, data, null,null,'anexos.zip');
-        }
-        cExecute("$this.imap_functions.download_all_local_attachments",handler_source,"source="+source);
-    }
-
-    /*************************************************************************/
-/* Funcao usada para exportar mensagens arquivadas localmente.
- * Rommel de Brito Cysne (rommel.cysne@serpro.gov.br)
- * em 22/12/2008.
- */
-    local_messages.prototype.local_messages_to_export = function(){
-
-        if (openTab.type[currentTab] > 1){
-            var msgs_to_export_id = currentTab.substring(0,currentTab.length-2,currentTab);
-        }else{
-            var msgs_to_export_id = get_selected_messages();
-        }
-        var handler_local_mesgs_to_export = function(data){
-            download_attachments(null, null, data, null,null,'mensagens.zip');
-        }
-        if(msgs_to_export_id){
-            this.init_local_messages();
-            var l_msg = "t";
-            var mesgs ="";
-            var subjects ="";
-            var rs = this.dbGears.execute("select mail,subject from mail where rowid in ("+msgs_to_export_id+")");
-            while(rs.isValidRow()){
-                mail = expresso.connector.unserialize(rs.field(0));
-                mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file);
-                subject = rs.field(1);
-                mesgs += src;
-                mesgs += "@@";
-                subjects += subject;
-                subjects += "@@";
-                rs.next();
-            }
-            rs.close();
-            this.finalize();
-            mesgs = escape(mesgs);
-            subjects = escape(subjects);
-            params = "subjects="+subjects+"&mesgs="+mesgs+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export_id;
-            cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params);
-        }
-        return true;
-    }
-
-    local_messages.prototype.get_all_local_folder_messages= function(folder_name){
-
-
-         var mesgs = new Array();
-         var subjects = new Array();
-         var hoje = new Date();
-         var msgs_to_export = new Array();
-         var l_msg="t";
-
-        this.init_local_messages();
-        var query = "select mail,subject,mail.rowid from mail inner join folder on (mail.id_folder=folder.rowid) where folder.folder='" + folder_name + "'";
-
-        var rs = this.dbGears.execute(" "+query)
-
-            var handler_local_mesgs_to_export = function(data){
-                    //alert("data - " + data + " - tipo - " + typeof(data));
-                    download_attachments(null, null, data, null,null,'mensagens.zip');
-            }
-        var j=0;
-        while (rs.isValidRow()){
-              msgs_to_export[j]=rs.field(2)
-              mail = expresso.connector.unserialize(rs.field(0));
-                      mail.msg_source?src = mail.msg_source:src = this.get_src(mail.url_export_file);
-                      subject = rs.field(1);
-                      mesgs += msg;
-                      mesgs += "@@";
-                      subjects += subject;
-                      subjects += "@@";
-                      rs.next();
-              j++;
-
-        }
-           rs.close();
-           this.finalize();
-           source = escape(mesgs);
-           subjects = escape(subjects);
-           params = "folder="+folder_name+"&subjects="+subjects+"&mesgs="+source+"&l_msg="+l_msg+"&msgs_to_export="+msgs_to_export;
-           cExecute ("$this.exporteml.makeAll&", handler_local_mesgs_to_export, params);
-          
-
-    }
-
-
-    /*************************************************************************/
-
-	
-/******************************************************************
-	 				Offline Part 
- ******************************************************************/
-
-	local_messages.prototype.is_offline_installed = function() {
-		this.init_local_messages();
-		var check = this.localServer.openManagedStore('expresso-offline');
-		this.finalize();
-		if(check==null)
-			return false;
-		else
-			return true;
-		
-	}
-	local_messages.prototype.update_offline = function(redirect) {
-		this.init_local_messages();
-		var managedStore = this.localServer.openManagedStore('expresso-offline');
-
-		if(managedStore!=null){
-			
-			managedStore.oncomplete = function(details){
-				if(redirect!=null)
-					location.href=redirect;
-			}
-			
-			managedStore.checkForUpdate();
-		} else if(redirect!=null) {
-			location.href=redirect;
-		}
-		this.finalize();
-	}
-	
-	local_messages.prototype.uninstall_offline = function() {
-		if (!window.google || !google.gears) {
-				temp = confirm(document.getElementById('lang_gears_redirect').value);
-				if (temp) {
-					expresso_local_messages.installGears();
-				}
-				return;
-
-		}
-		this.init_local_messages();
-		this.localServer.removeManagedStore('expresso-offline');
-		alert(document.getElementById('lang_offline_uninstalled').value);
-		//this.dbGears.execute('drop table user');
-		//this.dbGears.execute('drop table queue');
-		//this.dbGears.execute('drop table attachments_queue');
-		this.finalize();
-	}
-	
-	local_messages.prototype.get_folders_to_sync = function() {//Precisa ter visibilidade ao array de linguagens.
-		this.init_local_messages();
-		var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario="+account_id);
-		var retorno = new Array();
-		while(rs.isValidRow()) {
-			temp = new Array();
-			temp[0] = rs.field(0);
-			if(temp[0]=='INBOX/Drafts' ||temp[0]=='INBOX/Trash' || temp[0]=='INBOX/Sent') {
-				temp[1] = array_lang[rs.field(1).toLowerCase()];
-			}
-			else {
-				temp[1] = rs.field(1);	
-			}
-			
-			retorno.push(temp);
-			rs.next();
-		}
-		this.finalize();
-		return retorno;
-	}
-	
-	local_messages.prototype.install_offline = function(urlOffline,urlIcone,uid_usuario,login,pass,redirect) {
-		if (!window.google || !google.gears) {
-				temp = confirm(document.getElementById('lang_gears_redirect').value);
-				if (temp) {
-					 expresso_local_messages.installGears();
-				}
-				return;
-
-		}
-		
-		if(pass.length>0) {
-			only_spaces = true;
-			for(cont=0;cont<pass.length;cont++) {
-				if(pass.charAt(cont)!=" ")
-					only_spaces = false;
-			}
-			if(only_spaces) {
-				alert(document.getElementById('lang_only_spaces_not_allowed').value);
-				return false;
-			}
-		}
-
-		modal('loading');
-		var desktop = google.gears.factory.create('beta.desktop');
-		desktop.createShortcut('ExpressoMail Offline',
-			urlOffline,
-	        {'32x32': urlIcone},
-	        'ExpressoMail Offline');
-
-
-		this.init_local_messages();
-
-		//user with offline needs to have at least the folder Inbox already created.
-		tmp_rs = this.dbGears.execute("select rowid from folder where folder='Inbox' and uid_usuario=?",[uid_usuario]);
-		if(!tmp_rs.isValidRow())
-			this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)",['Inbox',uid_usuario]);
-
-		this.localServer.removeManagedStore('expresso-offline');
-	
-		var managedStore = this.localServer.createManagedStore('expresso-offline');
-		managedStore.manifestUrl = 'js/manifest';
-
-		managedStore.onerror = function (error) {
-			alert(error);
-		}
-		
-		managedStore.oncomplete = function(details) {
-			if (close_lightbox_div) {
-				close_lightbox();
-				close_lightbox_div = false;
-				alert(document.getElementById('lang_offline_installed').value);
-				location.href=redirect;
-			}
-		}
-
-		//create structure to user in db
-		this.dbGears.execute('create table if not exists user (uid_usuario int,login text,pass text, logged int,unique(uid_usuario))');
-		this.dbGears.execute('create table if not exists queue (ffrom text, fto text, cc text, cco text,'+
-			'subject text, conf_receipt int, important int,body text,sent int,user int)');
-		this.dbGears.execute('create table if not exists attachments_queue ('+
-			'id_queue int, url_attach text)');
-		this.dbGears.execute('create table if not exists sent_problems (' +
-			'id_queue int,message text)');
-		
-		//d = new Date();
-		
-		try {
-			var rs = this.dbGears.execute("select uid_usuario from user where uid_usuario=?",[uid_usuario]);
-			if(!rs.isValidRow())
-				this.dbGears.execute("insert into user (uid_usuario,login,pass) values (?,?,?)",[uid_usuario,login,pass]);
-			else
-				this.dbGears.execute("update user set pass=? where uid_usuario=?",[pass,uid_usuario]);
-		} catch (error) {
-			this.finalize();
-			alert(error);
-			return false;
-		}
-		managedStore.checkForUpdate();
-		this.capt_url('controller.php?action=$this.db_functions.get_dropdown_contacts_to_cache');
-		
-		this.finalize();
-	}
-	
-	/**
-	 * Return all users in an array following the structure below.
-	 * 
-	 * key: uid
-	 * value: user login
-	 */
-	local_messages.prototype.get_all_users = function() {
-		this.init_local_messages();
-		var users = new Array();
-		var rs = this.dbGears.execute("select uid_usuario,login from user");
-		while(rs.isValidRow()) {
-			users[rs.field(0)] = rs.field(1);
-			rs.next();
-		}
-		this.finalize();
-		return users;
-	}
-	
-	local_messages.prototype.set_as_logged = function(uid_usuario,pass,bypass) {
-		this.init_local_messages();
-		if (!bypass) {
-			var rs = this.dbGears.execute("select pass from user where uid_usuario=?", [uid_usuario]);
-			if (!rs.isValidRow() || (pass != rs.field(0) && pass != MD5(rs.field(0)))) {
-				this.finalize();
-				return false;
-			}
-		}
-		d = new Date();
-
-		this.dbGears.execute("update user set logged=null"); //Logoff in everybody
-		this.dbGears.execute("update user set logged=? where uid_usuario=?",[d.getTime(),uid_usuario]); //Login just in one...
-		this.finalize();
-		return true;
-	}
-	
-	local_messages.prototype.unset_as_logged = function() {
-		this.init_local_messages();
-		this.dbGears.execute("update user set logged=null"); //Logoff in everybody
-		this.finalize();
-	}
-	
-	local_messages.prototype.user_logged = function() {
-		this.init_local_messages();
-		var user_logged = new Array();
-		var rs = this.dbGears.execute("select uid_usuario,logged from user where logged is not null");
-		if(!rs.isValidRow()) {
-			this.finalize();
-			return null;
-		}
-		user_logged[0] = rs.field(0);
-		user_logged[1] = rs.field(1);
-		this.finalize();
-		return user_logged;
-	}
-	
-	local_messages.prototype.send_to_queue = function (form) {
-		this.init_local_messages();
-		var mail_values = new Array();
-		
-		for (var i=0;i<form.length;i++) {
-			if (form.elements[i].name != '') { //I.E made me to do that...
-				if(form.elements[i].name=='folder' || form.elements[i].name=='msg_id' || form.elements[i].name=='' || form.elements[i].name==null)
-					continue;
-				else if (form.elements[i].name == 'input_return_receipt' ) 
-					mail_values['conf_receipt'] = form.elements[i].checked ? 1 : 0;
-				else if(form.elements[i].name == 'input_important_message')
-					mail_values['important'] = form.elements[i].checked ? 1 : 0;
-				else 
-					if (form.elements[i].name == 'body') 
-						mail_values['body'] = form.elements[i].value;
-					else 
-						if (form.elements[i].name == 'input_from') 
-							mail_values['ffrom'] = form.elements[i].value;
-						else 
-							if (form.elements[i].name == 'input_to') 
-								mail_values['fto'] = form.elements[i].value;
-							else 
-								if (form.elements[i].name == 'input_cc') 
-									mail_values['cc'] = form.elements[i].value;
-								else 
-									if (form.elements[i].name == 'input_cco') 
-										mail_values['cco'] = form.elements[i].value;
-									else 
-										if (form.elements[i].name == 'input_subject') 
-											mail_values['subject'] = form.elements[i].value;
-			}
-		}
-		//mail_values['fto'] = input_to;
-		//mail_values['cc'] = input_cc;
-		//mail_values['cco'] = input_cco;
-		//mail_values['subject'] = input_subject;
-		//mail_values['conf_receipt'] = input_return_receipt;
-		//mail_values['important'] = input_important_message;
-		
-		try {
-			this.dbGears.execute("insert into queue (ffrom,fto,cc,cco,subject,conf_receipt,important,body,sent,user) values (?,?,?,?,?,?,?,?,0,?)", [mail_values['ffrom'], mail_values['fto'], mail_values['cc'], mail_values['cco'], mail_values['subject'], mail_values['conf_receipt'], mail_values['important'], mail_values['body'], account_id]);
-			this.send_attach_to_queue(this.dbGears.lastInsertRowId,form);
-		}catch(error) {
-			alert(error);
-			return get_lang('Error sending a mail to queue. Verify if you have installed ExpressoMail Offline');
-		}
-		this.finalize();
-		return true;
-	}
-	
-	local_messages.prototype.send_attach_to_queue = function(id_queue,form) {
-		
-		for(i=0;i<form.elements.length;i++) {
-			
-			if(form.elements[i].name.indexOf("file_")!=-1) {
-				var tmp_input = form.elements[i];
-				var d = new Date();
-				var url_local = 'local_attachs/'+d.getTime();
-				this.store.captureFile(tmp_input, url_local);
-				this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,url_local]);
-			}
-			else if(form.elements[i].name.indexOf("offline_forward_")!=-1){
-				//alert();
-				this.dbGears.execute("insert into attachments_queue (id_queue,url_attach) values (?,?)",[id_queue,form.elements[i].value]);
-			}
-		}
-	}
-
-	
-	local_messages.prototype.get_num_msgs_to_send = function() {
-		this.init_local_messages();
-
-		var rs = this.dbGears.execute("select count(*) from queue where user=? and sent=0",[account_id]);
-		var to_return = rs.field(0);
-
-		this.finalize();
-		return to_return;
-	}
-	
-	local_messages.prototype.set_problem_on_sent = function(rowid_message,msg) {
-		this.init_local_messages();
-		this.dbGears.execute("update queue set sent = 2 where rowid=?",[rowid_message]);
-		this.dbGears.execute("insert into sent_problems (id_queue,message) values (?,?)"[rowid_message,msg]);
-		this.finalize();
-	}
-	
-	local_messages.prototype.set_as_sent = function(rowid_message) {
-		this.init_local_messages();
-		this.dbGears.execute("update queue set sent = 1 where rowid=?",[rowid_message]);
-		this.finalize();
-	}
-	
-	local_messages.prototype.get_form_msg_to_send = function() {
-		this.init_local_messages();
-		var rs = this.dbGears.execute('select ffrom,fto,cc,cco,subject,conf_receipt,important,body,rowid from queue where sent=0 and user = ? limit 0,1',[account_id]);
-		if(!rs.isValidRow())
-			return false;
-		
-		var form = document.createElement('form');
-		form.method = 'POST';
-		form.name = 'form_queue_'+rs.field(8);
-		form.style.display = 'none';
-		form.onsubmit = function(){return false;}
-		if(!is_ie)
-			form.enctype="multipart/form-data";
-		else
-			form.encoding="multipart/form-data";
-		
-		var ffrom = document.createElement('TEXTAREA');
-		ffrom.name = "input_from";
-		ffrom.value = rs.field(0);
-		form.appendChild(ffrom);
-		
-		var fto = document.createElement('TEXTAREA');
-		fto.name = "input_to";
-		fto.value = rs.field(1);
-		form.appendChild(fto);
-		
-		var cc = document.createElement('TEXTAREA');
-		cc.name = "input_cc";
-		cc.value = rs.field(2);
-		form.appendChild(cc);
-
-		var cco = document.createElement('TEXTAREA');
-		cco.name = "input_cco";
-		cco.value = rs.field(3);
-		form.appendChild(cco);
-		
-		var subject = document.createElement('TEXTAREA');
-		subject.name = "input_subject";
-		subject.value = rs.field(4);
-		form.appendChild(subject);
-		
-		var folder = document.createElement('input');
-		folder.name='folder';
-		folder.value=preferences.save_in_folder;
-		form.appendChild(folder);
-		
-		if (rs.field(5) == 1) {
-			var conf_receipt = document.createElement('input');
-			conf_receipt.type='text';
-			conf_receipt.name = "input_return_receipt";
-			conf_receipt.value = 'on';
-			form.appendChild(conf_receipt);
-		}
-		
-		if (rs.field(6) == 1) {
-			var important = document.createElement('input');
-			important.type='text';
-			important.name = "input_important_message";
-			important.value = 'on';
-			form.appendChild(important);
-		}
-		
-		var body = document.createElement('TEXTAREA');
-		body.name = "body";
-		body.value = rs.field(7);
-		form.appendChild(body);
-		
-		var rowid = document.createElement('input');
-		rowid.type = 'hidden';
-		rowid.name = 'rowid';
-		rowid.value = rs.field(8);
-		form.appendChild(rowid);
-		
-		//Mounting the attachs
-		var divFiles = document.createElement("div");
-		divFiles.id = 'divFiles_queue_'+rs.field(8);
-		
-		form.appendChild(divFiles);
-		
-		document.getElementById('forms_queue').appendChild(form);
-
-		var is_local_forward = false;
-		try {
-			
-			var rs_attach = this.dbGears.execute('select url_attach from attachments_queue where id_queue=?', [rs.field(8)]);
-			while (rs_attach.isValidRow()) {
-				if(rs_attach.field(0).indexOf('../tmpLclAtt/')==-1) {
-					tmp_field = addForwardedFile('queue_' + rs.field(8), this.store.getCapturedFileName(rs_attach.field(0)), 'nothing');
-				}
-				else {
-					var tempNomeArquivo = rs_attach.field(0).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.
-					is_local_forward = true;
-					tmp_field = addForwardedFile('queue_' + rs.field(8), nomeArquivo, 'nothing');
-				}
-				fileSubmitter = this.store.createFileSubmitter();
-				fileSubmitter.setFileInputElement(tmp_field,rs_attach.field(0));
-		//		alert(form.innerHTML);
-			//	div.appendChild(tmp_field);
-				rs_attach.next();
-			}
-			
-			if(is_local_forward) {
-				var is_lcl_fw = document.createElement('input');
-				is_lcl_fw.type = 'hidden';
-				is_lcl_fw.name = 'is_local_forward';
-				is_lcl_fw.value = "1";
-				form.appendChild(is_lcl_fw);
-			}
-				
-		}
-		catch(exception) {
-			alert(exception);
-		}
-		
-		this.finalize();
-		return form;
-	}
-
-	var expresso_local_messages;
-	expresso_local_messages = new local_messages();
-	expresso_local_messages.create_objects();
Index: trunk/expressoMail1_2/js/TreeS.js
===================================================================
--- trunk/expressoMail1_2/js/TreeS.js	(revision 2010)
+++ 	(revision )
@@ -1,216 +1,0 @@
-/**************************************************************************\
- Início 
-\**************************************************************************/
-
-	function treeS()
-	{
-		this.arrayW = new Array();
-		this.el;
-		this.FOLDER = "";
-	}
-
-	treeS.prototype.make_Window = function(){	
-		_this = this;
-		expresso.connector.loadScript("TreeShow");
-		var title = ':: '+get_lang("Manager your folders and export messages")+' ::';
-		tree 				  = document.createElement("DIV");
-		tree.style.visibility = "hidden";
-		tree.style.position   = "absolute";
-		tree.style.left 	  = "0px";
-		tree.style.top 		  = "0px";
-		tree.style.width 	  = "0px";
-		tree.style.height 	  = "0px";									
-		tree.id				  = "window_tree";
-		document.body.appendChild(tree);
-
-		tree.innerHTML = "&nbsp;&nbsp;&nbsp;<b><font color='BLACK' nowrap>"+title+"</font></b>"+
-		"&nbsp;&nbsp;<br><u></u>&nbsp;&nbsp;";
-
-		var div_buttons = document.createElement("DIV");
-		div_buttons.id = "div_buttons";
-		div_buttons.style.position = "absolute";		
-		div_buttons.style.left = "440px";
-		div_buttons.style.top = "20px"		
-		div_buttons.style.width = "130px";
-		div_buttons.style.height = "214px";
-		div_buttons.innerHTML = "<table border='0' cellpading='0' cellspacing='0'>"+
-							    "<tr>"+
-							    "<td><input type='button' value='"+get_lang('New folder')+"' onclick='proxy_mensagens.proxy_create_folder()'></td>"+
-							    "</tr>"+
-							    "<tr>"+
-							    "<td><input type='button' value='"+get_lang('Delete folder')+"' onclick='proxy_mensagens.proxy_remove_folder()'></td>"+
-							    "</tr>"+
-							    "<tr>"+
-							    "<td><input type='button' value='"+get_lang('Rename folder')+"' onclick='proxy_mensagens.proxy_rename_folder()'></td>"+
-							    "</tr>"+
-							    "<tr>"+
-                                                            //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Chama o proxy_mensagens para que uma pasta local também possa ser exportada
-                                                            "<td><input type='button' value='"+get_lang('Export messages')+"' onclick='proxy_mensagens.proxy_export_all_msg()'></td>"+
-							    "</tr>"+
-							    "<tr><td><br><br><br><br><br></td></tr>"+
-							    "<tr><td><input type='button' value='"+get_lang('Close')+"' onclick='ttree.close_win()'></td></tr>"+
-							    "</table>";
-		tree.appendChild(div_buttons);		
-
-		// Conf tree
-		var jo = document.createElement("DIV");
-		jo.id = "div_tree";
-		jo.style.position = "absolute";
-		jo.style.left = "10px";
-		jo.style.top = "20px";
-		jo.style.width = "420px";
-		jo.style.height = "215px";
-		jo.style.borderStyle = "outset";
-		jo.style.borderColor = "black";
-		jo.style.borderWidth = "2px";
-		jo.style.background  = "#F7F7F7";
-		jo.style.overflow    = "auto";
-		jo.innerHTML = "";
-		tree.appendChild(jo);
-
-		if(!expresso_offline)
-			ttree.make_tree(folders,"div_tree","folders_tree","ttree.get_folder(\"root\")","","root",false);
-		else
-			ttree.make_tree(folders,"div_tree","folders_tree","ttree.get_folder(\"local_root\")","","local_root",false);
-		_this.showWindow(tree);
-
-	}
-	
-	treeS.prototype.get_folder = function(param){
-		this.FOLDER = param;
-	}
-
-	treeS.prototype.showWindow = function (div){
-		if(! div) {
-			return;
-		}
-		
-		if(! this.arrayW[div.id]) {
-			div.style.width  = "580px";
-			div.style.height = "250px";
-			div.style.zIndex = "10000";			
-			var title = get_lang("Folder Management");
-			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.arrayW[div.id] = win;
-			win.draw();
-		}
-		else {
-			win = this.arrayW[div.id];
-		}
-		win.open();
-	}
-	
-	treeS.prototype.close_win = function(){
-	
-		this.FOLDER = "";
-		this.arrayW['window_tree'].close();
-	
-	}
-
-	treeS.prototype.make_tree = function (data,destination,name_tree, click_root, opentomb, selected,menu_folder){
-		//Somente para teste
-		//alert("data: " + data.length + "\n" + "destination : " + destination + "\n" + "name_tree : " + name_tree + "\n" + "click_root : " + click_root + "\n" + "opentomb : " + opentomb + "\n" + "selected : " + selected + "\n" + "menu_folder : " + menu_folder);
-			
-		if(Element('dftree_' + name_tree)){
-			Element('dftree_' + name_tree).innerHTML = '';
-		}
-		
-		folders_tree = new dFTree({name: name_tree});
-		if (!expresso_offline) {		
-			if(click_root != ""){
-				var n_root = new dNode({id:'root', caption:get_lang("My Folders"), onClick:click_root});
-			}else{
-				var n_root = new dNode({id:'root', caption:get_lang("My Folders")});		
-			}
-			folders_tree.add(n_root,'root'); //Places the root; second argument can be anything.
-	
-			if(data.length == 0){
-				alert("sem dados");
-				return false;
-			}
-		
-			for (var i=0; i<data.length; i++){
-				if(menu_folder){
-					if (data[i].folder_unseen > 0)
-						var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+data[i].folder_id+"','"+data[i].folder_name+"')", plusSign:data[i].folder_hasChildren}); 
-					else
-						var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name), onClick:"change_folder('"+data[i].folder_id+"','"+data[i].folder_name+"')", plusSign:data[i].folder_hasChildren}); 
-				}else{
-					var nn = new dNode({id:data[i].folder_id, caption:lang_folder(data[i].folder_name), plusSign:data[i].folder_hasChildren});
-				}
-	
-				if (data[i].folder_parent == '')
-					data[i].folder_parent = 'root';
-				else if (data[i].folder_parent == 'user'){
-					if (!tree_folders.getNodeById('user')){
-						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared Folders"), plusSign:true}); 
-						folders_tree.add(n_root_shared_folders,'root');
-					}
-				}
-				folders_tree.add(nn,data[i].folder_parent);
-			}
-		}
-		//Pastas locais
-		if (preferences.use_local_messages == 1) {
-			var n_root_local = new dNode({
-				id: 'local_root',
-				caption: get_lang("local messages"),
-				plusSign: true,
-                                onClick:"ttree.get_folder('local_root')"
-			});
-			folders_tree.add(n_root_local, 'root');
-			
-			var local_folders = expresso_local_messages.list_local_folders();
-			for (var i in local_folders) { //Coloca as pastas locais.
-			
-				var node_parent = "local_root";
-				var new_caption = local_folders[i][0];
-				if(local_folders[i][0].indexOf("/")!="-1") {
-					final_pos = local_folders[i][0].lastIndexOf("/");
-					node_parent = "local_"+local_folders[i][0].substr(0,final_pos);
-					new_caption = local_folders[i][0].substr(final_pos+1);
-				}
-				
-				if (local_folders[i][1] > 0) 
-					var nodeLocal = new dNode({
-						id: "local_" + local_folders[i][0],
-						caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
-						plusSign: local_folders[i][2]
-					});
-				else 
-					var nodeLocal = new dNode({
-						id: "local_" + local_folders[i][0],
-						caption: lang_folder(new_caption),
-						plusSign: local_folders[i][2]
-					});
-				folders_tree.add(nodeLocal, node_parent);
-			}
-		}
-		folders_tree.draw(Element(destination));
-		if(!expresso_offline)
-			n_root.changeState();
-		else
-			n_root_local.changeState();
-		if(opentomb != ""){folders_tree.openTo(opentomb);}
-		if(selected != "" && folders_tree.getNodeById(selected)){folders_tree.getNodeById(selected)._select();}
-
-	}
-
-/* Build the Object */
-	var ttree;
-	ttree = new treeS();
Index: trunk/expressoMail1_2/js/globals.js
===================================================================
--- trunk/expressoMail1_2/js/globals.js	(revision 2328)
+++ 	(revision )
@@ -1,46 +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 array_lang = new Array();
-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 height="16px" 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="templates/'+template+'/images/menu/createmail.gif">'+
-	'&nbsp;Novo</a>&nbsp;&nbsp;'+
-	'<a href="#" onclick="javascript:wfolders.makeWindow(\'\', \'change_folder\')" align=left>'+
-	'<img src="templates/'+template+'/images/menu/editfolders.png">'+
-	'&nbsp;Trocar Pasta</a>&nbsp;&nbsp'+	
-	'<a href="#" onclick="javascript:refresh();" align=left>'+
-	'<img src="templates/'+template+'/images/menu/checkmail.gif">'+
-	'&nbsp;Atualizar</a>&nbsp;&nbsp;'+
-	'<a id="link_tools" href="#" align=left>'+
-	'<img height="16px" src="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');
-
Index: trunk/expressoMail1_2/js/gears_init.js
===================================================================
--- trunk/expressoMail1_2/js/gears_init.js	(revision 670)
+++ 	(revision )
@@ -1,86 +1,0 @@
-// Copyright 2007, Google Inc.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-//  1. Redistributions of source code must retain the above copyright notice,
-//     this list of conditions and the following disclaimer.
-//  2. Redistributions in binary form must reproduce the above copyright notice,
-//     this list of conditions and the following disclaimer in the documentation
-//     and/or other materials provided with the distribution.
-//  3. Neither the name of Google Inc. nor the names of its contributors may be
-//     used to endorse or promote products derived from this software without
-//     specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
-// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
-// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Sets up google.gears.*, which is *the only* supported way to access Gears.
-//
-// Circumvent this file at your own risk!
-//
-// In the future, Gears may automatically define google.gears.* without this
-// file. Gears may use these objects to transparently fix bugs and compatibility
-// issues. Applications that use the code below will continue to work seamlessly
-// when that happens.
-
-(function() {
-  // We are already defined. Hooray!
-  if (window.google && google.gears) {
-    return;
-  }
-
-  var factory = null;
-
-  // Firefox
-  if (typeof GearsFactory != 'undefined') {
-    factory = new GearsFactory();
-  } else {
-    // IE
-    try {
-      factory = new ActiveXObject('Gears.Factory');
-      // privateSetGlobalObject is only required and supported on WinCE.
-      if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
-        factory.privateSetGlobalObject(this);
-      }
-    } catch (e) {
-      // Safari
-      if ((typeof navigator.mimeTypes != 'undefined')
-           && navigator.mimeTypes["application/x-googlegears"]) {
-        factory = document.createElement("object");
-        factory.style.display = "none";
-        factory.width = 0;
-        factory.height = 0;
-        factory.type = "application/x-googlegears";
-        document.documentElement.appendChild(factory);
-      }
-    }
-  }
-
-  // *Do not* define any objects if Gears is not installed. This mimics the
-  // behavior of Gears defining the objects in the future.
-  if (!factory) {
-    return;
-  }
-
-  // Now set up the objects, being careful not to overwrite anything.
-  //
-  // Note: In Internet Explorer for Windows Mobile, you can't add properties to
-  // the window object. However, global objects are automatically added as
-  // properties of the window object in all browsers.
-  if (!window.google) {
-    google = {};
-  }
-
-  if (!google.gears) {
-    google.gears = {factory: factory};
-  }
-})();
Index: trunk/expressoMail1_2/js/wfolders.js
===================================================================
--- trunk/expressoMail1_2/js/wfolders.js	(revision 1121)
+++ 	(revision )
@@ -1,163 +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 */
-	var wfolders;
-	wfolders = new cWFolders();
Index: trunk/expressoMail1_2/js/filter.js
===================================================================
--- trunk/expressoMail1_2/js/filter.js	(revision 2400)
+++ 	(revision )
@@ -1,752 +1,0 @@
-
-	function charCounter(form)
-	{
-		if (form.value.length >= 300)
-		{
-			alert(get_lang("You have exceeded the number of allowed characters"));
-			return false;
-		}
-	}
-
-	function cfilter(){
-
-		this.mode_in   = "";
-		this.rulest		 = new Array;
-		this.rulesVoip	 = new Array;
-		this.out_officeR = "";
-		this.out_officeF = false;
-		this.email_deny  = new Array;
-		this.ac_form     = "";
-		this.ind		 = "";
-		this.email_deny  = new Array;
-		this.email_ld	 = "";
-		this.values = new Array("",
-					",checkBox1",
-					",select_size=1",
-					",checkBox1,select_size=1",
-					",select_rules=1",
-					",checkBox1,select_rules=1",				
-					",select_size=1,select_rules=1",				
-					",checkBox1,select_size=1,select_rules=1",
-					",checkBox2",				
-					",checkBox1,checkBox2",				
-					",checkBox2,select_size=1",
-					",ckeckBox1,checkBox2,select_size=1",
-					",checkBox2,select_rules=1",																				
-					",checkBox1,checkBox2,select_rules=1",				
-					",checkBox2,select_size=1,select_rules=1",				
-					",checkBox1,checkBox2,select_size=1,select_rules=1");
-		
-	}
-
-	
-	cfilter.prototype.load_rules = function()
-	{
-		var _this = this;
-		var cont1 = parseInt(0);
-		var cont2 = parseInt(0);
-				
-		if( _this.rulest.length == 0 )
-		{
-			var handler_sieve = function(data)
-			{
-				if(data.rule.length > 0){
-					for(var i=0 ; i < data.rule.length; i++)
-					{
-						var fields = data.rule[i].split("&&");
-						if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect )
-							_this.rulesVoip[cont1++] = data.rule[i];
-						else
-							_this.rulest[cont2++] = data.rule[i];
-					}
-				}
-				_this.out_officeR = data.vacation[0];
-				_this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : "";
-				if(data.mode.length > 0){_this.mode_in = data.mode[0];}
-			}
-			if(Element('form_status') != null)
-				Element('form_status').innerHTML = "<span style='background:#cc4444;'>&nbsp;&nbsp;<font color='WHITE'>Aguarde...</font>&nbsp;</span>";
-			cExecute("$this.ScriptS.init_a",handler_sieve);
-			_this.get_email();
-	    }
-	}
-	
-	cfilter.prototype.form_m = function(){
-		Element('form_body').innerHTML = "";
-		Element('form_buttons').style.display = '';
-		filters.mount_list();
-		this.ac_form = "";		
-	}
-	
-	cfilter.prototype.form_out = function(){
-		Element('form_body').innerHTML = "";
-		Element('form_body').innerHTML = this.forms_();
-		Element('div_vacation').style.display = "";
-		this.ac_form = "old_out";		
-		this.r_rules_out();		
-	}
-	
-	cfilter.prototype.form_r = function(pos,type)
-	{
-		Element('form_body').innerHTML = "";
-		Element('form_body').innerHTML = this.forms_();
-		this.ind = pos;		
-		
-		if( type === 'voip')
-		{
-			this.ac_form = "old_voip";
-			Element('div_voipFilter').style.display = "";
-			this.r_rules_form(pos, type);	
-		}
-		else
-		{
-			this.ac_form = "old_rule";
-			Element('div_rule').style.display = "";	
-			this.r_rules_form(pos, type);
-		}
-	}
-	
-	cfilter.prototype.get_email = function()
-	{
-		var _this = this;
-		var handler_get_email = function(data)
-		{
-			_this.email_ld = data ? data : "";
-		}
-		cExecute("$this.user.get_email",handler_get_email);
-	}
-	
-	cfilter.prototype.sel_boxes = function()
-	{
-		var nm_folders = tree_folders.getNodesList(cyrus_delimiter);
-		if(document.getElementById("select_mailboxes") != null){
-			var sel_nm = document.getElementById("select_mailboxes");
-			if(sel_nm.length > 0 ){
-				for(var i=0; i < sel_nm.options.length; i++){
-					sel_nm.options[i] = null;
-					i--;
-				}
-			}
-			for(var i=0; i < nm_folders.length; i++){
-				if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){
-					var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true);
-					sel_nm[sel_nm.length] = opt;
-				}
-			}
-			sel_nm[0].selected = true;
-		}
-	}
-
-	cfilter.prototype.box_select = function(param){
-		var aux = this.BoxSelection[param].split(",");
-		var ele1 = document.getElementById(aux[0]);
-		var ele2 = document.getElementById(aux[1]);
-		var noption = "";
-		if(param == 0 || param == 1){
-			if(ele1.selectedIndex != -1){
-				noption = new Option(ele1.value,ele1.value,false,false);
-				ele2.options[ele2.length] = noption;
-				ele1.options[ele1.selectedIndex] = null;
-				ele1.selectedIndex = 0;
-			}
-		}
-	}
-
-	cfilter.prototype.r_rules_form = function(ind, type)
-	{
-		var fields = new Array;
-		var _this = this;
-		
-		// hide buttons
-		Element('form_buttons').style.display = 'none';
-		
-		if( type === 'voip')
-		{
-			fields = _this.rulesVoip[ind].split("&&");
-			document.getElementById("field9").value = fields[5];			
-		}
-		else
-		{
-			this.sel_boxes();
-			if(this.rulest.length == 0){
-				return false;
-			}
-			fields = _this.rulest[ind].split("&&");
-			document.getElementById("field1").value = fields[3];
-			document.getElementById("field2").value = fields[4];
-			document.getElementById("field3").value = fields[5];
-			document.getElementById("field4").value = fields[11];				
-			
-			switch(fields[6]){
-				case "folder":
-					document.getElementById("radio1").checked  = true;
-					var name_mb = fields[7];
-					var sel_mb = document.getElementById("select_mailboxes");
-					for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) ==  name_mb){sel_mb.options[i].selected = true;}}
-					break;
-				case "address":
-					document.getElementById("radio2").checked   = true;
-					document.getElementById("field5").value 	= fields[7];
-					break;
-				case "reject":
-					 document.getElementById("radio3").checked  = true;
-					 var text0 = fields[7].split("\\n");				 	
-					 for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";}
-					 break;
-				case "discard":
-					document.getElementById("radio4").checked 	= true;
-					break;
-			}
-			var mark_values = this.values[fields[8]].split(",");
-			for(var i=0; i < mark_values.length; i++){
-				if( mark_values[i] == "checkBox1" || mark_values[i] == "checkBox2"){
-					document.getElementById(mark_values[i]).checked = true;
-				}
-				if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){
-					var mark_val = mark_values[i].split("=");
-					document.getElementById(mark_val[0]).options[mark_val[1]].selected = true;
-				}
-			}
-		}
-	}
-
-	cfilter.prototype.r_rules_out = function(){
-	
-		var _this = this;
-		if(_this.out_officeR.length == 0){
-			return false;
-		}
-		
-		// hide buttons
-		Element('form_buttons').style.display = 'none';
-	
-		var aux = _this.out_officeR.split("&&");
-		var days   = aux[1];
-		var emails = aux[2];
-		var mens   = aux[3];		
-		var p_emails = new Array;
-		var d_emails = new Array;
-				
-		var p_aux = emails.split(", ");
-		for(var i=0; i < p_aux.length; i++){
-			p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1));
-			p_emails[i] = p_emails[i].substr(1,(p_aux[i].length));
-		}
-		for(var i=0; i < _this.email_ld.length; i++){
-			d_emails[i] = _this.email_ld[i];
-		}
-
-		diff = function(vet, comp){
-			var sel1 = new Array;
-			for(var i=0; i < vet.length; i++){
-				for(var j=0; j < comp.length; j++){
-					if(vet[i] == comp[j]){
-						comp.splice(j,1);
-						j--;
-					}
-				}
-			}
-		};	
-		diff(p_emails,d_emails);
-		var text    = mens.split("\\n");
-		for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";}
-		for(var i=0; i < _this.email_ld.length; i++){
-			d_emails[i] = _this.email_ld[i];
-		}
-
-	}
-
-	/*
-	 * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição)
-	 * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada
-	 */
-	cfilter.prototype.disable_radio3 =  function()
-	{
-		radio3 = Element('radio3');
-		field6 = Element('field6');
-		cb2 = Element('checkBox2');
-
-		if (cb2.checked)
-		{
-			radio3.disabled = true;
-			field6.disabled = true;
-
-			if (radio3.checked)
-			{
-				radio3.checked = false;
-			}
-		}
-		else
-		{
-			radio3.disabled = false;
-			field6.disabled = false;
-		}
-
-	}
-
-	cfilter.prototype.forms_ = function()
-	{
-			 var form = "";
-				 form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+
-						"<tr><td colspan='2'><input type='checkBox' id='checkBox1' name='checkb'>"+get_lang('Also check message against next rule') + "</td></tr>"+
-						"<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio3();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+
-						"<tr><td colspan='2'><hr size='1' width='100%'></td></tr><tr>"+
-						"<td rowspan='4' width='20%'>"+get_lang('Coincident')+"<br><select id='select_rules' name='select_rules'>"+
-						"<option value='0'>"+get_lang("with all")+"</option><option value='1'>"+get_lang("with some")+"</option>"+
-						"</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+
-						"</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+
-						"</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+
-						"</tr><tr><td>"+get_lang('The size of the message is')+".: &nbsp<select id='select_size' name='select_size'>"+
-						"<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+						 
-						"</select>&nbsp;<input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+
-						"</tr><tr><td colspan='2'><hr size='1' width='100%'></td></tr>"+
-						"</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+
-						"<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+
-						"<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+
-						"</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+
-						"<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+
-						"</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+
-						"<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+
-						"</tr><tr><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+
-						"</tr></table></div><div id='div_vacation' style='display:none'>"+
-						"<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+
- 						"<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+
-						//"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+
-						"<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+
-	 					"</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>" +
-						"<div id='div_voipFilter' style='display:none'>" +
-						"<br/><table id='table_voipFilter'>" +
-						"<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+
-						"</td></tr><tr><td><input type='text' id='field9' size='50' maxlength='200'>" +
-						"</td></tr><br/></table></div>" +
-				 		"<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+
-				 		"<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>";
-		return form;
-	}
-
-	cfilter.prototype.enabled_disabled = function(param){
-
-		// Rules
-		if(Element("rule_0") != null){
-			for(var i=0; i < this.rulest.length; i++){
-				if(Element("rule_"+i).checked){
-					var aux_rul = this.rulest[i].split("&&");
-					if(aux_rul[2] != param){
-						aux_rul[2] = param;					
-						var rl = "";
-						for(var j=0; j < aux_rul.length; j++){
-							rl += aux_rul[j] + "&&";
-						}
-						rl = rl.substr(0,(rl.length - 2));
-						this.rulest[i] = rl;					
-					}
-				}
-			}
-		}
-		// Out Office
-		if(Element("out_0") != null){
-			if(Element("out_0").checked){
-				var aux_out = this.out_officeR.split("&&");
-				if(param == "ENABLED")
-					aux_out[4] = "on ";
-				else
-					aux_out[4] = "off";
-				var out = "";
-				for(var i=0; i < aux_out.length; i++){
-					out += aux_out[i] + "&&";
-				}				
-				out = out.substr(0,(out.length - 2));
-				this.out_officeR = out;
-			}
-		}
-
-		// Voip
-		if(Element("voip_rule_0") != null){
-			for(var i=0; i < this.rulesVoip.length; i++){
-				if(Element("voip_rule_"+i).checked){
-					var aux_rul = this.rulesVoip[i].split("&&");
-					if(aux_rul[2] != param){
-						aux_rul[2] = param;					
-						var rl = "";
-						for(var j=0; j < aux_rul.length; j++){
-							rl += aux_rul[j] + "&&";
-						}
-						rl = rl.substr(0,(rl.length - 2));
-						this.rulesVoip[i] = rl;					
-					}
-				}
-			}
-		}
-		
-		this.reload_rules();
-	}
-	
-	cfilter.prototype.new_rule = function(email){
-
-		if(this.email_deny.length > 0){
-			for(var i=0 ; i < this.email_deny.length; i++){
-				if(this.email_deny[i] == email){
-					alert(get_lang("Sender blocked")+"!");
-					return false;
-				}
-			}
-		}
-
-	    	if(!validateEmail(email)){
-			alert(get_lang("Inform a valid e-mail!"));
-			return false;
-		}
-
-		this.load_rules();
-		if(confirm(get_lang("Do you want to block this e-mail?"))){
-			new_r = "&&ENABLED&&" + email + "&&&&&&discard&&&&0&&&&&&0";
-//			setTimeout("filter.e_newrule('" + new_r + "')",2000);		
-			if (filter.e_newrule(new_r)){
-				this.email_deny.push(email);
-				write_msg(get_lang("The sender was blocked"));							
-			}else
-				write_msg(get_lang("You have reached the maximum number of rules"));
-		}
-	}
-	
-	cfilter.prototype.e_newrule = function(nw_rule)
-	{
-
-		var new_rl = "";
-		if (this.rulest.length >= rules_limit)
-			return false;
-			
-		if(this.rulest.length == 0){
-			new_rl = "#rule&&1" + nw_rule;
-		}else{
-			var aux = this.rulest[this.rulest.length -1 ].split("&&");
-			new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule;
-		}
-		this.rulest.push(new_rl);
-		this.saved_all();
-		return true;
-	}
-	
-	cfilter.prototype.delete_r = function(){
-	
-		// rule
-		var _this = this;
-		if(Element("rule_0") != null){
-			for(var i=0; i < _this.rulest.length; i++){
-				if(Element("rule_"+i).checked){_this.rulest[i] = "delete";}
-			}
-			for(var i=0; i < _this.rulest.length; i++){
-				if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;}
-			}
-		}
-	
-		if(_this.rulest.length > 0){
-			var cont = parseInt(1);
-			for(var i=0; i < _this.rulest.length ; i++){
-				var n_rulest = _this.rulest[i].split("&&");
-				n_rulest[1] = cont;
-				cont = cont + parseInt(2);
-				var aux = "";
-				for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
-				aux = aux.substr(0,(aux.length - 2));
-				_this.rulest[i] = aux;
-			}
-		} 
-		// out office
-		if(Element("out_0") != null){
-			if(Element("out_0").checked){
-				_this.out_officeR ='';
-				_this.out_officeF = false;
-				//Save outoffice in prefs:
-				expresso.connector.loadScript("preferences");
-				prefe.save("outoffice", _this.out_officeF);
-			}
-		}
-		
-		// Voip
-		if(Element("voip_rule_0") != null){
-			for(var i=0; i < _this.rulesVoip.length; i++){
-				if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";}
-			}
-			for(var i=0; i < _this.rulesVoip.length; i++){
-				if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;}
-			}
-		}
-	
-		if(_this.rulesVoip.length > 0){
-			var cont = parseInt(1);
-			for(var i=0; i < _this.rulesVoip.length ; i++){
-				var n_rulest = _this.rulesVoip[i].split("&&");
-				n_rulest[1] = cont;
-				cont = cont + parseInt(2);
-				var aux = "";
-				for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";}
-				aux = aux.substr(0,(aux.length - 2));
-				_this.rulesVoip[i] = aux;
-			}
-		} 
-
-		_this.reload_rules();
-	}
-	
-	cfilter.prototype.reload_rules = function()
-	{
-		this.saved_all();
-		Element('form_body').innerHTML = "";
-		this.load_rules();
-
-		if(this.out_officeF)
-		{
-			write_msg(get_lang("Attention, you are in out of office mode."), true);
-		}else{
-			clean_msg();
-			this.out_officeF = false;
-		}
-		filters.mount_list();
-	}
-
-	cfilter.prototype.saved_rules = function(){
-
-		var mount_rule = "";
-		var form = this.ac_form.split("_");
-		var n_rule = "";
-
-		if(form[1] == "rule")
-		{
-			mount_rule = "#rule&&";
-			if(form[0] == "new")
-			{
-				n_rule = "1&&";
-				if(this.rulest.length > 0)
-				{
-					aux = this.rulest[this.rulest.length - parseInt(1)].split("&&");
-					n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
-				}
-				mount_rule += n_rule + "ENABLED&&";
-			}
-			else
-			{
-				n_rule = this.rulest[this.ind].split("&&");
-				mount_rule += n_rule[1] + "&&";
-				mount_rule += n_rule[2] + "&&";
-			}
-
-			if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "")
-			{
-				alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
-				return false;
-			}
-
-			if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){
-				alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!"));
-				return false;
-			}
-			
-			for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";} 
-			var v_checked = false;
-			if(Element("radio1").checked){
-				mount_rule += "folder&&";
-				var sel_nameBox = Element("select_mailboxes");
-				for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}}
-				v_checked = true;
-			}
-			if(Element("radio2").checked){
-				mount_rule += "address&&";
-				if(Element("field5").value == ""){
-					alert(get_lang("Inform a forwarding e-mail!"));
-					return false;
-				}else{
-					var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
-			    	if(emailReg.test(Element("field5").value)){
-						mount_rule += Element("field5").value + "&&";
-					}else{
-						alert(get_lang("Inform a valid e-mail!"));
-						return false;
-					}
-				}
-				v_checked = true;
-			}
-			if(Element("radio3").checked){
-				mount_rule += "reject&&";
-				if(Element("field6").value == ""){
-					alert(get_lang("Inform a text for rejection!"));
-					return false;
-				}else{
-					mount_rule += Element("field6").value + "&&";
-				}
-				v_checked = true;
-			}				
-			if(Element("radio4").checked){
-				mount_rule += "discard&&&&";
-				v_checked = true;
-			}
-			if(!v_checked){
-				alert(get_lang("No option marked!"));
-				return false;
-			}
-			var opts = "";
-			if(Element("checkBox1").checked == true){opts += ",checkBox1";}
-			if(Element("checkBox2").checked == true){opts += ",checkBox2";}
-			if(Element("select_size").options[1].selected == true){opts += ",select_size=1";}
-			if(Element("select_rules").options[1].selected == true){opts += ",select_rules=1";}
-			for(var i=0; i < this.values.length; i++){if(this.values[i] == opts){mount_rule += i + "&&";}}
-			mount_rule += "&&&&";
-			if(LTrim(Element("field4").value) != ""){
-				mount_rule += LTrim(Element("field4").value);
-			}else{
-				mount_rule += 0;
-			}
-			if(form[0] == "new")
-			{
-				this.rulest[this.rulest.length] = mount_rule;
-			}
-			else
-				this.rulest[this.ind] = mount_rule;
-		}
-		else if(form[1] == "out")
-		{
-			mount_rule = "";
-			var fld_emails = this.email_ld; // Get first email of list!
-			var fld_men	   = Element("field8");
-			mount_rule = "#vacation&&";
-			mount_rule += "1&&";
-			mount_rule += "\"" + fld_emails + "\", ";			
-			mount_rule = mount_rule.substr(0,(mount_rule.length - 2));
-			mount_rule += "&&";
-			mount_rule += fld_men.value + "&&on";
-			if(LTrim(fld_men.value) == ""){
-				alert(get_lang("Inform a message!"));
-				return false;
-			}
-			this.out_officeR = mount_rule;
-		}
-		else if(form[1] == "voip")
-		{
-			if( Element("field9").value != "" && LTrim(Element("field9").value) != "" )
-			{
-				mount_rule = "#rule&&";
-				if(form[0] == "new")
-				{
-					n_rule = "1&&";
-					if( this.rulesVoip.length > 0 )
-					{
-						aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&");
-						n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&";
-					}
-					mount_rule += n_rule + "ENABLED&&";
-				}
-				else
-				{
-					n_rule = this.rulesVoip[this.ind].split("&&");
-					mount_rule += n_rule[1] + "&&";
-					mount_rule += n_rule[2] + "&&";
-				}
-
-				if ( Element("field9").value.indexOf("#") >= 0 )
-				{
-					alert(get_lang('Caracter "#" is not allowed!'));
-					return false;
-				}
-				
-				mount_rule = mount_rule + "&&&&" + Element("field9").value + "&&notify&&" + preferences.voip_email_redirect + "&&8&&&&&&0";
-
-				if( form[0] == "new" )
-				{
-					this.rulesVoip[this.rulesVoip.length] = mount_rule;
-				}
-				else
-				{
-					this.rulesVoip[this.ind] = mount_rule;
-				}
-			}
-			else
-			{
-				alert( 'CAMPOS EM BRANCO !!' );
-				return false;
-			}
-		}
-		
-		Element('form_buttons').style.display = '';
-		this.reload_rules();
-	}
-
-	cfilter.prototype.close_frm= function()
-	{
-		filters.filter_Sh['window_ffilter_ccform'].close();
-	}
-	
-	cfilter.prototype.saved_all = function()
-	{
-		var aux_rul = "";
-		var _this = this;
-		var cont = 0;
-		
-		// Regras Gerais
-		if(_this.rulest.length > 0)
-		{
-			for(var i=0; i < _this.rulest.length; i++)
-			{
-				var fieldsNormal = _this.rulest[i].split("&&");				
-				aux_rul += "_begin_##";
-				for(var j=0 ; j < fieldsNormal.length; j++)
-				{
-					aux_rul += url_encode(fieldsNormal[j]) + "##";
-					cont = parseInt(fieldsNormal[1]);					
-				}	
-				aux_rul += "_end_\n";
-			}
-		}
-	
-		// Voip
-		if(_this.rulesVoip.length > 0)
-		{
-			for(var i=0; i < _this.rulesVoip.length; i++)
-			{
-				var fieldsVoip = _this.rulesVoip[i].split("&&");
-				aux_rul += "_begin_##";
-				for(var j=0 ; j < fieldsVoip.length; j++)
-				{
-					if(j == 1)
-					{
-						if( cont == 0 )
-							cont = parseInt(1);
-						else
-							cont = parseInt(cont) + parseInt(2);
-						aux_rul += cont;
-						aux_rul += "##";
-					}
-					else
-						aux_rul += url_encode(fieldsVoip[j]) + "##";
-				}
-				aux_rul += "_end_\n";
-			}
-		}
-		
-		// Fora do Escritório
-		if(_this.out_officeR.length > 0)
-		{
-				var aux = _this.out_officeR.split("&&");				
-				aux_rul += "_begin_##";
-				for(var j=0 ; j < aux.length; j++)
-				{
-					aux_rul += url_encode(aux[j]) + "##";					
-				}	
-				aux_rul += "_end_\n";
-				_this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true;
-				//Save outoffice in prefs:
-				expresso.connector.loadScript("preferences");
-				prefe.save("outoffice", _this.out_officeF);
-		}
-		
-		var h_filter = function(data)
-		{
-			if(data != "Ok"){alert("Erro : \n" + data);}
-		}
-		var args   = "$this.ScriptS.rec_rules";
-		var params = "arfilter="+aux_rul;
-		cExecute(args,h_filter,params);
-	}
-
-// build object
-   var filter;
-   filter = new cfilter();
Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 2497)
+++ 	(revision )
@@ -1,3088 +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
-
-// 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 draw_tree_folders(folders){
-	// Check if the tree folders alredy exist.
-        translatedFolders = new Map();
-	if (Element('dftree_tree_folders')){
-		if (!expresso_offline) {
-			var update_tree_folders = function(data){
-				build_quota(data);
-				var unseen_in_mailbox = 0;
-				var unseen_in_shared_folders = 0;
-				for (var i=0; i<data.length; i++){
-					if ( data[i].folder_unseen > 0 )
-					{
-						unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
-						if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-							unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
-					}
-	
-					var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
-					
-					if ((folder_unseen) && (data[i].folder_unseen > 0))
-					{
-						folder_unseen.innerHTML = data[i].folder_unseen;
-					}
-					else if (data[i].folder_unseen > 0)
-					{
-						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
-						tree_folders.getNodeById(data[i].folder_id)._refresh();
-					}
-					else if (data[i].folder_unseen <= 0)
-					{
-						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name)});
-						tree_folders.getNodeById(data[i].folder_id)._refresh();
-					}
-
-					if(data[i].folder_id == current_folder){					
-						var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
-	//					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
-	//						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
-	//					}
-						Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
-						draw_paging(Element('tot_m').innerHTML);
-					}
-				}
-
-				var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
-				//if ( unseen_in_mailbox )
-				//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
-				//else
-					display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
-				display_unseen_in_mailbox._refresh();
-	
-				var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
-				if ( display_unseen_in_shared_folders )
-				{
-					if ( unseen_in_shared_folders )
-						display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
-					else
-						display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
-					display_unseen_in_shared_folders._refresh();
-				}
-			}
-			expresso.connector.cacheNextRequest(1);
-			cExecute ("expressoMail1_2.imap_functions.get_folders_list&folder=INBOX", update_tree_folders);
-		}
-	
-		return;
-	}
-	else{
-		if (!expresso_offline) {
-			tree_folders = new dFTree({name: 'tree_folders'});
-	
-			var n_root = new dNode({id:'root', caption: get_lang("My Folders")});
-			tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
-	
-			var unseen_in_mailbox = 0;
-			var unseen_in_shared_folders = 0;
-			for (var i=0; i<folders.length; i++){
-				if (folders[i].folder_unseen > 0)
-				{
-					unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
-					if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-						unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
-
-					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
-				
-					if( folders[i].folder_name.toLowerCase() == 'inbox' )
-						Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
-				}
-				else
-					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
-				
-				if (folders[i].folder_parent == '')
-					folders[i].folder_parent = 'root';
-				else if (folders[i].folder_parent == 'user'){	
-					
-					if (!tree_folders.getNodeById('user')){
-                                                tmpFolderId = folders[i].folder_id.split(cyrus_delimiter).pop();
-                                                if (tmpFolderId != folders[i].folder_name)
-                                                {
-                                                    translatedFolders.add(tmpFolderId, folders[i].folder_name);
-                                                }
-						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared folders"), plusSign:true}); 
-						tree_folders.add(n_root_shared_folders,'root');
-					}
-				}
-				tree_folders.add(nn,folders[i].folder_parent);
-			}
-		}
-		//tree_local_folders = new dFTree({name: 'tree_local_folders'});
-		/**
-		 * Pastas locais
-		 */
-		if (preferences.use_local_messages==1 || expresso_offline) {
-			if (!window.google || !google.gears) {
-				if (!expresso_local_messages.installGears())
-					preferences.use_local_messages=0;
-			}
-			else{
-				if (!window.google || !google.gears) {
-				temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
-				if (temp) {
-					location.href = "http://gears.google.com/?action=install&message="+
-					"Para utilizar o recurso de mensagens locais, instale o google gears&return=" +
-					document.location.href;
-				}
-				else {
-					preferences.use_local_messages=0;
-				}
-			}
-			else{
-				if (expresso_offline) 
-					tree_folders = new dFTree({
-						name: 'tree_folders'
-					});
-				var root_local = new dNode({
-					id: "local_root",
-					caption: get_lang('local folders')
-				});
-				tree_folders.add(root_local, "root"); //coloca root local
-				var local_folders = expresso_local_messages.list_local_folders();
-				for (var i in local_folders) { //Coloca as pastas locais.
-					var node_root = "local_root";
-					var new_caption = local_folders[i][0];
-					if (local_folders[i][0].indexOf("/") != "-1") {
-						final_pos = local_folders[i][0].lastIndexOf("/");
-						node_root = "local_" + local_folders[i][0].substr(0, final_pos);
-						new_caption = local_folders[i][0].substr(final_pos + 1);
-					}
-					if (local_folders[i][1] > 0) 
-						var nodeLocal = new dNode({
-							id: "local_" + local_folders[i][0],
-							caption: lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="local_unseen" style=color:red>' + local_folders[i][1] + '</span><font style=color:red>)</font>',
-							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-							plusSign: local_folders[i][2]
-						});
-					else 
-						var nodeLocal = new dNode({
-							id: "local_" + local_folders[i][0],
-							caption: lang_folder(new_caption),
-							onClick: "change_folder('local_" + local_folders[i][0] + "','" + new_caption + "')",
-							plusSign: local_folders[i][2]
-						});
-						tree_folders.add(nodeLocal, node_root);
-					}
-				}
-			}		
-		}
-
-		tree_folders.draw(Element('content_folders'));
-		if (!expresso_offline) {
-			n_root.changeState();
-			folder_select = (current_folder ? current_folder:"INBOX");
-			if (typeof(tree_folders.getNodeById(folder_select)) == 'undefined')
-				return false;
-			tree_folders.getNodeById(folder_select)._select();
-		}
-		else {
-			root_local.changeState();
-			tree_folders.getNodeById('local_Inbox')._select();
-		}
-
-		var trash_span=document.getElementById('lINBOX/'+trashfolder+'tree_folders');
-		var draft_span=document.getElementById('lINBOX/'+draftsfolder+'tree_folders');
-		var sent_span=document.getElementById('lINBOX/'+sentfolder+'tree_folders');
-		var spam_span=document.getElementById('lINBOX/'+spamfolder+'tree_folders');
-
-		if (trash_span)
-			trash_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_trash.png)";
-
-		if (draft_span)
-			draft_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_draft.png)"
-
-		if (sent_span)
-			sent_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_sent.png)";
-
-		if (spam_span)
-			spam_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_spam.png)";
-
-
-		draw_paging(Element('tot_m').innerHTML);
-		if(document.getElementById("nINBOX/"+trashfolder+"tree_folders"))
-		{
-			var trash = document.createElement("SPAN");
-			trash.id = 'empty_trash';
-			trash.className = 'clean_folder';
-			trash.style.cursor = 'pointer';
-			trash.onclick = function () {empty_trash_imap();};
-			trash.innerHTML = "["+get_lang("Clean")+"]";
-			trash.title=get_lang("Empty trash");
-			trash.onmouseover = function() {trash.style.color="red";};
-			trash.onmouseout= function() {trash.style.color="#666666";};
-			document.getElementById("nINBOX/"+trashfolder+"tree_folders").appendChild(trash);
-		}
-		if(document.getElementById("nINBOX/"+spamfolder+"tree_folders"))
-		{
-                        var spam = document.createElement("SPAN");
-                        spam.id = 'empty_spam';
-                        spam.className = 'clean_folder';
-                        spam.style.cursor = 'pointer';
-                        spam.style.padding = '0 0 0 6px';
-                        spam.onclick = function () {empty_spam_imap();};
-                        spam.innerHTML = "["+get_lang("Clean")+"]";
-                        spam.title=get_lang("Empty Spam Folder");
-                        spam.onmouseover = function() {spam.style.color="red";};
-                        spam.onmouseout= function() {spam.style.color="#666666";};
-                        document.getElementById("nINBOX/"+spamfolder+"tree_folders").appendChild(spam);
-               }
-
-		// Draw right menu folders.
-		/*
-		var treeroot = document.getElementById('chroottree_folders'); 
-		for (var linkBox = treeroot.firstChild; linkBox != null; linkBox = linkBox.nextSibling)
-			_dragArea.makeMenuBox(linkBox);
-		*/
-
-		if(!expresso_offline)
-			var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
-		else
-			var display_unseen_in_mailbox = tree_folders.getNodeById( 'local_root' );
-		//if ( unseen_in_mailbox )
-		//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
-		//else
-			display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
-		display_unseen_in_mailbox._refresh();
-
-		var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
-		if ( display_unseen_in_shared_folders )
-		{
-			if ( unseen_in_shared_folders )
-				display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
-			else
-				display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
-			display_unseen_in_shared_folders._refresh();
-		}
-	}
-
-	if (!expresso_offline) {
-		var folder_create = "";
-		var nm1 = "";
-		if(tree_folders._folderPr.length > 0){
-			var nm_folder = "";
-			for(var i=0; i < tree_folders._folderPr.length; i++){
-				nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
-				if(nm_folder[0] == "INBOX"){
-					if(nm1 == ""){
-						nm1 = nm_folder[1];
-						folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
-					}else{
-						if( nm1 != nm_folder[1]){
-							folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
-							nm1 = nm_folder[1];
-						}
-					}
-				}
-			}
-		}
-		if(folder_create != ""){
-			if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
-				var handler_correct_folders = function(data){
-					//Timeout to release HTTPRequest , loadScript and update tree folders.
-					if(data)
-						setTimeout("expresso.connector.loadScript('TreeShow');ttreeBox.update_folder();",500);
-				}
-				cExecute("expressoMail1_2.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
-			}
-		}
-	}
-}
-
-function draw_tree_local_folders() {
-	/**
-	 * Pastas locais
-	 */
-	if(preferences.use_local_messages==1 || expresso_offline) {
-		var local_folders = expresso_local_messages.list_local_folders();
-		var has_changes = false;
-		for (var i in local_folders) { //Coloca as pastas locais.
-			
-			var new_caption = local_folders[i][0];
-			if(local_folders[i][0].indexOf("/")!="-1") {
-				final_pos = local_folders[i][0].lastIndexOf("/");
-				new_caption = local_folders[i][0].substr(final_pos+1);
-			}
-			
-			var folder_unseen = Element('dftree_local_'+local_folders[i][0]+'_unseen');
-			
-			if ((folder_unseen) && (local_folders[i][1] > 0))
-			{
-				folder_unseen.innerHTML = local_folders[i][1];
-				has_changes = true;
-			}
-			else if (local_folders[i][1] > 0)
-			{
-				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption) + '<font style=color:red>&nbsp(</font><span id="dftree_local_'+local_folders[i][0]+'_unseen" style=color:red>'+local_folders[i][1]+'</span><font style=color:red>)</font>'});
-				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
-				has_changes = true;
-			}
-			else if (local_folders[i][1] <= 0)
-			{
-				tree_folders.getNodeById("local_"+local_folders[i][0]).alter({caption:lang_folder(new_caption)});
-				tree_folders.getNodeById("local_"+local_folders[i][0])._refresh();
-				has_changes = true;
-			}
-
-			if("local_"+local_folders[i][0] == get_current_folder()){					
-				var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
-				if(!isNaN(old_new_m) && old_new_m < local_folders[i][1]){
-					Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(local_folders[i][1])-old_new_m);
-				}
-				Element('new_m').innerHTML = local_folders[i][1] ? '<font color="RED">'+local_folders[i][1]+'</font>' : 0;
-				draw_paging(Element('tot_m').innerHTML);
-				has_changes = true;
-			}
-		}
-		if(has_changes)
-			tree_folders.getNodeById("local_root").open();
-
-	}	
-}
-
-function 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', '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(data, 'INBOX', true);
-	//alternate_border(0);
-}
-
-// Action on change folders.
-function change_folder(folder, folder_name){
-	if (openTab.imapBox[0] != folder)
-	{
-		current_folder = folder;
-		var handler_draw_box = function(data)
-		{
-			alternate_border(0);
-			Element("border_id_0").innerHTML = "&nbsp;" + lang_folder(folder_name) + '&nbsp;<font face="Verdana" size="1" color="#505050">[<span id="new_m">&nbsp;</span> / <span id="tot_m"></span>]</font>';
-			draw_box(data, folder, true);
-			draw_paging(data.num_msgs);
-			Element("tot_m").innerHTML = data.num_msgs;
-			update_menu();
-			return true;
-		}
-		proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort_box_type,search_box_type,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
-//		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
-	}
-	else
-		alternate_border(0);
-}
-
-function open_folder(folder, folder_name){
-	if (current_folder!= folder) {
-		current_folder = folder;
-		var handler_draw_box = function(data){
-			numBox++;
-			create_border(folder_name,numBox.toString());
-			draw_box(data, current_folder, false);
-			alternate_border(numBox);
-			return true;
-		}
-		cExecute ("expressoMail1_2.imap_functions.get_range_msgs2&folder="+current_folder+"&msg_range_begin=1&msg_range_end="+preferences.max_email_per_page+"&sort_box_type="+sort_box_type+ "&search_box_type="+ search_box_type +"&sort_box_reverse="+sort_box_reverse+"", handler_draw_box);
-	}
-	else
-		alternate_border(numBox);
-	return true;
-}
-
-var lastPage = 1;
-var numPages = 5;
-var last_folder = 'INBOX';
-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";
-		document.getElementById("div_menu_c3").appendChild(span_paging);	
-	}
-	span_paging.style.width="100%";		  	 		
-  	span_paging.innerHTML="";
-  	msg_range_begin = 1;
-	msg_range_end = preferences.max_email_per_page;
-  	if(current_page != 1) {
-	  	lnk_page = document.createElement("A");
-		lnk_page.setAttribute("href", "javascript:current_page=1;kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-  	}
-  	else {
-  	 	lnk_page = document.createElement("SPAN");
-  	}
-  	span_paging.appendChild(lnk_page);
-
-  	lnk_page.innerHTML = "&lt;&lt;";
-	lnk_page.title = get_lang("First");
-  	span_paging.innerHTML += "&nbsp;";
-  		
-  	if(current_page == lastPage + numPages)
-  		lastPage = current_page - 1;  		
-  	else if((lastPage != 1 && lastPage == current_page) || current_page == total_pages)  		
-  		lastPage = current_page - (numPages - 1);
-  	else if(current_page == 1)
-  	 	lastPage = 1;
-
-	if(lastPage < 1)
-		lastPage = 1;
-	else if(lastPage > 1 && (lastPage > (total_pages -(numPages - 1))))
-		lastPage = total_pages -(numPages - 1);
-
-	var	hasMarked = false;
-
-  	for(i = lastPage; i <= total_pages; i++) {
-  			
-  		if(current_page == i || (i == total_pages && !hasMarked)) {	  		
-  			lnk_page = document.createElement("SPAN");
-  			span_paging.appendChild(lnk_page);
-  			lnk_page.innerHTML = "&nbsp;<b>"+i+"</b>&nbsp;";
-  			hasMarked = true;
-  			continue;
-  		}
-  		else{	  		
-  			lnk_page = document.createElement("A");
-  			span_paging.appendChild(lnk_page);
-  			msg_range_begin = ((i*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
-			msg_range_end = (i*preferences.max_email_per_page);
-			lnk_page.setAttribute("href", "javascript:current_page="+i+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-  		}
-  		
-  		lnk_page.innerHTML = "&nbsp;...&nbsp;";
-  		
-  		if(i == (lastPage + numPages))
-  				break;	  		
-  		else if(lastPage == 1 || i != lastPage)	  			  			
-  			lnk_page.innerHTML = "&nbsp;"+i+"&nbsp;";
-  		
-  		span_paging.innerHTML += "&nbsp;";	  			  			  			  			  			  			  		
-  	}
-  	
- 	if(current_page != total_pages) {
-  		lnk_page = document.createElement("A");
-  		msg_range_begin = ((total_pages*preferences.max_email_per_page)-(preferences.max_email_per_page-1));
-		msg_range_end = (total_pages*preferences.max_email_per_page);  		
-		lnk_page.setAttribute("href", "javascript:current_page="+total_pages+";kill_current_box(); draw_paging("+num_msgs+"); proxy_mensagens.messages_list(get_current_folder(),"+msg_range_begin+","+msg_range_end+",'"+sort_box_type+"','"+search_box_type+"',"+sort_box_reverse+","+preferences.preview_msg_subject+","+preferences.preview_msg_tip+",function handler(data){draw_box(data, get_current_folder());});");
-	}
-	else {
-		lnk_page = document.createElement("SPAN");
-	}
-  	span_paging.innerHTML += "&nbsp;";
-  	span_paging.appendChild(lnk_page);
-
-	lnk_page.title = get_lang("Last");
-  	lnk_page.innerHTML = "&gt;&gt;";
-}
-
-
-// Draw the inbox and another folders
-function draw_box(headers_msgs, msg_folder, 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.imapBox[numBox] = msg_folder;
-	openTab.type[numBox] = 0;
-	
-	table_message_header_box = document.getElementById("table_message_header_box_"+numBox);
-	if (table_message_header_box == null){
-		var table_element = document.createElement("TABLE");
-		var tbody_element = document.createElement("TBODY");
-		table_element.setAttribute("id", "table_message_header_box_"+numBox);
-		table_element.className = "table_message_header_box";
-		
-		tr_element = document.createElement("TR");
-		tr_element.className = "message_header";
-		td_element1 = document.createElement("TD");
-		td_element1.setAttribute("width", "1%");
-		chk_box_element = document.createElement("INPUT");
-		chk_box_element.id  = "chk_box_select_all_messages";
-		chk_box_element.setAttribute("type", "checkbox");
-		chk_box_element.className = "checkbox";
-		chk_box_element.onclick = function(){select_all_messages(this.checked);};
-		chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
-		chk_box_element.onkeydown = function (e){
-			if (is_ie)
-			{
-				if ((window.event.keyCode) == 46)
-					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-			else
-			{
-				if ((e.keyCode) == 46)
-					proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		};
-		
-		td_element1.appendChild(chk_box_element);
-		
-		td_element2 = document.createElement("TD");
-		td_element2.setAttribute("width", "7%");
-		td_element3 = document.createElement("TD");
-		td_element3.setAttribute("width", "29%");
-		td_element3.onclick = function () {sort_box(search_box_type,'SORTFROM');};
-		td_element3.id = "message_header_SORTFROM_"+numBox;
-		td_element3.align = "left";
-		td_element3.innerHTML = get_lang("Who");
-		
-		td_element4 = document.createElement("TD");
-		td_element4.setAttribute("width", "38%");
-		td_element4.onclick = function () {sort_box(search_box_type,'SORTSUBJECT');};
-		td_element4.id = "message_header_SORTSUBJECT_"+numBox;
-		td_element4.align = "left";
-		td_element4.innerHTML = get_lang("Subject");
-	
-		td_element5 = document.createElement("TD");
-		td_element5.setAttribute("width", "14%");
-		td_element5.onclick = function () {sort_box(search_box_type,'SORTARRIVAL');};
-		td_element5.id = "message_header_SORTARRIVAL_"+numBox;
-		td_element5.align = "center";
-		td_element5.innerHTML = get_lang("Date");
-		td_element6 = document.createElement("TD");
-		td_element6.setAttribute("width", "14%");
-		td_element6.onclick = function () {sort_box(search_box_type,'SORTSIZE');}
-		td_element6.id = "message_header_SORTSIZE_"+numBox;
-		td_element6.align = "left";
-		td_element6.innerHTML = get_lang("Size");
-		
-		tr_element.appendChild(td_element1);
-		tr_element.appendChild(td_element2);		
-		var td_element21 = document.createElement("TD");
-		td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
-		var td_element22 = document.createElement("TD");
-		td_element22.innerHTML = "&nbsp;&nbsp;&nbsp;";
-		var td_element23 = document.createElement("TD");
-		td_element23.innerHTML = "&nbsp;&nbsp;";
-		tr_element.appendChild(td_element21);
-		tr_element.appendChild(td_element22);
-		tr_element.appendChild(td_element23);
-		tr_element.appendChild(td_element3);
-		tr_element.appendChild(td_element4);
-		tr_element.appendChild(td_element5);
-		tr_element.appendChild(td_element6);
-		tbody_element.appendChild(tr_element);
-		table_element.appendChild(tbody_element);
-		openTab.content_id[numBox].appendChild(table_element);
-	}
-	draw_header_box();
-	var table_element = document.createElement("TABLE");
-	var tbody_element = document.createElement("TBODY");	
-	table_element.id = "table_box";
-	table_element.className = "table_box";
-	table_element.borderColorDark = "#bbbbbb";
-	table_element.frame = "void";
-	table_element.rules = "rows";
-	table_element.cellPadding = "0";
-	table_element.cellSpacing = "0";
-	
-	table_element.onkeydown = function (e){
-		if (is_ie)
-		{
-			if ((window.event.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-		else
-		{
-			if ((e.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-	};
-	if (is_ie)
-		table_element.style.cursor = "hand";
-	
-	tbody_element.setAttribute("id", "tbody_box");
-	table_element.appendChild(tbody_element);
-	
-	var _divScroll = document.getElementById("divScrollMain_"+numBox);
-
-	var bar = document.getElementById("toolbar");
-	var offset = 0;
-
-	if(!_divScroll){		
-		_divScroll = document.createElement("DIV");
-		_divScroll.id = "divScrollMain_"+numBox;
-	}
-	
-	_divScroll.style.overflowY = "auto";								
-	_divScroll.style.overflowX = "hidden";
-	_divScroll.style.width	="100%";
-	
-	if (is_mozilla){
-		_divScroll.style.overflow = "-moz-scrollbars-vertical";
-		_divScroll.style.width	="99.3%";
-	}
-	// Inicio: Redimensiona DIV SCROLL
-	var bar = Element("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
-		offset = (bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight);		
-	var screenHeight = document.body.clientHeight ? document.body.clientHeight : document.body.offsetHeight;
-	var defaultHeight = screenHeight - offset;		
-	_divScroll.style.height 	= defaultHeight - 110;
-	Element('content_folders').style.height = defaultHeight - (is_ie ? 165 : 150);
-	// Fim: Redimensiona DIV SCROLL
-	_divScroll.appendChild(table_element);
-	openTab.content_id[numBox].appendChild(_divScroll);
-	
-	var f_unseen = 0;
-
-		if (headers_msgs.num_msgs == 0){
-			td_info = document.createElement("H3");
-			td_info.setAttribute("height", "25%");
-			td_info.setAttribute("background", "#FFF");
-			td_info.setAttribute("id", "msg_info");
-			td_info.align = "center";
-			td_info.innerHTML = get_lang("This mail box is empty");
-			tbody_element.appendChild(td_info);
-		}
-	
-	
-	for (var i=0; i < headers_msgs.length; i++){
-			if ((headers_msgs[i].Unseen == 'U') || (headers_msgs[i].Recent == 'N'))
-				f_unseen++;				
-			tr_element = this.make_tr_message(headers_msgs[i], msg_folder);
-			if (tr_element){
-				tbody_element.appendChild(tr_element);
-				add_className(tr_element, i%2 != 0 ? 'tr_msg_read2' : 'tr_msg_read');				
-			}
-			_dragArea.makeDragged(tr_element, headers_msgs[i].msg_number, headers_msgs[i].subject, true);
-	}
-	
-	if ((preferences.use_shortcuts == '1') && (headers_msgs[0]))
-		select_msg(headers_msgs[0].msg_number, 'null', true);
-
-	var tdFolders  =  Element("folderscol");
-	tdFolders.style.display = preferences.hide_folders == '1'  ? "none" : "";
-	if ( !currentTab )
-		alternate_border(numBox);
-	draw_footer_box(headers_msgs.num_msgs);	
-	Element('main_table').style.display = '';
-	if(debug) {
-		var _eTime = new Date();
-		_eTime = _eTime.getTime();
-		alert("Carregou em "+(_eTime - _bTime)+" ms");
-	}
-	var msg_folder = Element('msg_folder').value;
-	var msg_number = Element('msg_number').value;	
-	if(!msg_folder && msg_number) {
-		new_message('new','null');
-	}
-	else if(msg_folder && msg_number){
-		expresso.connector.cacheNextRequest();
-		cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+ msg_number + "&msg_folder=" + url_encode(msg_folder), show_msg);
-		Element('msg_folder').value = '';
-		Element('msg_number').value = '';
-	}
-
-	if(!is_ie) {
-		var scripts = new Array("ccQuickAdd",
-							"color_palette",
-							"filter",
-							"filters",
-							"html2xhtml",
-							"preferences",
-							"QuickCatalogSearch",
-							"QuickSearchUser",
-							"rich_text_editor",
-							"sharemailbox",
-							"search",
-							"TreeS",
-							"TreeShow");
-							
-		expresso.connector.loadAllScripts(scripts);
-	}
-	// Loading Quota View Folder Component (if exists...)
-	if(Element("table_quota"))
-		expresso.connector.loadScript("InfoQuota");	
-}
-
-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 = document.createElement("TD");
-		td_element1.className = "td_msg";
-		td_element1.setAttribute("width", "1%");
-		chk_box_element = document.createElement("INPUT");
-		chk_box_element.setAttribute("type", "checkbox");
-		chk_box_element.className = "checkbox";
-		chk_box_element.setAttribute("id", "check_box_message_"+headers_msgs.msg_number);
-		chk_box_element.onclick = function(e){
-			if (is_ie)
-				changeBgColor(window.event,headers_msgs.msg_number);
-			else
-				changeBgColor(e,headers_msgs.msg_number);
-		};
-		td_element1.appendChild(chk_box_element);
-		
-		td_element2 = document.createElement("TD");
-		td_element2.className = "td_msg";
-		td_element2.setAttribute("width", "2%");
-		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0)
-			td_element2.innerHTML = "<img src ='templates/"+template+"/images/clip.gif' title='" + url_decode(headers_msgs.attachment.names) + "'>";			
-			
-		td_element21 = document.createElement("TD");
-		td_element21.className = "td_msg";
-		td_element21.setAttribute("width", "1%");
-		td_element21.id = "td_message_answered_"+headers_msgs.msg_number;
-
-		if (headers_msgs.attachment && headers_msgs.attachment.number_attachments > 0) {
-			attach_name = headers_msgs.attachment.names.split(", ");
-			for(var item in attach_name)
-			{
-				if (url_decode(attach_name[item]) != 'smime.p7s' && url_decode(attach_name[item]) != 'smime.p7m'){
-					td_element21.innerHTML = "<img src ='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 ='templates/"+template+"/images/forwarded.gif' title='"+get_lang('Forwarded')+"'>";
-			headers_msgs.Draft = '' 
-			headers_msgs.Answered = '';
-			headers_msgs.Forwarded = 'F';
-		}
-		else if (headers_msgs.Draft == 'X')
-			td_element21.innerHTML = "<img src ='templates/"+template+"/images/draft.gif' title='"+get_lang('Draft')+"'>";
-		else if (headers_msgs.Answered == 'A')
-			td_element21.innerHTML = "<img src ='templates/"+template+"/images/answered.gif' title='"+get_lang('Answered')+"'>";
-		else
-			td_element21.innerHTML = "&nbsp;&nbsp;&nbsp;";
-
-		td_element22 = document.createElement("TD");
-		td_element22.className = "td_msg";
-		td_element22.setAttribute("width", "1%");
-		td_element22.id = "td_message_signed_"+headers_msgs.msg_number;
-
-        //td_element23 = document.createElement("TD");
-		//td_element23.setAttribute("width", "1%");
-		//td_element23.id = "td_message_signed_"+headers_msgs.msg_number;
-        switch(headers_msgs.ContentType)
-		{
-            case "signature":
-			{
-				td_element22.innerHTML = "<img src ='templates/"+template+"/images/signed_msg.gif' title='" + get_lang('Signed message') + "'>";
-				break;
-			}
-            case "cipher":
-			{
-				td_element22.innerHTML = "<img src ='templates/"+template+"/images/lock.gif' title='" + get_lang('Crypted message') + "'>";
-				break;
-			}
-            default:
-			{
-				break;
-			}
-		}
-
-        td_element23 = document.createElement("TD");
-		td_element23.className = "td_msg"
-		td_element23.setAttribute("width", "1%");
-		td_element23.id = "td_message_important_"+headers_msgs.msg_number;
-
-		if (headers_msgs.Flagged == 'F' || (headers_msgs.Importance.toLowerCase().indexOf("high") != -1 && parseInt(preferences.use_important_flag)))
-		{
-			td_element23.innerHTML = "<img src ='templates/"+template+"/images/important.gif' title='"+get_lang('Important')+"'>";
-		}
-		else
-			td_element23.innerHTML = "&nbsp;&nbsp;&nbsp;";
-
-		td_element24 = document.createElement("TD");
-		td_element24.className = "td_msg";
-		td_element24.setAttribute("width", "1%");
-		td_element24.id = "td_message_sent_"+headers_msgs.msg_number;
-		td_element24.innerHTML = "&nbsp;&nbsp;&nbsp;";
-		// preload image
-		var _img_sent = new Image();
-		_img_sent.src 	 = "templates/"+template+"/images/sent.gif";
-
-		td_element3 = document.createElement("TD");
-		td_element3.className = "td_msg";
-		td_element3.id = "td_who_"+ headers_msgs.msg_number;
-		td_element3.setAttribute("width", "20%");
-		var _onclick = function(){InfoContact.hide();proxy_mensagens.get_msg(headers_msgs.msg_number, msg_folder,true, show_msg);};
-		td_element3.onclick = _onclick;
-		td_element3.innerHTML = '&nbsp;';
-		
-		if (typeof(headers_msgs.from) == 'undefined')
-			return false;
-		if(headers_msgs.from.email.toLowerCase() == Element("user_email").value)
-		{ 
-			td_element3.onmouseover = function () {this.title=headers_msgs.to.email;};
-			if (headers_msgs.Draft == 'X')
-				td_element3.innerHTML += "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
-			else{				
-				if(headers_msgs.to.email != null && headers_msgs.to.email.toLowerCase() != Element("user_email").value)
-					td_element24.innerHTML = "<img valign='center' src ='templates/"+template+"/images/sent.gif' title='"+get_lang('Sent')+"'>";
-			
-				if ((headers_msgs.to)&&(headers_msgs.to.name != null))
-					td_element3.innerHTML += headers_msgs.to.name;
-				else if (headers_msgs.to){
-					td_element3.innerHTML += headers_msgs.to.email;
-				}
-			}
-		}
-		else{
-			if (headers_msgs.Draft == 'X'){
-				td_element3.innerHTML = "<span style=\"color:red\">("+get_lang("Draft")+") </span>";
-			}
-			else{				
-				var spanSender = document.createElement("SPAN");
-				spanSender.onmouseover = function (event) {this.style.textDecoration = "underline";try {InfoContact.begin(this,headers_msgs.from.email)} catch(e){};};
-				spanSender.onmouseout = function (){ try {this.style.textDecoration = "none"; clearTimeout(InfoContact.timeout);} catch(e){}};
-				spanSender.innerHTML =  headers_msgs.from.name != null ? headers_msgs.from.name : headers_msgs.from.email;
-				if (spanSender.innerHTML.indexOf(" ") == '-1' && spanSender.innerHTML.length > 25){
-					spanSender.innerHTML = spanSender.innerHTML.substring(0,25) + "...";
-				}
-				else if (spanSender.innerHTML.length > 40 ){
-					spanSender.innerHTML = spanSender.innerHTML.substring(0,40) + "...";
-				}				
-				td_element3.appendChild(spanSender);				
-			}
-		}			
-		td_element4 = document.createElement("TD");
-		td_element4.className = "td_msg";
-		td_element4.setAttribute("width", "50%");
-		td_element4.onclick = _onclick;
-//		td_element4.setAttribute("style","white-space:nowrap;");
-		td_element4.innerHTML = !is_ie ? "<a nowrap id='a_message_"+tr_element.id+"'>&nbsp;" : "&nbsp;";
-		
-		if ((headers_msgs.subject)&&(headers_msgs.subject.length > 50))
-		{
-//			if( (headers_msgs.subject.length+tr_element.msg_sample.length)>
-			td_element4.innerHTML += headers_msgs.subject.substring(0,50) + "..." + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample +"</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
-		}
-		else
-		{
-			td_element4.innerHTML += headers_msgs.subject + "<span style=\"color:#b3b3b3;\">  " + tr_element.msg_sample + "</span>";//modificacao feita para exibir o trecho do body ao lado do assunto da mensagem;
-		}
-					
-		td_element4.title=tr_element.tip;
-		if(!is_ie){
-			td_element4.innerHTML += "</a>";
-		}
-		
-
-		td_element5 = document.createElement("TD");
-		td_element5.className = "td_msg";
-		td_element5.setAttribute("width", "14%");
-		td_element5.onclick = _onclick;
-		td_element5.setAttribute("align", "center");
-		td_element5.innerHTML = headers_msgs.udate;
-
-		td_element6 = document.createElement("TD");
-		td_element6.className = "td_msg";
-		td_element6.setAttribute("width", "14%");
-		td_element6.onclick = _onclick;
-		td_element6.setAttribute("noWrap","true");
-		td_element6.setAttribute("align", "center");
-
-		td_element6.innerHTML = borkb(headers_msgs.Size);
-
-		tr_element.appendChild(td_element1);
-		tr_element.appendChild(td_element2);
-		tr_element.appendChild(td_element21);
-		tr_element.appendChild(td_element22);
-		tr_element.appendChild(td_element23);
-        tr_element.appendChild(td_element24);
-		tr_element.appendChild(td_element3);
-		tr_element.appendChild(td_element4);
-		tr_element.appendChild(td_element5);
-		tr_element.appendChild(td_element6);
-		return tr_element;
-}
-
-function sort_box(search, sort){
-	var message_header = Element("message_header_"+search);
-	var handler_draw_box = function(data){
-		draw_box(data, current_folder,true);
-		draw_paging(Element('tot_m').innerHTML);
-		//Mostrar as msgs nao lidas de acordo com o filtro de relevancia
-                var msgs_unseen = 0;
-                for(i in data){
-	                if(data[i].Unseen == 'U')
-		                msgs_unseen++;
-	}
-		Element("new_m").innerHTML = '<font style="color:'+(msgs_unseen == 0 ? '': 'red')+'">' + msgs_unseen + '</font>';
-	}
-
-	if(sort_box_type == sort && search_box_type == search){
-		sort_box_reverse = sort_box_reverse ? 0 : 1;
-	}
-	else if(sort_box_type != sort){
-		if ( (sort == 'SORTFROM') || (sort == 'SORTSUBJECT') )
-			sort_box_reverse = 0;
-		else
-			sort_box_reverse = 1;
-	}
-		
-	// Global variable.
-	sort_box_type = sort;
-	search_box_type = search;
-
-	proxy_mensagens.messages_list(current_folder,1,preferences.max_email_per_page,sort,search,sort_box_reverse,preferences.preview_msg_subject,preferences.preview_msg_tip,handler_draw_box);
-	current_page = 1;
-	//Comentado para nao sobrepor o numero de msgs nao lidas ao utilizar os filtros
-	//update_menu();
-}
-function 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("message_header_SORTFROM_"+numBox).innerHTML 	= get_lang("Who");
-	document.getElementById("message_header_SORTSUBJECT_"+numBox).innerHTML = get_lang("Subject");
-	document.getElementById("message_header_SORTARRIVAL_"+numBox).innerHTML = get_lang("Date");
-	document.getElementById("message_header_SORTSIZE_"+numBox).innerHTML	= get_lang("Size");	
-	document.getElementById("message_header_"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox ).innerHTML = "<B>"+type_name+"</B><img src ='templates/"+template+"/images/arrow_"+(sort_box_reverse == 1 ? 'desc' : 'asc')+"endant.gif'>";
-}
-function draw_message(info_msg, ID){
-	var content = document.getElementById('content_id_' + ID);
-	var defaultWidth = document.body.offsetWidth - 37;
-	
-	var menuHidden = Element("folderscol").style.display == 'none' ? true : false;
-	if(!menuHidden)
-		defaultWidth -= Element("folderscol").offsetWidth;
-	 //////////////////////////////////////////////////////////////////////////////////////////////////////
-	//Make the next/previous buttom.
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var next_previous_msg_td = document.createElement("TD");
-	next_previous_msg_td.setAttribute("noWrap","true");
-	next_previous_msg_td.align = "right";
-	next_previous_msg_td.width = "40px";
-	var img_next_msg = document.createElement("IMG");
-	img_next_msg.id = 'msg_opt_next_' + ID;
-	img_next_msg.src = './templates/'+template+'/images/down.button.png';
-	img_next_msg.title = get_lang('Next');
-	img_next_msg.style.cursor = 'pointer';
-
-	// Old
-	//img_next_msg.onclick = function () {cExecute ("expressoMail1_2.imap_functions.get_info_next_msg&msg_number="+ info_msg.msg_number + "&msg_folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type +  "&search_box_type="+ search_box_type +"&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)};
-    var folder_id = 0;
-    folder_id = info_msg.original_ID ? info_msg.original_ID: info_msg.msg_number;
-	var folder = document.getElementById(folder_id);
-	if (!folder){
-		delete_border(ID);
-		return;
-		}
-    if (folder){ // mensagem local criptografada nao tem ID da pasta local
-        if (folder.nextSibling){
-            var nextMsgBox = folder.nextSibling.name?folder.nextSibling.name:info_msg.msg_folder;
-
-            if (nextMsgBox == "INBOX/decifradas")// teste para ver se a mensagem vem da pasta oculta decifradas
-                    nextMsgBox = get_current_folder();
-
-            img_next_msg.onclick = function()
-            {
-                currentTab = ID;
-                openTab.type[ID] = 2;
-                            proxy_mensagens.get_msg(folder.nextSibling.id,nextMsgBox,true,show_msg);
-                //cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+folder.nextSibling.id+"&msg_folder="+nextMsgBox, show_msg);
-            };
-        }
-        else
-        {
-            img_next_msg.src = "./templates/"+template+"/images/down.gray.button.png";
-            img_next_msg.style.cursor = 'default';
-
-        }
-    }
-    else
-    {
-        img_next_msg.src = "./templates/"+template+"/images/down.gray.button.png";
-		img_next_msg.style.cursor = 'default';
-		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
-		{
-            img_next_msg.onclick = function()
-                {
-                    /*current_page++;
-                    msg_range_end = (current_page*preferences.max_email_per_page);
-                    msg_range_begin = (msg_range_end-(preferences.max_email_per_page)+1);
-                    kill_current_box();
-                    cExecute ('expressoMail1_2.imap_functions.get_range_msgs2&folder='+current_folder+'&msg_range_begin='+msg_range_begin+'&msg_range_end='+msg_range_end+'&sort_box_reverse=1', function handler(data){draw_box(data, current_folder);}) */
-                        delete_border(ID);
-                };
-        }
-    }
-	var img_space = document.createElement("SPAN");
-	img_space.innerHTML = "&nbsp;";
-	var img_previous_msg = document.createElement("IMG");
-	img_previous_msg.id = 'msg_opt_previous_' + ID;
-	img_previous_msg.src = './templates/'+template+'/images/up.button.png';
-	img_previous_msg.title = get_lang('Previous');
-	img_previous_msg.style.cursor = 'pointer';
-
-	//Old
-	//img_previous_msg.onclick = function () {cExecute ("expressoMail1_2.imap_functions.get_info_previous_msg&msgs_number="+ info_msg.msg_number + "&folder="+ info_msg.msg_folder + "&sort_box_type="+ sort_box_type+ "&search_box_type="+ search_box_type + "&sort_box_reverse="+ sort_box_reverse +"&reuse_border="+ID, show_msg)}
-	//folder = document.getElementById(ID.substr(0, ID.indexOf('_')));
-	if (!folder){
-	        delete_border(ID);
-		return;
-		}
-    if (folder){ // mensagem local criptografada nao tem ID da pasta local
-        if (folder.previousSibling)
-        {
-            var previousMsgBox = folder.previousSibling.name?folder.previousSibling.name:info_msg.msg_folder;
-
-            if (previousMsgBox == "INBOX/decifradas") // teste para ver se a mensagem vem da pasta oculta decifradas
-                    previousMsgBox = get_current_folder();
-
-            img_previous_msg.onclick = function()
-            {
-                currentTab = ID;
-                openTab.type[ID] = 2;
-                //cExecute("expressoMail1_2.imap_functions.get_info_msg&msg_number="+folder.previousSibling.id+"&msg_folder=" + previousMsgBox, show_msg);
-                            proxy_mensagens.get_msg(folder.previousSibling.id,previousMsgBox,true,show_msg);
-            };
-        }
-        else
-        {
-            img_previous_msg.src = "./templates/"+template+"/images/up.gray.button.png";
-            img_previous_msg.style.cursor = 'default';
-        }
-	}
-	else
-	{
-		img_previous_msg.src = "./templates/"+template+"/images/up.gray.button.png";
-		img_previous_msg.style.cursor = 'default';
-		if (!proxy_mensagens.is_local_folder(get_current_folder()) && !(info_msg.msg_folder == "INBOX/decifradas")) // testa se a mensagem e local
-        {
-            img_previous_msg.onclick = function()
-            {
-                delete_border(ID);
-            };
-        }
-    }
-	next_previous_msg_td.appendChild(img_previous_msg);
-	next_previous_msg_td.appendChild(img_space);
-	next_previous_msg_td.appendChild(img_next_msg);
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	//Make the header message.
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var table_message = document.createElement("TABLE");
-	var tbody_message = document.createElement("TBODY");
-	table_message.border = "0";
-	table_message.width = defaultWidth ;
-
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	//Make the options message.
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr0 = document.createElement("TR");
-	tr0.className = "tr_message_header";
-	var td0 = document.createElement("TD");
-	var table_message_options = document.createElement("TABLE");
-	table_message_options.width = "100%";
-	table_message_options.border = '0';
-	table_message_options.className = 'table_message';
-	var tbody_message_options = document.createElement("TBODY");
-	var tr = document.createElement("TR");
-	var td = document.createElement("TD");
-	td.setAttribute("noWrap","true");
-	var _name = '';
-	var _maxChar = menuHidden ? 40 : 15;
-	
-	if (info_msg.from.name)
-	{
-		var spanName = document.createElement("SPAN");
-			spanName.innerHTML = info_msg.from.name;
-		_name = spanName.innerHTML.length > _maxChar ? spanName.innerHTML.substring(0,_maxChar) + "..." : spanName.innerHTML;
-	}
-	else
-		_name = info_msg.from.email.length > _maxChar ? info_msg.from.email.substring(0,_maxChar) + "..." : info_msg.from.email;
-
-	td.innerHTML = _name.bold() + ', ' + info_msg.smalldate;
-	if (info_msg.attachments.length > 0)
-		td.innerHTML += "&nbsp<img style='cursor:pointer' onclick='javascript:Element(\"option_hide_more_"+ID+"\").onclick()' src ='templates/"+template+"/images/clip.gif' title='"+info_msg.attachments.names+"'>";
-	
-	if (typeof(info_msg.signature) == 'string')
-	{	
-		if (info_msg.signature != "void")
-			td.innerHTML += '&nbsp;<img style="cursor:pointer" onclick="alert(\''+ get_lang("This message is signed, and you can trust.") + info_msg.signature +'\');" src="templates/'+template+'/images/signed.gif">';
-		else
-			td.innerHTML += "&nbsp;<img style='cursor:pointer' onclick='alert(\""+get_lang("This message is signed, but it is invalid. You should not trust on it.")+"\");' title='"+get_lang("Voided message")+"' src='templates/"+template+"/images/invalid.gif'>";
-	}
-	
-	if (info_msg.DispositionNotificationTo)
-	{
-		td.innerHTML += '&nbsp;<img style="cursor:pointer" alt="'+ get_lang('Message with read notification') + '" title="'+ get_lang('Message with read notification') + '" src="templates/'+template+'/images/notification.gif">';
-	}
-	
-	// NORMAL MSG
-	if(info_msg.Draft != 'X')
-	{
-	var options = document.createElement("TD");
-	options.width = "30%";
-	options.setAttribute("noWrap","true");
-	var option_hide_more = document.createElement("SPAN");
-	option_hide_more.className = 'message_options';
-	options.align = 'right';
-	option_hide_more.value = 'more_options';
-	option_hide_more.id = 'option_hide_more_'+ID;
-	option_hide_more.onclick = function(){
-		var _height = Element("div_message_scroll_"+ID).style.height;
-		_height = parseInt(_height.replace("px",""));
-		var _offset = 35;
-		if (this.value == 'more_options'){
-			this.innerHTML = "<b><u>"+get_lang('Options')+"</u></b>";
-			this.value = 'hide_options';
-			Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
-			Element('table_message_others_options_'+ID).style.display = '';
-			Element('tr_other_options_'+ID).style.display = '';
-			
-		}
-		else{
-			this.innerHTML = get_lang('Options');
-			this.value = 'more_options';
-			Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
-			Element('table_message_others_options_'+ID).style.display = 'none';
-			Element('tr_other_options_'+ID).style.display = 'none';			
-		}
-	};
-	var option_mark = document.createElement('TD');
-	option_mark.align = "left";
-	option_mark.width = "50%";
-
-	var option_mark_as_unseen = '<span class="message_options" onclick="\
-		changeLinkState(this,\'seen\');\
-		set_messages_flag(\'unseen\','+folder_id+');\
-		write_msg(\''+get_lang('Message marked as ')+get_lang("Unseen")+
-	'.\');">'+get_lang("Unseen")+'</span>, ';
-
-	if (info_msg.Flagged == "F")
-		var option_mark_important = '<span class="message_options" onclick="\
-			changeLinkState(this,\'important\');\
-			set_messages_flag(\'unflagged\','+folder_id+');\
-			write_msg(\''+get_lang('Message marked as ')+get_lang("Normal")+
-			'.\');">'+get_lang("Normal")+'</span>';
-	else
-		var option_mark_important = '<span class="message_options" onclick="\
-			changeLinkState(this,\'normal\');\
-			set_messages_flag(\'flagged\','+folder_id+');\
-			write_msg(\''+get_lang('Message marked as ')+get_lang("Important")+
-			'.\');">'+get_lang("Important")+'</span>';
-	option_mark.innerHTML = option_mark_as_unseen+option_mark_important;
-	option_hide_more.innerHTML = get_lang('Options');
-	options.appendChild(option_hide_more);
-	
-	var space0 = document.createElement("SPAN");
-	space0.innerHTML = '&nbsp;|&nbsp;';
-	var space1 = document.createElement("SPAN");
-	space1.innerHTML = '&nbsp;|&nbsp;';
-	var space2 = document.createElement("SPAN");
-	space2.innerHTML = '&nbsp;|&nbsp;';
-	var space3 = document.createElement("SPAN");
-	space3.innerHTML = '&nbsp;|&nbsp;';
-	var space4 = document.createElement("SPAN");
-	space4.innerHTML = '&nbsp;|&nbsp;';
-
-	var option_forward = document.createElement("SPAN");
-	option_forward.id = 'msg_opt_forward_'+ID;
-	option_forward.className = 'message_options';
-	option_forward.onclick = function(){new_message('forward', ID);};
-	option_forward.innerHTML = get_lang('Forward');
-	options.appendChild(space1);
-	options.appendChild(option_forward);
-	var option_reply = document.createElement("SPAN");
-	option_reply.id = 'msg_opt_reply_'+ID;
-	option_reply.className = 'message_options';
-	option_reply.onclick = function(){new_message('reply_with_history', ID);};
-	option_reply.innerHTML = get_lang('Reply');
-	options.appendChild(space2);
-	options.appendChild(option_reply);
-	var option_delete = document.createElement("SPAN");
-	option_delete.id = 'msg_opt_delete_'+ID;
-	option_delete.className = 'message_options';
-	option_delete.onclick = function(){proxy_mensagens.delete_msgs(info_msg.msg_folder, info_msg.msg_number, ID);};
-	option_delete.innerHTML = get_lang('Delete');
-	options.appendChild(space3);
-	options.appendChild(option_delete);
-	
-	tr.appendChild(td);
-	tr.appendChild(option_mark);
-	tr.appendChild(options);
-	tr.appendChild(next_previous_msg_td);
-	tbody_message_options.appendChild(tr);
-	
-	////////// OTHER OPTIONS ////////////////////
-	var tr_other_options = document.createElement("TR");
-	tr_other_options.id = 'tr_other_options_' + ID;
-	tr_other_options.style.display = 'none';
-	
-	var td_other_options = document.createElement("TD");
-	td_other_options.colSpan = '3';
-	//td_other_options.align = 'right';
-	//td_other_options.setAttribute("noWrap","true");
-	var div_other_options = document.createElement("DIV");
-
-	var option_mark_as						= '<span>'+get_lang("Mark as")+'</span>: ';
-	var option_mark_as_unseen				= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'unseen\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Unseen")+'.\');">'+get_lang("Unseen")+'</span>, ';
-	var option_mark_as_important			= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'flagged\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Important")+'.\');">'+get_lang("Important")+'</span>, ';
-	var option_mark_as_normal				= '<span class="message_options" onclick="proxy_mensagens.proxy_set_messages_flag(\'unflagged\','+info_msg.msg_number+');write_msg(\''+get_lang('Message marked as ')+get_lang("Normal")+'.\');">'+get_lang("Normal")+'</span> | ';
-	
-	var option_move							= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","move_to");>'+get_lang("Move")+'</span> | ';
-	var option_reply_to_all					= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_to_all_with_history","'+ID+'");>'+get_lang("Reply to all")+'</span> | ';
-	var option_reply_without_history		= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_without_history","'+ID+'");>'+get_lang("Reply without history")+'</span> | ';
-	var option_reply_to_all_without_history	= '<span onmouseover="this.className=\'message_options_active\'" onmouseout="this.className=\'message_options\'" class="message_options" onclick=new_message("reply_to_all_without_history","'+ID+'");>'+get_lang("Reply to all without history")+'</span> |';
-	var option_source_msg = '<span class="message_options" onclick=proxy_mensagens.proxy_source_msg("'+ID+'","'+url_encode(info_msg.msg_folder)+'");>'+get_lang("Message Font")+'</span> </div>';		
-
-	div_other_options.innerHTML = option_reply_to_all + option_reply_without_history + option_reply_to_all_without_history + option_source_msg;
-	if (use_spam_filter) {
-		if(info_msg.msg_folder == 'INBOX'+cyrus_delimiter+'Spam')
-			div_other_options.innerHTML += ' | <span class="message_options" onclick="nospam('+info_msg.msg_number+',\'null\', \''+info_msg.msg_folder+'\')";>'+get_lang("Not Spam")+'</span>';	
-		else
-			div_other_options.innerHTML += ' | <span class="message_options" onclick="spam(\''+info_msg.msg_folder+'\', '+info_msg.msg_number+',\'null\')";>'+get_lang("Mark as Spam")+'</span>';	
-	}
-		
-	td_other_options.appendChild(div_other_options);
-	//td_other_options.innerHTML = option_print + option_reply_to_all + option_source_msg;
-	
-	tr_other_options.appendChild(td_other_options);
-	tbody_message_options.appendChild(tr_other_options);
-	////////// END OTHER OPTIONS ////////////////
-
-    	////////// BEGIN SIGNATURE //////////////////
-	if (info_msg.signature && info_msg.signature.length > 0)
-	{
-		var tr_signature = document.createElement("TR");
-		var td_signature = document.createElement("TD");
-		td_signature.className = 'tr_message_header';
-		tr_signature.id = 'tr_signature_'+ID;
-		td_signature.colSpan = "5";
-		tr_signature.style.display = 'none';
-
-		for (i in info_msg.signature)
-			td_signature.innerHTML += '<span>'+info_msg.signature[i]+'</span> <br /> ';
-		var signature_status_pos = info_msg.signature[0].indexOf(get_lang('Message untouched'));
-		td_signature.id = "td_signature_"+ID;
-		if(signature_status_pos < 0 )
-		{
-		td.innerHTML += '&nbsp;<img style="cursor:pointer" src="templates/'+template+'/images/signed_error.gif" title="'+get_lang("Details")+'">';
-		tr_signature.style.display = '';
-		}
-		else
-		{
-		td.innerHTML += '&nbsp;<img style="cursor:pointer" src="templates/'+template+'/images/signed_table.gif" title="'+get_lang("Details")+'">';
-		}
-		td.onclick = function(){
-		var _height = Element("div_message_scroll_"+ID).style.height;
-		_height = parseInt(_height.replace("px",""));
-		var _offset = 130;
-		if (this.value == 'more_cert'){
-			//this.innerHTML += "<b><u>Mais Informaï¿œï¿œes</u></b>";
-			this.value = 'hide_cert';
-			Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
-			Element('tr_signature_'+ID).style.display = 'none';
-			Element('td_signature_'+ID).style.display = 'none';
-
-		}
-		else{
-			//this.innerHTML += "Mais Informaï¿œï¿œes";
-			this.value = 'more_cert';
-			Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
-			Element('tr_signature_'+ID).style.display = '';
-			Element('td_signature_'+ID).style.display = '';
-		}
-	};
-
-		tr_signature.appendChild(td_signature);
-		tbody_message_options.appendChild(tr_signature);
-	/******************************************* Old signature   ***********************************************/
-		//if (info_msg.signature != "void")
-		//	td.innerHTML += '&nbsp;<img style="cursor:pointer" onclick="alert(\''+ get_lang("This message is signed, and you can trust.") + info_msg.signature +'\');" src="'+tpl_img_path+'/signed.gif">';
-		//else
-		//	td.innerHTML += "&nbsp;<img style='cursor:pointer' onclick='alert(\""+get_lang("This message is signed, but it is invalid. You should not trust on it.")+"\");' title='"+get_lang("Voided message")+"' src='"+tpl_img_path+"/invalid.gif'>";
-	/*****************************************															********/
-	}
-	//////////// END SIGNATURE ////////////////
-
-	table_message_options.appendChild(tbody_message_options);
-	td0.appendChild(table_message_options);
-	tr0.appendChild(td0);
-	tbody_message.appendChild(tr0);
-	}
-	// IF DRAFT
-	else
-	{
-		var options = document.createElement("TD");
-		options.width = "1%";
-		options.setAttribute("noWrap","true");
-		var option_edit	  = '<span class="message_options" onclick="new_message(\'edit\',\''+ID+'\');">'+get_lang('Edit')+'</span> | ';
-		var option_print = '<span class="message_options" onclick="print_msg(\''+info_msg.msg_folder+'\',\''+info_msg.msg_number+'\',\''+ID+'\');">'+get_lang('Print')+'</span> | ';
-		var option_delete = '<span class="message_options" onclick="proxy_mensagens.delete_msgs(\''+info_msg.msg_folder+'\',\''+info_msg.msg_number+'\',\''+ID+'\');">'+get_lang('Delete')+'</span> | ';		
-		var option_hide_more = document.createElement("SPAN");
-		option_hide_more.className = 'message_options';
-		options.align = 'right';
-		option_hide_more.value = 'more_options';
-		option_hide_more.id = 'option_hide_more_'+ID;
-		option_hide_more.innerHTML = get_lang('Options');
-		option_hide_more.onclick = function(){
-			var _height = Element("div_message_scroll_"+ID).style.height;
-			_height = parseInt(_height.replace("px",""));
-			var _offset = 35;
-			if (this.value == 'more_options'){
-				this.innerHTML = "<b><u>"+get_lang('Options')+"</u></b>";
-				this.value = 'hide_options';
-				Element("div_message_scroll_"+ID).style.height = (_height - _offset)+"px";
-				Element('table_message_others_options_'+ID).style.display = '';
-			}
-			else{
-				this.innerHTML = get_lang('Options');
-				this.value = 'more_options';
-				Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
-				Element('table_message_others_options_'+ID).style.display = 'none';
-			}
-		};
-		options.innerHTML = option_edit + option_print + option_delete;
-		options.appendChild(option_hide_more);
-		tr.appendChild(td);
-		tr.appendChild(options);
-		tr.appendChild(next_previous_msg_td);
-		tbody_message_options.appendChild(tr);
-		table_message_options.appendChild(tbody_message_options);
-		td0.appendChild(table_message_options);
-		tr0.appendChild(td0);
-		tbody_message.appendChild(tr0);
-	}
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	// END options message.
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-
-	var table_message_others_options = document.createElement("TABLE");
-	table_message_others_options.id = 'table_message_others_options_' + ID;
-	table_message_others_options.width =  defaultWidth - 30;
-	table_message_others_options.style.display = 'none';
-	table_message_others_options.className = "table_message";
-	var tbody_message_others_options = document.createElement("TBODY");
-	var tr1 = document.createElement("TR");
-	tr1.className = "tr_message_header";
-	var td1 = document.createElement("TD");
-	td1.innerHTML = get_lang("From: ");
-	td1.appendChild(deny_email(info_msg.from.email));
-	td1.width = "7%";
-	
-	if (info_msg.sender){
-		var tr111 = document.createElement("TR");
-		tr111.className = "tr_message_header";
-		var td111 = document.createElement("TD");
-		td111.innerHTML = get_lang("Sent by")+": ";
-		td111.appendChild(deny_email(info_msg.sender.email));
-		td111.setAttribute("noWrap","true");
-		var sender = document.createElement("TD");
-		sender.id = "sender_"+ID;
-		var sender_values = document.createElement("INPUT");
-		sender_values.id = "sender_values_"+ID;
-		sender_values.type = "HIDDEN";
-		sender_values.value = info_msg.sender.full; //Veio do IMAP, sem images nem links.
-		sender.innerHTML += draw_plugin_cc(ID, info_msg.sender.full);
-		sender.className = "header_message_field";
-		tr111.appendChild(td111);
-		tr111.appendChild(sender);
-		tr111.appendChild(sender_values);
-		tbody_message_others_options.appendChild(tr111);
-	}
-	
-	var from = document.createElement("TD");
-	from.id = "from_"+ID;
-	from.innerHTML = info_msg.from.full;
-	if (info_msg.Draft != "X"){
-		from.innerHTML += draw_plugin_cc(ID, info_msg.from);
-		tbody_message_others_options.appendChild(tr1);
-	}
-	from.className = "header_message_field";
-	var from_values = document.createElement("INPUT");
-	from_values.id = "from_values_"+ID;
-	from_values.type = "HIDDEN";
-	from_values.value = info_msg.from.full; //Veio do IMAP, sem images nem links.
-
-	var local_message = document.createElement("INPUT");
-	local_message.id = "is_local_"+ID;
-	local_message.name = "is_local";
-	local_message.type = "HIDDEN";
-	local_message.value = (info_msg.local_message)?"1":"0";
-
-	tr1.appendChild(td1);
-	tr1.appendChild(from);
-	tr1.appendChild(from_values);
-	tr1.appendChild(local_message);
-
-
-
-	if (info_msg.reply_to){
-		var tr11 = document.createElement("TR");
-		tr11.className = "tr_message_header";
-		var td11 = document.createElement("TD");
-		td11.innerHTML = get_lang("Reply to")+": ";
-		td11.setAttribute("noWrap","true");
-		var reply_to = document.createElement("TD");
-		reply_to.id = "reply_to_"+ID;
-		
-		var reply_to_values = document.createElement("INPUT");
-		reply_to_values.id = "reply_to_values_"+ID;
-		reply_to_values.type = "HIDDEN";
-		reply_to_values.value = info_msg.reply_to; //Veio do IMAP, sem images nem links.
-		reply_to.innerHTML = draw_plugin_cc(ID, info_msg.reply_to);
-		reply_to.className = "header_message_field";
-		tr11.appendChild(td11);
-		tr11.appendChild(reply_to);
-		tr11.appendChild(reply_to_values);
-		tbody_message_others_options.appendChild(tr11);
-	}
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr2 = document.createElement("TR");
-	tr2.className = "tr_message_header";
-	var td2 = document.createElement("TD");
-	td2.innerHTML = get_lang("To: ");
-	var to = document.createElement("TD");
-	to.id = "to_"+ID;
-
-	var to_values = document.createElement("INPUT");
-	to_values.id = "to_values_"+ID;
-	to_values.type = "HIDDEN";
-	to_values.value = info_msg.toaddress2; //Veio do IMAP, sem images nem links.	
-
-	// Salva a pasta da mensagem
-	var input_current_folder = document.createElement('input');	
-	input_current_folder.id = "input_folder_"+ID;
-	input_current_folder.name = "input_folder";
-	input_current_folder.type = "hidden";
-	input_current_folder.value = info_msg.msg_folder;
-	td2.appendChild(input_current_folder);	
-	// fim
-	toaddress_array[ID] = info_msg.toaddress2.split(",");
-	if (toaddress_array[ID].length > 1){
-		to.innerHTML += draw_plugin_cc(ID, toaddress_array[ID][0]);
-		var div_toaddress = document.createElement("SPAN");
-		div_toaddress.id = "div_toaddress_"+ID;
-		div_toaddress.style.display="";
-		div_toaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','to');>"+get_lang('more')+"</a>)";
-		to.appendChild(div_toaddress);		
-	}
-	else {
-		to.innerHTML += draw_plugin_cc(ID,toaddress_array[ID]);
-	}
-	to.className = "header_message_field";
-	tr2.appendChild(td2);
-	tr2.appendChild(to);
-	tr2.appendChild(to_values);
-	tbody_message_others_options.appendChild(tr2);
-
-	if (info_msg.cc){
-		var tr3 = document.createElement("TR");
-		tr3.className = "tr_message_header";
-		var td3 = document.createElement("TD");
-		td3.innerHTML = "CC: ";
-		var cc = document.createElement("TD");
-		cc.id = "cc_"+ID;
-
-		var cc_values = document.createElement("INPUT");
-		cc_values.id = "cc_values_"+ID;
-		cc_values.type = "HIDDEN";
-		cc_values.value = info_msg.cc;
-		
-		ccaddress_array[ID] = info_msg.cc.split(",");		
-		if (ccaddress_array[ID].length > 1){
-			var div_ccaddress = document.createElement("SPAN");
-			div_ccaddress.id = "div_ccaddress_"+ID;
-			var div_ccaddress_full = document.createElement("SPAN");
-			div_ccaddress_full.id = "div_ccaddress_full_"+ID;		
-			div_ccaddress.style.display="";
-			cc.innerHTML = draw_plugin_cc(ID, ccaddress_array[ID][0]);
-			div_ccaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','cc');>"+get_lang('more')+"</a>)";
-			cc.appendChild(div_ccaddress);
-		}
-		else{
-			cc.innerHTML = draw_plugin_cc(ID, info_msg.cc);
-		}
-		cc.className = "header_message_field";
-		tr3.appendChild(td3);
-		tr3.appendChild(cc);
-		tr3.appendChild(cc_values);
-		tbody_message_others_options.appendChild(tr3);
-	}
-
-	/*
-	 * @AUTHOR Rodrigo Souza dos Santos
-	 * @MODIFY-DATE 2008/09/11
-	 * @BRIEF Adding routine to create bcc field if there is one.
-	 */
-	if (info_msg.bcc)
-	{
-		var tr3 = document.createElement("tr");
-		tr3.className = "tr_message_header";
-		var td3 = document.createElement("td");
-		td3.innerHTML = get_lang("BCC") + " : ";
-		var cco = document.createElement("td");
-		cco.id = "cco_"+ID;
-
-		var cco_values = document.createElement("input");
-		cco_values.id = "cco_values_"+ID;
-		cco_values.type = "hidden";
-		cco_values.value = info_msg.bcc;
-
-		ccoaddress_array[ID] = info_msg.bcc.split(",");		
-		if (ccoaddress_array[ID].length > 1){
-			var div_ccoaddress = document.createElement("SPAN");
-			div_ccoaddress.id = "div_ccoaddress_"+ID;
-			var div_ccoaddress_full = document.createElement("SPAN");
-			div_ccoaddress_full.id = "div_ccoaddress_full_"+ID;		
-			div_ccoaddress.style.display="";
-
-			/*
-			 * The function below is ugly, doesn't possible use this.
-			 * The problem is that the code's function was written
-			 * on a hardcode concept.
-			 */
-			//cco.innerHTML = draw_plugin_cc(ID, ccoaddress_array[ID][0]);
-			cco.innerHTML = ccoaddress_array[ID][0];
-			div_ccoaddress.innerHTML += " (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','cco');>"+get_lang('more')+"</a>)";
-			cco.appendChild(div_ccoaddress);
-		}
-		else{
-			/*
-			 * The function below is ugly, it is not possible to use this.
-			 * The problem is that the code's function was written
-			 * on a hardcode concept.
-			 */
-			//cco.innerHTML = draw_plugin_cc(ID, info_msg.cco);
-			cco.innerHTML = info_msg.bcc;
-		}
-		cco.className = "header_message_field";
-		tr3.appendChild(td3);
-		tr3.appendChild(cco);
-		tr3.appendChild(cco_values);
-		tbody_message_others_options.appendChild(tr3);
-	}
-
-	var tr4 = document.createElement("TR");
-	tr4.className = "tr_message_header";
-	var td4 = document.createElement("TD");
-	td4.innerHTML = get_lang("Date: ");
-	var date = document.createElement("TD");
-	date.id = "date_"+ID;
-	date.innerHTML = info_msg.fulldate;
-	var date_day = document.createElement("INPUT");
-	date_day.id = "date_day_"+ID;
-	date_day.type = "HIDDEN";
-	date_day.value = info_msg.msg_day;
-	var date_hour = document.createElement("INPUT");
-	date_hour.id = "date_hour_"+ID;
-	date_hour.type = "HIDDEN";
-	date_hour.value = info_msg.msg_hour
-	date.className = "header_message_field";
-	tr4.appendChild(td4);
-	tr4.appendChild(date);
-	tr4.appendChild(date_day);
-	tr4.appendChild(date_hour);
-	tbody_message_others_options.appendChild(tr4);
-	
-	var tr5 = document.createElement("TR");
-	tr5.className = "tr_message_header";
-	var td5 = document.createElement("TD");
-	td5.innerHTML = get_lang("Subject");
-	var subject = document.createElement("TD");
-	subject.id = "subject_"+ID;
-	subject.innerHTML = info_msg.subject;
-	subject.className = "header_message_field";
-	tr5.appendChild(td5);
-	tr5.appendChild(subject);
-	tbody_message_others_options.appendChild(tr5);
-	if (info_msg.attachments.length > 0){
-		var tr6 = document.createElement("TR");
-		tr6.className = "tr_message_header";
-		var td6 = document.createElement("TD");
-		td6.innerHTML = get_lang("Attachments: ");
-
-		var attachments = document.createElement("TD");
-		td6.vAlign = "top";
-		attachments.align='left';
-		var zipped_attachments = '';
-		if(info_msg.attachments.length >= 1) {
-			var zipped_attachments  = document.createElement("TABLE");
-			zipped_attachments.style.marginBottom = "4px";
-			zipped_attachments.cellPadding="0";
-			zipped_attachments.cellSpacing="0";
-			var td = document.createElement("TD");
-			if(info_msg.attachments.length > 1) {
-				var link_attachment     = document.createElement("A");
-                 if(proxy_mensagens.is_local_folder(current_folder))
-                    link_attachment.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-                else
-                    link_attachment.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-				link_attachment.innerHTML = " "+info_msg.attachments.length+' '+get_lang('files')+' :: '+get_lang('Download all atachments');
-				link_attachment.innerHTML += '<BR>';
-				td.appendChild(link_attachment);
-			}
-			var tr = document.createElement("TR");
-			if(parseInt(preferences.remove_attachments_function))
-			{
-				var del_attachments = document.createElement("A");
-				del_attachments.setAttribute("href", "javascript:remove_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-				del_attachments.innerHTML = get_lang('remove all attachments');
-				del_attachments.appendChild(document.createElement('BR'));
-				td.appendChild(del_attachments);
-				tr.appendChild(td);
-			}
-			tr.appendChild(td);
-			zipped_attachments.appendChild(tr);
-			attachments.appendChild(zipped_attachments);
-		}
-
-		attachments.id = "attachments_" + ID;
-		for (var i=0; i<info_msg.attachments.length; i++){
-			var link_attachment = document.createElement("A");
-			link_attachment.setAttribute("href", proxy_mensagens.link_anexo(info_msg,i));
-//			link_attachment.setAttribute("href", "javascript:download_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"',"+i+",'"+info_msg.attachments[i].pid+"','"+info_msg.attachments[i].encoding+"')");
-			link_attachment.innerHTML = url_decode(info_msg.attachments[i].name);
-			link_attachment.innerHTML = borkb(info_msg.attachments[i].fsize);
-
-			if((url_decode(info_msg.attachments[i].name).indexOf(".ics")!=-1) || (url_decode(info_msg.attachments[i].name).indexOf(".vcard")!=-1)){
-				//Link para importar calendário
-				var link_import_attachment = new Image();
-				link_import_attachment.src = "templates/"+template+"/images/new.png";
-				link_import_attachment.setAttribute("onclick","javascript:import_calendar('"+info_msg.msg_folder+"&msg_number="+info_msg.msg_number+"&msg_part="+info_msg.attachments[i].pid+"&idx_file="+i+"&encoding="+info_msg.attachments[i].encoding+"');");
-				link_import_attachment.title = get_lang("Import to calendar");
-				link_import_attachment.align = "top";				
-				link_import_attachment.style.cursor = "pointer";
-				var space = document.createElement("span");
-				space.innerHTML = "&nbsp;";
-				attachments.appendChild(link_attachment);
-				attachments.appendChild(space);
-				attachments.appendChild(link_import_attachment);
-			}
-			else {
-				link_attachment.innerHTML += '<BR>';
-				attachments.appendChild(link_attachment);
-			}
-		}
-		tr6.appendChild(td6);
-		tr6.appendChild(attachments);
-		tbody_message_others_options.appendChild(tr6);
-	}
-
-
-	// BEGIN MAKE THE SCROLL HEIGHT
-	var bar = document.getElementById("toolbar");
-	var offset = 0;
-	if(bar.style.visibility != 'hidden')
-		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;
-	var div = document.createElement("DIV");
-	div.id = "div_message_scroll_"+ID;
-	div.style.background = 'WHITE';
-	div.style.height = document.body.clientHeight - offset - 125;
-	content.style.height = document.body.clientHeight - offset - 90;
-	div.style.overflow = "auto";
-	div.style.width = defaultWidth - (is_ie ? 5 : 0);
-	// END MAKE THE SCROLL HEIGHT
-	table_message_others_options.appendChild(tbody_message_others_options);
-	var tr = document.createElement("TR");
-	var td = document.createElement("TD");
-	td.colSpan = '2';
-	div.appendChild(table_message_others_options);
-	var imgTag = info_msg.body.match(/(<img[^>]*src[^>=]*=['"]?[^'">]*["']?[^>]*>)|(<[^>]*(style[^=>]*=['"][^>]*background(-image)?:[^:;>]*url\()[^>]*>)/gi);
-
-	var newBody = info_msg.body;
-	if(!info_msg.showImg && imgTag)
-	{
-		var domains = '';
-		var blocked = false;
-		var forbidden = true;
-
-		if (preferences.notification_domains != null && typeof(preferences.notification_domains) != 'undefined')
-		{
-			domains = preferences.notification_domains.split(',');
-			for(var j = 0; j < imgTag.length; j++)
-			{
-				for (var i = 0; i < domains.length; i++)
-				{
-					if (imgTag[j].match(/cid:([\w\d]){5,}/) || imgTag[j].match(/src=\"\.\/inc\/show_embedded_attach\.php/g))
-					{
-						forbidden = false;
-						continue;
-					}
-					imgSource = imgTag[j].match(/=['"](http:\/\/)+[^'"\/]*/);
-					if (imgSource && imgSource.toString().substr(5).match(domains[i]))
-						forbidden = false;
-				}
-				if (forbidden)
-				{
-					newBody = newBody.replace(imgTag[j],"<img src='templates/"+template+"/images/forbidden.jpg'>");
-					blocked=true;
-				}
-			}
-			if (blocked)
-			{
-				var showImgLink = document.createElement('DIV');
-				showImgLink.id="show_img_link_"+ID;
-				showImgLink.onclick = function(){show_msg_img(info_msg.msg_number,info_msg.msg_folder)};
-				showImgLink.className="show_img_link";
-				showImgLink.innerHTML = get_lang("Show images from")+": "+info_msg.from.email;
-				td.appendChild(showImgLink);
-			}
-		}
-	}
-	td.appendChild(div);
-	tr.appendChild(td)
-	tbody_message.appendChild(tr);
-
-
-	//////////////////////////////////////////////////////////////////////////////////////////////////////	
-	//Make the body message.
-	///////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr = document.createElement("TR");
-	tr.className = "tr_message_body";
-	var td = document.createElement("TD");
-	//td.setAttribute("colSpan","2");
-	newBody = newBody.replace("<body","<span");
-	newBody = newBody.replace("<BODY","<span");
-	div.innerHTML+= "<span id='body_"+ID+"' style='font-size:16px;'>"+newBody+"</span><br><br>";
-	function mailto( link )
-	{
-		var mail = link.href.substr( 7 );
-		link.onclick = function( )
-		{
-			new_message_to( mail );
-			return false;
-		};
-	}
-	var links = div.getElementsByTagName( 'a' );
-	for ( var i = 0; i < links.length; i++ )
-		if ( links.item( i ).href.indexOf( 'mailto:' ) === 0 )
-			mailto( links.item( i ) );
-		else
-		{
-			if ( links.item( i ).href.indexOf( 'javascript:' ) !== 0 )
-				links.item( i ).setAttribute( 'target', '_blank' );
-		}
-	//////////////////////////////////////////////////////////////////////////////////////////////////////	
-	//Make the thumbs of the message.
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	if ((info_msg.thumbs)&&(info_msg.thumbs.length > 0)){
-		var table_message_thumbs = document.createElement("TABLE");
-		table_message_thumbs.width = "80%";
-		table_message_thumbs.style.borderTop = "2px solid rgb(170, 170, 170)";
-		var tbody_message_thumbs = document.createElement("TBODY");
-		var tr = document.createElement("TR");
-		tr.className = "tr_message_body";
-		var td = document.createElement("TD");
-		td.setAttribute("colSpan","2");
-		td.id = "body_thumbs_"+ID;
-		td.innerHTML += "&nbsp;<font color='DARKBLUE' size='2'><b>"+info_msg.attachments.length+" "+get_lang("attachment")+(info_msg.attachments.length > 1 ? "s" : "")+" "+get_lang("in this message")+"</font></b>";
-		var _link_attachments = '';
-		if(info_msg.thumbs.length > 1){
-			_link_attachments 	= document.createElement("A");
-			_link_attachments.className = "message_options";
-             if(proxy_mensagens.is_local_folder(current_folder))
-                _link_attachments.setAttribute("href", "javascript:expresso_local_messages.download_all_local_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-            else
-                _link_attachments.setAttribute("href", "javascript:download_all_attachments('"+info_msg.msg_folder+"','"+info_msg.msg_number+"')");
-			_link_attachments.innerHTML = get_lang('Download all atachments');
-		}
-		
-		if(_link_attachments){
-			td.innerHTML +=	" :: ";
-			td.appendChild(_link_attachments);
-		}
-		
-		td.innerHTML +=	"<BR><img src='templates/"+template+"/images/menu/ktip.png'>"+get_lang("<b>Tip:</b> For faster save, click over the image with <u>right button</u>.");
-		td.innerHTML += "<BR>";
-
-		for (var i=0; i<info_msg.thumbs.length; i++){
-			if ((i % 4) == 0)
-				td.innerHTML += "<BR>";
-			td.innerHTML += info_msg.thumbs[i];
-			td.innerHTML += "&nbsp;&nbsp;";
-		}
-		tr.appendChild(td);
-		tbody_message_thumbs.appendChild(tr);
-		table_message_thumbs.appendChild(tbody_message_thumbs);
-		div.appendChild(table_message_thumbs);
-	}
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-	table_message.appendChild(tbody_message);
-	content.appendChild(table_message);
-	var msg_number = document.createElement('INPUT');
-	msg_number.id = "msg_number_" + ID;
-	msg_number.type = "hidden";
-	msg_number.value = info_msg.msg_number;
-	content.appendChild(msg_number);
-	//////////////////////////////////////////////////////////////////////////////////////////////////////
-
-	//Exibe o cabecalho da mensagem totalmente aberto caso esteja setado nas preferencias do usuario
-	if (preferences.show_head_msg_full == 1)
-	{
-		option_hide_more.onclick();
-
-		if (Element('div_toaddress_'+ID) != null)
-		{
-			show_div_address_full(ID,'to');
-		}	
-		if (Element('div_ccaddress_'+ID) != null)
-		{
-			show_div_address_full(ID,'cc');
-		}
-	}
-
-}
-function changeLinkState(el,state){
-	el.innerHTML = get_lang(state);
-	switch (state){
-		case 'important':
-			{
-				el.onclick = function(){changeLinkState(el,'normal');set_messages_flag('unflagged',currentTab.substr(0,currentTab.indexOf("_r"))); write_msg(get_lang('Message marked as ')+get_lang("Normal"))}
-				break;
-			}
-		case 'normal':
-			{
-				el.onclick = function(){  changeLinkState(el,'important');set_messages_flag('flagged',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("Important"))}
-				break;
-			}
-		case 'unseen':
-			{
-				el.onclick = function(){  changeLinkState(el,'seen');set_messages_flag('unseen',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("unseen"))}
-				break;
-
-			}
-		case 'seen':
-			{
-				el.onclick = function(){  changeLinkState(el,'unseen');set_messages_flag('seen',currentTab.substr(0,currentTab.indexOf("_r")));write_msg(get_lang('Message marked as ')+get_lang("seen"))}
-				break;
-
-			}
-		default:
-			{
-				break;
-			}
-	}
-}
-
-
-function draw_new_message(border_ID){
-	var ID = create_border("",border_ID);
-	if (ID == false)
-		return false;
-	expresso.connector.hold_session = true;
-	
-	var footer_menu = Element("footer_menu");	
-	if (footer_menu) {
-		footer_menu.style.display = 'none';
-	}
-/////////////////////////////////////////////////////////////////////////////////////////////////////////
-	var form = document.createElement("FORM");
-	form.name = "form_message_"+ID;
-	form.method = "POST";
-	form.onsubmit = function(){return false;}
-	if(!is_ie)
-		form.enctype="multipart/form-data";
-	else
-		form.encoding="multipart/form-data";
-/////////////////////////////////////////////////////////////////////////////////////////////////////////
-	//ConstructMenuNewMessage(ID);
-////////////////////////////////////////////////////////////////////////////////////////////////////////	
-	var content = Element('content_id_' + ID);
-	var table_message = document.createElement("TABLE");
-	table_message.width = "100%";
-	var tbody_message = document.createElement("TBODY");
-	var tr0 = document.createElement("TR");
-	tr0.className = "tr_message_header";
-	var td0 = document.createElement("TD");
-	td0.colSpan = '3';
-	
-	var table_menu_new_message = document.createElement("TABLE");
-	table_menu_new_message.width = "100%";
-	table_menu_new_message.border = '0';
-	table_menu_new_message.className = 'table_message';
-	var tbody_menu_new_message = document.createElement("TBODY");
-	var tr_menu_new_message = document.createElement("TR");
-	var td_menu_new_message = document.createElement("TD");
-	td_menu_new_message.setAttribute("noWrap","true");
-	
-	if ((preferences.save_in_folder == '-1') || (preferences.save_in_folder == '')){
-		//var option_send = '<span class="message_options" onclick=send_message("'+ID+'","null","null");>'+get_lang("Send")+'</span> | ';
-		var option_send   = '<input type="button" id="send_button_'+ID+'" class="em_button_like_span" tabindex="1" value="'+get_lang("Send")+'" onclick=send_message("'+ID+'","null","null");>' + ' | ';
-		if(!expresso_offline)
-			var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
-		else
-			var option_send_and_file='';
-	}
-	else{
-		//var option_send = '<span class="message_options" onclick="send_message(\''+ID+'\',\''+preferences.save_in_folder+'\',\'null\');">'+get_lang("Send")+'</span> | ';
-		var option_send   = '<input type="button" id="send_button_'+ID+'" class="em_button_like_span" tabindex="1" value="'+get_lang("Send")+'" onclick="send_message(\''+ID+'\',\''+preferences.save_in_folder+'\',\'null\');">' + ' | ';
-		var option_send_and_file='';
-		wfolders.alert = true;
-	}
-//	var option_save_as		= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","save");>'+get_lang("Save as")+'</span> | ';
-	if (!expresso_offline) {
-		var option_save = '<span id="save_message_options_'+ID+'" class="message_options" onclick="openTab.toPreserve['+ID+'] = true; save_msg('+ID+');">'+get_lang("Save")+'</span> | ';
-		var option_search = '<span class="message_options" onclick=openListUsers("'+ID+'");>'+get_lang("Search")+'</span>';
-	}
-	else {
-		var option_save = '<input type="hidden" id="save_message_options_'+ID+'">';
-		var option_search = '';
-	}
-	td_menu_new_message.innerHTML = option_send + option_send_and_file + option_save + option_search;
-	
-	tr_menu_new_message.appendChild(td_menu_new_message);
-	tbody_menu_new_message.appendChild(tr_menu_new_message);
-	table_menu_new_message.appendChild(tbody_menu_new_message);
-	
-	content.appendChild(table_menu_new_message);
-	tr0.appendChild(td0);
-	tbody_message.appendChild(tr0);
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr1_1 = document.createElement("TR");
-	tr1_1.style.display = 'none';
-	var td1_1 = document.createElement("TD");
-	td1_1.innerHTML = get_lang("From")+":";
-	td1_1.setAttribute("noWrap","true");
-	td1_1.style.width = "1%";
-	
-	var td_from = document.createElement("TD");
-	td_from.setAttribute("noWrap","true");
-	td_from.style.width = "100%";
-			
-	var sel_from = document.createElement('SELECT');	
-	sel_from.id = "from_"+ID;
-	sel_from.name = "input_from";
-	sel_from.style.width = "70%";
-	sel_from.setAttribute("wrap","soft");
-	td_from.appendChild(sel_from);	
-	tr1_1.appendChild(td1_1);
-	tr1_1.appendChild(td_from);
-	tbody_message.appendChild(tr1_1);	
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr1 = document.createElement("TR");
-	var td1 = document.createElement("TD");
-	td1.innerHTML = get_lang("To")+":";
-	td1.setAttribute("noWrap","true");
-	td1.style.width = "1%";
-	
-	var td_to = document.createElement("TD");
-	td_to.setAttribute("noWrap","true");
-	td_to.style.width = "100%";
-	
-	var input_to = document.createElement('TEXTAREA');
-	input_to.id = "to_"+ID;
-	input_to.name = "input_to";
-	input_to.setAttribute("tabIndex","1");	
-	input_to.style.width = "100%";
-	input_to.setAttribute("wrap","soft");
-	input_to.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus', this.id);};
-	input_to.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
-	if (!is_ie)
-	{
-		input_to.rows = 2;
-		input_to.onkeypress = function (e)
-        {
-            if ((e.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_to.value, 'to', ID);
-            }
-            else
-            {
-                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-                {
-                    e.preventDefault();
-                    search_contacts(e.keyCode,this.id);
-                }
-            }
-        }
-        input_to.onkeyup = function (e)
-        {
-            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-            {
-                search_contacts(e.keyCode,this.id);
-            }
-        }
-	}
-	else
-	{
-		input_to.rows = 3;
-		input_to.onkeyup = function (e)
-        {
-            if ((window.event.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_to.value, 'to', ID);
-            }
-            else 
-            { 
-                search_contacts(window.event.keyCode,this.id);
-            }   
-        }
-	}
-	td_to.appendChild(input_to);
-	
-	var forwarded_local_message = document.createElement("INPUT"); //Hidden para indicar se é um forward de uma mensagem local
-	forwarded_local_message.id = "is_local_forward"+ID;
-	forwarded_local_message.name = "is_local_forward";
-	forwarded_local_message.type = "HIDDEN";
-	forwarded_local_message.value = "0";
-	td_to.appendChild(forwarded_local_message);
-	
-	if (!expresso_offline) {
-		var img_search = document.createElement("IMG");
-		img_search.src = "./templates/"+template+"/images/search.gif";
-		img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
-		img_search.onclick = function () {emQuickSearch(document.getElementById('to_'+ID).value, 'to', ID);};
-	}
-	else {
-		var img_search = document.createElement("SPAN");
-	}
-	
-	var span_search = document.createElement("SPAN");
-	span_search.innerHTML = get_lang('Search');
-	
-	var td1_img_search = document.createElement("TD");
-	td1_img_search.setAttribute("noWrap","true");
-	var td1_span_search = document.createElement("TD");
-	td1_span_search.setAttribute("noWrap","true");	
-	
-	td1_img_search.appendChild(img_search);
-	td1_span_search.appendChild(span_search);
-	
-	tr1.appendChild(td1);
-	tr1.appendChild(td_to);
-	tr1.appendChild(td1_img_search);
-
-	tbody_message.appendChild(tr1);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr2 = document.createElement("TR");
-	tr2.id = "tr_cc_"+ID;
-	tr2.style.display = 'none';
-	var td2 = document.createElement("TD");
-	td2.innerHTML = "Cc:";
-	td2.setAttribute("noWrap","true");	
-	td2.style.width = "1%";
-	
-	var td_cc = document.createElement("TD");
-	td_cc.setAttribute("noWrap","true");
-	td_cc.style.width = "100%";
-	
-	var input_cc = document.createElement('TEXTAREA');
-	input_cc.id = "cc_"+ID;
-	input_cc.name = "input_cc";
-	input_cc.setAttribute("tabIndex","1");
-	input_cc.style.width = "100%";
-	input_cc.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
-	input_cc.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
-    if (!is_ie)
-    {
-        input_cc.rows = 2;
-        input_cc.onkeypress = function (e)
-        {
-            if ((e.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_cc.value, 'cc', ID);
-            }
-            else
-            {
-                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-                {
-                    e.preventDefault();
-                    search_contacts(e.keyCode,this.id);
-                }
-            }
-        }
-        input_cc.onkeyup = function (e)
-        {
-            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-            {
-                search_contacts(e.keyCode,this.id);
-            }
-        }
-    }
-    else if (is_ie)
-    {
-        input_cc.rows = 3;
-        input_cc.onkeyup = function (e)
-        {
-            if ((window.event.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_cc.value, 'cc', ID);
-            }
-            else
-            {
-                search_contacts(window.event.keyCode,this.id);
-            }
-        }
-    }
-	
-	td_cc.appendChild(input_cc);
-	var img_search = document.createElement("IMG");
-	img_search.src = "./templates/"+template+"/images/search.gif";
-	img_search.onclick = function () {emQuickSearch(document.getElementById('cc_'+ID).value, 'cc', ID)}
-	img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
-	var span_search = document.createElement("SPAN");
-	span_search.innerHTML = get_lang('Search');
-	
-	var td2_img_search = document.createElement("TD");
-	td2_img_search.setAttribute("noWrap","true");
-	var td2_span_search = document.createElement("TD");
-	td2_span_search.setAttribute("noWrap","true");	
-	
-	td2_img_search.appendChild(img_search);
-	td2_span_search.appendChild(span_search);
-		
-	tr2.appendChild(td2);
-	tr2.appendChild(td_cc);
-	tr2.appendChild(td2_img_search);
-	tbody_message.appendChild(tr2);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr3 = document.createElement("TR");
-	tr3.id = "tr_cco_"+ID;
-	tr3.style.display = 'none';
-	var td3 = document.createElement("TD");
-	td3.setAttribute("noWrap","true");
-	td3.innerHTML = get_lang("CCo")+":";
-	td3.style.width = "1%";
-	
-	var td_cco = document.createElement("TD");
-	td_cco.setAttribute("noWrap","true");
-	td_cco.style.width = "100%";
-	
-	var input_cco = document.createElement('TEXTAREA');
-	input_cco.id = "cco_"+ID;
-	input_cco.name = "input_cco";
-	input_cco.setAttribute("tabIndex","1");
-	input_cco.style.width = "100%";
-	input_cco.onfocus = function(){clearTimeout(parseInt(setTimeOutLayer)); search_contacts('onfocus',this.id);};
-	input_cco.onblur = function(){setTimeOutLayer=setTimeout('search_contacts("lostfocus","'+this.id+'")',100);};
-	
-	if (!is_ie)
-    {
-        input_cco.rows = 2;
-        input_cco.onkeypress = function (e)
-        {
-            if ((e.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_cco.value, 'cco', ID);
-            }
-            else 
-            { 
-                if (((e.keyCode == 13) || ((e.keyCode == 38)||(e.keyCode == 40))) && (document.getElementById('tipDiv').style.visibility!='hidden'))
-                {
-                    e.preventDefault();
-                    search_contacts(e.keyCode,this.id);
-                }
-            }
-        }
-        input_cco.onkeyup = function (e)
-        {
-            if ((e.keyCode != 13) && (e.keyCode != 38) && (e.keyCode != 40))
-            {
-                search_contacts(e.keyCode,this.id);
-            }
-        }
-    }
-    else if (is_ie)
-    {
-        input_cco.rows = 3;
-        input_cco.onkeyup = function (e)
-        {
-            if ((window.event.keyCode) == 120) //F9
-            {
-                emQuickSearch(input_cco.value, 'cco', ID);
-            }
-            else 
-            { 
-                search_contacts(window.event.keyCode,this.id);
-            }   
-        }
-    }
-	
-	td_cco.appendChild(input_cco);
-	var img_search = document.createElement("IMG");
-	img_search.src = "./templates/"+template+"/images/search.gif";
-	img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');	
-	img_search.onclick = function () {emQuickSearch(document.getElementById('cco_'+ID).value, 'cco', ID);};
-	var span_search = document.createElement("SPAN");
-	span_search.innerHTML = get_lang('Search');
-
-	var td3_img_search = document.createElement("TD");
-	td3_img_search.setAttribute("noWrap","true");
-	var td3_span_search = document.createElement("TD");
-	td3_span_search.setAttribute("noWrap","true");	
-	
-	td3_img_search.appendChild(img_search);
-	td3_span_search.appendChild(span_search);
-		
-	tr3.appendChild(td3);
-	tr3.appendChild(td_cco);
-	tr3.appendChild(td3_img_search);	
-	tbody_message.appendChild(tr3);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr_link = document.createElement("TR");
-	tr_link.id = "tr_link_"+ID;		
-	var td1_link = document.createElement("TD");
-	var td2_link = document.createElement("TD");
-	td1_link.innerHTML = "&nbsp;";
-	var a_cc_link = document.createElement('A');
-	a_cc_link.innerHTML = get_lang('Add CC');
-	a_cc_link.id = "a_cc_link_"+ID;
-	a_cc_link.setAttribute("href","javascript:void(0)");
-	a_cc_link.setAttribute("tabIndex","-1");
-	a_cc_link.onclick = function () {this.style.display='none';document.getElementById('tr_cc_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cc.focus(); return false;}
-	td2_link.appendChild(a_cc_link);	
-	var space = document.createElement("span");
-	space.id ="space_link_"+ID;
-	space.innerHTML="&nbsp;|&nbsp;";
-	td2_link.appendChild(space);
-	var a_cco_link = document.createElement('A');
-	a_cco_link.innerHTML = get_lang('Add BCC');
-	a_cco_link.id = "a_cco_link_"+ID;
-	a_cco_link.setAttribute("href","javascript:void(0)");
-	a_cco_link.setAttribute("tabIndex","-1");
-	a_cco_link.onclick = function () {this.style.display='none';document.getElementById('tr_cco_'+ID).style.display='';document.getElementById('space_link_'+ID).style.display='none';input_cco.focus(); return false;}
-	td2_link.appendChild(a_cco_link);	
-	tr_link.appendChild(td1_link);
-	tr_link.appendChild(td2_link);
-	tbody_message.appendChild(tr_link);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr4 = document.createElement("TR");
-	var td4 = document.createElement("TD");
-	//td4.setAttribute("noWrap","true");	
-	td4.innerHTML = get_lang("Subject")+":";
-	var td_subject = document.createElement("TD");
-	var input_subject = document.createElement('input');
-	input_subject.id = "subject_"+ID;
-	input_subject.name = "input_subject";
-	input_subject.setAttribute("tabIndex","1");
-	input_subject.style.width = "90%";
-	input_subject.setAttribute("autocomplete","off");
-	td_subject.appendChild(input_subject);
-	tr4.appendChild(td4);
-	tr4.appendChild(td_subject);
-	tbody_message.appendChild(tr4);
-//////////////////////////////////////////////////////////////////////////////////////////////////////	
-	var tr5 = document.createElement("TR");
-	var td5 = document.createElement("TD");
-	td5.innerHTML = "&nbsp;";
-	var td_return_receipt = document.createElement("TD");
-	td_return_receipt.setAttribute("noWrap","true");
-	td_return_receipt.innerHTML = get_lang("Return receipt")+":";
-        if (is_ie)
-        {
-            var input_return_receipt = document.createElement('input name=input_return_receipt');
-        }
-        else
-        {
-            var input_return_receipt = document.createElement('input');
-            input_return_receipt.name = "input_return_receipt";
-        }
-	input_return_receipt.type = "checkbox";
-	input_return_receipt.className = "checkbox";
-	input_return_receipt.id = "return_receipt_"+ID;
-	input_return_receipt.setAttribute("tabIndex","-1");
-	td_return_receipt.appendChild(input_return_receipt);
-
-    // Workaround para resolver problema ao enviar e-mails
-    if((preferences.use_assinar_criptografar != '0'))
-	{
-        if(parseInt(preferences.use_signature_digital_cripto)==1)
-		{
-			td_return_receipt.innerHTML +=  "&nbsp;&nbsp;" + get_lang("Digitally sign message?")+"";
-
-            if (is_ie)
-            {
-                var input_return_digital = document.createElement('input name=input_return_digital');
-            }
-            else
-            {
-			var input_return_digital = document.createElement('input');
-                input_return_digital.name = "input_return_digital";
-            }
-
-			input_return_digital.type = "checkbox";
-			input_return_digital.className = "checkbox";
-			input_return_digital.id = "return_digital_"+ID;
-			input_return_digital.setAttribute("tabIndex","-1");
-            if(parseInt(preferences.use_signature_digital)==1)
-			{
-				input_return_digital.defaultChecked=true;
-			}
-			td_return_receipt.appendChild(input_return_digital);
-			td_return_receipt.innerHTML +=  "&nbsp;&nbsp;" + get_lang("Digitally crypt message?")+"";
-
-            if (is_ie)
-            {
-                var input_return_cripto = document.createElement('input name=input_return_cripto');
-            }
-            else
-            {
-			var input_return_cripto = document.createElement('input');
-                input_return_cripto.name = "input_return_cripto";
-            }
-
-			input_return_cripto.type = "checkbox";
-			input_return_cripto.className = "checkbox";
-			input_return_cripto.id = "return_cripto_"+ID;
-			input_return_cripto.setAttribute("tabIndex","-1");
-			input_return_cripto.defaultChecked=false;
-
-            if(parseInt(preferences.use_signature_cripto)==1)
-			{
-				input_return_cripto.defaultChecked=true;
-			}
-
-			td_return_receipt.appendChild(input_return_cripto);
-		}
-                td_return_receipt.innerHTML += "";
-	}
-
-	tr5.appendChild(td5);
-	tr5.appendChild(td_return_receipt);
-	tbody_message.appendChild(tr5);
-	if (parseInt(preferences.use_important_flag))
-	{
-		var trn = document.createElement("TR");
-		var tdn = document.createElement("TD");
-		tdn.innerHTML = "&nbsp;";
-		var td_important_msg = document.createElement("TD");
-		td_important_msg.setAttribute("noWrap","true");
-		td_important_msg.innerHTML = get_lang("Important message")+":";
-		var input_important_message = document.createElement('input');
-		input_important_message.type = "checkbox";
-		input_important_message.className = "checkbox";
-		input_important_message.id = "important_message_"+ID;
-		input_important_message.name = "input_important_message";
-		input_important_message.setAttribute("tabIndex","-1");
-		td_important_msg.appendChild(input_important_message);	
-		trn.appendChild(tdn);
-		trn.appendChild(td_important_msg);
-		tbody_message.appendChild(trn);
-	}
-
-	var add_files = document.createElement("A");
-	add_files.setAttribute("href", "javascript:void(0)");
-	add_files.onclick = function () { addFile(ID); return false;};
-	add_files.innerHTML =  get_lang("Attachments: add+");
-	add_files.setAttribute("tabIndex","-1");
-	var divfiles = document.createElement("DIV");
-	divfiles.id = "divFiles_"+ID;
-	var tr5 = document.createElement("TR");
-	var td5_link = document.createElement("TD");
-	var td5_input = document.createElement("TD");	
-	td5_input.innerHTML = "&nbsp;"
-	td5_link.setAttribute("valign","top");
-	td5_link.setAttribute("colSpan","2");
-	td5_link.appendChild(add_files);
-	tr5.appendChild(td5_input);
-	tr5.appendChild(td5_link);
-	tbody_message.appendChild(tr5);
-	var tr6 = document.createElement("TR");
-	var td6_link  = document.createElement("TD");
-	var td6_input = document.createElement("TD");
-	tr6.appendChild(td6_link);
-	td6_input.appendChild(divfiles);
-	tr6.appendChild(td6_input);	
-	tbody_message.appendChild(tr6);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	var tr5 = document.createElement("TR");
-	var td5 = document.createElement("TD");	
-	td5.innerHTML = "&nbsp;";
-	var td_body = document.createElement("TD");
-	td_body.setAttribute("colSpan","2");
-	var div_body_position = document.createElement("DIV");
-	div_body_position.id = "body_position_" + ID;
-	td_body.appendChild(div_body_position);
-	tr5.appendChild(td5);
-	tr5.appendChild(td_body);
-	tbody_message.appendChild(tr5);
-// BEGIN MAKE THE SCROLL HEIGHT
-    var defaultWidth = document.body.clientWidth - (is_ie ? 200 : 195);
-	var _bar = document.getElementById("toolbar");
-	var _offset = 0;
-	if(_bar.style.visibility != 'hidden') 
-		_offset = _bar.offsetHeight ? _bar.offsetHeight :  _bar.clientHeight;		
-	var _div = document.createElement("DIV");
-	_div.id = "div_message_scroll_"+ID;
-	_div.style.height = document.body.clientHeight - _offset - 105;
-	content.style.height = document.body.clientHeight - _offset - 80;
-	_div.style.overflow = "auto";
-	_div.style.width = defaultWidth;
-	// END MAKE THE SCROLL HEIGHT
-
-	// Hide the contac tips and re-position the pallete color.
-	_div.onscroll = function() {
-		var intElemScrollTop = Element("div_message_scroll_"+ID).scrollTop;
-		if (!is_ie)
-			ColorPalette.repos(intElemScrollTop);
-		Tooltip.scrollChanged();
-	};
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	_div.appendChild(form);
-	content.appendChild(_div);
-	table_message.appendChild(tbody_message);
-	form.appendChild(table_message);
-	expresso.connector.loadScript("rich_text_editor");
-	RichTextEditor.loadEditor(ID);
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-	if(!expresso_offline)
-		draw_from_field(sel_from,tr1_1);
-	return ID;
-}
-
-//	Verify if any user is sharing his name/email address
-//	for use in the new messages's "From " field.
-function draw_from_field(sel_from,tr1_1){
-
-	var el_shared_users = Element("el_shared_users");
-	// The element was loaded and populated...so return.
-	if(el_shared_users){	
-		// Nothing to work...so return.
-		if(el_shared_users.options.length == 0)
-			return;
-		tr1_1.style.display = '';
-		for (var x = 0; x < el_shared_users.options.length; x++) {
-			var _option = document.createElement("OPTION");
-			_option.text = el_shared_users.options[x].text;
-			_option.value = el_shared_users.options[x].value;
-			sel_from.options[sel_from.options.length] = _option	;
-		}
-		return;
-	}
-	// Get the shared folders.....
- 	var sharedFolders = new Array();
-	for(var i = 0; i < folders.length; i++) {
-		var x = folders[i].folder_id;
-      	if (folders[i].folder_parent == 'user'){
-      		sharedFolders[sharedFolders.length] = x;
-      	}
-    }
-
-    var matchUser = '#';
-    var sharedUsers = new Array();
-  	// Filter the shared folders (only root folders) .....
-   	for(var i = 0; i < sharedFolders.length; i++) {
-      if(!sharedFolders[i].match(matchUser)) {
-		matchUser = sharedFolders[i];
-		sharedUsers[sharedUsers.length] = matchUser.substring(("user"+cyrus_delimiter).length,matchUser.length);
-      }
-    }
-
-	// Handler function for cExecute
-	var h_user = function(data) {
-		if(data.length > 0) {
-			tr1_1.style.display = '';
-			var _option = document.createElement("OPTION");
-			_option.text =  '"'+data.myname+'" <'+Element("user_email").value+'>';
-			_option.value  = data.myname+";"+Element("user_email").value;
-			sel_from.options[sel_from.options.length] = _option;
-	
-			var options = '';
-			for (var x = 0; x < data.length; x++)	{
-				var _option = document.createElement("OPTION");
-				_option.text = '"'+data[x].cn[0] + '" <'+data[x].mail[0]+'>';
-				_option.value = data[x].cn[0] + ';'+data[x].mail[0]+';'+data[x].save_shared[0]+';'+data[x].uid[0];
-				sel_from.options[sel_from.options.length] = _option	;
-			}
-		}
-		var shared_users_from = Element("el_shared_users");
-		if(!shared_users_from) {
-			shared_users_from = sel_from.cloneNode(true);
-			shared_users_from.id = "el_shared_users";
-			shared_users_from.style.display = 'none';
-			document.body.appendChild(shared_users_from);
-		}
-	}
-	// First time, so execute.....
-	cExecute ("expressoMail1_2.ldap_functions.getSharedUsersFrom&uids="+sharedUsers.join(';'), h_user);
-}
-
-function changeBgColorToON(all_messages, begin, end){
-	for (begin; begin<=end; begin++)
-	{
-		add_className(all_messages[begin], 'selected_msg');
-		Element("check_box_message_" + all_messages[begin].id).checked = true;
-	}
-}
-function updateBoxBgColor(box){
-	// Set first TR Class
-	var _className = 'tr_msg_read2';
-	for(var i = 0; i < box.length;i++){	
-		if(exist_className(box[i],_className))
-			remove_className(box[i], _className);
-		_className = (_className == 'tr_msg_read2' ? 'tr_msg_read' : 'tr_msg_read2');
-		if(!exist_className(box[i],_className))
-			add_className( box[i], _className);
-	}
-}
-
-function changeBgColor(event, msg_number){
-	actual_tr = Element(msg_number);
-
-	if (event.shiftKey)
-	{
-		last_tr = Element(last_message_selected);
-		if(!last_tr)
-			last_tr = actual_tr;
-
-		all_messages = actual_tr.parentNode.childNodes;
-		
-		for (var i=0; i < all_messages.length; i++)
-		{
-			if (actual_tr.id == all_messages[i].id)
-				first_order = i;
-			if (last_tr.id == all_messages[i].id)
-				last_order = i;
-		}
-		
-		if (parseInt(first_order) > parseInt(last_order))
-			changeBgColorToON(all_messages, last_order, first_order);
-		else
-			changeBgColorToON(all_messages, first_order, last_order);
-	}
-	else{
-		//if ( exist_className(actual_tr, 'selected_msg') )
-		if ( Element('check_box_message_' + msg_number).checked )
-			add_className(actual_tr, 'selected_msg');
-		else
-			remove_className(actual_tr, 'selected_msg');
-	}
-	last_message_selected = msg_number;
-}
-
-function build_quota(data){
-	id = "content_quota";
-	q_limit = data['quota_limit'];
-	var div	= document.getElementById(id);
-	if(!q_limit){
-	    div.innerHTML = '<span><font size="2" style="color:red"><strong>'+get_lang("Without Quota")+'</strong></font></span>';
-	}
-	else{
-	if(div)
-		div.innerHTML = '';
-	value = data['quota_percent'];
-	q_used = data['quota_used'];
-	table = document.getElementById("table_quota");
-	if(table)
-		table.parentNode.removeChild(table);
-	table = document.createElement("TABLE");	
-	tbody = document.createElement("TBODY");	
-	table.appendChild(tbody);
-	table.id = "table_quota";
-	table.width="102";
-	table.border="0";
-	table.cellSpacing = 0;
-	table.cellPadding = 0;
-	
-	//tr1 = document.createElement("TR");
-	td11 = document.createElement("TD");
-	td11.align="center";
-	td11.setAttribute("noWrap","true");
-	td11.innerHTML += '&nbsp;<span class="boxHeaderText">' + value+"% ("+q_used+"M/"+q_limit+"M)</span>";
-	//tr1.appendChild(td11);
-	
-	tr2 = document.createElement("TR");
-	td21 = document.createElement("TD");
-	td21.setAttribute("noWrap","true");
-	td21.height="15";
-	td22 = document.createElement("TD");	
-	td21.setAttribute("background","../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","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_quota(data){
-	build_quota(data);
-}
-
-function update_quota(folder_id){
-	cExecute ("expressoMail1_2.imap_functions.get_quota&folder_id="+folder_id,build_quota);
-}
-
-function draw_search(headers_msgs){
-	Element("border_id_0").innerHTML = "&nbsp;&nbsp;" + get_lang('Search Result') + "&nbsp;&nbsp;";
-
-	var tbody = Element('tbody_box');
-	for (var i=0; i<(headers_msgs.length); i++){
-		var tr = this.make_tr_message(headers_msgs[i], headers_msgs[i].msg_folder);
-		if (tr)
-			tbody.appendChild(tr);
-	}
-}
-
-function draw_search_header_box(){
-	var table_message_header_box = Element("table_message_header_box");
-	table_message_header_box.parentNode.removeChild(table_message_header_box);
-
-	var content_id_0 = Element("content_id_0");
-	var table_element = document.createElement("TABLE");
-	var tbody_element = document.createElement("TBODY");
-	table_element.setAttribute("id", "table_message_header_box");
-	table_element.className = "table_message_header_box";
-	tr_element = document.createElement("TR");
-	tr_element.className = "message_header";
-	td_element1 = document.createElement("TD");
-	td_element1.setAttribute("width", "1%");
-	chk_box_element = document.createElement("INPUT");
-	chk_box_element.id  = "chk_box_select_all_messages";
-	chk_box_element.setAttribute("type", "checkbox");
-	chk_box_element.className = "checkbox";
-	chk_box_element.onclick = function(){select_all_messages(this.checked);};
-	chk_box_element.onmouseover = function () {this.title=get_lang('Select all messages.')};
-	chk_box_element.onkeydown = function (e){
-		if (is_ie)
-		{
-			if ((window.event.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-		else
-		{
-			if ((e.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-	};
-	
-	td_element1.appendChild(chk_box_element);
-	td_element2 = document.createElement("TD");
-	td_element2.setAttribute("width", "3%");
-	td_element3 = document.createElement("TD");
-	td_element3.setAttribute("width", "30%");
-	td_element3.id = "message_header_SORTFROM";
-	td_element3.align = "left";
-	td_element3.innerHTML = get_lang("From");
-	td_element4 = document.createElement("TD");
-	td_element4.setAttribute("width", "49%");
-	td_element4.id = "message_header_SORTSUBJECT";
-	td_element4.align = "left";
-	td_element4.innerHTML = get_lang("Subject");	
-	td_element5 = document.createElement("TD");
-	td_element5.setAttribute("width", "10%");
-	td_element5.id = "message_header_SORTARRIVAL";
-	td_element5.align = "center";
-	td_element5.innerHTML = "<B>"+get_lang("Date")+"</B>";	
-	td_element5.innerHTML += "<img src ='templates/"+template+"/images/arrow_descendant.gif'>";
-	td_element6 = document.createElement("TD");
-	td_element6.setAttribute("width", "10%");
-	td_element6.id = "message_header_SORTSIZE";
-	td_element6.align = "right";
-	td_element6.innerHTML = get_lang("Size");
-	tr_element.appendChild(td_element1);
-	tr_element.appendChild(td_element2);
-	tr_element.appendChild(td_element3);
-	tr_element.appendChild(td_element4);
-	tr_element.appendChild(td_element5);
-	tr_element.appendChild(td_element6);
-	
-	tbody_element.appendChild(tr_element);
-	table_element.appendChild(tbody_element);
-	content_id_0.appendChild(table_element);
-}
-
-function draw_search_division(msg){
-	var tbody = Element('tbody_box');
-	var tr = document.createElement("TR");
-	var td = document.createElement("TD");
-	td.colSpan = '7';
-	td.width = '100%';
-
-	var action_info_table = document.createElement("TABLE");
-	var action_info_tbody = document.createElement("TBODY");
-	
-	action_info_table.className = "action_info_table";
-	action_info_table.width = "100%";
-	
-	var action_info_tr = document.createElement("TR");
-	
-	var action_info_th1 = document.createElement("TH");
-	action_info_th1.width = "40%";
-	action_info_th1.innerHTML = "&nbsp;";
-
-	var action_info_th2 = document.createElement("TH");
-	
-	action_info_th2.innerHTML = msg;
-	action_info_th2.className = "action_info_th";
-	action_info_th2.setAttribute("noWrap", "true");
-	
-	var action_info_th3 = document.createElement("TH");
-	action_info_th3.width = "40%";
-	action_info_th3.innerHTML = "&nbsp;";
-	
-	action_info_tr.appendChild(action_info_th1);
-	action_info_tr.appendChild(action_info_th2);
-	action_info_tr.appendChild(action_info_th3);
-	action_info_tbody.appendChild(action_info_tr);
-	action_info_table.appendChild(action_info_tbody);
-
-	td.appendChild(action_info_table);
-	tr.appendChild(td);
-	tbody.appendChild(tr);
-}
-
-function draw_search_box(){
-	var content_id_0 = Element("content_id_0");
-	var table = document.createElement("TABLE");
-	table.id = "table_box";
-	table.width = 'auto';
-	var tbody = document.createElement("TBODY");
-	tbody.id = "tbody_box";
-
-	table.className = "table_box";
-	table.setAttribute("frame", "below");
-	table.setAttribute("rules", "none");
-	table.setAttribute("cellpadding", "0");
-	table.onkeydown = function (e){
-		if (is_ie)
-		{
-			if ((window.event.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-		else
-		{
-			if ((e.keyCode) == 46)
-			{
-				//delete_all_selected_msgs_imap();
-				proxy_mensagens.delete_msgs(get_current_folder(),'selected','null');
-			}
-		}
-	};
-	if (is_ie)
-		table.style.cursor = "hand";
-	
-	table.appendChild(tbody);
-	content_id_0.appendChild(table);
-}
-	var idx_cc = 0;
-function draw_plugin_cc(ID, addrs)
-{
-	expresso.connector.loadScript("ccQuickAdd");
-
-	var array_addrs = '';
-	var array_name 	= '';	
-	var cc_data = new Array();
-	if(typeof(addrs.name) != 'undefined') {	
-		array_name 	= LTrim(addrs.name).split(" ");
-		array_addrs = new Array(addrs.email);		
-	}
-	else {
-		array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
-		array_name 	= LTrim(array_addrs[0]).replace('"','').split(" ");	
-	}
-
-	var _split = array_name[0].split('@');
-	cc_data[0] = _split[0];
-	cc_data[1] = _split[0];
-	cc_data[2] = '';
-
-	for (i=1; i < array_name.length; i++)
-		cc_data[2] += array_name[i] + " ";			
-	
-
-	if(array_addrs.length > 1)			
-		cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';		
-	else
-		cc_data[3] = array_addrs[0];
-	
-	var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
-	'" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="./templates/'+template+'/images/user_card.png">';
-	var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
-	to_addybook_add += addrs;
-	to_addybook_add +=  sm_envelope_img1;
-	idx_cc++;
-	to_addybook_add += "</SPAN>";
-	return to_addybook_add;
-}
-function deny_email(email){
-	expresso.connector.loadScript("filter");
-	expresso.connector.loadScript("filters");
-	var dn_em 	= document.createElement("SPAN");
-		dn_em.id = "tt_d";
-		dn_em.onclick = function(){filter_rules.new_rule(email);};
-		dn_em.setAttribute("title",get_lang("Block Sender"));
-		dn_em.style.cursor = "pointer";		
-		dn_em.innerHTML = "<img align='top' onclick=filter.new_rule('"+email+"') src='./templates/"+template+"/images/deny.gif'>";
-	return dn_em;
-	
-}
-function show_div_address_full(id, type) {
-	var div_address_full = Element("div_"+type+"address_full_"+id);
-	if(!div_address_full) {
-		div_address_full = document.createElement("SPAN");
-		div_address_full.id = "div_"+type+"address_full_"+id;	
-		div_address_full.style.display="none";	
-		var _address = eval(type+"address_array['"+id+"']");
-		var isOverLimit = (_address.length > 100);
-		
-		if(isOverLimit) {
-			alert("Esse campo possui muitos endereços ("+_address.length+" destinatários).\r\n"+
-			"Para evitar o travamento do navegador, o botão 'Adicionar Contato' foi desabilitado!");
-		}
-
-		for(var idx = 1 ; idx  < _address.length;idx++) {
-			div_address_full.innerHTML += isOverLimit ?  '<br>'+_address[idx] : ','+draw_plugin_cc(id,_address[idx]);
-		}		
-		div_address_full.innerHTML += " (<a STYLE='color: RED;' onclick=document.getElementById('div_"+type+"address_full_"+id+"').style.display='none';document.getElementById('div_"+type+"address_"+id+"').style.display='';>"+get_lang('less')+"</a>)";
-		Element(type+"_"+id).appendChild(div_address_full);
-	}
-	Element('div_'+type+'address_'+id).style.display='none';
-	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/doiMenuData.js
===================================================================
--- trunk/expressoMail1_2/js/doiMenuData.js	(revision 2005)
+++ 	(revision )
@@ -1,285 +1,0 @@
-_icon_dir="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=\"templates/"+template+"/images/menu/"+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("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/DropDownContacts.js
===================================================================
--- trunk/expressoMail1_2/js/DropDownContacts.js	(revision 804)
+++ 	(revision )
@@ -1,327 +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 table_contacts_header = "<table style='font-family:arial;font-size:12;color:#0000CF' border=0 cellpadding=0 cellspacing=0>";
-	var table_contacts_foot = "</table>";
-	var lines = '';
-	var REG_EXP = /^[^\#|^\$|^\%|^\!|^\?|^\"|^\']+$/;
-	var match_cont = "";
-	for (var i=0; i<match_contacts.length; i++)
-	{
-		var aux = match_contacts[i].split("");
-		for(var j in aux){
-			if(REG_EXP.test(aux[j])){
-				match_cont += aux[j];
-			}else{
-				match_cont += "";
-			}
-		}
-		//lines = lines + "<tr><td id=td_DD_"+i+" onClick=\"javascript:hideTip();makeMailList('"+match_contacts[i]+"','"+fld_id+"');document.getElementById('" + fld_id + "').focus();\" onmouseover=\"selectContact("+i+")\">" + match_contacts[i] + "</td></tr>"
-		lines = lines + "<tr><td id=td_DD_"+i+" onMouseDown=\"javascript:hideTip();makeMailList('"+match_cont+"','"+fld_id+"');setTimeout('document.getElementById(\\'"+fld_id+"\\').focus()',300);\" onmouseover=\"selectContact("+i+")\">" + match_cont + "</td></tr>"
-		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 != ''){
-		table_contacts = table_contacts_header + lines + table_contacts_foot
-		doTooltip(posX, posY, table_contacts)
-	}
-	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() {
-            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 ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = 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;
-			}
-		}
-	}
-}
-Tooltip.init();
-// 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/color_palette.js
===================================================================
--- trunk/expressoMail1_2/js/color_palette.js	(revision 320)
+++ 	(revision )
@@ -1,96 +1,0 @@
-// Inicializa palheta de cores;
-function cColorPalette(){
-	this.editor;
-	this.div;
-	this.parentDiv;
-	this.colors = new Array(	new Array("#FFFFFF","#FFCCCC","#FFCC99","#FFFF99","#FFFFCC","#99FF99","#99FFFF","#CCFFFF","#CCCCFF","#FFCCFF"),
-						new Array("#CCCCCC","#FF6666","#FF9966","#FFFF66","#FFFF33","#66FF99","#33FFFF","#66FFFF","#9999FF","#FF99FF"),
-						new Array("#C0C0C0","#FF0000","#FF9900","#FFCC66","#FFFF00","#33FF33","#66CCCC","#33CCFF","#6666CC","#CC66CC"),
-						new Array("#999999","#CC0000","#ff6600","#FFCC33","#FFCC00","#33CC00","#00CCCC","#3366FF","#6633FF","#CC33CC"),
-						new Array("#666666","#990000","#CC6600","#CC9933","#999900","#009900","#339999","#3333FF","#6600CC","#993399"),
-						new Array("#333333","#660000","#993300","#996633","#666600","#006600","#336666","#000099","#333399","#663366"),
-						new Array("#000000","#330000","#663300","#663333","#333300","#003300","#003333","#000066","#330099","#330033"));
-	this.buildPalette();
-}
-
-// funçoes
-cColorPalette.prototype.changeFontColor = function (color){	
-	var mainField = this.editor.contentWindow;
-	mainField.document.execCommand("forecolor", false, color);	
-	document.getElementById("palettecolor").style.visibility="hidden";
-	mainField.focus();
-}
-
-cColorPalette.prototype.repos = function (intElemScrollTop)
-{
-	var new_pos = findPosY(Element("forecolor")) - intElemScrollTop + 20;
-	this.div.style.top = new_pos;
-}
-
-cColorPalette.prototype.loadPalette = function (id)
-{
-	this.parentDiv = document.getElementById("body_position_"+id);
-	this.editor = document.getElementById("body_"+id);
-	if(this.div.parentNode)
-		this.div.parentNode.removeChild(this.div);	
-
-	this.parentDiv.appendChild(this.div);	
-	this.div.style.position = "absolute";
-
-	if(is_ie)
-	{
-		this.div.style.top = findPosY(Element("forecolor")) - 100;
-		this.div.style.left = findPosX(Element("forecolor"))- 200;
-	}
-	else
-	{
-		this.div.style.top = ColorPalette.repos(Element("div_message_scroll_"+id).scrollTop);
-		this.div.style.left = findPosY(Element("forecolor"))+ 227;
-	}
-}
-
-cColorPalette.prototype.buildPalette = function (){
-	
-  	this.div = document.createElement("DIV");
-	this.div.style.visibility="hidden";
-  	this.div.id= "palettecolor";
-  	this.div.style.top = "0px";
-  	this.div.style.left = "0px";
-  	this.div.style.width	= "auto";
-  	this.div.style.height= "auto";
-  	var t1 = document.createElement("TABLE");
- 	var tb1 = document.createElement("TBODY");
- 	t1.appendChild(tb1);
-  	t1.border ="1px";
-	t1.cellPadding ="0px";
-	t1.cellSpacing ="0px";
- 	t1.style.width = "100px";
- 	t1.bgcolor = "WHITE";
-  	this.div.appendChild(t1);
-  	_this = this;
-  	for( i = 0; i < 10; i++) {
-  		var _tr = document.createElement("TR");
-		tb1.appendChild(_tr);		
-  		for( j = 0; j < 7; j++) {
-			var _td = document.createElement("TD");
-  			_td.style.background =  this.colors[j][i];
-	  		_td.unselectable = "on";
-  			_td.style.width = "15px";
-  			_td.style.height = "15px";
-  			_td.title =   this.colors[j][i];
-  			_td.id =   this.colors[j][i];
-  			_td.className = "unsel_color";
-	  		_td.onclick= function(){ document.getElementById("palettecolor").style.visibility="hidden";ColorPalette.changeFontColor(this.id);};
-	  		_td.onmouseover = function(){ this.className = "sel_color";};
-	  		_td.onmouseout = function(){ this.className = "unsel_color";}
-			var p = new Image();
-  			p.style.width='1px';
-  			p.style.height='1px';
-			_td.appendChild(p);
-	  		_tr.appendChild(_td);
-  		}
-	}
-}
-
-/* Build the Object */
-var ColorPalette = new cColorPalette();
Index: trunk/expressoMail1_2/js/QuickCatalogSearch.js
===================================================================
--- trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 1610)
+++ 	(revision )
@@ -1,539 +1,0 @@
-	function emQuickCatalogSearch ()
-	{
-		this.arrayWin = new Array();
-		this.el;
-		this.cc_contacts = new Array();
-		this.cc_groups  = new Array();
-	}
-
-	emQuickCatalogSearch.prototype.showList = function(data, begin, end){
-		id = '1';
-		_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 = 'window_QuickCatalogSearch';
-		document.body.appendChild(el);
-		el.innerHTML = "";
-		
-		if (document.getElementById('select_QuickCatalogSearch') == null){
-
-			var title_innerHTML = get_lang('Select a name') + ':';
-			if (data.quickSearch_only_in_userSector)
-				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
-
-			var title = document.createElement("SPAM");
-			title.id = 'window_QuickCatalogSearch_title';
-			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
-			el.appendChild(title);
-			
-			var cmb = document.createElement("SELECT");
-			cmb.id = "select_QuickCatalogSearch";
-			cmb.style.width = "685px";
-			cmb.size = "12";
-			cmb.onkeypress = function (e)
-			{
-				if (is_ie)
-				{
-					if ((window.event.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((window.event.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-				else
-				{
-					if ((e.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((e.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-			};
-			el.appendChild(cmb);
-
-			var space = document.createElement('SPAN');
-			space.innerHTML = "<BR>&nbsp;&nbsp;";
-			el.appendChild(space);
-
-			var butt = document.createElement('BUTTON');
-			var buttext = document.createTextNode('OK');
-			butt.id = "QuickCatalogSearch_button_ok";
-			butt.appendChild(buttext);
-			butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			el.appendChild(butt);
-
-			var space = document.createElement('SPAN');
-			space.innerHTML = "&nbsp;&nbsp;";
-			el.appendChild(space);
-
-			var butt = document.createElement('BUTTON');
-			butt.id = "QuickCatalogSearch_button_close";
-			var buttext = document.createTextNode(get_lang('Close'));
-			butt.appendChild(buttext);
-			butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
-			el.appendChild(butt);
-		}
-		else{
-			var title_innerHTML = get_lang('Select a name') + ':';
-			if (data.quickSearch_only_in_userSector)
-				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
-
-			var title = Element('window_QuickCatalogSearch_title');
-			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
-			
-			var cmb = document.getElementById('select_QuickCatalogSearch');
-			cmb.onkeypress = function (e)
-			{
-				if (is_ie)
-				{
-					if ((window.event.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((window.event.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-				else
-				{
-					if ((e.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((e.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-			};
-
-			for (i=0; i<cmb.length; i++)
-				cmb.options[i--] = null;
-			
-			var butt_ok = document.getElementById("QuickCatalogSearch_button_ok");
-			var butt_close = document.getElementById("QuickCatalogSearch_button_close");
-			butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
-		}
-
-		for (i=0; i<data.length; i++){
-			var Op = document.createElement("OPTION");
-			Op.text = data[i].cn + ' (' + data[i].mail + ')';
-			if (data[i].phone != '')
-				Op.text += ' - ' + data[i].phone;
-			if (data[i].ou != '')
-				Op.text += ' - ' + data[i].ou; // adicionado "data[i].ou" para exibir setor (F9)
-			Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
-			cmb.options.add(Op);
-		}
-		cmb.options[0].selected = true;
-		_this.showWindow(el);
-	}
-	
-	emQuickCatalogSearch.prototype.showWindow = function (div)
-	{
-		if(! div) {
-			alert(get_lang('The list has no participant.'));
-			return;
-		}
-							
-		if(! this.arrayWin[div.id]) {
-			div.style.width = "700px";
-			div.style.height = "230px";
-			var title = get_lang('The results were found in the Global Catalog')+':';
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-			div.style.width = div.offsetWidth - 5;
-
-			win = new dJSWin({			
-				id: 'QuickCatalogSearch_'+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];
-		}
-		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "";
-		win.open();
-		document.getElementById('select_QuickCatalogSearch').focus();
-	}
-	
-	emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){
-		cm = document.getElementById('select_QuickCatalogSearch');
-		option_selected = cm.options[cm.selectedIndex].value + ", ";
-		emailList = document.getElementById(field + "_" + ID).value;
-		
-		new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length);
-		document.getElementById(field + "_" + ID).value = new_emailList;
-		document.getElementById(field + "_" + ID).focus();
-		
-		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
-		this.arrayWin['window_QuickCatalogSearch'].close();
-	}
-	
-	emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){
-		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
-		document.getElementById(field + "_" + ID).focus();
-		this.arrayWin['window_QuickCatalogSearch'].close();
-	}
-
-	emQuickCatalogSearch.prototype.close_window = function(id) {
-		this.arrayWin[id].close();
-		var group_values = Element('list_values');
-		var user_values = Element('user_values');	
-	}
-	emQuickCatalogSearch.prototype.showCatalogList = function (border_id){
-		var el = Element('catalog_list');
-
-		if(el) {
-			Element('border_id').value = border_id;
-			win = this.arrayWin[el.id];
-			win.open();
-			return;		
-		}
-		var border_input   = document.createElement("INPUT");
-		border_input.type  = 'hidden';
-		border_input.id    = 'border_id';
-		border_input.value = border_id;
-		document.body.appendChild(border_input);
-		el = document.createElement("DIV");		
-		el.id = 'catalog_list';
-		document.body.appendChild(el);			
-		el.style.visibility = "hidden";
-		el.style.position = "absolute";
-		el.style.width = "700px";
-		el.style.height = is_ie ? "360px" : "375px";		
-		el.style.left = "0px";
-		el.style.top = "0px";			
-		el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+
-					   "<tr><td id='td1' style='cursor:pointer' align='center' onclick='QuickCatalogSearch.select_div(\"tab1\")'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab1\");'>"+get_lang('Global Catalog')+"</a></td>"+
-					   "<td id='td2' style='background:#cecece;cursor:pointer' onclick='QuickCatalogSearch.select_div(\"tab2\")' align='center'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab2\");'>"+get_lang('Personal Catalog')+"</a></td></tr>"+
-					   '</table>'+
-					   '<div id="tab1" align="center"><br>'+
-					   '<table border="0" cellpading="0" cellspacing="0">'+
-					   '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+'&nbsp;:</td></tr>'+
-  					'<tr><td><select style="display:none;width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select>&nbsp'+
-					'<select id="select_organization" style="width:150px" name="select_organization"></select>&nbsp;'+   
-					'<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="30"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:visible" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
-					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type_l" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" id="type_u" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
-					   '<span style="visibility:hidden;background:#cc4444" id=msg_search>&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font>&nbsp;</span></td></tr>'+
-					   '<tr><td>'+
-				  	   '<span id="list_span"><select multiple style="display:none;width:580px" size="14" id="list_values"></select></span>'+
-				  	   '<span id="user_span"><select multiple style="width:580px" size="14" id="user_values"></select></span>'+
-				 	   '</td></tr>'+
-					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to\')">&nbsp;'+
-				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')">&nbsp;'+
-				   	   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">'+
-				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
-					   '</table>'+
-					   '</div>'+
-					   '<div style="display:none" id="tab2" align="center">'+
-					   '<br><br><br>'+
-					   '<table border="0" cellpading="0" cellspacing="0">'+
-					   '<tr><td>'+get_lang("Select the type of contact that you want to view")+'&nbsp;:</td></tr>'+
-					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" type="radio" name="type" value="p"/>' + get_lang('People') + '&nbsp;&nbsp;<input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>' + get_lang('Groups') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
-					   '<tr><td>'+
-				  	   '<span id="personal_span"><select multiple style="width:580px" size="14" id="list_personal"></select></span>'+
-				  	   '<span id="groups_span"><select multiple style="display:none;width:580px" size="14" id="list_groups"></select></span>'+
-				 	   '</td></tr>'+
-					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to1\')">&nbsp;'+
-				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')">&nbsp;'+
-				   	   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">'+
-				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
-					   '</table>'+
-					   '</div>';
-
-		var title = get_lang('Search in the Global Catalog');
-		var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px";
-		var wWidth =  el.offsetWidth   + "px";
-		el.style.width = el.offsetWidth;
-		
-		Element('search_for').onkeypress = function (e) {
-			if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) {
-				QuickCatalogSearch.searchCatalogList(true);
-			}
-		};
-
-		win = new dJSWin({			
-			id: 'win_'+el.id,
-			content_id: el.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[el.id] = win;		
-		win.draw();
-		win.open();
-
-		var handler_catalogs = function(data){
-			var user_catalog = get_lang("Global Catalog");
-			if(data.length > 1) {
-				Element('select_catalog').style.display = '';
-				for(i = 0; i < data.length; i++) {		
-					Element('select_catalog').options[i] = new Option(data[i],i);
-					if(user_catalog.toUpperCase() == data[i].toUpperCase())
-						Element('select_catalog').options[i].selected = true;
-				}
-			}
-		}
-		cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs);		
-		
-		this.update_organizations();
-		var handler_cc_contacts= function(data){
-			if(data && data.length > 0){
-				var aux = data.split(",");
-				for(var i=0; i< aux.length; i++){
-					QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i];				
-				}
-			}
-		}
-		cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts);
-
-		var handler_cc_groups = function(data){
-			if(data && data.length > 0){
-				var aux = data.split(",");
-				for(var i=0; i < data.length; i++){
-					QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i];								
-				}	
-			}
-		}
-		cExecute("$this.db_functions.get_cc_groups",handler_cc_groups);
-	
-	}
-	
-	emQuickCatalogSearch.prototype.select_div = function(element){
-		if(element == 'tab1'){
-		   Element('tab1').style.display = '';
-		   Element('tab2').style.display = 'none';
-		   Element('td1').style.background = '#eee';	
-		   Element('td2').style.background = '#cecece';
-		}
-		if(element == 'tab2'){
-		   Element('tab1').style.display = 'none';
-		   Element('tab2').style.display = '';
-		   Element('td1').style.background = '#cecece';
-		   Element('td2').style.background = '#eee';		   
-
-		}
-	}
-	
-	emQuickCatalogSearch.prototype.load_catalog = function(){
-	
-		var _this = this;
-		var content = new Array;
-		var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal');
-		
-		if(Element('list_personal').style.display == 'none'){
-			content = _this.cc_groups;
-		}else{
-			content = _this.cc_contacts;
-		}
-		if(select.options.length > 0){
-			for(var i=0; i < select.options.length; i++){
-				select.options[i] = null;
-				i--;
-			}
-		}
-		for(var i=0; i < content.length; i++){
-			if(content[i] != undefined){
-				var aux = content[i].split(";");
-				var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false);
-				select[select.length] = opt;
-			}
-		}
-		content.splice(0,(content.lenght));
-	}
-
-	emQuickCatalogSearch.prototype.update_organizations = function(){
-		while(Element('select_organization').options.length > 0) {
-			Element('select_organization').remove(0);
-		}
-	 	var handler_org = function(data){
-			Element('select_organization').options[0] = new Option(get_lang('all'),'all');
-			if (data != null){
-				var user_organization = Element('user_organization').value;
-				for(x = 0; x < data.length; x++) {
-					Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]);
-					if(user_organization.toUpperCase() == data[x].toUpperCase())
-						Element('select_organization').options[x+1].selected = true;
-				}
-			}
-		}		
-		cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org);		
-	}
-
-	emQuickCatalogSearch.prototype.changeOptions = function(type){	
-
-		switch(type){
-			case 'u':
-				Element('list_values').style.display = 'none';
-				Element('user_values').style.display = '';
-				break;
-			
-			case 'l':		
-				Element('user_values').style.display = 'none';
-				Element('list_values').style.display = '';		
-				break;
-
-			case 'p':
-				Element('list_personal').style.display = '';
-				Element('list_groups').style.display = 'none'
-				QuickCatalogSearch.load_catalog();				
-				break;
-			
-			case 'g':
-				Element('list_personal').style.display = 'none';
-				Element('list_groups').style.display = ''
-				QuickCatalogSearch.load_catalog();
-				break;
-		}
-
-	}
-
-	emQuickCatalogSearch.prototype.addContacts = function(field) {
-		
-		var border_id 	= Element('border_id').value;
- 		var select		= Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values');
-		if(field == "to1" || field == "cc1" || field == "cco1"){
-			field = field.substr(0,field.length - 1);
-			var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal');
-		}
-		var fieldOpener = Element(field+"_"+border_id);
-		var not_selected = true;		
-		for (i = 0 ; i < select.length ; i++) {			
-			if (select.options[i].selected && select.options[i].value != '-1') {
-				if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length -1))){
-					fieldOpener.value += ",";
-				}
-				fieldOpener.value += select.options[i].value + ",";
-				not_selected = false;
-				select.options[i].selected = false;
-			}
-		}
-		
-		if(not_selected)
-			return false;
-			
-		if(field != 'to'){
- 			a_link = Element("a_"+field+"_link_"+border_id);
- 			if(a_link)
- 				a_link.onclick(); 			
- 		}				
-	}
-	
-	emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){
-
-		if(itemSearch && Element('search_for').value.length < preferences.search_characters_number){
-			alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
-			Element('search_for').focus();
-			return false;
-		}
-		var organization = Element('select_organization').value;		
-		var search		 = itemSearch ? Element('search_for').value : '';
-		var catalog		 = Element('select_catalog').value;
-		var max_result	= 400;
-
-		var handler_searchResults = function(data){
-			Element('msg_search').style.visibility = 'hidden';
-			if(data.error){
-				alert(get_lang('More than %1 results. Please, try to refine your search.',max_result));
-				return false;
-			}else if(data.users.length == 0 && data.groups.length == 0){
-				alert(get_lang('None result was found.'));
-			}
-
-			
-			var group = Element('list_span');
-			var user  = Element('user_span');	
-			if(is_ie){
-				group.innerHTML = '';
-				user.innerHTML = '';
-			}
-			else {
-				group = Element('list_values');
-				user  = Element('user_values');	
-				for(var i = 0;i < group.options.length; i++)				
-					group.options[i--] = null;
-				for(var i = 0;i < user.options.length; i++)				
-					user.options[i--] = null;
-			}
-
-			var arr 	= new Array(max_result);
-
-			for(i = 0; data.groups && i < data.groups.length; i++) {
-				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
-				if(is_ie)
-					arr[i] = '<option value="'+'&quot;'+data.groups[i].name+'&quot; &lt;'+data.groups[i].email+'&gt;">'+data.groups[i].name+' ('+data.groups[i].email+')'+'</option>';
-				else
-					group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>');
-			}
-	
-			
-			if(is_ie)
-				group.innerHTML = '<select multiple style="display:none;width:580px" size="14" id="list_values">'+ arr.join() +'</select>';
-
-			arr = new Array(max_result);
-			
-			for(i = 0; data.users && i < data.users.length; i++) {
-			/*******************************************************************************************/
-			/* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela,
-			ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o
-			resultado apresentado em tela sera exibido de maneira mais apresentavel;
-			*/
-				//verifica se departamento eh null ou nao;
-				var department = data.users[i].department ? " - " + data.users[i].department : "";
-				//verifica se email eh null ou nao;
-				var email = data.users[i].email ? data.users[i].email : "";
-
-				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
-				if(is_ie)
-					arr[i] = '<option value="'+'&quot;'+data.users[i].name+'&quot; &lt;'+email+'&gt;">'+data.users[i].name+' ('+email+')'+department+'</option>';
-				else {
-					user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email;
-				}
-			}
-	
-			if(is_ie)
-				user.innerHTML = '<select multiple style="width:580px" size="14" id="user_values">'+ arr.join() +'</select>';
-
-			// Display entries found.
-			var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u';
-			Element("type_"+type).checked = true;
-			QuickCatalogSearch.changeOptions(type);
-		}
-
-		Element('msg_search').style.visibility = 'visible';
-		cExecute ("$this.ldap_functions.catalogsearch&max_result="+max_result+"&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults);
-	}
-
-	
-/* Build the Object */
-	var QuickCatalogSearch;
-	QuickCatalogSearch = new emQuickCatalogSearch();
Index: trunk/expressoMail1_2/js/rich_text_editor.js
===================================================================
--- trunk/expressoMail1_2/js/rich_text_editor.js	(revision 2170)
+++ 	(revision )
@@ -1,506 +1,0 @@
-function cRichTextEditor(){
-	this.emwindow   = new Array;
-	this.editor = "body_1";
-	this.table = "";
-	this.id = "1";
-	this.buildEditor();
-	this.saveFlag = 0;
-}
-
-cRichTextEditor.prototype.loadEditor = function(ID) {
-	var _this = this;
-	_this.id = ID;
-	parentDiv = document.getElementById("body_position_"+this.id);
-	this.editor = "body_"+this.id;
-
-	if(this.table.parentNode)
-		this.table.parentNode.removeChild(this.table);
-	
-	if( parentDiv.firstChild )
-	{
-		if (!parentDiv.firstChild.hasChildNodes()) 
-			parentDiv.insertBefore(this.table,parentDiv.firstChild);
-	}
-	else
-		parentDiv.appendChild(this.table);
-
-	if(!Element(this.editor))
-	{
-		this.createElementEditor(this.editor);
-	}
-	else
-	{
-		Element("viewsource_rt_checkbox").checked=false;
-	}
-
-	document.getElementById('fontname').selectedIndex = 0;
-	document.getElementById('fontsize').selectedIndex = 0;
-}
-
-cRichTextEditor.prototype.createElementEditor = function(pObj)
-{
-		iframe = document.createElement("IFRAME");
-		iframe.id = pObj;
-		iframe.name = pObj;
-		iframe.width = "99%";
-		iframe.height = 300;
-		iframe.setAttribute("unselectable","on");
-		iframe.setAttribute("tabIndex","1");
-
-		config_events( iframe, 'onload', function( )
-		{
-			iframe.contentWindow.document.designMode = "on";
-			if ( iframe.contentWindow.document.documentElement )
-				iframe.contentWindow.document.documentElement.style.background = '#fff';
-				iframe.contentWindow.document.documentElement.style.fontSize = '16px';
-		});
-
-		var checkbox = document.createElement("INPUT");
-		checkbox.id = 'viewsource_rt_checkbox';
-		checkbox.type = "checkbox";
-		checkbox.setAttribute("tabIndex","-1");
-		checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)};
-		var text = document.createTextNode(get_lang('View HTML source') + '.');
-		parentDiv.appendChild(iframe);
-		parentDiv.appendChild(checkbox);
-		parentDiv.appendChild(text);
-}
-
-cRichTextEditor.prototype.viewsource = function(source) {
-	var html;
-	var mainField = document.getElementById(this.editor).contentWindow;
-	if (source) {
-		if (is_ie){
-			expresso.connector.loadScript('html2xhtml');
-			html = frames[this.editor].document.body;
-			var xhtml = get_xhtml(html, 'en', 'iso-8859-1');
-			frames[this.editor].document.body.innerText = xhtml;
-			document.getElementById("table_richtext_toolbar").style.visibility="hidden";
-		}
-		else{
-			html = document.createTextNode(document.getElementById(this.editor).contentWindow.document.body.innerHTML);
-			document.getElementById(this.editor).contentWindow.document.body.innerHTML = "";
-			html = document.getElementById(this.editor).contentWindow.document.importNode(html,false);
-			document.getElementById(this.editor).contentWindow.document.body.appendChild(html);
-			document.getElementById("table_richtext_toolbar").style.visibility="hidden";
-		}		
-	} else {
-		if (is_ie){
-			var output = escape(frames[this.editor].document.body.innerText);
-			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
-			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
-			frames[this.editor].document.body.innerHTML = unescape(output);
-			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
-		}
-		else{
-			html = document.getElementById(this.editor).contentWindow.document.body.ownerDocument.createRange();
-			html.selectNodeContents(document.getElementById(this.editor).contentWindow.document.body);
-			document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString();
-			document.getElementById("table_richtext_toolbar").style.visibility="visible";  
-		}
-	}
-}
-
-cRichTextEditor.prototype.buildEditor = function() {
-	this.table = document.createElement("TABLE");
-	this.table.id = "table_richtext_toolbar";
-	this.table.className = "richtext_toolbar";
-	this.table.width = "100%";
-	var tbody = document.createElement("TBODY");
-	var tr = document.createElement("TR");
-	var td = document.createElement("TD");
-	var div_button_rt = document.createElement("DIV");
-	
-	selectBox=document.createElement("SELECT");
-	selectBox.id="fontname";
-	selectBox.setAttribute("tabIndex","-1");
-	selectBox.onchange = function () {RichTextEditor.Select("fontname");};
-	selectBox.className = 'select_richtext';
-	var option1 = new Option(get_lang('Font'), 'Font');
-	var option2 = new Option('Arial', 'Arial');
-	var option3 = new Option('Courier', 'Courier');
-	var option4 = new Option('Times New Roman', 'Times');
-	if (is_ie){
-		selectBox.add(option1);
-		selectBox.add(option2);
-		selectBox.add(option3);
-		selectBox.add(option4);
-	}
-	else{
-		selectBox.add(option1, null);
-		selectBox.add(option2, null);
-		selectBox.add(option3, null);
-		selectBox.add(option4, null);
-	}
-	div_button_rt.appendChild(selectBox);
-
-	selectBox=document.createElement("SELECT");
-	selectBox.id="fontsize";
-	selectBox.setAttribute("tabIndex","-1");
-	selectBox.setAttribute("unselectable","on");
-	selectBox.className = 'select_richtext';
-	selectBox.onchange = function () {RichTextEditor.Select("fontsize");};
-	var option1 = new Option(get_lang('Size'), 'Size');
-	var option2 = new Option('1 (8 pt)','1' );
-	var option3 = new Option('2 (10 pt)','2');
-	var option4 = new Option('3 (12 pt)','3');
-	var option5 = new Option('4 (14 pt)','4');
-	var option6 = new Option('5 (18 pt)','5');
-	var option7 = new Option('6 (24 pt)','6');
-	var option8 = new Option('7 (36 pt)','7');
-	if (is_ie){
-		selectBox.add(option1);
-		selectBox.add(option2);
-		selectBox.add(option3);
-		selectBox.add(option4);
-		selectBox.add(option5);
-		selectBox.add(option6);
-		selectBox.add(option7);
-		selectBox.add(option8);
-	}
-	else{
-		selectBox.add(option1, null);
-		selectBox.add(option2, null);
-		selectBox.add(option3, null);
-		selectBox.add(option4, null);
-		selectBox.add(option5, null);
-		selectBox.add(option6, null);
-		selectBox.add(option7, null);
-		selectBox.add(option8, null);	
-	}
-	div_button_rt.appendChild(selectBox);
-	
-	var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull',
-				   'undo', 'redo', 'insertorderedlist', 'insertunorderedlist', 'outdent', 'indent', 'link', 'image', 'table', 'signature'];
-
-	for (var i=0; i<buttons.length; i++){
-		var img = document.createElement("IMG");
-		img.id = buttons[i];
-		img.className = 'imagebutton';
-		img.align = 'center';
-		img.src = './templates/'+template+'/images/'+buttons[i]+'.gif';
-		img.title = get_lang(buttons[i]);
-		img.style.cursor = 'pointer';
-
-		if (buttons[i] == 'forecolor')
-			img.onclick = function () {RichTextEditor.show_pc('forecolor')};
-		else if (buttons[i] == 'link')
-			img.onclick = function () {RichTextEditor.createLink();};
-		else if (buttons[i] == 'image')
-			img.onclick = function () {RichTextEditor.createImage();};
-		else if (buttons[i] == 'table')
-			img.onclick = function () {RichTextEditor.createTable();};
-		else
-			img.onclick = function () {RichTextEditor.editorCommand(this.id,'');};
-		
-		img.onmouseover = function () {this.style.border="outset 2px";};
-		img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";};
-		div_button_rt.appendChild(img);
-	}
-
-	td.appendChild(div_button_rt);
-	tr.appendChild(td);
-	tbody.appendChild(tr);
-	this.table.appendChild(tbody);
-}
-
-cRichTextEditor.prototype.editorCommand = function(command, option) {
-	try {
-		var mainField = document.getElementById(this.editor).contentWindow;
-		mainField.focus();
-		var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>");
-		if (command == 'signature'){
-			if (is_ie){
-				var sel = document.selection;
-				if (sel!=null)
-				{
-				    var rng = sel.createRange();
-				    if (rng!=null)
-			        	rng.pasteHTML(signature);
-				}
-			}
-			else{
-				mainField.document.execCommand('inserthtml', false, signature);
-			}
-		}
-		else if (command == 'CreateLink')
-			mainField.document.execCommand('CreateLink', false, option);
-		else if (command == 'Table'){
-			if (is_ie){
-				var sel = document.selection;
-				if (sel!=null)
-				{
-				    var rng = sel.createRange();
-				    if (rng!=null)
-			        rng.pasteHTML(option);
-				}
-			}
-			else 
-				mainField.document.execCommand('inserthtml', false, option);
-			}
-		else if (command == 'Image')
-			mainField.document.execCommand('InsertImage', false, option);
-		else
-			mainField.document.execCommand(command, false, option);
-		//mainField.focus();
-    } catch (e) {/* alert(e);*/ }
-}
-
-cRichTextEditor.prototype.createLink = function(){
-	var mainField = document.getElementById(this.editor).contentWindow;
-	if (is_ie){
-		if ((mainField.document.selection.createRange().text) == ''){
-				alert(get_lang('Chose the text you want transform in link before.')); 
-			return;
-		}
-	}
-	else{
-		if (mainField.window.getSelection() == ''){
-				alert(get_lang('Chose the text you want transform in link before.')); 
-			return;
-		}
-	}
-		var szURL = prompt(get_lang('Enter with link URL:'), 'http://'); 
-	if ((szURL != null) && (szURL != "")){
-		this.editorCommand("CreateLink", szURL);
-	}
-}
-
-// It include the image file in emails body
-// It saves and attach in drafts folder and open it
-cRichTextEditor.prototype.addInputFile = function()
-{
-	//Begin: Verify if the image extension is allowed.
-	var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx");
-	var inputFile = document.getElementById('inputFile_img');	
-	if(!inputFile.value) 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;
-	}
-	// End: Verify image extension.
-	var id = this.editor.substr(5); // border_id
-	divFiles = document.getElementById("divFiles_"+id);
-	var countDivFiles = divFiles.childNodes.length + 1;
-
-	var divFiles = document.getElementById('divFiles_'+id);
-	inputFile.id = 'inputFile_'+id +"_"+countDivFiles;
-	inputFile.name = 'file_'+countDivFiles;
-	divFile = document.createElement('DIV');
-	divFile.appendChild(inputFile);
-	divFiles.appendChild(divFile);
-
-	var form_upload = document.getElementById('form_upload');
-	form_upload.parentNode.removeChild(form_upload);
-	win.close();
-
-	RichTextEditor.saveFlag = 0; // See if save function finished
-	var save_link = document.getElementById("save_message_options_"+id);
-	//save_link.onclick = function () {};
-	save_msg(id,true);
-	setTimeout("RichTextEditor.insertImgHtml("+id+")",1000);
-}
-
-cRichTextEditor.prototype.insertImgHtml = function (id){
-	if (RichTextEditor.saveFlag == 0)
-		setTimeout("RichTextEditor.insertImgHtml("+id+")",500);
-	else
-		if (RichTextEditor.saveFlag == 1)
-			this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=INBOX/'+draftsfolder+'&msg_num='+openTab.imapUid[id]+'&msg_part='+(openTab.countFile[id]+1));
-			// this.editorCommand('Image', '.inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params'));
-}
-
-cRichTextEditor.prototype.insertTableHtml = function (){
-	var id = this.editor.substr(5); // border_id
-	var	rows = document.getElementById('rows').value;
-	var	cols = document.getElementById('cols').value;
-	var border = document.getElementById('border').value;
-	var insertTable = '<table border="'+border+'px"><tbody>';
-	for (var i = 0; i < rows; i++){
-		insertTable += "<tr>";	
-		for (var j = 0; j < cols; j++)
-			insertTable += "<td>&nbsp;</td>";	
-		insertTable += "</tr>";
-	}
-	insertTable += "</tbody></table>";
-	this.editorCommand('Table', insertTable);
-}
-
-cRichTextEditor.prototype.createTable = function(){
-	var form = document.getElementById("table_window");
-	if (form == null){
-		form = document.createElement("DIV");
-		form.id  = "table_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);
-	}
-		
-		var form_table = document.createElement("DIV");
-		form_table.id = "form_table";
-		form_table.style.position = "absolute";
-		form_table.style.top = "5px";
-		form_table.style.left = "5px";
-		form_table.style.width = "190px";
-		form_table.style.height = "90px";
-		form_table.name = get_lang("Insert Table");		
-		form_table.innerHTML = get_lang('Select the table size')+':<br><br><table cellspacing="0"><tbody><tr><td align="center">'+
-								get_lang('Rows')+':</td><td></td><td align="center">'+get_lang('Cols')+':</td><td></td><td align="center">'+get_lang('Border')+':</td></tr>'+
-									'<tr><td align="right"><input type="text" readonly="true" id="rows" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'rows\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'rows\');"></img></td>'+
-									'<td align="right"><input type="text" readonly="true" id="cols" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'cols\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'cols\');"></img></td>'+
-									'<td align="right"><input type="text" readonly="true" id="border" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'border\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'border\');"></img></td>'+
-									'</tr></tbody></table>'+
-	  								'&nbsp;&nbsp;&nbsp;<input title="'+get_lang('Close')+'"  value="' + get_lang('Close') + '" type="button" onclick="win.close()">&nbsp;'+
-									'<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '" type="button" onclick="RichTextEditor.insertTableHtml();win.close();">';	
-		form.appendChild(form_table);
-		
-		this.showWindow(form);
-		}
-
-cRichTextEditor.prototype.incrementField = function(id_val){
-	var field_text = document.getElementById(id_val);
-	field_text.value = parseInt(field_text.value)+1;
-}
-
-cRichTextEditor.prototype.decrementField = function(id_val){
-	var field_text = document.getElementById(id_val);
-	if (parseInt(field_text.value) > 0)
-		field_text.value = parseInt(field_text.value)-1;
-}
-
-cRichTextEditor.prototype.createImage = function(){
-	if (preferences.auto_save_draft == 1){
-			autosave_time = 200000;
-			clearTimeout(openTab.autosave_timer[currentTab]);
-		}
-	var form = document.getElementById("attachment_window");
-	if (form == null){
-		form = document.createElement("DIV");
-		form.id  = "attachment_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);
-	}
-		var form_upload = Element('form_upload');
-		if (form_upload == null)
-			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("Upload File");
-		form_upload.style.width = "450px";
-		form_upload.style.height = "75px";
-		form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+
-								'<input name="image_at" maxlength="255" size="50" id="inputFile_img" type="file"><br>' +
-								'<input title="' + get_lang('Include') + '"  value="' + get_lang('Include') + '"' + 'type="button" onclick="RichTextEditor.addInputFile();">&nbsp;' +
-								'<input title="' + get_lang('Close') + '"  value="' + get_lang('Close') + '"' +
-								' type="button" onclick="win.close()">';
-		form.appendChild(form_upload);
-		
-		this.showWindow(form);
-}
-cRichTextEditor.prototype.showWindow = function (div){
-
-		if(! div) {
-			return;
-		}
-		
-		if(! this.emwindow[div.id]) {
-			div.style.width  =  div.firstChild.style.width;
-			div.style.height = div.firstChild.style.height;
-			div.style.zIndex = "10000";			
-			var title = div.firstChild.name;
-			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.emwindow[div.id] = win;
-			win.draw();
-		}
-		else
-			win = this.emwindow[div.id];
-		win.open();	
-}
-
-cRichTextEditor.prototype.Select = function(selectname)
-{
-	var mainField = Element(this.editor).contentWindow;
-	var cursel = document.getElementById(selectname).selectedIndex;
-
-	if (cursel != 0) {
-		var selected = document.getElementById(selectname).options[cursel].value;
-		mainField.document.execCommand(selectname, false, selected);
-		document.getElementById(selectname).selectedIndex = cursel;
-	}
-	mainField.focus();
-}
-
-cRichTextEditor.prototype.show_pc = function(command)
-{
-	expresso.connector.loadScript("color_palette");
-	ColorPalette.loadPalette(this.id);
-  	if (ColorPalette.div.style.visibility != "visible")
-		ColorPalette.div.style.visibility="visible";
-	else
-		this.hide_pc();
-}
-
-cRichTextEditor.prototype.hide_pc = function()
-{
-	document.getElementById("palettecolor").style.visibility="hidden";
-}
-
-cRichTextEditor.prototype.getOffsetTop = function(elm) {
-  var mOffsetTop = elm.offsetTop;1
-  var mOffsetParent = elm.offsetParent;
-  while(mOffsetParent){
-    mOffsetTop += mOffsetParent.offsetTop;
-    mOffsetParent = mOffsetParent.offsetParent;
-  }
-  return mOffsetTop;
-}
-
-cRichTextEditor.prototype.getOffsetLeft = function(elm) {
-  var mOffsetLeft = elm.offsetLeft;
-  var mOffsetParent = elm.offsetParent;
-  while(mOffsetParent){
-    mOffsetLeft += mOffsetParent.offsetLeft;
-    mOffsetParent = mOffsetParent.offsetParent;
-  }
-  return mOffsetLeft;
-}
-
-//Build the Object
-RichTextEditor = new cRichTextEditor();
Index: trunk/expressoMail1_2/js/TreeShow.js
===================================================================
--- trunk/expressoMail1_2/js/TreeShow.js	(revision 2402)
+++ 	(revision )
@@ -1,315 +1,0 @@
-/**************************************************************************\
- Início 
-\**************************************************************************/
-
-	function Tree_Box(){
-		
-		this.name_folder = "";
-		this.name_func   = "";
-		expresso.connector.loadScript("TreeS");
-	}
-	Tree_Box.prototype.update_folder = function(){
-
-		var handler_update_folders = function(data){
-			folders = data;
-			// update element dftree_folders_tree;
-			ttree.make_tree(data,"div_tree","folders_tree","ttree.get_folder(\"root\")",ttreeBox.name_folder,ttreeBox.name_folder,false);
-			
-			// update element dftree_tree_folders;
-			if(Element('content_folders')){Element('content_folders').innerHTML = "";}
-			draw_tree_folders(folders);
-			
-			// update element dftree_wfolders_tree;
-			if (Element('dftree_wfolders_tree')){
-				Element('dftree_wfolders_tree').innerHTML = '';
-				ttree.make_tree(data,"wfolders_content_tree","wfolders_tree","","","",false);	
-			}
-			ttree.FOLDER = ttreeBox.name_folder;
-			if (tree_folders.getNodeById(ttree.FOLDER))
-				tree_folders.getNodeById(ttree.FOLDER)._select();
-			/*
-			if (tree_folders.getNodeById(get_current_folder()))
-				tree_folders.getNodeById(get_current_folder())._select();
-			*/
-		}
-		if(!expresso_offline)
-		{
-			expresso.connector.cacheNextRequest(1);
-			cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, handler_update_folders);		
-		}
-		else
-			handler_update_folders('');
-	}
-
-	Tree_Box.prototype.verify_children = function(param){
-		var aux;
-		var aux1;
-		var cont = parseInt(0);
-		for(var i=0 ; i < folders.length; i++){
-			aux = folders[i].folder_id.split(cyrus_delimiter);
-			aux.pop();
-			for(var j=0; j < aux.length; j++){
-				if(j == 0)
-					aux1 = aux[j];
-				else
-					aux1 += cyrus_delimiter + aux[j];
-			}
-			if( aux1 == param){
-				cont++;
-			}
-		}
-		if( cont == 0){
-			ttreeBox.del_past(param);
-		}else{
-                       alert(get_lang("Delete your sub-folders first"));
-		}
-		cont = parseInt(0);
-	}
-	
-	Tree_Box.prototype.verify = function(exp)
- 	{
-                // IE does not understand regExp!!!
-		if (is_ie)
-			var reTipo = /[^a-z0-9 \-_+=]*$/i;
-		else
-			reTipo = /[^a-z0-9 \-_=áéíóúàèìòùâêôãõÃÕÁÉÍÓÚÀÈÌÒÙÂÊÔçÇüñ]/i;
-			
-        return reTipo.test(exp);
- 	}
-
- 	// Função para verificar o nome da caixa;
- 	Tree_Box.prototype.verify_names = function(name_folder){
-	    var arr_nm_folder = new Array("INBOX",trashfolder,draftsfolder,sentfolder,spamfolder);
- 		for(var i=0 ; i < arr_nm_folder.length; i++){
- 			if(name_folder == arr_nm_folder[i]){
-				ttree.FOLDER = "";
-				return true;
- 			}
- 		}
-		return false;
- 	}
-	
-	// Valida os nomes das pastas
-	Tree_Box.prototype.validate = function(func){
-		var aux = ttree.FOLDER.split(cyrus_delimiter);
-		var aux2;
-		if(ttree.FOLDER != ""){
-			if(aux.length > 1)
-			{
-				aux2 = aux[1];
-			}
-			else
-			{
-				aux2 = aux[0];
-			}
-			if(func == "rename" && this.verify_names(aux2)){
-			       alert(get_lang("It's not possible rename the folder: ") + lang_folder(aux2));
-			       return false;
-			}else{
-			if(func == "newpast"){
-	                    var button = prompt(get_lang('Enter the name of the new folder:'),"");
-					if (button.indexOf("local_") != -1  || button.toUpperCase() == "INBOX") {
-						alert(get_lang("cannot create folder. try other folder name"));
-						return false; //Não posso criar pastas contendo a string local_					
-					}
-
-					if(trim(button) == "" || trim(button) == null){
-						return false;
-					}else{
-						ttreeBox.new_past(button);
-					}
-				}
-				if(func == "rename"){
-					if(ttree.FOLDER == "root"){
-	                	alert(get_lang("It's not possible rename this folder!"));
-						return false;
-					}
-					if(ttree.FOLDER == get_current_folder()){
-                        alert(get_lang("It's not possible rename this folder, because it is being used in the moment!"));
-						return false;
-					}
-                    var button1 = prompt(get_lang("Enter a name for the box"), "");
-					if (button1.indexOf("local_") != -1 || button1.toUpperCase() == "INBOX") {
-						alert(get_lang("cannot create folder. try other folder name"));
-						return false; //Não posso criar pastas contendo a string local_					
-					}
-					if(trim(button1) == "" || trim(button1) == null){
-						return false;
-					}else{
-						ttreeBox.rename(button1);
-					}
-				}
-			}
-		}else{
-            alert(get_lang("Select a folder!"));
-			return false;
-		}
-	}
-
-// Para criar a nova pasta;
-	Tree_Box.prototype.new_past = function(newp){
-
-		var aux   = ttree.FOLDER.split(cyrus_delimiter);
-		var newp2 = "";
-		if( aux[0] == "root"){
-			if(this.verify(newp)){
-				alert(get_lang("The folder name must not contain special characters."));
-				newp = "";
-				return false;
-			}else{
-				newp2 = newp;
-				newp = "INBOX" + cyrus_delimiter + newp;
-			}
-		}else{
-			if(this.verify(newp)){
-				alert(get_lang("The folder name must not contain special characters."));
-				newp = "";
-				return false;
-			}else{
-				newp2 = newp;
-				newp = ttree.FOLDER + cyrus_delimiter + newp;
-			}
-		}
-
-		if(newp != ""){
-			var handler_return = function(data){		
-				if(data != "Ok"){
-					alert(get_lang(data));
-				}else{
-					ttreeBox.name_folder = "root"; //or use var newpast
-					this.name_func = "newpast";
-					expresso.connector.purgeCache();
-					ttreeBox.update_folder();
-				}
-			}
-			var args = "$this.imap_functions.create_mailbox";
-			var params = "newp="+newp;
-			cExecute(args,handler_return,params);
-		}	
-	}
-	
-	// Funcao para renomear a pasta;
-	Tree_Box.prototype.rename = function(rename){
-		var old_box  = ttree.FOLDER;
-		var aux = old_box.split(cyrus_delimiter);
-		var rename_new = "";
-		
-		if(old_box == "root"){
-            alert(get_lang("Select a folder!"));
-			return false;
-		}
-		if(aux.length == 1){
-            alert(get_lang("It's not possible rename the folder: ") + aux[0]);
-			rename = "";
-			return false;
-		}else{
-			if(this.verify_names(aux[1])){
-                alert(get_lang("It's not possible rename the folder: ") + aux[1]);
-				rename = "";
-				return false;
-			}else{
-				if(this.verify(rename)){
-                    alert(get_lang("The folder name must not contain special characters."));
-					rename = "";
-					return false;
-				}else{
-					aux.pop();
-					aux.push(rename);
-					for(var i=0; i< aux.length; i++){
-						if( i == 0)
-							rename_new = aux[i];
-						else
-							rename_new += cyrus_delimiter + aux[i];
-					}
-				}	
-			}
-		}
-		if(rename != ""){
-			var handler_return = function(data)
-			{
-				if (data != "Ok") {
-					alert(get_lang(data));
-				}
-				else {
-					expresso.connector.purgeCache();
-					ttreeBox.name_folder = "root";
-					ttreeBox.update_folder();
-				}
-			}
-			var args = "$this.imap_functions.ren_mailbox";
-			var params = "rename="+rename_new+"&current="+old_box;
-			cExecute(args,handler_return,params);
-		}
-	}
-	//
-	Tree_Box.prototype.export_all_msg = function(){
-			
-		if(ttree.FOLDER == "root"){return false;}
-		var nm_bx = ttree.FOLDER.split(cyrus_delimiter);
-		var name_f = nm_bx[nm_bx.length -1];
-		var hand_export = function(data){
-			if(!data){
-				write_msg(get_lang('Error compressing messages (ZIP). Contact the administrator.'))
-			}else if(data["empty_folder"]){
-				write_msg(get_lang("The selected folder is empty."));
-				alert(get_lang("The selected folder is empty."));
-			}else
-			  download_attachments(null, null, data, null,null, name_f +'.zip');
-		}
-		cExecute("$this.exporteml.export_all",hand_export,"folder="+ttree.FOLDER);	
-		write_msg(get_lang('You must wait while the messages will be exported...'));			
-	}
-	
-	// Função para deletar a pasta;
-	Tree_Box.prototype.del = function(){
-		var folder_name = ttree.FOLDER;
-		var aux = ttree.FOLDER.split(cyrus_delimiter);
-
-		if(aux[0] == "root" || ttree.FOLDER == ""){
-                        alert(get_lang("Select a folder!"));
-			return false;
-		}
-		
-		if(aux.length == 1){
-            alert(get_lang("It's not possible delete the folder: ") + get_lang("Inbox"));
-			return false;
-		}else{
-			if(this.verify_names(aux[1]) && typeof(aux[2]) == 'undefined'){
-	            alert(get_lang("It's not possible delete the folder: ") + get_lang(special_folders[aux[1]]));	 
-      			return false;
-			}else{
-				this.verify_children(folder_name);
-			}
-		}	
-	}
-	
-	Tree_Box.prototype.del_past = function(param){
-		var aux = param.split(cyrus_delimiter);
-		var aux1 = aux.pop();
-
-		if(ttree.FOLDER == get_current_folder()){
-            alert(get_lang("It's not possible delete this folder, because it is being used in the moment!"));
-			return false;
-		}
-        if(confirm(get_lang("Do you wish to exclude the folder ") + aux1+ "?")){
-			var handler_return = function(data)
-			{		
-				if(data != "Ok")
-				{
-					alert(data);
-				}else{
-					expresso.connector.purgeCache();
-					ttreeBox.name_folder = "root";
-					ttreeBox.update_folder();
-					write_msg(get_lang("The folder %1 was successfully removed", aux1));
-				}
-			}
-			var args = "$this.imap_functions.delete_mailbox";
-			var params = "del_past="+param;
-			cExecute(args,handler_return,params);
-		}
-	
-	}
-/* - Build Object -*/
- 	var ttreeBox;
-	ttreeBox = new Tree_Box();
Index: trunk/expressoMail1_2/js/preferences.js
===================================================================
--- trunk/expressoMail1_2/js/preferences.js	(revision 1308)
+++ 	(revision )
@@ -1,31 +1,0 @@
-/**************************************************************************\
- Início 
-\**************************************************************************/
-	function Preferences(){
-		this.prefeW 		= new Array;
-	}
-
-	// Salva uma unica preferencia
-	Preferences.prototype.save = function(key, value){
-		var _this = this;               
-		var handler_preferences = function(data){
-			if(data && data.success)
-				return;                 
-			else
-			alert(data);
-		}
-		preferences[key] = value;
-		var args   = "$this.db_functions.update_preferences";
-		var params = "prefe_string="+url_encode(connector.serialize(preferences));
-		cExecute(args,handler_preferences,params);
-	}
-
-	Preferences.prototype.delete_dynamic_contacts = function(){
-		var handler = function(data){}
-		var args   = "$this.dynamic_contacts.delete_dynamic_contacts";
-		var params = "";
-		cExecute(args,handler,params);
-	}
-// Cria o objeto	
-	var prefe;
-	prefe = new Preferences();
Index: trunk/expressoMail1_2/js/offline_access.js
===================================================================
--- trunk/expressoMail1_2/js/offline_access.js	(revision 1964)
+++ 	(revision )
@@ -1,65 +1,0 @@
-/**
- * @author diogenes
- */
-	function offline_access() {
-		this.login = null;
-		this.pass = null;
-		this.access = null;
-	}
-
-	offline_access.prototype.init = function (login,pass,access){
-		this.login = login;
-		this.pass = pass;
-		this.access = access;
-	}
-	
-	offline_access.prototype.fill_combo_of_users = function(users_combo) { 
-		
-		var users = expresso_local_messages.get_all_users();
-
-		for(var i in users) {
-					
-			var option = document.createElement('option');
-			option.value = i;
-			option.text = users[i];
-			try {
-				users_combo.add(option, null);
-			} 
-			catch (ex) {//I.E
-				users_combo.add(option);
-			}
-
-		}
-	}
-	
-	offline_access.prototype.do_login = function(uid_usuario,pass) {
-		control = expresso_local_messages.set_as_logged(uid_usuario,pass,false);
-		if(!control) {
-			document.getElementById('div_error').innerHTML = 'login ou senha inválida';
-		}
-		else {
-			document.location.href = 'offline.php';
-		}
-		
-	}
-	
-	offline_access.prototype.has_permition = function() {
-		var user_logged = expresso_local_messages.user_logged();
-		var d = new Date();
-
-		if(user_logged==null || d.getTime()>=user_logged[1]+60000) {
-			document.location.href = 'login_offline.php';
-		}
-		else	
-			account_id = user_logged[0];
-		
-	}
-
-	offline_access.prototype.do_logoff = function() {
-		expresso_local_messages.unset_as_logged();
-		location.href="login_offline.php"
-	}
-	
-
-	var expresso_offline_access;
-	expresso_offline_access = new offline_access();
