<!-- To change the layout of the detail view form, we recommend using JS code in hooks/applications_leases-dv.js rather than editing this file -->

<div id="detail-view"></div>
<div class="panel-heading"><h3 class="panel-title"><strong><%%DETAIL_VIEW_TITLE%%></strong></h3></div>

<div id="applications_leases_dv_container-loading" class="text-center text-info text-bold vspacer-lg"><i class="glyphicon glyphicon-refresh loop-rotate"></i> <%%TRANSLATION(Loading ...)%%></div>

<div class="panel-body hidden" id="applications_leases_dv_container">
	<!-- child links -->
	<div class="row vspacer-md">
		<div class="col-xs-12 children-links">
			<div class="clearfix"></div>
		</div>
	</div>
	<hr class="hidden-xs hidden-sm">

	<div class="row">
		<!-- form inputs -->
		<div class="col-md-8 col-lg-10" id="applications_leases_dv_form">
			<fieldset class="form-horizontal">

				<!-- Field: ID -->
				<div class="form-group applications_leases-id">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="id">ID</label>
					<div class="col-lg-9">
						<div class="form-control-static" id="id"><%%VALUE(id)%%></div>
					</div>
				</div>

				<!-- Field: Applicant/ Tenant -->
				<div class="form-group applications_leases-tenants">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="tenants" data-parent_link="view_parent_modal">Applicant/ Tenant</label>
					<div class="col-lg-9">
						<div class="lookup-flex"><%%COMBO(tenants)%%><%%PLINK(tenants)%%><%%ADDNEW(applicants_and_tenants)%%></div>
					</div>
				</div>

				<!-- Field: Application status -->
				<div class="form-group applications_leases-status">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3">Application status<span class="text-danger"><%%TRANSLATION(*)%%></span> <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#status-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="status-description"><div class="alert alert-info bspacer-xs">After an application is approved, set this to "Lease". When the lease expires or is terminated, set it to "Historical lease"</div></span>
						<%%COMBO(status)%%>
					</div>
				</div>

				<!-- Field: Property -->
				<div class="form-group applications_leases-property">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="property" data-parent_link="view_parent_modal">Property <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#property-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="property-description"><div class="alert alert-info bspacer-xs">The property containing the unit for which the applicant/tenant is applying for a lease.</div></span>
						<div class="lookup-flex"><%%COMBO(property)%%><%%PLINK(property)%%><%%ADDNEW(properties)%%></div>
					</div>
				</div>

				<!-- Field: Unit applied for -->
				<div class="form-group applications_leases-unit">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="unit" data-parent_link="view_parent_modal">Unit applied for</label>
					<div class="col-lg-9">
						<div class="lookup-flex"><%%COMBO(unit)%%><%%PLINK(unit)%%><%%ADDNEW(units)%%></div>
					</div>
				</div>

				<!-- Field: Lease type -->
				<div class="form-group applications_leases-type">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3">Lease type<span class="text-danger"><%%TRANSLATION(*)%%></span> <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#type-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="type-description"><div class="alert alert-info bspacer-xs">Specify the type of lease term.</div></span>
						<%%COMBO(type)%%>
					</div>
				</div>

				<!-- Field: Total number of occupants -->
				<div class="form-group applications_leases-total_number_of_occupants">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="total_number_of_occupants">Total number of occupants</label>
					<div class="col-lg-9">
						<input maxlength="15" type="text" class="form-control" name="total_number_of_occupants" id="total_number_of_occupants" value="<%%VALUE(total_number_of_occupants)%%>">
					</div>
				</div>

				<!-- Field: Lease period from -->
				<div class="form-group applications_leases-start_date">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="start_date-mm">Lease period from</label>
					<div class="col-lg-9">
						<%%COMBO(start_date)%%>
					</div>
				</div>

				<!-- Field: to -->
				<div class="form-group applications_leases-end_date">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="end_date-mm">to</label>
					<div class="col-lg-9">
						<%%COMBO(end_date)%%>
					</div>
				</div>

				<!-- Field: Recurring charges frequency -->
				<div class="form-group applications_leases-recurring_charges_frequency">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="recurring_charges_frequency">Recurring charges frequency<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<%%COMBO(recurring_charges_frequency)%%>
					</div>
				</div>

				<!-- Field: Next due date -->
				<div class="form-group applications_leases-next_due_date">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="next_due_date-mm">Next due date</label>
					<div class="col-lg-9">
						<%%COMBO(next_due_date)%%>
					</div>
				</div>

				<!-- Field: Rental amount -->
				<div class="form-group applications_leases-rent">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="rent">Rental amount</label>
					<div class="col-lg-9">
						<input maxlength="13" type="text" class="form-control" name="rent" id="rent" value="<%%VALUE(rent)%%>">
					</div>
				</div>

				<!-- Field: Security deposit -->
				<div class="form-group applications_leases-security_deposit">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="security_deposit">Security deposit</label>
					<div class="col-lg-9">
						<input maxlength="18" type="text" class="form-control" name="security_deposit" id="security_deposit" value="<%%VALUE(security_deposit)%%>">
					</div>
				</div>

				<!-- Field: Security deposit date -->
				<div class="form-group applications_leases-security_deposit_date">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="security_deposit_date-mm">Security deposit date</label>
					<div class="col-lg-9">
						<%%COMBO(security_deposit_date)%%>
					</div>
				</div>

				<!-- Field: Emergency contact -->
				<div class="form-group applications_leases-emergency_contact">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="emergency_contact">Emergency contact <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#emergency_contact-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="emergency_contact-description"><div class="alert alert-info bspacer-xs">Add all details of whom to contact in case of emergency</div></span>
						<textarea class="form-control" name="emergency_contact" id="emergency_contact" rows=" 2"><%%VALUE(emergency_contact)%%></textarea>
					</div>
				</div>

				<!-- Field: Co signer details -->
				<div class="form-group applications_leases-co_signer_details">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="co_signer_details">Co signer details <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#co_signer_details-description"></i></label>
					<div class="col-lg-9">
						<span class="help-block bspacer-xs collapse" id="co_signer_details-description"><div class="alert alert-info bspacer-xs">Add all details to your co-signer, for example name, e-mail, address, phone... etc.</div></span>
						<textarea class="form-control" name="co_signer_details" id="co_signer_details" rows=" 2"><%%VALUE(co_signer_details)%%></textarea>
					</div>
				</div>

				<!-- Field: Notes -->
				<div class="form-group applications_leases-notes">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="notes">Notes <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#notes-description"></i></label>
					<div class="col-lg-9 has-nicedit">
						<span class="help-block bspacer-xs collapse" id="notes-description"><div class="alert alert-info bspacer-xs">You can type any notes regarding this applicaton/lease here, for example rejected or cancelled by user or any other notes.</div></span>
						<%%HTMLAREA(notes)%%>
					</div>
				</div>

				<!-- Field: Applicant agrees -->
				<div class="form-group applications_leases-agreement">
					<hr class="hidden-md hidden-lg">
					<div class="col-lg-offset-3 col-lg-9">
						<span class="help-block bspacer-xs collapse" id="agreement-description"><div class="alert alert-info bspacer-xs"><b>The applicant must agree to the following terms: </b><br><ol><li>I understand that this is a routine application to establish credit, character, employment, and rental history.</li><br><li>I also understand that this is NOT an agreement to rent and that all applications must be approved.</li><br><li>I authorize verification of references given.</li><br><li>I declare that the statements above are true and correct, and I agree that the landlord may terminate my agreement entered into in reliance on any misstatement made above.</li><br></ul></div></span>
						<div class="checkbox">
							<label for="agreement"><input type="checkbox" name="agreement" id="agreement" value="1" <%%CHECKED(agreement)%%>> Applicant agrees</label> <i class="glyphicon glyphicon-info-sign text-info" data-toggle="collapse" data-target="#agreement-description"></i>
						</div>
					</div>
				</div>

			</fieldset>
		</div>

		<!-- DV action buttons -->
		<hr class="hidden-md hidden-lg">
		<div class="col-md-4 col-lg-2" id="applications_leases_dv_action_buttons">
			<div class="btn-toolbar">
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%UPDATE_BUTTON%%>
				</div><p></p>
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%DESELECT_BUTTON%%>
					<%%DVPRINT_BUTTON%%>
					<%%DELETE_BUTTON%%>
				</div><p></p>
				<div class="btn-group-vertical btn-group-lg" style="width: 100%;">
					<%%INSERT_BUTTON%%>
				</div>
			</div>
		</div>
	</div>


