Index: trunk/expressoMail1_2/js/QuickCatalogSearch.js
===================================================================
--- trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 5134)
+++ trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 5172)
@@ -10,15 +10,15 @@
 	emQuickCatalogSearch.prototype.showList = function(data, begin, end, ID, field)
 	{
-			data_    = data;	
-			id_    = ID;
-            field_ = field;
-            begin_ = begin;
-            end_   = end;
+		data_  = data;	
+		id_    = ID;
+        field_ = field;
+        begin_ = begin;
+        end_   = end;
 
-			keypress_read(data);
-            configure_slider(data);
+		keypress_read(data);
+		configure_slider(data);
 		create_list(data, true);
-            details_results(data);
-			
+		details_results(data);
+
 		id = '1';
 		_this = this;
@@ -36,45 +36,68 @@
 		func_add_contact = function () { 	
 		};		
-		
         _this.showWindow(el_A);	
 	}
-        
-        
+     
+	 
     /* Leitura das teclas de atalho */    
     function keypress_read(data) {	
-		$("#dialog-modal").keydown(function (e) {
+		$("#dialog-modal").unbind('keydown').keydown(function (e) {
 			var keyCode = e.keyCode;
-			arrow = {left: 37, up: 38, right: 39, down: 40, enter: 13, esc: 27};
-			var slider = $( "#slider"  );
+			arrow = {left: 37, up: 38, right: 39, down: 40, enter: 13, esc: 27, space: 32};
+			var slider = $( "#slider" );
 			switch (keyCode) 
 			{
-				case arrow.enter:
+				case arrow.enter:					
 					if(!search_focus){
 						i = $(".ui-selected:last").attr("value") + 1;
-						add_contact_field($("#contact_" + i).html());
+						if($("#actions_"+i).clone().find(".ui-button-text").text() == '+')
+							add_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i);
+						else{
+							remove_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i);
+						}
 						document.getElementById("busca").value = "";
-						$("#dialog-modal").unbind('keydown');
-					$("#dialog-modal").dialog("close");
+						$("#dialog-modal").dialog("close");
 					}
 					break;
 				case arrow.left:
-					slider.slider("value", $( "#slider" ).slider( "value" ) - 1);
-					create_list(data_, false);		
+					if(!search_focus){
+						slider.slider("value", $( "#slider" ).slider( "value" ) - 1);
+						create_list(data_, false);	
+					}
 					break;
 				case arrow.right:
-					if((($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/6))
-						break;
-					slider.slider( "value", $( "#slider" ).slider( "value" ) + 1);					
-					create_list(data_, false);							
+					if(!search_focus){
+						if((($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/6))
+							break;
+						slider.slider( "value", $( "#slider" ).slider( "value" ) + 1);					
+						create_list(data_, false);							
+					}
 					break;
 				case arrow.up:
-					show_detail(data_, "up");
+					if(!search_focus){
+						show_detail(data_, "up");
+					}
 					break;
 				case arrow.down:
-					show_detail(data_, "down");
-						break;
-                                }
+					if(!search_focus){
+						show_detail(data_, "down");
+					}
+					break;
+				case arrow.space:
+
+					if(!search_focus){
+						i = $(".ui-selected:last").attr("value") + 1;
+						if($("#actions_"+i).clone().find(".ui-button-text").text() == '+')
+						{
+							add_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i);
+						}else{
+							remove_contact_field(document.getElementById("contact_"+i).innerHTML, document.getElementById("actions_"+i), "contact_"+i);
+						}
+						document.getElementById("busca").value = "";
+					}
+					break;
+			}
 		});	
-							}
+	}
 	
 	
@@ -88,5 +111,5 @@
 			$('li.ui-selected').next().addClass("ui-selected"); 
 			id_contact++;
-                                        }
+		}
 		else {
 			if(id_contact == (($( "#slider" ).slider( "value" ) -1)*6)) 
@@ -95,18 +118,18 @@
 			$('li.ui-selected').prev().addClass("ui-selected"); 
 			id_contact--;
-                                    } 
+		}					
 		line_contact.removeClass("ui-selected").addClass("ui-selectee");
-		var details = $("#detalhes_contato").empty();                                 
+		var details = $("#detalhes_contato").empty();    
 		switch(data_['type_catalog']) {
 			case 'G':
-                                        var extra_fields = (data_['extra_ldap_fields']).split("#");   
+				var extra_fields = (data_['extra_ldap_fields']).split("#");   
 				if(preferences.default_fields_quick_search != 0) {
 					details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn[0]) + "</label>" + '<span class="value">' + data_[id_contact].mail[0] + '</span></p>');
 					details.append('<p><label class="attribute">Telefone </label>' + '<span class="value">' + data_[id_contact].telephonenumber[0] + '</span></p>');           
