<div id="primary_header">
	<h1><?php print $this->translate('Global Settings')?></h1>

</div>

<div id="primary_content">
	<div id="primary_content_inner">
		<div id="Flash" class="flash_notice"><?php print $this->translate('The settings have been updated') ?></div>
		<div id="licence-error" style="display: none;"><img class="regerror" src="<?php echo $this->siteBaseUrl; ?>/images/icons/error.png"/><span></span></div>

		<form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/settings/globalsave">

			<input type="hidden" name="save" value="1" />

			<table class="settings">

				<tr>
					<td class="label"><?php print $this->translate('Installation Mode')?></td>
					<td>
						<strong><?php echo ($this->global['install_type'] == 'server') ? 'Atmail Server Edition' : 'Atmail Webmail Client' ?></strong>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Admin Email')?></td>
					<td>
						<input type="text" class="medium" name="fields[admin_email]" id="admin_email" value="<?php echo $this->global['admin_email'] ?>" />
						<small><?php print $this->translate('Specify the administrator email that maintains the Atmail system')?></small>
					</td>
				</tr>

				<tr>
					<td class="label"><?php print $this->translate('Session timeout')?></td>
					<td>
						<input type="text" class="small" name="fields[session_timeout]" id="session_timeout" onKeyPress="return checkinput(this, event)" onChange="checknonzero(this)" value="<?php echo $this->global['session_timeout'] ?>" />
						<small><?php print $this->translate('Specify the timeout in minutes for a Webmail session to expire due to inactivity')?></small>
					</td>
				</tr>
				<tr>
					<td class="label"><label><?php print $this->translate('Default User License Type')?></label></td>
					<td class="tdstyle">
						<div class="styled-select">
						        <span class="arrow"></span>
                        <?php echo license::options($this->groupData); ?>
</div>
                        <?php echo license::optionssmall('users', $this->groupData); ?>
					</td>
				</tr>

				<tr>
					<td class="label"><label><?php print $this->translate('Exclusive Sessions')?></label></td>
					<td>
						<input type='hidden' name="fields[exclusive_sessions]" value='0' />
						<input type='checkbox' name="fields[exclusive_sessions]" value='1' class="iphoneStyle fieldsDebug" <?php echo (!isset($this->global['exclusive_sessions']) || (isset($this->global['exclusive_sessions']) && $this->global['exclusive_sessions']=='1')?' checked':'') ?>/>
						<small><?php print $this->translate('Enable clearing of current webmail session(s) when admin page is loaded.')?></small>
						<small style="color:#ff8888"><?php print $this->translate('Disabling this setting is a security risk and may expose your system to cross site exploits.')?></small>
					</td>
				</tr>

			</table>

			<div class='divider'/>
	
			<table class="settings">

				<tr>
					<td class="label"><?php print $this->translate('SQL Hostname')?></td>
					<td>
						<input type="text" class="medium" name="fields[sql_host]" id="sql_host" value="<?php echo $this->sql_host ?>" />
						<small><?php print $this->translate('Specify the hostname to the MySQL server. Seperate multiple servers with a comma. e.g. localhost,dbBackup1.lan')?></small>
					</td>
				</tr>

				<tr>
				<td class="label"><?php print $this->translate('SQL Username')?></td>
				<td>
					<input type="text" class="medium" name="fields[sql_user]" id="sql_user" value="<?php echo $this->sql_user ?>" />
					<small><?php print $this->translate('Specify the username to the MySQL server')?></small></td>
				</tr>

				<tr>
				<td class="label"><?php print $this->translate('SQL Password')?></td>
				<td>
					<input type="password" class="medium" name="fields[sql_pass]" id="sql_pass" value="<?php echo md5('__UNCHANGED__') ?>" />
					<small><?php print $this->translate('Optionally specify the password for the MySQL server. Leave blank if no password is defined')?></small></td>
				</tr>

				<tr>
				<td class="label"><?php print $this->translate('Database Name')?></td>
				<td>
					<input type="text" class="medium" name="fields[sql_table]" id="sql_table" value="<?php echo $this->sql_table ?>" />
					<small><?php print $this->translate('Specify the database used for Atmail. The table will be populated during the installer for the Atmail schema.')?></small></td>
				</tr>

			</table>

