{{function name="selectOptions" aOptions=0 mOption=0}}
	{{foreach from=$aOptions item=sOption}}
		<option value="{{$sOption@key}}" {{if ( is_array( $mOption ) && in_array( $sOption@key, $mOption ) ) || ( $sOption@key == $mOption )}}selected="selected"{{/if}}>{{$sOption}}</option>
	{{/foreach}}
{{/function}}

{{function name="selectPageOptions" aOptions=0 mOption=0 iLevel=0}}
	{{foreach from=$aOptions item=aOption}}
		<option value="{{$aOption.iPage}}"{{if $aOption.iPage == 0}} disabled="disabled" style="color:#888;"{{/if}}{{if ( is_array( $mOption ) && in_array( $aOption.iPage, $mOption ) ) || ( $aOption.iPage == $mOption )}} selected="selected"{{/if}}>{{str_repeat("&nbsp;&nbsp;", $iLevel)}}{{$aOption.sName}}</option>
		{{selectPageOptions aOptions=$aOption.aChildren mOption=$mOption iLevel=$iLevel+1}}
	{{/foreach}}
{{/function}}

<script type="text/javascript">
$(document).ready(function(){
	$("form#users-related-form").validate();
	$("form#users-related-form #users-related-name").rules("add", {required: true});
	$("form#users-related-form #group-discount").rules("add", {required: true});
});
</script>
<h1>{{$lang.Group}} - {{if isset( $aGroup.sName )}}{{$aGroup.sName}}{{else}}{{$lang.New}}{{/if}}</h1>
<form action="?p={{$_GET.p}}&amp;iGroup={{$aGroup.iGroup}}" method="post" id="users-related-form" > 
	<fieldset>
		<input type="hidden" name="iGroup" value="{{$aGroup.iGroup}}" />
		<table class="details">
			<tr>
				<th class="name">{{$lang.Name}}</th><td class="value"><input id="users-related-name" type="text" name="sName" value="{{$aGroup.sName}}" size="30" maxlength="20" class="input" alt="simple" /></td><td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Inform_user_group}}</th><td class="value"><input type="hidden" name="iInformEmail" value="0" /><input type="checkbox" name="iInformEmail" value="1" {{if $aGroup.iInformEmail}}checked="checked"{{/if}} /></td><td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Auto_group}}</th><td class="value"><input type="hidden" name="iAutoGroup" value="0" /><input id="group-auto" type="checkbox" name="iAutoGroup" value="1" {{if $aGroup.iAutoGroup}}checked="checked"{{/if}} class="input" /></td><td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Users_related}}:</th>
				<td class="value">
					<table id="users-multiselect" class="multiselect list">
						<thead>
							<tr>
							<th class="id">{{$lang.Id}}</th>
							<th class="name">{{$lang.Name}}</th>
							<th class="del">{{$lang.Delete}}</th></tr>
							<tr class="item" style="display: none">
								<td class="id">%iId%</td>
								<td class="name">%sName%</td>
								<td class="del"><a class="users-delete" href="#" ><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a></td>
								<td class="value" style="display: none"><input type="hidden" value="%iId%" name="aUsersRelated[]" /></td>
							</tr>
						</thead>
						<tbody>
							{{foreach from=$aUsersSelected item=iUserSelected}}
								<tr class="item">
									<td class="id">{{$iUserSelected}}</td>
									<td class="name"> {{$aUsers[$iUserSelected]}}</td>
									<td class="del"><a class="users-delete" href="#" ><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a></td>
									<td class="value" style="display: none"><input type="hidden" value="{{$iUserSelected}}" name="aUsersRelated[]" /></td>
								</tr>
							{{/foreach}}
						</tbody>
						<tfoot>
							<tr>
								<td></td>
								<td class="left" colspan="2"><a href="admin.php?p=users-multiselect&amp;request_type=users-multiselect" class="users-select new_element">{{$lang.Add_related_users}}</a></td>
							</tr>
						</tfoot>
					</table>
				</td>
				<td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Pages_related_more}}</th>
				<td class="value">
					<table id="pages-multiselect" class="multiselect list">
						<thead>
							<tr>
								<th class="id">{{$lang.Id}}</th>
								<th class="name">{{$lang.Name}}</th>
								<th class="del">{{$lang.Delete}}</th>
							</tr>
							<tr class="item" style="display: none">
								<td class="id">%iId%</td>
								<td class="name">%sName%</td>
								<td class="del"><a class="pages-delete" href="#" ><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a></td><td class="value" style="display: none"><input type="hidden" value="%iId%" name="aPagesRelated[]" /></td>
							</tr>
						</thead>
						<tbody>
							{{foreach from=$aPagesSelected item=sPageSelected}}
								<tr class="item">
									<td class="id">{{$sPageSelected@key}}</td>
									<td class="name"> {{$sPageSelected}}</td>
									<td class="del"><a class="users-delete" href="#" ><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a></td>
									<td class="value" style="display: none"><input type="hidden" value="{{$sPageSelected@key}}" name="aPagesRelated[]" /></td>
								</tr>
							{{/foreach}}
						</tbody>
						<tfoot>
							<tr>
								<td></td>
								<td class="left" colspan="2"><a href="admin.php?p=p-multiselect&amp;iAuthorized=1&amp;request_type=pages-multiselect" class="pages-select new_element">{{$lang.Add_related_pages}}</a></td>
							</tr>
						</tfoot>
					</table>
				</td>
				<td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Group_Discount}}</th><td class="value"><input id="group-discount" type="text" name="fDiscount" value="{{$aGroup.fDiscount}}" size="7" maxlength="7" class="input" /></td><td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Auto_group_summary}}</th><td class="value"><input id="group-auto-summary" type="text" name="fAutoSummary" value="{{$aGroup.fAutoSummary}}" class="input" /></td><td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Auto_group_days}}</th><td class="value"><input id="group-auto-days" type="text" name="iAutoDays" value="{{$aGroup.iAutoDays}}" class="input" /></td><td class="help"></td>
			</tr>
		</table>

		<div class="save float">
			<div class="save floatcontainer"><input type="submit" class="submit" value="&laquo; {{$lang.return}}"  onclick="location.href = '?p=users-groupList'; return false;"> <input type="submit" value="{{$lang.Save}} &raquo;" name="sOption" class="submit" /></div>
		</div>

	</fieldset>
</form>