<inp2:adm_SetPopupSize width="850" height="610"/>

<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="s" section="in-commerce:shipping" title_preset="costs" tab_preset="Default"/>

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

  				a_toolbar = new ToolBar();
				a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
						submit_event('s','<inp2:s_SaveEvent/>');
						}
					) );
				a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
						submit_event('s','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('s', '<inp2:s_PrevId/>');
						}
				 ) );
				a_toolbar.AddButton( new ToolBarButton('next', '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>', function() {
							go_to_id('s', '<inp2:s_NextId/>');
						}
				 ) );

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

				a_toolbar.AddButton( new ToolBarButton('in-commerce:flip', '<inp2:m_phrase label="la_ToolTip_Flip" escape="1"/>',
							function() {
								submit_event('s','OnFlip');
							} ) );

				a_toolbar.AddButton( new ToolBarButton('in-commerce:clear_all', '<inp2:m_phrase label="la_ToolTip_ClearAll" escape="1"/>', function() {
							if(confirm('<inp2:m_phrase label="la_ClearCostsWarning"/>'))
								submit_event('sc','OnClearAll');
						}
				 ) );

				a_toolbar.AddButton( new ToolBarButton('in-commerce:modify', '<inp2:m_phrase label="la_ToolTip_Modify" escape="1"/>',
							function() {
								openSelector('s', '<inp2:m_t t="in-commerce/shipping/modify_selector" pass="all,sc" sc_event="OnSaveCreated"/>');
							} ) );
				a_toolbar.Render();

				a_toolbar.DisableButton('modify');

				<inp2:m_if check="s_IsSingle" >
					a_toolbar.HideButton('prev');
					a_toolbar.HideButton('next');
					a_toolbar.HideButton('sep1');
				<inp2:m_else/>
					<inp2:m_if check="s_IsLast" >
						a_toolbar.DisableButton('next');
					</inp2:m_if>
					<inp2:m_if check="s_IsFirst" >
						a_toolbar.DisableButton('prev');
					</inp2:m_if>
				</inp2:m_if>

				function reflect_toolbar($prefix_special, $id, $field)
				{
					var $element = document.getElementById($prefix_special+'['+$id+']['+$field+']');
					if($element.checked)
					{
						$checked_count++;
					}
					else
					{
						$checked_count--;
					}

					if($checked_count)
					{
						a_toolbar.EnableButton('modify');
					}
					else
					{
						a_toolbar.DisableButton('modify');
					}
				}

			</script>
		</td>
	</tr>
</tbody>
</table>

<inp2:m_DefineElement name="row_header">
	<td>
		<input type="checkbox" name="<inp2:{$prefix}_InputName field="$IdField"/>" id="<inp2:{$prefix}_InputName field="$IdField"/>" value="<inp2:{$prefix}_field field="$IdField"/>" onclick="reflect_toolbar('<inp2:m_param name="prefix"/>', <inp2:{$prefix}_field field="$IdField"/>, '<inp2:m_param name="IdField"/>')">
		<inp2:m_RenderElement name="$header_caption"/>
		<a href="javascript:propagate_values('<inp2:m_param name="prefix"/>', <inp2:{$prefix}_field field="$IdField"/>)"><img src="<inp2:m_TemplatesBase module='In-Commerce'/>/img/list_horiz_propagate.gif" alt="<inp2:m_phrase label="la_PropagateValues"/>" border="0"></a>
	</td>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="column_header">
	<td align="center" style="border-left:1px solid black">
		<input type="checkbox" name="<inp2:{$prefix}_InputName field="$IdField"/>" id="<inp2:{$prefix}_InputName field="$IdField"/>" value="<inp2:{$prefix}_field field="$IdField"/>" onclick="reflect_toolbar('<inp2:m_param name="prefix"/>', <inp2:{$prefix}_field field="$IdField"/>, '<inp2:m_param name="IdField"/>')">
		<inp2:m_RenderElement name="$header_caption"/>
		<a href="javascript:propagate_values('<inp2:m_param name="prefix"/>', <inp2:{$prefix}_field field="$IdField"/>)"><img src="<inp2:m_TemplatesBase module='In-Commerce'/>/img/list_vertic_propagate.gif" alt="<inp2:m_phrase label="la_PropagateValues"/>" border="0"></a>
	</td>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="zone_caption">
	<nobr><inp2:z_field field="Name"/></nobr>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="bracket_caption">
	<inp2:m_if check="s_FieldEquals" name="Type" value="1">
		<inp2:m_if check="lang.current_FieldEquals" field="UnitSystem" value="1">
			<inp2:br_field field="Start"/>&nbsp;<inp2:m_Phrase label="la_kg" /> - <inp2:m_if check="br_fieldequals" field="End" value="-1">&infin;<inp2:m_else/><inp2:br_field field="End"/>&nbsp;<inp2:m_Phrase label="la_kg" /></inp2:m_if>
		</inp2:m_if>
		<inp2:m_if check="lang.current_FieldEquals" field="UnitSystem" value="2">
			<inp2:br_field field="Start_a"/>&nbsp;<inp2:m_Phrase label="la_lbs" />&nbsp;<inp2:br_field field="Start_b"/>&nbsp;<inp2:m_Phrase label="la_oz" /> - <inp2:m_if check="br_fieldequals" field="End" value="-1">&infin;<inp2:m_else/><inp2:br_field field="End_a"/>&nbsp;<inp2:m_Phrase label="la_lbs" />&nbsp;<inp2:br_field field="End_b"/>&nbsp;<inp2:m_Phrase label="la_oz"  /></inp2:m_if>
		</inp2:m_if>
	<inp2:m_else />
		<nobr><inp2:br_field field="Start"/> - <inp2:m_if check="br_fieldequals" field="End" value="-1">&infin;<inp2:m_else/><inp2:br_field field="End" /></inp2:m_if></nobr>
	</inp2:m_if>
