Index: /branches/2.2.0.1/expressoMail1_2/index.php
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/index.php	(revision 3994)
+++ /branches/2.2.0.1/expressoMail1_2/index.php	(revision 3995)
@@ -98,4 +98,5 @@
 
 	$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['quick_search_default'] : 1;
+        $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['auto_close_first_tab'] = $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['auto_close_first_tab'] ? $GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['auto_close_first_tab'] : "0";
 
 	//SpellChecker
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 3994)
+++ /branches/2.2.0.1/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 3995)
@@ -650,2 +650,4 @@
 Send messages with return recipient option by default	expressoMail1_2	pt-br	Sempre enviar mensagens com confirmação de leitura?
 With this option every new email will get the return recipient option marked	expressoMail1_2	pt-br	Com essa opção ativa todo novo e-mail terá marcada a opção de Confirmação de leitura padrão.
+You must manualy close one of your tabs before opening a new one	expressoMail1_2	pt-br	Você deve fechar uma de suas abas de edição manualmente para poder abrir outra.
+Auto close the first tab on reaching the maximum number of tabs?	expressoMail1_2	pt-br	Fechar automáticamente a primeira aba ao atingir o número máximo de abas?
Index: /branches/2.2.0.1/expressoMail1_2/inc/hook_settings.inc.php
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/inc/hook_settings.inc.php	(revision 3994)
+++ /branches/2.2.0.1/expressoMail1_2/inc/hook_settings.inc.php	(revision 3995)
@@ -260,4 +260,5 @@
 	'html' => lang('rich text')
 );
+create_check_box('Auto close the first tab on reaching the maximum number of tabs?','auto_close_first_tab','');
 create_check_box('Insert signature automatically in new messages?','use_signature','');
 create_select_box('Signature Type','type_signature',$default,'','','','onchange="javascript:changeType(this.value);" onload="javascript:alert(this.value);"');
Index: /branches/2.2.0.1/expressoMail1_2/js/abas.js
===================================================================
--- /branches/2.2.0.1/expressoMail1_2/js/abas.js	(revision 3977)
+++ /branches/2.2.0.1/expressoMail1_2/js/abas.js	(revision 3995)
@@ -127,12 +127,34 @@
 
 	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;
-		}
-	}
+        resize = resize_borders();
+        if (!resize){
+            var str_continue = '';
+            var bolContinue = true;
+            if (preferences.auto_close_first_tab == 1){
+                str_continue = '\n' + get_lang('You must manualy close one of your tabs before opening a new one');
+                var children = Element('border_tr').childNodes;
+                var bolDelete = true;
+                for (var i=0; i<children.length; i++) {
+                    if ((children[i].nodeName === 'TD') && (children[i].id!=='border_id_0') && (children[i].id!=='border_blank'))
+                    {
+                        bolDelete = true;
+                        var num_child = children[i].id.toString().substr(10);
+                        alternate_border(num_child);
+                        if (editTest(num_child)){
+                            bolDelete = false;
+                        }
+                        if (bolDelete){
+                            bolContinue = false;
+                            delete_border(num_child, 'false');
+                            break;
+                        }
+                    }
+                }
+            }
+            if (bolContinue){
+                alert(get_lang('Reached maximum tab limit') + str_continue );
+                return false;
+            }
+        }
 	
 	if (! id_value) // Is new message?
@@ -252,15 +274,11 @@
 function draftTests(ID, msg_sent){
     var cancel = new LertButton(get_lang('cancel'), function() {
-        Element("border_id_"+ID).onclick = function () { alternate_border(ID);};
+        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')));
+        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() {
@@ -286,27 +304,34 @@
 }
 
+function editTest(ID){
+    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 != ''))
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 function delete_border(ID, msg_sent)
 {
         var bolExecuteClose = true;
 	var borderElem = Element("border_id_" + ID)
-	if (borderElem)
-		borderElem.onclick = null; // It's avoid a FF3 bug
-	else
-		return false;
-
+	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 != ''))
-                    {
-                        draftTests(ID, msg_sent);
-                        bolExecuteClose = false;
-                    }
-		}
+            if (editTest(ID)){
+                bolExecuteClose = false;
+                return(draftTests(ID, msg_sent));
+            }
 	}
         if (bolExecuteClose)
