Index: trunk/expressoAdmin1_2/js/jscode/shared_accounts.js
===================================================================
--- trunk/expressoAdmin1_2/js/jscode/shared_accounts.js	(revision 1913)
+++ trunk/expressoAdmin1_2/js/jscode/shared_accounts.js	(revision 1913)
@@ -0,0 +1,542 @@
+countFiles = 1;
+
+function create_shared_accounts()
+{
+	select_owners = Element('ea_select_owners');
+        hidden_owners_acl = Element('owners_acls');
+	for(var i = 0;i < select_owners.options.length; i++){		
+		var user = select_owners.options[i].value;
+		select_owners.options[i].value = user;                
+	}
+        hidden_owners_acl.value =  connector.serialize(sharemailbox.ownersAcl);
+	cExecuteForm ("$this.shared_accounts.create", document.forms['shared_accounts_form'], handler_create_shared_accounts);
+        hidden_owners_acl.value = "";
+}
+
+function handler_create_shared_accounts(data_return)
+{
+	handler_create_shared_accounts2(data_return);
+	return;
+}
+
+function handler_create_shared_accounts2(data_return)
+{
+	if (!data_return.status)
+	{
+		write_msg(data_return.msg, 'error');
+	}
+	else
+	{
+		close_lightbox();
+		write_msg(get_lang('Shared account successful created') + '.', 'normal');
+	}
+	return;
+}
+
+function empty_inbox(uid)
+{
+var action = get_lang('Cleanned user mailbox');
+var handler_write_log = function(){}
+
+var handler_empty_inbox = function(data)
+{
+    if (!data.status)
+        alert(data.msg);
+    else{
+        cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
+        alert(get_lang('Emptied') +' '+ data.inbox_size + ' ' + get_lang('MB from user inbox'));
+        document.getElementById('mailquota_used').value = data.mailquota_used;
+    }
+}
+    cExecute ('$this.shared_accounts.empty_inbox&uid='+Element('anchor').value, handler_empty_inbox);
+}
+function set_onload()
+{
+	sinc_combos_org(Element('ea_combo_org').value);
+	get_available_users(Element('ea_combo_org').value);
+}
+
+function get_available_users(context)
+{
+	var	handler_get_users = function(data)
+	{
+		select_available_users = Element('ea_select_available_users');
+		
+		//Clean 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 = Element('ea_select_available_users').cloneNode(true);
+			//document.getElementById('ea_input_searchUser').value = '';
+		}
+	}
+	cExecute ('$this.ldap_functions.get_available_users2&context='+context, handler_get_users);
+}
+
+function search_organization(key, element)
+{
+	var organizations = Element(element);
+	var RegExp_org = new RegExp("\\b"+key, "i");
+	
+	for(i = 0; i < organizations.length; i++)
+	{
+		if (RegExp_org.test(organizations[i].text))
+		{
+			organizations[i].selected = true;
+			return;
+		}
+	}
+}
+
+function sinc_combos_org(context)
+{
+	combo_org_available_users = Element('ea_combo_org_available_users');
+
+	for (i=0; i<combo_org_available_users.length; i++)
+	{
+		if (combo_org_available_users.options[i].value == context)
+		{
+			combo_org_available_users.options[i].selected = true;
+			get_available_users(context);
+			break;
+		}
+	}
+}
+
+var finderTimeout = '';
+function optionFinderTimeout(obj)
+{
+	clearTimeout(finderTimeout);
+	var oWait = Element("ea_span_searching");
+	oWait.innerHTML = get_lang('searching') + '...';
+	finderTimeout = setTimeout("optionFinder('"+obj.id+"')",500);
+}
+function optionFinder(id) {
+	var oWait = Element("ea_span_searching");
+	var oText = Element(id);
+		
+	//Limpa todo o select
+	var select_available_users_tmp = Element('ea_select_available_users')
+
+	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");
+	
+	//Inclui usuï¿œrio comeï¿œando com a pesquisa
+	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;';
+}			
+
+function add_user()
+{
+	select_available_users = Element('ea_select_available_users');
+	select_owners = Element('ea_select_owners');
+
+	var count_available_users = select_available_users.length;
+	var new_options = '';
+
+	for (i = 0 ; i < count_available_users ; i++)
+	{
+		if (select_available_users.options[i].selected)
+		{
+			if(document.all)
+			{
+				if ( (select_owners.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
+				{
+					new_options +=  "<option value="
+								+ select_available_users.options[i].value
+								+ ">"
+								+ select_available_users.options[i].text
+								+ "</options>";
+				}
+			}
+			else
+			{
+				if ( (select_owners.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
+				{
+					new_options +=  "<option value="
+								+ select_available_users.options[i].value
+								+ ">"
+								+ select_available_users.options[i].text
+								+ "</options>";
+				}
+			}
+		}
+	}
+
+	if (new_options != '')
+	{
+		select_owners.innerHTML = "&nbsp;" + new_options + select_owners.innerHTML;
+		select_owners.outerHTML = select_owners.outerHTML;
+		select_owners.options[0].selected = true;
+                Element('em_input_readAcl').checked = false;
+		Element('em_input_deleteAcl').checked = false;
+		Element('em_input_writeAcl').checked = false;
+		Element('em_input_sendAcl').checked = false;
+                Element('em_input_sendAcl').disabled = true;
+	}
+}
+
+function remove_user()
+{
+	select_owners = Element('ea_select_owners');
+	for(var i = 0;i < select_owners.options.length; i++)
+		if(select_owners.options[i].selected){
+                        var user = select_owners.options[i].value;
+                        delete sharemailbox.ownersAcl[user];
+                        select_owners.options[i--] = null;
+                }
+       if(select_owners.options.length > 1 ){
+            select_owners.options[0].selected = true;
+            var user = select_owners.options[0].value;
+            sharemailbox.getaclfromuser(user);
+       }
+}
+
+function get_shared_accounts_timeOut(input)
+{
+	var head_table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("remove")+'</td></tr></table>';
+	
+	if (input.length > 4)
+	{
+		clearTimeout(finderTimeout);
+		finderTimeout = setTimeout("get_shared_accounts('"+input+"')",500);
+	}
+	else
+	{
+		Element('shared_accounts_content').innerHTML = head_table;
+	}
+}
+
+function get_shared_accounts(input)
+{
+	var handler_get_shared_accounts = function(data)
+	{
+		if (data.status == 'true')
+		{
+			var table = '<table border="0" width="90%"><tr bgcolor="#d3dce3"><td width="30%">'+get_lang("full name")+'</td><td width="30%">'+get_lang("mail")+'</td><td width="5%" align="center">'+get_lang("remove")+'</td></tr>'+data.trs+'</table>';
+			Element('shared_accounts_content').innerHTML = table;
+		}
+		else
+			write_msg(data.msg, 'error');
+	}
+	cExecute ('$this.ldap_functions.get_shared_accounts&input='+input, handler_get_shared_accounts);
+}
+
+function edit_shared_account(uid)
+{
+	var handle_edit_shared_account = function(data)
+	{
+		if (data.status == 'true')
+		{
+			modal('shared_accounts_modal','save');
+			
+			var combo_org = Element('ea_combo_org');
+			for (i=0; i<combo_org.length; i++)
+			{
+				if (combo_org.options[i].value == data.user_context)
+				{
+					combo_org.options[i].selected = true;
+					break;
+				}
+			}
+			
+			// anchor
+			Element('anchor').value = "uid=" + uid + ',' + data.user_context;                        
+                        
+			if (data.accountStatus != 'active')
+				Element('accountStatus').checked = false;
+				
+			if (data.phpgwAccountVisible == '-1')
+				Element('phpgwAccountVisible').checked = true;
+			
+			Element('cn').value = data.cn;
+			Element('mail').value = data.mail;
+                        Element('mailquota').value = data.mailquota;
+                        Element('mailquota_used').value = data.mailquota_used;
+                        Element('quota_used_field').style.display = 'inline';
+			Element('description').value = data.description;
+			Element('ea_select_owners').innerHTML = data.owners_options;
+                        Element('display_empty_inbox').style.display = data.display_empty_inbox;
+                        if( data.allow_edit_shared_account_acl == "0"){
+                            Element('bt_add_user').disabled = true;
+                            Element('bt_remove_user').disabled = true;
+                            Element('em_input_readAcl').disabled = true;
+                            Element('em_input_deleteAcl').disabled = true;
+                            Element('em_input_writeAcl').disabled = true;
+                            Element('em_input_sendAcl').disabled = true;
+                        }
+
+			sinc_combos_org(data.user_context);
+                        sharemailbox.ownersAcl = new Array();
+			for (i=0; i<data.owners.length; i++){
+					sharemailbox.ownersAcl[ data.owners[i] ] = data.owners_acl[i];	
+			}
+		}
+		else
+			write_msg(data.msg, 'error');
+	}
+	cExecute ('$this.shared_accounts.get_data&uid='+uid, handle_edit_shared_account);
+}
+
+function save_shared_accounts()
+{
+	if (is_ie){
+		var i = 0;
+		while (document.forms(i).name != "shared_accounts_form"){i++}
+		form = document.forms(i);
+	}
+	else   form = document.forms["shared_accounts_form"];
+        
+	hidden_owners_acl = Element('owners_acls');
+	select_owners = Element('ea_select_owners');
+	for(var i = 0;i < select_owners.options.length; i++){		
+		var user = select_owners.options[i].value;                
+		select_owners.options[i].value = user;
+		}
+        hidden_owners_acl.value =  connector.serialize(sharemailbox.ownersAcl);
+	cExecuteForm ("$this.shared_accounts.save", form, handler_save_shared_accounts);
+        hidden_owners_acl.value = "";
+}
+
+function handler_save_shared_accounts(data_return)
+{
+	handler_save_shared_accounts2(data_return);
+	return;
+}
+function handler_save_shared_accounts2(data_return)
+{
+	if (!data_return.status)
+	{
+		write_msg(data_return.msg, 'error');
+	}
+	else
+	{
+		get_shared_accounts(Element('ea_shared_account_search').value);
+		close_lightbox();
+		write_msg(get_lang('Shared account successful saved') + '.', 'normal');
+	}
+	return;
+}
+
+function delete_shared_accounts(uid)
+{
+	if (!confirm(get_lang('Are you sure that you want to delete this shared account') + "?"))
+		return;
+	
+	var handle_delete_shared_account = function(data_return)
+	{
+		if (!data_return.status)
+		{
+			write_msg(data_return.msg, 'error');
+		}
+		else
+		{
+			write_msg(get_lang('Shared account successful deleted') + '.', 'normal');
+			get_shared_accounts(Element('ea_shared_account_search').value);
+		}
+		return;
+	}
+	cExecute ('$this.shared_accounts.delete&uid='+uid, handle_delete_shared_account);
+}	function cShareMailbox()
+	{
+		this.arrayWin = new Array();
+		this.el;
+		this.alert = false;
+		this.ownersAcl = new Array();
+	}
+
+	cShareMailbox.prototype.get_available_users = function(context)
+	{
+		var handler_get_available_users = function(data)
+		{
+			select_available_users = document.getElementById('em_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 = '#' + data;
+				select_available_users.outerHTML = select_available_users.outerHTML;
+			
+				select_available_users.disabled = false;
+				select_available_users_clone = document.getElementById('em_select_available_users').cloneNode(true);
+				document.getElementById('em_input_searchUser').value = '';
+			}
+		}
+		cExecute ("$this.ldap_functions.get_available_users2&context="+context, handler_get_available_users);
+	}
+
+	cShareMailbox.prototype.getaclfromuser = function(user)
+	{
+	
+		Element('em_input_readAcl').checked = false;
+		Element('em_input_deleteAcl').checked = false;
+		Element('em_input_writeAcl').checked = false;
+		Element('em_input_sendAcl').checked = false;
+		Element('em_input_saveAcl').checked = false;
+		Element('em_input_saveAcl').disabled = true;
+		
+		if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('lrs',0) >= 0)
+		{
+			Element('em_input_sendAcl').disabled = false;
+			Element('em_input_readAcl').checked = true;
+		}
+		else
+			Element('em_input_sendAcl').disabled = true;
+			
+		if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('d',0) >= 0)
+		{
+			Element('em_input_deleteAcl').checked = true;
+		}
+		if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('wi',0) >= 0)
+		{
+			Element('em_input_writeAcl').checked = true;
+		}		
+		if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('a',0) >= 0)
+		{
+			Element('em_input_sendAcl').disabled = false;
+			Element('em_input_sendAcl').checked = true;
+		}
+		if (this.ownersAcl[user] != "false" && this.ownersAcl[user].indexOf('p',0) >= 0)
+		{
+			Element('em_input_saveAcl').disabled = false;
+			Element('em_input_saveAcl').checked = true;
+		}
+		if( this.ownersAcl[user] != "false" && Element('em_input_writeAcl').checked && Element('em_input_sendAcl').checked ){
+			Element('em_input_saveAcl').disabled = false;
+		} else Element('em_input_saveAcl').disabled = true;
+	}
+	
+	cShareMailbox.prototype.setaclfromuser = function()
+	{
+		var acl		= '';
+		var select 	= Element('ea_select_owners');
+
+		if(select.selectedIndex == "-1"){
+			alert("Selecione antes um usuario!");
+			return false;
+		}
+		var user = select.options[select.selectedIndex].value;
+		
+		if (Element('em_input_readAcl').checked) {
+			Element('em_input_sendAcl').disabled = false;
+			acl = 'lrs';
+		}
+		else{
+			Element('em_input_sendAcl').disabled = true;
+			Element('em_input_sendAcl').checked = false;
+		}
+				
+		if (Element('em_input_deleteAcl').checked)
+			acl += 'd';
+
+		if (Element('em_input_writeAcl').checked)
+			acl += 'wi';
+
+		if (Element('em_input_sendAcl').checked)
+			acl += 'a';
+				
+		if (Element('em_input_sendAcl').checked && Element('em_input_writeAcl').checked){
+			Element('em_input_saveAcl').disabled = false;				
+		} else {
+			Element('em_input_saveAcl').disabled = true;
+			Element('em_input_saveAcl').checked = false;
+		}
+		if (Element('em_input_saveAcl').checked)
+			acl += 'p';
+		this.ownersAcl[user] = acl;		
+	}
+		
+	cShareMailbox.prototype.add_user = function()
+	{
+		var select_available_users = document.getElementById('em_select_available_users');
+		var select_users = document.getElementById('ea_select_owners');
+
+		var count_available_users = select_available_users.length;
+		var count_users = select_users.options.length;
+		var new_options = '';
+	
+		for (i = 0 ; i < count_available_users ; i++)
+		{
+			if (select_available_users.options[i].selected)
+			{
+				if(document.all)
+				{
+					if ( (select_users.innerHTML.indexOf('value='+select_available_users.options[i].value)) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_users.options[i].value
+									+ '>'
+									+ select_available_users.options[i].text
+									+ '</option>';
+					}
+				}
+				else
+				{
+					if ( (select_users.innerHTML.indexOf('value="'+select_available_users.options[i].value+'"')) == '-1' )
+					{
+						new_options +=  '<option value='
+									+ select_available_users.options[i].value
+									+ '>'
+									+ select_available_users.options[i].text
+									+ '</option>';
+					}
+				}
+			}
+		}
+
+		if (new_options != '')
+		{
+			select_users.innerHTML = '#' + new_options + select_users.innerHTML;
+			select_users.outerHTML = select_users.outerHTML;
+                        
+		}
+	}
+
+	cShareMailbox.prototype.remove_user = function()
+	{
+		select_users = document.getElementById('ea_select_owners');
+	
+		for(var i = 0;i < select_users.options.length; i++)
+			if(select_users.options[i].selected)
+				select_users.options[i--] = null;
+				
+		Element('em_input_readAcl').checked = false;
+		Element('em_input_deleteAcl').checked = false;
+		Element('em_input_writeAcl').checked = false;
+		Element('em_input_sendAcl').checked = false;
+	}
+	
+	
+/* Build the Object */
+	var sharemailbox;
+	sharemailbox = new cShareMailbox();
Index: trunk/expressoAdmin1_2/js/jscode/users.js
===================================================================
--- trunk/expressoAdmin1_2/js/jscode/users.js	(revision 1594)
+++ trunk/expressoAdmin1_2/js/jscode/users.js	(revision 1913)
@@ -667,9 +667,9 @@
 		else{
 			cExecute ('$this.user.write_log_from_ajax&_action='+action+'&userinfo='+uid, handler_write_log);
-			alert(get_lang('Emptied ') + data.inbox_size + ' ' + get_lang('MB from user inbox'));
+			alert(get_lang('Emptied')+' '+ data.inbox_size + ' ' + get_lang('MB from user inbox'));
 			document.getElementById('mailquota_used').value = data.mailquota_used;
 		}
 	}
-	cExecute ('$this.imap_functions.empty_inbox&uid='+uid, handler_empty_inbox);
+	cExecute ('$this.imap_functions.empty_user_inbox&uid='+uid, handler_empty_inbox);
 }
 
