Index: /branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php
===================================================================
--- /branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php	(revision 493)
+++ /branches/2.2/expressoAdmin1_2/inc/class.uimaillists.inc.php	(revision 3351)
@@ -166,6 +166,7 @@
 		function add_maillists()
 		{
-			$GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
-
+			if($this->current_config['users_auto_search'] == "true"){
+				$GLOBALS['phpgw']->js->set_onload('get_available_users(document.forms[0].org_context.value, document.forms[0].ea_check_allUsers.checked);');
+			}
 			$manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
 			$manager_acl = $this->functions->read_acl($manager_lid);
@@ -205,5 +206,7 @@
 				'combo_manager_org'			=> $combo_manager_org,
 				'combo_all_orgs'			=> $combo_all_orgs,
-				'defaultDomain'				=> $this->current_config['expressoAdmin_defaultDomain']
+				'defaultDomain'				=> $this->current_config['expressoAdmin_defaultDomain'],
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
@@ -304,5 +307,7 @@
 				'phpgwAccountVisible_checked'	=> $maillist_info['phpgwAccountVisible'] == '-1' ? 'CHECKED' : '',
 				'ea_select_usersInMaillist'		=> $ea_select_usersInMaillist,
-				'defaultDomain'					=> $this->current_config['expressoAdmin_defaultDomain']
+				'defaultDomain'					=> $this->current_config['expressoAdmin_defaultDomain'],
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
@@ -373,5 +378,7 @@
 				'accountRestrictive_checked'	=> $maillist_info['accountRestrictive'] == 'mailListRestriction' ? 'CHECKED' : '',
 				'participantCanSendMail_checked'=> $maillist_info['participantCanSendMail'] == 'TRUE' ? 'CHECKED' : '',
-				'ea_select_users_SCL_Maillist'	=> $ea_select_users_SCL_Maillist
+				'ea_select_users_SCL_Maillist'	=> $ea_select_users_SCL_Maillist,
+				'autosearch'				=> $this->current_config['users_auto_search'],
+				'minNum'					=> ($this->current_config['min_num_characters'] == "") ? 0:$this->current_config['min_num_characters']
 			);
 			$p->set_var($var);
Index: /branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- /branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 3171)
+++ /branches/2.2/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 3351)
@@ -764,36 +764,37 @@
 
 		if ($recursive == 'true')
-		{
-			$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);
 			$users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese);
-		}
-		else
-		{
-			$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+		else
 			$users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese);
-		}
-		
+
 		/* email lists */
-		$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
-		
-		for ($i=0; $i<$lists_entries["count"]; $i++)
-		{
-			$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
-		}
-			
-		if (count($l_tmp))
-			natcasesort($l_tmp);
-			
-		$i = 0;
-		$lists = array();
-		
-		$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
-		if (count($l_tmp))
-		{
-			foreach ($l_tmp as $mail => $cn)
-			{
-				$options .= "<option value=$mail>$cn</option>";
-			}
-			unset($l_tmp);
+		if($params['listSearch'] == 'true'){
+			if ($recursive == 'true')
+				$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);			
+			else			
+				$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+
+			$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
+
+			for ($i=0; $i<$lists_entries["count"]; $i++)
+			{
+				$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
+			}
+
+			if (count($l_tmp))
+				natcasesort($l_tmp);
+
+			$i = 0;
+			$lists = array();
+
+			$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
+			if (count($l_tmp))
+			{
+				foreach ($l_tmp as $mail => $cn)
+				{
+					$options .= "<option value=$mail>$cn</option>";
+				}
+				unset($l_tmp);
+			}
 		}
 		
@@ -2626,4 +2627,98 @@
 		return $return;
 	}
