<!--// $Id$ //-->
{$restrictive_sensitive_data_access = ConfigHelper::checkConfig('customers.restrictive_sensitive_data_access')}
{$unsecure_pin_validity = intval(ConfigHelper::getConfig('customers.unsecure_pin_validity', ConfigHelper::getConfig('phpui.unsecure_pin_validity', 0, true), true))}
{$pin_tip = ConfigHelper::getConfig('customers.pin_restriction_description', ConfigHelper::getConfig('phpui.pin_restriction_description'))}
{if !empty($unsecure_pin_validity)}
	{$pin_tip = ConfigHelper::getConfig('customers.unsecure_pin_restriction_description', $pin_tip)}
{/if}
{if !$pin_tip}
	{if empty($unsecure_pin_validity)}
		{if $pin_min_size == $pin_max_size}
			{$pin_tip = trans("Enter \$a characters PIN code", $pin_min_size)}
		{else}
			{$pin_tip = trans("Enter \$a to \$b characters PIN code", $pin_min_size, $pin_max_size)}
		{/if}
	{else}
		{if $unsecure_pin_min_size == $unsecure_pin_max_size}
			{$pin_tip = trans("Enter \$a characters PIN code", $unsecure_pin_min_size)}
		{else}
			{$pin_tip = trans("Enter \$a to \$b characters PIN code", $unsecure_pin_min_size, $unsecure_pin_max_size)}
		{/if}
	{/if}
{/if}
{if !empty($unsecure_pin_validity)}
	{capture assign="pin_tip"}{strip}
		{$pin_tip}
		<br><br>
		<strong>{trans("If you leave this field empty, then PIN will not change!")}</strong>
	{/strip}{/capture}
{/if}
<script type="text/javascript" src="js/location_box_expandable.js"></script>
<style>

	.cell-flex {
		display: flex;
		flex-wrap: wrap;
	}

	@media screen and (max-width: 470px) {
		.lms-ui-address-box tr {
			display: flex;
			flex-wrap: wrap;
		}

		.cell-flex  > div textarea{
			max-width: 190px;
		}

		.lms-ui-wysiwyg-editor textarea{
			max-width: 230px;
		}
	}

	#paytime-cell .scombobox {
		width: 11em;
	}

	.consent-label {
		cursor: pointer;
	}

	.identity-document-box {
		padding-left: 0 !important;
	}

	.identity-document-properties {
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
	}

	.identity-document-property {
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
	}

	.identity-document-property > * {
		margin-top: 0.25em;
		margin-bottom: 0.25em;
	}

	.identity-document-property > input[type] {
		margin-left: 0;
	}

	.identity-document-property > select {
		margin-left: 0;
	}

	.customeredit-button-panel {
		display: flex;
		flex-direction: column;
	}

	.customeredit-buttons {
		display: flex;
		flex-wrap: wrap;
	}

	.customeredit-buttons > *:not(:first-child) {
		margin-left: 0.3em;
	}

</style>

{include file="customer/customercompanyselectiondialog.html"}

<FORM name="customeredit" id="customeredit" method="post" action="?m=customeredit&id={$customerinfo.id}{if $recover}&action=recover{/if}">
<INPUT type="hidden" name="customerdata[id]" value="{$customerinfo.id}">
<INPUT type="submit" class="hiddenbtn">

