<div id="primary_header">
	<h1><?php echo $this->translate('Email Settings')?></h1>
	<!--
	<div id="back_button">
		<a href="#" tabindex="0">
			<span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span>
		</a>
	</div>
  -->
</div>

<div id="primary_content">
	<div id="primary_content_inner">
		<div aria-live="polite" id="Flash" class="flash_notice" tabindex="0"><?php echo $this->translate('The settings have been updated') ?></div>
		<form id="settingsForm" method="post" action="<?php echo $this->moduleBaseUrl ?>/settings/webmailsave">
			<input type="hidden" name="save" value="1" />
			<table class="settings">
				<tr id="accountNameRow">
					<td class="label"><label for="AccountName"><?php echo $this->translate('Account Name')?></label></td>
					<td>
						<input type="text" tabindex="0" class="medium" value="<?php echo html_entity_decode($this->UserSettings['Account'], ENT_COMPAT, "utf-8"); ?>" name="fields[AccountName]" id="AccountName" />
						<small><?php echo $this->translate('The name that will appear on outgoing emails.')?></small>
					</td>
				</tr>

				<tr id="currentQuota">
					<td class="label"><?php echo $this->translate('Quota')?></td>
					<td tabindex="0" title="Account quota"><div class="quota">
						<div id="quota_bar"></div>
					</div>
					<div id="quotaMessage" class="quota_message"><li title="Account Quota" tabindex="0"><?php echo ((isset($this->quotaMessage) && $this->quotaMessage != '') ? $this->quotaMessage : "<img src='" . $this->siteBaseUrl . "/images/25.gif' style='width: 16px; height: 16px; padding: 2px; top:4px;position:relative;'>" . $this->translate('Calculating...')); ?></li></ul></td>	
				</tr>

				<tr id="realNameRow">
					<td class="label"><label for="RealName"><?php echo $this->translate('Real Name')?></label></td>
					<td>
						<input type="text" tabindex="0" class="medium" value="<?php echo html_entity_decode($this->UserSettings['RealName'], ENT_COMPAT, "utf-8"); ?>" name="fields[RealName]" id="RealName" />
						<small><?php echo $this->translate('The name that will appear on outgoing emails.')?></small>
					</td>
				</tr>

				<tr id="replyToRow">
					<td class="label"><label for="ReplyTo"><?php echo $this->translate('Reply To')?></label></td>
					<td>
						<input type="text" tabindex="0" class="medium" value="<?php echo $this->UserSettings['ReplyTo'] ?>" name="fields[ReplyTo]" id="ReplyTo" />
						<small><?php echo $this->translate('A Reply To field allows you to specify a different reply email address to your normal login.<br>Responses to your emails sent with a Reply To address defined will be delivered to that address.')?></small>
					</td>
				</tr>
			</table>
<!--
			<div class='divider threads'></div>
			<table class='settings threads'>
				<tr id="viewThreadsRow">
					<td class="label"><label for="ViewThreads"><?php echo $this->translate('Thread Support')?></label></td>
					<td>
						<input type="hidden" value="0" name="fields[ViewThreads]"/>
						<input tabindex="0" type="checkbox" value="1" name="fields[ViewThreads]" id="ViewThreads" <?php echo ($this->UserSettings['ViewThreads']) ? 'checked' : '' ?> />
						<small><?php echo $this->translate('Toggle to display email messages as threads, if supported by server.')?></small>
					</td>
				</tr>
				<tr id="threadLimitRow">
					<td class="label"><label id="ThreadLimitLabel" for="ThreadLimit"><?php echo $this->translate('Thread Limit')?></label></td>
					<td>
						<select name="fields[ThreadLimit]" id='ThreadLimit' tabindex="0" >
							<option value="3"><?php echo $this->translate('3 Months') ?></option>
							<option value="6"><?php echo $this->translate('6 Months') ?></option>
							<option value="12"><?php echo $this->translate('1 Year') ?></option>
							<option value="24"><?php echo $this->translate('2 Years') ?></option>
							<option value="0"><?php echo $this->translate('Infinite') ?></option>
						</select>
						<small><?php echo $this->translate('Determines how old emails can be before they are not included in threads.')?></small>
					</td>
				</tr>
				<tr id="threadCopyToCurrentFolder">
					<td class="label"><label id="copyThreadReplyToCurrentFolderLabel" for="copyThreadReplyToCurrentFolder"><?php echo $this->translate('Save sent emails to current folder')?></label></td>
					<td>
						<input type="hidden" value="0" name="fields[copyThreadReplyToCurrentFolder]"/>
						<input tabindex="0" type="checkbox" value="1" name="fields[copyThreadReplyToCurrentFolder]" id="copyThreadReplyToCurrentFolder" <?php echo ($this->UserSettings['copyThreadReplyToCurrentFolder']) ? 'checked' : '' ?> />
						<small><?php echo $this->translate('Enable to save sent emails to the current folder. This allows more complete thread building and tracking.')?></small>
					</td>
				</tr>
			</table>
