Index: trunk/expressoMail1_2/js/jscode/draw_api_messages.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2681)
+++ trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2694)
@@ -79,33 +79,14 @@
 	document.getElementById("message_header_"+(sort_box_type.lastIndexOf("SORT") != "-1" ? sort_box_type : "SORTARRIVAL")+"_"+numBox ).innerHTML = "<B>"+type_name+'</B><img src ="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/arrow_'+(sort_box_reverse == 1 ? 'desc' : 'asc')+'endant.gif">';
 }
-function draw_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 = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/down.button.png';
-	img_next_msg.title = get_lang('Next');
+
+function createNxtPrevButtons(info_msg,ID,folder_id){
+	var next_previous_msg_td = createAndSet("TD",[ "noWrap", "align", "width" ], [ "true", "right", "40px"]);
+	var img_next_msg = createAndSet("IMG", [ 'id', 'src', 'title' ], [
+			'msg_opt_next_' + ID,
+			URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/down.button.png',
+			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){
@@ -120,5 +101,4 @@
 				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);
 			};
 		}
@@ -138,9 +118,4 @@
 			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);
 			};
@@ -148,13 +123,10 @@
 	}
 	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 = URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/up.button.png';
-	img_previous_msg.title = get_lang('Previous');
+        img_space.innerHTML = "&nbsp;";
+	var img_previous_msg = createAndSet("IMG",['id','src','title'],['msg_opt_previous_' + ID,
+			URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/up.button.png',
+			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){
@@ -174,5 +146,4 @@
 				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);
 			};
@@ -199,205 +170,9 @@
 	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 ='" + URL_SERVER + "expressoMail1_2/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="' + URL_SERVER + 'expressoMail1_2/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='" + URL_SERVER + "expressoMail1_2/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="' + URL_SERVER + 'expressoMail1_2/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('hide details')+"</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('show details');