<TABLE class="lmsbox">
	<THEAD>
	<TR>
		<TD class="lmsbox-panels">
			<div class="lmsbox-panel">
				<table>
					<colgroup>
						<col style="width: 1%;">
						<col style="width: 99%;">
					</colgroup>
					<tr>
						<td>
							<label for="customerdata[lastname]">
								<strong>{trans("Name/Surname")}</strong>
							</label>
						</td>
						<td>
							<div class="valign-middle">
								<input type="text" name="customerdata[lastname]" maxlength="128"
									value="{$customerinfo.lastname|escape}" required
									{tip class="lms-ui-autogrow" trigger="lastname" bold=1}>
								{hint content="Enter first/lastname of customer"}
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<label for="customerdata[name]">
								<strong>{trans("First name")}</strong>
							</label>
						</td>
						<td>
							<div class="valign-middle">
								<input type="text" name="customerdata[name]" value="{$customerinfo.name|escape}"
									maxlength="128"
									{tip class="lms-ui-autogrow" trigger="name" bold=1}>
								{hint content="Enter first name of customer (optional)"}
							</div>
						</td>
					</tr>
				</table>
			</div>
			<div class="lmsbox-panel">
				<table>
					<tr>
						<td>
							<label for="extid">
								<strong>{trans("External system identifier")}</strong>
							</label>
						</td>
						<td>
							<div class="valign-middle">
								<input type="hidden" name="customerdata[extids][0][serviceproviderid]" value="0">
								<input type="text" id="extid" class="lms-ui-autogrow" name="customerdata[extids][0][extid]" value="{$customerinfo.extids[0].extid|escape}"
									{tip trigger="extid"}>
								{hint content="Enter customer identifier in external system (optional)"}
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<label for="altname">
								<strong>{trans("Alternative name")}</strong>
							</label>
						</td>
						<td>
							<div class="valign-middle">
								<input type="text" id="altname" class="lms-ui-autogrow" name="customerdata[altname]" maxlength="128" value="{$customerinfo.altname|escape}"}>
								{hint content="Customer Alternative name (brand, shortname, casual name)"}
							</div>
						</td>
					</tr>
				</table>
			</div>
		</TD>
	</TR>
	</THEAD>
	<TBODY>
	<TR>
		<TD class="lmsbox-panels">
			<div class="lmsbox-panel">
				<TABLE>
					<COLGROUP>
						<COL style="width: 1%;">
						<COL style="width: 99%;">
					</COLGROUP>
					{block name="customereditbox-leftcolumn"}
					<TR>
						<TD>
							<i class="lms-ui-icon-customer-status-{$_CSTATUSES[$customerinfo.status].alias}"></i>
						</TD>
						<TD>
							<select size="1" name="customerdata[status]" {tip trigger="status"}>
								{foreach $_CSTATUSES as $statusidx => $status}
									<option value="{$statusidx}"{if $customerinfo.status == $statusidx} selected{/if}>{$status.singularlabel}</option>
								{/foreach}
							</select>
						</TD>
					</TR>
					<tr>
						<td>
							{icon name="origin" class="fa-fw"}
						</td>
						<td>
							<select size="1" name="customerdata[origin]" {tip trigger="origin"}>
								<option value="">{trans("<!origin>— unspecified —")}</option>
								{foreach Localisation::arraySort($_ORIGINS) as $originidx => $origin}
									<option value="{$originidx}"{if $customerinfo.origin == $originidx} selected{/if}>{$origin}</option>
								{/foreach}
							</select>
						</td>
					</tr>
					{if $divisions}
					<TR>
						<TD>
							<i class="lms-ui-icon-division"></i>
						</TD>
						<TD>
							<select size="1" name="customerdata[divisionid]" {tip trigger="divisionid"}>
								{foreach $divisions as $item}
									{if !$item.status || $item.id == $customerinfo.divisionid}
										<option value="{$item.id}"{if $customerinfo.divisionid == $item.id} selected{/if}>{$item.label|escape}</option>
									{/if}
								{/foreach}
							</select>
						</TD>
					</TR>
					{/if}
					<TR>
						<TD>
							<i class="lms-ui-icon-legal-personality"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<label>
									<input type="radio" name="customerdata[type]" value="{$smarty.const.CTYPES_PRIVATE}" id="private"
										{tip trigger="type"}
										{if $customerinfo.type == $smarty.const.CTYPES_PRIVATE} checked{/if}>
									{$_CTYPES[$smarty.const.CTYPES_PRIVATE]}
								</label>
								<label>
									<input type="radio" name="customerdata[type]" value="{$smarty.const.CTYPES_COMPANY}" id="company"
										{tip trigger="type"}
										{if $customerinfo.type == $smarty.const.CTYPES_COMPANY} checked{/if}>
									{$_CTYPES[$smarty.const.CTYPES_COMPANY]}
								</label>
								{hint content="Select legal personality type"}
							</div>
						</TD>
					</TR>

					<TR>
						<TD>
							<i class="lms-ui-icon-legal-personality"></i>
						</TD>
						<TD>
							<select name="customerdata[flags][]" {tip text="Select customer flags (optional)" class="lms-ui-multiselect"}
								multiple>
								{foreach Localisation::arraySort($_CUSTOMERFLAGS, 'label') as $cflag => $flag}
									<option value="{$cflag}"
											{if is_array($customerinfo.flags) && in_array($cflag, $customerinfo.flags)} selected{/if}
											title="{$flag.tip}"
									>{$flag.label}</option>
								{/foreach}
							</select>
						</TD>
					</TR>

					{$addr_counter = 0}

					<tr>
						<td class="valign-top"><i class="lms-ui-icon-home fa-fw" title="{trans('billing address')}"></i></td>
						<td>
							{foreach $customerinfo.addresses as $v}
								{if $v.location_address_type == $smarty.const.BILLING_ADDRESS}
									{$v.prefix = "customerdata[addresses]["|cat:$addr_counter|cat:"]"}
									{$addr_counter = $addr_counter + 1}
									{$v.hide_name=true}
									{location_box_expandable data=$v}
								{/if}
							{/foreach}
						</td>
						<script type="text/javascript">
				/*
							var formid = $('form[name="customeredit"]').get(0);
							new AutoSuggest(formid, $('input[name="customerdata[addresses][0][location_street_name]"]').get(0),
								'?m=customeradd&ajax=1&mode=street&what=', 0);
							new AutoSuggest(formid, $('input[name="customerdata[addresses][0][location_city_name]"]').get(0),
								'?m=customeradd&ajax=1&mode=city&what=', 0);
							new AutoSuggest(formid, $('input[name="customerdata[addresses][0][location_zip]"]').get(0),
								'?m=customeradd&ajax=1&mode=zip&what=', 0);
				*/
						</script>
					</tr>

					<tr>
						<td class="valign-top"><i class="lms-ui-icon-message fa-fw" alt="" title="{trans('postal address')}"></i></td>
						<td>
							{$postal_addr = 0}
							{foreach $customerinfo.addresses as $v}
								{if $v.location_address_type == $smarty.const.POSTAL_ADDRESS}
									{$v.prefix = "customerdata[addresses]["|cat:$addr_counter|cat:"]"}
									{$addr_counter = $addr_counter + 1}
									{$postal_addr = 1}
									{location_box_expandable data=$v}
								{/if}
							{/foreach}

							{* if postal address is not set *}
							{if $postal_addr == 0}
								{$tmp['location_address_type'] = $smarty.const.POSTAL_ADDRESS}
								{$tmp['prefix'] = "customerdata[addresses]["|cat:$addr_counter|cat:"]"}
								{$addr_counter = $addr_counter + 1}
								{location_box_expandable data=$tmp}
							{/if}
						</td>
						<script type="text/javascript">
				/*
							new AutoSuggest(formid, $('input[name="customerdata[addresses][1][location_street_name]"]').get(0),
								'?m=customeradd&ajax=1&mode=street&what=', 0);
							new AutoSuggest(formid, $('input[name="customerdata[addresses][1][location_city_name]"]').get(0),
								'?m=customeradd&ajax=1&mode=city&what=', 0);
							new AutoSuggest(formid, $('input[name="customerdata[addresses][1][location_zip]"]').get(0),
								'?m=customeradd&ajax=1&mode=zip&what=', 0);
				*/
						</script>
					</tr>

					{foreach $customerinfo.addresses as $v}
						{if $v.location_address_type != $smarty.const.BILLING_ADDRESS && $v.location_address_type != $smarty.const.POSTAL_ADDRESS }
						<tr>
							<td class="valign-top">
								{if $v.location_address_type == $smarty.const.DEFAULT_LOCATION_ADDRESS}
									<i class="lms-ui-icon-default-customer-location fa-fw location-box-image" title="{trans('default location address')}"></i>
								{else}
									<i class="lms-ui-icon-customer-location fa-fw location-box-image" title="{trans('location/recipient address')}"></i>
								{/if}
							</td>
							<td>
								{$v.prefix = "customerdata[addresses]["|cat:$addr_counter|cat:"]"}
								{$address_idx = $addr_counter}
								{$v.default_type = 1}
								{$v.delete_button = 1}
								{$v.billing_address_button = 1}
								{$v.post_address_button = 1}
								{$addr_counter = $addr_counter + 1}
								{location_box_expandable data=$v}
							</td>
							<script type="text/javascript">
				/*
								new AutoSuggest(formid, $('input[name="customerdata[addresses][{$address_idx}][location_street_name]"]').get(0),
									'?m=customeradd&ajax=1&mode=street&what=', 0);
								new AutoSuggest(formid, $('input[name="customerdata[addresses][{$address_idx}][location_city_name]"]').get(0),
									'?m=customeradd&ajax=1&mode=city&what=', 0);
								new AutoSuggest(formid, $('input[name="customerdata[addresses][{$address_idx}][location_zip]"]').get(0),
									'?m=customeradd&ajax=1&mode=zip&what=', 0);
				*/
							</script>
						</tr>
						{/if}
					{/foreach}

					<tr>
						<td></td>
						<td>
							{button class="lms-ui-location-add-button" icon="add" label="Add address" data_prefix="customerdata"}
						</td>
					</tr>

					{include file="customer/customercontacts.html" customerinfo=$customerinfo formelemprefix="customerdata"}
					<TR>
						<TD>
							<i class="lms-ui-icon-customer-pin-code"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<input type="text" {if empty($unsecure_pin_validity)} required{/if}
									name="customerdata[pin]" size="{$pin_max_size}"
									value="{if $customerinfo.pin && (empty($unsecure_pin_validity) || !$customerinfo.secure_pin)}{$customerinfo.pin}{/if}" {tip trigger="pin"}>
								{button type="link" icon="next" id="randomize" tip="Generate PIN"}
								{hint text=$pin_tip}
							</div>
						</TD>
					</TR>
					<tr>
						<td class="valign-top">
							{icon name="user-id-number"}
						</td>
						<td class="cell-flex">
							<div>
								<table class="user-id-number">
									<colgroup>
										<col style="width: 1%;">
										<col style="width: 99%;">
									</colgroup>
									{if !ConfigHelper::checkPrivilege('hide_customer_sensitive_data', !$restrictive_sensitive_data_access)}
										<tr>
											<td colspan="2" class="identity-document-box">
												<fieldset>
													<legend class="bold">
														{trans("Identity document")}
													</legend>
													<div class="identity-document-properties">
														<label class="identity-document-property">
															<span>{trans("Type")}</span>
															{identitytypes elemname="customerdata[ict]" selected=$customerinfo.ict
																tip="" trigger="ict"}
														</label>
														<label class="identity-document-property">
															<span>{trans("Number")}</span>
															{if $customerinfo.icnwarning}
																<input type="hidden" name="customerdata[icnwarning]" value="1">
															{/if}
															{if ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access)}
																{$icn = $customerinfo.icn}
																{$disabled = false}
															{else}
																{$icn = preg_replace('/[^\s]/', '*', $customerinfo.icn)}
																{$disabled = true}
															{/if}
															<input type="text" value="{$icn}" name="customerdata[icn]" size="30"
																class="customer-sensitive-data" data-type="icn"
																{tip trigger="icn"}
																{if $disabled} disabled{/if}>
														</label>
														<label class="identity-document-property">
															<span>{trans("Expires")}</span>
															<input type="text" value="{if $customerinfo.icexpires > 0}{$customerinfo.icexpires}{/if}"
																name="customerdata[icexpires]" size="10" id="icexpires"
																class="lms-ui-date lms-ui-date-unix"
																{tip trigger="icexpires"}
																{if $customerinfo.icexpires == -1}disabled{/if}>
														</label>
														<label>
															<input type="checkbox" name="customerdata[icexpires]"
																id="icexpires-indefinitely"
																value="-1"{if $customerinfo.icexpires == -1} checked{/if}
																{tip trigger="icexpires-indefinitely"}>
															{trans("indefinitely")}
														</label>
													</div>
												</fieldset>
											</td>
										</tr>
										<tr>
											<td>
												{trans("SSN")}
											</td>
											<td>
												{if ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access)}
													{$ssn = $customerinfo.ssn}
													{$disabled = false}
												{else}
													{$ssn = preg_replace('/[^\s]/', '*', $customerinfo.ssn)}
													{$disabled = true}
												{/if}
												<input type="text" name="customerdata[ssn]" value="{$ssn}" size="30"
													data-type="ssn"
													{tip trigger="ssn" class="customer-sensitive-data"}
													{if $disabled} disabled{/if}>
												{if $customerinfo.ssnwarning}
													<input type="hidden" name="customerdata[ssnwarning]" value="1">
												{/if}
												{if $customerinfo.ssnexistencewarning}
													<input type="hidden" name="customerdata[ssnexistencewarning]" value="1">
												{/if}
											</td>
										</tr>
									{/if}
									<tr>
										<td>{trans("TEN")}</td>
										<td>
											<input type="text" name="customerdata[ten]" value="{$customerinfo.ten}" size="30"
												{tip trigger="ten"}>
											{if $customerinfo.tenwarning}
												<input type="hidden" name="customerdata[tenwarning]" value="1">
											{/if}
											{if $customerinfo.tenexistencewarning}
												<input type="hidden" name="customerdata[tenexistencewarning]" value="1">
											{/if}
											{button type="link" icon="division" class="gusapi-button"
												data_type=Utils::GUS_REGON_API_SEARCH_TYPE_TEN
												tip="Click here to autocomplete company data from GUS REGON database"}
										</td>
									</tr>
									<tr>
										<td>{trans("REGON")}</td>
										<td>
											<input type="text" value="{$customerinfo.regon}" name="customerdata[regon]" size="30"
												{tip trigger="regon"}>
											{button type="link" icon="division" class="gusapi-button"
												data_type=Utils::GUS_REGON_API_SEARCH_TYPE_REGON
												tip="Click here to autocomplete company data from GUS REGON database"}
										</td>
									</tr>
								</table>
							</div>
						</td>
					</tr>
					<tr>
						<td class="valign-top">
							{icon name="user-id-number"}
						</td>
						<td class="cell-flex identity-document-box">
							<div>
								<fieldset>
									<legend class="bold">
										{trans("Business register")}
									</legend>
									<div class="identity-document-properties">
										<label class="identity-document-property">
											<span>
												{trans("Name")}
												{hint content="Enter National Court Register / Register of Business Entities Name (optional)"}
											</span>
											<textarea name="customerdata[rbename]" cols="45" rows="4"
												{tip trigger="rbename"}
												>{$customerinfo.rbename|escape}</textarea>
										</label>
										<label class="identity-document-property">
											<span>
												{trans("Number")}
												{hint content="Enter National Court Register / Register of Business Entities Number (optional)"}
											</span>
											<span>
												<input type="text" value="{$customerinfo.rbe}" name="customerdata[rbe]" size="30"
													{tip trigger="rbe"}>
												{button type="link" icon="division" class="gusapi-button"
													data_type=Utils::GUS_REGON_API_SEARCH_TYPE_RBE
													tip="Click here to autocomplete company data from GUS REGON database"}
											</span>
										</label>
									</div>
								</fieldset>
							</div>
						</td>
					</tr>
					<TR>
						<TD class="valign-top">
							<i class="lms-ui-icon-paytype"></i>
						</TD>
						<TD>
							<TABLE>
								<TR>
									<TD>
										{trans("Deadline")}
									</TD>
									<TD id="paytime-cell">
										<div class="valign-middle">
											<select name="customerdata[paytime]" data-value="{$customerinfo.paytime}"
												{tip class="lms-ui-combobox" trigger="paytime"}>
												<option value="-1"{if $customerinfo.paytime == -1} selected{/if}>— {trans("default")} —</option>
												<option value="0"{if $customerinfo.paytime == 0} selected{/if}>0</option>
												<option value="7"{if $customerinfo.paytime == 7} selected{/if}>7</option>
												<option value="10"{if $customerinfo.paytime == 10} selected{/if}>10</option>
												<option value="14"{if $customerinfo.paytime == 14} selected{/if}>14</option>
												<option value="21"{if $customerinfo.paytime == 21} selected{/if}>21</option>
												<option value="30"{if $customerinfo.paytime == 30} selected{/if}>30</option>
												<option value="60"{if $customerinfo.paytime == 60} selected{/if}>60</option>
												<option value="90"{if $customerinfo.paytime == 90} selected{/if}>90</option>
											</select>
											{hint content="Select default deadline in days"}
										</div>
									</TD>
								</TR>
								<TR>
									<TD>
										{trans("Payment type")}
									</TD>
									<TD>
										<div class="valign-middle">
											{paytypes elemname="customerdata[paytype]" selected=$customerinfo.paytype
												trigger="paytype"}
											{hint content="Select default invoices payment type"}
										</div>
									</TD>
								</TR>
								<TR>
									<TD>
										{trans("Cutoff suspending")}
									</TD>
									<TD>
										<div class="valign-middle nobr">
											<label>
												<input type="checkbox" name="customerdata[cutoffstopindefinitely]"
													id="cutoffstopindefinitely" value="1"
													{if $customerinfo.cutoffstopindefinitely} checked{/if}>
												{trans("indefinitely")}
											</label>&nbsp;
										</div>
										<div class="valign-middle nobr cutoffstop">
											<input type="text" name="customerdata[cutoffstop]" id="cutoffstop"
												{if $customerinfo.cutoffstopindefinitely}style="display: none;"{elseif $customerinfo.cutoffstop}value="{$customerinfo.cutoffstop}"{/if}
												size="10" {tip class="lms-ui-date" trigger="cutoffstop"}>
											{day_selection elem="#cutoffstop" days="3,7,10,14"}
										</div>
										<div class="valign-middle nobr">
											{hint content="Select date of cutoff suspending (optional)"}
										</div>
									</TD>
								</TR>
							</TABLE>
						</TD>
					</TR>
					<tr>
						<TD class="valign-top">
							<i class="lms-ui-icon-consent"></i>
						</TD>
						<TD>
							{include file="customer/customerconsents.html" variable_prefix="customerdata" variables=$customerinfo}
						</TD>
					</TR>
					{/block}
				</TABLE>
			</div>
			<div class="lmsbox-panel">
				<TABLE>
					<COLGROUP>
						<COL style="width: 1%;">
						<COL style="width: 99%;">
					</COLGROUP>
					{block name="customereditbox-rightcolumn"}
					<TR>
						<TD>
							<i class="lms-ui-icon-optional-info"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<textarea name="customerdata[info]" class="lms-ui-wysiwyg-editor" cols="60" rows="10"
									{if isset($customerinfo.wysiwyg.info)} data-wysiwyg="{$customerinfo.wysiwyg.info}"{/if}
									>{$customerinfo.info|default:""|escape}</textarea>
								{hint content="Enter additional information (optional)"}
							</div>
						</TD>
					</TR>
					<TR>
						<TD>
							<i class="lms-ui-icon-warning"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<textarea name="customerdata[message]" class="lms-ui-wysiwyg-editor" cols="60" rows="10"
									{if isset($customerinfo.wysiwyg.message)} data-wysiwyg="{$customerinfo.wysiwyg.message}"{/if}>{$customerinfo.message|default:""|escape}</textarea>
								{hint content="Enter notice contents (optional)"}
							</div>
						</TD>
					</TR>
					<TR>
						<TD>
							<i class="lms-ui-icon-notes"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<textarea name="customerdata[notes]" class="lms-ui-wysiwyg-editor" cols="60" rows="10"
									{if isset($customerinfo.wysiwyg.notes)} data-wysiwyg="{$customerinfo.wysiwyg.notes}"{/if}
									>{$customerinfo.notes|default:""|escape}</textarea>
								{hint content="Enter notes (optional)"}
							</div>
						</TD>
					</TR>
					<TR>
						<TD>
							<i class="lms-ui-icon-memo"></i>
						</TD>
						<TD>
							<div class="valign-middle">
								<textarea name="customerdata[documentmemo]" class="lms-ui-wysiwyg-editor"
									cols="60" rows="10"
									{if isset($customerinfo.wysiwyg.documentmemo)} data-wysiwyg="{$customerinfo.wysiwyg.documentmemo}"{/if}
									>{$customerinfo.documentmemo|default:""|escape}</textarea>
								{hint content="Enter document memo (optional)"}
							</div>
						</TD>
					</TR>
					<TR>
						<TD>
							<i class="lms-ui-icon-money"></i>
						</TD>
						<TD>
							<strong>{trans("Balance")}</strong>
							{if $customerinfo.balance < 0}
								<span class="lms-ui-alert">{moneyf($customerinfo.balance)}</span>
							{else}
								{moneyf($customerinfo.balance)}
							{/if}
						</TD>
					</TR>
					<TR>
						<TD>
							<i class="lms-ui-icon-modified-date"></i>
						</TD>
						<TD>
							<strong>{trans("Created")}</strong>
							{$customerinfo.createdby|escape}, {$customerinfo.creationdateh}
							<br>
							<strong>{trans("Modified")}</strong>
							{if $customerinfo.moddate}{$customerinfo.modifiedby|escape}, {$customerinfo.moddateh}{else}-{/if}
						</TD>
					</TR>
					{/block}
				</TABLE>
			</div>
		</TD>
	</TR>
	<TR>
		<TD style="width: 100%;" class="lms-ui-box-buttons">
			<div class="customeredit-button-panel">
				<div class="customeredit-buttons">
					{button type="submit" id="save-button" icon="save" label="Submit"}
					{button id="cancel-button" icon="cancel" label="Cancel" onclick="location.href = '{$backurl}';"}
				</div>
				{if !ConfigHelper::checkPrivilege('customer_sensitive_data_view', !$restrictive_sensitive_data_access) && !ConfigHelper::checkPrivilege('hide_customer_sensitive_data', !$restrictive_sensitive_data_access)}
					<div class="customeredit-buttons">
						{button icon="sensitive-data" label="Show sensitive data" id="customer-sensitive-data-button"}
					</div>
				{/if}
			</div>
		</TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>
