<div class="content content-wrapper">
    <?php echo $this->load->view('components/banner') ?>
    <?php echo $this->load->view('components/slider') ?>
    <?php //echo $this->load->view('home/content_sidebar') ?>
    <?php echo $this->load->view('home/content_full') ?>
    <?php echo $this->load->view('components/offer_promo') ?>
    <?php echo $this->load->view('components/service') ?>
    <?php echo $this->load->view('components/offer_multidiscount') ?>
    <?php echo $this->load->view('components/offer_dish') ?>
    <?php echo $this->load->view('components/special_offer') ?>
    <?php echo $this->load->view('components/schedule_offer') ?>
</div>
<script>
    function setCollectionFromHome() {
        $.ajax({
            url: '<?php echo site_url('cart/setCollectionType') ?>',
            type: 'POST',
            dataType: 'json',
            data: {'type': 'collection'},
            beforeSend: function () {
                $('.loader-order-type').show();
            },
            success: function (response) {
                if (response.status) {
                    if (response.onlineOrderType === 'collection') {
                        window.location.href = '<?php echo site_url('online-order') ?>';
                    }
                }
            }
        });
    }
</script>
<div style="display: none;">
    <div id="customerPostcodeReceiverForm">
        <div class="popup-container">
            <?php echo form_open('cart/checkPostcode', array('id' => 'checkPostcodeForm')); ?>
            <div class="tab-group keypad">
                <div class="tab-item tab-item-title">Your delivery postcode</div>
            </div>
            <div class="loader-delivery-type" style="display: none; color: #d33">continue processing...</div>
            <div class="form-error" id="deliveryPostcodeErrorFromcheckPostcodeForm" style="color: #d33;"></div>
            <div class="tab-group" style="padding: 0px; border: none;">
                <input type="text" name="postcode" data-error="#deliveryPostcodeErrorFromcheckPostcodeForm" class="form-control text-uppercase" placeholder="AB1 2BC" style="width: 100%;">
            </div>
            <div><button type="submit" class="btn btn-b btn-sm" onclick="checkPostcodeFromHome('checkPostcodeForm')">Submit</button></div>
            <?php echo form_close() ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    function setDeliveryFromHome() {
        $.colorbox({
            inline: true,
            scrolling: false,
            href: "#customerPostcodeReceiverForm",
            width: '420px',
            height: 'auto',
            maxWidth: "100%",
            open: true,
            closeButton: true,
            transition: 'none',
            overlayClose: false,
            className: 'transparent-overlay',
            onOpen: function () {
                $('#colorbox').colorbox.resize();
            },
            onLoad: function () {

            },
            onComplete: function () {
            },
            onCleanup: function () {

            },
            onClosed: function () {
                window.location.reload();
            }
        });
    }
    function checkPostcodeFromHome(formId) {
        $('#' + formId).validate({
            submitHandler: function () {
                var myform = document.getElementById(formId);
                var formdata = new FormData(myform);
                $.ajax({
                    url: $('#' + formId).attr('action'),
                    data: formdata,
                    cache: false,
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    dataType: 'json',
                    beforeSend: function () {
                        $('.loader-delivery-type').show();
                        $('#colorbox').colorbox.resize();
                    },
                    success: function (response) {
                        response.status ? window.location.href = '<?php echo site_url('online-order') ?>' : $('#deliveryPostcodeErrorFromcheckPostcodeForm').text(response.message);
                    }
                });
            },
            errorClass: "has-error",
            highlight: function (e) {
                $(e).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (e) {
                $(e).closest('.form-group').removeClass('has-error');
            },
            rules: {postcode: {required: true, postcodeUK: true}},
            messages: {postcode: 'Please enter valid uk postcode'},
            errorPlacement: function (error, element) {
                errorPlacement(error, element);
                $('#colorbox').colorbox.resize();
            }
        });
    }
</script>

