{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->

<style>

	#action-panel {
		display: flex;
		align-items: center;
		padding-top: 0.3em;
		padding-bottom: 0.3em;
	}

	#action-panel > * {
		margin-left: 0.7em;
	}

	#action-panel button {
		margin-top: 0;
	}

</style>

<H1>{$layout.pagetitle}</H1>
<FORM NAME="setwarnings" ID="customersearchresults" METHOD="POST" ACTION="?m=customerwarn&search=0">
<TABLE class="lmsbox lms-ui-background-cycle">
    <THEAD>
	<TR {tip text="Click on column name to change sorting order"}>
		<TD width="97%">
			{icon name="customer"}
			<a href="?m=customersearch&search=1&o=customername{if $listdata.direction == "asc" && $listdata.order == "customername"},desc{/if}">
				{trans("First/last or Company name:")}
			</A>
			{if $listdata.order == "customername"}<IMG SRC="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			{icon name="karma"}
			<a href="?m=customersearch&search=1&o=karma{if $listdata.direction == "asc" && $listdata.order == "karma"},desc{/if}">
				{trans("Karma")}
			</A>
			{if $filter.order == "karma"}<IMG src="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
			<BR>
			{icon name="home"}
			<a href="?m=customersearch&search=1&o=address{if $listdata.direction == "asc" && $listdata.order == "address"},desc{/if}">
				{trans("Address:")}
			</A>
			{if $listdata.order == "address"}<IMG SRC="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}
		</TD>
		<TD align="right" width="1%" valign="top">
			<a href="?m=customersearch&search=1&o=id{if $listdata.direction == "asc" && $listdata.order == "id"},desc{/if}">{trans("ID:")}</A></B> {if $listdata.order == "id"}<IMG SRC="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}<BR>
			{trans("Services:")}
		</TD>
		<TD width="1%" ALIGN="right" valign="top">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_finances')}<a href="?m=customersearch&search=1&o=balance{if $listdata.direction == "asc" && $listdata.order == "balance"},desc{/if}">{trans("Balance:")}</A>&nbsp;{if $listdata.order == "balance"}<IMG SRC="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}<BR>
			<a href="?m=customersearch&search=1&o=tariff{if $listdata.direction == "asc" && $listdata.order == "tariff"},desc{/if}">{trans("Subscription:")}</A>&nbsp;{if $listdata.order == "tariff"}<IMG SRC="img/{if $listdata.direction == "desc"}asc{else}desc{/if}_order.gif" alt="">{/if}{/if}
		</TD>
		<TD width="1%" align="right" nowrap>
			<B>{t a=$listdata.total|default:"0"}Total: $a{/t}</B>&nbsp;
		</TD>
	</TR>
	{if $listdata.total != 0}
	<TR class="ftop">
		<TD class="lms-ui-pagination" COLSPAN="4">
			{include file="scroller.html" loop=$customerlist adlink="&search=1"}
			<INPUT type="hidden" id="warnon" name="setwarnings[warnon]" value="0">
			<INPUT type="hidden" id="warnoff" name="setwarnings[warnoff]" value="0">
		</TD>
	</TR>
	{/if}
    </THEAD>
    <TBODY>
	{foreach $customerlist as $customer}
		<INPUT type="hidden" class="hiddenbtn customer-item" name="setwarnings[mcustomerid][]" value="{$customer.id}" data-allowed-customer-status="{if empty($allowed_customer_status[$customer.status])}0{else}1{/if}">
	{/foreach}
	{section name=customerlist loop=$customerlist start=$start max=$pagelimit}
	<TR class="highlight {if $customerlist[customerlist].deleted} lms-ui-resource-deleted{/if} {if $customerlist[customerlist].account && !$customerlist[customerlist].nodeac} blend{/if}" data-name="{$customerlist[customerlist].customername|escape:"javascript"|escape:"html"}">
		<TD onClick="return self.location.href='?m=customerinfo&id={$customerlist[customerlist].id}';" valign="top">
			<i class="lms-ui-icon-customer-status-{$_CSTATUSES[$customerlist[customerlist].status].alias} fa-fw"></i>
			{if $customerlist[customerlist].info}
				<i class="lms-ui-icon-optional-info" title="{nl2br(htmlspecialchars($customerlist[customerlist].info))}"></i>
			{/if}
			<a name="{$customerlist[customerlist].id}" class="lms-ui-hint-rollover"
				data-url="?m=customerinfoshort&id={$customerlist[customerlist].id}">
					<strong>{$customerlist[customerlist].customername|escape}</strong>
			</a>
			{if !empty($customerlist[customerlist].karma)}
				<i class="lms-ui-icon-star{if $customerlist[customerlist].karma > 0} green{else} red{/if}" title="{trans('Karma')}"></i>
				(<span class="lms-ui-counter">{$customerlist[customerlist].karma}</span>)
			{/if}
			<br>
			<i class="lms-ui-icon-home fa-fw"></i>&nbsp;{$customerlist[customerlist].full_address}{if $customerlist[customerlist].country != ""}, {t}{$customerlist[customerlist].country}{/t}{/if}
		</TD>
		<TD valign="top" align="right" NOWRAP>
			({$customerlist[customerlist].id|string_format:"%04d"})
			<br>
			{if $customerlist[customerlist].account}
				<img src="img/node{if !$customerlist[customerlist].online}_off{/if}.gif" alt=""
					class="lms-ui-hint-rollover"
					data-url="?m=nodelistshort&id={$customerlist[customerlist].id}">
			{/if}
		</TD>
		<TD class="text-right valign-top nobr">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_finances')}
			<IMG src="img/empty.gif" width="1" height="16" ALT="">{if $customerlist[customerlist].balance < 0}<font class="alert">{/if}{$customerlist[customerlist].balance|money_format}{if $customerlist[customerlist].balance < 0}</span>{/if}<BR><IMG src="img/empty.gif" width="1" height="16" ALT=""><span CLASS="blend">{$customerlist[customerlist].tariffvalue|money_format}</span>
			{/if}
		</TD>
		<TD class="text-right nobr">
			{if ConfigHelper::checkConfig('privileges.superuser') || !ConfigHelper::checkConfig('privileges.hide_finances')}
				{if $customerlist[customerlist].balance < 0}
					{button type="link" class="balanceok-customer" href="?m=customerbalanceok&id={$customerlist[customerlist].id}" icon="settle" tip="Account"}
				{/if}
			{/if}

			{if ConfigHelper::checkPrivileges('customer_management', 'node_connections')}
				{if $customerlist[customerlist].account}
					{if $customerlist[customerlist].status == $smarty.const.CSTATUS_CONNECTED}
						{if $customerlist[customerlist].nodeac == 1}
							{button type="link" icon="connected" tip="Disconnect All" href="?m=nodeset&ownerid={$customerlist[customerlist].id}"}
						{else}
							{if $customerlist[customerlist].nodeac == 2}
								{button type="link" icon="mixconnected" tip="Disconnect All" href="?m=nodeset&ownerid={$customerlist[customerlist].id}"}
							{else}
								{button type="link" icon="disconnected" tip="Connect All" href="?m=nodeset&ownerid={$customerlist[customerlist].id}&access=1"}
							{/if}
						{/if}
					{/if}
				{/if}
			{/if}

			{if ConfigHelper::checkPrivileges('customer_management', 'node_management')}
				{if $customerlist[customerlist].warncount}
					{if $customerlist[customerlist].status == $smarty.const.CSTATUS_CONNECTED}
						{if $customerlist[customerlist].nodewarn == 1}
							{if $customerlist[customerlist].message}{$tip=htmlspecialchars($customerlist[customerlist].message)}{else}{$tip="Disable notices for all"}{/if}
							{button type="link" icon="warnon" tip=$tip href="?m=nodewarn&ownerid={$customerlist[customerlist].id}"}
						{else}
							{if $customerlist[customerlist].nodewarn == 2}
								{if $customerlist[customerlist].message}{$tip=htmlspecialchars($customerlist[customerlist].message)}{else}{$tip="Disable notices for all"}{/if}
								{button type="link" icon="warnmix" tip=$tip href="?m=nodewarn&ownerid={$customerlist[customerlist].id}"}
							{else}
								{if $customerlist[customerlist].message}{$tip=htmlspecialchars($customerlist[customerlist].message)}{else}{$tip="Enable notices for all"}{/if}
								{button type="link" icon="warnoff" tip=$tip href="?m=nodewarn&ownerid={$customerlist[customerlist].id}&warning=1"}
							{/if}
						{/if}
					{/if}
				{/if}
			{/if}

			{if ConfigHelper::checkPrivilege('customer_management')}
				{if $customerlist[customerlist].deleted}
					{if ConfigHelper::checkPrivilege('permanent_customer_removal')}
						{button type="link" class="remove-button" icon="clear" tip="Remove permanently" href="?m=customerdel&id={$customerlist[customerlist].id}&type=permanent"}
					{/if}
					{button type="link" icon="restore" tip="Recover" href="?m=customeredit&id={$customerlist[customerlist].id}&action=recover"}
				{else}
					{if ConfigHelper::checkPrivilege('customer_removal')}
						{button type="link" class="delete-customer" icon="delete" tip="Delete" href="?m=customerdel&id={$customerlist[customerlist].id}"}
					{/if}
					{button type="link" icon="edit" tip="Edit" href="?m=customeredit&id={$customerlist[customerlist].id}"}
				{/if}
			{/if}

			{button type="link" icon="info" tip="Info" href="?m=customerinfo&id={$customerlist[customerlist].id}"}
		</TD>
	</TR>
	{sectionelse}
	<tr>
		<td colspan="4" class="empty-table">
			{trans("No such customers matching search criteria.")}
		</td>
	</tr>
	{/section}
    </TBODY>
    <TFOOT>
	{if $listdata.total != 0}
	<TR class="ftop">
		<TD class="lms-ui-pagination" COLSPAN="4">
			{include file="scroller.html" loop=$customerlist adlink="&search=1"}
		</TD>
	</TR>
	<TR class="ftop">
		<TD COLSPAN="4" class="nobr">
			<div id="action-panel">
				<span class="bold">{trans("<!customersearch>Action:")}</span>
				<select id="customer-action" required>
					<option value="">{trans("— select —")}</option>
					{if ConfigHelper::checkPrivileges('customer_management', 'node_management')}
						<optgroup label="{trans("Warnings")}">
							<option value="1">{trans("<!customersearch>Enable warning")}</option>
							<option value="2">{trans("<!customersearch>Disable warning")}</option>
							<option value="3">{trans("Set notice content")}</option>
						</optgroup>
					{/if}
					{if ConfigHelper::checkPrivilege('customer_management')}
						<optgroup label="{trans("Customer statuses")}">
							{foreach $_CSTATUSES as $statusid => $status}
								<option value="{($statusid + 100)}">{$status.singularlabel}</option>
							{/foreach}
						</optgroup>
						<optgroup label="{trans("<!customersearch>Customer deletion")}">
							<option value="14">{trans("<!customersearch>Deletion")}</option>
							{if ConfigHelper::checkPrivilege('permanent_customer_removal')}
								<option value="16">{trans("<!customersearch>Permanent deletion")}</option>
							{/if}
							<option value="15">{trans("<!customersearch>Restoration")}</option>
						</optgroup>
					{/if}
					{if ConfigHelper::checkPrivilege('customer_group_assignments')}
						{if is_array($listdata.customergroup)}
							<optgroup label="{trans("Customer groups")}">
								{$groups = array_flip($listdata.customergroup)}
								<option value="4">{trans("<!customersearch>Add to groups")}</option>
								<option value="9">{trans("<!customersearch>Create new group")}</option>
								<option value="5">{trans("<!customersearch>Remove from groups")}</option>
								<option value="6">{trans("<!customersearch>Replace groups")}</option>
							</optgroup>
						{/if}
					{/if}
					{if ConfigHelper::checkPrivilege('customer_management')}
						<optgroup label="{trans("Customer consents")}">
							<option value="7">{trans("<!customersearch>Add consents")}</option>
							<option value="8">{trans("<!customersearch>Remove consents")}</option>
						</optgroup>
					{/if}
					{if ConfigHelper::checkPrivileges('messaging', 'messaging_creation')}
						<optgroup label="{trans("<!customersearch>Messages")}">
							<option value="10">{trans("<!customersearch>New email message")}</option>
							<option value="11">{trans("<!customersearch>New sms message")}</option>
						</optgroup>
					{/if}
					{if ConfigHelper::checkPrivilege('customer_management')}
						{foreach $_CUSTOMERCONTACTTYPES as $contacttypeidx => $contacttype}
							<optgroup label="{$contacttype.ui.legend.text}">
								<option value="{$contacttypeidx}-1" data-resource="{$contacttypeidx}" data-operation="1"
									data-target-multiselect="#contactflags-{$contacttypeidx}"
									>{trans("<!customersearch>Add flags")}</option>
								<option value="{$contacttypeidx}-2" data-resource="{$contacttypeidx}" data-operation="2"
									data-target-multiselect="#contactflags-{$contacttypeidx}"
									>{trans("<!customersearch>Remove flags")}</option>
							</optgroup>
						{/foreach}
						<optgroup label="{trans("Legal personality types")}">
							<option value="12">{$_CTYPES[$smarty.const.CTYPES_PRIVATE]}</option>
							<option value="13">{$_CTYPES[$smarty.const.CTYPES_COMPANY]}</option>
						</optgroup>
					{/if}
				</select>
				{if isset($groups)}
					<SELECT SIZE="1" class="lms-ui-multiselect-deferred" NAME="setwarnings[customergroup][]"
							id="customergroups" style="display: none;" multiple>
						{foreach $customergroups as $customergroup}
							<OPTION value="{$customergroup.id}"{if isset($groups[$customergroup.id])} selected{/if}>{$customergroup.name|truncate:50:"&hellip;":true}</OPTION>
						{/foreach}
					</SELECT>
				{/if}
				<input type="text" id="newcustomergroup" name="setwarnings[newcustomergroup]" style="display: none;">
				<select class="lms-ui-multiselect-deferred" name="consents[]" data-separator="<hr>"
						id="customerconsents" style="display: none;" multiple>
					{foreach $_CCONSENTS as $type => $consent}
						{if !is_array($consent)}
							{continue}
						{/if}
						{$customer_consent_group_id = Utils::findCustomerConsentGroupByCustomerConsent($type, $_CCONSENT_GROUPS)}
						{if $current_customer_consent_group_id && $current_customer_consent_group_id != $customer_consent_group_id || $current_customer_consent_group_id && $consent@last}
							</optgroup>
						{/if}
						{if $customer_consent_group_id && $customer_consent_group_id != $current_customer_consent_group_id}
							<optgroup label="{$_CCONSENT_GROUPS[$customer_consent_group_id].label}">
						{/if}
						{if $consent.type == 'selection'}
							{foreach $consent.values as $subtype => $subconsent}
								{if !isset($subconsent.name)}
									{continue}
								{/if}
								<option value="{$subtype}">{t a=$consent.label b=$subconsent.label}$a ($b){/t}</option>
							{/foreach}
						{else}
							<option value="{$type}">{$consent.label}</option>
						{/if}
						{$current_customer_consent_group_id = $customer_consent_group_id}
					{/foreach}
				</select>
				{foreach $_CUSTOMERCONTACTTYPES as $contacttypeidx => $contacttype}
					<select class="lms-ui-multiselect-deferred" name="contactflags[{$contacttypeidx}][]"
							id="contactflags-{$contacttypeidx}" style="display: none;" multiple>
						{foreach $contacttype.ui.flags as $flagidx => $flag}
							<option value="{$flagidx}">{$flag.label}</option>
						{/foreach}
					</select>
				{/foreach}
				{button icon="apply" label="Apply" id="customer-action-apply"}
			</div>
		</TD>
	</TR>
	{/if}
	<TR class="ftop">
		<TD align="right">
			&nbsp;
		</TD>
		<TD align="right">
			{if ConfigHelper::checkConfig('privileges.superuser') || (!ConfigHelper::checkConfig('privileges.hide_finances') && !ConfigHelper::checkConfig('privileges.hide_summaries'))}
			<B>{trans("Outstandings")}:<BR>
			{trans("Overcharges")}:</B>
			{/if}
		</TD>
		<TD align="right" nowrap>
			{if ConfigHelper::checkConfig('privileges.superuser') || (!ConfigHelper::checkConfig('privileges.hide_finances') && !ConfigHelper::checkConfig('privileges.hide_summaries'))}
			<B>{$listdata.below|money_format}<BR>
			{$listdata.over|money_format}</B>
			{/if}
		</TD>
		<TD align="right" valign="top" nowrap>
			<B>{trans("Total:")} {$listdata.total|default:"0"}</B>&nbsp;
		</TD>
	</TR>
    </TFOOT>
