<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

/** @var Mage_Adminhtml_Block_System_Convert_Gui_Edit_Tab_Wizard $this */
?>

<script type="text/javascript">
//<![CDATA[
var profileImportOnly = ['profile_number_of_records', 'profile_decimal_separator'];
function showOption(select)
{
    select = $(select);
    for (var i = 0, l = select.options.length; i<l; i++) {
        $$('.'+select.id+'_'+select.options[i].value).each(function (el) {
            el.style.display = select.selectedIndex==i ? '' : 'none';
        });
    }

}

function addFieldMapping()
{
    var entityType = $('profile_entity_type').value;
    Element.insert($('map_container_'+entityType), {bottom: $('map_template_'+entityType).innerHTML});
}

function removeFieldMapping(button)
{
    Element.remove(button.parentNode);
}

function setMapFileField(select)
{
    select.parentNode.getElementsByTagName('input')[0].value = select.value;
}

function toggleSelectOption(type, source, target, sourceValue, targetValue, targetText)
{
    source = $(source);
    target = $(target);

    var i, ex, option, present;
    var selectValue = source.options[source.selectedIndex].value;

    if('remove'==type && selectValue==sourceValue || 'add'==type && selectValue!=sourceValue) {
        for(i=0;i<target.options.length;i++){
            if(target.options[i].value==targetValue){
                target.remove(i);
                break;
            }
        }
    } else {
        for(i=0;i<target.options.length;i++){
            if(target.options[i].value==targetValue){
                present = true;
                break;
            } else {
                present = false;
            }
        }
        if(!present){
            option = document.createElement("OPTION");
            option.text = targetText;
            option.value = targetValue;
            try {
                target.add(option, null); // standards compliant; doesn't work in IE
            } catch(ex) {
                target.add(option); // IE only
            }
        }
    }
    showOption(target);
}

function exportUrlField()
{
    var urlFieldEl = $('profile_add_url_field').up();
    var entityType = $('profile_entity_type').value;
    var direction  = $('profile_direction').value;
    var storeId    = $('profile_store_id').value;

    if (entityType == 'product' && direction == 'export' && storeId > 0) {
        urlFieldEl.show();
    }
    else {
        urlFieldEl.hide();
    }
}

function changeEntityType()
{
    //toggleSelectOption('remove', 'profile_entity_type', 'profile_direction', 'customer', 'import', '<?= Mage::helper('core')->jsQuoteEscape($this->__('Import')) ?>');
    //toggleSelectOption('remove', 'profile_entity_type', 'profile_store_id', 'customer', '0', '<?= Mage::helper('core')->jsQuoteEscape($this->__('Default Values')) ?>');
    //showOption('profile_direction');
    changeDirection();
}


function changeDirection()
{
    toggleSelectOption('remove', 'profile_direction', 'profile_data_transfer', 'export', 'interactive', '<?= Mage::helper('core')->jsQuoteEscape($this->__('Interactive')) ?>');
    //showOption('profile_data_transfer');
    if ($('profile_direction').value == 'import') {
        profileImportOnly.each(function(id){if ($(id))$(id).up(1).show();});
    }
    else {
        profileImportOnly.each(function(id){if ($(id))$(id).up(1).hide();});
    }
    exportUrlField();
}

function updateRun(select)
{
    if ($('file_list') != null){
        if ($(select).value=='interactive') {
            $('file_list').show();
        } else {
            $('file_list').hide();
        }
    }
}

Event.observe(window, 'load', function(){
    if($('profile_data_transfer')) {
        updateRun('profile_data_transfer');
    }
});
//]]>
</script>