<?php if($this->global['install_type'] == 'server') : ?>
			<div class="divider"></div>

			<table class="settings">
				<tr>
					<td class="label"><label for="signature"><?php print $this->translate('Authentication Type')?></label></td>
					<td class="tdstyle">
						<div class="styled-select">
						        <span class="arrow"></span>
							<select name="dovecot[authType]" id="authType">
								<option value="sql" <?php echo ($this->dovecot['authType'] == 'sql') ? 'selected' : '' ?>>SQL (<?php echo $this->translate('Default, recommended') ?>)</option>
								<option value="ldap" <?php echo ($this->dovecot['authType'] == 'ldap') ? 'selected' : '' ?>>LDAP</option>
							</select>
							</div>
							<small><?php print $this->translate('Specify the authentication service used for POP3/IMAP/SMTP and Webmail logins. SQL recommended, if LDAP used, users must be managed via the LDAP server directly.') ?></small>
					</td>
				</tr>
			</table>
		
			<div id="ldapExpand" <?php echo ($this->dovecot['authType'] == 'ldap') ? '' : 'class="optionsHidden"' ?> >
				<div class="divider"></div>
				<table class="settings">
					<tr>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Type')?></label></td>
						<td class="tdstyle">
							<div class="styled-select">
							        <span class="arrow"></span>
							<select name="dovecot[ldapType]" id="ldapType">
								<option value="openldap" <?php echo ($this->dovecot['ldapType'] == 'openldap') ? 'selected' : '' ?>>OpenLDAP (<?php echo $this->translate('Default') ?>)</option>
								<option value="activedirectory" <?php echo ($this->dovecot['ldapType'] == 'activedirectory') ? 'selected' : '' ?>>Microsoft ActiveDirectory</option>
								<option value="other" <?php echo ($this->dovecot['ldapType'] == 'other') ? 'selected' : '' ?>><?php echo $this->translate('Other LDAP') ?></option>
							</select>
							</div>
							<small><?php print $this->translate('Specify the LDAP server type used') ?></small>
					
							<input type='hidden' name='dovecot[ldap_bindauth]' value='0' id='bindauth'/>
						</td>
					</tr>
		
					<tr>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Host')?></label></td>
					 	<td>
							<input type='text' name="dovecot[ldap_host]" id="ldap_host" value='<?php echo $this->dovecot['ldap_host'] ?>'>
							<small><?php print $this->translate('Specify the hostnames for the LDAP servers, separated by commas.')?></small>
						</td>
					</tr>

					<tr id='ldap_binddnTr'>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Bind DN')?></label></td>
						<td>
							<input type='text' name="dovecot[ldap_binddn]" id="ldap_binddn" value='<?php echo $this->dovecot['ldap_binddn'] ?>'>
							<small><?php print $this->translate('The Bind DN is used when you need to bind to the LDAP server. This is for setups where you need to fetch the password data to compare against.')?></small>
						</td>
					</tr>

					<tr id='ldap_bindpassTr'>
					<td class="label"><label for="signature"><?php print $this->translate('LDAP Bind Pass')?></label></td>
						<td>
							<input type='password' name="dovecot[ldap_bindpass]" id="ldap_bindpass" value='<?php echo $this->dovecot['ldap_bindpass'] ?>'>
							<small><?php print $this->translate('Use this field to specify the password used to bind against your LDAP Server.')?></small>
						</td>
					</tr>
				</table>
		
				<div class="divider"></div>

				<table class="settings">	
					<tr id='ldap_basednTr'>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Base DN')?></label></td>
						<td>
							<input type='text' name="dovecot[ldap_basedn]" id="ldap_basedn" value='<?php echo $this->dovecot['ldap_basedn'] ?>'>
							<small><?php print $this->translate('Specify the Base DN required by your LDAP Server.')?></small>
						</td>
					</tr>

					<tr id='ldap_passwdfieldTr'>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Password Field')?></label></td>
						<td>
							<input type='text' name="dovecot[ldap_passwdfield]" id="ldap_passwdfield" value='<?php echo $this->dovecot['ldap_passwdfield'] ?>'>
							<small><?php print $this->translate('You can define the LDAP attribute that stores the password data of your users.')?></small>
						</td>
					</tr>

					<tr id='ldap_passfilterTr'>
						<td class="label"><label for="signature"><?php print $this->translate('LDAP Password Filter')?></label></td>
						<td>
							<input type='text' name="dovecot[ldap_passfilter]" id="ldap_passfilter" value='<?php echo $this->dovecot['ldap_passfilter'] ?>'>
							<small><?php print $this->translate('You can define the LDAP filter to use when searching for passwords. This specifies what object class the users are under.')?></small>
						</td>
					</tr>

					<tr id='ldap_bindauthTr'>
						<td class="label"><label for="replyTo"><?php print $this->translate('Bind Authentication')?></label></td>
						<td>
							<input type="checkbox" value="1" name="dovecot[ldap_bindauth]" id="ldap_bindauth" <?php echo ($this->dovecot['ldap_bindauth']) ? 'checked' : '' ?> />
							<small><?php print $this->translate('Toggle to enable bind authentication. With this method, no lookups are needed. - Atmail will connect to the LDAP server via the username and password.')?></small>
						 </td>
					</tr>

					<tr id='ldap_bindauthdnTr'>
						<td class="label"><label for="signature"><?php print $this->translate('Bind Authentication DN')?></label></td>
						<td>
							<input type='text' name="dovecot[ldap_bindauthdn]" id="ldap_bindauthdn" value='<?php echo $this->dovecot['ldap_bindauthdn'] ?>'>
							<small><?php print $this->translate('This field specifies the DN format used for Bind Authentication.')?> <span id='ldap_bindauthdnExpand'></span></small>
						</td>
					</tr>
				</table>

			</div>
	