-                                        }
+				}
 				for (var i=0; i<=extra_fields.length-1; i++)
-                                            {
-                                                var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
-                                                var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
+				{
+					var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
+					var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
 					if(data_[id_contact][valor.toLowerCase()] != undefined) {
 						var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
@@ -114,24 +137,32 @@
 							details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>");
 							tmp_campo = "";
-                                            }
-                                        }
-                                    }
-					break;
+						}
+					}
+				}
+				break;
 			case 'P':
-				details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>');
+				if(utf8_decoder(data_[id_contact].cn) == 'undefined')
+					details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].title) + '</label>' + '<span class="value">' + data_[id_contact].short_name + '</span></p>');
+				else
+					details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>');
                 if(data_[id_contact].telephonenumber != null)
                     details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data_[id_contact].telephonenumber + '</span></p>');
-						break;	
+				break;
 			default:
-                                var extra_fields = (data_['extra_ldap_fields']).split("#");   
+				var extra_fields = (data_['extra_ldap_fields']).split("#");   
                 if(preferences.default_fields_quick_search != 0 || data_[id_contact].type_contact == "P") {
-					details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>');
+					if(utf8_decoder(data_[id_contact].cn) == 'undefined')
+						details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].title) + '</label>' + '<span class="value">' + data_[id_contact].short_name + '</span></p>');
+					else
+						details.append('<p><label class="attribute">' + utf8_decoder(data_[id_contact].cn) + '</label>' + '<span class="value">' + data_[id_contact].mail + '</span></p>');
 					if(data_[id_contact].telephonenumber != null)
 						details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data_[id_contact].telephonenumber + '</span></p>');
-							}
+				}	
+				if(data_[id_contact].mail[0] == 'undefined')
+					break;
 				if(data_[id_contact].mail[0].length > 1) {
 					for (var i=0; i<=extra_fields.length-1; i++) {
-                                                var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
-                                                var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
+						var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
+						var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
 						if(data_[id_contact][valor.toLowerCase()] != undefined) {
 							var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
@@ -139,17 +170,16 @@
 								details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>");
 								tmp_campo = "";
-                                                }
-                                            }
-                                        }
-                                    }
-					break;
-			}
+							}
+						}
+					}
+				}
+			break;
+		}				
 	}
+
 			
