<!-- To change the layout of the detail view form, we recommend using JS code in hooks/referencias_inativas-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="referencias_inativas_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="referencias_inativas_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="referencias_inativas_dv_form">
			<fieldset class="form-horizontal">

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

				<!-- Field: Nome -->
				<div class="form-group referencias_inativas-nome">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="nome">Nome<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="nome" id="nome" value="<%%VALUE(nome)%%>" required>
					</div>
				</div>

				<!-- Field: CPF -->
				<div class="form-group referencias_inativas-cpf">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="cpf">CPF<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="cpf" id="cpf" value="<%%VALUE(cpf)%%>" required>
					</div>
				</div>

				<!-- Field: Celular -->
				<div class="form-group referencias_inativas-celular">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="celular">Celular<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="celular" id="celular" value="<%%VALUE(celular)%%>" required>
					</div>
				</div>

				<!-- Field: E-mail -->
				<div class="form-group referencias_inativas-email">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="email">E-mail<span class="text-danger"><%%TRANSLATION(*)%%></span></label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="email" id="email" value="<%%VALUE(email)%%>" required>
					</div>
				</div>

				<!-- Field: Cidade -->
				<div class="form-group referencias_inativas-cidade">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="cidade">Cidade</label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="cidade" id="cidade" value="<%%VALUE(cidade)%%>">
					</div>
				</div>

				<!-- Field: UF -->
				<div class="form-group referencias_inativas-uf">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="uf">UF</label>
					<div class="col-lg-9">
						<%%COMBO(uf)%%>
					</div>
				</div>

				<!-- Field: Regi&#227;o/UF -->
				<div class="form-group referencias_inativas-regiao">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="regiao">Regi&#227;o/UF</label>
					<div class="col-lg-9">
						<%%COMBO(regiao)%%>
					</div>
				</div>

				<!-- Field: Qdade -->
				<div class="form-group referencias_inativas-quantidade">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="quantidade">Qdade</label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="quantidade" id="quantidade" value="<%%VALUE(quantidade)%%>">
					</div>
				</div>

				<!-- Field: Unidade -->
				<div class="form-group referencias_inativas-unidade">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="unidade">Unidade</label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="unidade" id="unidade" value="<%%VALUE(unidade)%%>">
					</div>
				</div>

				<!-- Field: UTA -->
				<div class="form-group referencias_inativas-uta">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="uta">UTA</label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="uta" id="uta" value="<%%VALUE(uta)%%>">
					</div>
				</div>

				<!-- Field: Valor -->
				<div class="form-group referencias_inativas-valor">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="valor">Valor</label>
					<div class="col-lg-9">
						<input maxlength="80" type="text" class="form-control" name="valor" id="valor" value="<%%VALUE(valor)%%>">
					</div>
				</div>

				<!-- Field: Observa&#231;&#227;o -->
				<div class="form-group referencias_inativas-obs">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="obs">Observa&#231;&#227;o</label>
					<div class="col-lg-9">
						<textarea class="form-control" name="obs" id="obs" rows=" 5"><%%VALUE(obs)%%></textarea>
					</div>
				</div>

				<!-- Field: Situa&#231;&#227;o -->
				<div class="form-group referencias_inativas-situacao">
					<hr class="hidden-md hidden-lg">
					<label class="control-label col-lg-3" for="situacao">Situa&#231;&#227;o</label>
					<div class="col-lg-9">
						<%%COMBO(situacao)%%>
					</div>
				</div>

			</fieldset>
		</div>

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

	<input type="hidden" name="id_categoria" value="<%%VALUE(id_categoria)%%>">

</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();

			$j('#referencias_inativas_dv_container-loading').addClass('hidden');
			$j('#referencias_inativas_dv_container').removeClass('hidden');
			if(!$j('.table_view').length || $j('[name=SelectedID]').val().length) AppGini.focusFormElement('referencias_inativas', 'nome');

			$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="<%%BASE_UPLOAD_PATH%%>"]').click(function() { return false; });


			if(true /* !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');

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