<!-- BEGIN {$smarty.template} -->
<script type="text/javascript">
{literal}
    $(document).ready(function() {

        $('.cbxsel').selectable( { 
            distance: 5,
            selected: function(event, ui) { $(ui.selected).find(":checkbox").attr('checked', true); },
            unselected: function (event, ui) { $(ui.unselected).find(":checkbox").attr('checked', false); }
        });

        var dates = $('#quot_datefrom, #quot_dateto').datepicker({
            changeMonth: true,
            changeYear: true,
            numberOfMonths: 2,
            dateFormat: 'yy-mm-dd',
            showOn: 'both',
            buttonImage: '../img/phpaga/cal.png',
            buttonImageOnly: true,
            onSelect: function(selectedDate) {
                var option = this.id == "quot_datefrom" ? "minDate" : "maxDate";
                var instance = $(this).data("datepicker");
                var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                dates.not(this).datepicker("option", option, date);
            }

        });

        /* Print dialog */
        $("#printbill").dialog({
                autoOpen: false,
                modal: true,
                buttons: {
                    "{/literal}{t}Open{/t}{literal}": function() {
                       $('#pdf_download').val('0');
                       $('#bill_print_form').submit(); 
                        $(this).dialog( "close" );
                    },
                    "{/literal}{t}Download{/t}{literal}": function() {
                       $('#pdf_download').val('1');
                       $('#bill_print_form').submit(); 
                        $(this).dialog( "close" );
                    },
                    Cancel: function() {
                        $(this).dialog( "close" );
                    }
                },
                close: function() {
                }
        });
        $("#printbill").parent().appendTo($('#bill_print_form')); // This is necessary for the dialog's form fields to be used on submit.

        $( "#select-quotations-message" ).dialog({
                modal: true,
                autoOpen: false,
                buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" );
                    }
                }
        });

        $('#export_pdf').click(function() { 
            if ($('.idcbx').filter(':checked').length==0)
                $( "#select-quotations-message" ).dialog( "open" ); 
            else
                $( "#printbill" ).dialog( "open" ); 
        });
    });
{/literal}
</script>

<div id="select-quotations-message" title="{t}Select quotations{/t}">
    <p>
    <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 50px 0;"> </span>
    {t}Please select the quotations you would like to print.{/t}
    </p>
</div>

<form action="{$FORM_ACTION}" method="post">

  <fieldset class="search">
    <legend>{t}Search quotations{/t}</legend>

    <label for="quot_number">{t}Quotation nr.{/t}:</label>
    <input type="text" class="tinput" id="quot_number" name="quot_number" value="{$quotInfo.quot_number|wash}" size="10" maxlength="10">
    <br>

    <label for="cpn_id">{t}Recipient (company){/t}:</label>
      <select id="cpn_id" name="cpn_id">
        {html_options options=$select_cpn selected=$quotInfo.cpn_id}
      </select>
    <br>

    <label for="quot_additional_line">{t}Additional information{/t}:</label>
     <input type="text" class="tinput" id="quot_additional_line" name="quot_additional_line" value="{$quotInfo.quot_additional_line|wash}" size="50" maxlength="255">
    <br>

    <label for="quot_datefrom">{t}Between{/t}:</label>
    <input type="text" class="tinput" id="quot_datefrom" name="quot_datefrom" value="{$quotInfo.quot_datefrom|wash}" size="10" maxlength="10" title="yyyy-mm-dd">
    <br>

    <label for="quot_dateto">{t}And{/t}:</label>
    <input type="text" class="tinput" id="quot_dateto" name="quot_dateto" value="{$quotInfo.quot_dateto|wash}" size="10" maxlength="10" title="yyyy-mm-dd">
    <br>

    <input type="submit" name="submit" value="{t}Search{/t}">
  </fieldset>
</form>

<form action="quotation_pdf.php" method="GET" id="bill_print_form">
    <input type="hidden" name="download" value="0" id="pdf_download" />
    <div id="printbill" title="{t}Print selected invoices to PDF{/t}">

        <h2>{t}Print options{/t}</h2>
        <input type="checkbox" class="cbox" name="letterhead" id="letterhead" value="1" {if $smarty.const.PHPAGA_PDF_PRINT_LETTERHEAD_DEFAULT}checked="checked"{/if}><label for="letterhead">{t}Print letterhead{/t}</label><br />
    </div>

    <table cellspacing="0">
        <caption><em>{t}Quotations{/t}</em>
            {if $perm_quotations}[ <a href="add_quotation.php">{t}Create quotation{/t}</a> 
            | <a id="export_pdf" href="#">{t}Print selected to PDF{/t}</a> 
            ]{else}&nbsp;{/if}
        </caption>
        {if (count($rows) > 0)}
        <thead>
            <tr>
                <th class="number"> {t}Quotation nr.{/t} </th>
                <th class="time"> {t}Quotation date{/t} </th>
                <th> {t}Recipient (company){/t} </th>
                <th> <img src="img/phpaga/page_white_acrobat.png" height="16" width="16" border="0" alt="{t}PDF{/t}" title="{t}PDF{/t}"> </th>                
                <th> {t}Actions{/t} </th>
            </tr>
        </thead>
        <tbody class="cbxsel">
            {section name=quotations loop=$rows}
            <tr>
                <td class="number"> <a href="quotation.php?id={$rows[quotations].quot_id}">{$rows[quotations].quot_number|wash}</a> </td>
                <td class="time"> <a href="quotation.php?id={$rows[quotations].quot_id}">{$rows[quotations].quot_date|wash|date_format:$smarty.const.PHPAGA_DATEFORMAT_SHORT}</a> </td>
                <td> <a href="company.php?id={$rows[quotations].cpn_id}">{$rows[quotations].cpn_name|wash}</a> </td>
                <td> <input class="idcbx" type="checkbox" name="id[]" value="{$rows[quotations].quot_id}"> </td>
                <td class="actions"><a href="quotation.php?id={$rows[quotations].quot_id}"><img src="img/phpaga/view.png" height="16" width="16" border="0" alt="{t}View{/t}" title="{t}View{/t}"></a></td>
            </tr>
            {/section}
        </tbody>
        {else}
        <tr>
            <td class="last" colspan="4"> {t}No quotations matching your search criteria were found.{/t} </td>
        </tr>
        {/if}
        {if strlen($BROWSE)}
        <tfoot>
            <tr>
                <td class="browse" colspan="4"> {$BROWSE} </td>
            </tr>
        </tfoot>
        {/if}
    </table>
</form>

<!-- END {$smarty.template} -->