-				this.value = 'more_options';
-				Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
-				Element('table_message_others_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('show details');
-		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_options = document.createElement("IMG");
-		option_reply_options.id = 'msg_opt_reply_options_'+ID;
-		option_reply_options.onmouseover = function(){
-				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/over.png';
-		};
-		option_reply_options.onmouseout = function(){
-			if (this.value == 'show')
-			{
-				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/down.png';
-			}
-			else
-			{
-				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/pressed.png';
-			}
-		};
-		option_reply_options.onclick = function(){
-			if (this.value == 'show'){
-				this.value = 'hide';
-				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/pressed.png';
-				Element('tr_other_options_'+ID).style.display = '';
-
-			}
-			else{
-				this.value = 'show';
-				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/down.png';
-				Element('tr_other_options_'+ID).style.display = 'none';
-			}
-		};
-		option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/down.png';
-		option_reply_options.value = 'show';
-		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_options);
-		options.appendChild(option_reply);
-
-		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_reply_without_history		= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_without_history","'+ID+'");>'+get_lang("Reply without history")+'</span>';
-		var option_reply_to_all					= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_to_all_with_history","'+ID+'");>'+get_lang("Reply to all")+'</span> | ';
-
-		var option_reply_to_all_without_history	= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_to_all_without_history","'+ID+'");>'+get_lang("Reply to all without history")+'</span> | </div>';
-
-		div_other_options.innerHTML = option_reply_to_all + option_reply_to_all_without_history + option_reply_without_history;
-		if (use_spam_filter) {
-			if(info_msg.msg_folder == 'INBOX'+cyrus_delimiter+'Spam')
-				div_other_options.innerHTML += ' | <span class="reply_options" onclick="nospam('+info_msg.msg_number+',\'null\', \''+info_msg.msg_folder+'\')";>'+get_lang("Not Spam")+'</span>';	
-			else
-				div_other_options.innerHTML += ' | <span class="reply_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)
-		{
+	return next_previous_msg_td;
+
+}
+
+function putSignature(ID,info_msg){
 			var tr_signature = document.createElement("TR");
 			var td_signature = document.createElement("TD");
@@ -442,5 +217,5 @@
 
 			tr_signature.appendChild(td_signature);
-			tbody_message_options.appendChild(tr_signature);
+			return tr_signature;
 			/******************************************* Old signature   ***********************************************/
 			//if (info_msg.signature != "void")
@@ -449,6 +224,181 @@
 			//	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 ////////////////
+}
+
+
+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;
+
+	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;
+	}
+
+	var next_previous_msg_td = createNxtPrevButtons(info_msg,ID,folder_id);
+	if (typeof(next_previous_msg_td) == 'undefined')
+		return;
+
+	var table_message = createAndSet("TABLE",['border','width'],["0",defaultWidth]);
+	var tbody_message = document.createElement("TBODY");
+
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	//Make the options message.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	var tr0 = document.createElement("TR");
+	tr0.className = "tr_message_header";
+	var td0 = document.createElement("TD");
+	var table_message_options = createAndSet("TABLE",['border','width','class'],["0","100%",'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 ='" + URL_SERVER + "expressoMail1_2/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="' + URL_SERVER + 'expressoMail1_2/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='" + URL_SERVER + "expressoMail1_2/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="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/notification.gif">';
+	}
+
+	// NORMAL MSG
+	if(info_msg.Draft != 'X')
+	{
+		var options = createAndSet("TD",['noWrap','width','align'],['true','30%','right']);
+		var option_hide_more = createAndSet("SPAN",['class','value','id'],['message_options','more_options','option_hide_more_'+ID],get_lang('show details'));
+		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('hide details')+"</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('show details');
+				this.value = 'more_options';
+				Element("div_message_scroll_"+ID).style.height = (_height + _offset)+"px";
+				Element('table_message_others_options_'+ID).style.display = 'none';
+			}
+		};
+		var option_mark = createAndSet("TD",['width','align'],['50%','left']);
+
+		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;
+
+		var option_forward = createAndSet("SPAN",['id','class'],['msg_opt_forward_'+ID, 'message_options'],get_lang('Forward'));
+		option_forward.onclick = function(){new_message('forward', ID);};
+		appendChilds(options,option_hide_more,createAndSet('SPAN',false,false,'&nbsp;|&nbsp;'),option_forward);
+		var option_reply_options = createAndSet("IMG",['id', 'src', 'value'],['msg_opt_reply_options_'+ID,URL_SERVER+'expressoMail1_2/templates/default/images/down.png','show']);
+		option_reply_options.onmouseover = function(){
+				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/over.png';
+		};
+		option_reply_options.onmouseout = function(){
+			if (this.value == 'show')
+			{
+				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/down.png';
+			}
+			else
+			{
+				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/pressed.png';
+			}
+		};
+		option_reply_options.onclick = function(){
+			if (this.value == 'show'){
+				this.value = 'hide';
+				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/pressed.png';
+				Element('tr_other_options_'+ID).style.display = '';
+
+			}
+			else{
+				this.value = 'show';
+				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/down.png';
+				Element('tr_other_options_'+ID).style.display = 'none';
+			}
+		};
+
+		var _option_reply = createAndSet("SPAN",['id','class'],['msg_opt_reply_'+ID,'message_options'],get_lang('Reply'));
+		_option_reply.onclick = function(){new_message('reply_with_history', ID);};
+
+		appendChilds(options,createAndSet('SPAN',false,false,'&nbsp;|&nbsp;'),option_reply_options,_option_reply);
+		appendChilds(tr,td,option_mark,options,next_previous_msg_td);
+		tbody_message_options.appendChild(tr);
+
+		////////// OTHER OPTIONS ////////////////////
+		var _tr_other_options = createAndSet("TR",['id'],['tr_other_options_' + ID]);
+		_tr_other_options.style.display = 'none';
+
+		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_reply_without_history		= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_without_history","'+ID+'");>'+get_lang("Reply without history")+'</span>';
+		var option_reply_to_all					= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_to_all_with_history","'+ID+'");>'+get_lang("Reply to all")+'</span> | ';
+
+		var option_reply_to_all_without_history	= '<span onmouseover="this.className=\'reply_options_active\'" onmouseout="this.className=\'reply_options\'" class="reply_options" onclick=new_message("reply_to_all_without_history","'+ID+'");>'+get_lang("Reply to all without history")+'</span> | </div>';
+
+		div_other_options.innerHTML = option_reply_to_all + option_reply_to_all_without_history + option_reply_without_history;
+		if (use_spam_filter) {
+			if(info_msg.msg_folder == 'INBOX'+cyrus_delimiter+'Spam')
+				div_other_options.innerHTML += ' | <span class="reply_options" onclick="nospam('+info_msg.msg_number+',\'null\', \''+info_msg.msg_folder+'\')";>'+get_lang("Not Spam")+'</span>';
+			else
+				div_other_options.innerHTML += ' | <span class="reply_options" onclick="spam(\''+info_msg.msg_folder+'\', '+info_msg.msg_number+',\'null\')";>'+get_lang("Mark as Spam")+'</span>';
+		}
+
+		var td_other_options = createAndSet("TD",['colSpan','align','noWrap'],['3','right','true']);
+		td_other_options.appendChild(div_other_options);
+
+		_tr_other_options.appendChild(td_other_options);
+		tbody_message_options.appendChild(_tr_other_options);
+		////////// END OTHER OPTIONS ////////////////
+
+		if (info_msg.signature && info_msg.signature.length > 0)
+		{
+			tbody_message_options.appendChild(putSignature(ID,info_msg));
+		}
 
 		table_message_options.appendChild(tbody_message_options);
