<?php
    Yii::app()->clientScript->registerScript('submit', '
        $(document).ready( function() {
            $("#submit_button").click(function() {
                $(this).prop("disabled",true)
                .parents("form").submit();
            });
        })
    ');

    $model->FUN_HORAMANHAINICIO = substr($model->FUN_HORAMANHAINICIO, 0, 5);
    $model->FUN_HORAMANHAFIM    = substr($model->FUN_HORAMANHAFIM, 0, 5);
    $model->FUN_HORATARDEINICIO = substr($model->FUN_HORATARDEINICIO, 0, 5);
    $model->FUN_HORATARDEFIM    = substr($model->FUN_HORATARDEFIM, 0, 5);
?>
<div class="form">
    <?php
    $form = $this->beginWidget('GxActiveForm', array(
        'id'                   => 'funcionarios-form',
        'enableAjaxValidation' => false,
        'focus'                => array($model, 'FUN_NOME'),
        'htmlOptions'          => array('class'=>'col-xs-12 form-cadastro')
    ));

    $this->widget('application.extensions.emultiselect.EMultiSelect');
    ?>
    <?= FaHtml::getFormInfo($form, $model); ?>
    <fieldset class="dark radius border-box col-xs-12 col-sm-12 col-md-12">
        <strong class="col-xs-12 col-sm-12 col-md-12 legenda">Dados do funcionário</strong>
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_NOME'); ?>
            <?= $form->textField($model, 'FUN_NOME', array('maxlength' => 50,'class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_NOME'); ?>
        </div><!-- row -->
        <div class="col-xs-12 col-sm-6 col-md-4">
            <div class="form-group col-xs-12 input-group reload-username">
                <?= $form->labelEx($model, 'FUN_USUARIO'); ?>
                <?= $form->textField($model, 'FUN_USUARIO', array('maxlength' => 50,'class' => 'remove-radius-right col-xs-12 col-sm-6 col-md-4 form-control btn-on-right')); ?>
                <span class="input-group-btn"><input id="reload-username" class="btn btn-default" type="button" value="Regerar nome"></span>
            </div>
            <?= $form->error($model, 'FUN_USUARIO'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?php $model->FUN_SENHA = ''; ?>
            <?= $form->labelEx($model, 'FUN_SENHA'); ?>
            <?= $form->passwordField($model, 'FUN_SENHA', array('maxlength' => 50)); ?>
            <?= $form->error($model, 'FUN_SENHA'); ?>
        </div><!-- row -->
        <div class="clearfix"></div>
        <div class="form-group col-xs-12 col-sm-6 col-md-3">
            <?= $form->labelEx($model, 'FUN_EMAIL'); ?>
            <?= $form->textField($model, 'FUN_EMAIL', array('maxlength' => 50, 'filter' => 'email', 'class' => 'col-xs-12 col-sm-6 col-md-4 mailtolower')); ?>
            <?= $form->error($model, 'FUN_EMAIL'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-3">
            <?= $form->labelEx($model, 'FUN_FONE'); ?>
            <?= $form->textField($model, 'FUN_FONE', array('maxlength' => 14, 'class' => 'mask_telefone col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_FONE'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-3">
            <?= $form->labelEx($model, 'FUN_CELULAR'); ?>
            <?= $form->textField($model, 'FUN_CELULAR', array('maxlength' => 14, 'class' => 'mask_telefone col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_CELULAR'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-3">
            <?= $form->labelEx($model, 'FUN_SKYPE'); ?>
            <?= $form->textField($model, 'FUN_SKYPE', array('maxlength' => 14, 'class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_SKYPE'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_IDREVENDA'); ?>
            <?= $form->dropDownList($model, 'FUN_IDREVENDA', GxHtml::listDataEx(Revendas::model()->findAll('REV_SITUACAO="A" order by REV_NOME')), array('prompt' => 'Selecione')); ?>
            <?= $form->error($model, 'FUN_IDREVENDA'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_COPIA_EMAIL_PENDENCIAS'); ?>
            <?= $form->dropDownList($model, 'FUN_COPIA_EMAIL_PENDENCIAS', array('0' => 'Inativo', '1' => 'Ativo'), array('class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_COPIA_EMAIL_PENDENCIAS'); ?>
        </div><!-- row -->
        <div class="clearfix"></div>
    </fieldset>
    <fieldset class="dark radius border-box col-xs-12 col-sm-12 col-md-12">
        <strong class="col-xs-12 col-sm-12 col-md-12 legenda">Unidades e regiões com acesso</strong>
        <div class="col-xs-12 col-sm-12 col-md-6">
            <label>Unidades</label>
            <?php
                if (!isset($_POST['Revendas']) || !is_array($_POST['Revendas'])) {
                    $data = FuncionariosRevendas::model()->findAll('FRV_IDFUNCIONARIO=:RedId', array(':RedId' => $model->FUN_IDFUNCIONARIO));
                    $data = CHtml::listData($data, 'FRV_ID', 'FRV_IDREVENDA');
                } else {
                    $data = $_POST['Revendas'];
                }
                echo CHtml::dropDownList('Revendas[]', $data, GxHtml::listDataEx(Revendas::model()->findAll('REV_SITUACAO="A" order by REV_FANTASIA')), array(
                        'multiple' => 'multiple',
                        'key'      => 'cidades',
                        'class'    => 'multiselect',
                        'size' => '15'
                    )
                );
            ?>
            <?= $form->error($model, 'FUN_IDREVENDA'); ?>
        </div><!-- row -->

        <div class="col-xs-12 col-sm-12 col-md-6">
            <label>Regiões</label>
            <?php
                unset($data);
                $data     = array();
                $Revendas = array();
                if ($model->isNewRecord) {
                    if (isset($_POST['Revendas'])) {
                        $Revendas = $_POST['Revendas'];
                    } else {
                        $data = array(0);
                    }
                } else {
                    if (!isset($_POST['regioes'])) {
                        $Revendas = FuncionariosRevendas::model()->findAll('FRV_IDFUNCIONARIO = '.$model->FUN_IDFUNCIONARIO);
                        $Revendas = CHtml::listData($Revendas, 'FRV_IDREVENDA', 'FRV_IDREVENDA');
                        $data     = FuncionariosRegioes::model()->findAll('FUR_IDFUNCIONARIO=:FunId', array(':FunId' => $model->FUN_IDFUNCIONARIO));
                        $data     = CHtml::listData($data, 'FUR_IDREGIAO', 'FUR_IDREGIAO');
                    } else {
                        $Revendas = isset($_POST['Revendas']) ? $_POST['Revendas'] : array(0);
                        $data     = isset($_POST['regioes']) ? $_POST['regioes'] : array(0);
                    }
                }
                if (count($Revendas) == 0) {
                    $Revendas[] = 0;
                }

                echo CHtml::dropDownList('regioes[]', $data, GxHtml::encodeEx(GxHtml::listDataEx(Regioes::model()->findAll("REG_IDREVENDA IN (".implode(',', $Revendas).") order by REG_DESCRICAO")), false, true), array('multiple' => 'multiple', 'key' => 'regioes', 'size' => '15', 'class'  => 'multiselect'));
            ?>
        </div>
    </fieldset>
    <fieldset class="dark radius border-box col-xs-12 col-sm-12 col-md-12">
        <strong class="col-xs-12 col-sm-12 col-md-12 legenda">Quando pode acessar</strong>
        <div class="form-group col-xs-12 col-sm-6 col-md-4" id="selecao_restricao">
            <?= $form->labelEx($model, 'FUN_RESTRICAOACESSO'); ?>
            <?= $form->dropDownList($model, 'FUN_RESTRICAOACESSO', array(Funcionarios::SEM_RESTRICAO => 'Sem restrição', Funcionarios::SOMENTE_DIAS => 'Somente dias', Funcionarios::DIAS_HORARIO => 'Dias e horário'), array('class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_RESTRICAOACESSO'); ?>
        </div><!-- row -->
        <div class="clearfix"></div>
        <table width="500" border="0" cellspacing="3" cellpadding="0" class="form-group col-xs-12 col-sm-6 col-md-4" id="dias_acessos" style="<?php if($model->FUN_RESTRICAOACESSO == Funcionarios::SEM_RESTRICAO){ echo 'display:none'; } ?>">
            <caption class="align-left">Dias da semana</caption>
            <tr>
                <td width="21" valign="bottom">
                    <?= $form->checkBox($model, 'FUN_SEGUNDA', array('value' => 1, 'uncheckValue' => 0)); ?>
                </td>
                <td width="220" valign="top">
                    <?= $form->labelEx($model, 'FUN_SEGUNDA'); ?>
                </td>
                <td width="21" valign="bottom">
                    <?= $form->checkBox($model, 'FUN_TERCA', array('value' => 2, 'uncheckValue' => 0)); ?>
                </td>
                <td width="223" valign="top">
                    <?= $form->labelEx($model, 'FUN_TERCA'); ?>
                </td>
            </tr>
            <tr>
                <td valign="bottom">
                    <?= $form->checkBox($model, 'FUN_QUARTA', array('value' => 3, 'uncheckValue' => 0)); ?>
                </td>
                <td valign="top">
                    <?= $form->labelEx($model, 'FUN_QUARTA'); ?>
                </td>
                <td valign="bottom">
                    <?= $form->checkBox($model, 'FUN_QUINTA', array('value' => 4, 'uncheckValue' => 0)); ?>
                </td>
                <td valign="top">
                    <?= $form->labelEx($model, 'FUN_QUINTA'); ?>
                </td>
            </tr>
            <tr>
                <td valign="bottom">
                    <?= $form->checkBox($model, 'FUN_SEXTA', array('value' => 5, 'uncheckValue' => 0)); ?>
                </td>
                <td valign="top">
                    <?= $form->labelEx($model, 'FUN_SEXTA'); ?>
                </td>
                <td valign="bottom">
                    <?= $form->checkBox($model, 'FUN_SABADO', array('value' => 6, 'uncheckValue' => 0)); ?>
                </td>
                <td valign="top">
                    <?= $form->labelEx($model, 'FUN_SABADO'); ?>
                </td>
            </tr>
            <tr>
                <td valign="bottom">
                    <?= $form->checkBox($model, 'FUN_DOMINGO', array('value' => 7, 'uncheckValue' => 0)); ?>
                </td>
                <td valign="top">
                    <?= $form->labelEx($model, 'FUN_DOMINGO'); ?>
                </td>
                <td valign="bottom"></td>
                <td valign="top"></td>
            </tr>
        </table>
        <div id="horarios_acesso" style="<?php if($model->FUN_RESTRICAOACESSO == Funcionarios::SEM_RESTRICAO || $model->FUN_RESTRICAOACESSO == Funcionarios::SOMENTE_DIAS){ echo 'display:none'; } ?>">
            <div class="form-group col-xs-12 col-sm-6 col-md-4 horario">
                <?= $form->labelEx($model, 'FUN_HORAMANHAINICIO'); ?>
                <?= $form->textField($model, 'FUN_HORAMANHAINICIO', array('maxlength' => 5, 'style' => 'width:50px', 'class' => 'col-xs-6 col-sm-6 col-md-6 format_hora hora_inicio')); ?>
                <span>até</span> <?= $form->textField($model, 'FUN_HORAMANHAFIM', array('maxlength' => 5, 'style' => 'width:50px', 'class' => 'col-xs-6 col-sm-6 col-md-6 format_hora hora_final')); ?>
                <?= $form->error($model, 'FUN_HORAMANHAINICIO'); ?>
                <?= $form->error($model, 'FUN_HORAMANHAFIM'); ?>

                <div style="display:none">
                    <?= $form->labelEx($model, 'FUN_HORAMANHAFIM'); ?>
                </div>
            </div><!-- row -->
            <div class="form-group col-xs-12 col-sm-6 col-md-4 horario">
                <?= $form->labelEx($model, 'FUN_HORATARDEINICIO'); ?>
                <?= $form->textField($model, 'FUN_HORATARDEINICIO', array('maxlength' => 5, 'style' => 'width:50px', 'class' => 'col-xs-12 col-sm-6 col-md-4 format_hora hora_inicio2')); ?>
                <span>até</span> <?= $form->textField($model, 'FUN_HORATARDEFIM', array('maxlength' => 5, 'style' => 'width:50px', 'class' => 'col-xs-12 col-sm-6 col-md-4 format_hora hora_final2')); ?>
                <?= $form->error($model, 'FUN_HORATARDEINICIO'); ?>
                <?= $form->error($model, 'FUN_HORATARDEFIM'); ?>

                <div style="display:none">
                    <?= $form->labelEx($model, 'FUN_HORATARDEFIM'); ?>
                </div>
            </div><!-- row -->
        </div>
    </fieldset>
    <fieldset class="dark radius border-box col-xs-12 col-sm-12 col-md-12 privilegios">
        <strong class="col-xs-12 col-sm-12 col-md-12 legenda">Permissões de acesso</strong>
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_IDSETOR'); ?>
            <?= $form->dropDownList($model, 'FUN_IDSETOR', GxHtml::listDataEx(Setores::model()->findAll(array('order' => 'SET_DESCRICAO'))), array('prompt' => 'Selecione', 'class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_IDSETOR'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_IDFUNCAO'); ?>
            <?= $form->dropDownList($model, 'FUN_IDFUNCAO', GxHtml::listDataEx(Funcoes::model()->findAll('FNS_SITUACAO="A" order by FNS_DESCRICAO')), array('prompt' => 'Selecione', 'class' => 'col-xs-12 col-sm-6 col-md-4')); ?>
            <?= $form->error($model, 'FUN_IDFUNCAO'); ?>
        </div><!-- row -->
        <div class="form-group col-xs-12 col-sm-6 col-md-4">
            <?= $form->labelEx($model, 'FUN_PRM_PRIVILEGIO'); ?>
            <?php
            $privilegios = Util::getPrivilegiosList();
            natsort($privilegios);
            echo $form->dropDownList($model, 'FUN_PRM_PRIVILEGIO', $privilegios, array('prompt' => 'Selecione'));
            ?>
            <?= $form->error($model, 'FUN_PRM_PRIVILEGIO'); ?>
        </div><!-- row -->
        <div class="clearfix"></div>
        <fieldset>
            <legend>Comercial</legend>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_AGENDA_VENDEDOR'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_AGENDA_VENDEDOR'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_PRM_EXCECOES'); ?>
                <?= $form->labelEx($model, 'FUN_PRM_EXCECOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_PROSPECTOS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_PROSPECTOS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_CONTROLE_DOCUMENTOS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_CONTROLE_DOCUMENTOS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_CONTROLE_NEGOCIACOES'); ?>
                <?= $form->labelEx($model, 'FUN_CONTROLE_NEGOCIACOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_INTERESSADOS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_INTERESSADOS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_SOLICITACOES_CANCELAMENTO'); ?>
                <?= $form->labelEx($model, 'FUN_SOLICITACOES_CANCELAMENTO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_SOLICITACOES_TRANSFERENCIA'); ?>
                <?= $form->labelEx($model, 'FUN_SOLICITACOES_TRANSFERENCIA'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_SINCRONIZACAO'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_SINCRONIZACAO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_DESCONTO'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_DESCONTO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2" style="display:none;"> <!-- Remover isso -->
                <?= $form->checkBox($model, 'FUN_TBL_RDM'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_RDM'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_PRM_STATUS'); ?>
                <?= $form->labelEx($model, 'FUN_PRM_STATUS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_PRM_ABAPRODUTOS'); ?>
                <?= $form->labelEx($model, 'FUN_PRM_ABAPRODUTOS'); ?>
            </li>
        </fieldset>
        <fieldset>
            <legend>Suporte</legend>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_AGENDA_TECNICO'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_AGENDA_TECNICO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_ATENDIMENTOS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_ATENDIMENTOS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_IMPLANTACAO'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_IMPLANTACAO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_SOLICITACOES'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_SOLICITACOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_CADASTRO_SOLICITACOES'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_CADASTRO_SOLICITACOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_PENDENCIAS_LOCAL'); ?>
                <?= $form->labelEx($model, 'FUN_PENDENCIAS_LOCAL'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?php echo $form->checkBox($model, 'FUN_SOLICITACOES_PRIORITARIAS'); ?>
                <?php echo $form->labelEx($model, 'FUN_SOLICITACOES_PRIORITARIAS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?php echo $form->checkBox($model, 'FUN_QUALIFICAR_PENDENCIAS'); ?>
                <?php echo $form->labelEx($model, 'FUN_QUALIFICAR_PENDENCIAS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_COBRANCA_ATENDIMENTO_SUPORTE'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_COBRANCA_ATENDIMENTO_SUPORTE'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_TERMO_LEVANT_DADOS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_TERMO_LEVANT_DADOS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_EDITAR_PREVISOES_SOLICITACOES'); ?>
                <?= $form->labelEx($model, 'FUN_EDITAR_PREVISOES_SOLICITACOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_DADOSACESSO'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_DADOSACESSO'); ?>
            </li>
        </fieldset>
        <fieldset>
            <legend>Gerais</legend>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_ATAS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_ATAS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_TELEFONISTA'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_TELEFONISTA'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_NOTICIAS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_NOTICIAS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_NOVIDADES'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_NOVIDADES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_SUGESTOES'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_SUGESTOES'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_PENDENCIAS_CRM'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_PENDENCIAS_CRM'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_CADASTRAR_DOCS_FISCAIS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_CADASTRAR_DOCS_FISCAIS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?= $form->checkBox($model, 'FUN_TBL_METAS'); ?>
                <?= $form->labelEx($model, 'FUN_TBL_METAS'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?php echo $form->checkBox($model, 'FUN_TBL_CONTROLE_IMPLANTACAO'); ?>
                <?php echo $form->labelEx($model, 'FUN_TBL_CONTROLE_IMPLANTACAO'); ?>
            </li>
            <li class="col-xs-6 col-sm-4 col-md-2">
                <?php echo $form->checkBox($model, 'FUN_TBL_CONTROLE_POSVENDAS'); ?>
                <?php echo $form->labelEx($model, 'FUN_TBL_CONTROLE_POSVENDAS'); ?>
            </li>
            <li class="col-xs-12 col-sm-12 col-md-12">
                <i class="alert-info alert-no-background">**As opções abaixo são usadas combinadas a cadastros como Atas, Atendimentos, Prospecto/Clientes, Endereços (dos clientes), Interessados, etc.</i>
                <li class="col-xs-6 col-sm-3 col-md-2">
                    <div class="clearfix"></div>
                    <?= $form->checkBox($model, 'FUN_PRM_UPDATE'); ?>
                    <?= $form->labelEx($model, 'FUN_PRM_UPDATE'); ?>
                </li>
                <li class="col-xs-6 col-sm-3 col-md-2">
                    <?= $form->checkBox($model, 'FUN_PRM_INCLUIR'); ?>
                    <?= $form->labelEx($model, 'FUN_PRM_INCLUIR'); ?>
                </li>
            </li>
        </fieldset>
        <fieldset>
            <legend>Gráficos/Relatórios</legend>
            <ul>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_VISITA'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_VISITA'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_BRINDES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_BRINDES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_DOCUMENTOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_DOCUMENTOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_PENDENCIAS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_PENDENCIAS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_PENDENCIAS_CRM'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_PENDENCIAS_CRM'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_CLIENTES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_CLIENTES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_FINANCEIRO'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_FINANCEIRO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_GRAFICO_VISITA'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_GRAFICO_VISITA'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_CANCELAMENTOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_CANCELAMENTOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2" style="display:none;">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_RDM'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_RDM'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RELATORIO_COMISSAO'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RELATORIO_COMISSAO'); ?>
                </li>
            </ul>
        </fieldset>
        <fieldset>
            <legend>Cadastros</legend>
            <ul>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_BAIRROS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_BAIRROS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_BRINDES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_BRINDES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_CIDADES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_CIDADES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_CRITERIOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_CRITERIOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_CONCORRENTES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_CONCORRENTES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_CONDICOES_PAGAMENTO'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_CONDICOES_PAGAMENTO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_DOCUMENTOS_FISCAIS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_DOCUMENTOS_FISCAIS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_FORMULARIOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_FORMULARIOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_FUNCIONARIOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_FUNCIONARIOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_FUNCOES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_FUNCOES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_TBL_CADASTRO_METAS_GRUPO'); ?>
                    <?php echo $form->labelEx($model, 'FUN_TBL_CADASTRO_METAS_GRUPO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_TBL_CADASTRO_METAS_UNIDADES'); ?>
                    <?php echo $form->labelEx($model, 'FUN_TBL_CADASTRO_METAS_UNIDADES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_TBL_CADASTRO_METAS_VENDEDORES'); ?>
                    <?php echo $form->labelEx($model, 'FUN_TBL_CADASTRO_METAS_VENDEDORES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_PRODUTOS_CONVERSAO'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_PRODUTOS_CONVERSAO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_MOTIVOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_MOTIVOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_NIVEIS_COMPLEXIDADE'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_NIVEIS_COMPLEXIDADE'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_OBS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_OBS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_PRODUTOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_PRODUTOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_PROJETOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_PROJETOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_QUESTIONARIO'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_QUESTIONARIO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_RAMOS_DE_ATIVIDADE'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_RAMOS_DE_ATIVIDADE'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_REGIOES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_REGIOES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_SERVICOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_SERVICOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_SETORES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_SETORES'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_CADASTRO_SOLICITACOES_CANCELAMENTO'); ?>
                    <?php echo $form->labelEx($model, 'FUN_CADASTRO_SOLICITACOES_CANCELAMENTO'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_CADASTRO_SOLICITACOES_TRANSFERENCIA'); ?>
                    <?php echo $form->labelEx($model, 'FUN_CADASTRO_SOLICITACOES_TRANSFERENCIA'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_REVENDAS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_REVENDAS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_VEICULOS'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_VEICULOS'); ?>
                </li>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?= $form->checkBox($model, 'FUN_TBL_VERSOES'); ?>
                    <?= $form->labelEx($model, 'FUN_TBL_VERSOES'); ?>
                </li>
            </ul>
        </fieldset>
        <fieldset>
            <legend>Implantação</legend>
            <ul>
                <li class="col-xs-6 col-sm-4 col-md-2">
                    <?php echo $form->checkBox($model, 'FUN_TECNICO_IMPLANTACAO'); ?>
                    <?php echo $form->labelEx($model, 'FUN_TECNICO_IMPLANTACAO'); ?>
                </li>
            </ul>
        </fieldset>
        <div class="col-xs-12 col-sm-12 col-md-12" id="div_projetos">
            <?php
                echo $form->labelEx($model, 'FUN_IDPROJETO');
                $data = (!isset($_POST['Projetos']) || !is_array($_POST['Projetos']))?FuncionariosProjetos::model()->getIds($model->FUN_IDFUNCIONARIO):$_POST['Projetos'];
                echo CHtml::dropDownList('Projetos[]', $data, GxHtml::listDataEx(Projetos::model()->findAll('PRO_STATUS="1" AND PRO_IDPROJETO != 20 order by PRO_PROJETO')), array(
                    'multiple' => 'multiple',
                    'key'      => 'projetos',
                    'class'    => 'multiselect',
                    'size' => '15'
                    )
                );
            ?>
            <?= $form->error($model, 'FUN_IDPROJETO'); ?>
        </div><!-- row -->
    </fieldset>

    <div class="clearfix"></div>
    <?php
    if(!isset($hide_save) || !$hide_save){
        echo FaHtml::saveButton();
    }
    $this->endWidget();
    ?>
</div>
<!-- form -->
<?php
    $cs = Yii::app()->getClientScript();
    $cs->registerScriptFile(FaHtml::getJsUrl('funcionarios.js'));
?>
<script type="text/javascript">
    function mostrarProjetos() {
        if($("#Funcionarios_FUN_TBL_SOLICITACOES").is(':checked')) {
            $('#div_projetos').show().css('margin-bottom', '15px');
            $('#projetos').multiselect({sortable:false,searchable:true});
            $('.connected-list').css('height', '250px');
        } else {
            $('#div_projetos').hide();
            $('#projetos').multiselect('destroy');
        }
    }
    $(document).ready(function() {
        mostrarProjetos();
    });
    $("#Funcionarios_FUN_TBL_SOLICITACOES").on("change", function() {
        mostrarProjetos();
    });
    $("#Funcionarios_FUN_PRM_PRIVILEGIO" ).on("change", function() {
        checkPermissoes($(this).val());
        mostrarProjetos();
    });
    jQuery('body').undelegate('#Revendas','change').delegate('#Revendas','change',function() {
        jQuery.ajax({
            type: 'POST',
            url: createUrl('regioes/dynamicRevenda'),
            cache: false,
            data: {
                'Revendas': $(this).val(),
            },
            success: function(html) {
                var regioes = $('#regioes').val();
                jQuery("#regioes").html(html);
                $('#regioes').val(regioes);
                $('#regioes').multiselect("destroy").multiselect({sortable:false,searchable:true});
            }
        });
        return false;
    });
    function gerarNome() {
        var nome = $.trim($("#Funcionarios_FUN_NOME").val());
        $("#Funcionarios_FUN_USUARIO").val(nome.toUserName());
    }
    $("#Funcionarios_FUN_NOME").blur(function() {
        var nome = $.trim($(this).val());
        $(this).val(nome.toLowerCase().camelize());
        if($("#Funcionarios_FUN_USUARIO").val().length == 0) {
            gerarNome();
        }
    });
    $("#reload-username").click(gerarNome);
    jQuery(document).ready(function($) {
        $(document).on('change', '#selecao_restricao select', function(event) {
            var restricao = $(this).val();
            if(restricao == 0){
                $("#dias_acessos, #horarios_acesso").hide();
            }
            else if(restricao == 1){
                $("#dias_acessos").show();
                $("#horarios_acesso").hide();
            }
            else{
                $("#dias_acessos").show();
                $("#horarios_acesso").show();
            }
        });
    });
</script>
<style type="text/css">
    .reload-username{
        margin-bottom: 5px;
    }
</style>