</inp2:m_DefineElement>

<inp2:m_DefineElement name="cost_cell">
	<td style="border-left:1px solid black" align="center">
		<nobr>$ <input type="text" maxlength="<inp2:s_CostInputSize/>" size="<inp2:s_CostInputSize/>" name="<inp2:sc_InputName field="Flat"/><inp2:m_if check="s_fieldequals" field="CostType" value="2">_input</inp2:m_if>" id="<inp2:sc_InputName field="Flat"/><inp2:m_if check="s_fieldequals" field="CostType" value="2" >_input</inp2:m_if>" value="<inp2:sc_field field="Flat" />"<inp2:m_if check="s_fieldequals" field="CostType" value="2" > disabled</inp2:m_if>>
		% <input type="text" maxlength="<inp2:s_CostInputSize/>" size="<inp2:s_CostInputSize/>" name="<inp2:sc_InputName field="PerUnit"/><inp2:m_if check="s_fieldequals" field="CostType" value="1">_input</inp2:m_if>" id="<inp2:sc_InputName field="PerUnit"/><inp2:m_if check="s_fieldequals" field="CostType" value="1" >_input</inp2:m_if>" value="<inp2:sc_field field="PerUnit" />"<inp2:m_if check="s_fieldequals" field="CostType" value="1" > disabled</inp2:m_if>></nobr>

		<inp2:m_if check="s_fieldequals" field="CostType" value="2" >
			<input type="hidden" name="<inp2:sc_InputName field="Flat"/>" id="<inp2:sc_InputName field="Flat"/>" value="<inp2:sc_field field="Flat"/>">
		</inp2:m_if>
		<inp2:m_if check="s_fieldequals" field="CostType" value="1" >
			<input type="hidden" name="<inp2:sc_InputName field="PerUnit"/>" id="<inp2:sc_InputName field="PerUnit"/>" value="<inp2:sc_field field="PerUnit"/>">
		</inp2:m_if>

		<input type="hidden" name="<inp2:sc_InputName field="BracketId"/>" id="<inp2:sc_InputName field="BracketId"/>" value="<inp2:br_field field="BracketId"/>">
		<input type="hidden" name="<inp2:sc_InputName field="ZoneID"/>" id="<inp2:sc_InputName field="ZoneID"/>" value="<inp2:z_field field="ZoneID"/>">
	</td>
</inp2:m_DefineElement>

<inp2:sc_SaveWarning name="grid_save_warning"/>
<inp2:sc_ErrorWarning name="form_error_warning"/>

<div id="scroll_container" mode="minimal">
	<table class="edit-form">
		<inp2:m_RenderElement name="subsection" title="la_section_General"/>
			<inp2:m_RenderElement name="inp_edit_options" prefix="s" field="CostType" title="la_fld_CostType"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="s" field="ZeroIfEmpty" title="la_fld_EmptyCellsAre" size="20"/>

			<inp2:m_RenderElement design="form_row" prefix="s" field="PrecisionBeforeSep" title="la_Precision">
				<td class="control-cell">
					<select tabindex="<inp2:m_get param="tab_index"/>" name="<inp2:{$prefix}_InputName field="PrecisionBeforeSep"/>" id="<inp2:{$prefix}_InputName field="PrecisionBeforeSep"/>">
						<inp2:m_if check="m_ParamEquals" name="use_phrases" value="1" >
							<inp2:{$prefix}_PredefinedOptions field="PrecisionBeforeSep" block="inp_option_phrase" selected="selected"/>
						<inp2:m_else/>
							<inp2:{$prefix}_PredefinedOptions field="PrecisionBeforeSep" block="inp_option_item" selected="selected"/>
						</inp2:m_if>
					</select>&nbsp;,&nbsp;<select tabindex="<inp2:m_get param="tab_index"/>" name="<inp2:{$prefix}_InputName field="PrecisionAfterSep"/>" id="<inp2:{$prefix}_InputName field="PrecisionAfterSep"/>">
						<inp2:m_if check="m_ParamEquals" name="use_phrases" value="1" >
							<inp2:{$prefix}_PredefinedOptions field="PrecisionAfterSep" block="inp_option_phrase" selected="selected"/>
						<inp2:m_else/>
							<inp2:{$prefix}_PredefinedOptions field="PrecisionAfterSep" block="inp_option_item" selected="selected"/>
						</inp2:m_if>
					</select>
				</td>
			</inp2:m_RenderElement>

			<inp2:m_RenderElement name="inp_edit_filler"/>
	</table>
</div>

<table class="edit-form">
	<inp2:m_RenderElement name="subsection" title="la_section_ShippingCosts"/>
</table>

<div id="cost_container" style="overflow: auto;">
	<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder" style="border-top:none">
		<inp2:s_ShowCostsTable/>
	</table>
</div>

<input type="hidden" name="z_propagate_id" id="z_propagate_id" value="">
<input type="hidden" name="br_propagate_id" id="br_propagate_id" value="">

<script type="text/javascript">
	function propagate_values(prefix,id)
	{
		document.getElementById(prefix + '_propagate_id').value = id;
		submit_event('sc', 'OnPropagate');
	}

	document.getElementById('<inp2:s_InputName field="CostType"/>').onchange = saveShipping;
	document.getElementById('<inp2:s_InputName field="PrecisionBeforeSep"/>').onchange = saveShipping;
	document.getElementById('<inp2:s_InputName field="PrecisionAfterSep"/>').onchange = saveShipping;

	function saveShipping()
	{
		submit_event('s', 'OnPreSave');
	}

	$(document).ready(
		function() {
			maximizeElement('#cost_container');


		}
	);
</script>

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