<div id="div-documentos-fiscais">
    <h1>Documentos Fiscais &raquo; <?php echo $nomeCliente; ?></h1>
    <div class="portlet" id="yw2">
        <div class="portlet-content">
            <ul id="yw3">
                <li><a class="search-button" href="#" id="abrir-formulario"><span class="text">Abrir Formulário</span> <?php echo FaHtml::iconSetaClose(false); ?></a></li>
            </ul>
        </div>
    </div>
    <div class="form">
        <?php
        $form = $this->beginWidget('GxActiveForm', array(
            'action' => Yii::app()->createUrl("clientesDocumentosFiscais/create"),
            'id' => 'documentos-fiscais-form',
            'enableAjaxValidation' => false,
            'htmlOptions' => array('style' => 'display:none')
            )
        );

        $this->widget('application.extensions.emultiselect.EMultiSelect'); 

        ?>

        <div class="row medium">
            <?php
            $DocumentosFiscais = ClientesDocumentosFiscais::model()->findAll("CDF_IDCLIENTE = " . $model->CLI_IDCLIENTE);
            $data = CHtml::listData($DocumentosFiscais, 'CDF_IDDOCUMENTO', 'CDF_IDDOCUMENTO');

            echo '<input name="IdCliente" type="hidden" value="' . $model->CLI_IDCLIENTE . '" />';

            echo CHtml::dropDownList('documento[]', $data, GxHtml::encodeEx(GxHtml::listDataEx(DocumentosFiscais::model()->findAll('DFS_SITUACAO="A" ORDER by DFS_DESCRICAO ASC')), false, true), array('multiple' => 'multiple', 'key' => 'documento', 'class' => 'multiselect', 'size' => 10));

            $redirect = $setor == 1 ? 'savview' : ($setor == 2 ? 'view' : 'posvendas_view');
            echo '<input type="hidden" name="redirect" value="'.$redirect.'" />';
            ?>
        </div>

        <?php
        echo FaHtml::saveButton();
        $this->endWidget();
        ?>
        <div class="row clientes-vinculados">
            <h2><?php echo GxHtml::encode('Documentos fiscais'); ?></h2>
            <span><?php if(count($DocumentosFiscais) == 0) echo 'Nenhum documento fiscal.'; ?></span>
            <ul id="clientes-vinculados">
                <?php
                foreach($DocumentosFiscais as $doc) {
                    echo '<li>' . $doc->DocumentoFiscal->DFS_DESCRICAO . '</li>';
                }
                ?>
            </ul>
        </div>
        <div class="clear"></div>
    </div><!-- form -->
    
    <script type="text/javascript">
        $('#abrir-formulario').click( function() {
            if($('.text').html() == 'Abrir Formulário') {
                $(this).html('<span class="text">Fechar Formulário</span> <?php echo FaHtml::iconSetaOpen(false); ?></a>');
            } else {
                $(this).html('<span class="text">Abrir Formulário</span> <?php echo FaHtml::iconSetaClose(false); ?></a>');
            }
            $('#documentos-fiscais-form').slideToggle();
        });
    </script>
</div>