Index: trunk/expressoMail1_2/preferences.php
===================================================================
--- trunk/expressoMail1_2/preferences.php	(revision 4231)
+++ trunk/expressoMail1_2/preferences.php	(revision 5075)
@@ -257,4 +257,10 @@
 		}
 
+		if ($GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'])  
+ 	                       $GLOBALS['phpgw']->preferences->change('expressoMail', 'catalog_search', $_POST['catalog_search']);  
+ 	                 else   
+ 	                       $GLOBALS['phpgw']->preferences->add('expressoMail', 'catalog_search', $_POST['catalog_search']); 
+		
+		
 		if ($GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_shortcuts'])
 			$GLOBALS['phpgw']->preferences->change('expressoMail','use_shortcuts',$_POST['use_shortcuts']);
@@ -383,4 +389,8 @@
 	$GLOBALS['phpgw']->template->set_var('lang_Would_you_like_to_use_local_messages_?',lang('Would you like to use local messages?'));
 
+	$GLOBALS['phpgw']->template->set_var('lang_global_catalog', lang('Global Catalog')); 
+ 	$GLOBALS['phpgw']->template->set_var('lang_personal_catalog', lang('Personal Catalog')); 
+ 	$GLOBALS['phpgw']->template->set_var('lang_all_catalog', lang('All Catalogs')); 
+	
 	$GLOBALS['phpgw']->template->set_var('url_offline','offline.php');
 	$GLOBALS['phpgw']->template->set_var('url_icon','templates/default/images/offline.png');
Index: trunk/expressoMail1_2/index.php
===================================================================
--- trunk/expressoMail1_2/index.php	(revision 4832)
+++ trunk/expressoMail1_2/index.php	(revision 5075)
@@ -144,4 +144,12 @@
 	$template->set_var("user_organization", $acc->get_organization($GLOBALS['phpgw_info']['user']['account_dn']));
 	$template->set_var("cyrus_delimiter",$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter']);	
+	$template->set_var("lang_contact_details", lang("Contact Details")); 
+ 	$template->set_var("lang_catalog", lang("catalog")); 
+ 	$template->set_var("lang_search", lang("search")); 
+ 	$template->set_var("lang_page", lang("page")); 
+ 	$template->set_var("lang_quick_search_users_dialog_title", lang("Quick Search Contacts")); 
+ 	$template->set_var("lang_global_catalog", lang("Global Catalog")); 
+ 	$template->set_var("lang_personal_catalog", lang("Personal Catalog")); 
+ 	$template->set_var("lang_all_catalogs", lang("All Catalogs")); 
 	// Fix problem with cyrus delimiter changes in preferences.
 	// Dots in names: enabled/disabled.
Index: trunk/expressoMail1_2/templates/default/index.tpl
===================================================================
--- trunk/expressoMail1_2/templates/default/index.tpl	(revision 4830)
+++ trunk/expressoMail1_2/templates/default/index.tpl	(revision 5075)
@@ -131,3 +131,42 @@
 	</table>
 </div>
+<link href="../library/jquery/css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css">
+		<script src='../library/jquery/jquery.js' language='javascript'></script> 
+ 		<script type="text/javascript" src="../library/jquery/jquery-ui.min.js"></script> 
+ 		<link href="templates/default/quick_search.css" rel="stylesheet" type="text/css"> 
+ 		<div style="display:none; width: auto; min-height: 0px; height: 410px;" id="dialog-modal" title="{lang_quick_search_users_dialog_title}"> 
+ 		    <div style="width:910px;height:410px;">                      
+ 		            <div class="acc-list" style="width:370px;height:85%;float:left;border:1px solid #DDD;background-color:#EEE;border-radius:3px;margin-left:1px;"> 
+ 		                    <h3 id="title_usuarios"></h3> 
+ 		                    <ul id="selectable" style="width:370px; height:350px;"></ul>   
+ 		                    <div class="demo" style="width:100%;margin-top:-5px;"> 
+ 		                        <div id="slider"></div> 
+ 		                            <p> 
+ 		                                <label for="amount">{lang_page}: </label> 
+ 		                                <input type="text" id="amount" style="border:0; font-weight:bold; width:85%" /> 
+ 		                            </p>             
+ 		                    </div> 
+ 		            </div> 
+ 		            <div style="width:525px;height:90%;float:left;">  
+ 		                <div id="accordion"> 
+ 		                        <div class="ui-widget" align="right"> 
+ 		                            <label>{lang_search}: </label> 
+ 		                                <input type="text" id="busca" size=30></input>                             
+ 		                            <select id="combobox"> 
+ 		                                <!-- Pegar essas opções das preferências --> 
+ 		                                <option value="global">{lang_global_catalog}</option> 
+ 		                                <option value="personal">{lang_personal_catalog}</option> 
+ 		                                <option value="all">{lang_all_catalogs}</option> 
+ 		                            </select> 
+ 		                            <input type="button" value="Buscar" onClick=buscaContato(busca.value); /> 
+ 		                            <input type="button" value="?" onClick="alert('Busca rápida de contatos versão 0.1\nPrognus Software Livre')" /> 
+ 		                        </div> 
+ 		                        <fieldset id="fieldset1" style="width:490px;height:85%;float:right;"> 
+ 		                            <legend>{lang_contact_details}</legend> 
+ 		                                <div style="float:left;"> <span id="detalhes_contato">---</span> </div> 
+ 		                        </fieldset>     
+ 		                 </div>   
+ 		             </div> 
+ 		        </div> 
+ 		</div> 
 <!-- END list -->
Index: trunk/expressoMail1_2/templates/default/quick_search.css
===================================================================
--- trunk/expressoMail1_2/templates/default/quick_search.css	(revision 5072)
+++ trunk/expressoMail1_2/templates/default/quick_search.css	(revision 5075)
@@ -47,5 +47,5 @@
                 #selectable { list-style-type: none; margin: 0; padding: 0; width: 100%; }
                 ul#selectable { overflow: hidden; width: 370px;}
-                ul#selectable li { width: 315px; overflow:hidden; }
+                ul#selectable li { width: 300px; overflow:hidden; }
                 ul#selectable li.ui-selected { width: 81%;  }
                 ul#selectable li div { width: 6000px; }
Index: trunk/expressoMail1_2/setup/phpgw_pt-br.lang
===================================================================
--- trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 4929)
+++ trunk/expressoMail1_2/setup/phpgw_pt-br.lang	(revision 5075)
@@ -675,2 +675,13 @@
 Attention! The original message will be sent along with the original source of the email message        expressoMail1_2 pt-br   Atenção! A mensagem original será enviado junto com a fonte original da mensagem de e-mail
 allow hidden copy       expressoMail1_2 pt-br   Liberar todos os usuários a enviar email com cópia oculta 
+Results expressoMail1_2 pt-br   Resultados 
+Please, enter a parameter to search expressoMail1_2 pt-br   Por favor, insira um parâmetro para a busca 
+Paramter must be at least   expressoMail1_2 pt-br   O Parâmetro deve ter pelo menos 
+characters  expressoMail1_2 pt-br   caracteres 
+Contact Details expressoMail1_2 pt-br   Detalhes do contato 
+page	expressoMail1_2 pt-br   Página 
+search	expressoMail1_2 pt-br   Busca 
+catalog	expressoMail1_2 pt-br   Catálogo 
+Quick Search Contacts   expressoMail1_2 pt-br   Busca rápida de contatos 
+All Catalogs    expressoMail1_2 pt-br   Todos catálogos 
+
Index: trunk/expressoMail1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 4929)
+++ trunk/expressoMail1_2/inc/class.ldap_functions.inc.php	(revision 5075)
@@ -285,4 +285,213 @@
 	}
 