<?php endif ?>
			<div id="userPasswordEncryptionSqlSection" <?php echo ($this->dovecot['authType'] != 'ldap') ? '' : 'class="optionsHidden"' ?> >
			<div class="divider"></div>

				<table class="settings">
<?php if($this->global['install_type'] == 'server') : ?>
					<tr id='userPasswordEncryptionSql'>
						<td class="label"><label for="encryptionType"><?php print $this->translate('Authentication encryption')?></label></td>
						<td class="tdstyle">
							<input type="hidden" id="userPasswordEncryptionTypeCurrent" name ="userPasswordEncryptionTypeCurrent" value="<?php echo $this->global['userPasswordEncryptionType'] ?>" />
							<div class="styled-select">
							        <span class="arrow"></span>
							<select name="fields[userPasswordEncryptionType]" id="userPasswordEncryptionType">
								<?php
									
									$plain = 1;
									$md5 = 2;
									$md5crypt = 4;
									$encrypted = 8;
									$disabledoptions = 0;
									$selected = 0;
									if(!isset($this->global['userPasswordEncryptionType']))
									{
										$disabledoptions = 0;
										$selected = $plain;
									}
									else
									{
										switch($this->global['userPasswordEncryptionType'])
										{
											case Atmail_Enum::PASSWORD_PLAIN:
											{
												$selected = $plain;
											} break;
											case Atmail_Enum::PASSWORD_ENCRYPTED:
											{
												$selected = $encrypted;
												$disabledoptions = $md5 | $md5crypt;
											} break;
											case Atmail_Enum::PASSWORD_MD5:
											{
												$selected = $md5;
												$disabledoptions = $plain | $encrypted;
											} break;
											case Atmail_Enum::PASSWORD_MD5_CRYPT:
											{
												$selected = $md5crypt;
												$disabledoptions = $plain | $encrypted | $md5;
											} break;
										}
									}
									
									?>
										<option <?php if($disabledoptions & $plain) echo "disabled='disabled'" ?> value="<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>" <?php if($selected & $plain) echo "selected"; ?>>PLAIN (<?php echo $this->translate('Default') ?>)</option>
										<!-- <option <?php if($disabledoptions & $encrypted) echo "disabled='disabled'" ?> value="<?php echo Atmail_Enum::PASSWORD_ENCRYPTED; ?>" <?php if($selected & $encrypted) echo "selected"; ?>>ENCRYPTED</option> -->
										<option <?php if($disabledoptions & $md5) echo "disabled='disabled'" ?> value="<?php echo Atmail_Enum::PASSWORD_MD5; ?>" <?php if($selected & $md5) echo "selected"; ?>>MD5</option>
										<option <?php if($disabledoptions & $md5crypt) echo "disabled='disabled'" ?> value="<?php echo Atmail_Enum::PASSWORD_MD5_CRYPT; ?>" <?php if($selected & $md5crypt) echo "selected"; ?>>MD5-CRYPT</option>
							</select>
							</div>
							<small><?php print $this->translate('Specify the encryption type to use for internal user passwords in the database.')?></small>
						</td>
					</tr>
					<tr id='userPasswordEncryptionExternalRequirements' style='<?php if($this->haveMcrypt) echo "display:none"; ?>'>
						<td class="label"><label><?php print $this->translate('External user and session encryption')?></label></td>
						<td>
							<small><?php print $this->translate('Atmail allows you to specify the encryption type to use for session data and external user passwords in the database.')?></small>
							<small><?php print $this->translate('Encryption requires the mcrypt php library to be installed which has not been detected as installed.')?></small>
							<small><?php print $this->translate('This functionality will become available once the optional mcrypt dependancy has been installed.')?></small>
						</td>
					</tr>
