<!DOCTYPE html>
<div class="panel panel-default" id="painelSelecaoFila">
    <div class="panel-body">
        <div class="row">
            <div class="col-lg-12">
                <form onsubmit="$.fn.Carregando()" method="post">
                    <div class="row">
                        <form method="post" id="formDataNascimento" autocomplete="off">
                            <div class="col-sm-7 col-sm-7">
                                <div id="painelDefault">
                                    <div class="row">
                                        <div class="col-md-12 "style="margin-top: -30px; margin-left: -100px" align="center">
                                            <input <?= KEYBOARD ?"class='keyboard-num-2-digitos'":"" ?> <?= KEYBOARD ? "type='text'":"type='number'" ?> name="dnascimento"  min="1" placeholder="DIA" max="31"
                                                   style="width: 150px; text-align: center" required>
                                            <input <?= KEYBOARD ?"class='keyboard-num-2-digitos'":"" ?> <?= KEYBOARD ? "type='text'":"type='number'" ?> name="mnascimento"  min="1" placeholder="MÊS" max="12"
                                                   style="width: 150px; text-align:center" required>
                                            <input <?= KEYBOARD ?"class='keyboard-num-4-digitos'":"" ?> <?= KEYBOARD ? "type='text'":"type='number'" ?> name="anascimento"  min="1900" placeholder="ANO"
                                                   max="9999"
                                                   style="width: 150px; text-align: center" required>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12" style="margin-top: 10%" align="center">
                                            <div id="virtualKeyboard"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="col-sm-5" align="center" style="margin-top: -5%">
                                <div class="row">

                                    <div class="col-md-12" id="btnActionGroup">
                                        <div id="btnControleDefault" align="left">
                                            <button  type="submit" name="PROXIMO" id="btnAction" class="btn btn-primary">
                                                <img src="assets/img/PROXIMO.png" class="img-circle">
                                                PROXIMO
                                            </button>
                                        </div>
                                    </div>

                                    <div class="col-md-12" id="btnActionGroup">
                                        <div id="btnControleDefault" align="left">
                                            <button type="submit" name="VOLTAR" id="btnAction" onClick="history.go(-1)"
                                                    class="btn btn-primary">
                                                <img src="assets/img/VOLTAR.png" class="img-circle">
                                                VOLTAR
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>





<?php
if (isset($_SESSION['retorno'])) {
    echo "<script>confirmMessage('messageDialog','" . $_SESSION['mensagemRetorno'] . "',800,300,'" . base_url() . "');</script>";
}
?>

<div id="messageDialog"></div>

<script>

    $(document).ready(function () {
        $("[name='anascimento']").blur(function () {
            if($(this).val().length == 2 && $(this).val()>= 32){
                $(this).val('19'+$(this).val())
            }else if($(this).val().length == 2 && $(this).val()<= 31){
                $(this).val('20'+$(this).val())
            }
        });

        $("form").submit(function (event) {
            var day = $("[name='dnascimento']").val(),
                month = $("[name='mnascimento']").val(),
                year = $("[name='anascimento']").val();

            if (month == 2) {
                if (day == 29) {
                    if (year % 4 != 0 || year % 100 == 0 && year % 400 != 0) {

                        $("#messageDialog").html('O mês de fevereiro do ano ' + year + ' tem 28 dias, no máximo.');

                        $("#messageDialog").dialog({
                            closeOnEscape: false,
                            modal: true,
                            closable: false,
                            resizable: false,
                            draggable: false,
                            dialogClass: "noclose",
                            width: 850,
                            height: 250,
                            buttons: {
                                OK: function () {
                                    $("#load").dialog("close");
                                    $(this).dialog("close");
                                }
                            }
                        });
                        event.preventDefault();
                    }
                }
                else if (day > 28) {
                    $("#messageDialog").html('O mês de fevereiro do ano ' + year + ' tem 28 dias, no máximo.');

                    $("#messageDialog").dialog({
                        closeOnEscape: false,
                        modal: true,
                        closable: false,
                        resizable: false,
                        draggable: false,
                        dialogClass: "noclose",
                        width: 850,
                        height: 250,
                        buttons: {
                            OK: function () {
                                $("#load").dialog("close");
                                $(this).dialog("close");
                            }
                        }
                    });
                    event.preventDefault();
                }
            }
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {

                    $("#messageDialog").html('O mês ' + month + ' tem 30 dias, no máximo.');

                    $("#messageDialog").dialog({
                        closeOnEscape: false,
                        modal: true,
                        closable: false,
                        resizable: false,
                        draggable: false,
                        dialogClass: "noclose",
                        width: 850,
                        height: 250,
                        buttons: {
                            OK: function () {
                                $("#load").dialog("close");
                                $(this).dialog("close");
                            }
                        }
                    });
                    event.preventDefault();
                }
            }
            else {
                if (day > 31) {

                    $("#messageDialog").html('O mês ' + month + ' tem 31 dias, no máximo.');

                    $("#messageDialog").dialog({
                        closeOnEscape: false,
                        modal: true,
                        closable: false,
                        resizable: false,
                        draggable: false,
                        dialogClass: "noclose",
                        width: 850,
                        height: 250,
                        buttons: {
                            OK: function () {
                                $("#load").dialog("close");
                                $(this).dialog("close");
                            }
                        }
                    });
                    event.preventDefault();
                }
            }

        });


    });
</script>

<script language="javascript" src="assets/keyboard/custom/keyboard.js"></script>