Index: trunk/expressoMail1_2/js/main.js
===================================================================
--- trunk/expressoMail1_2/js/main.js	(revision 5891)
+++ trunk/expressoMail1_2/js/main.js	(revision 5911)
@@ -283,11 +283,12 @@
 		{
 			away=false;
-			var save_link = Element("save_message_options_"+border_id);
+			var save_link = content.find(".save");
 			save_link.onclick = function onclick(event) {openTab.toPreserve[border_id] = true;save_msg(border_id);} ;
-			$("#save_message_options_"+border_id).button({disabled: false});
+			save_link.button({disabled: false});
 			$(".header-button").button();
 		};
-
-		var subject_obj = document.getElementById('subject_'+border_id);
+		var content = $("#content_id_"+border_id);
+		
+		var subject_obj = content.find(".subject");
 		if ( subject_obj.addEventListener )
 				subject_obj.addEventListener('keypress', keypress_handler, false);
@@ -295,5 +296,5 @@
 			subject_obj.attachEvent('onkeypress', keypress_handler);
 
-		var to_obj = document.getElementById('to_'+border_id);
+		var to_obj = content.find('[name="input_to"]');
 		if ( to_obj.addEventListener )
 				to_obj.addEventListener('keypress', keypress_handler, false);
@@ -301,5 +302,5 @@
 			to_obj.attachEvent('onkeypress', keypress_handler);
 			
-		var cc_obj = document.getElementById('cc_'+border_id);
+		var cc_obj = content.find('[name="input_cc"]');
 		if ( cc_obj.addEventListener )
 				cc_obj.addEventListener('keypress', keypress_handler, false);
@@ -307,6 +308,6 @@
 			cc_obj.attachEvent('onkeypress', keypress_handler);
 		
-		if(document.getElementById('cco_'+border_id)){
-			var cco_obj = document.getElementById('cco_'+border_id);
+		if(content.find('[name="input_cco"]').length){
+			var cco_obj = content.find('[name="input_cco"]');
 			if ( cco_obj.addEventListener )
 				cco_obj.addEventListener('keypress', keypress_handler, false);
@@ -1455,5 +1456,6 @@
                     if (type != 'edit')
                     {
-                        return new_border_ID;
+						delete_border(currentTab);
+						new_border_ID = draw_new_message(parseInt(border_ID));
                     }			
 		} else {
@@ -1560,22 +1562,26 @@
 	if(type!="new" && type!="edit" && document.getElementById("is_local_"+border_ID) != null)
 		data.is_local_message = (document.getElementById("is_local_"+border_ID).value=="1")?true:false;
-	switch(type){
+		
+	if(typeof($.fn.elastic) == "undefined"){
+		$.lazy({
+			src: '../prototype/plugins/jquery-elastic/jquery.elastic.source.js',
+			name: 'elastic'
+		});
+	}
+	var content = $("#content_id_"+new_border_ID);
+	content.find('[name="msg_reply_from"]').val($("#msg_number_" + border_ID).val());
+	
+switch(type){
 		case "reply_without_history":
 			RichTextEditor.replyController = true; //Seta o editor como modo reply
-			Element("to_" + new_border_ID).value = data.to;
+			content.find('[name="input_to"]').val(data.to);
 			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;			
-                        useOriginalAttachments(new_border_ID,border_ID);			
-			      
+			content.find(".subject").val("Re: " + data.subject);			
+			useOriginalAttachments(new_border_ID,border_ID);			
 
 			// Insert the signature automaticaly at message body if use_signature preference is set
 			if (preferences.use_signature == "1"){  
- 		                                RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature ,true) ;      
- 		                        } 
-			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);
+				RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature ,true) ;      
+			} 
 			break;
 		case "reply_with_history":
@@ -1583,6 +1589,6 @@
 			RichTextEditor.replyController = true; //Seta o editor como modo reply 
 			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
-			Element("to_" + new_border_ID).value = data.to;
+			content.find(".subject").val("Re: " + data.subject);
+			content.find('[name="input_to"]').val(data.to);
 
 			useOriginalAttachments(new_border_ID,border_ID);
