{extends file=$element.methods->getTemplatePath('general')}

{block name=input append}
	{if !$element.settings.singleElement && !$element.disabled && $element.possibleValues|count>1 && !$smarty.const.MODULE_REL_PATH}
		<div class="checkboxes-actions">
			{if $element.value and $element.possibleValues and $element.value|array_values == $element.possibleValues|array_keys}
				<button class="check-toggle checkNone" type="button">&nbsp;</button>
			{else}
				<button class="check-toggle checkAll" type="button">&nbsp;</button>
			{/if}
		</div>
	{/if}

	{if $element.style.renderMode!="inherit" && !$element.settings.singleElement}
		<div class="{$element.class} {if $element.style.highlight=='current'}highlightCurrent{/if}" id="{$element.id}">
	{/if}

	{foreach $element.possibleValues as $key=>$value}
		{* TODO: class:noBorder should be removed from here after the noBorder class is removed from the engine *}
		{if $element.settings.singleElement}
			{assign var=id value="{$element.id}"}
		{else}
			{assign var=id value="{$element.id}_{$key}_"}
		{/if}

		{if $value}
			<label for="{$id}" class="{strip}
					{if $element.style.highlight=='current' && $element.value==$key}highlight {/if}
					{if $element.style.renderMode=="inline"}float {/if}
					{if $element.style.renderMode=="aligned"}aligned {/if}
					{if $element.disabled}disabled {/if}
				{/strip}">
		{/if}

			<input type="checkbox" class="noBorder inputElement"
				{if $element.settings.singleElement}
					{if $element.name}
						name="{$element.name}"
					{/if}
				{else}
					{if $element.name}
						name="{$element.name}[{$key}]"
					{/if}
				{/if}
				id="{$id}"
				value="{$key}"
				{if $element['value'] and in_array($key, $element['value'])}
					checked="checked"
				{/if}

				{if $element.disabled or in_array($key, $element.partialDisabled)}
					disabled="disabled"
				{/if}

                {if $element.tooltip}
                    tooltip="{$element.tooltip}"
                {/if}

				{if $element.settings.events.onChange}
					onChange="var element = $(this); {$element.settings.events.onChange|join:";"}"
				{/if}
			/>

		{if $value}
			{$value}
			</label>
		{/if}

		{if $element.style.renderMode=="block"}
			<br/>
		{/if}
		{$elements[]=$id}
	{/foreach}
	{if $element.style.renderMode!="inherit" && !$element.settings.singleElement}
		</div>
	{/if}
{/block}


<script type="text/javascript">
	{block name=script}	{** dont append to prev validators!! **}
		{if $element.hasValidator && $elements}
			_inputValidator.createOnLoad(['{$elements|join:"', '"}'], '{$element.validatorType}', {$element.validatorParams|@json_encode}, { highlightParent: 'label' });
		{/if}

		{if $elements}
			MVC.scheduleOnLoad(function() {
				{if !$element.settings.singleElement && !$element.disabled && $element.possibleValues|count>1 && !$smarty.const.MODULE_REL_PATH}
					FormField.checkboxes.installCheckHandler($('{$elements[0]}').up('.inputElement'));
					FormField.checkboxes.installCheckAllHandler($('{$elements[0]}').up('.inputElement'));
				{/if}
			});
		{/if}
	{/block}
</script>