@@ -459,19 +409,6 @@
 	else 	// IF DRAFT
 	{
-		var options = document.createElement("TD");
-		options.width = "1%";
-		options.setAttribute("noWrap","true");
-		var option_edit	  = document.createElement("SPAN");
-		option_edit.className = 'message_options';
-		option_edit.innerHTML = get_lang('Edit');
-		option_edit.onclick= function () { new_message('edit',ID); };
- 		var separator = document.createElement("SPAN");
-		separator.innerHTML = "&nbsp;|&nbsp;";
-		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('Show details');
+		var options = createAndSet('TD',['width','noWrap','align'],['1%','true','right']);
+		var option_hide_more = createAndSet("SPAN",['class','value','id'],['message_options','more_options','option_hide_more_'+ID],get_lang('Show details'));
 		option_hide_more.onclick = function(){
 			var _height = Element("div_message_scroll_"+ID).style.height;
@@ -491,11 +428,9 @@
 			}
 		};
-		options.appendChild(option_hide_more);
-		options.appendChild(separator);
-		options.appendChild(option_edit);
-		tr.appendChild(td);
-		tr.appendChild(options);
-		tr.appendChild(next_previous_msg_td);
-		tbody_message_options.appendChild(tr);
+		var option_edit = createAndSet('SPAN',['class'],['message_options'], get_lang('Edit'));
+		option_edit.onclick= function () { new_message('edit',ID); };
+		appendChilds(options, option_hide_more, createAndSet('SPAN',false,false,"&nbsp;|&nbsp;"), option_edit);
+
+		tbody_message_options.appendChild(appendChilds(tr, td, options, next_previous_msg_td));
 		table_message_options.appendChild(tbody_message_options);
 		td0.appendChild(table_message_options);
@@ -507,50 +442,33 @@
 	//////////////////////////////////////////////////////////////////////////////////////////////////////
 
-	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;
+	var table_message_others_options = createAndSet("TABLE",['id','width','class'],['table_message_others_options_' + ID,defaultWidth - 30,'table_message']);
 	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: ");
