{{function name="selectPageOptions" aOptions=0 mOption=0 sPrefix="" iSkip=0}}{{foreach from=$aOptions item=aOption}}{{if $iSkip !== true && $aOption.iPage != $iSkip}}{{if isset( $aOption.iPage ) && $aOption.iPage !== 0}}<option value="{{$aOption.iPage}}"{{if ( is_array( $mOption ) && in_array( $aOption.iPage, $mOption ) ) || ( $aOption.iPage == $mOption )}} selected="selected"{{/if}}>{{$sPrefix}}{{$aOption.sName}}</option>{{/if}}{{if isset( $aOption.aChildren )}}{{selectPageOptions aOptions=$aOption.aChildren mOption=$mOption sPrefix="`$sPrefix`&nbsp;&nbsp;" iSkip=$iSkip}}{{/if}}{{else}}{{if isset( $aOption.iPage ) && $aOption.iPage !== 0}}<option value="{{$aOption.iPage}}" disabled="disabled">{{$sPrefix}}{{$aOption.sName}}</option>{{/if}}{{if isset( $aOption.aChildren )}}{{selectPageOptions aOptions=$aOption.aChildren mOption=$mOption sPrefix="`$sPrefix`&nbsp;&nbsp;" iSkip=true}}{{/if}}{{/if}}{{/foreach}}{{/function}}

<script type="text/javascript">
	$(document).ready(function(){
		$("form#producer-form").validate();
		$("form#producer-form #producer-name").rules("add", {required: true});
		$("form#producer-form #producer-position").rules("add", {required: true});
		$("form#producer-form textarea[name='sDescription']").rules('add', {maxbytes: 65535});
		
		$( 'a#add-guarantee' ).on( 'click', function( e ){
			e.preventDefault();
			$( 'td#guarantee-fields' ).append( '<div class="block50 quarantee"><div class="block50"><label>{{$lang.Guarantee_value}}</label><input name="aGuarantee[sGuarantee][]" value="" type="text"  /></div><div class="block50"><label>{{$lang.Category}}</label><select name="aGuarantee[iPage][]" id="oPageGuarantee" class="select"><option value="0">{{$lang.All_products}}</option>{{selectPageOptions aOptions=$aGeneralInfo.aPages mOption=$oGuarantee.iPage}}</select><a href="#" class="delete-quarantee"><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a></div></div>' );
		});
		
		$('html').on( 'click', 'a.delete-quarantee', function( e ){
			e.preventDefault();
			$( this ).closest( 'div.quarantee' ).remove();
		});
	});
