<!-- Edit this file to change the layout of the detail view form -->

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

<div class="panel-body" id="applicants_and_tenants_dv_container">
	<!-- child links -->
	<div class="row vspacer-md">
		<div class="col-xs-12">
			<a class="hidden-xs btn btn-default btn-lg pull-right hidden hspacer-sm" href="applications_leases_view.php?filterer_tenants=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="applications_leases_link"><i class="glyphicon glyphicon-list-alt"></i> Applications/Leases</a>
			<a class="visible-xs btn btn-default btn-lg btn-block hidden vspacer-sm" href="applications_leases_view.php?filterer_tenants=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="xs_applications_leases_link"><i class="glyphicon glyphicon-list-alt"></i> Applications/Leases</a>
			<input type="hidden" id="applications_leases_hclink" value="applications_leases_view.php?filterer_tenants=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>">
			<a class="hidden-xs btn btn-default btn-lg pull-right hidden hspacer-sm" href="residence_and_rental_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="residence_and_rental_history_link"><i class="glyphicon glyphicon-list-alt"></i> Residence and rental history</a>
			<a class="visible-xs btn btn-default btn-lg btn-block hidden vspacer-sm" href="residence_and_rental_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="xs_residence_and_rental_history_link"><i class="glyphicon glyphicon-list-alt"></i> Residence and rental history</a>
			<input type="hidden" id="residence_and_rental_history_hclink" value="residence_and_rental_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>">
			<a class="hidden-xs btn btn-default btn-lg pull-right hidden hspacer-sm" href="employment_and_income_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="employment_and_income_history_link"><i class="glyphicon glyphicon-list-alt"></i> Employment and income history</a>
			<a class="visible-xs btn btn-default btn-lg btn-block hidden vspacer-sm" href="employment_and_income_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="xs_employment_and_income_history_link"><i class="glyphicon glyphicon-list-alt"></i> Employment and income history</a>
			<input type="hidden" id="employment_and_income_history_hclink" value="employment_and_income_history_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>">
			<a class="hidden-xs btn btn-default btn-lg pull-right hidden hspacer-sm" href="references_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="references_link"><i class="glyphicon glyphicon-list-alt"></i> References</a>
			<a class="visible-xs btn btn-default btn-lg btn-block hidden vspacer-sm" href="references_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>" id="xs_references_link"><i class="glyphicon glyphicon-list-alt"></i> References</a>
			<input type="hidden" id="references_hclink" value="references_view.php?filterer_tenant=<%%URLVALUE(id)%%>&<%%EMBEDDED%%>">
			<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="applicants_and_tenants_dv_form">
			<fieldset class="form-horizontal">

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

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="last_name" class="control-label col-lg-3">Last name</label>
					<div class="col-lg-9">
						<input maxlength="15" type="text" class="form-control" name="last_name" id="last_name" value="<%%VALUE(last_name)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="first_name" class="control-label col-lg-3">First name</label>
					<div class="col-lg-9">
						<input maxlength="15" type="text" class="form-control" name="first_name" id="first_name" value="<%%VALUE(first_name)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="email" class="control-label col-lg-3">Email</label>
					<div class="col-lg-9">
						
						<div>
							<a id="email-link" href="mailto:<%%VALUE(email)%%>" target="_blank"><i class="glyphicon glyphicon-envelope text-info" title="<%%VALUE(email)%%>"></i></a>
							<label for="email"><button type="button" id="email-edit-link" class="btn btn-default hspacer-lg vspacer-sm" data-toggle="collapse" data-target="#email" title="<%%TRANSLATION(Edit)%%>"><i class="glyphicon glyphicon-pencil"></i></button></label>
						</div>
						<script>jQuery(function(){ var e_email = '<%%VALUE(email)%%>'; if(e_email == '' || e_email == '&nbsp;' || e_email == 'blank.gif') jQuery('#email-link').hide(); });</script><input maxlength="80" type="text" class="form-control collapse" name="email" id="email" value="<%%VALUE(email)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="phone" class="control-label col-lg-3">Phone</label>
					<div class="col-lg-9">
						<input maxlength="15" type="text" class="form-control" name="phone" id="phone" value="<%%VALUE(phone)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="birth_date" class="control-label col-lg-3">Birth date</label>
					<div class="col-lg-9">
						<%%COMBO(birth_date)%%>
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="driver_license_number" class="control-label col-lg-3">Driver license number</label>
					<div class="col-lg-9">
						<input maxlength="15" type="text" class="form-control" name="driver_license_number" id="driver_license_number" value="<%%VALUE(driver_license_number)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="monthly_gross_pay" class="control-label col-lg-3">Monthly gross pay</label>
					<div class="col-lg-9">
						<input maxlength="11" type="text" class="form-control" name="monthly_gross_pay" id="monthly_gross_pay" value="<%%VALUE(monthly_gross_pay)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="additional_income" class="control-label col-lg-3">Additional income</label>
					<div class="col-lg-9">
						<input maxlength="11" type="text" class="form-control" name="additional_income" id="additional_income" value="<%%VALUE(additional_income)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="assets" class="control-label col-lg-3">Assets</label>
					<div class="col-lg-9">
						<input maxlength="11" type="text" class="form-control" name="assets" id="assets" value="<%%VALUE(assets)%%>">
					</div>
				</div>

				<div class="form-group">
					<hr class="hidden-md hidden-lg">
					<label for="status" class="control-label col-lg-3">Status<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<%%COMBO(status)%%>
					</div>
				</div>

			</fieldset>
		</div>

		<!-- DV action buttons -->
		<hr class="hidden-md hidden-lg">
		<div class="col-md-4 col-lg-2" id="applicants_and_tenants_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>


	<!-- child records -->
	<hr>
	<div class="row">
		<div class="col-lg-10 col-lg-offset-1">
			<div id="applicants_and_tenants-children" class="children-tabs"></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);
			}

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

			if(!(embedded_mode && AppGini.mobileDevice())){
				$j('select, input[type=text], textarea').not(':disabled').eq(0).focus();
			}

			$j('form').eq(0).change(function(){
				if($j(this).data('already_changed')) return;
				if($j('#deselect').length) $j('#deselect').removeClass('btn-default').addClass('btn-warning').get(0).lastChild.data = " <%%TRANSLATION(Cancel)%%>";
				$j(this).data('already_changed', true);
			});

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

			if(embedded_mode){
				/* hide links to children tables in embedded mode */
				$j('.detail_view a[id$=_link]').remove();

				/* append embedded mode to all links */
				var append_embedded = function(){
					$j('a[href]:not([href^="#"]):not([href^="javascript"]):not([href$="Embedded=1"]):not([href*="link.php?t="]):not([href^="mailto:"])').each(
						function(){
							$j(this).attr('href', $j(this).attr('href') + '&Embedded=1');
						}
					);
				}
				setTimeout(append_embedded, 500);
				setTimeout(append_embedded, 1500);
				setTimeout(append_embedded, 2500);
				setTimeout(append_embedded, 3500);
			}

			/* when no record is selected ('add new' mode) */
			if(add_new_mode){
				/* hide links to children tables */
				$j('.detail_view a[id$=_link]').remove();
			}else{
				post(
					'parent-children.php', {
						ParentTable: 'applicants_and_tenants',
						SelectedID: '<%%VALUE(id)%%>',
						Operation: 'show-children'
					},
					'applicants_and_tenants-children'
				);
			}

			if(!embedded_mode){
				/* add a horizontal spacer to [add new parent] buttons that don't have a spacered element before them */
				$j('.add_new_parent').prev(':not(.hspacer-md)').next().addClass('hspacer-md');

				$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');
						},
						size: 'full',
						title: $j(this).attr('title')
					});
				});
			}

			/* find and hide parent links if field label has data 'parent_link' set to 'view_parent_hidden' */
			$j('label[data-parent_link=view_parent_hidden]').each(function(){
				$j(this).parents('.form-group').find('.view_parent').hide();
			});

			$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');
								},
								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;
					}

				}
			});


			/* 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=applicants_and_tenants&id=<%%URLVALUE(id)%%>',
					function(resp){
						if(!resp.length) return;
						$j.ajax('ajax_admin_tools.php?action=get_admin_tools_js&table=applicants_and_tenants&id=<%%URLVALUE(id)%%>');
					}
				);
			}

			/* warn user if 'add new' clicked while unsaved changes exist */
			$j('#addNew').click(function(){
				if($j('#deselect.btn-warning').length){
					return confirm('<%%TRANSLATION(discard changes confirm)%%>');
				}
			});

		});
	</script>