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);