+	var td1 = createAndSet('TD',['width'],['7%'],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")+": ";
+		var td111 = createAndSet('TD',['noWrap'],['true'],get_lang("Sent by")+": ");
 		td111.appendChild(deny_email(info_msg.sender.email));
-		td111.setAttribute("noWrap","true");
 		var sender = document.createElement("TD");
+		sender.className = "header_message_field";
 		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;
+		var sender_values = createAndSet("INPUT",['id','type','value'],["sender_values_"+ID,"HIDDEN",info_msg.sender.full]);
+
+		tbody_message_others_options.appendChild(appendChilds(tr111, td111, sender, sender_values));
+	}
+
+	var from = createAndSet('TD',['id','class'],["from_"+ID,"header_message_field"],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 from_values = createAndSet('INPUT',['id','type','value'],["from_values_"+ID,"HIDDEN",info_msg.from.full]);
 
 	var local_message = document.createElement("INPUT");
@@ -560,10 +478,5 @@
 	local_message.value = (info_msg.local_message)?"1":"0";
 
-	tr1.appendChild(td1);
-	tr1.appendChild(from);
-	tr1.appendChild(from_values);
-	tr1.appendChild(local_message);
-
-
+	appendChilds(tr1,td1,from,from_values,local_message);
 
 	if (info_msg.reply_to){
@@ -582,8 +495,5 @@
 		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);
+		tbody_message_others_options.appendChild(appendChilds(tr11,td11,reply_to,reply_to_values));
 	}
 	//////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -615,5 +525,5 @@
 		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);		
+		to.appendChild(div_toaddress);
 	}
 	else {
@@ -621,8 +531,5 @@
 	}
 	to.className = "header_message_field";
-	tr2.appendChild(td2);
-	tr2.appendChild(to);
-	tr2.appendChild(to_values);
-	tbody_message_others_options.appendChild(tr2);
+	tbody_message_others_options.appendChild(appendChilds(tr2,td2,to,to_values));
 
 	if (info_msg.cc){
@@ -654,8 +561,5 @@
 		}
 		cc.className = "header_message_field";
-		tr3.appendChild(td3);
-		tr3.appendChild(cc);
-		tr3.appendChild(cc_values);
-		tbody_message_others_options.appendChild(tr3);
+		tbody_message_others_options.appendChild(appendChilds(tr3,td3,cc,cc_values));
 	}
 
@@ -707,8 +611,5 @@
 		}
 		cco.className = "header_message_field";
-		tr3.appendChild(td3);
-		tr3.appendChild(cco);
-		tr3.appendChild(cco_values);
-		tbody_message_others_options.appendChild(tr3);
+		tbody_message_others_options.appendChild(appendChilds(tr3,td3,cco,cco_values));
 	}
 
@@ -729,9 +630,5 @@
 	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);
+	tbody_message_others_options.appendChild(appendChilds(tr4,td4,date,date_day,date_hour));
 
 	var tr5 = document.createElement("TR");
@@ -743,7 +640,5 @@
 	subject.innerHTML = info_msg.subject;
 	subject.className = "header_message_field";
-	tr5.appendChild(td5);
-	tr5.appendChild(subject);
-	tbody_message_others_options.appendChild(tr5);
+	tbody_message_others_options.appendChild(appendChilds(tr5,td5,subject));
 	if (info_msg.attachments.length > 0){
 		var tr6 = document.createElement("TR");
@@ -805,7 +700,5 @@
 				var space = document.createElement("span");
 				space.innerHTML = "&nbsp;";
-				attachments.appendChild(link_attachment);
-				attachments.appendChild(space);
-				attachments.appendChild(link_import_attachment);
+				appendChilds(attachments,link_attachment,space,link_import_attachment);
 			}
 			else {
@@ -834,8 +727,10 @@
 	// END MAKE THE SCROLL HEIGHT
 	table_message_others_options.appendChild(tbody_message_others_options);
+	div.appendChild(table_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);
 
@@ -883,5 +778,4 @@
 	tr.appendChild(td);
 	tbody_message.appendChild(tr);
-
 
 	//////////////////////////////////////////////////////////////////////////////////////////////////////	
Index: trunk/expressoMail1_2/js/jscode/filter.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/filter.js	(revision 2673)
+++ trunk/expressoMail1_2/js/jscode/filter.js	(revision 2694)
@@ -575,6 +575,5 @@
 					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)){
+			    	if(validateEmail(Element("field5").value)){
 						mount_rule += Element("field5").value + "&&";
 					}else{