-			
-			
-		/*
-		* Método que cria a lista de contatos
-		*/
+	/*
+	* Método que cria a lista de contatos
+	*/
 	function create_list(data, begin, uiValue) {
 		var sliderValue = 1;
@@ -158,32 +188,78 @@
 		if(uiValue)
 			sliderValue = uiValue;
-					$("#detalhes_contato").empty();
+		$("#detalhes_contato").empty();
 		var paginas = Math.ceil(data.length/6); 
-					$("#title_usuarios").html( get_lang("Results") );
-                        var selectable = $("#selectable");
-						selectable.empty();
-                        var Ul = document.createElement("ul");
+		$("#title_usuarios").html( get_lang("Results") );
+        var selectable = $("#selectable");
+		selectable.empty();
+		var acento = data.search_for;
+        var Ul = document.createElement("ul");
+		var caracteresInvalidos = 'àèìòùâêîôûäëïöüáéíóúãõÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÁÉÍÓÚÃÕ';
+		var caracteresValidos =   'aeiouaeiouaeiouaeiouaoAEIOUAEIOUAEIOUAEIOUAO';	
+		
+		var i = new Number();
+		var j = new Number();
+		var cString = new String();
+		var varRes = '';
+
+		for (i = 0; i < data.search_for.length; i++) {
+			cString = data.search_for.substring(i, i + 1);
+			for (j = 0; j < caracteresInvalidos.length; j++) {
+				if (caracteresInvalidos.substring(j, j + 1) == cString){
+					cString = caracteresValidos.substring(j, j + 1);
+				}
+			}
+			varRes += cString;
+		}
+		data.search_for = varRes;
+		
 		for (i=((sliderValue -1)*6)+1; i<(((sliderValue -1)*6)+1)+6; i++) {
-                        var Op = document.createElement("li");
+			var Op = document.createElement("li");
 			if(i > data.length)
-								break;
-							if (data['type_catalog'] != 'G' && (data[i-1].mail == null || data[i-1].mail == ""))
-                                data[i-1].mail = "No mail"; 
+				break;
+			if (data['type_catalog'] != 'G' && (data[i-1].mail == null || data[i-1].mail == ""))
+				data[i-1].mail = get_lang("No mail"); 
 				
 			if(i == (((sliderValue -1)*6)+1)) {
-								Op.setAttribute("class", "ui-selected");
+				Op.setAttribute("class", "ui-selected");
 				Op.setAttribute("className", "ui-selected");
-							}
-							else {	
-								Op.setAttribute("class", "ui-selectee");
+			}	
+			else { 	
+				Op.setAttribute("class", "ui-selectee");
 				Op.setAttribute("className", "ui-selectee");
-							}
-							var contact_name = utf8_decoder(data[i-1].cn);
-			if(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) != -1 && data.search_for.indexOf(" ") == -1 && data.search_for.indexOf("@") == -1)									
-								contact_name = contact_name.substring(0, contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) + "<u>" + contact_name.substr(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()), data.search_for.length) + "</u>" + contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) + data.search_for.length);
-			Op.innerHTML = '<span class="menu-control"><button onClick="add_contact_field(document.getElementById(\'contact_' + i + '\').innerHTML)">+</button><button onClick="remove_contact_field(document.getElementById(\'contact_' + i + '\').innerHTML)">x</button></span><div id="contact_' + i + '" onDblClick="add_contact_field(this.innerHTML)"><div class="name_contact"><strong>' + contact_name + '</strong><em>' + utf8_decoder(data[i-1].mail) + '</em></div></div>';
-                            $(Op).val(i - 1);
+			}
+			var contact_name = utf8_decoder(data[i-1].cn);
+			if(contact_name == 'undefined'){
+				contact_name = utf8_decoder(data[i-1].title);
+				if(contact_name != 'undefined'){
+					data[i-1].mail = data[i-1].short_name;
+				}
+			}
+			var exist = "add_contact_field";
+			var signal = "+";
+			var btnClass = "add";
+			var emailList = $("#" + field_ + "_" + id_).val();
+			var emails_adicionados = emailList.split(",");
+			for(aux=0; aux<emails_adicionados.length -1; aux++) {
+				if(emails_adicionados[aux].match(/<([^<]*)>[\s]*$/)[1] == utf8_decoder(data[i-1].mail)){
+					emails_adicionados[aux] = "%";
+					exist = "remove_contact_field";
+					signal = "x";
+					btnClass = "remove";
+				}
+			}
+			
+			if(contact_name.toLowerCase().indexOf(acento.toLowerCase()) != -1 && acento.indexOf(" ") == -1 && acento.indexOf("@") == -1)									
+				contact_name = contact_name.substring(0, contact_name.toLowerCase().indexOf(acento.toLowerCase())) + "<u>" + contact_name.substr(contact_name.toLowerCase().indexOf(acento.toLowerCase()), acento.length) + "</u>" + contact_name.substring(contact_name.toLowerCase().indexOf(acento.toLowerCase()) + acento.length);
+			else if(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) != -1 && data.search_for.indexOf(" ") == -1 && data.search_for.indexOf("@") == -1)									
+				contact_name = contact_name.substring(0, contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) + "<u>" + contact_name.substr(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()), data.search_for.length) + "</u>" + contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase()) + data.search_for.length);
+			var line = '<span class="menu-control"><button class="'+btnClass+'" id="actions_'+i+'" onClick="'+exist+'(document.getElementById(\'contact_' + i + '\').innerHTML, this, \'contact_' + i + '\')">'+ signal +'</button></span><div id="contact_' + i + '" onDblClick="'+exist+'(this.innerHTML, document.getElementById(\'actions_'+i+'\'), \'contact_' + i + '\')"><div class="name_contact"><strong class="name">' + contact_name + '</strong><em class="email">' + utf8_decoder(data[i-1].mail) + '</em></div></div>';
+			Op.innerHTML = line;
+            $(Op).val(i - 1);
             selectable.append(Op);
-                        }
+			$("#contact_"+i).click(function(){
+				document.getElementById("amount-text").focus();
+			});
+        }
 		selectable.append(Ul);
 		var first_contact;
@@ -198,5 +274,6 @@
 			});
 		}
-		var details = $("#detalhes_contato").empty();                                 
+		var details = $("#detalhes_contato").empty();   
+		
 		switch (data['type_catalog']) {
 			case 'G':
@@ -220,17 +297,23 @@
 				break;
 			case 'P':
-				details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + '</label>' + '<span class="value">' + data[first_contact].mail + '</span></p>');
+				if(utf8_decoder(data[first_contact].cn) != 'undefined')
+					details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + '</label>' + '<span class="value">' + data[first_contact].mail + '</span></p>');
+				else
+					details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].title) + '</label>' + '<span class="value">' + data[first_contact].short_name + '</span></p>');
                 if(data[first_contact].telephonenumber != null)
 					details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber  + '</span></p>');
 				break;
