Index: /branches/2.2.0.1/expressoMail1_2/index.php
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/index.php	(revision 3877)
+++ /branches/2.2.0.1/expressoMail1_2/index.php	(revision 3977)
@@ -16,4 +16,6 @@
 	echo "<script type='text/javascript'>var template = '".$_SESSION['phpgw_info']['expressoMail1_2']['user']['preferences']['common']['template_set']."';</script>";
 	echo "<script src='js/modal/modal.js'></script>";
+        echo '<link href="js/lert/lert.css" rel="stylesheet" type="text/css"/>';
+        echo '<script src="js/lert/lert.js" type="text/javascript"></script>';
 	echo "<script src='js/globals.js?".$update_version."' type='text/javascript'></script>";
 	echo "<script src='js/sniff_browser.js?".$update_version."' type='text/javascript'></script>";
Index: /branches/2.2.0.1/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3962)
+++ /branches/2.2.0.1/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3977)
@@ -610,5 +610,5 @@
 Your mailbox is shared with	expressoMail1_2	pt-br	Sua caixa postal está compartilhada com
 Your message has not been sent and will be discarted.	expressoMail1_2	pt-br	Sua mensagem não foi enviada e será perdida.
-Your message has not been sent. Discard your message?	expressoMail1_2	pt-br	Sua mensagem não foi salva ou enviada. Descartar a mensagem?
+Your changes are not saved. What to do?	expressoMail1_2	pt-br	Suas alterações não foram salvas. O que deseja fazer?
 Your message to %1 has not been saved or sent. To %2 will be necessary open it again. Discard your message?	expressoMail1_2	pt-br	Sua mensagem para %1 não foi salva ou enviada. Para %2 será preciso abrir novamente. Descartar sua mensagem?
 Your message was rejected by antivirus. Perhaps your attachment has been infected.	expressoMail1_2	pt-br	Sua mensagem foi rejeitada pelo anti-virus. Seu anexo pode estar infectado.
@@ -646,2 +646,4 @@
 Your rule contains any accented character. The filter may not work. Do you wish to continue?	expressoMail1_2	en	Sua regra contem algum caracter acentuado. O filtro pode nao funcionar. Deseja continuar?
 The selected folder cotain any accented character. The filter dont work with accented folders. Please, rename the folder or choose another folder.	expressoMail1_2	pt-br	A pasta selecionada contém algum caracter acentuado. O filtro não funcionada com pastas acentuadas. Por favor, mude o nome da pasta ou escolha outra.
+Warning	expressoMail1_2	pt-br	Atenção
+Discard	expressoMail1_2	pt-br	Descartar
Index: /branches/2.2.0.1/expressoMail1_2/js/abas.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/abas.js	(revision 3876)
+++ /branches/2.2.0.1/expressoMail1_2/js/abas.js	(revision 3977)
@@ -250,6 +250,43 @@
 }
 
