{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
{$hide_disabled_users = ConfigHelper::checkConfig('rt.hide_disabled_users', ConfigHelper::checkConfig('phpui.helpdesk_hide_disabled_users'))}
<!--// $Id$ //-->

<style>

	.lms-ui-box,
	.lms-ui-box-nested-box {
		border: 1px dotted black;
		border-radius: 5px;
		background-color: #DFD5BD;
	}

	.lms-ui-box-header {
		padding-top: 0.7em;
		padding-bottom: 0.3em;
	}

	.lms-ui-box-footer {
		padding-top: 0.3em;
		padding-bottom: 0.7em;
	}

	.lms-ui-box-header {
		border-bottom: 1px solid black;
		border-top-left-radius: 4px;
		border-top-right-radius: 4px;
		background-color: #CEBD9B;

		display: flex;
		flex-grow: 1;
	}

	.lms-ui-box-footer {
		background-color: #CEBD9B;
		border-top: 1px dotted black;
	}

	.lms-ui-box-body {
		display: flex;
		flex-grow: 1;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.lms-ui-flex-row {
		display: flex;
		flex-direction: row;
	}

	.lms-ui-flex-column {
		display: flex;
		flex-direction: column;
	}

	.lms-ui-box-panel {
		padding: 1em;
		padding-top: 0;
		padding-bottom: 0;
		display: flex;
		flex-direction: column;
		width: fit-content;
	}

	.lms-ui-box-panel:first-child {
		padding-left: 0.5em;
	}

	.lms-ui-box-panel:last-child {
		padding-right: 1em;
	}

	.lms-ui-box-left-panel {
		flex-grow: 2;
	}

	.lms-ui-box-right-panel {
		flex-wrap: nowrap;
		flex-grow: 3;
	}

	.lms-ui-box-right-panel .lms-ui-box-row fieldset {
		display: flex;
		margin-bottom: 1em;
		margin-top: 0.7em;
		flex-grow: 1;
	}

	.lms-ui-box-panel > .lms-ui-box-row {
		flex-grow: 0;
	}

	.lms-ui-box-row {
		display: flex;
		justify-content: stretch;
		flex-grow: 1;
	}

	.lms-ui-box-field {
		padding: 0.5em 0.7em 0.5em 0.7em;
	}

	.lms-ui-box-field {
		display: flex;
	}

	.lms-ui-box-body .lms-ui-box-field {
		padding-top: 0.3em;
		padding-bottom: 0.3em;
	}

	.lms-ui-background-cycle .lms-ui-box-body .lms-ui-box-row:not(:last-child) {
		border-bottom: 1px dotted grey;
	}

	.lms-ui-background-cycle .lms-ui-box-body .lms-ui-box-row:nth-child(even) {
		background-color: #EBE4D6;
	}

	.lms-ui-background-cycle .lms-ui-box-body .lms-ui-box-row:nth-child(even).highlight:hover {
		background-color: #CFC;
	}

	.lms-ui-background-cycle .lms-ui-box-body .lms-ui-box-row:nth-child(odd) {
		background-color: #DFD5BD;
	}

	.lms-ui-background-cycle .lms-ui-box-body .lms-ui-box-row:nth-child(odd).highlight:hover {
		background-color: #CFC;
	}

	.lms-ui-box-field-label {
		padding-top: 0.5em;
		padding-bottom: 0.5em;
		display: flex;
		width: fit-content;
		cursor: pointer;
	}

	.lms-ui-box-field-label > *:not(:last-child) {
		margin-right: 0.2em;
	}

	.lms-ui-box-field,
	.lms-ui-box-field input[type="text"]:not(.chosen-search-input),
	.lms-ui-box-field input[type="email"] {
		width: 100%;
		min-width: 15em;
		/*max-width: 50em;*/
	}

	.lms-ui-box-field {
		flex-direction: column;
	}

	.lms-ui-box-field.single-line {
		flex-direction: row;
	}

	.lms-ui-box-field.single-line > *:not(:first-child) {
		margin-left: 0.5em;
	}

	.lms-ui-box-nested-box .lms-ui-box-header {
		border-bottom: 1px dotted black;
	}

	.lms-ui-box-nested-box .lms-ui-box-row {
		width: 100%;
	}

	.lms-ui-box-nested-box .lms-ui-box-field {
		min-width: unset;
	}

	.lms-ui-box-field textarea {
		width: 100%;
		min-width: 20em;
		/*max-width: 50em;*/
	}

	.lms-ui-box-buttons {
		background-image: linear-gradient(to right, black 33%, rgba(255,255,255,0) 0%);
		background-position: left 0.5em;
		background-size: 3px 1px;
		background-repeat: repeat-x;
		padding: 1em 0.5em 0.5em 0.5em;
	}

	.lms-ui-box-buttons > *:not(:first-child) {
		margin-left: 0.3em;
	}

	#verifier-notifications {
		margin: 0.3em;
	}

	#notification-tabs {
		width: 100%;
	}

	#notification-tabs input[type="text"] {
		min-width: 20em;
	}

	#notification-tabs textarea {
		min-width: 20em;
	}

	#verifier-notifications {
		width: 100%;
		border: 1px dotted grey;
		padding: 1em 1.4em;
	}

	#verifier-notifications input[type="text"] {
		min-width: 20em;
	}

	#verifier-notifications textarea {
		min-width: 20em;
	}

	.lms-ui-box-header .lms-ui-box-field.permission {
		writing-mode: vertical-rl;
		transform: rotate(0deg);
		white-space: nowrap;
		display: inline-block;
		overflow: visible;
	}

	.lms-ui-box-body .username {
		align-self: flex-end;
		align-items: flex-start;
	}

	.lms-ui-box-body .lms-ui-box-footer .username {
		align-self: center;
	}

	.lms-ui-box-footer .lms-ui-box-row .username {
	}

	.lms-ui-box-body .permission {
		align-self: center;
		align-items: flex-end;
		flex-grow: 1;
	}

	.lms-ui-box-header .permission {
		align-self: flex-end;
	}

	.lms-ui-box-footer .username {
		align-items: flex-end;
	}

	.username {
		flex-basis: 100vw;
	}

	#queue-name {
		max-width: 30em;
	}

	.user-login {
		transform: scale(0.8);
		transform-origin: left;
	}

	.permission {
		width: 1em;
		min-width: 2em !important;
	}