+	
+	 /**
+        * Método que faz o roteamento entre os métodos de busca (Catálogo pessoal, global e todos)
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
+        * @param      <array> <$param> <parametros vindos do cliente>
+        */
+        function quicksearchcontact($params)
+        {
+            $modal = false;
+            if($params['catalog'])
+                $modal = true;
+             
+            include_once $_SESSION['rootPath']. '/header.inc.php';
+            
+                      
+            if (stripos( $params['search_for'] , '@' ) !== false) 
+                $params['search_for'] = substr($params['search_for'], 0 , stripos( $params['search_for'] , '@' ) ); 
+            
+            
+            if($modal)
+            {
+                if($params['catalog'] == "global")
+                {        
+                    return $this->quickSearchGlobal($params);
+                }
+                else
+                {
+                    if($params['catalog'] == "personal")
+                        return $this->quickSearchPersonal($params);
+                    else
+                        return $this->quickSearchAll($params);
+                }
+            }
+            else
+            {
+                if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "global")
+                {
+                    return $this->quickSearchGlobal($params);
+                } 
+                else
+                {    
+                    if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "personal")
+                        return $this->quickSearchPersonal($params);                   
+                    else
+						//Veirifica se quem chamou foi o campo de pesquisa rápida Expresso_Mail
+						if(($params['field'] == 'null') && ($params['ID'] == 'null'))
+							return $this->quickSearch($params);
+						else
+							return $this->quickSearchAll($params);							
+                }
+            }
+        }
+        
+        
+
+        /**
+        * Método que faz a busca de usuários em todos os catálogos
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
+        * @param      <array> <$param> <parametros vindos do cliente>
+        * @return     <array> <$retorno> <Array com os usuários de todos os catálogos, de acordo com o parâmetro>
+        */
+        function quickSearchAll($params)
+        {
+                
+            $retorno_personal = $this->quickSearchPersonal($params);
+            $retorno_global   = $this->quickSearchGlobal($params);
+            //$retorno = $retorno_personal + $retorno_global;
+            $retorno = array_merge($retorno_personal, $retorno_global);
+            $retorno['search_for'] = $params['search_for'];
+			$retorno['type_catalog'] = "A";
+            return $retorno;
+        }
+        
+        
+        /**
+        * Método que faz a busca de usuários no Catálogo Pessoal
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
+        * @param      <array> <$param> <parametros vindos do cliente>
+        * @return     <array> <$retorno> <Array com os usuários do Catálogo Pessoal, de acordo com o parâmetro>
+        */
+        function quickSearchPersonal($params, $all=false) 
+        {
+            $results = array();
+            $DBService = ServiceLocator::getService('db');
+            $results   = $DBService->search_contacts($params['search_for']);
+            
+            if(!$all)
+                $results['type_catalog'] = "P";
+            $results['search_for'] = $params['search_for'];
+			return $results;
+        } 
+        
+        
+        /**
+        * Método que faz a busca de usuários no Catálogo Geral
+        * @license    http://www.gnu.org/copyleft/gpl.html GPL
+        * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+        * @sponsor    Caixa Econômica Federal
+        * @author     Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br>
+        * @param      <array> <$param> <parametros vindos do cliente>
+        * @return     <array> <$retorno> <Array com os usuários do Catálogo Global, de acordo com o parâmetro>
+        */
+        function quickSearchGlobal($params, $all=false) 
+        {              
+            include_once $_SESSION['rootPath']. '/header.inc.php';
+            $c = CreateObject('phpgwapi.config','contactcenter');
+            $all_data = $c->read_repository();
+            
+            $searchable_fields = array();           
+            foreach($all_data as $index => $value)
+            {
+                $parts = explode('_', $index);
+                if (is_numeric($parts[3]) && $parts[1]=='attribute')
+                {    
+                    if($parts[2] == 'searchable' && $value == 'true')
+                        $searchable_fields[$all_data['cc_attribute_ldapname_' . $parts[3]]] = $all_data['cc_attribute_name_' . $parts[3]];   
+                }
+            }    
+            include_once("class.functions.inc.php");
+            $functions      = new functions;
+            $field	    = $params['field'];
+            $ID             = $params['ID'];
+            $ldapService    = ServiceLocator::getService('ldap');
+            $filter         = $ldapService->getSearchFilter($params['search_for']);
+  
+            $contacts_result          = array();
+            $contacts_result['field'] = $field;
+            $contacts_result['ID']    = $ID;
+            $search_for               = utf8_encode($params['search_for']);
+            
+            $this->ldapConnect(true);
+            if ($this->ds)
+            {
+                $ldapService->connection = $this->ds;
+                $campos_extras = '';
+                $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou");
+                foreach($searchable_fields as $fields_ldap => $value_field)
+                {   
+                    $campos_extras .= $fields_ldap . "|" . $value_field . "#";
+                    array_push($justthese, $fields_ldap);   
+                } 
+                $types = false;
+
+                $campos_extras = substr($campos_extras,0,-1);
+                
+                if($field == 'null' || $ID == 'null')
+                {
+                    $justthese[] = "jpegphoto";
+                    $types = 'u';
+                }  
+                $filter = $ldapService->getSearchFilter($params['search_for'], $types);
+                // Retirei o this->max_results, que limitava a busca. Agora ta retornando tudo amigo.
+                $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0);
+                 
+                if(!$sr)
+                    return null;
+                
+                $count_entries = ldap_count_entries($this->ds,$sr);
+                $info          = ldap_get_entries($this->ds, $sr);
+                $info_return   = $info;
+                //if($campos_extras != '')
+                //array_push($info_return, $campos_extras);
+			}
+			ldap_close($this->ds);      
+		
+			//Busca em Catalagos externos
+			$catalogsNum=count($this->external_srcs);
+			for ($i=0; $i<=$catalogsNum; $i++)	{
+				if ($this->external_srcs[$i]["quicksearch"]) 
+				{
+					$this->ldapConnect(true,$i);
+					$filter="(|(cn=*$search_for*)(mail=*$search_for*))";
+					$justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou");
+					$sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1);
+					if(!$sr)
+						return null;
+					$count_entries = ldap_count_entries($this->ds,$sr);
+					$search = ldap_get_entries($this->ds, $sr);
+					for ($j=0; $j<$search["count"]; $j++) {
+						$info_return[] = $search[$j];
+					}
+					$info_return["count"] = count($info_return)-1;
+				}
+			}
+			//---------------------------------------------------------------//
+			
+            if($all == false)
+                $info_return['type_catalog'] = "G";
+            
+            $info_return['search_for'] = $params['search_for'];
+			$info_return['extra_ldap_fields'] = $campos_extras; 
+            return $info_return;
+        } 
+        
+	
+	
+	
+	
+	
+	
 	function make_quicksearch_card($info, $cn)
 	{
Index: trunk/expressoMail1_2/inc/hook_settings.inc.php
===================================================================
--- trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 4885)
+++ trunk/expressoMail1_2/inc/hook_settings.inc.php	(revision 5075)
@@ -411,4 +411,14 @@
 create_select_box('What is the maximum size of embedded images?','image_size',$default,'When user send an email with image in body message, it changes the size');
 