-->
			<div class='divider' <?php if(!$this->global['themeEnabled']) echo "style='display:none'"; ?> ></div>
			<table class="settings" <?php if(!$this->global['themeEnabled']) echo "style='display:none'"; ?>>
				<tbody>
					<tr>
						<td class="label"><label for="cssStyleTheme"><?php echo $this->translate('Change Theme')?></label></td>
						<td>
							<select id="cssStyleTheme" name="fields[cssStyleTheme]" tabindex="0" >
<!--
<?php 	foreach( $this->availableThemes as $theme ) : ?> 
								<option value="<?php echo $theme['folder'] ?>"<?php if($this->UserSettings['cssStyleTheme']==$theme['folder']) echo ' selected'?>><?php echo $theme['name'] ?></option>
<?php 	endforeach ?>
-->
								<option value="fresh" selected="">fresh</option>

							</select>
							<input type="hidden" name="cssStyleThemePrev" value="<?php echo $this->UserSettings['cssStyleTheme'] ?>" />
							<small><?php echo $this->translate('Specify which theme to use for the Webmail interface.') ?></small>
						</td>
					</tr>


					<tr>
						<td class="label"><?php echo $this->translate('Theme Example') ?></td>
						<td>
							<img alt="screenshot example of selected style" id="cssStyleThemeScreenshot" width="201" height="152" src='<?php echo $this->siteBaseUrl .$this->availableThemes[$this->UserSettings['cssStyleTheme']]['screenshot'] ?>' />
						</td>
					</tr>
				</tbody>
			</table>

			<div class='divider'></div>
			<table class='settings'>
				<tr id="displayEmailImagesRow">
					<td class="label"><label for="DisplayEmailImages"><?php echo $this->translate('Display Email Images')?></label></td>
					<td>
						<input type="hidden" value="0" name="fields[DisplayEmailImages]"/>
						<input tabindex="0" type="checkbox" value="1" name="fields[DisplayEmailImages]" id="DisplayEmailImages" <?php echo ($this->UserSettings['DisplayEmailImages']=='1' ? 'checked' : '') ?> />
						<small><?php echo $this->translate('Toggle to automatically display external images in email messages.')?></small>
					</td>
				</tr>
			</table>	
			<table class="settings">
				<tr id="saveDraftsRow">
					<td class="label"><label for="SaveDrafts"><?php echo $this->translate('Automatic Draft Save')?></label></td>
					<td>
						<input type="hidden" name="fields[SaveDrafts]" value="0">
						<input tabindex="0" type="checkbox" name="fields[SaveDrafts]" id="SaveDrafts" value="1" <?php echo $this->UserSettings['SaveDrafts']=='1'?' checked':'' ?> />
						<small><?php echo $this->translate('Save drafts automatically while composing email messages.')?></small>
					</td>
				</tr>
			</table>
			<table class="settings">
				<?php
					$enabled = ($this->UserSettings['AutoReload'] != 0);
					$audioNotify = ($this->UserSettings['AutoReload'] & Atmail_Enum::AUTORELOAD_AUDIO);
					$faviconNotify = ($this->UserSettings['AutoReload'] & Atmail_Enum::AUTORELOAD_FAVICON);
				?>

				<tr id="autoReloadRow">
					<td class="label"><?php echo $this->translate('Notifications')?></td>
					<td>
						<table class="settings" style="width: 300px; margin: 0;">
							<td>
								<input type="hidden" value="0" name="fields[AutoReload]" id="AutoReload"/>
								<label for="AutoReload_Bitfield_Enabled"><?php echo $this->translate('Enabled')?></label>
								<input tabindex="0" type="checkbox" value="<?php echo Atmail_Enum::AUTORELOAD_ENABLED; ?>" name="fields[AutoReload_Bitfield]" bf="Enabled" id="AutoReload_Bitfield_Enabled" <?php echo ($enabled ? 'checked' : '') ?> />
							</td>
							<!--
							<td>
							<label for="AutoReload_Bitfield_Audio"><?php echo $this->translate('Audio')?></label>
								<input tabindex="0" type="checkbox" value="<?php echo Atmail_Enum::AUTORELOAD_AUDIO; ?>" name="fields[AutoReload_Bitfield]" bf="Audio" id="AutoReload_Bitfield_Audio" <?php echo ($audioNotify ? 'checked' : '') ?> />
							</td>
							-->
							<!--
							<td id="faviconSetting">
								<label for="AutoReload_Bitfield_Favicon"><?php echo $this->translate('Favicon')?></label>
								<input tabindex="0" type="checkbox" value="<?php echo Atmail_Enum::AUTORELOAD_FAVICON; ?>" name="fields[AutoReload_Bitfield]" bf="Favicon" id="AutoReload_Bitfield_Favicon" <?php echo ($faviconNotify ? 'checked' : '') ?> />
							</td>
							-->
							</tr>
						</table>
						<small><?php echo $this->translate('Enable automatic checking for new email in the currently selected folder. Optionally enable sound notification <!-- and/or animated favicon for new messages--> on supported browsers.')?></small>
					</td>
				</tr>
			</table>
			<!--
			<table class="settings">
				<tr id="deleteTrashOnLogoutRow">
					<td class="label"><label for="DeleteTrashOnLogout"><?php echo $this->translate('Delete Trash on Logout')?></label></td>
					<td>
						<input type="hidden" name="fields[DeleteTrashOnLogout]" value="0">
						<input tabindex="0" type="checkbox" name="fields[DeleteTrashOnLogout]" id="DeleteTrashOnLogout" value="1" <?php echo $this->UserSettings['DeleteTrashOnLogout']=='1'?' checked':'' ?> />
						<small><?php echo $this->translate('Automatically delete all mail from the Trash folder upon logout.')?></small>
					</td>
				</tr>
			</table>			
			-->
			<?php if ($this->global['enableConfirmOnSend'] == 1): ?>
			<table class="settings">
				<tr id="confirmOnSend">
					<td class="label"><label for="confirmOnSend"><?php echo $this->translate('Confirm on Send Email')?></label></td>
					<td>
						<input type="hidden" name="fields[confirmOnSend]" value="0">
						<input tabindex="0" type="checkbox" name="fields[confirmOnSend]" id="confirmOnSend" value="1" <?php echo $this->UserSettings['confirmOnSend']=='1'?' checked':'' ?> />
						<small><?php echo $this->translate('Show confirm before sending email.')?></small>
					</td>
				</tr>
			</table>
			<?php endif; ?>

		<div class='divider'></div>
			<table class='settings'>
				<tr id="defaultViewRow">
					<td class="label"><label for="View"><?php echo $this->translate('Default View')?></label></td>
					<td>
						<select name="fields[DefaultView]" id='View' tabindex="0" >
							<option value="2p">2 Pane</option>
							<option value="3p">3 Pane</option>
						</select>
						<input type='hidden' name='ViewPrev' value="<?php echo $this->UserSettings['DefaultView'] ?>"/>
						<small><?php echo $this->translate('Select the mode to render the Webmail interface.')?></small>
					</td>
				</tr>
				<tr id="enableMessagePreviewRow">
					<td class="label"><label for="enableMessagePreview"><?php echo $this->translate('Enable message preview')?></label></td>
					<td>
						<input type="hidden" name="fields[enableMessagePreview]" value="0">
						<input tabindex="0" type="checkbox" name="fields[enableMessagePreview]" id="enableMessagePreview" value="1" <?php echo $this->UserSettings['enableMessagePreview']=='1'?' checked':'' ?> />
						<small><?php echo $this->translate('Display an inline preview of each email message.')?></small>
					</td>
				</tr>
				<tr id="enableExtraAddressFieldsRow">
					<td class="label"><label for="enableExtraAddressFields"><?php echo $this->translate('Enable extra address fields')?></label></td>
					<td>
						<input type="hidden" name="fields[enableExtraAddressFields]" value="0">
						<input tabindex="0" type="checkbox" name="fields[enableExtraAddressFields]" id="enableExtraAddressFields" value="1" <?php echo $this->UserSettings['enableExtraAddressFields']=='1'?' checked':'' ?> />
						<small><?php echo $this->translate('Show cc and bcc fields by default.')?></small>
					</td>
				</tr>
				<tr id="languageRow">
					<td class="label"><label for="Language"><?php echo $this->translate('Interface Language')?></label></td>
					<td>
						<select name="fields[Language]" id='Language' tabindex="0" >
							<?php foreach( $this->availableLocales as $k => $v ) : ?>
							<option value="<?php echo $k ?>"<?php echo ($this->localeString==$k?' selected':'') ?>><?php echo $v ?></option>
							<?php endforeach ?>
						</select>

						<input type='hidden' name='LanguagePrev' value="<?php echo $this->UserSettings['Language'] ?>"/>
						<small><?php echo $this->translate('Select the Language to render the Webmail interface.')?></small>
					</td>
				</tr>
				<tr id="dateDisplayRow">
					<td class="label"><label for="DateDisplay"><?php echo $this->translate('Date display')?></label></td>
					<td>
						<select name="fields[DateDisplay]" id='DateDisplay' tabindex="0" >
							<option value="1"><?php echo $this->translate('Time Since Delivery') ?></option>
							<option value="2">DD/MM/YY</option>
							<option value="3">MM/DD/YY</option>
						</select>
						<small><?php echo $this->translate('Select the display format for date received.')?></small>
					</td>
				</tr>
				<tr id="msgNumRow">
					<td class="label"><label for="MsgNum"><?php echo $this->translate('Messages per page')?></label></td>
					<td>
						<select name="fields[MsgNum]" id='MsgNum'tabindex="0" >
							<option value="10"><?php echo $this->translate('10')?></option>
							<option value="25"><?php echo $this->translate('25')?></option>
							<option value="50"><?php echo $this->translate('50')?></option>
							<option value="100"><?php echo $this->translate('100')?></option>
							<option value="200"><?php echo $this->translate('200')?></option>
						</select>
						<small><?php echo $this->translate('Select the number of email messages to display per page.')?></small>
					</td>
				</tr>
				<tr id="timezoneRow">
					<td class="label"><label for="TimeZoneSetting"><?php echo $this->translate('Timezone')?></label></td>
					<td>
						<select name="fields[TimeZone]" id='TimeZoneSetting'tabindex="0" >
							<option value=""><?php echo $this->translate('Please Select') ?></option>
							<?php echo $this->timezoneList; ?>
						</select>
						<small><?php echo $this->translate('Specify your timezone for date calculation in the Web-interface.')?></small>
					</td>
				</tr>
			</table>
			<div class="divider"></div>
			<table class="settings">
				<tr id="signatureRow">
					<td class="label"><label for="Signature"><?php echo $this->translate('Signature')?></label></td>
					<td>
						<div class='reply'>
							<textarea name="fields[Signature]" tabindex="0" id="Signature" class='rte-zone'><?php echo htmlspecialchars($this->UserSettings['Signature']); ?></textarea>
						</div>
						<small><?php echo $this->translate('Your signature will be added to the end of every new email.')?></small>
					</td>
				</tr>
			</table>
			<div class="bottomFormMainButtonArea" style="display:none;">
				<div id="back_button"><a href="#" tabindex="0" id="backBtnAnchor"><span class="stronglastword"><?php echo $this->translate('Save Settings') ?></span></a></div>
			</div>
			<br />
			<br />
			<br />
		</div>
	</form>