-			default:
+			default:				
 				var extra_fields = (data['extra_ldap_fields']).split("#");   
 				if(preferences.default_fields_quick_search != 0 || data[first_contact].type_contact == "P") {
-					details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + "</label>" + '<span class="value">' + data[first_contact].mail + "</span></p>");
+					if(utf8_decoder(data[first_contact].cn) != 'undefined')
+						details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].cn) + '</label>' + '<span class="value">' + data[first_contact].mail + '</span></p>');
+					else
+						details.append('<p><label class="attribute">' + utf8_decoder(data[first_contact].title) + '</label>' + '<span class="value">' + data[first_contact].short_name + '</span></p>');
 					if(data[first_contact].telephonenumber != null)
 						details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber + "</span></p>");
 				}
-				if(data[first_contact].mail != "No mail") {
-					if(data[first_contact].mail[0].length > 1) {
+				if(data[first_contact].mail != get_lang("No mail")) {
+					if(data[first_contact].mail.length > 1) {
 						for (var i=0; i<=extra_fields.length-1; i++) {
 							var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
@@ -251,53 +334,31 @@
 		$( "#amount-text" ).val( string_results );
 		$("button").button();
+		//$("button.remove").button({icons:{primary:"ui-icon-close"}, text: false});
+		//$("button.add").button({icons:{primary:"ui-icon-plus"}, text: false});
 		if(!is_ie)
 			document.getElementById("amount-text").focus();	
-		$("#selectable li:first button:first").focus();
+		$("#selectable li:first").focus();
 		removeFocus();
-		}	
+	}	
 		
 		
 	/* Método que configura os detalhes do resultado da busca */
 	function details_results(data) {
-				$(function() {
-                    $( "#selectable" ).selectable({
-						stop: function() {
-								var details = $("#detalhes_contato").empty();                                 
-                                $( ".ui-selected", this ).each(function() {
-                        switch(data['type_catalog']) {
-							case 'G':
-                                        var extra_fields = (data['extra_ldap_fields']).split("#");   
-								if(preferences.default_fields_quick_search != 0) {	
-									details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn[0]) + "</label>" + '<span class="value">' + data[this.value].mail[0] + "</span></p>");
-									details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber[0] + "</span></p>");
-								}
-								for (var i=0; i<=extra_fields.length-1; i++) {
-                                            var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
-                                            var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
-									if(data[this.value][valor.toLowerCase()] != undefined) {
-										var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
-										for(j=0; j<data[this.value][valor.toLowerCase()].length; j++) {
-											details.append(tmp_campo + '<span class="value">' + data[this.value][valor.toLowerCase()][j] + "</span></p>");
-											tmp_campo = "";
-                                            }
-                                        }
-                                    }
-								break;
-							case 'P':
-								details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>");
-                                if(data[this.value].telephonenumber != null)
-                                    details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>");
-								break;
-							default:
-                                                var extra_fields = (data['extra_ldap_fields']).split("#");   
-                                if(preferences.default_fields_quick_search != 0 || data[this.value].type_contact == "P") {
-									details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>");
-									if(data[this.value].telephonenumber != null)
-										details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>");
-                                                }
-								if(data[this.value].mail[0].length > 1) {
+		$(function() {
+			$( "#selectable" ).selectable({
+				stop: function() {
+					var details = $("#detalhes_contato").empty();                                 
+                    $( ".ui-selected", this ).each(function() {
+						if(data.length > 0){
+							switch(data['type_catalog']) {
+								case 'G':
+									var extra_fields = (data['extra_ldap_fields']).split("#");   
+									if(preferences.default_fields_quick_search != 0) {	
+										details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn[0]) + "</label>" + '<span class="value">' + data[this.value].mail[0] + "</span></p>");
+										details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber[0] + "</span></p>");
+									}
 									for (var i=0; i<=extra_fields.length-1; i++) {
-                                                        var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
-                                                        var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
+										var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
+										var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
 										if(data[this.value][valor.toLowerCase()] != undefined) {
 											var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
@@ -305,59 +366,95 @@
 												details.append(tmp_campo + '<span class="value">' + data[this.value][valor.toLowerCase()][j] + "</span></p>");
 												tmp_campo = "";
-                                                        }
-                                                    }
-                                                }
-                                        }
-								break;
-                                    }
-								});
-						}
-                    });
-                });
-        }
-        
-        
-        /* 
-         * Método que configura o slider e os resultados 
-         */
+											}
+										}
+									}
+									break;
+								case 'P':
+									if(utf8_decoder(data[this.value].cn) == 'undefined')
+										details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].title) + "</label>" + '<span class="value">' + data[this.value].short_name + "</span></p>");
+									else
+										details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>");
+									if(data[this.value].telephonenumber != null)
+										details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>");
+									break;
+								default:
+									var extra_fields = (data['extra_ldap_fields']).split("#");   
+									if(preferences.default_fields_quick_search != 0 || data[this.value].type_contact == "P") {
+										if(utf8_decoder(data[this.value].cn) == 'undefined')
+											details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].title) + "</label>" + '<span class="value">' + data[this.value].short_name + "</span></p>");
+										else
+											details.append('<p><label class="attribute">' + utf8_decoder(data[this.value].cn) + "</label>" + '<span class="value">' + data[this.value].mail + "</span></p>");
+										if(data[this.value].telephonenumber != null)
+											details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[this.value].telephonenumber + "</span></p>");
+									}
+									if(data[this.value].mail[0] == 'undefined')
+											break;
+									if(data[this.value].mail[0] != get_lang("No mail")) {
+										if(data[this.value].mail[0].length > 1) {
+											for (var i=0; i<=extra_fields.length-1; i++) {
+												var campo = extra_fields[i].substr(extra_fields[i].indexOf("|")+1);    
+												var valor = extra_fields[i].substr(0, (extra_fields[i].indexOf("|")));                                          
+												if(data[this.value][valor.toLowerCase()] != undefined) {
+													var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
+													for(j=0; j<data[this.value][valor.toLowerCase()].length; j++) {
+														details.append(tmp_campo + '<span class="value">' + data[this.value][valor.toLowerCase()][j] + "</span></p>");
+														tmp_campo = "";
+													}
+												}
+											}
+										}
+									}
+									break;
+							}
+						}
+					});
+				}
+            });
+        });
+    }
+     
+	 
+    /* 
+    * Método que configura o slider e os resultados 
+    */
     function configure_slider(data) {	
         var paginas = (Math.ceil(data.length/6)); 
-            $("#title_usuarios").html( get_lang("Results") );
-            $(function() {
-                $( "#slider" ).slider({
-					value:1,
-					min: 1,
-					max: paginas,
-					step: 1,
+        $("#title_usuarios").html( get_lang("Results") );
+        $(function() {
+            $( "#slider" ).slider({
+				value:1,
+				min: 1,
+				max: paginas,
+				step: 1,
 				slide: function( event, ui ) {
 					create_list(data, false, ui.value); 
-								var string_results = ui.value + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; 
+					var string_results = ui.value + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; 		
 					$( "#amount-text" ).val( string_results );
-						}
-                    });
+				}
+            });
 			$("#selectable li:first button:first").focus();
-                });
-        }
+		});
+    }
         
 	var search_focus = false;