<?php endif ?>
					<tr id='userPasswordEncryptionExternal' style='<?php if(!$this->haveMcrypt) echo "display:none"; ?>'>
						<td class="label"><label for="externalEncryptionType"><?php print $this->translate('External user authentication encryption')?></label></td>
						<td class="tdstyle">
							<input type="hidden" id="externalUserPasswordEncryptionTypeCurrent" name ="externalUserPasswordEncryptionTypeCurrent" value="<?php echo $this->global['externalUserPasswordEncryptionType'] ?>" />
							<div class="styled-select">
							        <span class="arrow"></span>
							<select name="fields[externalUserPasswordEncryptionType]" id="externalUserPasswordEncryptionType">
								<?php
									$plain = 1;
									$encrypted = 8;
									$selected = 0;
									if(!isset($this->global['externalUserPasswordEncryptionType']))
									{
										$selected = $plain;
									}
									else
									{
										switch($this->global['externalUserPasswordEncryptionType'])
										{
											case Atmail_Enum::PASSWORD_PLAIN:
											{
												$selected = $plain;
											} break;
											case Atmail_Enum::PASSWORD_ENCRYPTED:
											{
												$selected = $encrypted;
											} break;
										}
									}
									
									?>
										<option value="<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>" <?php if($selected & $plain) echo "selected"; ?>>PLAIN (<?php echo $this->translate('Default') ?>)</option>
										<option value="<?php echo Atmail_Enum::PASSWORD_ENCRYPTED; ?>" <?php if($selected & $encrypted) echo "selected"; ?>>ENCRYPTED</option>
							</select>
							</div>
							<small><?php print $this->translate('Specify the encryption type to use for external user passwords in the database. (Encrypted passwords will require mcrypt dependency installed)')?></small>
						</td>
					</tr>
					<tr id='userPasswordMasterKey' style='<?php if(!$this->haveMcrypt || $this->haveMasterKey) echo "display:none"; ?>'>
						<td class="label"><label for="encryptionType"><?php print $this->translate('Encryption Master Key')?></label></td>
						<td>
							<input type='text' name="fields[master_key]" id="master_key" value='' <?php if($this->hasMasterKey) { echo "disabled=disabled"; } ?>>
							<small><?php print $this->translate('The master key is used for external account password storage and user and admin session encryption.')?></small>
							<small><?php print $this->translate('Once set, Atmail will encrypt all session data.')?></small>
							<small><?php print $this->translate('Note: This key is VERY IMPORTANT and should have a SECURE BACKUP made. This field can only be set once.')?></small>
						</td>
					</tr>
				</table>
	
			</div>

			<div class="divider"></div>

			<table class="settings">	
				<tr>
					<td class="label"><label><?php print $this->translate('Log Data Retention')?></label></td>
					<td class="tdstyle">
					<?php if (!$this->cleanLogsScript): ?>
						<?php if (strlen($this->dailyCronDir)): ?>
						<div class="" style="color: red"><?php echo $this->translate("You need to copy <b>" . APP_ROOT . "utilities/tools/clean-logs.sh</b> into the <b>$this->dailyCronDir</b> directory and make sure it has execute permissions for the log pruning to work") ?></div>
						<?php else: ?>
						<div class="" style="color: red"><?php echo $this->translate("Could not determine your daily cron directory. You need to copy <b>" . APP_ROOT . "utilities/tools/clean-logs.php</b> into your daily cron directory or edit your crontab to run this file daily and make sure it has execute permissions for the log pruning to work") ?></div>
						<?php endif; ?>
					<?php endif; ?>
					<div class="styled-select">
					        <span class="arrow"></span>
						<select name="fields[log_purge_days]" id='log_purge_days'>
                            <option value="7"><?php echo $this->translate("1 week") ?></option>
                            <option value="30"><?php echo $this->translate("1 month") ?></option>
                            <option value="90"><?php echo $this->translate("3 months") ?></option>
                            <option value="180"><?php echo $this->translate("6 months") ?></option>
                            <option value="365"><?php echo $this->translate("1 year") ?></option>
                            <option value="730"><?php echo $this->translate("2 years") ?></option>
                            <option value="1095"><?php echo $this->translate("3 years") ?></option>
                            <option value="1460"><?php echo $this->translate("4 years") ?></option>
                            <option value="1825"><?php echo $this->translate("5 years") ?></option>
                            <option value="0"><?php echo $this->translate("forever") ?></option>
						</select>
					</div>
						<small><?php print $this->translate("How long Atmail will keep data in it's Log_* tables. This data is used to create the graphs on the Dashboard page. Note that keeping data for a long period of time may result in very large tables, which could consume considerable disk space and could impact performance.")?></small>
					</td>
				</tr>
			</table>
			
			<div class="divider"></div>

			<table class="settings">	
				<tr id='ldap_bindauthdnTr'>
					<td class="label"><label><?php print $this->translate('Enable Debug')?></label></td>
					<td>
						<input type='hidden' name="fields[debug]" value='0' />
						<input type='checkbox' name="fields[debug]" value='1' class="iphoneStyle fieldsDebug" <?php echo (isset($this->global['debug']) && $this->global['debug']=='1'?' checked':'') ?>/>
						<small><?php print $this->translate('Enable debug logging to: webmail/log/debug.log, and webmail/log/imap.log')?></small>
					</td>
				</tr>
			</table>
		</form>
		<div class="divider"></div>
		<div id="back_button">
			<a href="#">
				<span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
			</a>
		</div>
	</div>
