Index: trunk/expressoMail1_2/js/QuickCatalogSearch.js
===================================================================
--- trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 5075)
+++ trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 5134)
@@ -7,4 +7,5 @@
 	}
         
+	/* showlist */	
 	emQuickCatalogSearch.prototype.showList = function(data, begin, end, ID, field)
 	{
@@ -16,14 +17,8 @@
 
 			keypress_read(data);
-            init_results(data);
             configure_slider(data);
+		create_list(data, true);
             details_results(data);
 			
-  		    connector.loadScript("ccQuickAdd");
-
-            if(preferences.use_shortcuts == '0'){
-                connector.loadScript("shortcut");
-            }
-		
 		id = '1';
 		_this = this;
@@ -46,180 +41,108 @@
         
         
-    function keypress_read(data) 
-	{
-		$("#dialog-modal").keypress(function (e) 
-		{
-			var keyCode = e.keyCode || e.which,
-			arrow = {left: 37, up: 38, right: 39, down: 40, enter: 13, esc: 27 };
+    /* Leitura das teclas de atalho */    
+    function keypress_read(data) {	
+		$("#dialog-modal").keydown(function (e) {
+			var keyCode = e.keyCode;
+			arrow = {left: 37, up: 38, right: 39, down: 40, enter: 13, esc: 27};
 			var slider = $( "#slider"  );
 			switch (keyCode) 
 			{
 				case arrow.enter:
-					add_contact_field(document.getElementsByClassName("ui-selected")[0].getElementsByClassName("name_contact")[0].innerHTML);
+					if(!search_focus){
+						i = $(".ui-selected:last").attr("value") + 1;
+						add_contact_field($("#contact_" + i).html());
+						document.getElementById("busca").value = "";
+						$("#dialog-modal").unbind('keydown');
 					$("#dialog-modal").dialog("close");
+					}
 					break;
-				
 				case arrow.left:
-					slider.slider( "value", $( "#slider" ).slider( "value" ) - 1);
-					create_list(data_);					
+					slider.slider("value", $( "#slider" ).slider( "value" ) - 1);
+					create_list(data_, false);		
 					break;
-				
 				case arrow.right:
-					if( (($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/7) )
-					{
-						alert("Não há mais páginas");
+					if((($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/6))
 						break;
-					}
 					slider.slider( "value", $( "#slider" ).slider( "value" ) + 1);					
-					create_list(data_);						
+					create_list(data_, false);							
 					break;
-				
 				case arrow.up:
-					id_contact = document.getElementsByClassName("ui-selected")[0].value;
-					if(id_contact == (($( "#slider" ).slider( "value" ) -1)*7))
+					show_detail(data_, "up");
+					break;
+				case arrow.down:
+					show_detail(data_, "down");
 						break;
-					var line_contact = $('li.ui-selected');
-					$('li.ui-selected').prev().removeClass("ui-selectee").addClass("ui-selected"); //css('background-color', '#72A9D3');
-					line_contact.removeClass("ui-selected").addClass("ui-selectee");
-					var details = $("#detalhes_contato").empty();                                 
-						$( ".ui-selected", this ).each(function() {
-                            if(data_['type_catalog'] == 'G')
-                            {                                         
-                                var extra_fields = (data_['extra_ldap_fields']).split("#");   
-                                /* Default fields */
-                                details.append("<strong>" + utf8_decoder(data_[this.value].cn[0]));
-                                details.append("<br />" + data_[this.value].mail[0]);
-                                details.append("<br /><br /><strong>Matrícula<br />");
-                                details.append(data_[this.value].employeenumber[0] + "<br />");
-                                details.append("<br /><strong> Telefone <br />");
-                                details.append(data_[this.value].telephonenumber[0] + "<br />");
-                                details.append(data_[this.value].telephonenumber[0]);
-                                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] != undefined)
-                                    {    
-                                        details.append("<br /><br /><strong>" + campo);
-                                        details.append("<br />" + data_[this.value][valor][0]);
-                                    }
                                 }
+		});	
 							}
-                            else
-                            {
-                                    if(data_['type_catalog'] == 'P')
-                                    {
-                                        /* Default fields */
-                                        details.append("<strong>" + utf8_decoder(data_[this.value].cn));
-                                        details.append("<br />" + data_[this.value].mail);
-                                        if(data_[this.value].telephonenumber != "")
-                                        {
-                                            details.append("<br /><br /><br /><strong> Telefone <br />");
-                                            details.append(data_[this.value].telephonenumber + "<br />");  
+	
+	
+	/* Mostra os detalhes do contato selecionado */
+	function show_detail(data_, direction) {
+		id_contact = $(".ui-selected:last").attr("value");
+		if(direction == "down") {
+			if((id_contact == (((((parseInt($( "#slider" ).slider( "value" )) - 1)*6))+6)-1)) || id_contact == data_.length - 1 || data_.length == 1)
+				return;	
+			var line_contact = $('li.ui-selected');
+			$('li.ui-selected').next().addClass("ui-selected"); 
+			id_contact++;
                                         }
+		else {
+			if(id_contact == (($( "#slider" ).slider( "value" ) -1)*6)) 
+				return;
+			var line_contact = $('li.ui-selected');
+			$('li.ui-selected').prev().addClass("ui-selected"); 
+			id_contact--;
                                     } 
-                                    else
-                                    {
+		line_contact.removeClass("ui-selected").addClass("ui-selectee");
+		var details = $("#detalhes_contato").empty();                                 
+		switch(data_['type_catalog']) {
+			case 'G':
                                         var extra_fields = (data_['extra_ldap_fields']).split("#");   
-                                        /* Default fields */
-                                        details.append("<strong>" + utf8_decoder(data_[this.value].cn));
-                                        details.append("<br />" + data_[this.value].mail);
-                                        if(data_[this.value].telephonenumber != "")
-                                        {
-                                            details.append("<br /><br /><br /><strong> Telefone <br />");
-                                            details.append(data_[this.value].telephonenumber + "<br />");  
+				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>');           
                                         }
-                                        if(data_[this.value].mail[0].length > 1) 
-                                        {
-                                            for (var i=0; i<extra_fields.length-1; i++)
+				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] != undefined)
-                                                {    
-                                                    details.append("<br /><br /><strong>" + campo);
-                                                    details.append("<br />" + data_[this.value][valor][0]);
+					if(data_[id_contact][valor.toLowerCase()] != undefined) {
+						var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
+						for(j=0; j<data_[id_contact][valor.toLowerCase()].length; j++) {
+							details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>");
+							tmp_campo = "";
+                                            }
+                                        }
+                                    }
+					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(data_[id_contact].telephonenumber != null)
+                    details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data_[id_contact].telephonenumber + '</span></p>');
+						break;	
+			default:
+                                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(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].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_[id_contact][valor.toLowerCase()] != undefined) {
+							var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
+							for(j=0; j<data_[id_contact][valor.toLowerCase()].length; j++) {
+								details.append(tmp_campo + '<span class="value">' + data_[id_contact][valor.toLowerCase()][j] + "</span></p>");
+								tmp_campo = "";
                                                 }
                                             }
                                         }
                                     }
-                            }
-						});
-					break;
-				
-				case arrow.down:
-					id_contact = document.getElementsByClassName("ui-selected")[0].value;
-					if((id_contact == (((((parseInt($( "#slider" ).slider( "value" )) - 1)*7))+7)-1)) || id_contact == data_.length - 2 || data_.length == 1)
-						break;	
-					var line_contact = $('li.ui-selected');
-					$('li.ui-selected').next().removeClass("ui-selectee").addClass("ui-selected"); 
-					line_contact.removeClass("ui-selected").addClass("ui-selectee");
-					var details = $("#detalhes_contato").empty();                                 
-                        $( ".ui-selected", this ).each(function() {
-                            if(data_['type_catalog'] == 'G')
-                            {                                         
-                                var extra_fields = (data_['extra_ldap_fields']).split("#");   
-                                /* Default fields */
-                                details.append("<strong>" + utf8_decoder(data_[this.value].cn[0]));
-                                details.append("<br />" + data_[this.value].mail[0]);
-                                details.append("<br /><br /><strong>Matrícula<br />");
-                                details.append(data_[this.value].employeenumber[0] + "<br />");
-                                details.append("<br /><strong> Telefone <br />");
-                                details.append(data_[this.value].telephonenumber[0] + "<br />");
-                                details.append(data_[this.value].telephonenumber[0]);
-                                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] != undefined)
-                                    {    
-                                        details.append("<br /><br /><strong>" + campo);
-                                        details.append("<br />" + data_[this.value][valor][0]);
-                                    }
-                                }
-							}
-                            else
-                            {
-                                    if(data_['type_catalog'] == 'P')
-                                    {
-                                        /* Default fields */
-                                        details.append("<strong>" + utf8_decoder(data_[this.value].cn));
-                                        details.append("<br />" + data_[this.value].mail);
-                                        if(data_[this.value].telephonenumber != "")
-                                        {
-                                            details.append("<br /><br /><br /><strong> Telefone <br />");
-                                            details.append(data_[this.value].telephonenumber + "<br />");  
-                                        }
-                                    } 
-                                    else
-                                    {
-                                        var extra_fields = (data_['extra_ldap_fields']).split("#");   
-                                        /* Default fields */
-                                        details.append("<strong>" + utf8_decoder(data_[this.value].cn));
-                                        details.append("<br />" + data_[this.value].mail);
-                                        if(data_[this.value].telephonenumber != "")
-                                        {
-                                            details.append("<br /><br /><br /><strong> Telefone <br />");
-                                            details.append(data_[this.value].telephonenumber + "<br />");  
-                                        }
-                                        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] != undefined)
-                                                {    
-                                                    details.append("<br /><br /><strong>" + campo);
-                                                    details.append("<br />" + data_[this.value][valor][0]);
-                                                }
-                                            }
-                                        }
-                                    }
-                            }
-						});
 					break;
 			}