-
+		
 	function setFocus() {search_focus = true;return;}
-		
+	
 	function removeFocus() {search_focus = false;return;}
 		
     function checkEnter(e) {
-			var kC = window.event ? event.keyCode :
-            e && e.keyCode ? e.keyCode :
-            e && e.which ? e.which : null;
+		var kC = window.event ? event.keyCode :
+        e && e.keyCode ? e.keyCode :
+        e && e.which ? e.which : null;
         if (kC) 
-				return kC == 13;
+			return kC == 13;
         else
-				return false;
-			}
+			return false;
+	}
         
-        
-        /* 
-         * Faz a busca direto da tela modal  
-         */
+		
+    /* 
+     * Faz a busca direto da tela modal  
+     */
     function buscaContato(param) {
 		$("#busca, #detalhes_contato, #selectable").empty();
@@ -365,131 +462,187 @@
             alert(get_lang("Please enter a parameter to search"));
             return;
+        }            
+		if(param.length < preferences.search_characters_number) {
+            alert(get_lang("parameter must be at least") + " " +  preferences.search_characters_number + " " + get_lang("characters"));
+            return false;
+        }
+        var catalog = $("#combobox").val();
+        var handler_emQuickSearch = function(data) {
+            data_ = data;
+			if(data_.length > 0) {     
+				configure_slider(data_);
+				create_list(data, true);
+				details_results(data_);
             }
-		if(param.length < preferences.search_characters_number) {
-                alert(get_lang("parameter must be at least") + " " +  preferences.search_characters_number + " " + get_lang("characters"));
-                return false;
+            else {
+				$("#detalhes_contato, #selectable").empty();
+				var selectable = $("#selectable");
+				var Ul = document.createElement("ul");
+				Ul.onclick = function(){
+				};
+				var Op = document.createElement("li");
+				Op.innerHTML = '<span class="menu-control"></span><div id="no_results"><div class="name_contact"><strong class="name">Nenhum Resultado Encontrado</strong></div></div>';
+				selectable.append(Op);
+				selectable.append(Ul);
+				var string_results = "0 " + get_lang("of") + " 0 (0 "  + get_lang("Results") + ")"; 		
+				$( "#amount-text" ).val( string_results );
+				details_results(data);
+                configure_slider(data); 
             }
-            var catalog = $("#combobox").val();
-        var handler_emQuickSearch = function(data) {
-                data_ = data;
-			if(data_.length > 0) {        
-                    configure_slider(data_);    
-                create_list(data_, true);
-                    details_results(data_);
-                }
-            else {
-                    $("#detalhes_contato, #selectable").empty();
-                    configure_slider(data); 
-                }
-            }
-            cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+param+"&field=TO&ID=0&catalog="+catalog, handler_emQuickSearch);
         }