</TABLE>
</FORM>
<script>

	$(function() {
		var customergroups = [];
		{foreach $customergroups as $customergroup}
			customergroups.push('{$customergroup.name}');
		{/foreach}

		function setWarnings(on) {
			if (on == 1) {
				$('#warnon').val(1);
				$('#warnoff').val(0);
			} else {
				$('#warnon').val(0);
				$('#warnoff').val(1);
			}
			$('#customersearchresults').submit();
		}

		function changeCustomerGroups(oper) {
			var action = null;

			switch (oper) {
				case 1:
					var selectedCustomerGroups = $('#customergroups').val();
					if (!selectedCustomerGroups.length) {
						alertDialog($t("<!customersearch>No customer groups were selected!"), $('#customergroups').closest('.lms-ui-multiselect-container'));
						return false;
					}
					action = '?m=customergroup&oper=addtogroups';
					break;
				case 0:
					var selectedCustomerGroups = $('#customergroups').val();
					if (!selectedCustomerGroups.length) {
						alertDialog($t("<!customersearch>No customer groups were selected!"), $('#customergroups').closest('.lms-ui-multiselect-container'));
						return false;
					}
					action = '?m=customergroup&oper=removefromgroups';
					break;
				case 2:
					var selectedCustomerGroups = $('#customergroups').val();
					if (!selectedCustomerGroups.length) {
						alertDialog($t("<!customersearch>No customer groups were selected!"), $('#customergroups').closest('.lms-ui-multiselect-container'));
						return false;
					}
					action = '?m=customergroup&oper=changegroups';
					break;
				case 3:
					var newgroup = $('#newcustomergroup').val();
					if (!newgroup.length) {
						alertDialog($t("<!customersearch>New customer group name cannot be empty!"), $('#newcustomergroup'));
						return false;
					}
					if (customergroups.indexOf(newgroup) != -1) {
						alertDialog($t("<!customersearch>Customer group with specified name already exists!"), $('#newcustomergroup'));
						return false;
					}
					{literal}
					if (!newgroup.match(/^[\._\-0-9\p{L}]+$/iu)) {
						alertDialog($t("Invalid chars in group name!"), $('#newcustomergroup'));
						return false;
					}
					{/literal}

					action = '?m=customergroup&oper=addtogroups';
					break;
			}

			if (action === null) {
				return false;
			}

			$('#customersearchresults').attr('action', action).submit();
		}

		function changeCustomerConsents(oper) {
			var action = null;

			switch (oper) {
				case 1:
					action = '?m=customeredit&search=1&oper=addconsents';
					break;
				case 2:
					action = '?m=customeredit&search=1&oper=removeconsents';
					break;
			}

			if (action === null) {
				return false;
			}

			$('#customersearchresults').attr('action', action).submit();
		}

		function sendMessage(type) {
			var action = null;

			switch (type) {
				case 'sms':
					action = '?m=messageadd&type={$smarty.const.MSG_SMS}';
					break;
				case 'email':
					action = '?m=messageadd&type={$smarty.const.MSG_MAIL}';
					break;
			}

			if (action === null) {
				return false;
			}

			$('.customer-item').each(function() {
				$(this).attr('name', $(this).attr('name').replace('setwarnings[mcustomerid]', 'customers'));
			}).filter('[data-allowed-customer-status="0"]').prop('disabled', true);

			$('#customersearchresults').attr('action', action).submit();
		}

		function changeContactFlags(type, operation) {
			var action = null;

			switch (operation) {
				case 1:
					action = '?m=customeredit&search=1&type=' + type + '&oper=addflags';
					break;
				case 2:
					action = '?m=customeredit&search=1&type=' + type + '&oper=removeflags';
					break;
			}

			if (action === null) {
				return false;
			}

			$('#customersearchresults').attr('action', action).submit();
		}

		function changeCustomerType(type)
		{
			var action = '?m=customeredit&search=1&type=' + type + '&oper=changetype';

			$('#customersearchresults').attr('action', action).submit();
		}

		function changeCustomerStatus(status) {
			var action = '?m=customeredit&search=1&status=' + status + '&oper=changestatus';

			$('#customersearchresults').attr('action', action).submit();
		}

		function deleteCustomer(permanent) {
			permanent = typeof(permanent) != 'undefined' && permanent;
			var action = '?m=customerdel' + (permanent ? '&type=permanent' : '');

			$('#customersearchresults').attr('action', action).submit();
		}

		function restoreCustomer() {
			var action = '?m=customeredit&search=1&oper=restore';

			$('#customersearchresults').attr('action', action).submit();
		}

		$('#customer-action').change(function() {
			var action = parseInt($(this).val());

			if ($('#customergroups').parent('.lms-ui-multiselect-container').length) {
				$('#customergroups').parent('.lms-ui-multiselect-container').toggle(action >= 4 && action <= 6);
			} else if (action >= 4 && action <= 6) {
				$('#customergroups').show();
				init_multiselects('#customergroups');
			}

			$('#newcustomergroup').toggle(action == 9);
			if (action == 9) {
				initAutoGrow('#newcustomergroup');
			}

			if ($('#customerconsents').parent('.lms-ui-multiselect-container').length) {
				$('#customerconsents').parent('.lms-ui-multiselect-container').toggle(action >= 7 && action <= 8);
			} else if (action >= 7 && action <= 8) {
				$('#customerconsents').show();
				init_multiselects('#customerconsents');
			}

			var target_multiselect = $('option:selected', this).attr('data-target-multiselect');
			$('[id|="contactflags"]').each(function() {
				if (target_multiselect && '#' + $(this).attr('id') == target_multiselect) {
					if ($(this).parent('.lms-ui-multiselect-container').length) {
						$(this).parent('.lms-ui-multiselect-container').show();
					} else {
						$(this).show();
						init_multiselects(target_multiselect);
					}
				} else {
					$(this).parent('.lms-ui-multiselect-container').hide();
				}
			});
		});

		$('#customer-action-apply').click(function() {
			var action = parseInt($('#customer-action').val());
			var option = $('#customer-action option:selected');

			if (isNaN(action) && !option.is("[data-operation]")) {
				alertDialog($t("No action selected!"), this);
				return;
			}

			switch (action) {
				case 1:
					setWarnings(1);
					break;
				case 2:
					setWarnings(0);
					break;
				case 3:
					location.href = '?m=customerwarn&search=1';
					break;
				case 4:
					changeCustomerGroups(1);
					break;
				case 5:
					changeCustomerGroups(0);
					break;
				case 6:
					changeCustomerGroups(2);
					break;
				case 7:
					changeCustomerConsents(1);
					break;
				case 8:
					changeCustomerConsents(2);
					break;
				case 9:
					changeCustomerGroups(3);
					break;
				case 10:
					sendMessage('email');
					break;
				case 11:
					sendMessage('sms');
					break;
				case 12:
					changeCustomerType({$smarty.const.CTYPES_PRIVATE});
					break;
				case 13:
					changeCustomerType({$smarty.const.CTYPES_COMPANY});
					break;
				case 14:
					deleteCustomer();
					break;
				case 15:
					restoreCustomer();
					break;
				case 16:
					deleteCustomer(true);
					break;
				default:
					if (action >= {($smarty.const.CSTATUS_CONNECTED + 100)} && action <= {($smarty.const.CSTATUS_LAST + 100)}) {
						changeCustomerStatus(action - 100);
					} else {
						var resource = option.attr('data-resource');
						var operation = option.attr('data-operation');
						if (resource && operation) {
							changeContactFlags(resource, parseInt(operation));
						}
					}
					break;
			}
		});

		$('.balanceok-customer').click(function () {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to account ALL debts of customer \'$a\'?", name), this).done(function () {
				location.href = $(this).attr('href');
			});
			return false;
		});

		$('.delete-customer').click(function () {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Are you sure, you want to remove customer '$a' from database?\n\nIf that customer have some nodes, they will be also removed and data definitely lost!", name), this).done(function () {
				location.href = $(this).attr('href');
			});
			return false;
		});

		$('.remove-button').click(function() {
			var name = $(this).closest('tr').attr('data-name');
			confirmDialog($t("Do you want to permanently remove $a customer?", name), this).done(function() {
				location.href = $(this).attr('href');
			});
			return false;
		});
	})

</script>
{/block}