-		});	
 	}
 			
@@ -229,46 +152,112 @@
 		* Método que cria a lista de contatos
 		*/
-		function create_list(data)
-		{
+	function create_list(data, begin, uiValue) {
+		var sliderValue = 1;
+		if(typeof($( "#slider" ).slider( "value" )) != "object")
+			sliderValue = $( "#slider" ).slider( "value" );
+		if(uiValue)
+			sliderValue = uiValue;
 					$("#detalhes_contato").empty();
-					var paginas = Math.ceil(data.length/7) - 1; 
+		var paginas = Math.ceil(data.length/6); 
 					$("#title_usuarios").html( get_lang("Results") );
-					var string_results = $( "#slider" ).slider( "value" ) + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; 
                         var selectable = $("#selectable");
 						selectable.empty();
                         var Ul = document.createElement("ul");
+		for (i=((sliderValue -1)*6)+1; i<(((sliderValue -1)*6)+1)+6; i++) {
                         var Op = document.createElement("li");
-						for (i=(($( "#slider" ).slider( "value" ) -1)*7)+1; i<((($( "#slider" ).slider( "value" ) -1)*7)+1)+7; i++) 
-                        {
-							if(i >= data.length)
+			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"; 
-                            if(i == ((($( "#slider" ).slider( "value" ) -1)*7)+1)){
+				
+			if(i == (((sliderValue -1)*6)+1)) {
 								Op.setAttribute("class", "ui-selected");
+				Op.setAttribute("className", "ui-selected");
 							}
 							else {	
 								Op.setAttribute("class", "ui-selectee");
+				Op.setAttribute("className", "ui-selectee");
 							}
 							var contact_name = utf8_decoder(data[i-1].cn);
-							if(contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) != -1)									
+			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 style="float:right; left:335px; position: absolute; z-index: 100; background-color: #EEE; padding:0"><button onClick="add_contact_field(contact_' + i + '.innerHTML)">+</button><button onClick="remove_contact_field(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.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);
-                            Ul.appendChild(Op);
-                            selectable.append(Ul.innerHTML);
+            selectable.append(Op);
                         }
-                        $( "#amount" ).val( string_results );
-						$( "#amount" ).val( $( "#slider" ).slider( "value" ) + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")");   
-						document.getElementById("amount").focus();	
+		selectable.append(Ul);
+		var first_contact;
+		begin ? first_contact = 0 : first_contact = ((sliderValue* 6) -6);			
+		if(first_contact == 0) {
+			$(document).ready(function(){
+				$('#combobox option').each(function(){
+					if($(this).val() == preferences.catalog_search){
+						$(this).attr('selected',true);
+					}
+				});
+			});
+		}
+		var details = $("#detalhes_contato").empty();                                 
+		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[first_contact].cn[0]) + "</label>" + '<span class="value">' + data[first_contact].mail[0] + "</span></p>");
+					details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_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("|")));                                          
+					if(data[0][valor.toLowerCase()] != undefined)
+					{
+						var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
+						for(j=0; j<data[first_contact][valor.toLowerCase()].length; j++) {
+							details.append(tmp_campo + '<span class="value">' + data[first_contact][valor.toLowerCase()][j] + "</span></p>");
+							tmp_campo = "";
+						}
+					}
+				}			
+				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(data[first_contact].telephonenumber != null)
+					details.append('<p><label class="attribute">Telefone</label>' + '<span class="value">' + data[first_contact].telephonenumber  + '</span></p>');
+				break;
+			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(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) {
+						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[first_contact][valor.toLowerCase()] != undefined) {
+								var tmp_campo = '<p><label class="attribute">' + campo + "</label>" ;
+								for(j=0; j<data[first_contact][valor.toLowerCase()].length; j++) {
+									details.append(tmp_campo + '<span class="value">' + data[first_contact][valor.toLowerCase()][j] + "</span></p>");
+									tmp_campo = "";
+								}	
+							}	
+						}
+					}
+				}
+				break;
+		}
+		var string_results = sliderValue + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")"; 		
+		$( "#amount-text" ).val( string_results );
+		$("button").button();
+		if(!is_ie)
+			document.getElementById("amount-text").focus();	
+		$("#selectable li:first button:first").focus();
+		removeFocus();
 		}	
 		
 		