-		
+        cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+param+"&field=TO&ID=0&catalog="+catalog, handler_emQuickSearch);
+    }
+		
+	function verifyEmails(emailAux, contato) {	
+		var contact_id = contato.split("_");		
+		if(contact_id[1] != 0)
+		{
+			var ini = parseInt((contact_id[1]/6).toFixed(0));
+			if(ini != 0 && ini != 1){
+				ini = ini * 6;
+				var fim = ini+1;
+			}
+			else{
+				ini = 1;
+				var fim = ini;
+			}
+			fim = fim +5;
+			var contact2 = "";
+			for(aux = ini; aux <= fim; aux++){
+				if(contact_id[1] != aux){
+					if($("#"+contact_id[0]+"_"+aux).find('.email').text() == emailAux){
+						contact2 = contact_id[0]+"_"+aux;
+						var button = document.getElementById("actions_"+aux);
+						var div = document.getElementById(contact2);
+						if($("#actions_"+aux).find('.ui-button-text').text() == '+'){
+							button.onclick = function(){
+								remove_contact_field(div.innerHTML, button, contact2);
+							};
+							div.ondblclick = function(){
+								remove_contact_field(div.innerHTML, button, contact2);
+							};
+							$("#actions_"+aux).find('.ui-button-text').text('x');
+						}
+						else{
+							button.onclick = function(){
+								add_contact_field(div.innerHTML, button, contact2);
+							};
+							div.ondblclick = function(){
+								add_contact_field(div.innerHTML, button, contact2);
+							};
+							$("#actions_"+aux).find('.ui-button-text').text('+');
+						}
+					}
+				}
+			}
+		}
+	}
+    /* 
+    * Método que adiciona o contato selecionado no campo do email (To, CC, CCo) 
+    */
+    function add_contact_field(contact, button, divs) {
+	
+		var nome = $(contact).clone().find('.name').text();
+		var email = $(contact).clone().find('.email').text();
+		
+		if(email == get_lang("No mail")){
+			alert(get_lang("It is not possible to add this contact as a recipient because it does not have email"));
+			if(!is_ie)
+				document.getElementById("amount-text").focus();
+			return;
+		}
+		
+		verifyEmails(email, divs);
+		
+		final_contact = "\""+nome +"\" <"+email+">, ";
+		
+		var emailList      = document.getElementById(field_ + "_" + id_).value; 
+		
+        if (emailList[0] != '"' && emailList.indexOf(",") < 0)
+			emailList = emailList.substr(end_);
+        if(emailList.lastIndexOf(",") > 0) 
+			emailList = emailList.substr(0, emailList.lastIndexOf(",") + 1);
         
-        /* 
-         * Método que adiciona o contato selecionado no campo do email (To, CC, CCo) 
-         */
-    function add_contact_field(contact) {
-			var emailList      = document.getElementById(field_ + "_" + id_).value; 
-		var contact_parsed = contact.replace(/<[\/]*u>/gi, '');
-		contact_parsed     = contact_parsed.replace(/<u[^>]*>/gi, '');
-		contact_parsed     = contact_parsed.replace(/<\/?[^>]+>/gi, ' ');
-            contact_parsed     = contact_parsed.replace(/^\s+|\s+$/gi, "").replace(/\s{2,}/gi, "|");
-            var tokens_contact = contact_parsed.split("|");
-            if (tokens_contact[1].indexOf("(") > 0)
-                tokens_contact[1] = tokens_contact[1].substr(0, (tokens_contact[1].indexOf("("))-2);
-				
-			var final_contact;
-			if(tokens_contact[2] == undefined)
-			final_contact = "\"" + tokens_contact[0] + "" + "\" <" + tokens_contact[1] + ">, ";
-			else
-			{			
-				if(tokens_contact[3] == undefined)               
-				final_contact =  "\"" + tokens_contact[0] + "" +  tokens_contact[1] + "\" <" + tokens_contact[2] + ">, ";
-				else
-				final_contact =  "\"" + tokens_contact[0] + "" +  tokens_contact[1] + "" +  tokens_contact[2] + "\" <" + tokens_contact[3] + ">, ";
-            }
-        if (emailList[0] != '"' && emailList.indexOf(",") < 0)
-                emailList = emailList.substr(end_);
-            if(emailList.lastIndexOf(",") > 0)
-			emailList = emailList.substr(0, emailList.lastIndexOf(",") + 1);
-            
 		final_contact = final_contact.replace(/\/n/, "");
-            new_emailList = emailList + final_contact;    
-            document.getElementById(field_ + "_" + id_).value = new_emailList;
-		
-		if (is_ie) { 
-			var range= document.getElementById(field_ + "_" + id_).createTextRange(); 
-			range.collapse(false); 
-			range.select(); 
-		} else { 
-			document.getElementById(field_ + "_" + id_).focus();   
-		} 
-		
-		
-		
-			$(this).unbind('keypress');
-			$(this).dialog("close");
-        }
-		
-		/* 
-         * Método que remove o contato selecionado no campo do email (To, CC, CCo) 
-         */
-	function remove_contact_field(contact) {
-			var contact_parsed = contact.replace(/<\/?[^>]+>/gi, ' ');
-            contact_parsed     = contact_parsed.replace(/^\s+|\s+$/gi, "").replace(/\s{2,}/gi, "|");
-			
-		var tokens_contact = contact_parsed.split("|");	
-			if (tokens_contact[2].indexOf("(") > 0)
-                tokens_contact[2] = tokens_contact[2].substr(0, (tokens_contact[2].indexOf("("))-2);
-			var final_contact;
-			if(tokens_contact[3] == undefined)               
-				final_contact =  "\"" + tokens_contact[0] + " " +  tokens_contact[1] + "\" <" + tokens_contact[2] + ">";
-			else
-				final_contact =  "\"" + tokens_contact[0] + " " +  tokens_contact[1] + " " +  tokens_contact[2] + "\" <" + tokens_contact[3] + ">";
-			
+		new_emailList = emailList + final_contact;    
+        document.getElementById(field_ + "_" + id_).value = new_emailList;
+		
+		button.onclick = function(){
+			remove_contact_field(document.getElementById(divs).innerHTML, button, divs);
+		};
+		var div = document.getElementById(divs);
+		
+		div.ondblclick = function(){
+			remove_contact_field(div.innerHTML, button, divs);
+		};
+		
+		button.innerHTML = '<span class="ui-button-text" style="">x</span>';
+    }
+		
+		
+	/* 
+    * Método que remove o contato selecionado no campo do email (To, CC, CCo) 
+    */
+	function remove_contact_field(contact, button, divs) {
+		var email = $(contact).clone().find('.email').text();
 		var exist = false;
+		
 		var emailList = $("#" + field_ + "_" + id_).val();
-			var emails_adicionados = emailList.split(",");
+		var emails_adicionados = emailList.split(",");
+		
+		verifyEmails(email, divs);
+		
 		for(i=0; i<emails_adicionados.length -1; i++) {
-			emails_adicionados[i].replace(/^\s+|\s+$/g, ''); 
-			if(emails_adicionados[i] == final_contact) {
-					emails_adicionados[i] = "%";
+
+			if(emails_adicionados[i].match(/<([^<]*)>[\s]*$/)[1] == email) {
+				emails_adicionados[i] = "%";
 				exist = true;
-				}
-			}
+			}
+		}
+		
 		if (exist == false) 
-				return false;
-			var novos_contatos = emails_adicionados.join(",");  
-            novos_contatos = novos_contatos.replace(/%,/g, "");
+			return false;
+		var novos_contatos = emails_adicionados.join(",");  
+		novos_contatos = novos_contatos.replace(/%,/g, "");
 		$("#" + field_ + "_" + id_).val(novos_contatos);
-		}
+		
+		button.onclick = function(){
+			add_contact_field(document.getElementById(divs).innerHTML, button, divs);
+		};
+		
+		var div = document.getElementById(divs);
+		
+		div.ondblclick = function(){
+			add_contact_field(div.innerHTML, button, divs);
+		};
+		
+		button.innerHTML = '<span class="ui-button-text" style="">+</span>';
+	}
         
