<form id="login" name="login" target="_blank"  action="{$GLOBALS.user_site_url}/login/" method="post">
	<input type="hidden" name="action" value="login" />
	<input type="hidden" name="as_user" />
	<input type="hidden" name="username" value="" />
	<input type="hidden" name="password" value="" />
</form>

{breadcrumbs}
	<a href="{$GLOBALS.site_url}/manage-users/{$user_group_info.id|lower}/?restore=1">
		[[{$user_group_info.name} Profiles]]
	</a>
	/
	[[Edit {$user_group_info.name}]]
{/breadcrumbs}
<div class="page-title">
	<h1 class="title">[[Edit {$user_group_info.name}]]</h1>
	<div class="page-title__buttons">
		<button type="button" name="button" value="[[Login]]" class="btn--bordered login-as">
			[[Login]]
		</button>
		{if $user_group_info.id == 'Employer'}
			<a href="{$GLOBALS.site_url}/manage-jobs/?company_name[like]={$user_info.username|escape:'url'}" class="grayButton">[[View {$user_group_info.name} Jobs]]</a>
		{/if}
		<a href="{$GLOBALS.site_url}/user-products/?user_sid={$user_info.sid}" class="grayButton">[[{$user_group_info.name} Products]]</a>
	</div>
</div>

<div class="form-group clearfix">

</div>
{include file='field_errors.tpl'}
<div class="panel panel-default panel--max">
	<form method="post" enctype="multipart/form-data" class="panel-body form-horizontal">
		{set_token_field}
		<input type="hidden" id="action_name" name="action_name" value="apply_info" />
		{foreach from=$form_fields item=form_field}
			<div class="form-group" {if $form_field.id == 'Location'}style="display: none;"{/if}>
				<label class="col-md-2 control-label">[[{$form_field.caption|escape}]]{if $form_field.is_required}&nbsp;<span class="required">*</span>{/if}</label>
				<div class="col-md-7">
					{input property=$form_field.id}
					{if in_array($form_field.type, array('multilist'))}
						<div id="count-available-{$form_field.id}" class="mt-count-available"></div>
					{/if}
				</div>
			</div>
		{/foreach}
		<div class="form-group">
			<label class="col-md-2 control-label">IP</label>
			<div class="col-md-7"><label style="padding-top: 7px;">{$user_info.ip}</label></div>
		</div>
		<div class="form-group">
			<div class="col-md-7 col-md-offset-2">
				<input type="hidden" name="user_sid" value="{$user_info.sid}" />
				<input type="submit" value="[[Save]]" class="grayButton" />
			</div>
		</div>
	</form>
</div>

<div class="modal fade" id="modal-error" role="dialog">
	<div class="modal-dialog modal-sm">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">[[Error]]</h4>
			</div>
			<div class="modal-body"></div>
		</div>
	</div>
</div>
{javascript}
	<script>
		$('.login-as').on('click', function() {
			login_as_user('{$user_info.username}', '{$user_info.password}');
		});

		function login_as_user( name, pass ) {
			$.get('{$GLOBALS.site_url}/login-as-user/', { username: name, password: pass}, function (data) {
				var response = $.trim(data);
				if (response == "") {
					document.login.username.value = name;
					document.login.password.value = pass;
					document.getElementById('login').submit();
				} else {
					$('#modal-error').show();
					$('#modal-error').find('.modal-body').html(data);
				}
			});
		}
	</script>
{/javascript}