<inp2:adm_SetPopupSize width="780" height="670"/>

<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="ord.export" section="in-commerce:orders" title_preset="orders_export"/>

<!-- 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() {

						document.getElementById('hidden_export_columns').value = select_to_string('<inp2:ord.export_InputName field="ExportColumns"/>');
						submit_event('ord.export', 'OnExportBegin');

						}
					) );
				a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
							submit_event('ord.export', 'OnGoBack');
						}
				 ) );

				a_toolbar.Render();
			</script>
		</td>
	</tr>
</tbody>
</table>

<inp2:ord.export_SaveWarning name="grid_save_warning"/>
<inp2:ord.export_ErrorWarning name="form_error_warning"/>

<div id="scroll_container">
	<table class="edit-form">
		<inp2:m_RenderElement name="subsection" title="la_section_General"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="ord.export" field="ExportFormat" title="la_fld_ExportFormat" use_phrases="0"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="ord.export" field="FieldsSeparatedBy" title="la_fld_FieldsSeparatedBy" size="2" maxlength="1"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="ord.export" field="FieldsEnclosedBy" title="la_fld_FieldsEnclosedBy" size="2" maxlength="1"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="ord.export" field="LineEndings" title="la_fld_LineEndings" use_phrases="0"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="ord.export" field="LineEndingsInside" title="la_fld_LineEndingsInside" use_phrases="0"/>

			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="ord.export" field="IncludeFieldTitles" title="la_fld_IncludeFieldTitles"/>

			<inp2:m_RenderElement design="form_row" prefix="ord.export" field="ExportPresets" title="la_fld_ExportPresets">
				<td class="control-cell">
					<select tabindex="<inp2:m_get param="tab_index"/>" name="<inp2:ord.export_InputName field="ExportPresets"/>" id="<inp2:ord.export_InputName field="ExportPresets"/>" onchange="update_fields(this.value)">
						<inp2:ord.export_PredefinedOptions field="ExportPresets" block="inp_option_item" selected="selected"/>
					</select>
					&nbsp;&nbsp;
					<input class="button" type="button" value="<inp2:m_Phrase label="la_Text_Delete"/>" onclick="delete_preset()">
				</td>
			</inp2:m_RenderElement>

			<inp2:m_RenderElement design="form_row" prefix="ord.export" field="ExportColumns" title="la_fld_ExportColumns">
				<td class="control-cell">
					<table cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td>
								<input type="button" value="<inp2:m_phrase name="la_btn_Up"/>" onclick="move_options_up('<inp2:ord.export_InputName field="ExportColumns"/>', 1)" class="button">
								<input type="button" value="<inp2:m_phrase name="la_btn_Down"/>" onclick="move_options_down('<inp2:ord.export_InputName field="ExportColumns"/>', 1)" class="button"><br />
								<img src="img/s.gif" width="1" height="5" alt=""><br />
							</td>
							<td><img src="img/s.gif" width="45" height="1" alt=""><br></td>
							<td><inp2:m_phrase name="la_fld_AvailableColumns"/>:</td>
						</tr>
						<tr>
							<td>
								<select multiple id="<inp2:ord.export_InputName field="ExportColumns"/>" size="15" style="width: 225px;">
									<inp2:ord.export_PredefinedOptions field="ExportColumns" block="inp_option_item" selected="selected"/>
								</select>
								<input type="hidden" id="hidden_export_columns" name="<inp2:ord.export_InputName field="ExportColumns"/>" value="<inp2:ord.export_Field field="ExportColumns"/>" />
							</td>
							<td align="center">
								<input type="button" value="&nbsp;&laquo;&laquo;&nbsp;" onclick="move_selected('<inp2:ord.export_InputName field="AvailableColumns"/>', '<inp2:ord.export_InputName field="ExportColumns"/>')" class="button"><br>
								<img src="img/s.gif" width="1" height="4" alt=""><br>
								<input type="button" value="&nbsp;&raquo;&raquo;&nbsp;" onclick="move_selected('<inp2:ord.export_InputName field="ExportColumns"/>', '<inp2:ord.export_InputName field="AvailableColumns"/>'); select_sort('<inp2:ord.export_InputName field="AvailableColumns"/>');" class="button">
							</td>
							<td>
								<select multiple id="<inp2:ord.export_InputName field="AvailableColumns"/>" size="15" style="width: 225px;">
									<inp2:ord.export_PredefinedOptions field="AvailableColumns" block="inp_option_item" selected="selected"/>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</inp2:m_RenderElement>

			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="ord.export" field="ExportSavePreset" title="la_fld_ExportSavePreset" size="2" maxlength="1" onclick="update_preset_field(this.checked)"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="ord.export" field="ExportPresetName" title="la_fld_ExportPresetName" size="20" />

			<inp2:m_RenderElement name="inp_edit_box" prefix="ord.export" field="ExportFilename" title="la_fld_ExportFilename" size="20" />
		<inp2:m_RenderElement name="inp_edit_filler"/>
	</table>