+$default = array( 
+ 		    'global'     => lang("Global catalog"), 
+ 		    'personal'   => lang("Personal catalog"), 
+ 		    'all' => lang("All catalogs") 
+ 		); 
+ 		 
+ 	create_select_box('The dynamic search will use the catalog','catalog_search',$default,'Seleciona o catálogo que será usado para fazer a busca'); 
+
+
+
 if($GLOBALS['phpgw_info']['server']['use_assinar_criptografar'])
 {
@@ -439,5 +449,5 @@
 	$vars = $GLOBALS['phpgw']->preferences->user['expressoMail'];
 
-	create_html_code("signature","<script src='../library/jquery/jquery-1.6.1.min.js' language='javascript'></script><script src='../library/tiny_mce/jquery.tinymce.js' language='javascript'></script><script src='../library/tiny_mce/tiny_mce.js' language='javascript'></script>
+	create_html_code("signature","<script src='../library/jquery/jquery.js' language='javascript'></script><script src='../library/tiny_mce/jquery.tinymce.js' language='javascript'></script><script src='../library/tiny_mce/tiny_mce.js' language='javascript'></script>
 	<input type='hidden' id='counter' value='0'>
 	<input type='hidden' id='signatures' name='user[signatures]' value='". $vars['signatures']."'>
Index: trunk/expressoMail1_2/js/common_functions.js
===================================================================
--- trunk/expressoMail1_2/js/common_functions.js	(revision 4929)
+++ trunk/expressoMail1_2/js/common_functions.js	(revision 5075)
@@ -561,8 +561,4 @@
 	var handler_emQuickSearch = function(data)
 	{
-		window_DropDownContacts = Element('tipDiv');
-		if (window_DropDownContacts.style.visibility != 'hidden'){
-			window_DropDownContacts.style.visibility = 'hidden';
-		}
 
 		if ((!data.status) && (data.error == "many results")){
@@ -574,5 +570,5 @@
 			if ((field != 'null') && (ID != 'null'))
 			{
-				QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd);
+				QuickCatalogSearch.showList(data, quickSearchKeyBegin, quickSearchKeyEnd, ID, field);
 			}
 			else
@@ -612,5 +608,5 @@
 	}
 
-	cExecute ("$this.ldap_functions.quicksearch&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
+	cExecute ("$this.ldap_functions.quicksearchcontact&search_for="+search_for+"&field="+field+"&ID="+ID, handler_emQuickSearch);
 }
 
Index: trunk/expressoMail1_2/js/QuickCatalogSearch.js
===================================================================
--- trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 4833)
+++ trunk/expressoMail1_2/js/QuickCatalogSearch.js	(revision 5075)
@@ -6,15 +6,27 @@
 		this.cc_groups  = new Array();
 	}
-
-	emQuickCatalogSearch.prototype.showList = function(data, begin, end){
-		connector.loadScript("ccQuickAdd");
-
-                if(preferences.use_shortcuts == '0'){
-                    connector.loadScript("shortcut");
-                }
+        
+	emQuickCatalogSearch.prototype.showList = function(data, begin, end, ID, field)
+	{
+			data_    = data;	
+			id_    = ID;
+            field_ = field;
+            begin_ = begin;
+            end_   = end;
+
+			keypress_read(data);
+            init_results(data);
+            configure_slider(data);
+            details_results(data);
+			
+  		    connector.loadScript("ccQuickAdd");
+
+            if(preferences.use_shortcuts == '0'){
+                connector.loadScript("shortcut");
+            }
 		
 		id = '1';
 		_this = this;
-                var el_A = document.createElement("DIV");
+        var el_A = document.createElement("DIV");
 		el_A.style.visibility = "hidden";
 		el_A.style.position = "absolute";
@@ -25,178 +37,611 @@
 		el_A.id = 'window_QuickCatalogSearch_A';
 		document.body.appendChild(el_A);
-		el_A.innerHTML = "";
-
-		var el = document.createElement("DIV");
-		el.style.visibility = "hidden";
-		el.style.position = "absolute";
-		el.style.left = "0px";
-		el.style.top = "40px";
-		el.style.width = "695px";
-		el.style.height = "186px";
-                el.style.overflow = "auto";
-		el.id = 'window_QuickCatalogSearch';
-		el_A.appendChild(el);
-		el.innerHTML = "";
-		
-		
-		func_add_contact = function () { 
-			var select_QuickCatalogSearch = document.getElementById("select_QuickCatalogSearch");
-			var contact_selected = select_QuickCatalogSearch.options[select_QuickCatalogSearch.selectedIndex].text;
-			
-			contact_selected = contact_selected.split('(');
-			
-			var first_and_last_name = contact_selected[0].split(" ");
-			
-			var data = [];
-			data[0] = first_and_last_name[0];
-			data[1] = first_and_last_name[0];
-			data[2] = "";
-			
-			for (i=1; i < first_and_last_name.length; i++)
-				data[2] += first_and_last_name[i] + " ";
-			
-			data[2] = data[2].replace(/\s*$/g,'');
-			data[3] = contact_selected[1].substring(0, contact_selected[1].indexOf(")") );
-			
-			ccQuickAddOne.showList( data );			
+		el_A.innerHTML = "";		
+		
+		func_add_contact = function () { 	
 		};		
 		
-			var title_innerHTML = get_lang('Select a name') + ':';
-			if (data.quickSearch_only_in_userSector)
-				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
-
-			var title = document.createElement("SPAM");
-			title.id = 'window_QuickCatalogSearch_title';
-			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
-			el_A.appendChild(title);
-                        var butt = document.createElement('BUTTON');
-			var buttext = document.createTextNode('OK');
-			butt.id = "QuickCatalogSearch_button_ok";
-			butt.appendChild(buttext);
-			butt.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			el_A.appendChild(butt);
-
-			var space = document.createElement('SPAN');
-			space.innerHTML = "&nbsp;&nbsp;";
-			el_A.appendChild(space);
-
-			var butt = document.createElement('BUTTON');
-			butt.id = "QuickCatalogSearch_button_close";
-			var buttext = document.createTextNode(get_lang('Close'));
-			butt.appendChild(buttext);
-			butt.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
-			el_A.appendChild(butt);
-
-                        var space = document.createElement('SPAN');
-			space.innerHTML = "&nbsp;&nbsp;";
-			el_A.appendChild(space);
-
-                        var butt = document.createElement('BUTTON');
-			butt.id = "QuickCatalogSearch_button_add_contact";
-			var buttext = document.createTextNode(get_lang("Add Contact"));
-			butt.appendChild(buttext);
-			butt.onclick = func_add_contact;
-			el_A.appendChild(butt);
-
-		if (document.getElementById('select_QuickCatalogSearch') == null){
-			
-			var cmb = document.createElement("SELECT");
-			cmb.id = "select_QuickCatalogSearch";
-			cmb.style.width = "2400px";
-			//cmb.size = "12";
-                        cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			cmb.onkeypress = function (e)
+        _this.showWindow(el_A);	
+	}
+        
+        
+    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 };
+			var slider = $( "#slider"  );
+			switch (keyCode) 
 			{
-				if (is_ie)
+				case arrow.enter:
+					add_contact_field(document.getElementsByClassName("ui-selected")[0].getElementsByClassName("name_contact")[0].innerHTML);
+					$("#dialog-modal").dialog("close");
+					break;
+				
+				case arrow.left:
+					slider.slider( "value", $( "#slider" ).slider( "value" ) - 1);
+					create_list(data_);					
+					break;
+				
+				case arrow.right:
+					if( (($( "#slider" ).slider( "value" ))) == Math.ceil(data_.length/7) )
+					{
+						alert("Não há mais páginas");
+						break;
+					}
+					slider.slider( "value", $( "#slider" ).slider( "value" ) + 1);					
+					create_list(data_);						
+					break;
+				
+				case arrow.up:
+					id_contact = document.getElementsByClassName("ui-selected")[0].value;
+					if(id_contact == (($( "#slider" ).slider( "value" ) -1)*7))
+						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 />");  
+                                        }
+                                    } 
+                                    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;
+				
+				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;
+			}
+		});	
+	}
+			
+			
+			
+		/*
+		* Método que cria a lista de contatos
+		*/
+		function create_list(data)
+		{
+					$("#detalhes_contato").empty();
+					var paginas = Math.ceil(data.length/7) - 1; 
+					$("#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");
+                        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)
+								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)){
+								Op.setAttribute("class", "ui-selected");
+							}
+							else {	
+								Op.setAttribute("class", "ui-selectee");
+							}
+							var contact_name = utf8_decoder(data[i-1].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.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).val(i - 1);
+                            Ul.appendChild(Op);
+                            selectable.append(Ul.innerHTML);
+                        }
+                        $( "#amount" ).val( string_results );
+						$( "#amount" ).val( $( "#slider" ).slider( "value" ) + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")");   
+						document.getElementById("amount").focus();	
+		}	
+		
+		
+		
+		
+		
+		
+		function details_results(data) 
+        {
+				$(function() {
+                    $( "#selectable" ).selectable({
+						stop: function() {
+								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]);
+                                                        }
+                                                    }
+                                                }
+                                        }
+                                    }
+								});
+						}
+                    });
+                });
+        }
+        
+        
+        /* 
+         * 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 == ""))
 				{
-					if ((window.event.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((window.event.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
+					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); 
+            $("#title_usuarios").html( get_lang("Results") );
+            $(function() {
+                $( "#slider" ).slider({
+					value:1,
+					min: 1,
+					max: paginas,
+					step: 1,
+                        slide: function( event, ui ) 
+                        {
+								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" ).val( $( "#slider" ).slider( "value" ) + " " + get_lang("of") + " " + paginas + " (" + data.length + " " + get_lang("Results") + ")");         
+                });
+        }
+        
+
+		
+        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');
+				return kC == 13;
+			}
+            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;
+            }
+            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)
+                {        
+                    init_results(data_);
+                    configure_slider(data_);    
+                    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);
+        }
+		
+        
+		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.");
+			var emailList      = document.getElementById(field_ + "_" + id_).value; 
+            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[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 = emailList.substr(end_);
+            
+            if(emailList.lastIndexOf(",") > 0)
+                emailList = emailList.substr(0, emailList.lastIndexOf(",") + 2);
+            
+            new_emailList = emailList + final_contact;    
+            document.getElementById(field_ + "_" + id_).value = new_emailList;
+			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] + ">";
+			
+			if(quantidade_contatos ==0)
+			{
+				alert("Nenhum contato adicionado!");
+				return false;
+			}
+			
+			var encontrou = false;
+			var emailList = document.getElementById(field_ + "_" + id_).value; 
+			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)
 				{
-					if ((e.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((e.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
+					emails_adicionados[i] = "%";
+					quantidade_excluidos++;
+					encontrou = true;
 				}
-			};
-			el.appendChild(cmb);
-
-		}
-		else{
-			var title_innerHTML = get_lang('Select a name') + ':';
-			if (data.quickSearch_only_in_userSector)
-				title_innerHTML += "<font color='BLACK' nowrap> ("+get_lang('Showing only the results found in your organization')+".)</font>"
-
-			var title = Element('window_QuickCatalogSearch_title');
-			title.innerHTML = "&nbsp;&nbsp;<b><font color='BLUE' nowrap>"+title_innerHTML+"</font></b><br>&nbsp;&nbsp;";
-			
-			var cmb = document.getElementById('select_QuickCatalogSearch');
-                        cmb.ondblclick = function() {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			cmb.onkeypress = function (e)
+			}
+			if (encontrou == false) 
 			{
-				if (is_ie)
-				{
-					if ((window.event.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((window.event.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-				else
-				{
-					if ((e.keyCode) == 13)
-					{
-						QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);
-					}
-					else if ((e.keyCode) == 27)
-					{
-						QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);
-					}
-				}
-			};
-
-			for (i=0; i<cmb.length; i++)
-				cmb.options[i--] = null;
-			
-			var butt_ok = document.getElementById("QuickCatalogSearch_button_ok");
-			var butt_close = document.getElementById("QuickCatalogSearch_button_close");
-			var butt_add_contact = document.getElementById("QuickCatalogSearch_button_add_contact");
-			butt_ok.onclick = function () {QuickCatalogSearch.transfer_result(data.field, data.ID, begin, end);};
-			butt_close.onclick = function () {QuickCatalogSearch.close_QuickSearch_window(data.field, data.ID);};
-			butt_add_contact.onclick = func_add_contact;
-		}
-
-		for (i=0; i<data.length; i++){
-			var Op = document.createElement("OPTION");
-			Op.text = data[i].cn + ' (' + data[i].mail + ')';
-			if (data[i].phone != '')
-				Op.text += ' - ' + data[i].phone;
-			if (data[i].ou != '')
-				Op.text += ' - ' + data[i].ou; // adicionado "data[i].ou" para exibir setor (F9)
-			Op.value = '"' + data[i].cn + '" ' + '<' + data[i].mail + '>';
-			cmb.options.add(Op);
-		}
-		cmb.options[0].selected = true;
-		cmb.size = data.length+1;
-		_this.showWindow(el_A);
-	}
-	
+				alert("Não pode excluir um contato que ainda não adicionou.");
+				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;
+		}
+        
+	      
+        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 ) 
+            {
+                c1 = str_data.charCodeAt(i);
+                if (c1 < 128) 
+                {
+                    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('');
+        }
+        
+              
+    function show_help()
+	{
+		$(function() {
+			$( "#dialog-modal_help" ).dialog({
+						resizable: false,
+						height: 230,
+						width: 540,
+						modal: true,
+						closeOnEscape: true,
+
+			});
+		});
+	}	
+		  
+              
 	emQuickCatalogSearch.prototype.showWindow = function (div)
 	{
-		if(! div) {
+				$(this).bind('keypress');
+				$(function() {
+                    $( "#dialog:ui-dialog" ).dialog( "destroy" );                    
+                    $( "#dialog-modal" ).dialog({
+						resizable: false,
+						height: 530,
+						width: 940,
+						modal: true,
+						closeOnEscape: true,
+						close: function (event, ui) {
+							event.stopPropagation();
+							$(this).unbind('keypress');
+						},
+						focus: function (event, ui) {
+							$(this).bind('keypress');
+						},
+						beforeClose: function (event, ui) {
+							$(this).bind('keypress');
+						},
+						buttons:{
+							'Fechar' : function(){
+								$("#detalhes_contato, #selectable, #busca").empty();
+								$(this).dialog("close");
+							} 
+						}
+					});
+                });
+	
+                
+                
+        if(! div) {
 			alert(get_lang('The list has no participant.'));
 			return;
@@ -222,5 +667,5 @@
 				button_x_img: '../phpgwapi/images/winclose.gif',
 				border: true,
-                                onclose: 'QuickCatalogSearch.restoreShortcuts("'+ div.id +'")' });
+                                onclose: 'QuickCatalogSearch.restoreShortcuts("'+ div.id +'")'});
 
 			this.arrayWin[div.id] = win;
@@ -230,7 +675,7 @@
 			win = this.arrayWin[div.id];
 		}
-		document.getElementById("window_QuickCatalogSearch").style.visibility = "visible";
-		win.open();
-		document.getElementById('select_QuickCatalogSearch').focus();
+		//document.getElementById("window_QuickCatalogSearch").style.visibility = "visible";
+		//win.open();
+		//document.getElementById('select_QuickCatalogSearch').focus();
 
                 if(is_ie && (preferences.use_shortcuts == '1')){
@@ -249,5 +694,4 @@
 		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";
@@ -397,5 +841,5 @@
 			title_text_color: 'white',
 			button_x_img: '../phpgwapi/images/winclose.gif',
-			border: true });
+			border: true});
 			
 		this.arrayWin[el.id] = win;		
