Index: trunk/calendar/templates/default/js/edit_exmail.js
===================================================================
--- trunk/calendar/templates/default/js/edit_exmail.js	(revision 1587)
+++ trunk/calendar/templates/default/js/edit_exmail.js	(revision 1640)
@@ -21,5 +21,4 @@
 var agt = navigator.userAgent.toLowerCase();
 var is_firefox_0 = agt.indexOf('firefox/1.0') != -1 && agt.indexOf('firefox/0.') ? true : false;
-	
 /*
 	Semelhante a função get_avaiable_users, porém trás apenas usuários, ignorando os grupos...
@@ -55,68 +54,85 @@
 }
 
-function get_available_users(filter,autoSearch)
-//function get_available_users(path,context,type)
-{
-	text= document.getElementById("cal_input_searchUser");
-	
-	var handler_get_available_users = function(data)
-	{	
-		select_available_users = document.getElementById('user_list_in');
+var handler_get_available_users = function(data)
+{	
+	select_available_users = Element('user_list_in');
+	
+	for(var i=0; i<select_available_users.options.length; i++){
+		select_available_users.options[i] = null;
+		i--;
+	}
+	var options = '###';
+	if (data) {
+		if(data.groups && data.groups.length > 0) {
+			data.groups = '<option  value="-1" disabled>------------------- '+Element("txt_groups").value+' ------------------ </option>' + data.groups;
+		}		
+		if(data.users && data.users.length > 0) {
+			data.users = '<option  value="-1" disabled>------------------- '+Element("txt_users").value+' ------------------ </option>' + data.users;
+		}
+		options +=  data.groups && data.groups.length > 0 ? data.groups : '';
+		options +=  data.users  && data.users.length  > 0 ? data.users  : '';
 		
-		for(var i=0; i<select_available_users.options.length; i++){
-			select_available_users.options[i] = null;
-			i--;
-		}
-		var options = '###';
-		if (data) {
-			if(data.groups && data.groups.length > 0) {
-				data.groups = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_groups").value+' ------------------ </option>' + data.groups;
-			}
-			
-			if(data.users && data.users.length > 0) {
-				data.users = '<option  value="-1" disabled>------------------- '+document.getElementById("txt_users").value+' ------------------ </option>' + data.users;
-			}
-			options +=  data.groups && data.groups.length > 0 ? data.groups : '';
-			options +=  data.users  && data.users.length  > 0 ? data.users  : '';
-			
-			if(is_firefox_0)
-				fixBugInnerSelect(select_available_users,options);
-			else
-				select_available_users.innerHTML = options;
-
-			select_available_users.outerHTML = select_available_users.outerHTML;
-			select_available_users.disabled = false;
-			select_available_users_clone = document.getElementById('user_list_in').cloneNode(true);
-			//document.getElementById('cal_input_searchUser').value = '';
-		}
-	}	
-		context = document.getElementById('combo_org').value;
-		cExecute ('expressoMail1_2'+'.ldap_functions.search_users&filter='+filter+'&context='+context+'&type=search', handler_get_available_users);
-		
-		if((autoSearch == 'True') && (!text.value)){
-	                var search = " ";
-	                get_available_users(search);
-	        }
-		//cExecute (path+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users);
-}
-
-function optionFinderTimeout(obj,numMin){
-		var oWait = document.getElementById("cal_span_searching");
-		clearTimeout(finderTimeout);
-		if (obj.value.length >= numMin){				
-			oWait.innerHTML = 'Buscando...';
-			finderTimeout = setTimeout("optionFinder('"+obj.id+"','"+numMin+"')",500);
-		}else {
-			oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa';
-			var select_available_users_tmp = document.getElementById('user_list_in');
-			for(var i = 0;i < select_available_users_tmp.options.length; i++)
-			select_available_users_tmp.options[i--] = null;
-		}
-}
-	
-function optionFinder(id,numMin){
-	
-		var oWait = document.getElementById("cal_span_searching");
-		var oText = document.getElementById(id);
+		if(is_firefox_0)
+			fixBugInnerSelect(select_available_users,options);
+		else
+			select_available_users.innerHTML = options;
+
+		select_available_users.outerHTML = select_available_users.outerHTML;
+		select_available_users.disabled = false;
+		select_available_users_clone = Element('user_list_in').cloneNode(true);		
+	}
+}	
+
+function get_available_users(module,context,type, autoSearch){
+	Element('cal_input_searchUser').value = '';
+	if(autoSearch != 'True'){
+		return true;
+	}
+	var context = document.getElementById('combo_org').value;	
+	cExecute (module+'.ldap_functions.get_available_users&context='+context+'&type='+type, handler_get_available_users);
+}
+
+function optionFinderTimeout(obj, numMin, type, autoSearch){
+	var oWait = Element("cal_span_searching");
+	oWait.innerHTML = 'Buscando...';
+	clearTimeout(finderTimeout);		
+	
+	if(autoSearch == "True"){
+		finderTimeout = setTimeout("optionFinderLocal('"+obj.id+"')",500);
+	}
+	else if (obj.value.length >= numMin){
+		finderTimeout = setTimeout("optionFinderLdap('"+obj.id+"','"+numMin+"','"+type+"')",500);
+	}else {
+		oWait.innerHTML = 'Mínimo de '+numMin+' letras para pesquisa';
+		var select_available_users_tmp = document.getElementById('user_list_in');
+		for(var i = 0;i < select_available_users_tmp.options.length; i++)
+		select_available_users_tmp.options[i--] = null;
+	}
+}
+// Pesquisa Javascript
+function optionFinderLocal(id){
+	var oText = Element(id);
+	var oWait = Element("cal_span_searching");
+	var select_available_users_tmp = Element('user_list_in');
+	for(var i = 0;i < select_available_users_tmp.options.length; i++)
+		select_available_users_tmp.options[i--] = null;
+	var RegExp_name = new RegExp("\\b"+oText.value, "i");
+
+	for(i = 0; i < select_available_users_clone.length; i++){
+		if (RegExp_name.test(select_available_users_clone[i].text) || select_available_users_clone[i].value =="-1")
+		{
+			sel = select_available_users_tmp.options;
+			option = new Option(select_available_users_clone[i].text,select_available_users_clone[i].value);
+			if( select_available_users_clone[i].value == "-1") option.disabled = true;
+			sel[sel.length] = option;
+		}
+	}
+	oWait.innerHTML = '&nbsp;';	
+}
+
+// Pesquisa LDAP
+function optionFinderLdap(id,numMin, type){
+		var oWait = Element("cal_span_searching");
+		var oText = Element(id);
 			
 		if (oText.value.length < numMin) {
@@ -127,24 +143,10 @@
 		}
 		
-		if (oText.value.length >= numMin) {
-			get_available_users(oText.value);
-		
-			var select_available_users_tmp = document.getElementById('user_list_in');
-			for(var i = 0;i < select_available_users_tmp.options.length; i++)
-				select_available_users_tmp.options[i--] = null;
-			var RegExp_name = new RegExp("\\b"+oText.value, "i");
-	
+		if (oText.value.length >= numMin){
+			var context = document.getElementById('combo_org').value;
+			cExecute ('expressoMail1_2.ldap_functions.search_users&context='+(context)+'&type='+(type == '' ? 'list' : 'search')+'&filter='+oText.value, handler_get_available_users);
 			oWait.innerHTML = '&nbsp;';
 		}
 }
-	function autoOptionFinder(){
-		var oWait = document.getElementById("cal_span_searching");
-                var oText = document.getElementById(id);
-		var select_available_users_tmp = document.getElementById('user_list_in');
-                for(var i = 0;i < select_available_users_tmp.options.length; i++)
-                	select_available_users_tmp.options[i--] = null;
-		var RegExp_name = new RegExp("\\b   ", "i");
-		oWait.innerHTML = '&nbsp;';
-	}
 
 function add_user()
@@ -427,3 +429,2 @@
 	}
 };
-
Index: trunk/calendar/templates/default/js/edit.js
===================================================================
--- trunk/calendar/templates/default/js/edit.js	(revision 1447)
+++ trunk/calendar/templates/default/js/edit.js	(revision 1640)
@@ -7,5 +7,5 @@
 	var select_in  = document.getElementById('user_list');
 	var select_out  = document.getElementById('user_list_in');	
-	var users_out = select_out.cloneNode(true);
+	var users_out = select_out ? select_out.cloneNode(true) : '';
 	var finderTimeout = '';
 																		
