{if $form.methods->getMessages()}
	<div class='messageDivContainer'>
		{$form.methods->getMessages()->Draw()}
	</div>
{/if}

<div class="formField-container-VL">
	{foreach from=$form.childs item=element}
		{if $element->isContainer()}
			{$element->render(null, $form.element)}
		{else}
			{if !$element->getInvisible()}
				<div
					{if $element->getParentId()}id="{$element->getParentId()}"{/if}
					style="{if $style['display']|default:''}display:{$style['display']}{/if}"
					class="input"
				>
					<div class="label">{$element->getLabel()}</div>

					<div class="inputElement">
						{if $element->getTooltip()}
							<var class="icon-info" tooltip="{$element->getTooltip()}"></var>
						{/if}

						{$element->render(null, $form.element)}
					</div>

					{if $element->getMessages()}
						<div class="messages">
							<div class='messageDivContainer'>
								{$element->getMessages()->Draw()}
							</div>
						</div>
					{/if}
				</div>
			{/if}
		{/if}
	{/foreach}

	{if $form.methods->hasButtons()}
		<div class="button-container">
			{$form.methods->renderButtons()}
		</div>
	{/if}
</div>

{foreach from=$form.childs item=element}
	{if !$element->isContainer() && $element->getInvisible()}
		{$element->render()}
	{/if}
{/foreach}


{*** handle controlled elements(hiding/showing one element according to the value of another ***}
{capture assign=javascriptContent}
	{foreach from=$form.childs item=element}
		{if !$element->isContainer(1)}
			{$controlledElements=$element->getControlledElements()}
			{$controllerType=$element->getControlledType()}
			{if $controlledElements and !$element->getDisabled()}
				{strip2}
				function {$element->getID()}_change(nodeType){
					{$class=$element|get_class|replace:'\\':'/'}
					var value = FormField.getValue('{$form.id}', '{$class}', '{$element->getName()}', '{$element->getID()}');
					if (nodeType=='leaf-off') {
						value = null;
					}

					switch(value){
						{foreach $controlledElements as $condition=>$elements}
						case '{$condition}':
							{$offElements=[]}
							{foreach $controlledElements as $c=>$els}
								{if $condition!=$c}
									{foreach $els as $e}
										{if !in_array($e, $elements)}	{* this element will get toggled to 'on' afterwards, so dont set if 'off' not *}
											{if !in_array($e, $offElements)}	{* this element was already off-ed *}
												{if !$e->getInvisible()}
													FormField.toggleControlledElement('{$controllerType}', '{$e|get_class|replace:'\\':'/'}', '{$e->getID()}', 'off');
													{if $e->getControlledElements()}
														{$e->getID()}_change('leaf-off');
													{/if}
													{$offElements[]=$e}
												{/if}
											{/if}
										{/if}
									{/foreach}
								{/if}
							{/foreach}

							{foreach $elements as $el}
								{if !$el->getInvisible()}
									FormField.toggleControlledElement('{$controllerType}', '{$el|get_class|replace:'\\':'/'}', '{$el->getID()}', 'on');
									{if $el->getControlledElements()}
										{$el->getID()}_change('leaf-on');
									{/if}
								{/if}
							{/foreach}
						break;
						{/foreach}

						default:
							{$offElements=[]}

							{foreach $controlledElements as $c=>$els}
								{foreach $els as $el}
									{if !in_array($el, $offElements)}	{* this element waqs already off-ed *}
										{if !$el->getInvisible()}
											FormField.toggleControlledElement('{$controllerType}', '{$el|get_class|replace:'\\':'/'}', '{$el->getID()}', 'off');
											{if $el->getControlledElements()}
												{$el->getID()}_change('leaf-off');
											{/if}
											{$offElements[]=$el}
										{/if}
									{/if}
								{/foreach}
							{/foreach}
						break;
					}
				};

				if(MVC){
					MVC.scheduleOnLoad(function(){
						FormField.observeElement('change', {$element->getID()}_change.bind(null, 'root'), '{$form.id}', '{$class}', '{$element->getName()}', '{$element->getID()}');
						{$element->getID()}_change();
					});
				}else{
					FormField.observeElement('change', {$element->getID()}_change.bind(null, 'root'), '{$form.id}', '{$class}', '{$element->getName()}', '{$element->getID()}');
					{$element->getID()}_change();
				}

				{/strip2}
			{/if}
		{/if}
	{/foreach}
{/capture}

{if $javascriptContent|trim}
	<script type="text/javascript">
		// fieldset.tpl
		{$javascriptContent|trim}
	</script>
{/if}