@@ -1594,9 +1600,4 @@
 			else
 				RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>'+ block_quoted_body,true);
-			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":
@@ -1610,13 +1611,52 @@
 
 			title = "Re: " + data.subject;
-			Element("subject_" + new_border_ID).value = "Re: " + data.subject;
+			content.find(".subject").val("Re: " + data.subject);
 			
 			if (data.to.indexOf(Element("user_email").value) > 0 )
-				Element("to_" + new_border_ID).value = data.to_all;
+				content.find('[name="input_to"]').val(data.to_all);
 			else
-				Element("to_" + new_border_ID).value = data.to + ',' + data.to_all;
-			//Element("to_" + new_border_ID).value = data.to;
-			//Element("to_" + new_border_ID).value += ', ' + data.to_all;
+				content.find('[name="input_to"]').val(data.to + ',' + data.to_all);
+				
+			if (data.cc){
+				data.cc = new Array();
+				data.cc = removeUserEmail(_array_cc);
+				data.cc = removeAlternative(data.cc,_array_to_alternative);
+					if (data.cc != get_lang("undisclosed-recipient"))
+						data.cc = data.cc.join(",");
+					else
+						data.cc = "";	
+				if(data.cc != ""){
+					content.find('[name="input_cc"]').val(data.cc);
+					content.find(".cc-tr").css("display"," ");//cc-button
+					//document.getElementById("a_cc_link" + new_border_ID).value = data.cc;
+					content.find(".cc-button").toggleClass("expressomail-button-icon-ative");
+					content.find(".cc-button").find("span").html("Remover CC");
+					content.find('[name="input_cc"]').elastic().unbind('blur');
+					content.find('[name="input_cc"]').trigger("update");
+				}
+			}
+                        
+			useOriginalAttachments(new_border_ID,border_ID);  
+			if (preferences.use_signature == "1")  
+				RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature,true);
+				
+			break;
+		case "reply_to_all_with_history":
+			RichTextEditor.replyController = true; //Seta o editor como modo reply 
+			//delete user email from to_all array.
+			data.to_all = new Array();
+			data.to_all = removeUserEmail(_array_to_all);
+			data.to_all = removeAlternative(data.to_all,_array_to_alternative);
+		
+			if (data.to_all != get_lang("undisclosed-recipient"))
+				data.to_all = data.to_all.join(",");
+			else
+				data.to_all = "";
+			title = "Re: " + data.subject;
 			
