Index: trunk/expressoAdmin1_2/inc/class.bosectors.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.bosectors.inc.php	(revision 1850)
+++ trunk/expressoAdmin1_2/inc/class.bosectors.inc.php	(revision 1991)
@@ -47,5 +47,13 @@
 			$sector_info['objectClass'][0]	= 'top';
 			$sector_info['objectClass'][1]	= 'organizationalUnit';
-			
+
+                        if( isset($_POST['associated_domain']) )
+                        {
+				if ( $_POST['associated_domain'] != "") {
+					$sector_info['objectClass'][2]  = 'domainRelatedObject';
+        	                        $sector_info['associatedDomain'] = trim($_POST['associated_domain']);
+				}
+                        }
+		
 			/*
 			 Insere as informações sobre quota total por usuários e por gigabytes de espaço em disco 
Index: trunk/expressoAdmin1_2/inc/class.uisectors.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 1684)
+++ trunk/expressoAdmin1_2/inc/class.uisectors.inc.php	(revision 1991)
@@ -185,4 +185,5 @@
 				'context'			=> $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
 				'sector'			=> $_POST['sector'],
+				'associated_domain'		=> $_POST['associated_domain'],
 				'disk_quota'        => $_POST['disk_quota'],
 				'users_quota'       => $_POST['users_quota'],
@@ -242,4 +243,5 @@
 				$sector_disk_quota = $sector_info[0]['diskquota'][0];
 				$sector_users_quota = $sector_info[0]['usersquota'][0];
+				$sector_associated_domain = $sector_info[0]['associateddomain'][0];
 				$_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
 			} 
@@ -254,7 +256,7 @@
 				'manager_org'		=> $combo_manager_org,
 				'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
+				'associated_domain'        => $_POST['associated_domain'] == '' ? $sector_associated_domain : $_POST['associated_domain'],
 				'disk_quota'        => $_POST['disk_quota'] == '' ? $sector_disk_quota : $_POST['disk_quota'],
 				'users_quota'       => $_POST['users_quota'] == '' ? $sector_users_quota : $_POST['users_quota'],
-				
 				'lang_add'			=> lang('Add'),
 				'disable'			=> 'disabled',
Index: trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php
===================================================================
--- trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 1975)
+++ trunk/expressoAdmin1_2/inc/class.ldap_functions.inc.php	(revision 1991)
@@ -1532,4 +1532,13 @@
 	}
 
+	function get_associated_domain($params)
+	{
+			$justthese = array("associatedDomain");
+			$filter="(objectClass=domainRelatedObject)";;
+			$context = $params['context'];
+			$search = ldap_search($this->ldap,$context, $filter, $justthese);
+			$entry = ldap_get_entries($this->ldap, $search);
+			return $entry[0]['associateddomain'][0];
+        }
 	
 	function change_user_context($dn, $newrdn, $newparent)
Index: trunk/expressoAdmin1_2/js/jscode/expressoadmin.js
===================================================================
--- trunk/expressoAdmin1_2/js/jscode/expressoadmin.js	(revision 1916)
+++ trunk/expressoAdmin1_2/js/jscode/expressoadmin.js	(revision 1991)
@@ -33,4 +33,20 @@
 }
 
+function get_associated_domain(context)
+{
+	var handler_associated_domain = function(data)
+	{
+		if (data != null)
+		{
+			document.forms[0].associated_domain.value = data;
+		}
+		else
+		{
+			document.forms[0].associated_domain.value = '';
+		}
+	}
+	cExecute ('$this.ldap_functions.get_associated_domain&context='+context, handler_associated_domain);	
+}
+
 function emailSugestion_expressoadmin2(email) {		
 		if ( email.value.indexOf('@', 0) < 0 )  emailSugestion = 1;
@@ -39,5 +55,5 @@
 			var context = "";
 
-			organization_context = Element('ea_combo_org').value;
+			organization_context = Element('ea_combo_org').value.toLowerCase();
 			// Transformar os DN em User Friendly Naming format
 			organization_name = organization_context.split(",");
@@ -46,7 +62,14 @@
 				context += tmp[1];
 				if( i < (organization_name.length - 1) ) context +=  '.';
-			}			 
-			email.value = email.value + context;
-			emailSugestion = 0;
+			}
+			if (document.forms[0].associated_domain.value != '')
+			{
+				associatedDomain_name = document.forms[0].associated_domain.value;
+				email.value = email.value + associatedDomain_name;
+				emailSugestion = 0;
+			} else{
+				email.value = email.value + context;
+				emailSugestion = 0;
+			}
 		}		
 }
@@ -91,7 +114,17 @@
 		org_name = org_name_par.split('.');
 		org_name = org_name[org_name.length-1];
-	
+
 		if (org_name != '')
-			document.forms[0].mail1.value = document.forms[0].uid.value + '@' + org_name + '.' + domain_name;
+		{
+			if (document.forms[0].associated_domain.value != '')
+			{
+				associatedDomain_name = document.forms[0].associated_domain.value;
+				document.forms[0].mail1.value = document.forms[0].uid.value + '@' + associatedDomain_name;
+			}
+			else
+			{
+				document.forms[0].mail1.value = document.forms[0].uid.value + '@' + org_name + '.' + domain_name;
+			}
+		}
 		else
 			document.forms[0].mail1.value = document.forms[0].uid.value;
Index: trunk/expressoAdmin1_2/templates/default/accounts_form.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 1329)
+++ trunk/expressoAdmin1_2/templates/default/accounts_form.tpl	(revision 1991)
@@ -15,11 +15,12 @@
 <input type="hidden" name="photo_exist"  		value="{photo_exist}">
 <input type="hidden" name="user_context"		value="{user_context}">
-<input type="hidden" name="departmentnumber"	value="{departmentnumber}">
+<input type="hidden" name="departmentnumber"		value="{departmentnumber}">
 <input type="hidden" name="userSamba"			value="{userSamba}">
-<input type="hidden" name="defaultLogonScript"	value="{defaultLogonScript}">
+<input type="hidden" name="defaultLogonScript"		value="{defaultLogonScript}">
 <input type="hidden" name="imapDelimiter"		value="{imapDelimiter}">
-<input type="hidden" name="minimumSizeLogin"	value="{minimumSizeLogin}">
+<input type="hidden" name="minimumSizeLogin"		value="{minimumSizeLogin}">
 <input type="hidden" name="defaultDomain"		value="{defaultDomain}">
 <input type="hidden" name="ldap_context"		value="{ldap_context}">
+<input type="hidden" name="associated_domain"		value="{associated_domain}">
 
 <br>
@@ -42,10 +43,10 @@
 		<tr bgcolor={row_on}>
 			<td>{lang_search_organization}:</td>
-			<td><input type="text" id="organization_search" {disabled} autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org_info');" onBlur="javascript:sinc_combos_org(context.value); get_available_groups(context.value); get_available_maillists(context.value); get_available_sambadomains(context.value, '{type}')"></td>
+			<td><input type="text" id="organization_search" {disabled} autocomplete="off" size=20 onKeyUp="javascript:search_organization(this.value, 'ea_combo_org_info');" onBlur="javascript:sinc_combos_org(context.value); get_associated_domain(context.value); get_available_groups(context.value); get_available_maillists(context.value); get_available_sambadomains(context.value, '{type}')"></td>
 		</tr>
 
 		<tr bgcolor={row_off}>
 			<td>{lang_organizations}:</td>
-			<td><select {disabled} id="ea_combo_org_info" name="context" onchange="javascript:sinc_combos_org(this.value); get_available_groups(this.value); get_available_maillists(this.value); get_available_sambadomains(this.value, '{type}')">{sectors}</select></td>
+			<td><select {disabled} id="ea_combo_org_info" name="context" onchange="javascript:sinc_combos_org(this.value); get_associated_domain(this.value); get_available_groups(this.value); get_available_maillists(this.value); get_available_sambadomains(this.value, '{type}')">{sectors}</select></td>
 		</tr>
 							
Index: trunk/expressoAdmin1_2/templates/default/sectors_form.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/sectors_form.tpl	(revision 1516)
+++ trunk/expressoAdmin1_2/templates/default/sectors_form.tpl	(revision 1991)
@@ -21,4 +21,12 @@
    			<td>
 				<input type="text" {disable} autocomplete="off" name="sector" value={sector}>
+   			</td>
+ 		</tr>
+  		<tr>  
+   			<td>
+   				{lang_Associated_domain}:
+   			</td>
+   			<td>
+				<input type="text" {disable} autocomplete="off" name="associated_domain" value={associated_domain}>
    			</td>
  		</tr>
Index: trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl	(revision 1975)
+++ trunk/expressoAdmin1_2/templates/default/institutional_accounts_modal.tpl	(revision 1991)
@@ -17,5 +17,7 @@
 			<br>
 			{lang_organization}:<br>
-			<select id="ea_combo_org" name="context" onchange="javascript:sinc_combos_org(this.value);">{manager_organizations}</select><br>
+			<select id="ea_combo_org" name="context" onchange="javascript:sinc_combos_org(this.value);javascript:get_associated_domain(this.value);">{manager_organizations}</select><br>
+			
+			<input type="hidden" id="associated_domain" name="associated_domain">
 							
 			{lang_full_name}: <font color="blue">{lang_eg}: Setor Diser</font><br>
Index: trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl
===================================================================
--- trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl	(revision 1986)
+++ trunk/expressoAdmin1_2/templates/default/shared_accounts_modal.tpl	(revision 1991)
@@ -16,5 +16,7 @@
 			
 			{lang_organization}:
-			<select id="ea_combo_org" name="context" onchange="javascript:sinc_combos_org(this.value);">{manager_organizations}</select><br>
+			<select id="ea_combo_org" name="context" onchange="javascript:sinc_combos_org(this.value);javascript:get_associated_domain(this.value);">{manager_organizations}</select><br>
+			
+			<input type="hidden" id="associated_domain" name="associated_domain">
 							
 			{lang_full_name}: 