<script>

	$('[name="customerdata[type]"]').change(function() {
		$('.gusapi-button').toggle(!$('#private').prop('checked'));
	}).filter(':checked').change();

	function init_email_validators() {
		$('[name^="customerdata[emails]"][value="16"]').off('click').click(function() {
			var checked = $(this).prop('checked');
			if (!$('#chkconsent{$smarty.const.CCONSENT_INVOICENOTICE}').prop('checked') && checked) {
				alertDialog($t("Customer has not checked \'electronic invoice\' consent and you are trying to mark this mail contact for invoice sending!"), this);
			}
		});
	}

	$(function() {
		$('form[name="customeredit"] [name="customerdata[lastname]"]').focus();

		$('[name="customerdata[pin]"]').change(function() {
			{if empty($unsecure_pin_validity)}
				if (validate_random_string(this.value, {$pin_min_size}, {$pin_max_size}, '{str_replace("'", "\'", $pin_allowed_characters)}')) {
					this.setCustomValidity('');
				} else {
					this.setCustomValidity('{$pin_tip}');
				}
			{else}
				if (validate_random_string(this.value, {$unsecure_pin_min_size}, {$unsecure_pin_max_size}, '{str_replace("'", "\'", $unsecure_pin_allowed_characters)}')) {
					this.setCustomValidity('');
				} else {
					this.setCustomValidity('{$pin_tip}');
				}
			{/if}
		});

		init_email_validators();

		$('.contacts[data-type="email"] .newcontact a').click(function() {
			init_email_validators();
		});

		$('.gusapi-button').click(function() {
			var identifier = $(this).siblings('input[type="text"]').val().replace(/-/g, '');
			if (!identifier.length) {
				return;
			}
			var that = this;
			GusApiGetCompanyDetails(
				$(this).attr('data-type'),
				identifier,
				function(data) {
					if (data.length > 1) {
						customerCompanySelectionDialog(data, that).done(function(company) {
							GusApiFinished('customerdata', company);
						});
					} else {
						GusApiFinished('customerdata', data[0]);
					}
                });
			return false;
		});

		$('[name="customerdata[type]"]').change(function() {
			$('[name="customerdata[name]"]').prop('required', $('#private').prop('checked'));
		}).change();

		$('#randomize').click(function() {
			if ($('[name="customerdata[pin]"]').val().length) {
				confirmDialog($t("Are you sure, you want to generate new PIN?"), this).done(function () {
					{if empty($unsecure_pin_validity)}
						$('[name="customerdata[pin]"]').val(
							generate_random_string({$pin_min_size} +Math.floor(Math.random() * {($pin_max_size - $pin_min_size) + 1}), '{str_replace("'", "\'", $pin_allowed_characters)}')
						);
					{else}
						$('[name="customerdata[pin]"]').val(
							generate_random_string({$unsecure_pin_min_size} +Math.floor(Math.random() * {($unsecure_pin_max_size - $unsecure_pin_min_size) + 1}), '{str_replace("'", "\'", $unsecure_pin_allowed_characters)}')
						);
					{/if}
				});
			}
		});

		$('#icexpires-indefinitely').change(function() {
			var checked = $(this).prop('checked');
			$('#icexpires').datepicker("option", "disabled", checked).closest('.lms-ui-date-container').prev().prop('disabled', checked);
		}).change();

		var inSubmit = false;
		$('#customeredit').submit(function () {
			if (!inSubmit) {
				inSubmit = true;
				$('#save-button').prop('disabled', true);
				$.ajax({
					url: "?m={$layout.module}&id={$customerinfo.id}&oper=check-conflict",
					dataType: "json",
					success: function (data) {
						if (data.length) {
							confirmDialog(data, $('#save-button')).done(function() {
								$('#customeredit').submit();
								inSubmit = false;
							}).fail(function() {
								$('#save-button').prop('disabled', false);
								inSubmit = false;
							});
						} else {
							$('#customeredit').submit();
							inSubmit = false;
						}
					}
				});
				return false;
			}
		});

		$('[name="customerdata[addresses][0][location_city_name]"]').on('invalid', function() {
			if (!$(this).is(':visible')) {
				$(this).closest('.location-box-expandable').find('[data-state="closed"]').click();
				this.scrollIntoView({
					behavior: 'smooth',
					block: 'center',
					inline: 'nearest'
				});
			}
		});

		$('#check-all-consents').change(function() {
			$(this).closest('.lms-ui-multi-check').find(':radio').prop('checked', $(this).prop('checked'));
		});

		$('#cutoffstopindefinitely').change(function() {
			$('.cutoffstop').toggle(!this.checked);
		});

		$('#customer-sensitive-data-button').click(function() {
			var btn = $(this);

			$.ajax({
				url: "?m=customerinfo&api=1&id={$customerinfo.id}&action=get_sensitive_data",
				dataType: "json",
				success: function(data) {
					$('.customer-sensitive-data[data-type]').each(function() {
						var type = $(this).attr('data-type');
						if (data.hasOwnProperty(type)) {
							$(this).val(data[type]).prop('disabled', false);
						}
					});
					btn.prop('disabled', true);
				}
			});
		});

		$("#reset-consents").click(function() {
			$("#customer-consent-table").find("[data-default-checked]").each(function() {
				if ($(this).is(":checkbox")) {
					$(this).prop("checked", $(this).attr("data-default-checked") == "1");
				} else {
					$(this).prop("checked", $(this).attr("data-default-checked") == $(this).val());
				}
			});
		});
	});

</script>