-	      
+	 
 	/* Decoder utf8 */	
     function utf8_decoder ( str_data ) {
-            var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
-            str_data += '';
+        var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;     
+        str_data += '';    
         while ( i < str_data.length ) {
-                c1 = str_data.charCodeAt(i);
+            c1 = str_data.charCodeAt(i);
             if (c1 < 128) {
-                    tmp_arr[ac++] = String.fromCharCode(c1);
-                    i++;
+				tmp_arr[ac++] = String.fromCharCode(c1);
+                i++;
             } else if ((c1 > 191) && (c1 < 224)) {
-                            c2 = str_data.charCodeAt(i+1);
-                            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
-                            i += 2;
-                        } else {
-                                    c2 = str_data.charCodeAt(i+1);
-                                    c3 = str_data.charCodeAt(i+2);
-                                    tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
-                                    i += 3;
-                                }
-            }
- 
-            return tmp_arr.join('');
+                        c2 = str_data.charCodeAt(i+1);
+                        tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
+                        i += 2;
+                      } else {
+                                c2 = str_data.charCodeAt(i+1);
+                                c3 = str_data.charCodeAt(i+2);
+                                tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+                                i += 3;
+                             }
         }
+        return tmp_arr.join('');
+    }
         
-              
+    
 	/* Mostra tela de help */	
     function show_help() {
@@ -499,23 +652,32 @@
 						width: 540,
 						modal: true,
-						closeOnEscape: true
+						closeOnEscape: true,
+						close : function (event, ui) {
+									$( "#amount-text" ).focus();
+									event.stopPropagation();
+								}
 			});
 		});
 	}	
