<!-- START - CHECKOUT FORM -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        
        $(".checkout").submit(function(){
            // Fields
            let mail = $("#billing_email").val();
            let full_name = $("#billing_first_name").val() + ' ' + $("#billing_last_name").val()
            let company_name = $("#billing_company").val();
            let phone = $("#billing_phone").val();

            let country = $("#billing_country").val();
            let city = $("#billing_city").val();
            let address_1 = $("#billing_address_1").val();
            let address_2 = $("#billing_address_2").val();
            let postcode = $("#billing_postcode").val();
            let comments = $("#order_comments").val();

            // Build JSON to subscriber_full_data
            var full_data = { };
            full_data[mail] = [];
            // country
            full_data[mail][0] = {};
            full_data[mail][0]['label'] = "Country";
            full_data[mail][0]['content'] = country;

            // city
            full_data[mail][1] = {};
            full_data[mail][1]['label'] = "City";
            full_data[mail][1]['content'] = city;

            // address 1
            full_data[mail][2] = {};
            full_data[mail][2]['label'] = "Address1";
            full_data[mail][2]['content'] = address_1;

            // address 2
            full_data[mail][3] = {};
            full_data[mail][3]['label'] = "Address2";
            full_data[mail][3]['content'] = address_2;
            
            // postcode
            full_data[mail][4] = {};
            full_data[mail][4]['label'] = "Postcode";
            full_data[mail][4]['content'] = postcode;
            
            // comments
            full_data[mail][5] = {};
            full_data[mail][5]['label'] = "Comments";
            full_data[mail][5]['content'] = comments;
            let full_data_encoded = btoa(unescape(encodeURIComponent(JSON.stringify(full_data))));

            let api_url = 'https://www.powerly.co.il/lethe.api.php?act=add&pkey=5d2aebda25b91c6f186baf8fa6aa10b3&akey=NTJjNzViMmUwMGQ5OTI5MjI0MTNlZjdi&lmail='+mail+'&lgrp=374&&lsname='+full_name+'lscomp='+company_name+'&lsphone='+phone+'&lsfdata='+full_data_encoded;
            $.ajax({
                url: api_url,
                type : "POST",
                dataType: "json",
                async: false,
                data : $(".checkout").serialize(),
                success : function(result) {
                    return true;
                },
                error: function(xhr, resp, text) {
                    console.log(xhr, resp, text);
                }
            })
        });
    });
</script>
<!-- END - CHECKOUT FORM -->