-		
-		
-		
-		
-		function details_results(data) 
-        {
+	/* Método que configura os detalhes do resultado da busca */
+	function details_results(data) {
 				$(function() {
                     $( "#selectable" ).selectable({
@@ -276,64 +265,49 @@
 								var details = $("#detalhes_contato").empty();                                 
                                 $( ".ui-selected", this ).each(function() {
-                                    if(data['type_catalog'] == 'G')
-                                    {                                         
+                        switch(data['type_catalog']) {
+							case 'G':
                                         var extra_fields = (data['extra_ldap_fields']).split("#");   
-                                        /* Default fields */
-                                        details.append("<strong>" + utf8_decoder(data[this.value].cn[0]));
-                                        details.append("<br />" + data[this.value].mail[0]);
-                                        details.append("<br /><br /><strong>Matrícula<br />");
-                                        details.append(data[this.value].employeenumber[0] + "<br />");
-                                        details.append("<br /><strong> Telefone <br />");
-                                        details.append(data[this.value].telephonenumber[0] + "<br />");
-                                        details.append(data[this.value].telephonenumber[0]);
-                                        for (var i=0; i<extra_fields.length-1; i++)
-                                        {
+								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] != undefined)
-                                            {    
-                                                details.append("<br /><br /><strong>" + campo);
-                                                details.append("<br />" + data[this.value][valor][0]);
+									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 = "";
                                             }
                                         }
                                     }
-                                    else
-                                    {
-                                        if(data['type_catalog'] == 'P')
-                                        {
-                                            /* Default fields */
-                                            details.append("<strong>" + utf8_decoder(data[this.value].cn));
-                                            details.append("<br />" + data[this.value].mail);
-                                            if(data[this.value].telephonenumber != "")
-                                            {
-                                                details.append("<br /><br /><br /><strong> Telefone <br />");
-                                                details.append(data[this.value].telephonenumber + "<br />");  
-                                            }
-                                        } 
-                                        else
-                                        {
+								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("#");   
-                                                /* Default fields */
-                                                details.append("<strong>" + utf8_decoder(data[this.value].cn));
-                                                details.append("<br />" + data[this.value].mail);
-                                                if(data[this.value].telephonenumber != "")
-                                                {
-                                                    details.append("<br /><br /><br /><strong> Telefone <br />");
-                                                    details.append(data[this.value].telephonenumber + "<br />");  
+                                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) 
-                                                {
-                                                    for (var i=0; i<extra_fields.length-1; i++)
-                                                    {
+								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] != undefined)
-                                                        {    
-                                                            details.append("<br /><br /><strong>" + campo);
-                                                            details.append("<br />" + data[this.value][valor][0]);
+										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;
                                     }
 								});
@@ -345,44 +319,8 @@
         
         /* 
-         * Método que inicializa a tela de contatos 
-         */
-        function init_results(data)
-        {			
-			var Op = null;
-			var Ul = null;
-			var selectable = $("#selectable");
-            selectable.empty();
-            Ul = document.createElement("ul");
-            Op = document.createElement("li");
-			var limit = data.length < 7 ? data.length : 7;
-			for (i=1; i<=limit; i++) 
-            {
-				Op.setAttribute("class", "ui-selectee");
-				if(i == 1)
-					Op.setAttribute("class", "ui-selected");
-				var contact_name = utf8_decoder(data[i-1].cn);
-				if(data['type_catalog'] != 'G' && (data[i-1].mail == null || data[i-1].mail == ""))
-				{
-					data[i-1].mail = "No mail"; 
-				}
-				
-				if(contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) != -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 style="float:right; left:335px; position: absolute; z-index: 100; background-color: #EEE; padding:0"><button onClick="add_contact_field(contact_' + i + '.innerHTML)">+</button><button onClick="remove_contact_field(contact_' + i + '.innerHTML)">x</button></span><div class="id_contact_field" 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);
-                Ul.appendChild(Op);
-                selectable.append(Ul.innerHTML);
-            }
-			$("#adds").html("Foram adicionados " + quantidade_contatos + " contatos.");
-        }
-        
-        
-        /* 
          * Método que configura o slider e os resultados 
          */
-        function configure_slider(data) 
-        {	
-			$("#detalhes_contato").empty();
-            var paginas = Math.ceil(data.length/7); 
+    function configure_slider(data) {	
+        var paginas = (Math.ceil(data.length/6)); 
             $("#title_usuarios").html( get_lang("Results") );
             $(function() {
@@ -392,80 +330,53 @@
 					max: paginas,
 					step: 1,
-                        slide: function( event, ui ) 
-                        {
+				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 selectable = $("#selectable");
-                                selectable.empty();
-                                var Ul = document.createElement("ul");
-                                var Op = document.createElement("li");
-								for (i=((ui.value-1)*7)+1; i<(((ui.value-1)*7)+1)+7; i++) 
-                                {
-                                    if(data['type_catalog'] != 'G' && (data[i-1].mail == null || data[i-1].mail == ""))
-									{
-										data[i-1].mail = "No mail"; 
-									}	
-									var contact_name = utf8_decoder(data[i].cn);
-									if(contact_name.substring(contact_name.toLowerCase().indexOf(data.search_for.toLowerCase())) != -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.setAttribute("class", "ui-selectee");
-									Op.innerHTML = '<span style="float:right; left:335px; position: absolute; z-index: 100; background-color: #EEE; padding:0"><button onClick="add_contact_field(contact_' + i + '.innerHTML)">+</button><button onClick="remove_contact_field(contact_' + i + '.innerHTML)">x</button></span><div class="id_contact_field" id=contact_' + i + ' onDblClick="add_contact_field(this.innerHTML)"><div class="name_contact"><strong>' + contact_name + '</strong><em>' + utf8_decoder(data[i].mail) + '</em></div></div>';
-                                    $(Op).val(i);
-                                    Ul.appendChild(Op);
-                                    selectable.append(Ul.innerHTML);
-                                }
-                                $( "#amount" ).val( string_results );
-								$(this).unbind('keypress');
-								document.getElementById("amount").focus();
+					$( "#amount-text" ).val( string_results );
 						}
                     });
-                    $( "#amount" ).val( $( "#slider" ).slider( "value" ) + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")");         
+			$("#selectable li:first button:first").focus();
                 });
         }
         
+	var search_focus = false;
 
-		
-        function checkEnter(e) 
-		{
+	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;
-            if (kC) { 
-				//$("#dialog-modal").unbind('keypress');
+        if (kC) 
 				return kC == 13;
-			}
-            else{ 
+        else
 				return false;
 			}
-		}
+        
         
         /* 
          * Faz a busca direto da tela modal  
          */
-        function buscaContato(param)
-        {
-			$("#busca").empty();
-			if(param.length == 0)
-            {
-                alert(get_lang("Please enter a parameter to search."));
-                return false;
+    function buscaContato(param) {
+		$("#busca, #detalhes_contato, #selectable").empty();
+		if(param.length == 0) {
+            alert(get_lang("Please enter a parameter to search"));
+            return;
             }
-            if(param.length < preferences.search_characters_number)
-            {
+		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) 
-            {
+        var handler_emQuickSearch = function(data) {
                 data_ = data;
-				if(data_.length > 0)
-                {        
-                    init_results(data_);
+			if(data_.length > 0) {        
                     configure_slider(data_);    
+                create_list(data_, true);
                     details_results(data_);
                 }
-                else
-                {
+            else {
                     $("#detalhes_contato, #selectable").empty();
                     configure_slider(data); 
@@ -476,17 +387,14 @@
 		
         
-		quantidade_contatos = 0;
         /* 
          * Método que adiciona o contato selecionado no campo do email (To, CC, CCo) 
          */
-        function add_contact_field(contact)
-        {
-			quantidade_contatos++;
-            $("#adds").html("Foram adicionados " + quantidade_contatos + " contatos.");
+    function add_contact_field(contact) {
 			var emailList      = document.getElementById(field_ + "_" + id_).value; 
-            var contact_parsed = contact.replace(/<\/?[^>]+>/gi, ' ');
+		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);
@@ -494,21 +402,31 @@
 			var final_contact;
 			if(tokens_contact[2] == undefined)
-				final_contact = "\"" + tokens_contact[0] + " " + "\" <" + tokens_contact[1] + ">, ";
+			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] + ">, ";
+				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] + ">, ";
+				final_contact =  "\"" + tokens_contact[0] + "" +  tokens_contact[1] + "" +  tokens_contact[2] + "\" <" + tokens_contact[3] + ">, ";
             }
-            if (emailList[0] != '"')
+        if (emailList[0] != '"' && emailList.indexOf(",") < 0)
                 emailList = emailList.substr(end_);
+            if(emailList.lastIndexOf(",") > 0)
+			emailList = emailList.substr(0, emailList.lastIndexOf(",") + 1);
             
-            if(emailList.lastIndexOf(",") > 0)
-                emailList = emailList.substr(0, emailList.lastIndexOf(",") + 2);
-            
+		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");
@@ -518,10 +436,9 @@
          * Método que remove o contato selecionado no campo do email (To, CC, CCo) 
          */
-		function remove_contact_field(contact)
-		{
+	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("|");
 			
+		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);
@@ -532,53 +449,32 @@
 				final_contact =  "\"" + tokens_contact[0] + " " +  tokens_contact[1] + " " +  tokens_contact[2] + "\" <" + tokens_contact[3] + ">";
 			
-			if(quantidade_contatos ==0)
-			{
-				alert("Nenhum contato adicionado!");
-				return false;
-			}
-			
-			var encontrou = false;
-			var emailList = document.getElementById(field_ + "_" + id_).value; 
+		var exist = false;
+		var emailList = $("#" + field_ + "_" + id_).val();
 			var emails_adicionados = emailList.split(",");
-			var quantidade_excluidos = 0;
-			for(i=0; i<emails_adicionados.length -1; i++)
-			{
-				if(emails_adicionados[i].trim() == final_contact)
-				{
+		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] = "%";
-					quantidade_excluidos++;
-					encontrou = true;
+				exist = true;
 				}
 			}
-			if (encontrou == false) 
-			{
-				alert("Não pode excluir um contato que ainda não adicionou.");
+		if (exist == false) 
 				return false;
-			}
-			
-			quantidade_contatos -= quantidade_excluidos;
-            $("#adds").html("Foram adicionados " + quantidade_contatos + " contatos.");
-			
 			var novos_contatos = emails_adicionados.join(",");  
             novos_contatos = novos_contatos.replace(/%,/g, "");
-			document.getElementById(field_ + "_" + id_).value = novos_contatos;
+		$("#" + field_ + "_" + id_).val(novos_contatos);
 		}
         
 	      
-        function utf8_decoder ( str_data ) 
-        {
+	/* Decoder utf8 */	
+    function utf8_decoder ( str_data ) {
             var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
-            
             str_data += '';
-            
-            while ( i < str_data.length ) 
-            {
+        while ( i < str_data.length ) {
                 c1 = str_data.charCodeAt(i);
-                if (c1 < 128) 
-                {
+            if (c1 < 128) {
                     tmp_arr[ac++] = String.fromCharCode(c1);
                     i++;
-                } else if ((c1 > 191) && (c1 < 224)) 
-                       {
+            } else if ((c1 > 191) && (c1 < 224)) {
                             c2 = str_data.charCodeAt(i+1);
                             tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
@@ -596,14 +492,12 @@
         
               
-    function show_help()
-	{
+	/* Mostra tela de help */	
+    function show_help() {
 		$(function() {
 			$( "#dialog-modal_help" ).dialog({
 						resizable: false,
-						height: 230,
 						width: 540,
 						modal: true,
-						closeOnEscape: true,
-
+						closeOnEscape: true
 			});
 		});
@@ -611,483 +505,66 @@
 		  
               
-	emQuickCatalogSearch.prototype.showWindow = function (div)
-	{
-				$(this).bind('keypress');
+	emQuickCatalogSearch.prototype.showWindow = function (div) {
+		$(this).bind('keydown');
 				$(function() {
                     $( "#dialog:ui-dialog" ).dialog( "destroy" );                    
                     $( "#dialog-modal" ).dialog({
 						resizable: false,
-						height: 530,
-						width: 940,
+//			height: "auto",
+			width: 780,
 						modal: true,
+			position: 'bottom',
 						closeOnEscape: true,
 						close: function (event, ui) {
 							event.stopPropagation();
-							$(this).unbind('keypress');
+				$(this).unbind('keydown');
+				if (is_ie) { 
+					var range= document.getElementById(field_ + "_" + id_).createTextRange(); 
+					range.collapse(false); 
+					range.select(); 
+				} else { 
+					document.getElementById(field_ + "_" + id_).focus();    
+				} 
+			},
+			open: function () {
+				$("#selectable li:first button:first").focus();    
 						},
 						focus: function (event, ui) {
-							$(this).bind('keypress');
+				//$(this).unbind('keydown');
 						},
 						beforeClose: function (event, ui) {
-							$(this).bind('keypress');
+				$(this).unbind('keydown');
 						},
-						buttons:{
-							'Fechar' : function(){
+			buttons:[
+						{
+							text: "Fechar",
+							click: function(){
 								$("#detalhes_contato, #selectable, #busca").empty();
 								$(this).dialog("close");
+												if (is_ie) { 
+													var range= document.getElementById(field_ + "_" + id_).createTextRange(); 
+													range.collapse(false); 
+													range.select(); 
+												} 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>')
+		.find('.ui-dialog-titlebar-minimize').click(function() {
+			$(".ui-dialog-buttonpane, .ui-dialog-content").toggle();
+			$(".ui-icon-minusthick, .ui-icon-newwin").toggleClass('ui-icon-minusthick').toggleClass('ui-icon-newwin');
+		});
 	
-                
-                
-        if(! div) {
-			alert(get_lang('The list has no participant.'));
-			return;
-		}
-							
-		if(! this.arrayWin[div.id]) {
-			div.style.width = "700px";
-			div.style.height = "230px";
-			var title = get_lang('The results were found in the Global Catalog')+':';
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-			div.style.width = div.offsetWidth - 5;
-
-			win = new dJSWin({			
-				id: 'QuickCatalogSearch_'+div.id,
-				content_id: div.id,
-				width: wWidth,
-				height: wHeight,
-				title_color: '#3978d6',
-				bg_color: '#eee',
-				title: title,						
-				title_text_color: 'white',
-				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true,
-                                onclose: 'QuickCatalogSearch.restoreShortcuts("'+ div.id +'")'});
-
-			this.arrayWin[div.id] = win;
-			win.draw();
-		}
-		else {
-			win = this.arrayWin[div.id];
-		}
-		//document.getElementById("window_QuickCatalogSearch").style.visibility = "visible";
-		//win.open();
-		//document.getElementById('select_QuickCatalogSearch').focus();
-
-                if(is_ie && (preferences.use_shortcuts == '1')){
-                    shortcut.remove('down');
-                    shortcut.remove('up');
-                    shortcut.remove('return');
-                }
-	}
-	
-	emQuickCatalogSearch.prototype.transfer_result = function (field, ID, begin, end){
-		cm = document.getElementById('select_QuickCatalogSearch');
-		option_selected = cm.options[cm.selectedIndex].value + ", ";
-		emailList = document.getElementById(field + "_" + ID).value;
-		
-		new_emailList = emailList.substring(0, begin) + option_selected + emailList.substring((parseInt(end) + 2), emailList.length);
-		document.getElementById(field + "_" + ID).value = new_emailList;
-		document.getElementById(field + "_" + ID).focus();
-		this.arrayWin['window_QuickCatalogSearch_A'].close();
-                document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";
-	}
-
-	emQuickCatalogSearch.prototype.close_QuickSearch_window = function (field, ID){
-		//document.getElementById('QuickCatalogSearch_window_QuickCatalogSearch').style.display = "none";
-		document.getElementById(field + "_" + ID).focus();
-		this.arrayWin['window_QuickCatalogSearch_A'].close();
-                document.getElementById("window_QuickCatalogSearch").style.visibility = "hidden";
-                if(typeof shortcut.all_shortcuts['down'] == 'undefined'){
-                    if(is_ie  && (preferences.use_shortcuts == '1'))
-                    {
-                        shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false});
-                        shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false});
-                        shortcut.add("return",function(){
-                            if ( Element('border_id_0').className==='menu-sel' )
-                            {
-                                    all_messages = Element('tbody_box').childNodes;
-                                    for (var i=0; i < all_messages.length; i++)
-                                    {
-                                            if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-                                            {
-                                                    Element("td_who_" + all_messages[i].id).onclick();
-                                                    return;
-                                            }
-                                    }
-                            }
-                        },{'disable_in_input':true});
-                    }
-                }
-	}
-
-        emQuickCatalogSearch.prototype.restoreShortcuts = function(id) {
-
-            var search_win = document.getElementById(id);
-            if(typeof shortcut.all_shortcuts['down'] == 'undefined'){
-                if (search_win.style.visibility == 'visible')
-                {
-                    shortcut.add("down",function(){select_msg('null', 'down');},{'disable_in_input':false});
-                    shortcut.add("up",function(){select_msg('null', 'up');},{'disable_in_input':false});
-                    shortcut.add("return",function(){
-                        if ( Element('border_id_0').className==='menu-sel' )
-                        {
-                                all_messages = Element('tbody_box').childNodes;
-                                for (var i=0; i < all_messages.length; i++)
-                                {
-                                        if ( exist_className(all_messages[i], 'selected_shortcut_msg') )
-                                        {
-                                                Element("td_who_" + all_messages[i].id).onclick();
-                                                return;
-                                        }
-                                }
-                        }
-                    },{'disable_in_input':true});
-                }
-            }
-            search_win.style.visibility = 'hidden';
-
-        }
-
-	emQuickCatalogSearch.prototype.close_window = function(id) {
-                this.arrayWin[id].close();
-		var group_values = Element('list_values');
-		var user_values = Element('user_values');
-	}
-	emQuickCatalogSearch.prototype.showCatalogList = function (border_id){
-		var el = Element('catalog_list');
-
-		if(el) {
-			Element('border_id').value = border_id;
-			win = this.arrayWin[el.id];
-			win.open();
-			return;		
-		}
-		var border_input   = document.createElement("INPUT");
-		border_input.type  = 'hidden';
-		border_input.id    = 'border_id';
-		border_input.value = border_id;
-		document.body.appendChild(border_input);
-		el = document.createElement("DIV");		
-		el.id = 'catalog_list';
-		document.body.appendChild(el);			
-		el.style.visibility = "hidden";
-		el.style.position = "absolute";
-		el.style.width = "700px";
-		el.style.height = is_ie ? "360px" : "375px";		
-		el.style.left = "0px";
-		el.style.top = "0px";			
-		el.innerHTML = "<table border='0' cellpading='0' cellspacing='0' width='100%'>"+
-					   "<tr><td id='td1' style='cursor:pointer' align='center' onclick='QuickCatalogSearch.select_div(\"tab1\")'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab1\");'>"+get_lang('Global Catalog')+"</a></td>"+
-					   "<td id='td2' style='background:#cecece;cursor:pointer' onclick='QuickCatalogSearch.select_div(\"tab2\")' align='center'><a href='#' class='catalog' onclick='QuickCatalogSearch.select_div(\"tab2\");'>"+get_lang('Personal Catalog')+"</a></td></tr>"+
-					   '</table>'+
-					   '<div id="tab1" align="center"><br>'+
-					   '<table border="0" cellpading="0" cellspacing="0">'+
-					   '<tr><td>'+get_lang("Select an organization and click on button <b>Search</b>")+'&nbsp;:</td></tr>'+
-  					'<tr><td><select style="display:none;width:150px" id="select_catalog" name="select_catalog" onchange="javascript:QuickCatalogSearch.update_organizations();"></select>&nbsp'+
-					'<select id="select_organization" style="width:150px" name="select_organization"></select>&nbsp;'+   
-					'<input type="text" id="search_for" name="search_for" value="" size="30" maxlength="30"/>&nbsp;<input type="button" onclick="QuickCatalogSearch.searchCatalogList(true)" class="button" value="'+get_lang('Search')+'">&nbsp;<input style="display:visible" type="button" onclick="QuickCatalogSearch.searchCatalogList(false)" class="button" value="'+get_lang('List All')+'"></td></tr>'+
-					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" id="type_l" type="radio" name="type" value="l"/>'+get_lang('Public Lists')+'&nbsp;&nbsp;<input type="radio" id="type_u" name="type" value="u" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" checked/>'+get_lang('Users')+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
-					   '<span style="visibility:hidden;background:#cc4444" id=msg_search>&nbsp;&nbsp;<font face="Verdana" size="1" color="WHITE">'+get_lang('Search in Catalog')+'...</font>&nbsp;</span></td></tr>'+
-					   '<tr><td>'+
-				  	   '<span id="list_span"><select multiple style="display:none;width:580px" size="14" id="list_values"></select></span>'+
-				  	   '<span id="user_span"><select multiple style="width:580px" size="14" id="user_values"></select></span>'+
-				 	   '</td></tr>'+
-					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to\')">&nbsp;'+
-				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc\')">&nbsp;'+( allow_hidden_copy ?  
- 	                   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco\')">' : '' )+
-				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
-					   '</table>'+
-					   '</div>'+
-					   '<div style="display:none" id="tab2" align="center">'+
-					   '<br><br><br>'+
-					   '<table border="0" cellpading="0" cellspacing="0">'+
-					   '<tr><td>'+get_lang("Select the type of contact that you want to view")+'&nbsp;:</td></tr>'+
-					   '<tr><td><input onclick="javascript:QuickCatalogSearch.changeOptions(this.value)" type="radio" name="type" value="p"/>' + get_lang('People') + '&nbsp;&nbsp;<input type="radio" name="type" value="g" onclick="javascript:QuickCatalogSearch.changeOptions(this.value)"/>' + get_lang('Groups') + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
-					   '<tr><td>'+
-				  	   '<span id="personal_span"><select multiple style="width:580px" size="14" id="list_personal"></select></span>'+
-				  	   '<span id="groups_span"><select multiple style="display:none;width:580px" size="14" id="list_groups"></select></span>'+
-				 	   '</td></tr>'+
-					   '<tr><td nowrap><center>'+get_lang('Click here to add into the fields')+':&nbsp;<input type="button" class="button" value="'+get_lang('TO')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'to1\')">&nbsp;'+
-				  	   '<input type="button" class="button" value="'+get_lang('CC')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cc1\')">&nbsp;'+ ( allow_hidden_copy ? 
- 	                   '<input type="button" class="button" value="'+get_lang('CCo')+'" onClick="javascript:QuickCatalogSearch.addContacts(\'cco1\')">' : '' )+
-				  	   '</center></td></tr><tr><td nowrap><center><input type="button" value="'+get_lang('Close')+'" onClick="javascript:QuickCatalogSearch.close_window(\'catalog_list\')"></center></td></tr>'+
-					   '</table>'+
-					   '</div>';
-
-		var title = get_lang('Search in the Global Catalog');
-		var wHeight = el.offsetHeight - (is_ie ? 10 : 0) + "px";
-		var wWidth =  el.offsetWidth   + "px";
-		el.style.width = el.offsetWidth;
-		
-		Element('search_for').onkeypress = function (e) {
-			if ((is_ie && (window.event.keyCode == 13)) || (!is_ie && e.keyCode == 13)) {
-				QuickCatalogSearch.searchCatalogList(true);
-			}
-		};
-
-		win = new dJSWin({			
-			id: 'win_'+el.id,
-			content_id: el.id,
-			width: wWidth,
-			height: wHeight,
-			title_color: '#3978d6',
-			bg_color: '#eee',
-			title: title,						
-			title_text_color: 'white',
-			button_x_img: '../phpgwapi/images/winclose.gif',
-			border: true});
-			
-		this.arrayWin[el.id] = win;		
-		win.draw();
-		win.open();
-
-		var handler_catalogs = function(data){
-			var user_catalog = get_lang("Global Catalog");
-			if(data.length > 1) {
-				Element('select_catalog').style.display = '';
-				for(i = 0; i < data.length; i++) {		
-					Element('select_catalog').options[i] = new Option(data[i],i);
-					if(user_catalog.toUpperCase() == data[i].toUpperCase())
-						Element('select_catalog').options[i].selected = true;
-				}
-			}
-		}
-		cExecute ("$this.ldap_functions.get_catalogs", handler_catalogs);		
-		
-		this.update_organizations();
-		var handler_cc_contacts= function(data){
-			if(data && data.length > 0){
-				var aux = data.split(",");
-				for(var i=0; i< aux.length; i++){
-					QuickCatalogSearch.cc_contacts[QuickCatalogSearch.cc_contacts.length] = aux[i];				
-				}
-			}
-		}
-		cExecute("$this.db_functions.get_cc_contacts",handler_cc_contacts);
-
-		var handler_cc_groups = function(data){
-			if(data && data.length > 0){
-				var aux = data.split(",");
-				for(var i=0; i < data.length; i++){
-					QuickCatalogSearch.cc_groups[QuickCatalogSearch.cc_groups.length] = aux[i];								
-				}	
-			}
-		}
-		cExecute("$this.db_functions.get_cc_groups",handler_cc_groups);
-	
-	}
-	
-	emQuickCatalogSearch.prototype.select_div = function(element){
-		if(element == 'tab1'){
-		   Element('tab1').style.display = '';
-		   Element('tab2').style.display = 'none';
-		   Element('td1').style.background = '#eee';	
-		   Element('td2').style.background = '#cecece';
-		}
-		if(element == 'tab2'){
-		   Element('tab1').style.display = 'none';
-		   Element('tab2').style.display = '';
-		   Element('td1').style.background = '#cecece';
-		   Element('td2').style.background = '#eee';		   
-
-		}
-	}
-	
-	emQuickCatalogSearch.prototype.load_catalog = function(){
-	
-		var _this = this;
-		var content = new Array;
-		var select = Element('list_personal').style.display == 'none'? Element('list_groups'): Element('list_personal');
-		
-		if(Element('list_personal').style.display == 'none'){
-			content = _this.cc_groups;
-		}else{
-			content = _this.cc_contacts;
-		}
-		if(select.options.length > 0){
-			for(var i=0; i < select.options.length; i++){
-				select.options[i] = null;
-				i--;
-			}
-		}
-		for(var i=0; i < content.length; i++){
-			if(content[i] != undefined){
-				var aux = content[i].split(";");
-				var opt = new Option(aux[0] + ' (' + aux[1] + ')','"' + aux[0] + '" ' + '<' + aux[1] + '>',false,false);
-				select[select.length] = opt;
-			}
-		}
-		content.splice(0,(content.lenght));
-	}
-
-	emQuickCatalogSearch.prototype.update_organizations = function(){
-		while(Element('select_organization').options.length > 0) {
-			Element('select_organization').remove(0);
-		}
-	 	var handler_org = function(data){
-			Element('select_organization').options[0] = new Option(get_lang('all'),'all');
-			if (data != null){
-				var user_organization = Element('user_organization').value;
-				for(x = 0; x < data.length; x++) {
-					Element('select_organization').options[x+1] = new Option(data[x].toUpperCase(),data[x]);
-					if(user_organization.toUpperCase() == data[x].toUpperCase())
-						Element('select_organization').options[x+1].selected = true;
-				}
-			}
-		}		
-		cExecute ("$this.ldap_functions.get_organizations&referral=false&catalog="+Element('select_catalog').value, handler_org);		
-	}
-
-	emQuickCatalogSearch.prototype.changeOptions = function(type){	
-
-		switch(type){
-			case 'u':
-				Element('list_values').style.display = 'none';
-				Element('user_values').style.display = '';
-				break;
-			
-			case 'l':		
-				Element('user_values').style.display = 'none';
-				Element('list_values').style.display = '';		
-				break;
-
-			case 'p':
-				Element('list_personal').style.display = '';
-				Element('list_groups').style.display = 'none'
-				QuickCatalogSearch.load_catalog();				
-				break;
-			
-			case 'g':
-				Element('list_personal').style.display = 'none';
-				Element('list_groups').style.display = ''
-				QuickCatalogSearch.load_catalog();
-				break;
-		}
-
-	}
-
-	emQuickCatalogSearch.prototype.addContacts = function(field) {
-		
-		var border_id 	= Element('border_id').value;
- 		var select		= Element('user_values').style.display == 'none' ? Element('list_values') : Element('user_values');
-		if(field == "to1" || field == "cc1" || field == "cco1"){
-			field = field.substr(0,field.length - 1);
-			var select = Element('list_personal').style.display == 'none' ? Element('list_groups') : Element('list_personal');
-		}
-		var fieldOpener = Element(field+"_"+border_id);
-		var not_selected = true;
-		
-		for (i = 0 ; i < select.length ; i++) {
-			if (select.options[i].selected && select.options[i].value != '-1') {
-				if(fieldOpener.value.length > 0 && (fieldOpener.value.lastIndexOf(',') != (fieldOpener.value.length - 1))){
-					fieldOpener.value += ",";
-				}
-				fieldOpener.value += select.options[i].value + ",";
-				not_selected = false;
-				select.options[i].selected = false;
-			}
-		}
-		
-		if(not_selected)
-			return false;
-			
-		if(field != 'to'){
- 			a_link = Element("a_"+field+"_link_"+border_id);
- 			if(a_link)
- 				a_link.onclick();
- 		}
-	}
-	
-	emQuickCatalogSearch.prototype.searchCatalogList = function (itemSearch){
-
-		if(itemSearch && Element('search_for').value.length < preferences.search_characters_number){
-			alert(get_lang('Your search argument must be longer than %1 characters.', preferences.search_characters_number));
-			Element('search_for').focus();
-			return false;
-		}
-		var organization = Element('select_organization').value;		
-		var search		 = itemSearch ? Element('search_for').value : '';
-		var catalog		 = Element('select_catalog').value;
-
-		var handler_searchResults = function(data){
-			Element('msg_search').style.visibility = 'hidden';
-			if(data.error){
-				alert(get_lang('More than %1 results. Please, try to refine your search.',data.maxResult));
-				return false;
-			}else if(data.users.length == 0 && data.groups.length == 0){
-				alert(get_lang('None result was found.'));
-			}
-
-			
-			var group = Element('list_span');
-			var user  = Element('user_span');	
-			if(is_ie){
-				group.innerHTML = '';
-				user.innerHTML = '';
-			}
-			else {
-				group = Element('list_values');
-				user  = Element('user_values');	
-				for(var i = 0;i < group.options.length; i++)				
-					group.options[i--] = null;
-				for(var i = 0;i < user.options.length; i++)				
-					user.options[i--] = null;
-			}
-
-			var arr 	= new Array(data.maxResult);
-
-			for(i = 0; data.groups && i < data.groups.length; i++) {
-				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
-				if(is_ie)
-					arr[i] = '<option value="'+'&quot;'+data.groups[i].name+'&quot; &lt;'+data.groups[i].email+'&gt;">'+data.groups[i].name+' ('+data.groups[i].email+')'+'</option>';
-				else
-					group.options[i] = new Option(data.groups[i].name+' ('+data.groups[i].email+')','"'+data.groups[i].name+'" <'+data.groups[i].email+'>');
-			}
-	
-			
-			if(is_ie)
-				group.innerHTML = '<select multiple style="display:none;width:580px" size="14" id="list_values">'+ arr.join() +'</select>';
-
-			arr = new Array(data.maxResult);
-			
-			for(i = 0; data.users && i < data.users.length; i++) {
-			/*******************************************************************************************/
-			/* O resultado pratico do bloco de codigo a seguir eh a exibicao dos valores em tela,
-			ja que vai verificar se o departamento e o email estao vazios ou nulos e a partir dai o
-			resultado apresentado em tela sera exibido de maneira mais apresentavel;
-			*/
-				//verifica se departamento eh null ou nao;
-				var department = data.users[i].department ? " - " + data.users[i].department : "";
-				//verifica se email eh null ou nao;
-				var email = data.users[i].email ? data.users[i].email : "";
-
-				// Maneiras diferentes de se montar uma tag OPTION, pois no IE o objeto Option é muito lento.
-				if(is_ie)
-					arr[i] = '<option value="'+'&quot;'+data.users[i].name+'&quot; &lt;'+email+'&gt;">'+data.users[i].name+' ('+email+')'+department+'</option>';
-				else {
-					user.options[i] = new Option(data.users[i].name+' ('+email+')'+department,'"'+data.users[i].name+'" <'+email+'>'); // incluido data.users[i].department para exibir setor na opcao "Pesquisar" do email;
-				}
-			}
-	
-			if(is_ie)
-				user.innerHTML = '<select multiple style="width:580px" size="14" id="user_values">'+ arr.join() +'</select>';
-
-			// Display entries found.
-			var type = (data.groups.length > 0 && data.users.length == 0) ? 'l' : 'u';
-			Element("type_"+type).checked = true;
-			QuickCatalogSearch.changeOptions(type);
-		}
-
-		Element('msg_search').style.visibility = 'visible';
-		cExecute ("$this.ldap_functions.catalogsearch&organization="+organization+"&search_for="+search+"&catalog="+catalog, handler_searchResults);
+		$("#dialog-modal button, input.button").button();				
 	}
 
 	
-/* Build the Object */
+	/* Build the Object */
 	//QuickCatalogSearch;
 	QuickCatalogSearch = new emQuickCatalogSearch();