<!--	<div id='confirm-dialog'>
		<input type='button' name='confirm' class='confirm' value='Test'/>
	</div>
	<div id='confirm'>
		<div class='header'><span>Confirm</span></div>
		<div class='message'></div>
		<div class='buttons'>
			<div class='no simplemodal-close'>No</div><div class='yes'>Yes</div>
		</div>
	</div>-->
</div>

<script type="text/javascript">
	function updateWebmailSettings() {
		$("#TimeZoneSetting option", '#global').removeAttr('selected');
		$("#TimeZoneSetting option[value=<?php echo $this->UserSettings['TimeZone'] ?>]", '#global').attr('selected', 'true');

		$("#MsgNum option", '#global').removeAttr('selected');
		$("#MsgNum option[value=<?php echo $this->UserSettings['MsgNum'] ?>]", '#global').attr('selected', 'true');

		$("#Language option", '#global').removeAttr('selected');
		$("#Language option[value=<?php echo $this->UserSettings['Language'] ?>]", '#global').attr('selected', 'true');

		$("#View option", '#global').removeAttr('selected');
		$("#View option[value=<?php echo $this->UserSettings['DefaultView'] ?>]", '#global').attr('selected', 'true');

		$("#DateDisplay option", '#global').removeAttr('selected');
		$("#DateDisplay option[value=<?php echo $this->UserSettings['DateDisplay'] ?>]", '#global').attr('selected', 'true');

		$("#ThreadLimit option", '#global').removeAttr('selected');
		$("#ThreadLimit option[value=<?php echo $this->UserSettings['ThreadLimit'] ?>]", '#global').attr('selected', 'true');
	}

	function toggleThreads()
	{
		if($("#ViewThreads", "#global").attr('checked') == true)
		{
			$("#ThreadLimitLabel", "#global").fadeTo("slow", 1);
			$("#ThreadLimit", "#global").removeAttr("disabled");
			$("#copyThreadReplyToCurrentFolderLabel", "#global").fadeTo("slow", 1);
			$("#copyThreadReplyToCurrentFolder", "#global").removeAttr("disabled");
		}
		else
			{
			$("#ThreadLimitLabel", "#global").fadeTo("fast", 0.5);
			$("#ThreadLimit", "#global").attr("disabled","disabled");
			$("#copyThreadReplyToCurrentFolderLabel", "#global").fadeTo("fast", 0.5);
			$("#copyThreadReplyToCurrentFolder", "#global").attr("disabled","disabled");
		}

	}

	
	$(function()
	{

		$("#quota_bar").progressbar({
			value: 0,
			disabled: true
		});
		$.php('<?php echo $this->moduleBaseUrl ?>/settings/updateQuota');
		
		// Create the HTML editor for the signature
		$('.rte-zone', '#global').rte({ focus_after_element:$("#back_button a:first-child"), content_css_url: '<?php echo $this->siteBaseUrl ?>css/webmail.css', media_url: '<?php echo $this->siteBaseUrl ?>images/rte-light/' });
        
		$("#cssStyleTheme").change(function()
		{
			$("#cssStyleThemeScreenshot").attr('src', '<?php echo $this->siteBaseUrl ?>images/themes/' + $(this).attr('value') + '.png');
		});
		
		$('[name="fields[AutoReload_Bitfield]"]', '#global').bind('change', function(){
			var value = $('#AutoReload', '#global').attr('value');
      // console.log(value);

			if($(this).attr('checked'))
			{
				value = value | $(this).attr('value');
			}
			else
			{
				if($(this).attr('value') == <?php echo Atmail_Enum::AUTORELOAD_ENABLED; ?>)
				{
					// enable behaviour
					value = 0;
				}
				if(value & $(this).attr('value'))
				{
					value = value ^ $(this).attr('value');
				}
			}


			enabled = (value != 0);
			audioNotify = (value & <?php echo Atmail_Enum::AUTORELOAD_AUDIO; ?>);
			faviconNotify = (value & <?php echo Atmail_Enum::AUTORELOAD_FAVICON; ?>);

			if(!enabled)
			{
				$('[name="fields[AutoReload_Bitfield]"][bf="Audio"]', '#global').disable(true).parent().addClass('iPhoneCheckDisabled');
				$('[name="fields[AutoReload_Bitfield]"][bf="Favicon"]', '#global').disable(true).parent().addClass('iPhoneCheckDisabled');
			}
			else
			{
				$('[name="fields[AutoReload_Bitfield]"][bf="Audio"]', '#global').enable(false).parent().removeClass('iPhoneCheckDisabled');
				$('[name="fields[AutoReload_Bitfield]"][bf="Favicon"]', '#global').enable(false).parent().removeClass('iPhoneCheckDisabled');
			}

			$('#AutoReload', '#global').attr('value', value);
		});

		// bind to the form's submit event and cancel legacy submit
		$('#settingsForm', '#global').submit(function()
		{
			$("#Flash", "#global").hide();

			// Grab the HTML content, put into the textarea to save

			$('.rte-zone', '#global').contents().find('SCRIPT').remove();
			var html = $('.rte-zone', '#global').rte_html();
			$("#Signature", "#global").attr('value', html);

			$.php($("#settingsForm", '#global').attr("action"),$("#settingsForm", '#global').serializeArray());
			return false;
		});
		$('#back_button a', '#global').bind("click", function() { return $('#settingsForm', '#global').submit()});

		$("#ViewThreads", "#global").change( function() { toggleThreads() });

		updateWebmailSettings();
		toggleThreads();

		try{
			$('#Settings :checkbox').iphoneStyle();
		  $('faviconSetting').disable();
		}
		catch(e) {
		}

		if($.browser.msie && $.browser.version < 9)
		{
			$('#faviconSetting').disable();
			$('#faviconSetting input').attr('checked','').disable();
			$('#autoReloadRow small').append("<?php echo $this->translate(' This feature not fully supported by your current browser.') ?>");
		}

		$('[name=AutoReload_Bitfield]', '#global').trigger('change');

		$('.stronglastword').each( function() { $(this).stronglastword() });

	});
    
	
	
setFocusableElements();
setSettingsContextTabOrder();
$('#skip-link').focus();	
</script>