</div><!-- /div class="panel-body" -->
	<script>
		$j(function() {
			var add_new_mode = (!$j('input[name=SelectedID]').val());
			var embedded_mode = ($j('input[name=Embedded]').val() == 1);

			/* auto-close embedded page? */
			var autoclose_mode = ($j('input[name=AutoClose]').val() == 1);
			var record_added_ok = (location.search.split('record-added-ok=').length == 2);
			var record_updated_ok = (location.search.split('record-updated-ok=').length == 2);
			if((record_added_ok || record_updated_ok) && embedded_mode && autoclose_mode) {
				setTimeout(AppGini.closeParentModal, 2000);
			}

			AppGini.once({
				condition: function() { return bkLib != undefined; },
				action: function() {
					if($j('textarea#notes').length) new nicEditor({ fullPanel : true }).panelInstance('notes');
				}
			});

			/* enable DV action buttons to float on scrolling down the form */
			enable_dvab_floating();

			if(!$j('.table_view').length || $j('[name=SelectedID]').val().length) {
				AppGini.once({
					condition: function() {
						return $j('.form-group.applications_leases-tenants')
									.find('.nicEdit-main, .select2-container, input[type=radio]')
									.length > 0
								// or read-only DV
								|| (!$j('#update').length && !$j('#insert').length);
					},
					action: function() {
						$j('#applications_leases_dv_container-loading').addClass('hidden');
						$j('#applications_leases_dv_container').removeClass('hidden');
						AppGini.focusFormElement('applications_leases', 'tenants');
					},
					timeout:  5000,
					doActionOnTimeout:  true
				});
			} else {
				$j('#applications_leases_dv_container-loading').addClass('hidden');
				$j('#applications_leases_dv_container').removeClass('hidden');
			}

			// try to detect rich text changes by adding 'input' handler after nicedit is loaded ...
			AppGini.detectContentEditableChanges();

			$j('a[href="<%%BASE_UPLOAD_PATH%%>"]').click(function() { return false; });


			if(true /* !embedded_mode */) {
				$j('.add_new_parent').click(function() {
					var pt = $j(this).attr('id').replace(/_add_new$/, '');
					modal_window({
						url: pt + '_view.php?addNew_x=1&Embedded=1',
						close: function() {
							var field_id = $j('#' + pt + '_add_new').prevAll('input:hidden').eq(0).attr('id');
							$j('#' + field_id + '-container').select2('focus').select2('focus');

							/* if a new parent was added, select it */
							var new_id = localStorage.getItem(pt + '_last_added_id');
							if(new_id === null) return;

							localStorage.removeItem(pt + '_last_added_id');
							AppGini.lookupText({
								id: new_id,
								table: 'applications_leases',
								field: field_id,
								callback: function(data) {
									$j('#' + field_id + '-container').select2('data', data, true);
								}
							});
						},
						size: 'full',
						title: $j(this).attr('title')
					});
				});
			}

			AppGini.hideViewParentLinks();

			$j('form').on('click', '.view_parent', function() {
				var pt = $j(this).attr('id').replace(/_view_parent$/, '');
				if($j(this).prevAll('input:hidden').length) {
					var parent_id = $j(this).prevAll('input:hidden').eq(0).val();
				} else {
					var parent_id = $j(this).prevAll().children('input:hidden').eq(0).val();
				}

				/* handle radio lookups */
				if($j(this).prevAll('[type=radio]').length) {
					parent_id = $j(this).prevAll('[type=radio]').eq(0).val();
				}

				if(parent_id != '{empty_value}' && parent_id != undefined && parent_id != '') {
					var parent_link = $j(this).parents('.form-group').children('label').data('parent_link');
					switch(parent_link) {
						case 'view_parent_hidden':
							break;
						case 'view_parent_modal':
							modal_window({
								url: pt + '_view.php?Embedded=1&SelectedID=' + encodeURIComponent(parent_id),
								close: function() {
									var field_id = $j('#' + pt + '_view_parent').prevAll('input:hidden').eq(0).attr('id');
									$j('#' + field_id + '-container').select2('focus').select2('focus');

									// in case the parent record was updated, we should update auto-fills
									var updaterName = field_id + '_update_autofills';
									if(typeof(window[updaterName]) == 'function')
										window[updaterName]();
								},
								size: 'full',
								title: $j(this).attr('title')
							});
							break;
						case 'view_parent_same_window':
							window.location = pt + '_view.php?Embedded=' + (embedded_mode ? '1' : '') + '&SelectedID=' + encodeURIComponent(parent_id);
							break;
						case 'view_parent_new_window':
							window.open(pt + '_view.php?SelectedID=' + encodeURIComponent(parent_id));
							break;
					}

				}
			});

			applications_leasesUniqueFields.forEach(fieldName => enforce_uniqueness('applications_leases', fieldName));

			/* load admin tools for admin user */
			if(!add_new_mode) {
				$j('body').append('<div id="admin-tools-appendix"></div>');
				$j('#admin-tools-appendix').load(
					'ajax_admin_tools.php?table=applications_leases&id=<%%URLVALUE(id)%%>',
					function(resp) {
						if(!resp.length) return;
						$j.ajax('ajax_admin_tools.php?action=get_admin_tools_js&table=applications_leases&id=<%%URLVALUE(id)%%>');
					}
				);
			}
		});

		var applications_leasesUniqueFields = [
		];
	</script>