Index: trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2692)
+++ trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2699)
@@ -177,44 +177,4 @@
     table.appendChild(tbody);
     content_id_0.appendChild(table);
-}
-var idx_cc = 0;
-function draw_plugin_cc(ID, addrs)
-{
-    expresso.connector.loadScript("jscode/ccQuickAdd");
-
-    var array_addrs = '';
-    var array_name 	= '';
-    var cc_data = new Array();
-    if(typeof(addrs.name) != 'undefined') {
-	array_name 	= LTrim(addrs.name).split(" ");
-	array_addrs = new Array(addrs.email);
-    }
-    else {
-	array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
-	array_name 	= LTrim(array_addrs[0]).replace('"','').split(" ");
-    }
-
-    var _split = array_name[0].split('@');
-    cc_data[0] = _split[0];
-    cc_data[1] = _split[0];
-    cc_data[2] = '';
-
-    for (i=1; i < array_name.length; i++)
-	cc_data[2] += array_name[i] + " ";
-
-
-    if(array_addrs.length > 1)
-	cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';
-    else
-	cc_data[3] = array_addrs[0];
-
-    var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
-    '" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/user_card.png">';
-    var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
-    to_addybook_add += addrs;
-    to_addybook_add +=  sm_envelope_img1;
-    idx_cc++;
-    to_addybook_add += "</SPAN>";
-    return to_addybook_add;
 }
 
Index: trunk/expressoMail1_2/js/jscode/draw_api_messages.js
===================================================================
--- trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2695)
+++ trunk/expressoMail1_2/js/jscode/draw_api_messages.js	(revision 2699)
@@ -173,4 +173,45 @@
 
 }