</style>

<H1>{$layout.pagetitle}</H1>

<form method="post" name="queue" id="queue-form"
	action="?m={$layout.module}{if isset($queue.id)}&id={$queue.id}{/if}">
</form>

<div class="lms-ui-box">
	<div class="lms-ui-box-header">
		<div class="lms-ui-box-row">
			<div class="lms-ui-box-field single-line">
				<label for="queue-name">
					{icon name="queue"}
					<strong>{trans("Name")}</strong>
				</label>
				<input type="text" name="queue[name]" value="{$queue.name}"
					id="queue-name" form="queue-form"
					{tip text="Enter queue name" trigger="name" bold=1}>
				{if isset($queue.id)}
					<strong>({$queue.id|string_format:"%04d"})</strong>
				{/if}
			</div>
		</div>
	</div>
	<div class="lms-ui-box-body lms-ui-flex-row">
		<div class="lms-ui-box-panel lms-ui-box-left-panel">
			<div class="lms-ui-box-row">
				<div class="lms-ui-box-field">
					<div class="lms-ui-box-field-label">
						{icon name="mail"}
						<strong>{trans("E-mail")}</strong>
					</div>
					<input type="email" name="queue[email]" form="queue-form"
						value="{$queue.email}" class="lms-ui-box-field-value"
						{tip text="Enter e-mail address" trigger="email"}>
				</div>
			</div>
			<div class="lms-ui-box-row">
				<div class="lms-ui-box-field">
					<div class="lms-ui-box-field-label">
						{icon name="description"}
						<strong>{trans("Description")}</strong>
					</div>
					<textarea name="queue[description]" rows="1" id="queue-description" form="queue-form"
						class="lms-ui-autogrow lms-ui-box-field-value"
						{tip text="Enter additional information (optional)"}>{$queue.description}</textarea>
				</div>
			</div>
			<div class="lms-ui-box-row">
				<div class="lms-ui-box-field">
					<div class="lms-ui-box-field-label">
						{icon name="verifier"}
						<strong>{trans("<!rt>Verifier")}</strong>
					</div>
					<select size="1" id="queue-verifierid" form="queue-form" class="lms-ui-box-field-value"
							name="queue[verifierid]" {tip text="Select user" trigger="verifierid"}>
						<option value="">{trans("— select user —")}</option>
						{foreach $userlist as $user}
							<option value="{$user.id}" {if $user.id == $queue.verifierid} selected{/if}>{$user.rname|escape}
								({$user.login})
							</option>
						{/foreach}
					</select>
				</div>
			</div>
			<div class="lms-ui-box-row">
				<div class="lms-ui-box-field">
					<label class="lms-ui-box-field-label">
						{icon name="queue"}
						<strong>{trans("Default categories")}</strong>
						<input type="checkbox" id="checkall">
					</label>
					<div class="lms-ui-box-field-value">
						{include file="rt/rtcategoryselection.html" id="categories" name_prefix="queue[categories]"
							categories=$categories form="queue-form"}
					</div>
				</div>
			</div>
			{if !empty($configsections)}
				<div class="lms-ui-box-row">
					<div class="lms-ui-box-field">
						<div class="lms-ui-box-field-label">
							{icon name="configuration"}
							<strong>{trans("<!rt>Configuration section")}</strong>
						</div>
						<select size="1" id="uiconfigsection" form="queue-form" class="lms-ui-box-field-value"
								name="queue[uiconfigsection]" {tip trigger="uiconfigsection"}>
							<option value="">{trans("<!rt-configuration-section>— default —")}</option>
							{foreach $configsections as $configsection}
								<option value="{$configsection}" {if $configsection == $queue.uiconfigsection} selected{/if}>{$configsection}</option>
							{/foreach}
						</select>
					</div>
				</div>
			{/if}
			<div class="lms-ui-box-row">
				<div class="lms-ui-box-field">
					<div class="lms-ui-box-field-label">
						{icon name="user"}
						<strong>{trans("Permissions")}</strong>
					</div>
					<div class="lms-ui-box-field-value lms-ui-box-nested-box lms-ui-background-cycle">
						<div class="lms-ui-box-header">
							<div class="lms-ui-box-row">
								<div class="lms-ui-box-field username">
									<strong>{trans("User")}</strong>
									{*<COL style="width: {100-count($_RT_RIGHTS)}%">*}
								</div>
								{foreach $_RT_RIGHTS as $label}
									<div class="lms-ui-box-field permission">
										<strong>
											{$label}
										</strong>
									</div>
								{/foreach}
							</div>
						</div>
						<div class="lms-ui-box-body lms-ui-flex-column">
							{foreach $queue.rights as $right}
								<div class="lms-ui-box-row highlight lms-ui-row-all-check{if empty($right.access)} blend{/if}"
									{if empty($right.access) && $hide_disabled_users} style="display: none;"{/if}>
									<div class="lms-ui-box-field username">
										<a href="?m=userinfo&id={$right.id}">{$right.rname}</a>
										<span class="user-login">({$right.login})</span>
										<input type="hidden" name="queue[usernames][{$right.id}]"
											value="{$right.rname}" form="queue-form">
										<input type="hidden" name="queue[userlogins][{$right.id}]"
											value="{$right.login}" form="queue-form">
									</div>
									{foreach $_RT_RIGHTS as $rightvalue => $label}
										<div class="lms-ui-box-field permission">
											<input type="checkbox" name="queue[users][{$right.id}][{$rightvalue}]"
												form="queue-form"
												value="{$rightvalue}"{if ($right.rights & $rightvalue) == $rightvalue} checked{/if}>
										</div>
									{/foreach}
								</div>
								{if empty($right.access) && $hide_disabled_users}
									<div style="display: none;"></div>
								{/if}
							{/foreach}
						</div>
						<div class="lms-ui-box-footer">
							<div class="lms-ui-box-row">
								<div class="lms-ui-box-field username">
									<strong>
										{trans("Check All")}
									</strong>
								</div>
								{foreach $_RT_RIGHTS as $rightvalue => $label}
									<div class="lms-ui-box-field permission">
										<input type="checkbox" name="allbox[{$rightvalue}]"
											data-value="{$rightvalue}">
									</div>
								{/foreach}
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="lms-ui-box-panel lms-ui-box-right-panel">
			<div class="lms-ui-box-row">
				<fieldset>
					<legend>
						{icon name="notifications"}
						<strong>{trans("Customer notifications")}</strong>
					</legend>
					<div id="notification-tabs">
						<ul>
							<li><a href="#notification-tab-email">{trans("Email")}</a></li>
							<li><a href="#notification-tab-sms">{trans("SMS")}</a></li>
						</ul>
						<div id="notification-tab-email" class="lms-ui-box notification-tab">
							<div class="lms-ui-box-body lms-ui-flex-column">
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Subject (new ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Subject of mail sent after new ticket is created")}
											<br>
											{trans("<!customer-notification-subject>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%title</strong> - ticket title.<br>")}
										{/capture}
										<input type="text" name="queue[newticketsubject]"
											form="queue-form" value="{$queue.newticketsubject}"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newticketsubject"}>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (new ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Body of mail sent after new ticket is created")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - new ticket body.<br>")}
										{/capture}
										<textarea name="queue[newticketbody]" rows="10" form="queue-form"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newticketbody"}
											>{$queue.newticketbody}</textarea>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Subject (new message)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Subject of mail sent after new message is added")}
											<br>
											{trans("<!customer-notification-subject>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%title</strong> - ticket title.<br>")}
										{/capture}
										<input type="text" name="queue[newmessagesubject]"
											form="queue-form" value="{$queue.newmessagesubject}"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newmessagesubject"}>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (new message)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Body of mail sent after new message is added")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - new message body.<br>")}
										{/capture}
										<textarea name="queue[newmessagebody]" rows="10" form="queue-form"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newmessagebody"}
											>{$queue.newmessagebody}</textarea>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Subject (resolve ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Subject of mail sent after ticket is resolved")}
											<br>
											{trans("<!customer-notification-subject>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%title</strong> - ticket title.<br>")}
										{/capture}
										<input type="text" name="queue[resolveticketsubject]"
											   form="queue-form" value="{$queue.resolveticketsubject}"
											   class="lms-ui-box-field-value"
												{tip text=$tip trigger="resolveticketsubject"}>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (resolve ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("Body of mail sent after ticket is resolved")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - ticket last message body.<br>")}
										{/capture}
										<textarea name="queue[resolveticketbody]" rows="10" form="queue-form"
												  class="lms-ui-box-field-value"
											{tip text=$tip trigger="resolveticketbody"}
											>{$queue.resolveticketbody}</textarea>
									</div>
								</div>
							</div>
						</div>
						<div id="notification-tab-sms" class="lms-ui-box notification-tab">
							<div class="lms-ui-box-body lms-ui-flex-column">
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (new ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("SMS sent after new ticket is created")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - new ticket body.<br>")}
										{/capture}
										<textarea name="queue[newticketsmsbody]" rows="10" form="queue-form"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newticketsmsbody"}
											>{$queue.newticketsmsbody}</textarea>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (new message)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("SMS sent after new message is added")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - new message body.<br>")}
										{/capture}
										<textarea name="queue[newmessagesmsbody]" rows="10" form="queue-form"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="newmessagesmsbody"}
											>{$queue.newmessagesmsbody}</textarea>
									</div>
								</div>
								<div class="lms-ui-box-row">
									<div class="lms-ui-box-field">
										<div class="lms-ui-box-field-label">
											<strong>
												{trans("Body (resolve ticket)")}
											</strong>
										</div>
										{capture assign="tip"}
											{trans("SMS sent after ticket is resolved")}
											<br>
											{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title,<br><strong>%body</strong> - ticket last message body.<br>")}
										{/capture}
										<textarea name="queue[resolveticketsmsbody]" rows="10" form="queue-form"
											class="lms-ui-box-field-value"
											{tip text=$tip trigger="resolveticketsmsbody"}
											>{$queue.resolveticketsmsbody}</textarea>
									</div>
								</div>
							</div>
						</div>
					</div>
				</fieldset>
			</div>
			<div class="lms-ui-box-row">
				<fieldset>
					<legend>
						{icon name="verifier"}
						<strong>{trans("Verifier notifications")}</strong>
					</legend>
					<div id="verifier-notifications" class="lms-ui-box">
						<div class="lms-ui-box-body lms-ui-flex-column">
							<div class="lms-ui-box-row">
								<div class="lms-ui-box-field">
									<div class="lms-ui-box-field-label">
										<strong>
											{trans("Subject (ticket verifier)")}
										</strong>
									</div>
									{capture assign="tip"}
										{trans("Subject of mail sent to verifier after ticket is transferred to him")}
										<br>
										{trans("<!customer-notification-subject>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%title</strong> - ticket title.<br>")}
									{/capture}
									<input type="text" name="queue[verifierticketsubject]"
										form="queue-form" value="{$queue.verifierticketsubject}"
										class="lms-ui-box-field-value"
										{tip text=$tip trigger="verifierticketsubject"}>
								</div>
							</div>
							<div class="lms-ui-box-row">
								<div class="lms-ui-box-field">
									<div class="lms-ui-box-field-label">
										<strong>
											{trans("Body (ticket verifier)")}
										</strong>
									</div>
									{capture assign="tip"}
										{trans("Body of mail sent to verifier after ticket is transferred to him")}
										<br>
										{trans("<!customer-notification-body>The following special symbols are supported:<br><strong>%tid</strong> - ticket identifier,<br><strong>%cid</strong> - customer identifier,<br><strong>%pin</strong> - customer PIN,<br><strong>%customername</strong> - customer full name,<br><strong>%title</strong> - ticket title.<br>")}
									{/capture}
									<textarea name="queue[verifierticketbody]" rows="10" form="queue-form"
										class="lms-ui-box-field-value"
										{tip text=$tip trigger="verifierticketbody"}
										>{$queue.verifierticketbody}</textarea>
								</div>
							</div>
						</div>
					</div>
				</fieldset>
			</div>
		</div>
	</div>
	<div class="lms-ui-box-buttons">
		{button type="submit" icon="save" label="Submit"
			onclick="javascript:document.queue.submit()" form="queue-form"}
		{if $layout.module == 'rtqueueedit'}
			{button id="delete-rtqueue" icon="delete" label="Delete"
				data_href="?m=rtqueuedel&id={$queue.id}&qaction=delete" data_name=$queue.name}
		{/if}
		{button icon="cancel" label="Cancel" href="?m=rtqueuelist"}
	</div>
</div>

<script>

	$(function() {
		$('#queue-name').focus();

		for (var i = 0; i < {count($_RT_RIGHTS)}; i++) {
			$('input:checkbox[name="allbox[' + Math.pow(2, i) + ']"]').click(function() {
				$('input:checkbox[name*="queue[users]"][value="' + $(this).attr('data-value') + '"]:visible').prop('checked', this.checked);
			});
		}

		$('#checkall').change(function() {
			$('#categories option').attr('selected', $(this).prop('checked')).trigger('chosen:updated');
			$('.category-checkbox').prop('checked', $(this).prop('checked'));
		});

		var categories = $('#categories option');
		if (categories.length) {
			$('#checkall').prop('checked', categories.length == categories.filter(':selected').length);
			$('#categories').change(function() {
				$('#checkall').prop('checked', categories.length == categories.filter(':selected').length);
			});
		} else {
			categories = $('.category-checkbox')
			$('#checkall').prop('checked', categories.length == categories.filter(':checked').length);
			categories.change(function() {
				$('#checkall').prop('checked', categories.length == categories.filter(':checked').length);
			});
		}

		$('#delete-rtqueue').click(function() {
			var name = $(this).attr('data-name');
			confirmDialog($t("Are you sure, you want to remove queue '$a' and all assigned tickets and messages?", name), this).done(function() {
				location.href = $(this).attr('data-href');
			});
			return false;
		});

		$('[name="queue"]').submit(function() {
			window.sessionStorage.setItem('rtqueuemodify-active-notification-tab', $('.notification-tab:visible').attr('id'));
		});

		var activeNotificationTab = window.sessionStorage.getItem('rtqueuemodify-active-notification-tab');
		if (activeNotificationTab) {
			window.sessionStorage.removeItem('rtqueuemodify-active-notification-tab');
		}

		var errors = [];
		$('.notification-tab').each(function() {
			if ($(this).find('.lms-ui-error').length) {
				errors.push($(this).attr('id'));
			}
		});

		var newActiveNotificationTab;

		if (activeNotificationTab) {
			newActiveNotificationTab = activeNotificationTab;
		}
		if (errors.length && errors.indexOf(activeNotificationTab) == -1) {
			newActiveNotificationTab = errors[0];
		}

		if (newActiveNotificationTab) {
			newActiveNotificationTab = $('.notification-tab').index('#' + newActiveNotificationTab);
		} else {
			newActiveNotificationTab = $('.notification-tab').first();
		}
		$('#notification-tabs').tabs({
			active: newActiveNotificationTab
		});

		$.each(errors, function(index, value) {
			$('[href="#' + value + '"]').closest('.ui-tab').addClass('lms-ui-error');
		});

		$('.lms-ui-box-field-label').click(function() {
			$(this).siblings('.lms-ui-box-field-value').focus();
		});
	});

</script>
{/block}
