Index: sandbox/expresso/novos_templates/expressoMail1_2/js/abas.js
===================================================================
--- trunk/expressoMail1_2/js/abas.js	(revision 667)
+++ sandbox/expresso/novos_templates/expressoMail1_2/js/abas.js	(revision 773)
@@ -14,5 +14,7 @@
 		return false; // Not possible to alternate
 	show_hide_span_paging(ID);
-	Element("footer_menu").style.display = (ID != "0" ? 'none' : '');
+	spanD = Element("span_D");
+	if (spanD)
+		spanD.style.display = (openTab.type[ID] == 0 ? '' : 'none');
 	var len = BordersArray.length;
 	for (var i=0; i < len; i++)
@@ -80,4 +82,7 @@
 	 	numBox=ID;
  	}
+	else
+        	if (ID.match("search_"))
+                	numBox=ID.substr(7);
         currentTab=ID;
 	return ID;
@@ -86,5 +91,5 @@
 function create_border(borderTitle, id_value)
 {
-	var resize = false;	
+	var resize = false;
 	var offWidth = Element('border_blank').offsetWidth ? Element('border_blank').offsetWidth : Element('border_blank').clientWidth;
 	if (offWidth < 200) {
@@ -95,27 +100,13 @@
 		}
 	}
-	Element("footer_menu").style.display = 'none';
 	
 	if (! id_value) // Is new message?
 		var ID = parseInt(BordersArray[(BordersArray.length-1)].sequence) + 1;
-	else{
-		if (Element("border_id_"+id_value)){ // It's opened already!
-			alternate_border(id_value);
-			return false;
-			}
-		
-		if (typeof(id_value) == 'string')
-			for (var bord = 1; bord <= 10; bord++)
-				if (openTab.imapUid[bord] == id_value.substr(0,id_value.length-2)){
-					alternate_border(bord); // It's opened already! (in a new message)
-					return false;
-				}
-
-		
+	else
+	{
+                if (Element("border_id_"+id_value)) // It's opened already!
+			return alternate_border(id_value);
 		var ID = id_value;
-		if (Element("border_id_"+id_value+"_r")) // Edit message? if yes treat like new in dragdrop case
-					var id_value = null;
-	}
-	
+	}
 	td = document.createElement("TD");
 	td.id="border_id_" + ID;
@@ -126,31 +117,28 @@
 	else
 		td.setAttribute("width", "200px");
-		
-	td.className = "menu";
+
 	td.setAttribute("align", "right");
 	td.onclick = function(){alternate_border(ID);};
 	td.setAttribute("noWrap","true");
-	var subject = borderTitle;
-	
+
 	borderTitle = borderTitle ?  borderTitle : id_value ? get_lang("No Subject") : "&nbsp;"	;
 	td.value = borderTitle;
-	if (borderTitle.length > 21){
+	if (borderTitle.length > 21)
 		borderTitle = borderTitle.substring(0,21) + "...";
-	}
-	
+
 	if (resize)
 		borderTitle = borderTitle.substring(0, resize*0.08);
-		
-	td.innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + ID+" class='font-menu' width=*>" + borderTitle + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='templates/default/images/close_button.gif'></td></tr></table>";
+
+	td.innerHTML = "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td id=font_border_id_" + ID+" class='font-menu' width=*>" + borderTitle + "</td><td width=1px><img onmousedown='javascript:return false' style='cursor:pointer' onclick=delete_border('" + ID + "','false') src='templates/"+template+"/images/close_button.gif'></td></tr></table>";
 
 	bb = document.getElementById("border_blank");
 	parent_bb = bb.parentNode; //Pego o tbody
 	parent_bb.insertBefore(td, bb);
-	
-	if((typeof(id_value) == 'string') && id_value.match(/_r$/))	
+
+	if(! Element("border_id_"+id_value+"_r") ||((typeof(id_value) == 'string') && id_value.match(/_r$/)))
 		_dragArea.makeDragged(td, id_value,td.value);
 
 	BordersArray[BordersArray.length] = new setBorderAttributes(ID);
-	
+
 	var div = document.createElement("DIV");
 	div.id = "content_id_" + ID;
@@ -160,7 +148,7 @@
 	var bar = document.getElementById("toolbar");
 	var offset = 0;
-	if(bar.style.visibility != 'hidden') 
+	if(bar.style.visibility != 'hidden')
 		offset = bar.offsetHeight ? bar.offsetHeight :  bar.clientHeight;
-		
+
 	div.style.height = document.body.clientHeight - offset - (is_ie ? 76 : 86);
 	div.style.overflow = "hidden";
@@ -173,9 +161,7 @@
 
 		div.style.width = defaultWidth;
-//		div.style.width ="99.3%";
-	}
-	document.getElementById("exmail_main_body").appendChild(div);
+	}
+	Element("exmail_main_body").insertBefore(div,Element("footer_menu"));
 	alternate_border(ID);
-	
 	return ID;
 }
@@ -249,17 +235,10 @@
 
 	hold_session = false;
-	for (i=0;i<BordersArray.length;i++)
-	{
-		m = document.getElementById(BordersArray[i].border_id);
-		if ((m) && (m.className == 'menu-sel'))
-			border_selected = BordersArray[i].border_id;
-	}
-	
-	if ('border_id_' + ID == border_selected)
-	{
-		if (BordersArray[i-2].sequence == ID)
+	if (exist_className(Element('border_id_'+ID),'menu-sel'))
+	{
+		if (BordersArray[BordersArray.length-2].sequence == ID)
 			this.alternate_border(0);
 		else
-			this.alternate_border(BordersArray[i-2].sequence);
+			this.alternate_border(BordersArray[BordersArray.length-2].sequence);
 	}
 
@@ -267,20 +246,18 @@
 	border = Element('border_id_' + ID);
 	border.parentNode.removeChild(border);
+	var j=0;
+	var new_BordersArray = new Array();
+	for (i=0;i<BordersArray.length;i++)
+		if (document.getElementById(BordersArray[i].border_id) != null){
+			new_BordersArray[j] = BordersArray[i];
+			j++;
+		}
+	if(j == 1)
+		Element("footer_menu").style.display = '';
+	BordersArray = new_BordersArray;
+
 	// Remove Div Content
 	content = Element('content_id_' + ID);
 	content.parentNode.removeChild(content);
-	
-	var new_BordersArray = new Array();
-	j = 0;
-	for (i=0;i<BordersArray.length;i++)
-	{
-		if (Element(BordersArray[i].border_id) != null){
-			new_BordersArray[j] = BordersArray[i];
-			j++;	
-		}
-	}
-	if(j == 1)
-		Element("footer_menu").style.display = '';
-	BordersArray = new_BordersArray;
 	return true;
 }