+function draftTests(ID, msg_sent){
+    var cancel = new LertButton(get_lang('cancel'), function() {
+        Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
+    });
+    var yes = new LertButton(get_lang('Save'), function() {
+            if (openTab.imapUid[ID]!=undefined){
+                delete_msgs(openTab.imapBox[ID],openTab.imapUid[ID].toString(),0,0,1);
+                delete(openTab.imapBox[ID]);
+            }
+            save_msg(ID);
+            openTab.toPreserve[ID] = false;
+            close_delete(ID, msg_sent);
+            write_msg(get_lang('Your message was save as draft in folder %1.', lang_folder('Drafts')));
+    });
+    var discard = new LertButton(get_lang('Discard'), function() {
+            if (openTab.imapBox[ID] && !openTab.toPreserve[ID])
+            {
+                //delete_msgs(openTab.imapBox[ID], openTab.imapUid[ID].toString(), 0)
+                //delete(openTab.imapBox[ID]);
+                openTab.toPreserve[ID] = false;
+            }
+            close_delete(ID, msg_sent);
+    });
+    var titulo = '<b>' + get_lang('Warning') + '!</b>';
+    var message = get_lang("Your changes are not saved. What to do?");
+    var multConfirm = new Lert(
+            titulo,
+            message,
+            [cancel,discard,yes],
+            {
+                    defaultButton:yes,
+                    icon:'js/lert/images/dialog-help.gif'
+            });
+    multConfirm.display();
+}
+
 function delete_border(ID, msg_sent)
 {
+        var bolExecuteClose = true;
 	var borderElem = Element("border_id_" + ID)
 	if (borderElem)
@@ -263,31 +300,25 @@
 		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 
-				}
-			}
-		}
-	}
-
+                    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 != ''))
+                    {
+                        draftTests(ID, msg_sent);
+                        bolExecuteClose = false;
+                    }
+		}
+	}
+        if (bolExecuteClose)
+        {
+            close_delete(ID, msg_sent);
+	}
+        return true;
+}
+
+function close_delete(ID, msg_sent)
+{
 	openTab.toPreserve[ID] = false;
 	openTab.imapUid[ID] = 0;
-	delete(openTab.type[ID]);
 
 	if (preferences.auto_save_draft == 1)
Index: /branches/2.2.0.1/expressoMail1_2/js/main.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/main.js	(revision 3955)
+++ /branches/2.2.0.1/expressoMail1_2/js/main.js	(revision 3977)
@@ -1293,5 +1293,5 @@
 		case "edit":
 			openTab.imapBox[new_border_ID] = folder_message.value;
-			openTab.toPreserve[new_border_ID] = true;
+			//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;
Index: /branches/2.2.0.1/expressoMail1_2/js/draw_api.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/draw_api.js	(revision 3975)
+++ /branches/2.2.0.1/expressoMail1_2/js/draw_api.js	(revision 3977)
@@ -2227,5 +2227,5 @@
 //	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_save = '<span id="save_message_options_'+ID+'" class="message_options" onclick="save_msg('+ID+');">'+get_lang("Save")+'</span> | ';
 		var option_search = '<span class="message_options" onclick=openListUsers("'+ID+'");>'+get_lang("Search")+'</span>';
 	}