+			if (data.to.indexOf(Element("user_email").value) > 0 )
+				content.find('[name="input_to"]').val(data.to_all);
+			else
+				content.find('[name="input_to"]').val(data.to + ',' + data.to_all);			
 			if (data.cc){
 				data.cc = new Array();
@@ -1627,90 +1667,26 @@
 					else
 						data.cc = "";			
-				if(data.cc == ""){
-					//document.getElementById("cc_" + new_border_ID).value = data.cc;
-					document.getElementById("tr_cc_" + new_border_ID).style.display='none';
-				}else{
-					document.getElementById("cc_" + new_border_ID).value = data.cc;
-					document.getElementById("tr_cc_" + new_border_ID).style.display='';
-					//document.getElementById("a_cc_link" + new_border_ID).value = data.cc;
-					$("#a_cc_link_"+new_border_ID).toggleClass("expressomail-button-icon-ative");
-					$("#a_cc_link_"+new_border_ID).find("span").html("Remover CC");
-					$("#cc_"+new_border_ID).elastic().unbind('blur');
-					$("#cc_"+new_border_ID).trigger("update");
+				if(data.cc != ""){
+					content.find('[name="input_cc"]').val(data.cc);
+					content.find(".cc-tr").show();
+					content.find(".cc-button").toggleClass("expressomail-button-icon-ative");
+					content.find(".cc-button").find("span").html("Remover CC");
+					content.find('[name="input_cc"]').elastic().unbind('blur');
+					content.find('[name="input_cc"]').trigger("update");
 				}
 			}
-                        
-                        useOriginalAttachments(new_border_ID,border_ID);  
-
-			// Insert the signature automaticaly at message body if use_signature preference is set
-			if (preferences.use_signature == "1")  
-				RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature,true); 
-			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":
-			RichTextEditor.replyController = true; //Seta o editor como modo reply 
-			//delete user email from to_all array.
-			data.to_all = new Array();
-			data.to_all = removeUserEmail(_array_to_all);
-			data.to_all = removeAlternative(data.to_all,_array_to_alternative);
-		
-			if (data.to_all != get_lang("undisclosed-recipient"))
-				data.to_all = data.to_all.join(",");
-			else
-				data.to_all = "";
-			title = "Re: " + data.subject;
-			
-			if (data.to.indexOf(Element("user_email").value) > 0 )
-				Element("to_" + new_border_ID).value = data.to_all;
-			else
-				Element("to_" + new_border_ID).value = data.to + ',' + data.to_all;			
-			if (data.cc){
-				data.cc = new Array();
-				data.cc = removeUserEmail(_array_cc);
-				data.cc = removeAlternative(data.cc,_array_to_alternative);
-					if (data.cc != get_lang("undisclosed-recipient"))
-						data.cc = data.cc.join(",");
-					else
-						data.cc = "";			
-				if(data.cc == ""){
-					//document.getElementById("cc_" + new_border_ID).value = data.cc;
-					document.getElementById("tr_cc_" + new_border_ID).style.display='none';
-				}else{
-					document.getElementById("cc_" + new_border_ID).value = data.cc;
-					document.getElementById("tr_cc_" + new_border_ID).style.display='';
-					//document.getElementById("a_cc_link" + new_border_ID).value = data.cc;
-					$("#a_cc_link_"+new_border_ID).toggleClass("expressomail-button-icon-ative");
-					$("#a_cc_link_"+new_border_ID).find("span").html("Remover CC");
-					$("#cc_"+new_border_ID).elastic().unbind('blur');
-					$("#cc_"+new_border_ID).trigger("update");
-				}
-			}
-			document.getElementById("subject_" + new_border_ID).value = "Re: " + data.subject;
+			content.find(".subject").val("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);
-			// Insert the signature automaticaly at message body if use_signature preference is set
+			
 			if (preferences.use_signature == "1")  
-									RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature + '<div><br type="_moz"></div>'+ block_quoted_body,true); 
- 		                        else                   
- 		                            RichTextEditor.setInitData(new_border_ID,block_quoted_body,true);     
-			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);
+				RichTextEditor.setInitData(new_border_ID,'<div><br type="_moz"></div>' + signature + '<div><br type="_moz"></div>'+ block_quoted_body,true); 
+			else                   
+				RichTextEditor.setInitData(new_border_ID,block_quoted_body,true); 
+				
 			break;
 		case "forward":
-			
-			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;
+			content.find(".subject").val("Fw: " + data.subject);
 			var divFiles = Element("divFiles_"+new_border_ID);
 			var campo_arquivo;
@@ -1741,5 +1717,5 @@
 					}
 				}
-				Element("to_" + new_border_ID).value = _to +',';
+				content.find('[name="input_to"]').val(_to +',');
 				Element('msg_number').value = '';
 			}
@@ -1749,5 +1725,5 @@
 				RichTextEditor.setInitData(new_border_ID, '<div><br type="_moz"></div>' + signature);
 			 else
-			   $('#to_'+new_border_ID).focus(); 
+			   content.find('[name="input_to"]').focus(); 
 			break;
 		case "edit":
@@ -1764,40 +1740,30 @@
 			}
 