<div id="profile-generator" class="entry-edit profile-generator">
    <div class="entry-edit-head">
        <h4><?= $this->__("Profile Information") ?></h4>
    </div>
    <fieldset>
        <legend><?= $this->__("Profile Information") ?></legend>
        <span class="field-row">
            <label for="profile_name"><?= $this->__("Name:") ?> <span class="required">*</span></label>
            <input class="required-entry required-entry input-text" id="profile_name" name="name" value="<?= $this->getValue('name') ?>"/>
        </span>
        <span class="field-row">
            <label for="profile_entity_type"><?= $this->__("Entity type:") ?></label>
            <select id="profile_entity_type" name="entity_type" onchange="showOption(this);changeEntityType();" class="option-control">
                <option value="product" <?= $this->getSelected('entity_type', 'product') ?>><?= $this->__("Products") ?></option>
                <option value="customer" <?= $this->getSelected('entity_type', 'customer') ?>><?= $this->__("Customers") ?></option>
            </select>
        </span>
        <span class="field-row">
            <label for="profile_direction"><?= $this->__("Direction:") ?></label>
            <select id="profile_direction" name="direction" onchange="showOption(this);changeDirection();" class="option-control">
                <option value="import" <?= $this->getSelected('direction', 'import') ?>><?= $this->__("Import") ?></option>
                <option value="export" <?= $this->getSelected('direction', 'export') ?>><?= $this->__("Export") ?></option>
            </select>
        </span>
        <span class="field-row">
            <label for="profile_store_id"><?= $this->__("Store:") ?></label>
            <span class="with-tip">
                <select id="profile_store_id" name="store_id" onchange="exportUrlField();">
                <option value="0"><?= $this->__('Default (Admin) Values') ?></option>
                    <?php foreach ($this->getWebsiteCollection() as $_website): ?>
                        <?php $_websiteShow=false; ?>
                        <?php foreach ($this->getGroupCollection() as $_group): ?>
                            <?php if ($_website->getId() != $_group->getWebsiteId()) continue; ?>
                            <?php $_groupShow=false; ?>
                            <?php foreach ($this->getStoreCollection() as $_store): ?>
                                <?php if ($_group->getId() != $_store->getGroupId()) continue; ?>
                                <?php if (!$_websiteShow): ?>
                                    <?php $_websiteShow=true; ?>
                                    <optgroup label="<?= Mage::helper('core')->quoteEscape($_website->getName()) ?>"></optgroup>
                                <?php endif ?>
                                <?php if (!$_groupShow): ?>
                                    <?php $_groupShow=true; ?>
                                    <optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->escapeHtml($_group->getName()) ?>">
                                <?php endif ?>
                                <option value="<?= $_store->getId() ?>" <?= $this->getSelected('store_id', $_store->getId()) ?>>&nbsp;&nbsp;&nbsp;&nbsp;<?= $this->escapeHtml($_store->getName()) ?></option>
                            <?php endforeach ?>
                            <?php if ($_groupShow): ?>
                                </optgroup>
                            <?php endif ?>
                        <?php endforeach ?>
                    <?php endforeach ?>
                </select>
                <small class="profile_direction_import profile_entity_type_product">
                        <?= $this->__("(Products will be added/updated to this store if 'store' column is blank or missing in the import file.)") ?>
                </small>
            </span>
        </span>
        <span class="field-row">
            <label for="profile_add_url_field"><?= $this->__("Add Field with URL:") ?></label>
            <select id="profile_add_url_field" name="gui_data[export][add_url_field]" class="option-control">
                <option value="0"<?= $this->getSelected('gui_data/export/add_url_field', 0) ?>><?= $this->__("No") ?></option>
                <option value="1"<?= $this->getSelected('gui_data/export/add_url_field', 1) ?>><?= $this->__("Yes") ?></option>
            </select>
        </span>
        <span class="field-row">
            <label for="profile_number_of_records"><?= $this->__("Number of records:") ?></label>
            <span class="with-tip">
                <input class="required-entry validate-number input-text" id="profile_number_of_records" name="gui_data[import][number_of_records]" value="<?= (($numbers = $this->getValue('gui_data/import/number_of_records')) ? $numbers : 1) ?>"/>
                <small><?= $this->__("(You have to increase php memory_limit before changing this value)") ?></small>
            </span>
        </span>
        <span class="field-row">
            <label for="profile_decimal_separator"><?= $this->__("Decimal separator:") ?></label>
            <span class="with-tip">
                <input class="required-entry input-text" id="profile_decimal_separator" name="gui_data[import][decimal_separator]" value="<?= (($separator = $this->getValue('gui_data/import/decimal_separator')) ? $separator : '.') ?>"/>
            </span>
        </span>
    </fieldset>

    <div class="entry-edit-head">
    <h4><?= $this->__("File Information") ?></h4>
    </div>
    <fieldset>
        <legend><?= $this->__("File Information") ?></legend>
        <span class="field-row">
            <label for="profile_data_transfer"><?= $this->__("Data transfer:") ?></label>
            <select id="profile_data_transfer" name="data_transfer" onchange="showOption(this);updateRun(this)" class="option-control">
                <option value="interactive" <?= $this->getSelected('data_transfer', 'interactive') ?>><?= $this->__("Interactive") ?></option>
                <option value="file" <?= $this->getSelected('data_transfer', 'file') ?>><?= $this->__("Local/Remote Server") ?></option>
            </select>
        </span>
        <!--
        <div class="profile_data_transfer_interactive">
            <span class="field-row">
                <label for="interactive_filename"><?= $this->__("Archive file name:") ?></label>
                <input class="input-text" id="interactive_filename" name="gui_data[interactive][filename]" value="<?= $this->getValue('gui_data/interactive/filename') ?>"/>
                <?= $this->__('(If left empty will be auto-generated)') ?>
            </span>
        </div>
        -->
        <div class="profile_data_transfer_file">
            <span class="field-row">
                <label for="file_type"><?= $this->__("Type:") ?></label>
                <select id="file_type" name="gui_data[file][type]" onchange="showOption(this)" class="option-control">
                    <option value="file" <?= $this->getSelected('gui_data/file/type', 'file') ?>><?= $this->__("Local Server") ?></option>
                    <option value="ftp" <?= $this->getSelected('gui_data/file/type', 'ftp') ?>><?= $this->__("Remote FTP") ?></option>
                </select>
            </span>
            <span class="field-row">
                <label for="file_filename"><?= $this->__("File name:") ?></label>
                <input class="input-text" id="file_filename" name="gui_data[file][filename]" value="<?= $this->getValue('gui_data/file/filename') ?>"/>
            </span>
            <span class="field-row">
                <label for="file_path"><?= $this->__("Path:") ?></label>
                <span class="with-tip">
                    <input class="input-text" id="file_path" name="gui_data[file][path]" value="<?= $this->getValue('gui_data/file/path') ?>"/>
                    <small class="file_type_file">
                        <?= $this->__('(For Type "Local Server" need to use relative path to Magento install var/export or var/import, e.g. var/export, var/import, var/export/some/dir, var/import/some/dir)') ?>
                    </small>
                </span>
            </span>
            <div class="file_type_ftp">
                <span class="field-row">
                    <label for="file_host"><?= $this->__("FTP Host[:Port]") ?></label>
                    <input class="input-text" id="file_host" name="gui_data[file][host]" value="<?= $this->getValue('gui_data/file/host') ?>"/>
                </span>
                <span class="field-row">
                    <label for="file_user"><?= $this->__("User name") ?></label>
                    <input class="input-text" id="file_user" name="gui_data[file][user]" value="<?= $this->getValue('gui_data/file/user') ?>"/>
                </span>
                <span class="field-row">
                    <label for="file_password"><?= $this->__("Password") ?></label>
                    <input class="input-text" type="password" id="io_password" name="gui_data[file][password]" value="<?= $this->getValue('gui_data/file/password') ?>"/>
                </span>
                <span class="field-row">
                    <label for="file_mode"><?= $this->__("File mode") ?></label>
                    <select id="file_mode" name="gui_data[file][file_mode]" onchange="showOption(this)" class="option-control">
                        <option value="<?= FTP_BINARY ?>" <?= $this->getSelected('gui_data/file/file_mode', FTP_BINARY) ?>><?= $this->__('BINARY') ?></option>
                        <option value="<?= FTP_ASCII ?>" <?= $this->getSelected('gui_data/file/file_mode', FTP_ASCII) ?>><?= $this->__('ASCII') ?></option>
                    </select>
                </span>
                <span class="field-row">
                    <label for="file_passive"><?= $this->__("Passive mode") ?></label>
                    <select id="file_passive" name="gui_data[file][passive]" onchange="showOption(this)" class="option-control">
                        <option value="" <?= $this->getSelected('gui_data/file/passive', false) ?>><?= $this->__("No") ?></option>
                        <option value="true" <?= $this->getSelected('gui_data/file/passive', true) ?>><?= $this->__("Yes") ?></option>
                    </select>
                </span>
            </div>
        </div>
    </fieldset>

    <div class="entry-edit-head">
    <h4><?= $this->__("Data Format") ?></h4>
    </div>
    <fieldset>
        <legend><?= $this->__("Data Format") ?></legend>
        <span class="field-row">
            <label for="parse_type"><?= $this->__("Type:") ?></label>
            <select id="parse_type" name="gui_data[parse][type]" onchange="showOption(this)" class="option-control">
                <option value="excel_xml" <?= $this->getSelected('gui_data/parse/type', 'excel_xml') ?>><?= $this->__("MS Excel XML") ?></option>
                <option value="csv" <?= $this->getSelected('gui_data/parse/type', 'csv') ?>><?= $this->__("CSV / Tab separated") ?></option>
            </select>
        </span>
        <div class="parse_type_excel_xml">
            <span class="field-row">
                <label for="parse_single_sheet"><?= $this->__("Spreadsheet Name:") ?></label>
                <span class="with-tip">
                    <input class="input-text" id="parse_single_sheet" name="gui_data[parse][single_sheet]" value="<?= $this->getValue('gui_data/parse/single_sheet') ?>"/>
                    <small><?= $this->__("(Leave empty for first spreadsheet)") ?></small>
                </span>
            </span>
        </div>
        <div class="parse_type_csv">
            <span class="field-row">
                <label for="parse_delimiter"><?= $this->__("Value Delimiter:") ?></label>
                <input class="input-text" style="width:3em" id="parse_delimiter" name="gui_data[parse][delimiter]" value="<?= $this->getValue('gui_data/parse/delimiter', ',') ?>"/>
                <small><?= $this->__("(\\t for tab)") ?></small>
            </span>
            <span class="field-row">
                <label for="parse_enclose"><?= $this->__("Enclose Values In:") ?></label>
                <input class="input-text" style="width:3em" id="parse_enclose" name="gui_data[parse][enclose]" value="<?= $this->getValue('gui_data/parse/enclose', '', '"') ?>"/>
                <small><?= $this->__("Warning! Empty value can cause problems with CSV format.") ?></small>
            </span>
        </div>
        <span class="field-row">
            <label for="parse_fieldnames"><?= $this->__("Original Magento attribute names in first row:") ?></label>
            <span class="with-tip">
                <select id="parse_fieldnames" name="gui_data[parse][fieldnames]" onchange="showFeildMapping();showOption(this)" class="option-control">
                    <option value="" <?= $this->getSelected('gui_data/parse/fieldnames', false) ?>><?= $this->__("No") ?></option>
                    <option value="true" <?= $this->getSelected('gui_data/parse/fieldnames', true) ?>><?= $this->__("Yes") ?></option>
                </select>
                <small class="profile_direction_import">
                    <span class="parse_fieldnames_">
                        <?= $this->__("(When 'No', only mapped fields will be imported. When mapping, use 'column1', 'column2', etc.)") ?>
                    </span>
                </small>
            </span>
        </span>
        <div class="profile_direction_export">
            <span class="field-row">
                <label for="map_only_specified"><?= $this->__("Export:") ?></label>
                <select id="map_only_specified" name="gui_data[map][only_specified]" onchange="showFeildMapping();showOption(this)">
                    <option value="" <?= $this->getSelected('gui_data/map/only_specified', false) ?>><?= $this->__("All fields") ?></option>
                    <option value="true" <?= $this->getSelected('gui_data/map/only_specified', true) ?>><?= $this->__("Only mapped fields") ?></option>
                </select>
            </span>
        </div>
    </fieldset>

    <div id="__fieldmapping">
    <div class="entry-edit-head">
    <h4><?= $this->__("Field Mapping") ?></h4>
    </div>
    <fieldset>
        <legend><?= $this->__("Field Mapping") ?></legend>
        <?php foreach (['product', 'customer'] as $_entityType): ?>
            <div class="profile_entity_type_<?= $_entityType ?>">
                <div id="map_template_<?= $_entityType ?>" style="display:none">
                    <span class="field-row">
                        <?= $this->__("In Database:") ?> <select name="gui_data[map][<?= $_entityType ?>][db][]" onchange="setMapFileField(this)">
                            <?php
                                $fieldMappingInDatabase = $this->getAttributes($_entityType);
                                asort($fieldMappingInDatabase);
                                foreach ($fieldMappingInDatabase as $_value=>$_label): ?>
                                <option value="<?= $_value ?>"><?= $_label ?></option>
                            <?php endforeach ?>
                        </select>
                        &lt;--&gt;
                        <?= $this->__("In File:") ?> <input class="input-text" name="gui_data[map][<?= $_entityType ?>][file][]"/>
                        <?= $this->getRemoveMapButtonHtml() ?>
                    </span>
                </div>
                <div id="map_container_<?= $_entityType ?>">
                    <?php foreach ($this->getMappings($_entityType) as $_i=>$_dbField): ?>
                        <span class="field-row">
                            <?= $this->__("In Database:") ?> <select name="gui_data[map][<?= $_entityType ?>][db][]">
                            <?php foreach ($this->getAttributes($_entityType) as $_value=>$_label): ?>
                                <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/map/'.$_entityType.'/db/'.$_i, $_value) ?>><?= $_label ?></option>
                            <?php endforeach ?>
                            </select>
                            &lt;--&gt;
                            <?= $this->__("In File:") ?> <input class="input-text" name="gui_data[map][<?= $_entityType ?>][file][]" value="<?= $this->getValue('gui_data/map/'.$_entityType.'/file/'.$_i) ?>"/>
                            <?= $this->getRemoveMapButtonHtml() ?>
                        </span>
                    <?php endforeach ?>
                </div>
            </div>
        <?php endforeach ?>
        <?= $this->getAddMapButtonHtml() ?>
    </fieldset>
    </div>
    <div class="profile_direction_export">
        <div class="entry-edit-head">
            <h4><?= $this->__("Export Filters") ?></h4>
        </div>
        <fieldset>
            <div class="profile_entity_type_product">
                <span class="field-row">
                    <label for="product_filter_name"><?= $this->__("Name:") ?></label>
                    <input class="input-text" id="product_filter_name" name="gui_data[product][filter][name]" value="<?= $this->getValue('gui_data/product/filter/name') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="product_filter_sku"><?= $this->__("SKU:") ?></label>
                    <input class="input-text" id="product_filter_sku" name="gui_data[product][filter][sku]" value="<?= $this->getValue('gui_data/product/filter/sku') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="product_filter_type"><?= $this->__("Type:") ?></label>
                    <select id="product_filter_type" name="gui_data[product][filter][type]">
                        <?php foreach ($this->getProductTypeFilterOptions() as $_value=>$_label): ?>
                            <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/product/filter/type', $_value) ?>><?= htmlspecialchars($_label) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
                <span class="field-row">
                    <label for="product_filter_attribute_set"><?= $this->__("Attribute Set Name:") ?></label>
                    <select id="product_filter_attribute_set" name="gui_data[product][filter][attribute_set]">
                        <?php foreach ($this->getProductAttributeSetFilterOptions() as $_value=>$_label): ?>
                            <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/product/filter/attribute_set', $_value) ?>><?= htmlspecialchars($_label) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
                <span class="field-row">
                    <label for="product_filter_price_from"><?= $this->__("Price:") ?></label>
                    <input class="input-text" style="width:5em" id="product_filter_price_from" name="gui_data[product][filter][price][from]" value="<?= $this->getValue('gui_data/product/filter/price/from') ?>"/> <?= $this->__('to') ?>
                    <input class="input-text" style="width:5em" id="product_filter_price_to" name="gui_data[product][filter][price][to]" value="<?= $this->getValue('gui_data/product/filter/price/to') ?>"/>
                </span>
                <span class="field-row">
                    <label for="product_filter_qty_from"><?= $this->__("Stock Quantity:") ?></label>
                    <input class="input-text" style="width:5em" id="product_filter_qty_from" name="gui_data[product][filter][qty][from]" value="<?= $this->getValue('gui_data/product/filter/qty/from') ?>"/> <?= $this->__('to') ?>
                    <input class="input-text" style="width:5em" id="product_filter_qty_to" name="gui_data[product][filter][qty][to]" value="<?= $this->getValue('gui_data/product/filter/qty/to') ?>"/>
                </span>
                <span class="field-row">
                    <label for="product_filter_visibility"><?= $this->__("Visibility:") ?></label>
                    <select id="product_filter_visibility" name="gui_data[product][filter][visibility]">
                        <?php foreach ($this->getProductVisibilityFilterOptions() as $_value=>$_label): ?>
                            <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/product/filter/visibility', $_value) ?>><?= htmlspecialchars($_label) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
                <span class="field-row">
                    <label for="product_filter_status"><?= $this->__("Status:") ?></label>
                    <select id="product_filter_status" name="gui_data[product][filter][status]">
                        <?php foreach ($this->getProductStatusFilterOptions() as $_value=>$_label): ?>
                            <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/product/filter/status', $_value) ?>><?= htmlspecialchars($_label) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
            </div>
            <div class="profile_entity_type_customer">
                <span class="field-row">
                    <label for="customer_filter_firstname"><?= $this->__("First Name:") ?></label>
                    <input class="input-text" id="customer_filter_firstname" name="gui_data[customer][filter][firstname]" value="<?= $this->getValue('gui_data/customer/filter/firstname') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="customer_filter_lastname"><?= $this->__("Last Name:") ?></label>
                    <input class="input-text" id="customer_filter_lastname" name="gui_data[customer][filter][lastname]" value="<?= $this->getValue('gui_data/customer/filter/lastname') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="customer_filter_email"><?= $this->__("Email:") ?></label>
                    <input class="input-text" id="customer_filter_email" name="gui_data[customer][filter][email]" value="<?= $this->getValue('gui_data/customer/filter/email') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="customer_filter_group"><?= $this->__("Group:") ?></label>
                    <select id="customer_filter_group" name="gui_data[customer][filter][group]">
                        <?php foreach ($this->getCustomerGroupFilterOptions() as $_value=>$_label): ?>
                            <option value="<?= $_value ?>" <?= $this->getSelected('gui_data/customer/filter/group', $_value) ?>><?= htmlspecialchars($_label) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
                <span class="field-row">
                    <label for="customer_filter_adressType"><?= $this->__("Address Type:") ?></label>
                    <select id="customer_filter_adressType" name="gui_data[customer][filter][adressType]" >
                            <option value="default_billing" <?= $this->getSelected('gui_data/customer/filter/adressType', 'default_billing') ?>><?= $this->__('Billing Address') ?></option>
                            <option value="default_shipping" <?= $this->getSelected('gui_data/customer/filter/adressType', 'default_shipping') ?>><?= $this->__('Shipping Address') ?></option>
                    </select>
                </span>
                <span class="field-row">
                    <label for="customer_filter_telephone"><?= $this->__("Phone:") ?></label>
                    <input class="input-text" id="customer_filter_telephone" name="gui_data[customer][filter][telephone]" value="<?= $this->getValue('gui_data/customer/filter/telephone') ?>"/>
                    <?= $this->__('(Starting with)') ?>
                </span>
                <span class="field-row">
                    <label for="customer_filter_postcode"><?= $this->__("Zip/Postal Code:") ?></label>
                    <input class="input-text" id="customer_filter_postcode" name="gui_data[customer][filter][postcode]" value="<?= $this->getValue('gui_data/customer/filter/postcode') ?>"/>
                </span>
                <span class="field-row">
                    <label for="customer_filter_country"><?= $this->__("Country:") ?></label>
                    <select id="customer_filter_country" name="gui_data[customer][filter][country]">
                        <?php foreach ($this->getCountryFilterOptions() as $_value): ?>
                            <option value="<?= $_value['value'] ?>" <?= $this->getSelected('gui_data/customer/filter/country', $_value['value']) ?>><?= htmlspecialchars($_value['label']) ?></option>
                        <?php endforeach ?>
                    </select>
                </span>
                <span class="field-row">
                    <label for="customer_filter_region"><?= $this->__("State/Province:") ?></label>
                    <input class="input-text" id="customer_filter_region" name="gui_data[customer][filter][region]" value="<?= $this->getValue('gui_data/customer/filter/region') ?>"/>
                    <?= $this->__('(For US 2-letter state names)') ?>
                </span>
                <span class="field-row">
                    <label for="customer_filter_created_at_from"><?= $this->__("Customer Since:") ?></label>
                    <input class="input-text" style="width:5em" id="customer_filter_created_at_from" name="gui_data[customer][filter][created_at][from]" value="<?= $this->getValue('gui_data/customer/filter/created_at/from') ?>"/>
                     <?= $this->__('to') ?>
                    <input class="input-text" style="width:5em" id="customer_filter_created_at_to" name="gui_data[customer][filter][created_at][to]" value="<?= $this->getValue('gui_data/customer/filter/created_at/to') ?>"/>
