<% var e, error, n, notice; %>

<% if (!_.isEmpty(m.errors)) { %>
	<div class="zfab_error_wrap"><div><div class="zfab_error messageDisplay">
		<% foreach (m.errors as e => error) { %>
			<div class="zfab_error_inner">
				{{zenario.htmlspecialchars(error.message, true)}}
			</div>
		<% } %>
	</div></div></div>
<% } %>	
<% foreach (m.notices as n => notice) { %>
	<div class="{{notice.type|escape}}DisplayRow"><div><div class="messageDisplay"><div>
		<% if (notice.html) { %>
			{{notice.message}}
		<% } else { %>
			{{zenario.htmlspecialchars(notice.message, true)}}
		<% } %>
	</div></div></div></div>
<% } %>

<% if (m.fields) { %>
	<%
		var f,
			field,
			ff = m.fields[0],
			fl = m.fields.length,
			lf = m.fields[fl-1],
			pgf = ff._cms_lastVisibleGroupingField,
			lgf = lf._cms_lastVisibleGroupingField,
			rowHasError = false;
	%>
	
	<% foreach (m.fields as f => field) { %>
		<% if (field.error) { %>
			<% rowHasError = true; %>
			<% break; %>
		<% } %>	
	<% } %>	
	
	<% if (ff._cms_lastVisibleGrouping !== ff.grouping) { %>
		<% if (pgf) { %>
			</fieldset>
			<% if (pgf.post_grouping_html) { %>
				{{pgf.post_grouping_html}}
			<% } %>
			<% if (!ff.grouping || m.grouping.start_new_grouping_wrapper) { %>
				</x-zenario-grouping-wrapper>
			<% } %>
		<% } %>
		<% if (ff.grouping) { %>
			<% if (!pgf || m.grouping.start_new_grouping_wrapper) { %>
				<x-zenario-grouping-wrapper
					class="
						zenario_ab_grouping_wrapper
						{{m.grouping.grouping_wrapper_css_class|escape}}
					"
					style="{{m.grouping.grouping_wrapper_style|escape}}"
				>
					<% if (m.grouping.grouping_wrapper_icon_class) { %>
						<div class="zenario_ab_grouping_wrapper_icon {{m.grouping.grouping_wrapper_icon_class|escape}}">
							<% if (zenario.defined(m.grouping.grouping_wrapper_record_count)) { %>
								<span class="zenario_ab_grouping_wrapper_record_count">{{m.grouping.grouping_wrapper_record_count|escape}}</span>
							<% } %>
						</div>
					<% } %>
			<% } %>
			<% if (m.grouping.pre_grouping_html) { %>
				{{m.grouping.pre_grouping_html}}
			<% } %>
			<fieldset
				class="
					zenario_grouping zenario_grouping__{{ff.grouping|escape}}
					{{m.grouping.grouping_css_class|escape}}
					
					<% if (ff.type == 'radio') { %>
						zenario_grouping_with_input zenario_grouping_with_radio
						
						<% if (!_.isEmpty(m.lib.value(ff.id))) { %>
							zenario_grouping_with_input_selected zenario_grouping_with_radio_selected
						<% } %>
					<% } %>
					<% if (ff.type == 'checkbox') { %>
						zenario_grouping_with_input zenario_grouping_with_checkbox
						
						<% if (!_.isEmpty(m.lib.value(ff.id))) { %>
							zenario_grouping_with_input_selected zenario_grouping_with_checkbox_selected
						<% } %>
					<% } %>
				"
				style="{{m.grouping.grouping_style|escape}}"
				onclick="{{m.grouping.grouping_onclick|escape}}"
			>
		<% } %>
	<% } %>
	<% if (ff.legend) { %>
		<legend class="zenario_legend zenario_legend_for__{{ff._cms_fieldID|escape}}"><span>{{ff.legend}}</span></legend>
	<% } %>
	
	<div id="{{m.lib.idPrefix()|escape}}row__{{ff._cms_fieldID|escape}}" style="{{ff.row_style|escape}}" class="
		zenario_ab_row
		zenario_ab_row__{{ff._cms_fieldID|escape}}
		{{rowHasError? 'zenario_row_with_error' : ''}}
		{{ff.error? 'zenario_row_with_error_on_first_field' : ''}}
		{{ff.row_class|escape}}
		{{ff.pressed? 'zenario_row_pressed' : ''}}
		{{ff.type=='checkbox'? 'zenario_single_line' : ''}}
		{{ff.onoff? 'zenario_onoffswitch zenario_onoffswitch_welcome' : ''}}
		{{ff._cms_hideOnOpen? 'zenario_hide_row_on_open' : ''}}
		{{ff.indent? 'zenario_indent_level zenario_indent_level_' +  (1*ff.indent) : ''}}
		zenario_row_for_{{ff.snippet? 'snippet' : ff.upload? 'upload' : ff.pick_items? 'pick_items' : ff.type |escape}}
		
		<% if (fl > 1) { %>
			zfab_row_with_multiple_fields zfab_row_with_{{fl}}_fields
		<% } else { %>
			zfab_row_with_1_field
		<% } %>
		
		<% if (ff.pre_field_html || ff.post_field_html) { %>
			zfab_row_with_pre_or_post_field_html
		<% } %>
		
		{{m.lib.classesForRowContents('zfab_row_with_', m.fields)}}
	">
		<% if (zenario.engToBoolean(ff.full_width)) { %>
			<div >
		<% } else { %>
			<div class="title" {{zenario.browserIsIE(8)? ' style="width: 25%"' : ''}}>
				<% if (ff.label && !zenario.IN(ff.type, 'checkbox', 'radio')) { %>
					<div class="{{ff._cms_hideOnOpen? 'zenario_hide_on_open' : ''}} {{ff._cms_showOnOpen? 'zenario_show_on_open' : ''}}">
						<label for="{{ff._cms_fieldID|escape}}">{{ff.label|escape}}</label>
					</div>
				<% } %>
			</div><div>
		<% } %>
				<div class="
					zfab_row_fields
					{{ff._cms_hideOnOpen? 'zenario_hide_on_open' : ''}}
					{{ff._cms_showOnOpen? 'zenario_show_on_open' : ''}}
					{{ff.type=='checkbox'? 'zenario_input_checkbox' : ''}}
				">
					{{m.lib.microTemplate('zenario_welcome_field', m.fields)}}
				</div>
			</div>
	</div>
	
	<% if (ff._cms_fieldIsOnLastRow) { %>
		<% if (ff.grouping) { %>
			</fieldset>
			<% if (lgf && lgf.post_grouping_html) { %>
				{{lgf.post_grouping_html}}
			<% } %>
			</x-zenario-grouping-wrapper>
		<% } %>
	<% } %>
<% } %>