Index: /branches/2.2.0.1/expressoMail1_2/js/lert/lert.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/lert/lert.js	(revision 3977)
+++ /branches/2.2.0.1/expressoMail1_2/js/lert/lert.js	(revision 3977)
@@ -0,0 +1,132 @@
+/*
+* Lert v1.0
+* by Jeffrey Sambells - http://JeffreySambells.com
+* For more information on this script, visit http://JeffreySambells.com/openprojects/lert/
+* Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
+* Icons from Tango Desktop Project http://tango.freedesktop.org/Tango_Desktop_Project
+*/
+function Lert(title, message, buttons, options) {
+	this.title_ = title;
+	this.message_ = message;
+	this.buttons_ = buttons;
+	this.defaultButton_ = options.defaultButton || this.buttons_[0];
+	this.icon_ = options.icon || null;
+}
+
+Lert.prototype.display = function() {
+	var body = document.getElementsByTagName ('BODY')[0];
+	//create the overlay if necessary
+	var overlay = document.getElementById('lertOverlay');
+	if(!overlay) {
+		var overlay = document.createElement("div");
+		overlay.setAttribute('id','lertOverlay');
+		overlay.style.display = 'none';
+		body.appendChild(overlay);
+	}
+
+	//position and show the overlay
+	overlay.style.height='100%';
+	overlay.style.display='block';
+
+	//create the container if necessary
+	var container = document.getElementById('lertContainer');
+	if(!container) {
+		var container = document.createElement("div");
+		container.setAttribute('id','lertContainer');
+		container.style.display = 'none';
+		body.appendChild(container);
+	}
+
+	//position and show the container
+	container.style.top = '35%';
+	container.style.display = 'block';
+
+	//create the window
+	var win = document.createElement('div');
+	win.setAttribute('id','lertWindow');
+
+	var topBorder = document.createElement('div');
+	topBorder.setAttribute('id','topBorder');
+	topBorder.innerHTML = this.title_;
+	var iconClose = document.createElement('img');
+	    iconClose.setAttribute('src', 'js/lert/images/close_button.gif');
+	    iconClose.setAttribute('id','closeIcon');
+	    iconClose.setAttribute('alt','');
+	    iconClose.setAttribute('style','cursor: pointer;');
+	    iconClose.setAttribute('onclick', "document.getElementById('lertOverlay').style.display='none';document.getElementById('lertContainer').style.display='none';document.getElementById('lertContainer').innerHTML = '';");
+	topBorder.appendChild(iconClose);
+	win.appendChild(topBorder);
+	//create the optional icon
+	if(this.icon_ != null) {
+		var icon = document.createElement('img');
+		icon.setAttribute('src',this.icon_);
+
+		icon.setAttribute('id','lertIcon');
+		icon.setAttribute('alt','');
+		win.appendChild(icon);
+	}
+
+	//create the message space
+	var message = document.createElement('p');
+	message.setAttribute('id','lertMessage');
+	message.innerHTML = this.message_;
+	win.appendChild(message);
+
+	//create the button space
+	var buttons = document.createElement('div');
+	buttons.setAttribute('id','lertButtons');
+
+	var oldKeyDown = document.onkeydown;
+
+	//add each button
+	for(i in this.buttons_) {
+		var button = this.buttons_[i];
+		if(button.getDom) {
+			var domButton = button.getDom(function() {
+				container.style.display = 'none';
+				overlay.style.display = 'none';
+				document.onkeydown=oldKeyDown;
+				container.innerHTML = '';
+				button.onclick_;
+			},this.defaultButton_);
+			buttons.appendChild(domButton);
+		}
+	}
+	win.appendChild(buttons);
+
+	document.onkeydown = this.keyboardControls;
+
+	//append the window
+	container.appendChild(win);
+
+}
+
+Lert.prototype.keyboardControls = function(e) {
+	if (e == null) { keycode = event.keyCode; } // ie
+	else { keycode = e.which; } // mozilla
+	if(keycode==13){ 
+		document.getElementById('lertDefaultButton').onclick();
+	}
+}
+
+function LertButton(label, event, options) {
+	this.label_ = label;
+	this.onclick_ = event;
+	this.eventClick = function() {};
+}
+
+LertButton.prototype.getDom = function(eventCleanup,defaultButton) {
+	var button = document.createElement('a');
+	//button.setAttribute('href','javascript:void(0);');
+	button.className = 'lertButton';
+	if(this == defaultButton) button.setAttribute('id','lertDefaultButton');
+	button.innerHTML = this.label_;
+
+	var eventOnclick =  this.onclick_;
+	button.onclick = function() {
+		eventCleanup();
+		eventOnclick();
+	}
+	this.eventClick = button.onclick;
+	return button;
+}
Index: /branches/2.2.0.1/expressoMail1_2/js/lert/lert.css
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/lert/lert.css	(revision 3977)
+++ /branches/2.2.0.1/expressoMail1_2/js/lert/lert.css	(revision 3977)
@@ -0,0 +1,83 @@
+#lertOverlay{
+	position: absolute;
+	top: 0;
+	left: 0;
+	z-index: 90;
+	width: 100%;
+	height: 500px;
+	background-color: #000;
+	filter:alpha(opacity=60);
+	-moz-opacity: 0.6;
+	opacity: 0.6;
+}
+
+#lertContainer{
+	position: absolute;
+	top: 40px;
+	left: 0;
+	width: 100%;
+	z-index: 100;
+	text-align: center;
+}
+
+#lertWindow {
+	font-weight:normal;
+	font-size:1em;
+	font-family: Tahoma, Verdana, Sans;
+	border:4px double #aaa;
+	width:40%;
+	margin:0 auto;
+	padding:1px;
+	background:#FFF /*url(i/grad.gif) top left repeat-x;*/
+}
+
+#topBorder{
+	border-bottom:1px solid #aaa;
+	width:100.5%;
+	margin-left:-1px;
+}
+
+#closeIcon{
+	float:right;
+}
+
+#lertMessage {
+	clear:right;
+	padding-bottom:15px;
+	width:80%;
+	text-align:left;
+	margin-left:52px;
+}
+
+#lertIcon {
+	float:left;
+	padding:10px;
+}
+
+#lertButtons {
+	font-size:1.4em;
+	clear:both;
+	text-align:right;
+	margin-bottom:10px;
+}
+
+.lertButton {
+        cursor: pointer;
+	height:20px;
+	background:#DDD;
+	padding:1px 4px;
+	margin: 0px 5px;
+	border:2px outset #AAA;
+	color:#000;
+	text-decoration:none;
+	font: normal 0.7em Verdana, Tahoma, sans;
+}
+
+.lertButton:hover {
+	background:#FFC;
+}
+
+#lertDefaultButton {
+	font-weight:bold;
+}
+