</script>
<h1>{{$lang.Edit_producer}}</h1>
<form action="?p={{$_GET.p}}" method="post" enctype="multipart/form-data" id="producer-form" >
	<fieldset>
		<input type="hidden" name="iProducer" value="{{$aProducer.iProducer}}" />
		<table class="details">
			<tr>
				<th class="name">{{$lang.Name}}</th><td class="value"><input id="producer-name" type="text" name="sName" value="{{$aProducer.sName}}" class="input" size="50" maxlength="40" alt="simple" /></td>
				<td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Type}}</th><td class="value"><input id="producer-type" type="text" name="sType" value="{{$aProducer.sType}}" class="input" alt="simple" /></td>
				<td class="help"></td>
			</tr><tr>
				<th class="name">{{$lang.Position}}</th><td class="value"><input id="producer-position" type="text" name="iPosition" value="{{$aProducer.iPosition}}"  size="3" maxlength="3" class="input" /></td>
				<td class="help"><img class="tTip info" src="templates/images/info.png"  title="{{$lang.help_producer_position}}" /></td>
			</tr><tr>
				<th class="name">{{$lang.Margin}}</th><td class="value"><input id="producer-margin" type="text" name="sMargin" value="{{$aProducer.sMargin}}" class="input" /></td>
				<td class="help"><img class="tTip info" src="templates/images/info.png"  title="{{$lang.help_producer_position}}" /></td>
			</tr><tr>
				<th class="name">{{$lang.Update_all_margins_producer}}</th><td class="value"><input name="bUpdateMargins" value="1" type="checkbox" /></td>
				<td class="help"><img class="tTip info" src="templates/images/info.png"  title="{{$lang.help_producer_update_all_margins_producer}}" /></td>
			</tr><tr>
				<th class="name">{{$lang.Logo_upload}}</th><td class="value"><input id="producer-logo" type="file" name="producerLogo" class="finput" accept="image/*" /></td>
				<td class="help"></td>
			</tr>
			<tr>
				<th class="name">{{$lang.Guarantee}}</th>
				<td id="guarantee-fields" class="value">
					<a id="add-guarantee" class="new_element" href="#">{{$lang.Add_guarantee}}</a>
					<div class="clear"></div>
					{{foreach from = $aProducer.aGuarantee item = oGuarantee}}
						<div class="block50 quarantee">
							<div class="block50">
								<label>{{$lang.Guarantee_value}}</label>
								<input name="aGuarantee[sGuarantee][]" value="{{$oGuarantee.sGuarantee}}" type="text"  />
							</div>
							<div class="block50">
								<label>{{$lang.Category}}</label>
								<select name="aGuarantee[iPage][]" id="oPageGuarantee"  class="select">
									<option value="0">{{$lang.All_products}}</option>
									{{selectPageOptions aOptions=$aGeneralInfo.aPages mOption=$oGuarantee.iPage}}
								</select><a href="#" class="delete-quarantee"><img src="{{$config.dir_templates}}admin/images/ico/delete.png" alt="{{$lang.Delete}}" title="{{$lang.Delete}}"/></a>
							</div>
						</div>
					{{/foreach}}
				</td>
				<td class="help"><img class="tTip info" src="templates/images/info.png"  title="{{$lang.help_producer_gurantee}}" /></td>
			</tr>
			<tr>
				<th class="name">{{$lang.Guarantee_file}}</th><td id="guarantee-file" class="value">
					<div class="block30" style="margin-left: 0;"><input type="file" name="sGuaranteeFile" class="finput" accept="application/pdf" /></div>
					{{if !empty( $aProducer.sGuaranteeFile )}}
						<div class="block30">
							<input id="producer-guarantee-file-delete" type="checkbox" name="iDeleteGuaranteeFile" value="1" class="input" />
							<a class="producer-guarantee-file" href="{{$config.dir_files}}{{$aProducer.sGuaranteeFile}}" alt="{{$lang.Guarantee_file}}" target="_blank" >{{$aProducer.sGuaranteeFile}}</a>
						</div>
					{{/if}}
					<div class="block30">
						<h2>{{$lang.Files_on_server}}</h2>
						<p class="files-dir"></p>
						<a href="#" id="add-file-dir-link" class="new_element">{{$lang.Add_file_dir}}</a>
					</div>
				</td>
				<td class="help"></td>
			</tr>
			{{if !empty( $aProducer.sLogoUrl )}}
				<tr class="producer-logo">
					<th class="name">{{$lang.Logo_delete}}</th><td class="value"><input id="producer-logodelete" type="checkbox" name="iDeleteLogo" value="1" class="input" /><img class="producer-logo" src="{{$config.dir_files}}{{$aProducersMinSizes.1}}/{{$aProducer.sLogoUrl}}" alt="logo" /></td>
					<td class="help"></td>
				</tr>
			{{/if}}
		</table>
		<h2>{{$lang.Description}}</h2>
		<div id="description" class="description">{{htmlEditor sName='sDescription' iH='280px' iW='100%' sContent=$aProducer.sDescription}}</div>
		
		<div class="save float">
		<div class="save floatcontainer"><input type="submit" class="submit" value="{{$lang.Save}}" name="sOption" /></div>
		</div>
		
	</fieldset>
</form>