+var idx_cc = 0;
+function draw_plugin_cc(ID, addrs)
+{
+    expresso.connector.loadScript("jscode/ccQuickAdd");
+
+    var array_addrs = '';
+    var array_name      = '';
+    var cc_data = new Array();
+    if(typeof(addrs.name) != 'undefined') {
+        array_name      = LTrim(addrs.name).split(" ");
+        array_addrs = new Array(addrs.email);
+    }
+    else {
+        array_addrs = (typeof addrs == 'object' ? addrs.toString().split("\" ") : addrs.split("\" "));
+        array_name      = LTrim(array_addrs[0]).replace('"','').split(" ");
+    }
+
+    var _split = array_name[0].split('@');
+    cc_data[0] = _split[0];
+    cc_data[1] = _split[0];
+    cc_data[2] = '';
+
+    for (i=1; i < array_name.length; i++)
+        cc_data[2] += array_name[i] + " ";
+
+
+    if(array_addrs.length > 1)
+        cc_data[3] = array_addrs[1] ? array_addrs[1].replace("&lt;",'').replace("&gt;",'') : '';
+    else
+        cc_data[3] = array_addrs[0];
+
+    var sm_envelope_img1 = '<img style="cursor:'+ (is_ie ? 'hand' : 'pointer') +'" title="' + get_lang("Add Contact") +
+    '" onclick="ccQuickAddOne.showList(\''+cc_data+'\')" src="' + URL_SERVER + 'expressoMail1_2/templates/'+template+'/images/user_card.png">';
+    var to_addybook_add = "<SPAN id='insert_plugin_"+idx_cc+"_"+ID+"'>";
+    to_addybook_add += addrs;
+    to_addybook_add +=  sm_envelope_img1;
+    idx_cc++;
+    to_addybook_add += "</SPAN>";
+    return to_addybook_add;
+}
+
 
 function putSignature(ID,info_msg){
@@ -299,5 +340,5 @@
 			_height = parseInt(_height.replace("px",""));
 			var _offset = 35;
-			if (this.value == 'more_options'){
+			if (this.value != 'hide_options'){
 				this.innerHTML = "<b><u>"+get_lang('hide details')+"</u></b>";
 				this.value = 'hide_options';
@@ -331,4 +372,5 @@
 		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(){
@@ -346,5 +388,5 @@
 		};
 		option_reply_options.onclick = function(){
-			if (this.value == 'show'){
+			if (this.value != 'hide'){
 				this.value = 'hide';
 				option_reply_options.src= URL_SERVER+'expressoMail1_2/templates/default/images/pressed.png';
@@ -415,5 +457,5 @@
 			_height = parseInt(_height.replace("px",""));
 			var _offset = 35;
-			if (this.value == 'more_options'){
+			if (this.value != 'hide_options'){
 				this.innerHTML = "<b><u>"+get_lang('Hide details')+"</u></b>";
 				this.value = 'hide_options';
@@ -471,11 +513,5 @@
 	}
 	var from_values = createAndSet('INPUT',['id','type','value'],["from_values_"+ID,"HIDDEN",info_msg.from.full]);
-
-	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";
-
+	var local_message = createAndSet("INPUT",['id','name','type','value'],["is_local_"+ID,"is_local","HIDDEN",(info_msg.local_message)?"1":"0"]);
 	appendChilds(tr1,td1,from,from_values,local_message);
 
@@ -483,17 +519,8 @@
 		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";
-		tbody_message_others_options.appendChild(appendChilds(tr11,td11,reply_to,reply_to_values));
+		var _td11 = createAndSet('TD',['noWrap'],['true'],get_lang("Reply to")+": ");
+		var _reply_to = createAndSet('TD',['id', 'class'],["reply_to_"+ID, "header_message_field"],draw_plugin_cc(ID, info_msg.reply_to));
+		var _reply_to_values = createAndSet('INPUT',['id', 'type', 'value'],["reply_to_values_"+ID,"HIDDEN",info_msg.reply_to]);
+		tbody_message_others_options.appendChild(appendChilds(tr11,_td11,_reply_to,_reply_to_values));
 	}
 	//////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -505,25 +532,14 @@
 	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.	
-
+	var _to_values = createAndSet('INPUT',['id', 'type', 'value'],["to_values_"+ID, "HIDDEN", info_msg.toaddress2]);
 	// 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
+	var _input_cfolder = createAndSet('INPUT',['id', 'name', 'type', 'value'],["input_folder_"+ID, "input_folder", "hidden", info_msg.msg_folder]);
+	td2.appendChild(_input_cfolder);
+
 	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);
+		var _div_toaddrs = createAndSet('SPAN',['id','style'],["div_toaddress_"+ID,'display: inline']," (<a STYLE='color: RED;' onclick=javascript:show_div_address_full('"+ID+"','to');>"+get_lang('more')+"</a>)");
+		to.appendChild(_div_toaddrs);
 	}
 	else {
@@ -531,5 +547,5 @@
 	}
 	to.className = "header_message_field";
-	tbody_message_others_options.appendChild(appendChilds(tr2,td2,to,to_values));
+	tbody_message_others_options.appendChild(appendChilds(tr2,td2,to,_to_values));
 
 	if (info_msg.cc){
@@ -538,19 +554,12 @@
 		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;
-
+		var cc = createAndSet("TD",['id', 'class'],["cc_"+ID,"header_message_field"]);
+
+		var cc_values = createAndSet("INPUT",['id', 'type', 'value'],["cc_values_"+ID, "HIDDEN", 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="";
+			var div_ccaddress_full = createAndSet("SPAN",['id', 'style'],["div_ccaddress_full_"+ID, "display: inline"]);
 			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>)";
@@ -560,5 +569,4 @@
 			cc.innerHTML = draw_plugin_cc(ID, info_msg.cc);
 		}
-		cc.className = "header_message_field";
 		tbody_message_others_options.appendChild(appendChilds(tr3,td3,cc,cc_values));
 	}
@@ -578,17 +586,10 @@
 		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;
-
+		var cco_values = createAndSet("INPUT",['id', 'type', 'value'],["cco_values_"+ID,"hidden",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="";
-
+			var div_ccoaddress_full = createAndSet("SPAN",['id', 'style'],["div_ccoaddress_full_"+ID, "display:inline"]);
 			/*
 			 * The function below is ugly, doesn't possible use this.
@@ -618,16 +619,7 @@
 	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";
+	var date = createAndSet('TD',['id','class'],["date_"+ID,"header_message_field"],info_msg.fulldate);
+	var date_day = createAndSet('INPUT',['id', 'type', 'value'],["date_day_"+ID, "HIDDEN", info_msg.msg_day]);
+	var date_hour = createAndSet('INPUT',['id', 'type', 'value'],["date_hour_"+ID, "HIDDEN", info_msg.msg_hour]);
 	tbody_message_others_options.appendChild(appendChilds(tr4,td4,date,date_day,date_hour));
 
@@ -636,8 +628,5 @@
 	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";
+	var subject = createAndSet('TD',['id', 'class'],["subject_"+ID, "header_message_field"],info_msg.subject);
 	tbody_message_others_options.appendChild(appendChilds(tr5,td5,subject));
 	if (info_msg.attachments.length > 0){
@@ -648,12 +637,10 @@
 
 		var attachments = document.createElement("TD");
+		attachments.align='left';
 		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 zipped_attachments  = createAndSet("TABLE",['style','cellPadding','cellSpacing'],['margin-bottom: 4px','0','0']);
 			var td = document.createElement("TD");
 			if(info_msg.attachments.length > 1) {
@@ -692,10 +679,5 @@
 			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 link_import_attachment = createAndSet("IMG",['src','onclick','title','align','style'],["templates/"+template+"/images/new.png","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+"');",get_lang("Import to calendar"),"top","cursor: pointer"]);
 				var space = document.createElement("span");
 				space.innerHTML = "&nbsp;";
@@ -733,46 +715,6 @@
 	td.colSpan = '2';
 
-	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='" + URL_SERVER + "expressoMail1_2/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);
-			}
-		}
-	}
+	var newBody = blockImage(info_msg,ID,td);
+
 	td.appendChild(div);
 	tr.appendChild(td);
@@ -854,8 +796,5 @@
 	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;
+	var msg_number = createAndSet("INPUT",['id','type','value'],["msg_number_" + ID, "hidden", info_msg.msg_number]);
 	content.appendChild(msg_number);
 	//////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -875,4 +814,51 @@
 		}
 	}
+
+}
+
+function blockImage(info_msg,ID,td){
+	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='" + URL_SERVER + "expressoMail1_2/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);
+			}
+		}
+	}
+	return newBody;
 
 }