+
+	function search_available_users_and_maillist($params)
+	{
+		$context = $params['context'];
+		$recursive = $params['recursive'];
+		 $filtro =utf8_encode($params['filter']);
+		//Usado para retirar a própria lista das possibilidades de inclusão.
+		$denied_uidnumber = $params['denied_uidnumber'];
+		
+		$justthese = array("cn", "uidNumber", "mail");				
+		
+		$users_filter="(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))";
+		$lists_filter = $denied_uidnumber == '' ? "(&(phpgwAccountType=l)(cn=*$filtro*))" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber))(|(cn=*$filtro*)(mail=$filtro*)))";
+		
+		$users = Array();
+		$lists = Array();		
+
+		/* folling referral connection */
+		$ldap_conn_following_ref = ldap_connect($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['host']);
+		if ($ldap_conn_following_ref)
+		{
+			ldap_set_option($ldap_conn_following_ref, LDAP_OPT_PROTOCOL_VERSION, 3);
+			ldap_set_option($ldap_conn_following_ref, LDAP_OPT_REFERRALS, 1);
+
+			if ( ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'] != '') && ($_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw'] != '') )
+				ldap_bind($ldap_conn_following_ref, $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['acc'], $_SESSION['phpgw_info']['expresso']['cc_ldap_server']['pw']);
+		}
+		else
+			return false;
+		
+		if ($recursive == 'true')
+			$users_search = ldap_search($ldap_conn_following_ref, $context, $users_filter, $justthese);
+		else
+			$users_search = ldap_list($ldap_conn_following_ref, $context, $users_filter, $justthese);
+		
+		/* email lists */
+		if($params['listSearch'] == 'true'){
+			if ($recursive == 'true')
+				$lists_search = ldap_search($ldap_conn_following_ref, $context, $lists_filter, $justthese);			
+			else			
+				$lists_search = ldap_list($ldap_conn_following_ref, $context, $lists_filter, $justthese);
+				
+			$lists_entries = ldap_get_entries($ldap_conn_following_ref, $lists_search);
+			
+			for ($i=0; $i<$lists_entries["count"]; $i++)
+			{
+				$l_tmp[$lists_entries[$i]["mail"][0]] = $lists_entries[$i]["cn"][0];
+			}
+				
+			if (count($l_tmp))
+				natcasesort($l_tmp);
+				
+			$i = 0;
+			$lists = array();
+			
+			$options .= '<option  value="-1" disabled>------------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('email lists').'&nbsp;&nbsp;&nbsp;&nbsp;------------------------------ </option>'."\n";	
+			if (count($l_tmp))
+			{
+				foreach ($l_tmp as $mail => $cn)
+				{
+					$options .= "<option value=$mail>$cn</option>";
+				}
+				unset($l_tmp);
+			}
+		}
+		
+		/* users */
+		$users_entries = ldap_get_entries($ldap_conn_following_ref, $users_search);
+		for ($i=0; $i<$users_entries["count"]; $i++)
+		{
+			$u_tmp[$users_entries[$i]["mail"][0]] = $users_entries[$i]["cn"][0];
+		}
+			
+		if (count($u_tmp))
+			natcasesort($u_tmp);
+			
+		$i = 0;
+		$users = array();
+		
+		$options .= '<option  value="-1" disabled>-----------------------------&nbsp;&nbsp;&nbsp;&nbsp;'.$this->functions->lang('users').'&nbsp;&nbsp;&nbsp;&nbsp;---------------------------- </option>'."\n";
+			
+		if (count($u_tmp))
+		{
+			foreach ($u_tmp as $mail => $cn)
+			{
+				$options .= "<option value=$mail class='line-above'>$cn</option>";
+			}
+			unset($u_tmp);
+		}
+		
+		ldap_close($ldap_conn_following_ref);
+   		return $options;
+	}
+
 }
 ?>
Index: /branches/2.2/expressoAdmin1_2/js/jscode/maillists.js
===================================================================
--- /branches/2.2/expressoAdmin1_2/js/jscode/maillists.js	(revision 482)
+++ /branches/2.2/expressoAdmin1_2/js/jscode/maillists.js	(revision 3351)
@@ -157,42 +157,22 @@
 }
 
