Index: /trunk/prototype/modules/mail/js/label.js
===================================================================
--- /trunk/prototype/modules/mail/js/label.js	(revision 5547)
+++ /trunk/prototype/modules/mail/js/label.js	(revision 5554)
@@ -29,5 +29,7 @@
 			$(span).html($(".label-list").find(".edit-value-list").val())
 			.parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel).trigger("click");
+			winElement.find(".buttons .save-label").click(save_editLabel());	
 			winElement.find(".buttons .save-label").trigger("click");
+			
 		}else if( event.keyCode == 27){
 			$(this).trigger("focusout");
@@ -44,294 +46,5 @@
 	event.stopImmediatePropagation();
 }
-function colors_suggestions(){
-	return [
-				{name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'},
-				{name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'},
-				{name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'},
-				{name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'},
-				{name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'}
-			]		
-}
-function rgb2hex(rgb){
- rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
- return "#" +
-  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
-  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
-  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
-}
-
-function confirmDelete(id){
-	$.Zebra_Dialog('<strong>Deseja excluir esse marcador?</strong>', {
-		'type':     'question',
-		'title':    'Atenção',
-		'buttons': ['Sim','Não'],	
-		'onClose':  function(caption) {
-			if(caption == 'Sim'){
-				delete_label(id);
-			}
-		}
-	});	
-}			
-function delete_label(id){
-	$(".label-list li").each(function () {
-		var regex_match = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
-		if (regex_match && regex_match[1] && regex_match[1] == id) {	
-			$(this).remove();
-		}
-	});
-	DataLayer.remove('label', id);
-	DataLayer.commit();
-	winElement.find(".label-list li:first").trigger("click");
-	
-	if($(".label-list li").length == 0){
-		winElement.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');			
-	} 
-	var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
-	if (qtdLi == 0){
-		$(".my-labels").addClass("hidden");
-		$(".label-list-container ul").find(".empty-item").css("display","");
-		winElement.find(".buttons .save-label .ui-button-text").text('Criar');
-		$(".delete-label").button("disable");	
-				
-		winElement.find('.input-nome').val("");
-		winElement.find(".preview-label-inner").text("");
-	
-		var colorpicker = winElement.find('.lebals-colorpicker');
-		colorpicker.find('input[name="backgroundColor"]').val("#ebebeb")
-		.css("background-color", "#ebebeb").focus().end()
-		.find('input[name="fontColor"]').val("#000000").css("background-color", "#000000").focus().end()
-		.find('input[name="borderColor"]').val("#000000").css("background-color", "#000000").focus().end()
-		.find('.preview-label-outer').css({
-			'background-color':"#ebebeb",
-			'color':"#000000",
-			'border-color':"#000000"
-		});
-		$(".input-nome").keyup(function () {
-			var value = $(this).val();
-			winElement.find('.preview-label-inner').text(value);
-		}).keyup();				
-	}		
-}
-function new_label(nameLabel, isNew){
-	var labelCreated = {
-		uid: User.me.id,
-		name : nameLabel,
-		backgroundColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
-		fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
-		borderColor :!!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
-	}
-	DataLayer.put('label', labelCreated);
-	
-	$(".add-label-button").removeClass("ui-icon ui-icon-plus")
-	.html('<img alt="Carregando" title="Carregando" style="margin-left:10px;" src="../prototype/modules/mail/img/loader.gif" />');
-	
-	DataLayer.commit(false, false, function(){
-
-		labels = DataLayer.get('label',{criteria:{order: 'id'}}, true);
-		newLabel = {
-			id: labels[labels.length - 1].id, 
-			name : labels[labels.length- 1].name,
-			uid: User.me.id,
-			bgColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
-			fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
-			borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
-		};
-
-		$(".label-list-container ul").find(".empty-item").css("display","none");
-		$(".label-list-container ul")
-		.prepend(DataLayer.render("../prototype/modules/mail/templates/label_listitem.ejs", newLabel))
-		.find("li:first")
-		.fadeIn("slow").click(configureLabel);
-		
-		$("#MyMarckersList")
-		.html(
-			"<div class='my-labels'>" +
-				"<img src='../prototype/modules/mail/img/tag.png'/>" +
-				"<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
-				
-				"<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
-			"</div>"
-		)		
-		.append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
-		.find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
-		.find(".square-color").css("display","").click(function(){
-			$(this).parent(".label-item").each(function(){
-				configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
-			});
-		});
-		$("#MyMarckersList a.title-my-labels").click(function() {
-			$("#MyMarckersList ul.label-list").toggleClass("hidden")
-			$('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
-			$('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
-		 });
-
-		$(".label-list-container .label-list li").not(".empty-item").click(function(){
-			$(".label-list-container .label-list li").find("img").remove();
-			$(".label-list-container .label-list li.label-item").removeClass("selected");
-			$(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
-			$(this).addClass("selected");
-		});
-		
-		$(".label-list-container .label-list li").find('.button').button()
-		.filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
-		.filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
-		
-		//posiciona para edição o label inserido			
-		winElement.find("ul.label-list li:first").trigger("click");			
-		winElement.find(".buttons .save-label .ui-button-text").text('Salvar');
-		$(".delete-label").button("enable");
-		
-		winElement.find('.edit').unbind("click").click(editLabel);				
-		winElement.find('.close').click(deleteLabel);
-		
-		$(".my-labels").removeClass("hidden");
-		
-		$.contextMenu( 'destroy', ".table_box tbody tr");
-		loadMenu();
-		
-		$(".add-label-button").empty()
-		.addClass("ui-icon ui-icon-plus");
-	});
-
-}
-function init_label(data){
-
-	winElement = data.window;
-	
-	//TODO Mudar quando API abstrair atualizações no cache
-	DataLayer.remove('label',false);
-	labels = DataLayer.get('label',{criteria:{order: 'name'}});
-	
-	if(labels){
-		Label_List = winElement
-		.find(".label-list-container").html(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels: labels}));
-		
-	}else{
-		//Exibe a mensagem informando o usuário de que não há nenhum marcador cadastrado.
-		Label_List = winElement
-		.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');
-		
-	}
-	Label_List.end()
-	.find('.button').button()
-	.filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
-	.filter('.close').button({icons:{primary:'ui-icon-close'}, text:false}); 	
-	
-	winElement.find('.edit').click(editLabel);
-	winElement.find('.close').click(deleteLabel);
-	
-	//marca 'd agua
-	winElement.find(".insert-label").Watermark(winElement.find(".insert-label").val());
-	
-	$("input.insert-label").keyup(function () {
-		$.Watermark.HideAll();
-		var value = $(this).val();
-		winElement.find('.input-nome').val(value);
-	}).keyup();
-	
-	if (!(labels)){
-		winElement.find(".buttons .save-label .ui-button-text").text('Criar');
-		$(".delete-label").button("disable");
-	}else{
-		winElement.find(".label-list li:first").addClass("selected").prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
-	}
-	$(".save-label").button("disable");
-	/**
-	* seta a ação de click para os marcadores listados na tela
-	*/
-	winElement.find(".label-list li").not(".empty-item").click(configureLabel);
-	
-	if (data.selectedItem)
-		winElement.find(".label-list li.label-item-"+data.selectedItem).trigger("click");
-	else
-		winElement.find(".label-list li:first").trigger("click");
-		
-	var dataColorPicker = {
-		colorsSuggestions: colors_suggestions()
-	};
-	
-	winElement.find('select.color-suggestions').change(function() {
-		$(".save-label").button("enable");
-		var colorpicker = winElement.find('.lebals-colorpicker');
-		var colors;
-		if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) {	
-			colorpicker
-			.find('input[name="fontColor"]').val(colors.font).focus().end()	
-			.find('input[name="backgroundColor"]').val(colors.background).focus().end()
-			.find('input[name="borderColor"]').val(colors.border).focus().end()
-
-			.find('.preview-label-outer').css({
-				'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background,
-				'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border,
-				'color':dataColorPicker.colorsSuggestions[$(this).val()].font 
-			});
-		}					
-	});
-	var colorpickerPreviewChange = function(color) {
-			
-		var pickedup = winElement.find('.colorwell-selected').val(color).css('background-color', color);
-
-		$(".save-label").button("enable");
-		
-		var colorpicker = winElement.find('.lebals-colorpicker');			
-
-		if (pickedup.is('input[name="backgroundColor"]')) {
-			colorpicker.find('.preview-label-outer').css('background-color',color);
-		} else if (pickedup.is('input[name="fontColor"]')) {
-			colorpicker.find('.preview-label-outer').css('color',color);
-		} else if (pickedup.is('input[name="borderColor"]')) {
-			colorpicker.find('.preview-label-outer').css('border-color',color);
-		}		
-	} 
-		
-	var f = $.farbtastic(winElement.find('.colorpicker'), colorpickerPreviewChange);
-	var selected;
-				
-	winElement.find('.colorwell').each(function () {
-		f.linkTo(this);
-	})
-	.focus(function() {
-		if (selected) {
-			$(selected).removeClass('colorwell-selected');
-		}
-		$(selected = this).addClass('colorwell-selected');
-		f.linkTo(this, colorpickerPreviewChange);
-		f.linkTo(colorpickerPreviewChange);
-	});
-	
-	winElement.find(".add-label-button").click(function (event) {
-		$.Watermark.HideAll();
-		var nameLabel = winElement.find(".insert-label").val();
-		if(nameLabel.length >= 2){
-			new_label(nameLabel, true);
-			$.Watermark.ShowAll();
-			winElement.find(".insert-label").val("");
-			} else {
-				alert("Mínimo 2 caracteres");
-			}
-		event.stopImmediatePropagation();
-	});
-	
-	winElement.find('.insert-label').keydown(function(event, ui) {
-		if (event.keyCode == 13)
-			winElement.find(".add-label-button").trigger('click');
-	});
-	
-	//excluir marcador {deve ser para o botão grande na janela de edição e nao o pequeno da lista}
-	winElement.find(".buttons .delete-label").click(function(event){
-		var id = winElement.find(".edit-label").val();
-		confirmDelete(id);
-		event.stopImmediatePropagation();
-	});
-	
-	$(".label-list-container .label-list li").not(".empty-item").click(function(){
-		$(".label-list-container .label-list li").find("img").remove();
-		$(".label-list-container .label-list li.label-item").removeClass("selected");
-		$(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
-		$(this).addClass("selected");
-	});
-		
-	//salvar/criar marcador
-	winElement.find(".buttons .save-label").click(function(){
+function save_editLabel(){
 		$(".save-label").button("disable");
 		var labelEdited = {
@@ -420,5 +133,296 @@
 		
 		$(".label-list-container .label-list").find(".label-item-"+labelEdited.id).trigger("click");
+
+}
+function colors_suggestions(){
+	return [
+				{name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'},
+				{name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'},
+				{name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'},
+				{name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'},
+				{name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'}
+			]		
+}
+function rgb2hex(rgb){
+ rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
+ return "#" +
+  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
+  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
+  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
+}
+
+function confirmDelete(id){
+	$.Zebra_Dialog('<strong>Deseja excluir esse marcador?</strong>', {
+		'type':     'question',
+		'title':    'Atenção',
+		'buttons': ['Sim','Não'],	
+		'onClose':  function(caption) {
+			if(caption == 'Sim'){
+				delete_label(id);
+			}
+		}
 	});	
+}			
+function delete_label(id){
+	$(".label-list li").each(function () {
+		var regex_match = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
+		if (regex_match && regex_match[1] && regex_match[1] == id) {	
+			$(this).remove();
+		}
+	});
+	DataLayer.remove('label', id);
+	DataLayer.commit();
+	winElement.find(".label-list li:first").trigger("click");
+	
+	if($(".label-list li").length == 0){
+		winElement.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');			
+	} 
+	var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
+	if (qtdLi == 0){
+		$(".my-labels").addClass("hidden");
+		$(".label-list-container ul").find(".empty-item").css("display","");
+		winElement.find(".buttons .save-label .ui-button-text").text('Criar');
+		$(".delete-label").button("disable");	
+				
+		winElement.find('.input-nome').val("");
+		winElement.find(".preview-label-inner").text("");
+	
+		var colorpicker = winElement.find('.lebals-colorpicker');
+		colorpicker.find('input[name="backgroundColor"]').val("#ebebeb")
+		.css("background-color", "#ebebeb").focus().end()
+		.find('input[name="fontColor"]').val("#000000").css("background-color", "#000000").focus().end()
+		.find('input[name="borderColor"]').val("#000000").css("background-color", "#000000").focus().end()
+		.find('.preview-label-outer').css({
+			'background-color':"#ebebeb",
+			'color':"#000000",
+			'border-color':"#000000"
+		});
+		$(".input-nome").keyup(function () {
+			var value = $(this).val();
+			winElement.find('.preview-label-inner').text(value);
+		}).keyup();				
+	}		
+}
+function new_label(nameLabel, isNew){
+	var labelCreated = {
+		uid: User.me.id,
+		name : nameLabel,
+		backgroundColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
+		fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
+		borderColor :!!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
+	}
+	DataLayer.put('label', labelCreated);
+	
+	$(".add-label-button").removeClass("ui-icon ui-icon-plus")
+	.html('<img alt="Carregando" title="Carregando" style="margin-left:10px;" src="../prototype/modules/mail/img/loader.gif" />');
+	
+	DataLayer.commit(false, false, function(){
+
+		labels = DataLayer.get('label',{criteria:{order: 'id'}}, true);
+		newLabel = {
+			id: labels[labels.length - 1].id, 
+			name : labels[labels.length- 1].name,
+			uid: User.me.id,
+			bgColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
+			fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
+			borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
+		};
+
+		$(".label-list-container ul").find(".empty-item").css("display","none");
+		$(".label-list-container ul")
+		.prepend(DataLayer.render("../prototype/modules/mail/templates/label_listitem.ejs", newLabel))
+		.find("li:first")
+		.fadeIn("slow").click(configureLabel);
+		
+		$("#MyMarckersList")
+		.html(
+			"<div class='my-labels'>" +
+				"<img src='../prototype/modules/mail/img/tag.png'/>" +
+				"<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
+				
+				"<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
+			"</div>"
+		)		
+		.append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
+		.find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
+		.find(".square-color").css("display","").click(function(){
+			$(this).parent(".label-item").each(function(){
+				configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
+			});
+		});
+		$("#MyMarckersList a.title-my-labels").click(function() {
+			$("#MyMarckersList ul.label-list").toggleClass("hidden")
+			$('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
+			$('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
+		 });
+
+		$(".label-list-container .label-list li").not(".empty-item").click(function(){
+			$(".label-list-container .label-list li").find("img").remove();
+			$(".label-list-container .label-list li.label-item").removeClass("selected");
+			$(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
+			$(this).addClass("selected");
+		});
+		
+		$(".label-list-container .label-list li").find('.button').button()
+		.filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
+		.filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
+		
+		//posiciona para edição o label inserido			
+		winElement.find("ul.label-list li:first").trigger("click");			
+		winElement.find(".buttons .save-label .ui-button-text").text('Salvar');
+		$(".delete-label").button("enable");
+		
+		winElement.find('.edit').unbind("click").click(editLabel);				
+		winElement.find('.close').click(deleteLabel);
+		
+		$(".my-labels").removeClass("hidden");
+		
+		$.contextMenu( 'destroy', ".table_box tbody tr");
+		loadMenu();
+		
+		$(".add-label-button").empty()
+		.addClass("ui-icon ui-icon-plus");
+	});
+
+}
+function init_label(data){
+
+	winElement = data.window;
+	
+	//TODO Mudar quando API abstrair atualizações no cache
+	DataLayer.remove('label',false);
+	labels = DataLayer.get('label',{criteria:{order: 'name'}});
+	
+	if(labels){
+		Label_List = winElement
+		.find(".label-list-container").html(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels: labels}));
+		
+	}else{
+		//Exibe a mensagem informando o usuário de que não há nenhum marcador cadastrado.
+		Label_List = winElement
+		.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');
+		
+	}
+	Label_List.end()
+	.find('.button').button()
+	.filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
+	.filter('.close').button({icons:{primary:'ui-icon-close'}, text:false}); 	
+	
+	winElement.find('.edit').click(editLabel);
+	winElement.find('.close').click(deleteLabel);
+	
+	//marca 'd agua
+	winElement.find(".insert-label").Watermark(winElement.find(".insert-label").val());
+	
+	$("input.insert-label").keyup(function () {
+		$.Watermark.HideAll();
+		var value = $(this).val();
+		winElement.find('.input-nome').val(value);
+	}).keyup();
+	
+	if (!(labels)){
+		winElement.find(".buttons .save-label .ui-button-text").text('Criar');
+		$(".delete-label").button("disable");
+	}else{
+		winElement.find(".label-list li:first").addClass("selected").prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
+	}
+	$(".save-label").button("disable");
+	/**
+	* seta a ação de click para os marcadores listados na tela
+	*/
+	winElement.find(".label-list li").not(".empty-item").click(configureLabel);
+	
+	if (data.selectedItem)
+		winElement.find(".label-list li.label-item-"+data.selectedItem).trigger("click");
+	else
+		winElement.find(".label-list li:first").trigger("click");
+		
+	var dataColorPicker = {
+		colorsSuggestions: colors_suggestions()
+	};
+	
+	winElement.find('select.color-suggestions').change(function() {
+		$(".save-label").button("enable");
+		var colorpicker = winElement.find('.lebals-colorpicker');
+		var colors;
+		if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) {	
+			colorpicker
+			.find('input[name="fontColor"]').val(colors.font).focus().end()	
+			.find('input[name="backgroundColor"]').val(colors.background).focus().end()
+			.find('input[name="borderColor"]').val(colors.border).focus().end()
+
+			.find('.preview-label-outer').css({
+				'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background,
+				'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border,
+				'color':dataColorPicker.colorsSuggestions[$(this).val()].font 
+			});
+		}					
+	});
+	var colorpickerPreviewChange = function(color) {
+			
+		var pickedup = winElement.find('.colorwell-selected').val(color).css('background-color', color);
+
+		$(".save-label").button("enable");
+		
+		var colorpicker = winElement.find('.lebals-colorpicker');			
+
+		if (pickedup.is('input[name="backgroundColor"]')) {
+			colorpicker.find('.preview-label-outer').css('background-color',color);
+		} else if (pickedup.is('input[name="fontColor"]')) {
+			colorpicker.find('.preview-label-outer').css('color',color);
+		} else if (pickedup.is('input[name="borderColor"]')) {
+			colorpicker.find('.preview-label-outer').css('border-color',color);
+		}		
+	} 
+		
+	var f = $.farbtastic(winElement.find('.colorpicker'), colorpickerPreviewChange);
+	var selected;
+				
+	winElement.find('.colorwell').each(function () {
+		f.linkTo(this);
+	})
+	.focus(function() {
+		if (selected) {
+			$(selected).removeClass('colorwell-selected');
+		}
+		$(selected = this).addClass('colorwell-selected');
+		f.linkTo(this, colorpickerPreviewChange);
+		f.linkTo(colorpickerPreviewChange);
+	});
+	
+	winElement.find(".add-label-button").click(function (event) {
+		$.Watermark.HideAll();
+		var nameLabel = winElement.find(".insert-label").val();
+		if(nameLabel.length >= 2){
+			new_label(nameLabel, true);
+			$.Watermark.ShowAll();
+			winElement.find(".insert-label").val("");
+			} else {
+				alert("Mínimo 2 caracteres");
+			}
+		event.stopImmediatePropagation();
+	});
+	
+	winElement.find('.insert-label').keydown(function(event, ui) {
+		if (event.keyCode == 13)
+			winElement.find(".add-label-button").trigger('click');
+	});
+	
+	//excluir marcador {deve ser para o botão grande na janela de edição e nao o pequeno da lista}
+	winElement.find(".buttons .delete-label").click(function(event){
+		var id = winElement.find(".edit-label").val();
+		confirmDelete(id);
+		event.stopImmediatePropagation();
+	});
+	
+	$(".label-list-container .label-list li").not(".empty-item").click(function(){
+		$(".label-list-container .label-list li").find("img").remove();
+		$(".label-list-container .label-list li.label-item").removeClass("selected");
+		$(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
+		$(this).addClass("selected");
+	});
+		
+	//salvar/criar marcador
+	winElement.find(".buttons .save-label").click(save_editLabel());	
 	//desfazer marcador
 	winElement.find(".buttons .undo-label").click(function(event){
Index: /trunk/prototype/modules/mail/js/followupflag.js
===================================================================
--- /trunk/prototype/modules/mail/js/followupflag.js	(revision 5548)
+++ /trunk/prototype/modules/mail/js/followupflag.js	(revision 5554)
@@ -350,4 +350,5 @@
 	
 	.filter('.menu-configure-followupflag .delete').click(function(){
+
 		for(i = 0; i < selectedMessageIds.length; i++){
 			var folder_name;
@@ -372,4 +373,5 @@
 		DataLayer.commit();
 		winElement.dialog("close");
+		
 	});
 
Index: /trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- /trunk/expressoMail1_2/js/common_functions.js	(revision 5540)
+++ /trunk/expressoMail1_2/js/common_functions.js	(revision 5554)
@@ -676,5 +676,8 @@
 		modal: true,
 		closeOnEscape:true,
-		close:function(event, ui) {event.stopPropagation();},
+		close:function(event, ui) {
+			select_all_search_messages(false, 'content_id_'+currentTab);
+			event.stopPropagation();
+		},
 		autoOpen:false,
 		dialogClass: 'dialog-configure-label'
@@ -724,4 +727,5 @@
 		close:function(event, ui) {
 			$('.followupflag-configure-win').addClass('hidden');
+			select_all_search_messages(false, 'content_id_'+currentTab);
 			event.stopPropagation();
 		},