<script type="text/javascript">
    Calendar.setup({
        inputField : "customer_filter_created_at_from",
        ifFormat : "<?= $this->getShortDateFormat() ?>"
    });
    Calendar.setup({
        inputField : "customer_filter_created_at_to",
        ifFormat : "<?= $this->getShortDateFormat() ?>"
    });
</script>
                </span>
            </div>
        </fieldset>
    </div>

</div>

<script type="text/javascript">
//<![CDATA[
    $$('.option-control').each(showOption);
    changeEntityType();

    function showFeildMapping() {
        var direction = $('profile_direction').options[$('profile_direction').options.selectedIndex].value;
        var value = $('parse_fieldnames').options[$('parse_fieldnames').options.selectedIndex].value;
        var map = $('map_only_specified').options[$('map_only_specified').options.selectedIndex].value;

        if (direction == 'export') {
            if (map) {
                Element.show($('__fieldmapping'));
            } else {
                deleteAllAddedMappingFields();
                Element.hide($('__fieldmapping'));
            }
        } else {
            if (value) {
                Element.hide($('__fieldmapping'));
                deleteAllAddedMappingFields();
            } else {
                Element.show($('__fieldmapping'));
            }
        }

    }

    function deleteAllAddedMappingFields()
    {
        var type = $('profile_entity_type').options[$('profile_entity_type').options.selectedIndex].value;

        var elems = $('map_container_'+type).childElements();
        if (elems.length > 0) for (var idx in elems) {
            if (elems[idx] != undefined && elems[idx].tagName != undefined) {
                elems[idx].remove();
            }
        }
    }
    var direction = $('profile_direction').options[$('profile_direction').options.selectedIndex].value;
    if (direction == 'import') {
        if ($('parse_fieldnames').options[$('parse_fieldnames').options.selectedIndex].value) {
            Element.hide($('__fieldmapping'));
            deleteAllAddedMappingFields();
        } else {
            Element.show($('__fieldmapping'));
        }
    } else {
        var map = $('map_only_specified').options[$('map_only_specified').options.selectedIndex].value;
        if (map) {
            Element.show($('__fieldmapping'));
        } else {
            deleteAllAddedMappingFields();
            Element.hide($('__fieldmapping'));
        }
    }
//]]>
</script>
