<div class="wide form">

    <?php
    $form = $this->beginWidget('GxActiveForm', array('action' => Yii::app()->createUrl($this->route),'method' => 'get'));
    $this->widget('application.extensions.EChosen.EChosen', array('target' => '.echosen','useJQuery' => true));

    $countRevendas = count(User::getRevendas());
    ?>

    <div class="row">
        <?php echo $form->label($model, 'MKT_TEXTO', array('label' => 'Busca textual')); ?>
        <?php echo $form->textField($model, 'MKT_TEXTO'); ?>
    </div>

    <div class="row">
        <?php echo $form->label($model, 'MKT_DATA_LANCAMENTO'); ?>
        <?php $form->widget('ext.Utils.widgets.CrmDatePicker', array('model' => $model, 'attribute' => 'MKT_DATA_LANCAMENTO')); ?> à 
        <?php $form->widget('ext.Utils.widgets.CrmDatePicker', array('model' => $model, 'attribute' => 'MKT_DATA_LANCAMENTO_FINAL')); ?>
    </div>

    <div class="row">
        <?php echo $form->label($model, 'MKT_DATA_ENVIO'); ?>
        <?php $form->widget('ext.Utils.widgets.CrmDatePicker', array('model' => $model, 'attribute' => 'MKT_DATA_ENVIO')); ?> à 
        <?php $form->widget('ext.Utils.widgets.CrmDatePicker', array('model' => $model, 'attribute' => 'MKT_DATA_ENVIO_FINAL')); ?>
    </div>
    
    <?php if (User::canListUsers()) { ?>
        <div class="row">
            <?php echo $form->label($model, 'MKT_RESPONSAVEL'); ?>
            <?php echo $form->dropDownList($model, 'MKT_RESPONSAVEL', User::getFuncionariosComercialAdministrativo(), array('prompt' => 'Selecione')); ?>
        </div>
        <div class="row">
            <?php echo $form->label($model, 'MKT_AUTOR'); ?>
            <?php echo $form->dropDownList($model, 'MKT_AUTOR', User::getFuncionariosComercialAdministrativo(), array('prompt' => 'Selecione')); ?>
        </div>
    <?php } ?>
    <div class="search_colunas">
        <p>Filtros aplicados</p>
        <?php if($countRevendas > 1) { ?>
        <div class="row">
            <?php echo $form->label($model, 'Revenda'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'Revenda',
                'data' => User::getRevendas(),
                'options' => ['noneSelectedText' => 'Todas']
                )
            );
            ?>
        </div>
        <?php } ?>

        <div class="row">
            <?php echo $form->labelEx($model, 'Regiao'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'Regiao',
                'data' => User::getRegioes(),
                'options' => ['noneSelectedText' => 'Todas']
                )
            );
            ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'Estado'); ?>
            <?php echo $form->dropDownList($model, 'Estado', User::getEstados(), array('class' => 'echosen', 'multiple' => 'multiple')); ?>
            <?php echo $form->error($model, 'Estado'); ?>
        </div><!-- row -->

        <div class="row">
            <?php echo $form->labelEx($model, 'Cidade'); ?>
            <?php echo $form->dropDownList($model, 'Cidade', User::getCidadesEstados(), array('class' => 'echosen', 'multiple' => 'multiple')); ?>
            <?php echo $form->error($model, 'Cidade'); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'Produto'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'Produto',
                'data' => CacheUtil::getProdutosList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'ModuloComplementar'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'ModuloComplementar',
                'data' => CacheUtil::getModulosComplementaresList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'DocumentoFiscal'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'DocumentoFiscal',
                'data' => CacheUtil::getDocumentosFiscaisList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'RamoAtividade'); ?>
            <?php echo $form->dropDownList($model, 'RamoAtividade', CacheUtil::getRamosAtividadeList(), array('multiple' => 'multiple', 'class' => 'echosen')); ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'Status'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'Status',
                'data' => Util::getStatusClienteList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'TipoPessoa'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'TipoPessoa',
                'data' => Util::getTiposPessoaList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'NivelInteresse'); ?>
            <?php echo $form->dropDownList($model, 'NivelInteresse', Util::getNiveisInteresselist(), array('multiple' => 'multiple', 'class' => 'echosen')); ?>
        </div>

        <div class="col-sm-6 col-md-4 col-lg-4 row">
            <?php echo $form->labelEx($model, 'ComoConheceu'); ?>
            <?php
            $this->widget('application.extensions.multiselect.JMultiSelect', array(
                'model' => $model,
                'attribute' => 'ComoConheceu',
                'data' => CacheUtil::getComoNosConheceuList(),
                'options' => ['noneSelectedText' => 'Todos']
                )
            );
            ?>
        </div>
    </div>

    <div class="row buttons">
        <input type="hidden" name="busca" value="1" />
        <?php echo FaHtml::searchButton(); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- search-form -->
<script>
    $(document).ready(function () {
        jQuery('body').undelegate('#Atendimentos_ATD_IDREVENDA','change').delegate('#Atendimentos_ATD_IDREVENDA','change',function(){
            var revenda = $('#Atendimentos_ATD_IDREVENDA').val();
            var funcionario = $("#Atendimentos_ATD_IDFUNCIONARIO").val();
            jQuery.ajax({
                type: 'GET',
                url: createUrl('autocomplete/vendedor'),
                cache: false,
                data: {revenda: revenda, selecione:true},
                success: function(html){
                    jQuery("#Atendimentos_ATD_IDFUNCIONARIO").html(html);
                    selectField('Atendimentos_ATD_IDFUNCIONARIO', funcionario);
                    $('#Atendimentos_ATD_IDFUNCIONARIO').trigger('change');
                }
            });

            return false;
        });

        jQuery('body').undelegate('#Atendimentos_ATD_IDFUNCIONARIO','change').delegate('#Atendimentos_ATD_IDFUNCIONARIO','change',function(){
            var revenda = $('#Atendimentos_ATD_IDREVENDA').val();
            var funcionario = $("#Atendimentos_ATD_IDFUNCIONARIO").val();
            var cidade = $("#Atendimentos_ATD_CIDADE").val();
            jQuery.ajax({
                type: 'GET',
                url: createUrl('autocomplete/cidades'),
                cache: false,
                data: {revenda: revenda, funcionario: funcionario, selecione:false},
                success: function(html){
                    jQuery("#Atendimentos_ATD_CIDADE").html(html);
                    selectField('Atendimentos_ATD_CIDADE', cidade);
                    $(".echosen").trigger("chosen:updated");
                }
            });

            return false;
        });
    });
</script>