<link href="<?php echo ROOT_URL; ?>src/jq-ui/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
<script src="<?php echo ROOT_URL; ?>src/jq-ui/jquery-ui.min.js" type="text/javascript"></script>
<style>
.conteudo-pagina {
    max-width: initial;
    margin: auto;
    /*padding: 0px 0px 0px 0px;*/
    z-index: 3;
    background-color: #EEEEEE;
}
/*ajuste form*/
.form-signin {
  max-width: 580px;
  padding: 15px 35px 45px;
  margin: 0 auto;
  background-color: #fff;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
  margin-bottom: 30px;
}
.form-signin .checkbox {
  font-weight: normal;
}
.form-signin .form-control {
  position: relative;
  font-size: 16px;
  height: auto;
  padding: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.back-page
{
    background-color: #EEEEEE;
}

/*REC SENHA preloader*/
body{background:#ECF0F1}

.load{
    position:absolute;
    /*top:50%;*/
    left:50%;
    transform:translate(-50%, -50%);
  /*change these sizes to fit into your project*/
  width:100px;
  height:100px;
  display: none;
  z-index: 1;
}
.load hr{border:0;margin:0;width:40%;height:40%;position:absolute;border-radius:50%;animation:spin 2s ease infinite}

.load :first-child{background:#19A68C;animation-delay:-1.5s}
.load :nth-child(2){background:#193B48;animation-delay:-1s}
.load :nth-child(3){background:#19A68C;animation-delay:-0.5s}
.load :last-child{background:#193B48}

@keyframes spin{
  0%,100%{transform:translate(0)}
  25%{transform:translate(160%)}
  50%{transform:translate(160%, 160%)}
  75%{transform:translate(0, 160%)}
}
</style>
<div class="involucro-conteudo-pagina">

    <div class="conteudo-pagina">
        <div class="row">
            <div class="col-md-12">
                <div class="conteudo-direito">

                    <?php
                    if ( isset($msg) ) {
                        echo '<div class="alert alert-warning">Dados incorretos</div>';
                    }
                    ?>

<?php if ( isset($novo_cadastro) ) { ?>
                        <form class="form-signin" action="<?php echo current_url() ?>" method="post">
                        <!--<div class="form-group">
                                <label for="nome">Nome</label>
                                <input type="text" class="form-control" name="nome" id="nome" placeholder="Digite seu nome completo" min="6" required value="">
                            </div>-->
                            <div class="form-group">
                                <label for="email">Email</label>
                                <?php echo form_error('email'); ?>
                                <input type="email" class="form-control ui-autocomplete-input" name="email" id="imz-user-email" placeholder="Informe um email válido" min="6" required value="<?php echo set_value('email'); ?>">
    <?php echo form_error('email', '<div class="label label-danger">', '</div>'); ?>
                            </div>


                            <div class="row">
                                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                                    <div class="form-group">
                                        <label for="Numero">DDD</label>
                                        <input required="" pattern="\d{2}" title="Digite apenas dois digitos" min="2" maxlength="2"  type="tel" class="form-control ddd-aluno" id="ddd" name="ddd" placeholder="DDD">
                                    </div>
                                </div>
                                <div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
                                    <label for="Numero">Celular/ Whatsapp*</label>
                                    <div class="form-group">
                                        <input required="" pattern="\d{9}" title="Digite 9 digitos" min="9" maxlength="9" type="tel" class="form-control tel-aluno" id="telefone" name="celular" placeholder="Número do Celular">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="error_ddd"></div>
                                <div class="error_celular"></div>
                            </div>


<!--                            <div class="form-group">
                                <label for="Numero">Celulartt</label>
                                <div class="row">
                                    <div class="col-md-2">
                                        <input type="text" class="form-control" value="<?php echo set_value('ddd_celular'); ?>" name="ddd" id="ddd" maxlength="2" minlength="2" required="" placeholder="DDD">
                                    </div>
                                    <div class="col-xs-4">
                                        <input type="text" class="form-control" value="<?php echo set_value('celular'); ?>" name="celular" id="celular" maxlength="12" minlength="8" required="" id="telefone" placeholder="Celular">
                                    </div>
                                </div>
    <?php echo form_error('ddd_celular', '<div class="label label-warning">', '</div>'); ?>
    <?php echo form_error('celular', '<div class="label label-warning">', '</div>'); ?>
                            </div>-->
                            <!--<div class="form-group">
                                <label for="senha">Senha</label>
                                <?php echo form_error('senha'); ?>
                                <input type="password" class="form-control" name="senha" id="senha" placeholder="Digite uma senha" min="6" required value="<?php echo set_value('senha'); ?>">
    <?php echo form_error('senha', '<div class="label label-danger">', '</div>'); ?>
                            </div>-->
                            <!--<div class="form-group">
                                <label for="senha2">Repita a sua senha</label>
                                <?php echo form_error('senha2'); ?>
                                <input type="password" class="form-control" name="senha2" id="senha2" placeholder="Repita a senha digitada" min="6" required value="<?php echo set_value('senha2'); ?>">
                            <?php echo form_error('senha2', '<div class="label label-danger">', '</div>'); ?>
                            </div>-->
                            <?php
                            if ($curso && $carga_horaria) {
                                echo '<input type="hidden" name="curso" value="' . $curso . '"/>';
                                echo '<input type="hidden" name="carga_horaria" value="' . $carga_horaria . '"/>';
                            }
                            ?>
                            <pre>Captcha: <b id="text-captcha"></b></pre>
                            <div class="form-group">
                                <div class="error_captcha"></div>
                                <input autocomplete="off" placeholder="Digite o Código do Captcha" maxlength="5" type="tel" class="form-control" id="captcha" minlength="4" required>
                            </div>

                           <div class="form-group form-check">
                                    <input type="checkbox" class="form-check-input" id="receberMensagensPublicitarias" name="receberMensagensPublicitarias" value="aceito" checked />
                                    <label class="form-check-label" for="receberMensagensPublicitarias">Gostaria de receber promoções por SMS, Push, WhatsApp e Email</label>
                           </div>

                            <input required="" type="hidden" id="fonte" value=""/>
                            <button id="btn-continuar" disabled="" type="submit" class="btn btn-primary mais-carga-horaria" onclick="">Cadastrar</button>
		                            <p style="font-size:12px; font-weight:bold;">*Ao clicar em cadastrar você estará concordando com nosso <a href="<?php echo base_url(); ?>termo" target="_blank">termo de uso</a></p>
		                        </form>


<?php } else if ( isset($usuario_existente) ) { ?>
                        <form class="frm-login form-signin" action="<?php echo current_url() ?>" method="post">
                            <div class="load">Enviando...
                                <hr/><hr/><hr/><hr/>
                            </div>
                            <div class="form-group">
                                <label for="email">Email</label>
                                <input type="email" class="form-control ui-autocomplete-input email-aluno" name="email" id="imz-user-email" placeholder="Informe um email válido" min="6" required value="<?php echo set_value('email'); ?>">
                            </div>
                            <div class="form-group">
                                <label for="senha">Senha</label>
                                <?php echo form_error('senha'); ?>
                                <input type="password" class="form-control" name="senha" id="senha" placeholder="Digite sua senha" min="6" required value="<?php echo set_value('senha'); ?>">
                            <?php echo form_error('senha', '<div class="label label-danger">', '</div>'); ?>
                            </div>
                            <?php
                            if ($curso && $carga_horaria) {
                                echo '<input type="hidden" name="curso" value="' . $curso . '"/>';
                                echo '<input type="hidden" name="carga_horaria" value="' . $carga_horaria . '"/>';
                            }
                            ?>
                            <button type="submit" class="btn btn-primary">Matricular</button>
								<!--<a href="<?php echo base_url(); ?>rec_senha" class="btn btn-default">Recuperar senha</a>-->
	                            <button type="button" class="btn btn-link" onclick="recuperar_senha_email()">Esqueci minha senha</button>
                        </form>
                        <br>
<?php } else { ?>

                        <form class="form-signin" action="<?php echo current_url() ?>" method="post">
                            <div class="form-group">
                                <label for="email">Email</label>
                                <?php echo form_error('email'); ?>
                                <div class="ui-widget">
                                    <input autocomplete="off" type="email" class="form-control" name="email" id="imz-user-email" placeholder="Informe um email válido" min="6" required value="<?php echo set_value('email'); ?>">
                                </div>
                            <?php echo form_error('email', '<div class="label label-danger">', '</div>'); ?>
                            </div>
                            <?php
                            if ($curso && $carga_horaria) {
                                echo '<input type="hidden" name="curso" value="' . $curso . '"/>';
                                echo '<input type="hidden" name="carga_horaria" value="' . $carga_horaria . '"/>';
                            }
                            ?>
                            <button type="submit" id="btn-continuar" class="btn btn-primary">Continuar</button>
                       <i class="glyphicon glyphicon-lock"></i> Página Segura. A transmissão dos dados é criptografada.
                        </form>
                        <br>

<?php } ?>
                    <div style="height: 10px;"></div>
                </div>
            </div>
        </div>
    </div>

</div>
<script>

window.onload = function () {
   document.getElementById("text-captcha").innerHTML = Math.floor(Math.random() * 9999)+ 1000 ;
}
</script>
<script>
$('#captcha').on('keyup touchend', function(){
    var captcha= $(this).val();
    var text_captcha = $("b#text-captcha").text();

    if(captcha.length>=4){

        if(captcha==text_captcha)
        {
            $('button#btn-continuar').prop('disabled', false);
            $(".error_captcha").hide();
        }
        else
        {
            $(".error_captcha").show();
            $(".error_captcha").html('<div class="alert alert-danger">Por favor apenas números, preencha o Captcha corretamente!</div>');
            $('button#btn-continuar').prop('disabled', true);
        }
    }
    else
    {
        $('button#btn-continuar').prop('disabled', true);
    }


});

$('#ddd').on('keyup touchend', function(){
    var ddd= $(this).val();

        if(ddd.length==2 && ddd>=11)
        {
            //$('button#btn-continuar').prop('disabled', false);
            $(".error_ddd").hide();
        }
        else
        {
            $(".error_ddd").show();
            $(".error_ddd").html('<div class="alert alert-danger">O campo ddd deve ter 2 digitos e não pode ser menor do que 11</div>');
            $('button#btn-continuar').prop('disabled', true);
        }


});

$('#telefone').on('keyup touchend', function(){
    var telefone= $(this).val();

    var l = Math.pow(10, Math.floor(Math.log(telefone)/Math.log(10))-1);
    var l = l*10;
    var digit = Math.floor(telefone/l);
    //var digit = b-Math.floor(b/10)*10;

        if(telefone.length==9 && digit==9)
        {
            //$('button#btn-continuar').prop('disabled', false);
            $(".error_celular").hide();
        }
        else
        {
            $(".error_celular").show();
            $(".error_celular").html('<div class="alert alert-danger">O campo celular deve ter 9 digitos e o primeiro digito deve ser o número 9</div>');
            $('button#btn-continuar').prop('disabled', true);
        }

});
</script>
<script>
function recuperar_senha_email() {
    var URL_BASE = "<?php echo base_url(); ?>";

    var email = $(".email-aluno").val();

    if ( (email.trim()!=='') && (email.length >= 6) ) {

        $('form button[type="submit"]').prop("disabled", true);
        $('.btn.btn-link').prop("disabled", true);

            $(".load").show();
        $.post(URL_BASE + 'recuperar_senha', {email:email}, function (e) {


            var resposta = JSON.parse(e);
            if (typeof resposta.mensagem !== 'undefined')
            {
                if(resposta.situacao==1)
                {
                    $(".load").show();
                    alert(resposta.mensagem);
                }
                else
                {
                    alert(resposta.mensagem);
                }
            }
            else
            {
                alert("Não foi possível enviar sua senha. Problema encontrado!");
            }
            window.location.reload();
        });
    }
    else {
        alert("Digite um email válido no campo de E-mail!");
        window.location.reload();
    }
}
</script>