-function get_available_users(context, recursive)
-{
-	var handler_get_available_users = function(data)
-	{
-		select_available_users = document.getElementById('ea_select_available_users');
-		
-		//Limpa o select
-		for(var i=0; i<select_available_users.options.length; i++)
-		{
-			select_available_users.options[i] = null;
-			i--;
-		}
-
-		if ((data) && (data.length > 0))
-		{
-			// Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
-			select_available_users.innerHTML = '&nbsp;' + data;
+function get_available_users(context, recursive,listSearch)
+{
+	//Impede chamada recursiva na raiz das organizações
+	if(document.getElementById("autosearch").value == "true"){
+		if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_maillists').value))
+		{
+			alert(get_lang('It is not allow select all users from the root organization') + '.');
+			document.getElementById('ea_check_allUsers').checked = false;
+			
+			// Limpa select
+			select_available_users = document.getElementById('ea_select_available_users');
+			select_available_users.innerHTML = '&nbsp;';
 			select_available_users.outerHTML = select_available_users.outerHTML;
-			
-			select_available_users.disabled = false;
-			select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true);
-			document.getElementById('ea_input_searchUser').value = '';
-		}
-	}
-	
-	//Impede chamada recursiva na raiz das organizações
-	if ((recursive) && (document.forms[0].ldap_context.value == document.getElementById('ea_combo_org_maillists').value))
-	{
-		alert(get_lang('It is not allow select all users from the root organization') + '.');
-		document.getElementById('ea_check_allUsers').checked = false;
-		
-		// Limpa select
-		select_available_users = document.getElementById('ea_select_available_users');
-		select_available_users.innerHTML = '&nbsp;';
-		select_available_users.outerHTML = select_available_users.outerHTML;
-		return;
-	}
-	cExecute ('$this.ldap_functions.get_available_users_and_maillist&context='+context+'&recursive='+recursive+'&denied_uidnumber='+document.forms[0].uidnumber.value, handler_get_available_users);
+			return;
+		}
+	cExecute ('$this.ldap_functions.get_available_users_and_maillist&context='+context+'&recursive='+recursive+'&denied_uidnumber='+document.forms[0].uidnumber.value+'&listSearch='+listSearch, handler_get_available_users);
+	}else
+		document.getElementById('ea_input_searchUser').value = '';
 }
 
@@ -321,5 +301,5 @@
 
 // Funcoes
