
<script type="text/javascript">
    <!--
    function clearFilters()
    {
        Eventum.getField('keywords').val('');
        Eventum.getField('sender').val('');
        Eventum.getField('to').val('');
        Eventum.getField('ema_id').val('');
        Eventum.getField('filter[arrival_date]').attr('checked', false);
        toggleDateFields('arrival_date');
        // need to hack this value in the query string so the saved search options don't override this one
        if (!Eventum.getField('filter[arrival_date]').is(':checked')) {
            Eventum.getField('hidden1').attr('name', 'filter[arrival_date]').val('no');
        }
        $('#email_filter_form').submit();
    }
    function toggleDateFields()
    {
        var field_name = 'arrival_date';

        if (Eventum.getField('filter[' + field_name + ']').is(':checked')) {
            var bool = false;
        } else {
            var bool = true;
        }
        Eventum.getField(field_name + '[Month]').attr('disabled', bool);
        Eventum.getField(field_name + '_end[Month]').attr('disabled', bool);
        Eventum.getField(field_name + '[Day]').attr('disabled', bool);
        Eventum.getField(field_name + '[Year]').attr('disabled', bool);
        Eventum.getField(field_name + '_end[Day]').attr('disabled', bool);
        Eventum.getField(field_name + '_end[Year]').attr('disabled', bool);
        Eventum.getField(field_name + '[filter_type]').attr('disabled', bool);
    }
    function selectDateOptions(field_prefix, date_str)
    {
        if (date_str.length != 10) {
            return false;
        } else {
            var year = date_str.substring(0, date_str.indexOf('-'));
            var month = date_str.substring(date_str.indexOf('-')+1, date_str.lastIndexOf('-'));
            var day = date_str.substring(date_str.lastIndexOf('-')+1);
            selectDateField(field_prefix, day, month, year);
        }
    }
    function selectDateField(field_name, day, month, year)
    {
        selectOption(getForm('email_filter_form'), field_name + '[Day]', day);
        selectOption(getForm('email_filter_form'), field_name + '[Month]', month);
        selectOption(getForm('email_filter_form'), field_name + '[Year]', year);
    }
    function checkDateFilterType()
    {
        var option = Eventum.getField('arrival_date[filter_type]').val();
        $('#arrival_end_date').toggle(option == 'between');
    }

    $().ready(function() {
        $('#clear_button').click(clearFilters);
        Eventum.getField('arrival_date[filter_type]').change(checkDateFilterType);
        Eventum.getField('filter[arrival_date]').change(toggleDateFields);

        checkDateFilterType();
        toggleDateFields();
    });
    //-->
</script>

<form action="emails.php" method="get" id="email_filter_form" onSubmit="return validateForm(this);">
    <input type="hidden" name="cat" value="search">
    <input type="hidden" name="hidden1" value="">
    <table class="bordered" id="email_filters" {get_display_style element_name="email_filters"}>
    <tr>
        <td>
            <span>{t}Subject/Body{/t}:</span><br />
            <input type="text" name="keywords" size="20" value="{$options.keywords|escape:"html"}">
        </td>
        <td>
            <span>{t}Sender{/t}:</span><br />
            <input type="text" name="sender" size="20" value="{$options.sender|escape:"html"}">
        </td>
        <td>
            <span>{t}To{/t}:</span><br />
            <input type="text" name="to" size="20" value="{$options.to|escape:"html"}">
        </td>
        <td>
            <span>{t}Email Account{/t}:</span><br />
            <select name="ema_id">
                <option value="">{t}any{/t}</option>
                {html_options options=$accounts selected=$options.ema_id}
            </select>
        </td>
        <td>
            <input type="submit" value="{t}Search{/t}">
            <input type="button" value="{t}Clear{/t}" id="clear_button">
        </td>
    </tr>
    <tr>
        <td colspan="5">
            <table width="100%" cellspacing="0" border="0" cellpadding="0">
                <tr>
                    <td nowrap width="50%">
                        <label>
                        <input {if $options.filter.arrival_date|default:'' == "yes"}checked{/if} type="checkbox" name="filter[arrival_date]" value="yes" id="arrival_date">
                            {t}Filter by Arrival Date{/t}:
                        </label><br />
                        <select name="arrival_date[filter_type]">
                            <option {if $options.filter.arrival_date|default:'no' != 'no' && $options.arrival_date.filter_type == "greater"}selected{/if} value="greater">{t}Greater Than{/t}</option>
                            <option {if $options.filter.arrival_date|default:'no' != 'no' && $options.arrival_date.filter_type == "less"}selected{/if} value="less">{t}Less Than{/t}</option>
                            <option {if $options.filter.arrival_date|default:'no' != 'no' && $options.arrival_date.filter_type == "between"}selected{/if} value="between">{t}Between{/t}</option>
                        </select>&nbsp;
                        {html_select_date field_array="arrival_date" prefix="" start_year="-10" end_year="+10" all_extra='class="default"'}
                    </td>
                    <td nowrap id="arrival_end_date" width="50%" valign="bottom">
                        <span>{t}Arrival Date{/t}: <i>({t}End date{/t})</i></span><br />
                        {html_select_date field_array="arrival_date_end" prefix="" start_year="-10" end_year="+10" all_extra='class="default"'}
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    </table>
</form>

<br />
