<inp2:adm_SetPopupSize width="750" height="400"/>

<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="ap" section="in-commerce:affiliate_plans" title_preset="affiliate_plans_brackets" tab_preset="Default"/>

<!-- ToolBar -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
	<tr>
  	<td>
  		<script type="text/javascript">
				a_toolbar = new ToolBar();

				a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
							submit_event('ap','<inp2:ap_SaveEvent/>');
						}
					) );
				a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
							submit_event('ap','OnCancelEdit');
						}
				 ) );

				a_toolbar.AddButton( new ToolBarSeparator('sep1') );

				a_toolbar.AddButton( new ToolBarButton('prev', '<inp2:m_phrase label="la_ToolTip_Prev" escape="1"/>', function() {
							go_to_id('ap', '<inp2:ap_PrevId/>');
						}
				 ) );
				a_toolbar.AddButton( new ToolBarButton('next', '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>', function() {
							go_to_id('ap', '<inp2:ap_NextId/>');
						}
				 ) );

				a_toolbar.AddButton( new ToolBarSeparator('sep2') );

				function add_brackets()
	  			{
	  				submit_event('apbrackets', 'OnMoreBrackets')
	  			}
				a_toolbar.AddButton( new ToolBarButton('in-commerce:more_brackets', '<inp2:m_phrase label="la_ToolTip_MoreBrackets" escape="1"/>', add_brackets) );

				function infinity()
	  			{
					submit_event('apbrackets', 'OnInfinity');
	  			}
				a_toolbar.AddButton( new ToolBarButton('in-commerce:infinity', '<inp2:m_phrase label="la_ToolTip_Infinity" escape="1"/>', infinity) );

				function arrange_brackets()
	  			{
					submit_event('apbrackets', 'OnArrange')
	  			}
				a_toolbar.AddButton( new ToolBarButton('in-commerce:arrange', '<inp2:m_phrase label="la_ToolTip_Arrange" escape="1"/>', arrange_brackets) );

				a_toolbar.Render();

				<inp2:m_if check="ap_IsSingle" >
					a_toolbar.HideButton('prev');
					a_toolbar.HideButton('next');
					a_toolbar.HideButton('sep1');
					//a_toolbar.HideButton('sep2');
				<inp2:m_else/>
					<inp2:m_if check="ap_IsLast" >
						a_toolbar.DisableButton('next');
					</inp2:m_if>
					<inp2:m_if check="ap_IsFirst" >
						a_toolbar.DisableButton('prev');
					</inp2:m_if>
				</inp2:m_if>
			</script>
		</td>
	</tr>
</tbody>
</table>

<inp2:m_DefineElement name="pr_edit_box" >
<td>
	<input type="text" size="<inp2:m_param name="size"/>" name="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				id="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				tabindex="<inp2:m_get param="tab_index"/>"
				value="<inp2:m_param name="$field"/>"
			>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="pr_edit_max" >
<td>
			<input type="text" size="10" name="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				id="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				tabindex="<inp2:m_get param="tab_index"/>"
				value="<inp2:m_param name="max"/>"
				<inp2:m_if check="m_ParamEquals" param="next_min_id" value="">
				<inp2:m_else />
				onchange="set_start(<inp2:m_param name="id"/>, <inp2:m_param name="next_min_id"/>,'<inp2:m_param name="PrefixSpecial"/>')"
				</inp2:m_if>

			>
</td>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="pr_edit_min" >
<td>
			<input type="hidden" name="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="IdField"/>]" id="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="IdField"/>]" value="<inp2:m_param name="id"/>">
			<input type="text" size="10"
				<inp2:m_if check="m_ParamEquals" param="first" value="1">
					<inp2:m_inc param="tab_index" by="1"/>
					tabindex="<inp2:m_get param="tab_index"/>"
				<inp2:m_else/>
					readonly
				</inp2:m_if>
				name="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				id="<inp2:m_param name="PrefixSpecial"/>[<inp2:m_param name="id"/>][<inp2:m_param name="field"/>]"
				value="<inp2:m_param name="min"/>"
				<inp2:m_if check="m_ParamEquals" param="first" value="1"><inp2:m_else/>disabled</inp2:m_if>
			>
</td>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="prbracket">
	<tr class="<inp2:m_odd_even odd="table-color1" even="table-color2"/>">

		<inp2:m_RenderElement name="pr_edit_min" IdField="$IdField" PrefixSpecial="$PrefixSpecial" field="FromAmount" size="40" pass_params="true"/>

		<inp2:m_RenderElement name="pr_edit_max" IdField="$IdField" PrefixSpecial="$PrefixSpecial" field="ToAmount" size="40" pass_params="true"/>

		<inp2:m_RenderElement name="pr_edit_box" IdField="$IdField" PrefixSpecial="$PrefixSpecial" field="Percent" size="4" pass_params="true"/>

	</tr>
</inp2:m_DefineElement>


<script>

	function set_start(id, next_id, prefix_special)
	{
		//var next_id = id - 1;
		var input_id = prefix_special + '[' + next_id + '][FromAmount]';
		//var orig_id = prefix_special + '[' + id + '][FromAmount]';
		if(document.getElementById(input_id) != null)
		{
			var new_value = parseInt(document.getElementById(prefix_special + '[' + id + '][ToAmount]').value);
			if( isNaN(new_value) ) new_value = 0;
			document.getElementById(prefix_special + '[' + id + '][ToAmount]').value = new_value;
			document.getElementById(input_id).value = new_value;
		}
	}

	function enableKernelFormFields()
	{
		var kForm = document.forms.kernel_form;
		var elem = false;
		for (var i=0; i<kForm.elements.length; i++){
			elem = kForm.elements[i];
			if (elem.type == "text" && elem.disabled == true){
				elem.disabled = false;
			}
		}
	}

</script>

<inp2:m_DefineElement name="pr_grid_th" >
	<td class="columntitle_small"><inp2:m_phrase label="$phrase" /></td>
</inp2:m_DefineElement>

<inp2:apbrackets_SaveWarning name="grid_save_warning"/>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
	<tr nowrap="nowrap" class="grid-header-row-0">
		<inp2:m_RenderElement name="pr_grid_th" phrase="column:la_fld_FromAmount"/>
		<inp2:m_RenderElement name="pr_grid_th" phrase="column:la_fld_ToAmount"/>
		<inp2:m_RenderElement name="pr_grid_th" phrase="la_col_Percent"/>
	</tr>
	<inp2:apbrackets_ShowPricingForm block="prbracket" IdField="AffiliateBracketId"/>
</table>

<inp2:m_include t="incs/footer"/>

<script>
	document.forms.kernel_form.onsubmit =  enableKernelFormFields;
</script>