-		  
-              
+	
+	$("#dialog-modal_help").live("dialogclose", function(){
+		if(!is_ie)
+			$( "#amount-text" ).focus();
+	});
+
+          
 	emQuickCatalogSearch.prototype.showWindow = function (div) {
 		$(this).bind('keydown');
-				$(function() {
-                    $( "#dialog:ui-dialog" ).dialog( "destroy" );                    
-                    $( "#dialog-modal" ).dialog({
-						resizable: false,
+		$(function() {
+        $( "#dialog:ui-dialog" ).dialog( "destroy" );                    
+        $( "#dialog-modal" ).dialog({
+			resizable: false,
 //			height: "auto",
 			width: 780,
-						modal: true,
+			modal: true,
 			position: 'bottom',
-						closeOnEscape: true,
-						close: function (event, ui) {
-							event.stopPropagation();
+			closeOnEscape: true,
+			close: function (event, ui) {
+				event.stopPropagation();
 				$(this).unbind('keydown');
 				if (is_ie) { 
@@ -528,18 +690,20 @@
 			},
 			open: function () {
-				$("#selectable li:first button:first").focus();    
-						},
-						focus: function (event, ui) {
+				removeFocus();
+				$("#selectable li:first").focus();
+				document.getElementById("amount-text").focus();	
+			},
+			focus: function (event, ui) {
 				//$(this).unbind('keydown');
-						},
-						beforeClose: function (event, ui) {
+			},
+			beforeClose: function (event, ui) {
 				$(this).unbind('keydown');
-						},
+			},
 			buttons:[
 						{
 							text: "Fechar",
 							click: function(){
-								$("#detalhes_contato, #selectable, #busca").empty();
-								$(this).dialog("close");
+												$("#detalhes_contato, #selectable, #busca").empty();
+												$(this).dialog("close");
 												if (is_ie) { 
 													var range= document.getElementById(field_ + "_" + id_).createTextRange(); 
@@ -548,11 +712,11 @@
 												} else { 
 														document.getElementById(field_ + "_" + id_).focus();    
-							} 
+												} 
 											 },
 							style: "margin-top: -2.1em" 
 						}
 					]
-					});
-                });
+			});
+        });
 		$(".ui-dialog .ui-dialog-titlebar")
 		.append('<a href="#" class="ui-dialog-titlebar-minimize ui-corner-all" role="button"><span class="ui-icon ui-icon-minusthick">minimize</span></a>')
@@ -561,5 +725,5 @@
 			$(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin');
 		});
-	
+		
 		$("#dialog-modal button, input.button").button();				
 	}
