<?xml version="1.0" encoding="UTF-8"?>
<!--/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed  under the  License is distributed on an "AS IS" BASIS,
WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
implied.

See the License for the specific language governing permissions and
limitations under the License.
*/-->
<div xmlns:th="http://www.thymeleaf.org">
	<script type="text/javascript" th:inline="javascript">
		/*<![CDATA[*/
		var [(${namespace})]_updateAttachments = function(responseJSON) {
			$('#[(${namespace})]attachmentsTableBody').empty();
			$('#[(${namespace})]inputFile').val('');
			$.each(responseJSON, function(i, item) {
				$('<tr>').append(
					$('<td>').append(
						$('<input>').attr(
							'type', 'image').attr(
							'src',
							'[(${contextPath})]/images/icon-delete.png').attr(
							'name', 'attachmentIndex').attr('value', i)),
					$('<td>').text(item.fileName),
					$('<td>').text(item.size)
				).appendTo('#[(${namespace})]attachmentsTableBody');
			});
		}
		/*]]>*/
	</script>
	<script type="text/javascript" th:inline="javascript">
		/*<![CDATA[*/
		$(document).ready(function(){
			$('#[(${namespace})]postalCode').on('change', function submitXHR(){
				$.ajax({
					data: {
						[(${mvc.csrf.name})]: '[(${mvc.csrf.token})]',
						[(${namespace})]postalCode: $(this).val()
					},
					type: 'post',
					url: '[(${autoFillResourceURL})]'
				}).done(function(responseData) {
					var responseJSON = JSON.parse(responseData);
					$('#[(${namespace})]city').val(responseJSON['cityName']).change();
					$('#[(${namespace})]provinceId').val(responseJSON['provinceId']).change();
				}).fail(function() {
					console.log('XHR failed');
				});
			});
		});
		/*]]>*/
	</script>
	<script type="text/javascript" th:inline="text">
		/*<![CDATA[*/
		$(document).ready(function(){
			$('#[(${namespace})]deleteFileForm').on('click', 'input', function (event) {
				event.preventDefault();
				if (confirm('[(#{are-you-sure-you-want-to-delete-this})]')) {
					$.ajax({
						data: {
							[(${namespace})]attachmentIndex: event.target.value,
							[(${mvc.csrf.name})]: '[(${mvc.csrf.token})]'
						},
						type: 'post',
						url: '[(${deleteFileResourceURL})]'
					}).done(function (responseData) {
						[(${namespace})]_updateAttachments(JSON.parse(responseData));
					}).fail(function () {
						console.log('XHR failed');
					});
				}
			});
		});
		/*]]>*/
	</script>
	<script type="text/javascript" th:inline="text">
		/*<![CDATA[*/
		$(document).ready(function(){
			$('#[(${namespace})]fileUploadForm').submit(function (event) {
				event.preventDefault();
				var formData = new FormData($(this)[0]);
				$.ajax({
					async: false,
					cache: false,
					contentType: false,
					data: formData,
					processData: false,
					type: 'post',
					url: '[(${uploadFilesResourceURL})]'
				}).done(function(responseData) {
					[(${namespace})]_updateAttachments(JSON.parse(responseData));
				}).fail(function() {
					console.log('XHR failed');
				});
			});
		});
		/*]]>*/
	</script>
	<script type="text/javascript" th:inline="text">
		/*<![CDATA[*/
		$(document).ready(function(){
			$('#[(${namespace})]mainForm input[type=email],input[type=tel],input[type=text],select').on('blur change', function(event) {
				$(event.target).parent().children('span').remove();
				if ($.trim(event.target.value) == 0) {
					$('<span>').attr(
						'class', 'portlet-msg-error').text(
						'[(#{value-is-required})]').appendTo(
						$(event.target).parent());
				}
			});
			$('#[(${namespace})]dateOfBirth').datepicker({dateFormat:'[(${jQueryDatePattern})]'});
			$('#[(${namespace})]hideComments').click(function(){
				$('#[(${namespace})]comments').hide();
				$('#[(${namespace})]hideComments').hide();
				$('#[(${namespace})]showComments').show();
			});
			$('#[(${namespace})]showComments').click(function(){
				$('#[(${namespace})]comments').show();
				$('#[(${namespace})]hideComments').show();
				$('#[(${namespace})]showComments').hide();
			});
		});
		/*]]>*/
	</script>
	<div class="container">
		<div class="row">
			<div class="col-6">
				<form th:id="|${namespace}mainForm|" method="post" th:action="${mainFormActionURL}" th:object="${applicant}">
					<span class="portlet-msg-info" th:if="${globalInfoMessage != null}" th:text="${globalInfoMessage}"/>
					<span class="portlet-msg-error" th:if="${globalErrorMessage != null}" th:text="${globalErrorMessage}"/>
					<fieldset>
						<div class="row">
							<div class="col-6">
								<div class="form-group">
									<label th:for="|${namespace}firstName|" th:text="#{first-name}"/>
									<input th:id="|${namespace}firstName|" class="form-control" th:name="|${namespace}firstName|" type="text" th:value="*{firstName}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('firstName')}" th:text="${fields.error('firstName')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}lastName|" th:text="#{last-name}"/>
									<input th:id="|${namespace}lastName|" class="form-control" th:name="|${namespace}lastName|" type="text" th:value="*{lastName}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('lastName')}" th:text="${fields.error('lastName')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}emailAddress|" th:text="#{email-address}"/>
									<input th:id="|${namespace}emailAddress|" class="form-control" th:name="|${namespace}emailAddress|" type="email" th:value="*{emailAddress}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('emailAddress')}" th:text="${fields.error('emailAddress')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}phoneNumber|" th:text="#{phone-number}"/>
									<input th:id="|${namespace}phoneNumber|" class="form-control" th:name="|${namespace}phoneNumber|" type="tel" th:value="*{phoneNumber}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('phoneNumber')}" th:text="${fields.error('phoneNumber')}"/>
								</div>
							</div>
							<div class="col-6">
								<div class="form-group">
									<label th:for="|${namespace}dateOfBirth|" th:text="#{date-of-birth}"/>
									<input th:id="|${namespace}dateOfBirth|" class="form-control" th:name="|${namespace}dateOfBirth|" type="text" th:value="${converter.convert('applicant.dateOfBirth')}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('dateOfBirth')}" th:text="${fields.error('dateOfBirth')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}city|" th:text="#{city}"/>
									<input th:id="|${namespace}city|" class="form-control" th:name="|${namespace}city|" type="text" th:value="*{city}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('city')}" th:text="${fields.error('city')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}provinceId|" th:text="#{state-province}"/>
									<select th:id="|${namespace}provinceId|" class="form-control" th:name="|${namespace}provinceId|" th:value="*{provinceId}">
										<option th:text="#{select}" value=""/>
										<option th:each="province: ${provinces}" th:text="${province.provinceName}" th:selected="(${province.provinceId} == *{provinceId})" th:value="${province.provinceId}"/>
									</select>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('provinceId')}" th:text="${fields.error('provinceId')}"/>
								</div>
								<div class="form-group">
									<label th:for="|${namespace}postalCode|" th:text="#{zip-postal}"/>
									<input th:id="|${namespace}postalCode|" class="form-control" th:name="|${namespace}postalCode|" type="text" th:value="*{postalCode}"/>
									<img th:src="|${contextPath}/images/icon-help.png|" th:title="#{postal-code-hint}"/>
									<span class="portlet-msg-error" th:if="${fields.hasErrors('postalCode')}" th:text="${fields.error('postalCode')}"/>
								</div>
							</div>
						</div>
					</fieldset>
					<fieldset>
						<div class="row">
							<div class="col">
								<div class="form-group">
									<label th:for="|${namespace}comments|" th:text="#{comments}"/>
									<div>
										<a th:id="|${namespace}hideComments|" href="javascript:;" th:text="#{hide}"/>
									</div>
									<div>
										<a th:id="|${namespace}showComments|" href="javascript:;" style="display:none;" th:text="#{show}"/>
									</div>
									<textarea th:id="|${namespace}comments|" class="form-control" th:value="*{comments}"></textarea>
								</div>
							</div>
						</div>
					</fieldset>
					<input th:name="|${mvc.csrf.name}|" th:value="|${mvc.csrf.token}|" type="hidden"/>
					<input th:name="|${namespace}javax.portlet.action|" value="submitApplicant" type="hidden"/>
					<input class="btn btn-primary" th:text="${submit}" type="submit"/>
				</form>
			</div>
			<div class="col-6">
				<div class="row">
					<div class="col">
						<form th:id="|${namespace}deleteFileForm|" method="post" th:action="${deleteFileResourceURL}" th:object="${applicant}">
							<h3 th:text="#{attachments}"/>
							<table class="table">
								<thead>
									<tr>
										<th><img th:src="|${contextPath}/images/icon-delete.png|" style="display:none;"/></th>
										<th th:text="#{file-name}"/>
										<th th:text="#{size}"/>
									</tr>
								</thead>
								<tbody th:id="|${namespace}attachmentsTableBody|">
									<tr th:each="attachment,attachmentStatus: *{attachments}">
										<td>
											<input name="attachmentIndex" th:src="|${contextPath}/images/icon-delete.png|" th:value="${attachmentStatus.index}" type="image"/>
										</td>
										<td th:text="${attachment.name}"/>
										<td th:text="${attachment.size}"/>
									</tr>
								</tbody>
							</table>
						</form>
						<hr/>
						<form th:id="|${namespace}fileUploadForm|" enctype="multipart/form-data">
							<div class="form-group">
								<input th:id="|${namespace}inputFile|" class="form-control" th:name="multipartFiles" multiple="multiple" type="file"/>
								<input th:name="|${mvc.csrf.name}|" th:value="|${mvc.csrf.token}|" type="hidden"/>
								<input class="btn btn-primary" th:value="#{submit}" type="submit"/>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<hr />
	<ul>
		<li th:text="|Weld ${weldVersion}|"/>
	</ul>
	<a th:href="${viewTermsResourceURL}" style="float:right;line-height:0px;" target="_blank" th:text="#{terms-of-service}"/>
</div>
