

function getCart()
{
    var data = new FormData();
    data.append("request", "get_cart");
    $.ajax
    ({
        type: "POST",
        enctype: 'multipart/form-data',
        url: "../controllers/cart.php",
        data: data,
        processData: false,
        contentType: false,
        cache: false,
        timeout: 600000,
        async: false,
        success: function (response) 
        {
            response    =   JSON.parse(response);
            if((response["error"] == false))
            {
                if((response["html"]))
                {
                    $("#CartWrapper").html('');
                    $("#CartWrapper").html(response["html"]);

                }
            }
            console.log(response);
        },
        error: function (e) 
        {
            console.log("ERROR : ", e);
        }
    });
}






$(document).ready(function()
{


    $("#CheckoutForm").validate
    ({

        rules:
        {
            firstname:
            {
                required: true
            },
            lastname:
            {
                required: true
            },
            email:
            {
                required: true
            },
            country:
            {
                required: true
            },
            state:
            {
                required: true
            },
            city:
            {
                required: true
            },
            address:
            {
                required: true
            },
        }


    });




    $("#CheckoutForm").on("submit", function(event)
    {
        event.preventDefault();
        var FS  =   $(this).valid();
        if((FS))
        {
            var form    =   $(this)[0];
            var data = new FormData(form);
            data.append("request", "place_order");
            $("#CheckoutFormSB").prop("disabled", true);
            $.ajax
            ({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "../controllers/checkout.php",
                data: data,
                processData: false,
                contentType: false,
                cache: false,
                timeout: 600000,
                async: true,
                success: function (response) 
                {
                    response    =   JSON.parse(response);
                    if((response["error"] == false))
                    {
                        alert(response["message"]);
                        window.location.reload();
                    }
                    else
                    {
                        alert(response["error_msg"]);
                        window.location.reload();
                    }

                },
                error: function (e) 
                {
                    console.log("ERROR : ", e);
                }
            });

        }

    });













    getCart();






});