-function optionFinderTimeout(obj)
+/*function optionFinderTimeout(obj)
 {
 	clearTimeout(finderTimeout);	
@@ -327,6 +307,67 @@
 	oWait.innerHTML = get_lang('Searching') + '...';
 	finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
-}
-function optionFinder(id) {
+}*/
+
+function optionFinderTimeout(obj, numMin, type, autoSearch,listSearch){
+	var oWait = document.getElementById("ea_span_searching");
+	oWait.innerHTML = 'Buscando...';
+	clearTimeout(finderTimeout);		
+	
+	if(autoSearch == "True"){
+		finderTimeout = setTimeout("optionFinderLocal('"+obj.id+"')",600);
+	}
+	else if (obj.value.length >= numMin){
+		finderTimeout = setTimeout("optionFinderLdap('"+obj.id+"','"+numMin+"','"+type+"','"+listSearch+"')",600);
+	}else {
+		oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa';
+		var select_available_users_tmp = document.getElementById('ea_select_available_users');
+		for(var i = 0;i < select_available_users_tmp.options.length; i++)
+		select_available_users_tmp.options[i--] = null;
+	}
+}
+var handler_get_available_users = function(data)
+	{
+		select_available_users = document.getElementById('ea_select_available_users');
+		
+		//Limpa o select
+		for(var i=0; i<select_available_users.options.length; i++)
+		{
+			select_available_users.options[i] = null;
+			i--;
+		}
+
+		if ((data) && (data.length > 0))
+		{
+			// Necessario, pois o IE6 tem um bug que retira o primeiro options se o innerHTML estiver vazio.
+			select_available_users.innerHTML = '&nbsp;' + data;
+			select_available_users.outerHTML = select_available_users.outerHTML;
+			
+			select_available_users.disabled = false;
+			select_available_users_clone = document.getElementById('ea_select_available_users').cloneNode(true);
+			//document.getElementById('ea_input_searchUser').value = '';
+		}
+	
+	}
+// Pesquisa LDAP
+function optionFinderLdap(id,numMin, type,listSearch){
+	var oWait = document.getElementById("ea_span_searching");
+	var oText = document.getElementById(id);
+	
+	if (oText.value.length < numMin) {
+		oWait.innerHTML = '';
+		var select_available_users_tmp = document.getElementById('ea_select_available_users');
+		for(var i = 0;i < select_available_users_tmp.options.length; i++)
+			select_available_users_tmp.options[i--] = null;
+	}
+	
+	if (oText.value.length >= numMin){
+		var context = document.getElementById('ea_combo_org_maillists').value;
+		recursive = document.getElementById("ea_check_allUsers").checked;
+		cExecute ('$this.ldap_functions.search_available_users_and_maillist&context='+(context)+'&recursive='+(recursive)+'&type='+(type == '' ? 'list' : 'search')+'&filter='+oText.value+'&listSearch='+listSearch, handler_get_available_users);
+		oWait.innerHTML = '&nbsp;';
+	}
+}
+
+function optionFinderLocal(id) {
 	var oWait = document.getElementById("ea_span_searching");
 	var oText = document.getElementById(id);
Index: /branches/2.2/expressoAdmin1_2/templates/default/maillists_form.tpl
===================================================================
--- /branches/2.2/expressoAdmin1_2/templates/default/maillists_form.tpl	(revision 621)
+++ /branches/2.2/expressoAdmin1_2/templates/default/maillists_form.tpl	(revision 3351)
@@ -14,4 +14,5 @@
 					<input type="hidden" name="restrictionsOnEmailLists" value="{restrictionsOnEmailLists}">
 					<input type="hidden" name="defaultDomain" value="{defaultDomain}">
+					<input type="hidden" id="autosearch" value="{autosearch}">
 
 					<tr>
@@ -62,5 +63,5 @@
 							
 							{lang_organizations}:<br>
-							<select name="org_context" id="ea_combo_org_maillists" onchange="javascript:get_available_users(this.value, ea_check_allUsers.checked);">{combo_all_orgs}</select>
+							<select name="org_context" id="ea_combo_org_maillists" onchange="javascript:get_available_users(this.value, ea_check_allUsers.checked,true);">{combo_all_orgs}</select>
 							<br>
 							<input type="checkbox" name="ea_check_allUsers" id="ea_check_allUsers" onclick="javascript:get_available_users(org_context.value, this.checked);">{lang_show_users_from_all_sub-organizations}.
@@ -68,5 +69,5 @@
 							
 							{lang_search_user}:<br>
-							<input id="ea_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this)"><br>
+							<input id="ea_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this,{minNum},'search',{autosearch},true)"><br>
 							
 							<font color="red"><span id="ea_span_searching">&nbsp;</span></font>
Index: /branches/2.2/expressoAdmin1_2/templates/default/maillists_scl.tpl
===================================================================
--- /branches/2.2/expressoAdmin1_2/templates/default/maillists_scl.tpl	(revision 483)
+++ /branches/2.2/expressoAdmin1_2/templates/default/maillists_scl.tpl	(revision 3351)
@@ -12,5 +12,5 @@
 					<input type="hidden" name="ldap_context" value="{ldap_context}">
 					<input type="hidden" name="manager_context" value="{manager_context}">
-					
+					<input type="hidden" id="autosearch" value="{autosearch}">
 					<tr>
 						<td colspan="3" align="right" bgcolor="{color_bg1}">
@@ -39,5 +39,5 @@
 						<td valign="bottom" bgcolor="#DDDDDD">
 							{lang_organizations}:<br>
-							<select name="org_context" id="ea_combo_org_maillists" onchange="javascript:get_available_users(this.value, ea_check_allUsers.checked);">{combo_org}</select>
+							<select name="org_context" id="ea_combo_org_maillists" onchange="javascript:get_available_users(this.value, ea_check_allUsers.checked,false);">{combo_org}</select>
 							
 							<br>
@@ -47,5 +47,5 @@
 							
 							{lang_search_user}:<br>
-							<input id="ea_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this)"><br>
+							<input id="ea_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this,{minNum},'search',{autosearch},false)"><br>
 							
 							<font color="red"><span id="ea_span_searching">&nbsp;</span></font>
Index: /branches/2.2/expressoAdmin1_2/templates/default/config.tpl
===================================================================
--- /branches/2.2/expressoAdmin1_2/templates/default/config.tpl	(revision 1867)
+++ /branches/2.2/expressoAdmin1_2/templates/default/config.tpl	(revision 3351)
@@ -150,4 +150,21 @@
 	</tr>
 	
+	<tr bgcolor="{row_on}">
+     <td>{lang_Do_you_wish_enable_autosearch?}</td>
+     <td>
+       <select id="usersAutoSearch" name="newsettings[users_auto_search]">
+        <option value="false" {selected_users_auto_search_false}>{lang_No}</option>
+        <option value="true" {selected_users_auto_search_true}>{lang_Yes}</option>
+       </select>
+     </td>
+   </tr>
+   
+   <tr bgcolor="{row_off}">
+       <td>{lang_Minimum_number_of_characters_to_start_the_search_for_participants}</td>
+       <td>
+          <input type="text" id="minNum" value="{value_min_num_characters}" name="newsettings[min_num_characters]    " size=2 maxlength=2 />
+       </td>
+   </tr>
+	
 	<tr class="th">
 		<td colspan="2" align="center"><b>{lang_Configurations_to_get_nextID_from_another_DB}<br>{lang_Leave_the_host_field_empty_to_use_the_same_DB_of_the_ExpressoLivre}</b></td>