-			Element("to_" + new_border_ID).value = data.to;
+			content.find('[name="input_to"]').val(data.to);
 			if (data.cc){
 				data.cc = data.cc.replace(/&lt;/gi,"<");
 				data.cc = data.cc.replace(/&gt;/gi,">");
-				Element("cc_" + new_border_ID).value = data.cc;
-				Element("cc_" + new_border_ID).style.display = "";
-				Element("tr_cc_"+ new_border_ID).style.display = '';
-				Element("cc_" + new_border_ID).style.width = "100%";
-				$("#a_cc_link_"+new_border_ID).toggleClass("expressomail-button-icon-ative");
-				$("#a_cc_link_"+new_border_ID).find("span").html("Remover CC");
-				$("#cc_"+new_border_ID).elastic().unbind('blur');
-				$("#cc_"+new_border_ID).trigger("update");
-				//Element("a_cc_link_" + new_border_ID).style.display = 'none';
-				//if(Element("cco_" + new_border_ID) != null)
-				//	Element("space_link_" + new_border_ID).style.display = 'none';
+				content.find('[name="input_cc"]').val(data.cc);
+				content.find(".cc-tr").show();
+				content.find(".cc-button").toggleClass("expressomail-button-icon-ative");
+				content.find(".cc-button").find("span").html(get_lang('Remove CC'));
+				content.find('[name="input_cc"]').elastic().unbind('blur');
+				content.find('[name="input_cc"]').trigger("update");
 			}
 			if (data.cco){
-				if(Element("cco_" + new_border_ID) != null){
-				Element("cco_" + new_border_ID).value = data.cco;
-				Element("cco_" + new_border_ID).style.display = '';
-				Element("cco_" + new_border_ID).style.width = "100%";
-				Element("tr_cco_"+ new_border_ID).style.display = '';
-				$("#a_cco_link_"+new_border_ID).toggleClass("expressomail-button-icon-ative");
-				$("#a_cco_link_"+new_border_ID).find("span").html("Remover CC");
-				$("#cco_"+new_border_ID).elastic().unbind('blur');
-				$("#cco_"+new_border_ID).trigger("update");
-				//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;
+				if(content.find('[name="input_cco"]').length){
+					content.find('[name="input_cco"]').val(data.cco);
+					content.find(".cco-tr").show();
+					content.find(".cco-button").toggleClass("expressomail-button-icon-ative");
+					content.find(".cco-button").find("span").html(get_lang('Remove CCo'));
+					content.find('[name="input_cco"]').elastic().unbind('blur');
+					content.find('[name="input_cco"]').trigger("update");
+				}
+			}
+			content.find(".subject").val(data.subject);
 			
-			if( Element("disposition_notification_" + border_ID) ){
-				$("#return_receipt_"+new_border_ID).attr("checked", true);
-				$("[name=return_receipt_"+new_border_ID+"]").toggleClass("expressomail-button-icon-ative");
+			if( $("#disposition_notification_" + border_ID).length ){
+				content.find('[name="input_return_receipt"]').attr("checked", true);
+				content.find(".return-recept").toggleClass("expressomail-button-icon-ative");
 				//Element("return_receipt_" + new_border_ID).checked = true;
 			}
@@ -1806,13 +1772,12 @@
 			if(element_important_message) {
 					
-				if(Element("disposition_important_" + border_ID)){
-					$("#important_message_"+new_border_ID).attr("checked", true);
-					$("[name=important_message_"+new_border_ID+"]").toggleClass("expressomail-button-icon-ative");
-					//element_important_message.checked = true;		
+				if($("#disposition_important_" + border_ID).length){
+					content.find('[name="input_important_message"]').attr("checked", true);
+					content.find(".important").toggleClass("expressomail-button-icon-ative");	
 				}
 			}
 
 			if (Element("attachments_" + border_ID))
-                               addOriginalAttachments(new_border_ID,border_ID);
+				addOriginalAttachments(new_border_ID,border_ID);
                          
 			RichTextEditor.setInitData(new_border_ID, data.body, 'edit');
@@ -1822,19 +1787,19 @@
 	}
 	
-	$("#to_"+new_border_ID).trigger("update");	
-	var txtarea = Element('body_'+new_border_ID);
+	content.find('[name="input_to"]').trigger("update");	
+	var txtarea = $('#body_'+new_border_ID);
 	var height = document.body.scrollHeight - 330;
-	txtarea.style.overflowY = "auto";
-	txtarea.style.height = height;
+	txtarea.css("overflowY","auto");
+	txtarea.css("height",height);
 	//Insere o conteúdo da mensagem e a assinatura no editor de texto simples
-     if (preferences.plain_text_editor == 1){
-	   Element('textplain_rt_checkbox_'+new_border_ID).checked = true;
-	   if (txtarea != null){
-		  if (data.body != undefined)
-		    txtarea.value = data.body.replace( new RegExp('<pre>((.\n*)*)</pre>'),'$1');
-	      if (preferences.use_signature == "1")
-            txtarea.value += '\n' + signature;     
-       }
-	 } 
+	if (preferences.plain_text_editor == 1){
+		Element('textplain_rt_checkbox_'+new_border_ID).checked = true;
+		if (txtarea != null){
+			if (data.body != undefined)
+				txtarea.val(data.body.replace( new RegExp('<pre>((.\n*)*)</pre>'),'$1'));
+			if (preferences.use_signature == "1")
+				txtarea.val(txtarea.val + '\n' + signature);     
+		}
+	} 
 	Element("border_id_" + new_border_ID).title = title;
 	set_border_caption("border_id_" + new_border_ID, title);
@@ -1843,5 +1808,4 @@
 	return new_border_ID; //Preciso retornar o ID da nova mensagem.
 }
-
 
 //Remove o email do usuario ao responder a todos
@@ -2204,12 +2168,11 @@
 function send_valided_message(ID, folder, folder_name)
 { 
-        
-       if (preferences.auto_save_draft == 1)
-           autoSaveControl.status[ID] = true;
-        
-        var save_link = Element("save_message_options_"+ID);
-        var onClick = save_link.onclick;
+	if (preferences.auto_save_draft == 1)
+	   autoSaveControl.status[ID] = true;
+	var content = $("#content_id_"+ID);
+	var save_link = $("#content_id_"+ID).find(".save");
+	var onClick = save_link.onclick;
 	save_link.onclick = '';
-	$("#save_message_options_"+ID).button({disabled: true});
+	save_link.button({disabled: true});
 
 	ID_tmp = ID;
@@ -2294,23 +2257,23 @@
         form.parentNode.appendChild(mail_type);
 
-	var _subject = trim(Element("subject_"+ID).value);
+	var _subject = trim(content.find(".subject").val());
 	if((_subject.length == 0) && !confirm(get_lang("Send this message without a subject?"))) {
-                save_link.onclick = onClick;
-		Element("subject_"+ID).focus();
+		save_link.click(onClick);
+		content.find(".subject").focus();
 		return;
 	}
-	stringEmail = Element("to_"+ID).value;
+	stringEmail = content.find('[name="input_to"]').val();
 	
-	if ( Element("cco_"+ID) != null)
-		if(Element("tr_cco_"+ID).style.display != "none")
-			stringEmail += Element("cco_"+ID).value =='' ? "":", "+Element("cco_"+ID).value;
+	if ( content.find('[name="input_cco"]').length)
+		if(content.find(".cco-tr").css("display") != "none")
+			stringEmail += content.find('[name="input_cco"]').val() =='' ? "":", "+content.find('[name="input_cco"]').val();
 			
-	if(Element("tr_cc_"+ID).style.display != "none")
-		stringEmail += Element("cc_"+ID).value =='' ? "":", "+Element("cc_"+ID).value;
+	if(content.find(".cc-tr").css("display") != "none")
+		stringEmail += content.find('[name="input_cc"]').val() =='' ? "":", "+content.find('[name="input_cc"]').val();
 		
 	if (expresso_offline) {
 		
 		var invalidEmail = searchEmail(stringEmail);
-		if(Element("to_"+ID).value=="" && Element("cco_"+ID).value=="" && Element("cc_"+ID).value=="") {
+		if(content.find('[name="input_to"]').val()=="" && content.find('[name="input_cco"]').val()=="" && content.find('[name="input_cc"]').val()=="") {
 			write_msg(get_lang("message without receiver"));
 			return;
