{assign var=meth value=':'|explode:$VAR._page}
<!-- {$meth.0}:{$meth.1} -->

{$method->exe($meth.0,$meth.1)}
{if ($method->result == false)}
	{$block->display('core:method_error')}
{else}
	{include file='file:../core/view_pre.tpl'}

	<!-- Display the field validation -->
	{if $form_validation}
		{$block->display('core:alert_fields')}
	{/if}

	<!-- Display each record -->
	<form id="view" method="post" action="" enctype="multipart/form-data">

		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_background">
			<tr>
				<td>
					<table width="100%" border="0" cellspacing="1" cellpadding="0">
						<tr valign="top">
							<td class="table_heading">{osb f=tt}</td>
						</tr>
						<tr valign="top">
							<td class="row1">
								<table width="100%" border="0" cellspacing="3" cellpadding="1" class="row1">
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=name}</td>
										<td style="width: 65%;"><input type="text" name="affiliate_template_name" value="{$record.name}" size="32"/></td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=notes}</td>
										<td style="width: 65%;"><textarea name="affiliate_template_notes" cols="40" rows="5" >{$record.notes}</textarea></td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=status}</td>
										<td style="width: 65%;">{$list->bool('affiliate_template_status',$record.status,'form_menu')}</td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=affiliate_plugin}</td>
										<td style="width: 65%;">{$list->menu_files('','affiliate_template_affiliate_plugin',$record.affiliate_plugin,'affiliate_plugin','','.php','form_menu')}</td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=avail_campaign_id}</td>
										<td style="width: 65%;">{$list->menu_multi($record.avail_campaign_id,'affiliate_template_avail_campaign_id','campaign','name','','5','form_menu')}</td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=max_tiers}</td>
										<td style="width: 65%;"><input type="text" id="affiliate_template_max_tiers" name="affiliate_template_max_tiers" value="{$record.max_tiers}" size="5" onchange="TierUpdate();"/></td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=commission_minimum}</td>
										<td style="width: 65%;"><input type="text" name="affiliate_template_commission_minimum" value="{$record.commission_minimum}" size="5"/></td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=new_commission_type}</td>
										<td style="width: 65%;">{$list->menu_staticlist('commissiontype','affiliate_template_new_commission_type','affiliate_template_new_commission_type',$record.new_commission_type,'form_menu')}</td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=recurr_commission_type}</td>
										<td style="width: 65%;">{$list->menu_staticlist('commissiontype','affiliate_template_recurr_commission_type','affiliate_template_recurr_commission_type',$record.recurr_commission_type,'form_menu')}</td>
									</tr>
									<tr valign="top">
										<td style="width: 35%;">{osb f=tf field=recurr_max_commission_periods}</td>
										<td style="width: 65%;"><input type="text" name="affiliate_template_recurr_max_commission_periods" value="{$record.recurr_max_commission_periods}" size="5"/></td>
									</tr>
								</table>
							</td>
						</tr>
						{include file='file:../core/view_tr_submit_delete.tpl'}
					</table>
				</td>
			</tr>
		</table>

		<div>
			{section name=i start=0 loop=100 step=1}
				<input type="hidden" id="new_{$smarty.section.i.index}" name="affiliate_template_new_commission_rate[]"/>
				<input type="hidden" id="rec_{$smarty.section.i.index}" name="affiliate_template_recurr_commission_rate[]"/>
			{/section}
		</div>
		{include file='file:../core/view_post.tpl'}
	</form>

	<div><br/></div>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td style="width: 50%;" align="left"><iframe name="iframeNewTier" id="iframeNewTier" style="border:0px; width:0px; height:0px;" scrolling="auto" allowtransparency="true" frameborder="0" src="themes/{$THEME_NAME}/IEFrameWarningBypass.htm"></iframe></td>
			<td style="width: 50%;" align="right"><iframe name="iframeRecTier" id="iframeRecTier" style="border:0px; width:0px; height:0px;" scrolling="auto" allowtransparency="true" frameborder="0" src="themes/{$THEME_NAME}/IEFrameWarningBypass.htm"></iframe></td>
		</tr>
	</table>

	<script type="text/javascript">
	<!--
		var new_array = new Array(99);
		var rec_array = new Array(99);

		{literal}
		// create the hidden fields for the tier rates
		for(i=0; i<99; i++) {
			new_array[i] = '';
			rec_array[i] = '';
		}
		{/literal}

		{$list->unserial($record.new_commission_rate,'new_commission_rate')}
		{foreach key=key item=item from=$new_commission_rate}
			{if $item}
				UpdateTierValueNew({$key},"{$item}");
			{/if}
		{/foreach}

		{$list->unserial($record.recurr_commission_rate,'recurr_commission_rate')}
		{foreach key=key item=item from=$recurr_commission_rate}
			{if $item}
				UpdateTierValueRecur({$key},"{$item}");
			{/if}
		{/foreach}

		{literal}
		function UpdateTierValueNew(id,value) {
			new_array[id] = value;
			document.getElementById('new_'+id).value = value;
		}

		function UpdateTierValueRecur(id,value) {
			rec_array[id] = value;
			document.getElementById('rec_'+id).value = value;
		}

		function GetTierValueNew(id) {
			return new_array[id];
		}

		function GetTierValueRecur(id) {
			return rec_array[id];
		}

		function TierUpdate() {
			var tiers = document.getElementById('affiliate_template_max_tiers').value;

			if(tiers > 99) {
				tiers = 99;
				document.getElementById('affiliate_template_max_tiers').value = 99;
			}
			showIFrame('iframeNewTier',400,400,'?_page=affiliate:new_tier_iframe&_escape=1&tiers='+tiers);
			showIFrame('iframeRecTier',400,400,'?_page=affiliate:recurr_tier_iframe&_escape=1&tiers='+tiers);
		}
		{/literal}

		TierUpdate();
	//-->
	</script>
{/if}