</div>

<script type="text/javascript" src="incs/ajax.js"></script>
<script type="text/javascript">
	var delete_busy = false;

	function delete_preset()
	{
		if (!confirm('<inp2:m_Phrase label="la_ConfirmDeleteExportPreset" js_escape="1"/>')) return;
		var $kf = document.getElementById('kernel_form');
		tmp = $kf.elements['events[ord.export]'].value;
		$kf.elements['events[ord.export]'].value = 'OnDeleteExportPreset';
		Request.method = 'POST';
		Request.params = Request.serializeForm($kf);
		$kf.elements['events[ord.export]'].value = tmp;
		Request.makeRequest('<inp2:m_t ajax="1" ord.export_event="OnDeleteExportPreset" no_amp="1" js_escape="1"/>', delete_busy, '', function() {
			presets = document.getElementById('<inp2:ord.export_InputName field="ExportPresets"/>');

			for (i=0; i< presets.options.length; i++) {
				if (presets.options[i].selected) {
					presets.options.remove[i];
				}
			}
			presets.options[0].selected = true;
		}, function() {alert('error')} );
	}

	function update_preset_field(status)
	{
		if (status) {
			presets = document.getElementById('<inp2:ord.export_InputName field="ExportPresets"/>');
			if ( presets.value != '' ) {
				for (i=0; i< presets.options.length; i++) {
					if (presets.options[i].selected) {
						preset_name = presets.options[i].text
					}
				}
				document.getElementById('<inp2:ord.export_InputName field="ExportPresetName"/>').value = preset_name;
			}
		}
		document.getElementById('<inp2:ord.export_InputName field="ExportPresetName"/>').disabled = !status;
	}

	function update_fields(preset)
	{
		$export = select_to_string(document.getElementById('<inp2:ord.export_InputName field="ExportColumns"/>'));
		if ($export != '') {
			string_to_selected($export, document.getElementById('<inp2:ord.export_InputName field="ExportColumns"/>'));
			move_selected('<inp2:ord.export_InputName field="ExportColumns"/>', '<inp2:ord.export_InputName field="AvailableColumns"/>');
		}

		av = document.getElementById('<inp2:ord.export_InputName field="AvailableColumns"/>');
		fields = preset.split('|');

		for (var i=0; i<fields.length; i++) {
			fld = fields[i];
			var $cur = null;
			for (var $i = 0; $i < av.length; $i++)
			{
				cur = av.options[$i];
				if (cur.value == fld) {
					av.options[$i].selected = true;
					move_selected('<inp2:ord.export_InputName field="AvailableColumns"/>', '<inp2:ord.export_InputName field="ExportColumns"/>');
				}
				else {
					av.options[$i].selected = false;
				}
			}
		}
	}

	update_preset_field(document.getElementById('<inp2:ord.export_InputName field="ExportPresetName"/>').checked)

</script>

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