<?php
if (!isset($_COOKIE['nfs_pwd']) || $_COOKIE['nfs_pwd'] !== 'Errands@agent') {
    header('Location: login.php');
    exit;
}

$res = '';
$num = '';
if (isset($_POST['submit'])) {
    include("api_process.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Lead addition</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
    <link href="css/daterangepicker.css" rel="stylesheet" media="all">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>

    <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

    <script src="js/validator.min.js"></script>
    <link href="css/custom.css" rel="stylesheet" media="all">
</head>

<body>

<div class="form-body">
    <div class="row">
        <div class="form-holder">
            <div class="form-content">
                <div class="form-items">
                    <h3>Medicare Clients</h3>
                    <h5 style="color: gold;"><?php echo $res;?></h5>
                    <form class="requires-validation" method="post" id="lead-form">
                        <div class="col-md-12">
                            <select name="type" id="type">
                                <option value="">Please Select Client</option>
                                <option value="m2">M2-SVG</option>
                                <option value="m3">M3-GH</option>
                                <option value="m4">M4-GH</option>
                                <option value="m57">M5/M7-SQ</option>
                                <option value="justdata">MH1/M1/M14</option>
                            </select>
                        </div>
                        <div class="col-md-12">
                            <input class="form-control" type="text" name="agent_name" placeholder="Agent Name">
                        </div>
                        <div class="col-md-12">
                            <input class="form-control" type="text" name="fname" placeholder="First Name">
                        </div>
                        <div class="col-md-12">
                            <input class="form-control" type="text" name="lname" placeholder="Last Name">
                        </div>

                        <div class="col-md-12">
                            <input class="form-control" type="number" name="zip" placeholder="Zip">
                        </div>


                        <div class="col-md-12">
                            <input class="form-control" type="text" name="state" placeholder="State">
                        </div>

                        <div class="col-md-12">
                            <input class="form-control" type="email" name="email" placeholder="Email">
                        </div>

                        <div class="col-md-12">
                            <input type="date" name="dob" class="form-control"
                                   placeholder="Date of birth" data-error="Please enter Date of Birth">
                        </div>

                        <div class="col-md-12">
                            <input id="phone_number" class="form-control" type="number" name="phone_number"
                                   placeholder="Phone" required>
                            <span id="warning-message"><?php echo $num; ?></span>
                        </div>


                        <div class="col-md-12">
                            <input class="form-control" type="text" name="og_leads_pii_id" placeholder="Lead ID">
                        </div>

                        <div class="col-md-12 form-button mt-3" style="margin-top: 16px;">
                            <button name="submit" id="submit" type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="js/daterangepicker.js"></script>
<script>
    $(function () {
        $("#datepicker").datepicker();
    });
</script>
<script type="text/javascript">

    var minLength = 10;
    var maxLength = 10;
    $('#phone_number').on('keydown keyup change', function () {
        var char = $(this).val();
        var charLength = $(this).val().length;
        if (charLength < minLength) {
            $('#warning-message').text('Length is short, minimum ' + minLength + ' required.');
        } else if (charLength > maxLength) {
            $('#warning-message').text('Length is not valid, maximum ' + maxLength + ' allowed.');
            $(this).val(char.substring(0, maxLength));
        } else {
            $('#warning-message').text('');
        }
    });
    (function () {
        'use strict'
        const forms = document.querySelectorAll('.requires-validation')
        Array.from(forms)
            .forEach(function (form) {
                form.addEventListener('submit', function (event) {
                    if (!form.checkValidity()) {
                        event.preventDefault()
                        event.stopPropagation()
                    }

                    form.classList.add('was-validated')
                }, false)
            })
    })()

</script>

</body>

</html>