</div>

<script type="text/javascript">
	function checknonzero(myfield)
	{
		if(parseInt(myfield.value) <= 0)
		{
			myfield.value = "120";
		}		
	}
	function checkinput(myfield, e, dec)
	{
		var key;
		var keychar;
		var returnval = false;
	
		if (window.event)
		{
			key = window.event.keyCode;
		}
		else if (e)
		{
			key = e.which;
		}
		else
		{
			return true;
		}
		
		keychar = String.fromCharCode(key);
	
		// control keys
		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		{
			return true;
		}
		// numbers
		else if ((("0123456789").indexOf(keychar) > -1))
		{
			return true;
		}
		// decimal point jump
		else if (dec && (keychar == "."))
		{
			myfield.form.elements[dec].focus();
			return false;
		}
		else
		{
			return false;
		}
	}

$( function()
{

	$('#ldap_bindauth', '#Global_Settings').iphoneStyle();
	$('.iphoneStyle', '#Global_Settings').iphoneStyle();
	
	$('.fieldsDebug', '#Global_Settings').bind('change', function() {  

		debugEnabled = $(this).attr('checked')

	})

	$('#back_button a', '#Global_Settings').bind("click", function() 
	{ 
		
		$("#Global_Settings #Flash").hide(); return $('#settingsForm', '#Global_Settings').submit()
		
	})
	<?php if(!$this->haveMcrypt) echo "disableItem($('#userPasswordEncryptionExternal'), false);" ?>
	$('#externalUserPasswordEncryptionType').change( function() {
		var newEncryptionType = $(this).attr('value');
		var encryptionType = $('#externalUserPasswordEncryptionTypeCurrent').attr('value');
	} );
	
	$('#userPasswordEncryptionType').change( function() {
		
		
		warningMessage1 = '<?php echo addslashes($this->translate("*** WARNING WARNING WARNING ***")) ?> \r\n <?php echo addslashes($this->translate("Changing user password encryption can not be undone without manually resetting them. All user passwords will become unusable until the server has been reset. Are you sure you want to change user password encryption?") ) ?>'

		var newEncryptionType = $(this).attr('value');
		var encryptionType = $('#userPasswordEncryptionTypeCurrent').attr('value');
		if(newEncryptionType != '<?php echo Atmail_Enum::PASSWORD_ENCRYPTED; ?>' && !confirm( (encryptionType == '<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>'?warningMessage1:warningMessage1) ) )
		{
				
			prevSelectedIndex = ( encryptionType=='<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>'?0:(encryptionType=='<?php echo Atmail_Enum::PASSWORD_MD5; ?>'?2:1))
			$(this).attr('selectedIndex', prevSelectedIndex);
				
		}
	})

	$('#log_purge_days option[value="<?php echo $this->global['log_purge_days'] ?>"]', '#Global_Settings').attr("selected", "selected");
	
	$("#authType", '#Global_Settings').change(function() 
	{

		if($(this).val() == 'ldap')
		{
			
			$("#ldapExpand").show();
			$('#userPasswordEncryptionSqlSection').hide();
			$('#master_key').hide();
			
		}
		else
		{
			
			$("#ldapExpand").hide();
			$('#userPasswordEncryptionSqlSection').show();
			$('#master_key').show();
			
		}

		$("#ldapType", '#Global_Settings').ldapType();
		
	});

	$("#ldapType", '#Global_Settings').change(function() 
	{

		$(this).ldapType();

	});

	$.fn.ldapType = function() 
	{
	
		if($(this).val() == 'openldap') 
		{
		
			$('#ldap_binddnTr', '#Global_Settings').hide();
			$('#ldap_bindpassTr', '#Global_Settings').hide();
			$('#ldap_passwdfieldTr', '#Global_Settings').hide();
			$('#ldap_passfilterTr', '#Global_Settings').hide();
			$('#ldap_bindauthTr', '#Global_Settings').hide();
			$('#bindauth', '#Global_Settings').attr('value', 1);
		
			// Show default values for OpenLDAP
			if(!$('#ldap_bindauthdn', '#Global_Settings').val() || $('#ldap_bindauthdn', '#Global_Settings').val() == '%u') 
			{

				$('#ldap_bindauthdn', '#Global_Settings').val('cn=%u,dc=domain,dc=org');

			}
		
			$('#ldap_bindauthdnExpand', '#Global_Settings').html("<?php echo $this->translate('Default for OpenLDAP is cn=%u,dc=domain,dc=org') ?>");
		
		} 
		else if($(this).val() == 'activedirectory') 
		{

			$('#ldap_binddnTr', '#Global_Settings').hide();
			$('#ldap_bindpassTr', '#Global_Settings').hide();
			$('#ldap_passwdfieldTr', '#Global_Settings').hide();
			$('#ldap_passfilterTr', '#Global_Settings').hide();
			$('#ldap_bindauthTr', '#Global_Settings').hide();
			$('#bindauth', '#Global_Settings').attr('value', 1);
		
			// Show default values for ActiveDirectory
			if(!$('#ldap_bindauthdn', '#Global_Settings').val() || $('#ldap_bindauthdn', '#Global_Settings').val() == 'cn=%u,dc=domain,dc=org') 
			{

				$('#ldap_bindauthdn', '#Global_Settings').val('%u');

			}
		
			$('#ldap_bindauthdnExpand', '#Global_Settings').html("<?php echo $this->translate('Default for ActiveDirectory is %u.') ?>");		
		
		} 
		else 
		{

			$('#ldap_binddnTr', '#Global_Settings').show();
			$('#ldap_bindpassTr', '#Global_Settings').show();
			$('#ldap_passwdfieldTr', '#Global_Settings').show();
			$('#ldap_passfilterTr', '#Global_Settings').show();
			$('#ldap_bindauthTr', '#Global_Settings').show();
			$('#bindauth', '#Global_Settings').attr('value', 0);
			$('#ldap_bindauthdnExpand', '#Global_Settings').html("<?php echo $this->translate('Use %u in the BindDN to evaluate the users email, or %n for the username only.') ?>");
		
		}
	
	}

	// bind to the form's submit event and cancel legacy submit 
	$('#settingsForm', '#Global_Settings').submit(function() 
	{	
		switch($('#userPasswordEncryptionType').attr('value'))
		{
			case '<?php echo Atmail_Enum::PASSWORD_ENCRYPTED; ?>' :
			{
				// nothing to do, internal passwords cannot be encrypted until
				// dovecot pam module is completed
			} break;
			case '<?php echo Atmail_Enum::PASSWORD_MD5; ?>' :
			{
				// disable plaintext, its no longer available
				$('option[value="<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>"]', '#userPasswordEncryptionType').attr('disabled', 'disabled');
			} break;
			case '<?php echo Atmail_Enum::PASSWORD_MD5_CRYPT; ?>' :
			{
				// md5-crypt will disable plain and md5, as the md5-crypt function is still a one way algorithm
				$('option[value="<?php echo Atmail_Enum::PASSWORD_PLAIN; ?>"]', '#userPasswordEncryptionType').attr('disabled', 'disabled');
				$('option[value="<?php echo Atmail_Enum::PASSWORD_MD5; ?>"]', '#userPasswordEncryptionType').attr('disabled', 'disabled');
			} break;
		}
	 	$.php($("#settingsForm", '#Global_Settings').attr("action"),$("#settingsForm", '#Global_Settings').serializeArray());
		return false; 

	})

	$("#ldapType", '#Global_Settings').ldapType();

	$('.stronglastword').each( function() { $(this).stronglastword() });
	
});
</script>
